/** * Short for {@code failure(logger,message,null)} */ public final void failure(Logger logger, String message) { failure(logger,message,null); }
/** * Short for {@code failure(logger,message,null)} */ public final void failure(Logger logger, String message) { failure(logger,message,null); }
abstract void doWork(VirtualMachine vm) throws VirtException; }
public static void ensureTopLevelConfig(Domain domain, ActionReport actionReport) { if (domain.getExtensionByType(Virtualizations.class)==null) { try { ConfigSupport.apply(new SingleConfigCode<Domain>() { @Override public Object run(Domain wDomain) throws PropertyVetoException, TransactionFailure { Virtualizations virts = wDomain.createChild(Virtualizations.class); wDomain.getExtensions().add(virts); return virts; } }, domain); } catch (TransactionFailure transactionFailure) { actionReport.failure(RuntimeContext.logger, "Cannot create parent virtualizations configuration",transactionFailure); return; } } } }
public void execute(AdminCommandContext context) { this.report = context.getActionReport(); ServerPool vmProvider = gm.byName(groupName); if (vmProvider!=null && vmProvider instanceof PhysicalServerPool) { PhysicalServerPool group = (PhysicalServerPool) vmProvider; Machine machine = group.byName(machineName); if (machine==null) { context.getActionReport().failure(Logger.getAnonymousLogger(), "Don't know about machine " + machineName); return; } try { doWork(machine); } catch(VirtException e) { context.getActionReport().failure(Logger.getAnonymousLogger(), e.getMessage(), e); } } else { context.getActionReport().failure(RuntimeContext.logger, "serverPool does not exist or does not contain physical machines"); } }
protected Collection<EngineInfo> setupContainer(Sniffer sniffer, Logger logger, DeploymentContext context) { ActionReport report = context.getActionReport(); ContainerStarter starter = habitat.getService(ContainerStarter.class); Collection<EngineInfo> containersInfo = starter.startContainer(sniffer); if (containersInfo == null || containersInfo.size()==0) { report.failure(logger, "Cannot start container(s) associated to application of type : " + sniffer.getModuleType(), null); return null; } return containersInfo; }
protected Collection<EngineInfo> setupContainer(Sniffer sniffer, Logger logger, DeploymentContext context) { ActionReport report = context.getActionReport(); ContainerStarter starter = habitat.getService(ContainerStarter.class); Collection<EngineInfo> containersInfo = starter.startContainer(sniffer); if (containersInfo == null || containersInfo.size()==0) { report.failure(logger, "Cannot start container(s) associated to application of type : " + sniffer.getModuleType(), null); return null; } return containersInfo; }
/** * Opens and returns an archive for the injected "path" parameter. If there * is any problem the method updates the action report accordingly. * @param logger * @param report * @return */ private ReadableArchive archive(final Logger logger, final ActionReport report) { try { return archiveFactory.openArchive(path, this); } catch (IOException e) { final String msg = localStrings.getLocalString("deploy.errOpeningArtifact", "deploy.errOpeningArtifact", path.getAbsolutePath()); if (logReportedErrors) { report.failure(logger, msg, e); } else { report.setMessage(msg + path.getAbsolutePath() + e.toString()); report.setActionExitCode(ActionReport.ExitCode.FAILURE); } return null; } }
@Override public <T extends ConfigBeanProxy> T resolve(AdminCommandContext context, Class<T> type) { Virtualization virt = virtualization==null?virts.getVirtualizations().get(0):virts.byName(virtualization); ServerPoolConfig config = virt.serverPoolByName(group); if (config!=null) { return (T) config; } context.getActionReport().failure(context.getLogger(), "Cannot find a serverPool by the name of " + group); return null; } }
@Override public <T extends ConfigBeanProxy> T resolve(AdminCommandContext context, Class<T> type) { ServerPoolConfig serverPool = (ServerPoolConfig) super.resolve(context,type); if (serverPool!=null) { MachineConfig mc = serverPool.machineByName(name); if (mc!=null) return (T) mc; context.getActionReport().failure(context.getLogger(), "Cannot find a machine by the name of " + serverPool); } return null; }
@Override public <T extends ConfigBeanProxy> T resolve(AdminCommandContext context, Class<T> type) { Virtualization virt = virtualization==null?virts.getVirtualizations().get(0):virts.byName(virtualization); ServerPoolConfig config = virt.serverPoolByName(serverPool); if (config!=null) { return (T) config.machineByName(machine); } context.getActionReport().failure(context.getLogger(), "Cannot find a machine by the name of " + machine); return null; } }
/** * Executes the particular xxx-secure-admin command (enable or disable). * @param context */ @Override public void execute(final AdminCommandContext context) { final ActionReport report = context.getActionReport(); try { report.setActionExitCode(ActionReport.ExitCode.SUCCESS); run(); } catch (TransactionFailure ex) { report.failure(context.getLogger(), Strings.get(transactionErrorMessageKey()), ex); } catch (SecureAdminCommandException ex) { report.failure(context.getLogger(), ex.getLocalizedMessage(), ex); } }
/** * Executes the particular xxx-secure-admin command (enable or disable). * @param context */ @Override public void execute(final AdminCommandContext context) { final ActionReport report = context.getActionReport(); try { report.setActionExitCode(ActionReport.ExitCode.SUCCESS); run(); report.setMessage(Strings.get("restartReq")); } catch (TransactionFailure ex) { report.failure(context.getLogger(), Strings.get(transactionErrorMessageKey()), ex); } catch (SecureAdminCommandException ex) { report.failure(context.getLogger(), ex.getLocalizedMessage()); } }
/** * unloads the module from its container. * * @param context unloading context * @return */ public boolean unload(ExtendedDeploymentContext context) { ActionReport report = context.getActionReport(); // then remove the application from the container Deployer deployer = ctrInfo.getDeployer(); try { deployer.unload(appCtr, context); ctrInfo.unload(context); } catch(Exception e) { report.failure(context.getLogger(), "Exception while shutting down application container", e); return false; } appCtr=null; return true; }
/** * unloads the module from its container. * * @param context unloading context * @return */ public boolean unload(ExtendedDeploymentContext context) { ActionReport report = context.getActionReport(); // then remove the application from the container Deployer deployer = ctrInfo.getDeployer(); try { deployer.unload(appCtr, context); ctrInfo.unload(context); } catch(Exception e) { report.failure(context.getLogger(), "Exception while shutting down application container", e); return false; } appCtr=null; return true; }
@Override public Object run(ConfigBeanProxy parentProxy) throws PropertyVetoException, TransactionFailure { ConfigSupport._deleteChild(child.parent(), (WriteableView) Proxy.getInvocationHandler(parentProxy), child); DeletionDecorator<ConfigBeanProxy, ConfigBeanProxy> decorator = habitat.getService(delete.decorator()); if (decorator==null) { String msg = localStrings.getLocalString(GenericCrudCommand.class, "GenericCreateCommand.deletion_decorator_not_found", "The DeletionDecorator {0} could not be found in the habitat,is it annotated with @Service ?", delete.decorator().toString()); result.failure(logger, msg); throw new TransactionFailure(msg); } else { // inject the decorator with any parameters from the initial CLI invocation manager.inject(decorator, paramResolver); // invoke the decorator decorator.decorate(context, parentProxy, tgt); } return null; } }, parentProxy);
@Override public Object run(ConfigBeanProxy parentProxy) throws PropertyVetoException, TransactionFailure { ConfigSupport._deleteChild(child.parent(), (WriteableView) Proxy.getInvocationHandler(parentProxy), child); DeletionDecorator<ConfigBeanProxy, ConfigBeanProxy> decorator = habitat.getComponent(delete.decorator()); if (decorator==null) { String msg = localStrings.getLocalString(GenericCrudCommand.class, "GenericCreateCommand.deletion_decorator_not_found", "The DeletionDecorator {0} could not be found in the habitat,is it annotated with @Service ?", delete.decorator().toString()); result.failure(logger, msg); throw new TransactionFailure(msg); } else { // inject the decorator with any parameters from the initial CLI invocation manager.inject(decorator, paramResolver); // invoke the decorator decorator.decorate(context, parentProxy, target); } return null; } }, parentProxy);
@Override public void execute(AdminCommandContext context) { //To change body of implemented methods use File | Settings | File Templates. try { for (ServerPool group : gm) { context.getActionReport().setMessage("For Group : " + group.getName()); for (VirtualMachine vm : group.getVMs()) { context.getActionReport().getTopMessagePart().addChild().setMessage( "Virtual Machine: " + vm.getName() + " is " + vm.getInfo().getState()); } } } catch(VirtException e) { context.getActionReport().failure(Logger.getAnonymousLogger(), "Exception while listing machines ", e); } } }
public ApplicationInfo unload(ApplicationInfo info, ExtendedDeploymentContext context) { ActionReport report = context.getActionReport(); if (info==null) { report.failure(context.getLogger(), "Application not registered", null); return null; } notifyLifecycleInterceptorsBefore(ExtendedDeploymentContext.Phase.STOP, context); if (info.isLoaded()) { info.stop(context, context.getLogger()); notifyLifecycleInterceptorsAfter(ExtendedDeploymentContext.Phase.STOP, context); notifyLifecycleInterceptorsBefore(ExtendedDeploymentContext.Phase.UNLOAD, context); info.unload(context); notifyLifecycleInterceptorsAfter(ExtendedDeploymentContext.Phase.UNLOAD, context); } events.send(new Event<ApplicationInfo>(Deployment.APPLICATION_DISABLED, info), false); try { notifyLifecycleInterceptorsBefore(ExtendedDeploymentContext.Phase.CLEAN, context); info.clean(context); notifyLifecycleInterceptorsAfter(ExtendedDeploymentContext.Phase.CLEAN, context); } catch(Exception e) { report.failure(context.getLogger(), "Exception while cleaning", e); return info; } return info; }
public void undeploy(String appName, ExtendedDeploymentContext context) { ActionReport report = context.getActionReport(); UndeployCommandParameters params = context.getCommandParameters(UndeployCommandParameters.class); ApplicationInfo info = appRegistry.get(appName); if (info==null) { report.failure(context.getLogger(), "Application " + appName + " not registered", null); events.send(new Event(Deployment.UNDEPLOYMENT_FAILURE, context)); return; } events.send(new Event(Deployment.UNDEPLOYMENT_START, info)); // for DAS target, the undeploy should unload the application // as well if (DeploymentUtils.isDASTarget(params.target)) { unload(info, context); } if (report.getActionExitCode().equals(ActionReport.ExitCode.SUCCESS)) { events.send(new Event(Deployment.UNDEPLOYMENT_SUCCESS, context)); deploymentLifecycleProbeProvider.applicationUndeployedEvent(appName, getApplicationType(info)); } else { events.send(new Event(Deployment.UNDEPLOYMENT_FAILURE, context)); } appRegistry.remove(appName); }