use of org.jvnet.hk2.config.SingleConfigCode in project Payara by payara.
the class SetBatchRuntimeConfiguration method execute.
@Override
public void execute(final AdminCommandContext context) {
final ActionReport actionReport = context.getActionReport();
Properties extraProperties = actionReport.getExtraProperties();
if (extraProperties == null) {
extraProperties = new Properties();
actionReport.setExtraProperties(extraProperties);
}
if (dataSourceLookupName == null && executorServiceLookupName == null) {
actionReport.setMessage("Either dataSourceLookupName or executorServiceLookupName must be specified.");
actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
try {
Config config = targetUtil.getConfig(target);
BatchRuntimeConfiguration batchRuntimeConfiguration = config.getExtensionByType(BatchRuntimeConfiguration.class);
if (batchRuntimeConfiguration != null) {
ConfigSupport.apply(new SingleConfigCode<BatchRuntimeConfiguration>() {
@Override
public Object run(final BatchRuntimeConfiguration batchRuntimeConfigurationProxy) throws PropertyVetoException, TransactionFailure {
boolean encounteredError = false;
int tableprefixlength = 0;
int tablesuffixlength = 0;
if (dataSourceLookupName != null) {
try {
validateDataSourceLookupName(context, target, dataSourceLookupName);
batchRuntimeConfigurationProxy.setDataSourceLookupName(dataSourceLookupName);
actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
} catch (GlassFishBatchValidationException ex) {
logger.log(Level.WARNING, ex.getMessage());
actionReport.setMessage(dataSourceLookupName + " is not mapped to a DataSource");
actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
throw new GlassFishBatchValidationException(dataSourceLookupName + " is not mapped to a DataSource");
}
}
if (executorServiceLookupName != null && !encounteredError) {
try {
validateExecutorServiceLookupName(context, target, executorServiceLookupName);
batchRuntimeConfigurationProxy.setExecutorServiceLookupName(executorServiceLookupName);
actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
} catch (GlassFishBatchValidationException ex) {
logger.log(Level.WARNING, ex.getMessage());
actionReport.setMessage("No executor service bound to name = " + executorServiceLookupName);
actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
throw new GlassFishBatchValidationException("No executor service bound to name = " + executorServiceLookupName);
}
}
if (schemaName != null && !encounteredError) {
batchRuntimeConfigurationProxy.setSchemaName(schemaName);
actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
if (tablePrefix != null && !encounteredError) {
tableprefixlength = tablePrefix.length();
batchRuntimeConfigurationProxy.setTablePrefix(tablePrefix);
actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
if (tableSuffix != null && !encounteredError) {
tablesuffixlength = tableSuffix.length();
batchRuntimeConfigurationProxy.setTableSuffix(tableSuffix);
actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
if (targetUtil.isThisDAS() && isOracle(dataSourceLookupName)) {
if (tablesuffixlength + tableprefixlength + MAX_TABLE_LENGTH > 30) {
actionReport.setMessage("The table name cannot be greater than 30 characters in Oracle, please amend the table prefix or suffix size ");
actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
throw new GlassFishBatchValidationException("The table name cannot be greater than 30 characters in Oracle, please amend the table prefix or suffix size ");
}
}
return null;
}
}, batchRuntimeConfiguration);
}
} catch (TransactionFailure txfEx) {
logger.log(Level.WARNING, "Exception during command ", txfEx);
actionReport.setMessage(txfEx.getCause().getMessage());
actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
}
use of org.jvnet.hk2.config.SingleConfigCode in project Payara by payara.
the class CreateJMSHost method execute.
/**
* 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();
Config targetConfig = domain.getConfigNamed(target);
if (targetConfig != null)
config = targetConfig;
Server targetServer = domain.getServerNamed(target);
// String configRef = targetServer.getConfigRef();
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());
}
if (jmsHostName == null) {
report.setMessage(localStrings.getLocalString("create.jms.host.noJmsHost", "No JMS Host name specified."));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
JmsService jmsservice = config.getExtensionByType(JmsService.class);
// ensure we don't already have one of this name before creating it.
for (JmsHost jmsHost : jmsservice.getJmsHost()) {
if (jmsHostName.equals(jmsHost.getName())) {
if (force) {
ActionReport deleteReport = report.addSubActionsReport();
ParameterMap parameters = new ParameterMap();
parameters.set("DEFAULT", jmsHostName);
parameters.set("target", target);
commandRunner.getCommandInvocation("delete-jms-host", deleteReport, context.getSubject()).parameters(parameters).execute();
if (ActionReport.ExitCode.FAILURE.equals(deleteReport.getActionExitCode())) {
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
break;
} else {
report.setMessage(localStrings.getLocalString("create.jms.host.duplicate", "A JMS Host named {0} already exists.", jmsHostName));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
}
}
try {
ConfigSupport.apply(new SingleConfigCode<JmsService>() {
public Object run(JmsService param) throws PropertyVetoException, TransactionFailure {
// TODO: need a way to create a JmsHost instance
JmsHost jmsHost = param.createChild(JmsHost.class);
jmsHost.setAdminPassword(mqpassword);
jmsHost.setAdminUserName(mquser);
jmsHost.setName(jmsHostName);
jmsHost.setHost(mqhost);
jmsHost.setPort(mqport);
if (props != null) {
for (Map.Entry e : props.entrySet()) {
Property prop = jmsHost.createChild(Property.class);
prop.setName((String) e.getKey());
prop.setValue((String) e.getValue());
jmsHost.getProperty().add(prop);
}
}
param.getJmsHost().add(jmsHost);
return jmsHost;
}
}, jmsservice);
} catch (TransactionFailure tfe) {
report.setMessage(localStrings.getLocalString("create.jms.host.fail", "Unable to create jms host {0}.", jmsHostName) + " " + tfe.getLocalizedMessage());
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setFailureCause(tfe);
}
report.setMessage(localStrings.getLocalString("create.jms.host.success", "Jms Host {0} created.", jmsHostName));
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
use of org.jvnet.hk2.config.SingleConfigCode in project Payara by payara.
the class PersistenceManagerFactoryResourceMigrator method postConstruct.
public void postConstruct() {
Collection<PersistenceManagerFactoryResource> pmfResources = resources.getResources(PersistenceManagerFactoryResource.class);
for (final PersistenceManagerFactoryResource pmfResource : pmfResources) {
String jdbcResourceName = pmfResource.getJdbcResourceJndiName();
final JdbcResource jdbcResource = (JdbcResource) ConnectorsUtil.getResourceByName(resources, JdbcResource.class, jdbcResourceName);
try {
ConfigSupport.apply(new SingleConfigCode<Resources>() {
public Object run(Resources resources) throws PropertyVetoException, TransactionFailure {
// delete the persitence-manager-factory resource
resources.getResources().remove(pmfResource);
// create a jdbc resource which points to same connection pool and has same jndi name as pmf resource.
JdbcResource newResource = resources.createChild(JdbcResource.class);
newResource.setJndiName(pmfResource.getJndiName());
newResource.setDescription("Created to migrate persistence-manager-factory-resource from V2 domain");
newResource.setPoolName(jdbcResource.getPoolName());
newResource.setEnabled("true");
resources.getResources().add(newResource);
return newResource;
}
}, resources);
} catch (TransactionFailure tf) {
Logger.getAnonymousLogger().log(Level.SEVERE, "Failure while upgrading persistence-manager-factory-resource", tf);
throw new RuntimeException(tf);
}
}
// end of iteration
}
use of org.jvnet.hk2.config.SingleConfigCode in project Payara by payara.
the class SetMonitoringConfiguration method execute.
@Override
public void execute(AdminCommandContext context) {
final ActionReport actionReport = context.getActionReport();
Config config = targetUtil.getConfig(target);
final MonitoringService service = serviceLocator.getService(MonitoringService.class);
if (service == null) {
actionReport.appendMessage("Could not find a monitoring service.");
actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
monitoringConfig = config.getExtensionByType(MonitoringServiceConfiguration.class);
try {
ConfigSupport.apply(new SingleConfigCode<MonitoringServiceConfiguration>() {
@Override
public Object run(final MonitoringServiceConfiguration monitoringConfigProxy) throws PropertyVetoException, TransactionFailure {
updateConfiguration(monitoringConfigProxy);
updateAttributes(monitoringConfigProxy, actionReport);
actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
return monitoringConfigProxy;
}
}, monitoringConfig);
if (dynamic) {
enableOnTarget(actionReport, context, enabled);
}
} catch (TransactionFailure ex) {
Logger.getLogger(SetMonitoringConfiguration.class.getName()).log(Level.WARNING, "Exception during command " + "set-monitoring-configuration: " + ex.getCause().getMessage());
actionReport.setMessage(ex.getCause().getMessage());
actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
}
}
use of org.jvnet.hk2.config.SingleConfigCode in project Payara by payara.
the class SetZendeskSupportConfigurationCommand method execute.
@Override
public void execute(AdminCommandContext acc) {
Config config = targetUtil.getConfig(target);
ActionReport actionReport = acc.getActionReport();
ZendeskSupportConfiguration zendeskSupportConfiguration = config.getExtensionByType(ZendeskSupportConfiguration.class);
if (zendeskSupportConfiguration != null) {
try {
ConfigSupport.apply(new SingleConfigCode<ZendeskSupportConfiguration>() {
@Override
public Object run(ZendeskSupportConfiguration config) {
if (enabled != null) {
config.setEnabled(Boolean.toString(enabled));
}
if (!Strings.isNullOrEmpty(emailAddress)) {
config.setEmailAddress(emailAddress);
}
return null;
}
}, zendeskSupportConfiguration);
} catch (TransactionFailure ex) {
// Set failure
actionReport.failure(Logger.getLogger(SetZendeskSupportConfigurationCommand.class.getName()), "Failed to update configuration", ex);
}
}
}
Aggregations