@Override public boolean preAuthorization(AdminCommandContext context) { spb = CLIUtil.chooseTarget(domain, target); if (spb == null) { final ActionReport report = context.getActionReport(); report.setActionExitCode(ActionReport.ExitCode.FAILURE); String msg = localStrings.getLocalString("invalid.target.sys.props", "Invalid target:{0}. Valid targets types are domain, config, cluster, default server, clustered instance, stand alone instance", target); report.setMessage(msg); return false; } return true; }
@Override public void decorate(AdminCommandContext context, LbConfigs parent, LbConfig child) throws PropertyVetoException, TransactionFailure { Logger logger = LogDomains.getLogger(LbConfig.class, LogDomains.ADMIN_LOGGER); LocalStringManagerImpl localStrings = new LocalStringManagerImpl(LbConfig.class); String lbConfigName = child.getName(); LbConfig lbConfig = domain.getExtensionByType(LbConfigs.class).getLbConfig(lbConfigName); //Ensure there are no refs if ( (lbConfig.getClusterRefOrServerRef().size() != 0 ) ) { String msg = localStrings.getLocalString("LbConfigNotEmpty", lbConfigName); throw new TransactionFailure(msg); } logger.info(localStrings.getLocalString("http_lb_admin.LbConfigDeleted", lbConfigName)); } }
@Override public void decorate(AdminCommandContext context, LbConfigs parent, LbConfig child) throws PropertyVetoException, TransactionFailure { Logger logger = LogDomains.getLogger(LbConfig.class, LogDomains.ADMIN_LOGGER); LocalStringManagerImpl localStrings = new LocalStringManagerImpl(LbConfig.class); String lbConfigName = child.getName(); LbConfig lbConfig = domain.getLbConfigs().getLbConfig(lbConfigName); //Ensure there are no refs if ( (lbConfig.getClusterRefOrServerRef().size() != 0 ) ) { String msg = localStrings.getLocalString("LbConfigNotEmpty", lbConfigName); throw new TransactionFailure(msg); } logger.info(localStrings.getLocalString("http_lb_admin.LbConfigDeleted", lbConfigName)); } }
/** * 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) { ActionReport report = context.getActionReport(); try { ConfigSupport.apply(new SingleConfigCode<SecurityService>() { public Object run(SecurityService param) throws PropertyVetoException, TransactionFailure { param.getAuthRealm().remove(authRealm); //temporary fix - since the SecurityConfigListener is not being called on an realm delete. SecurityConfigListener.authRealmDeleted(authRealm); return null; } }, securityService); } catch(TransactionFailure e) { report.setMessage(localStrings.getLocalString( "delete.auth.realm.fail", "Deletion of Authrealm {0} failed", authRealmName) + " " + e.getLocalizedMessage()); report.setActionExitCode(ActionReport.ExitCode.FAILURE); report.setFailureCause(e); return; } report.setActionExitCode(ActionReport.ExitCode.SUCCESS); }
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); } }
final ActionReport report = context.getActionReport(); Server targetServer = domain.getServerNamed(target); if (targetServer != null) { config = domain.getConfigNamed(targetServer.getConfigRef()); com.sun.enterprise.config.serverbeans.Cluster cluster = domain.getClusterNamed(target); if (cluster != null) { config = domain.getConfigNamed(cluster.getConfigRef()); SecurityService securityService = config.getSecurityService(); for (AuthRealm authrealm : authrealms) { if (authrealm.getName().equals(authRealmName)) { report.setMessage(localStrings.getLocalString( "create.auth.realm.duplicatefound", "Authrealm named {0} exists. Cannot add duplicate AuthRealm.", authRealmName)); report.setActionExitCode(ActionReport.ExitCode.FAILURE); return; ConfigSupport.apply(new SingleConfigCode<SecurityService>() { report.setMessage(localStrings.getLocalString("create.auth.realm.fail", "Creation of Authrealm {0} failed", authRealmName) + " " + e.getLocalizedMessage() ); report.setActionExitCode(ActionReport.ExitCode.FAILURE); report.setFailureCause(e);
@Override public void execute(AdminCommandContext context) { ActionReport report = context.getActionReport(); report.setActionExitCode(ActionReport.ExitCode.SUCCESS); report.setMessage(localStrings.getLocalString("Config.badConfigNames", "You must specify a source and destination config.")); report.setActionExitCode(ActionReport.ExitCode.FAILURE); return; final Config config = domain.getConfigNamed(srcConfig); if (config == null ){ report.setMessage(localStrings.getLocalString( final Config destinationConfig = domain.getConfigNamed(destConfig); if (destinationConfig != null ){ report.setMessage(localStrings.getLocalString( } ,domain.getConfigs()); localStrings.getLocalString( "Config.copyConfigError", "CopyConfig error caused by " , e.getLocalizedMessage()));
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); }
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); }
@Override public void decorate(AdminCommandContext context, LoadBalancers parent, LoadBalancer child) throws PropertyVetoException, TransactionFailure{ ActionReport report = context.getActionReport(); Logger logger = LogDomains.getLogger(LoadBalancer.class, LogDomains.ADMIN_LOGGER); LocalStringManagerImpl localStrings = new LocalStringManagerImpl(LoadBalancer.class); Transaction t = Transaction.getTransaction(parent); LbConfig lbConfig = domain.getExtensionByType(LbConfigs.class).getLbConfig(lbConfigName); for (LoadBalancer lb:domain.getExtensionByType(LoadBalancers.class).getLoadBalancer()) { if (!lb.getName().equals(lbName) && lb.getLbConfigName().equals(lbConfigName)) { String msg = localStrings.getLocalString("LbConfigIsInUse", lbConfigName); report.setMessage(msg); report.setActionExitCode(ActionReport.ExitCode.FAILURE); throw new TransactionFailure(msg); localStrings.getLocalString("DeleteLbConfigFailed", "Unable to remove lb config {0}", lbConfigName), ex); String msg = ex.getMessage() != null ? ex.getMessage() : localStrings.getLocalString("DeleteLbConfigFailed", "Unable to remove lb config {0}", lbConfigName); report.setMessage(msg); report.setActionExitCode(ActionReport.ExitCode.FAILURE); report.setFailureCause(ex);
@Override public void decorate(AdminCommandContext context, LoadBalancers parent, LoadBalancer child) throws PropertyVetoException, TransactionFailure{ ActionReport report = context.getActionReport(); Logger logger = LogDomains.getLogger(LoadBalancer.class, LogDomains.ADMIN_LOGGER); LocalStringManagerImpl localStrings = new LocalStringManagerImpl(LoadBalancer.class); Transaction t = Transaction.getTransaction(parent); LbConfig lbConfig = domain.getLbConfigs().getLbConfig(lbConfigName); for (LoadBalancer lb:domain.getLoadBalancers().getLoadBalancer()) { if (!lb.getName().equals(lbName) && lb.getLbConfigName().equals(lbConfigName)) { String msg = localStrings.getLocalString("LbConfigIsInUse", lbConfigName); report.setMessage(msg); report.setActionExitCode(ActionReport.ExitCode.FAILURE); throw new TransactionFailure(msg); localStrings.getLocalString("DeleteLbConfigFailed", "Unable to remove lb config {0}", lbConfigName), ex); String msg = ex.getMessage() != null ? ex.getMessage() : localStrings.getLocalString("DeleteLbConfigFailed", "Unable to remove lb config {0}", lbConfigName); report.setMessage(msg); report.setActionExitCode(ActionReport.ExitCode.FAILURE); report.setFailureCause(ex);
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); }
/** * Executes the command. * * @param context information */ public void execute(AdminCommandContext context) { final ActionReport report = context.getActionReport(); ActionReport.MessagePart msgPart = report.getTopMessagePart(); msgPart.setChildrenType("WARNING"); ActionReport.MessagePart childPart = msgPart.addChild(); String commandName = getClass().getAnnotation(Service.class).name(); childPart.setMessage(localStrings.getLocalString("deploydir.command.deprecated", "{0} command deprecated. Please use {1} command instead.", commandName, "deploy")); super.execute(context); } }
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); } }
private void setModuleMonitoringLevel(String moduleName, String level, ActionReport report) { ActionReport.MessagePart part = report.getTopMessagePart().addChild(); if (!isValidString(moduleName)) { part.setMessage(localStrings.getLocalString("enable.monitoring.invalid", "Invalid module name {0}", moduleName)); report.setActionExitCode(ActionReport.ExitCode.FAILURE); } if ((!isValidString(level)) || (!isValidLevel(level))) { part.setMessage(localStrings.getLocalString("enable.monitoring.invalid", "Invalid level {0} for module name {1}", level, moduleName)); report.setActionExitCode(ActionReport.ExitCode.FAILURE); } MonitoringConfig.setMonitoringLevel(ms, moduleName, level, report); }
/** * Get a localized string from the package of the default class. * @param key The name of the resource to fetch * @param defaultValue The default return value if not found * @return The localized string */ public String getLocalString(String key, String defaultValue) { return getLocalString(null, key, defaultValue); }
@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);
private void createConfigElement(final String configElement) { try { ConfigSupport.apply(new SingleConfigCode<MonitoringService>() { public Object run(MonitoringService param) throws PropertyVetoException, TransactionFailure { ContainerMonitoring newItem = param.createChild(ContainerMonitoring.class); newItem.setName(configElement); param.getContainerMonitoring().add(newItem); return newItem; } }, monitoringService); } catch (TransactionFailure tf) { String msg = localStrings.getLocalString(cannotCreateConfigElement, "Unable to create container-monitoring for", configElement); logger.log(Level.SEVERE, msg, tf); } }
public ResourceStatus create(Resources resources, HashMap attributes, final Properties properties, String target) throws Exception { setAttributes(attributes); ResourceStatus validationStatus = isValid(resources); if(validationStatus.getStatus() == ResourceStatus.FAILURE){ return validationStatus; } try { ConfigSupport.apply(new SingleConfigCode<Resources>() { public Object run(Resources param) throws PropertyVetoException, TransactionFailure { return createResource(param, properties); } }, resources); } catch (TransactionFailure tfe) { String msg = localStrings.getLocalString( "create.jdbc.connection.pool.fail", "JDBC connection pool {0} create failed: {1}", jdbcconnectionpoolid, tfe.getMessage()); return new ResourceStatus(ResourceStatus.FAILURE, msg); } String msg = localStrings.getLocalString( "create.jdbc.connection.pool.success", "JDBC connection pool {0} created successfully", jdbcconnectionpoolid); return new ResourceStatus(ResourceStatus.SUCCESS, msg); }
@Override public void postConstruct() { super.postConstruct(); listing = targetMethod.getAnnotation(Listing.class); resolverType = listing.resolver(); try { // we pass false for "useAnnotations" as the @Param declarations on // the target type are not used for the List method parameters. cmdModel = new GenericCommandModel(targetType, false, null, listing.i18n(), new LocalStringManagerImpl(targetType), habitat.<DomDocument>getService(DomDocument.class), commandName, false, listing.resolver(), GenericListCommand.class); targetModel = habitat.<DomDocument>getService(DomDocument.class).buildModel(targetType); if (logger.isLoggable(level)) { for (String paramName : cmdModel.getParametersNames()) { CommandModel.ParamModel param = cmdModel.getModelFor(paramName); logger.log(Level.FINE, "I take {0} parameters", param.getName()); } } } catch(Exception e) { String msg = localStrings.getLocalString(GenericCrudCommand.class, "GenericCreateCommand.command_model_exception", "Exception while creating the command model for the generic command {0} : {1}", commandName, e.getMessage()); LogHelper.log(logger, Level.SEVERE,ConfigApiLoggerInfo.GENERIC_CREATE_CMD_FAILED, e, commandName); throw new RuntimeException(msg, e); } }