/** * Indicate in the action report that the command failed. */ private static void fail(AdminCommandContext context, String msg, Exception ex) { context.getActionReport().setActionExitCode( ActionReport.ExitCode.FAILURE); if (ex != null) context.getActionReport().setFailureCause(ex); context.getActionReport().setMessage(msg); }
private void copyActionReportContent(ActionReport source, ActionReport dest) { if (source == null || dest == null) { return; } dest.setActionExitCode(source.getActionExitCode()); dest.setExtraProperties(source.getExtraProperties()); //No deep copy. Any change of source is unexpected copyMessagePart(source.getTopMessagePart(), dest.getTopMessagePart()); List<? extends ActionReport> subReports = source.getSubActionsReport(); if (subReports != null) { for (ActionReport subrep : subReports) { copyActionReportContent(subrep, dest.addSubActionsReport()); } } }
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; } } } }
private void reportFailure(final String partName, final String formattedMessage, final Exception e) { if (report != null) { report.setActionExitCode(ActionReport.ExitCode.FAILURE); report.setMessage(formattedMessage); report.setFailureCause(e); } }
/** * Indicate in the action report a warning message. */ private void warning(AdminCommandContext context, String msg) { ActionReport ar = context.getActionReport().addSubActionsReport(); ar.setActionExitCode(ActionReport.ExitCode.WARNING); ar.setMessage(msg); }
public void reportError(ActionReport report, TransactionFailure e) { report.setMessage(localStrings.getLocalString("create.ssl.fail", "Creation of Ssl in {0} failed", listenerId)); report.setActionExitCode(ActionReport.ExitCode.FAILURE); report.setFailureCause(e); }
/** * Executes the command with the command parameters passed as Properties * where the keys are the paramter names and the values the parameter values * * @param context information */ public void execute(AdminCommandContext context) { final ActionReport report = context.getActionReport(); try { Collection<JdbcConnectionPool> connPools = domain.getResources().getResources(JdbcConnectionPool.class); for (JdbcConnectionPool pool : connPools) { final ActionReport.MessagePart part = report.getTopMessagePart().addChild(); part.setMessage(pool.getName()); } } catch (Exception e) { report.setMessage(localStrings.getLocalString("list.jdbc.connection.pools.failed", "List JDBC connection pools failed")); report.setActionExitCode(ActionReport.ExitCode.FAILURE); report.setFailureCause(e); return; } report.setActionExitCode(ActionReport.ExitCode.SUCCESS); } }
/** * Executes the command with the command parameters passed as Properties * where the keys are the paramter names and the values the parameter values * * @param context information */ public void execute(AdminCommandContext context) { final ActionReport report = context.getActionReport(); try { ConfigSupport.apply(new SingleConfigCode<JavaConfig>() { public Object run(JavaConfig param) throws PropertyVetoException, TransactionFailure { if (param.getProfiler() != null) { param.setProfiler(null); report.setActionExitCode(ActionReport.ExitCode.SUCCESS); return param; } // not found report.setMessage(localStrings.getLocalString("delete.profiler.notfound", "delete failed, profiler not found")); report.setActionExitCode(ActionReport.ExitCode.FAILURE); return null; } }, javaConfig); } catch(TransactionFailure e) { report.setMessage(localStrings.getLocalString("delete.profiler.fail", "delete failed ")); report.setActionExitCode(ActionReport.ExitCode.FAILURE); report.setFailureCause(e); } } }
private static void handleRetrieveException(final Exception e, final AdminCommandContext context, final boolean reportErrorsInTopReport) { final String errorMsg = localStrings.getLocalString( "download.errDownloading", "Error while downloading generated files"); final Logger logger = context.getLogger(); logger.log(Level.SEVERE, errorMsg, e); ActionReport report = context.getActionReport(); if ( ! reportErrorsInTopReport) { report = report.addSubActionsReport(); report.setActionExitCode(ExitCode.WARNING); } else { report.setActionExitCode(ExitCode.FAILURE); } report.setMessage(errorMsg); report.setFailureCause(e); }
static void setMBeanEnabled(MonitoringService ms, final String enabled, final ActionReport report) { try { ConfigSupport.apply(new SingleConfigCode<MonitoringService>() { public Object run(MonitoringService param) throws PropertyVetoException, TransactionFailure { param.setMbeanEnabled(enabled); return param; } }, ms); } catch(TransactionFailure tfe) { report.setMessage(localStrings.getLocalString("disable.monitoring.exception", "Encountered exception while setting mbean-enabled to false {0}", tfe.getMessage())); report.setActionExitCode(ActionReport.ExitCode.FAILURE); } }
/** * Executes the command * * @param context information */ @Override public void execute(AdminCommandContext context) { final ActionReport report = context.getActionReport(); final Target targetUtil = habitat.getComponent(Target.class ) ; final Config config = targetUtil.getConfig(target) ; final IiopService iiopService = config.getIiopService(); try { List<IiopListener> listenerList = iiopService.getIiopListener(); for (IiopListener listener : listenerList) { final ActionReport.MessagePart part = report.getTopMessagePart() .addChild(); part.setMessage(listener.getId()); } report.setActionExitCode(ActionReport.ExitCode.SUCCESS); } catch (Exception e) { report.setMessage(localStrings.getLocalString("list.iiop.listener" + ".fail", "List IIOP listeners failed.")); report.setActionExitCode(ActionReport.ExitCode.FAILURE); report.setFailureCause(e); } } }
private void fail(final ActionReport report, final String messageKey, final String fallbackMessageText, final Object... args) { report.setMessage(localStrings.getLocalString(messageKey, fallbackMessageText, args)); report.setActionExitCode(ActionReport.ExitCode.FAILURE); }
private void validateDeploymentProperties(Properties properties, DeploymentContext context) { String compatProp = properties.getProperty( DeploymentProperties.COMPATIBILITY); if (compatProp != null && !compatProp.equals("v2")) { // this only allowed value for property compatibility is v2 String warningMsg = localStrings.getLocalString("compat.value.not.supported", "{0} is not a supported value for compatibility property.", compatProp); ActionReport subReport = context.getActionReport().addSubActionsReport(); subReport.setActionExitCode(ActionReport.ExitCode.WARNING); subReport.setMessage(warningMsg); context.getLogger().log(Level.WARNING, warningMsg); } }
@Override public void execute(AdminCommandContext context) { final ActionReport report = context.getActionReport(); String[] cipherSuites = sslutils.getSupportedCipherSuites(); for (String cipherSuite : cipherSuites) { if (!cipherSuite.contains("_KRB5_")) { ActionReport.MessagePart part = report.getTopMessagePart().addChild(); part.setMessage(cipherSuite); } } report.setActionExitCode(ActionReport.ExitCode.SUCCESS); } }
@Override public void execute(AdminCommandContext context) { ActionReport report = context.getActionReport(); Logger logger= context.getLogger(); ManagedJobConfig managedJobConfig = domain.getExtensionByType(ManagedJobConfig.class); if (managedJobConfig == null ) { logger.warning(KernelLoggerInfo.getFailManagedJobConfig); report.setActionExitCode(ActionReport.ExitCode.FAILURE); report.setMessage(KernelLoggerInfo.getLogger().getResourceBundle().getString(KernelLoggerInfo.getFailManagedJobConfig)); return; ConfigSupport.apply(new SingleConfigCode<ManagedJobConfig>() { report.setActionExitCode(ActionReport.ExitCode.FAILURE); report.setMessage(e.getMessage());
@Override public void execute(AdminCommandContext context) { report = context.getActionReport(); logger = context.getLogger(); ListNodesHelper lnh = new ListNodesHelper(logger, servers, nodes, "CONFIG", long_opt, terse); String nodeList = lnh.getNodeList(); report.setMessage(nodeList); report.setActionExitCode(ExitCode.SUCCESS); } }
public void execute(AdminCommandContext context) { ActionReport report = context.getActionReport(); ActionReport.MessagePart part = report.getTopMessagePart(); boolean found = false; for (Application app : domain.getApplicationsInTarget(target)) { if (app.isLifecycleModule()) { ActionReport.MessagePart childPart = part.addChild(); childPart.setMessage(app.getName()); found = true; } } if (!found && !terse) { part.setMessage(localStrings.getLocalString("list.components.no.elements.to.list", "Nothing to List.")); } report.setActionExitCode(ActionReport.ExitCode.SUCCESS); } }
@Override public void execute(AdminCommandContext context) { up.postConstruct(); String msg = "Testing upgrade!"; ActionReport report = context.getActionReport(); report.setActionExitCode(ExitCode.SUCCESS); report.setMessage(msg); } }
public static void fillActionReport(final ActionReport ar, final JSONObject json) throws JSONException { ar.setActionExitCode(ActionReport.ExitCode.valueOf(json.getString("exit_code"))); ar.setActionDescription(json.optString("command")); String failure = json.optString("failure_cause"); if (failure != null && !failure.isEmpty()) { ar.setFailureCause(new Exception(failure)); } ar.setExtraProperties((Properties) extractMap(json.optJSONObject("extraProperties"), new Properties())); ar.getTopMessagePart().setMessage(json.optString("top_message", json.optString("message"))); Properties props = (Properties) extractMap(json.optJSONObject("properties"), new Properties()); for (Map.Entry entry : props.entrySet()) { ar.getTopMessagePart().addProperty(String.valueOf(entry.getKey()), String.valueOf(entry.getValue())); } //Sub messages fillSubMessages(ar.getTopMessagePart(), json.optJSONArray("children")); //Sub action reports JSONArray subJsons = json.optJSONArray("subReports"); if (subJsons != null) { for (int i = 0; i < subJsons.length(); i++) { JSONObject subJson = subJsons.getJSONObject(i); fillActionReport(ar.addSubActionsReport(), subJson); } } }
@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); } } }