use of org.glassfish.api.ActionReport 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.glassfish.api.ActionReport in project Payara by payara.
the class DeleteJavaMailResource 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();
// ensure we already have this resource
if (!isResourceExists(domain.getResources(), jndiName)) {
report.setMessage(localStrings.getLocalString("delete.mail.resource.notfound", "A Mail resource named {0} does not exist.", jndiName));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
if (environment.isDas()) {
if ("domain".equals(target)) {
if (resourceUtil.getTargetsReferringResourceRef(jndiName).size() > 0) {
report.setMessage(localStrings.getLocalString("delete.mail.resource.resource-ref.exist", "mail-resource [ {0} ] is referenced in an" + "instance/cluster target, Use delete-resource-ref on appropriate target", jndiName));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
} else {
if (!resourceUtil.isResourceRefInTarget(jndiName, target)) {
report.setMessage(localStrings.getLocalString("delete.mail.resource.no.resource-ref", "mail-resource [ {0} ] is not referenced in target [ {1} ]", jndiName, target));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
if (resourceUtil.getTargetsReferringResourceRef(jndiName).size() > 1) {
report.setMessage(localStrings.getLocalString("delete.mail.resource.multiple.resource-refs", "mail-resource [ {0} ] is referenced in multiple " + "instance/cluster targets, Use delete-resource-ref on appropriate target", jndiName));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
}
}
try {
// delete resource-ref
resourceUtil.deleteResourceRef(jndiName, target);
// delete java-mail-resource
ConfigSupport.apply(new SingleConfigCode<Resources>() {
public Object run(Resources param) throws PropertyVetoException, TransactionFailure {
MailResource resource = (MailResource) ResourceUtil.getBindableResourceByName(domain.getResources(), jndiName);
return param.getResources().remove(resource);
}
}, domain.getResources());
report.setMessage(localStrings.getLocalString("delete.mail.resource.success", "Mail resource {0} deleted", jndiName));
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
} catch (TransactionFailure tfe) {
report.setMessage(localStrings.getLocalString("delete.mail.resource.failed", "Unable to delete mail resource {0}", jndiName) + " " + tfe.getLocalizedMessage());
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setFailureCause(tfe);
}
}
use of org.glassfish.api.ActionReport in project Payara by payara.
the class ListJavaMailResources 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();
try {
List<String> list = new ArrayList<String>();
Collection<MailResource> mailResources = domain.getResources().getResources(MailResource.class);
for (MailResource mailResource : mailResources) {
if (bindableResourcesHelper.resourceExists(mailResource.getJndiName(), targetOperand)) {
list.add(mailResource.getJndiName());
}
}
for (String jndiName : list) {
final ActionReport.MessagePart part = report.getTopMessagePart().addChild();
part.setMessage(jndiName);
}
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
} catch (Exception e) {
report.setMessage(localStrings.getLocalString("list.javamail.resources.failed", "Unable to list mail resources") + " " + e.getLocalizedMessage());
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setFailureCause(e);
}
}
use of org.glassfish.api.ActionReport in project Payara by payara.
the class CreateJndiResource method execute.
/**
* Executes the command with the command parameters passed as Properties
* where the keys are the parameter names and the values the parameter values
*
* @param context information
*/
public void execute(AdminCommandContext context) {
final ActionReport report = context.getActionReport();
HashMap attrList = new HashMap();
attrList.put(FACTORY_CLASS, factoryClass);
attrList.put(RES_TYPE, resType);
attrList.put(JNDI_LOOKUP, jndiLookupName);
attrList.put(ENABLED, enabled.toString());
attrList.put(JNDI_NAME, jndiName);
attrList.put(ServerTags.DESCRIPTION, description);
ResourceStatus rs;
try {
rs = jndiResManager.create(domain.getResources(), attrList, properties, target);
} catch (Exception e) {
Logger.getLogger(CreateJndiResource.class.getName()).log(Level.SEVERE, "Unable to create jndi resource " + jndiName, e);
String def = "jndi resource: {0} could not be created, reason: {1}";
report.setMessage(localStrings.getLocalString("create.jndi.resource.fail", def, jndiName) + " " + e.getLocalizedMessage());
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setFailureCause(e);
return;
}
ActionReport.ExitCode ec = ActionReport.ExitCode.SUCCESS;
if (rs.getStatus() == ResourceStatus.FAILURE) {
ec = ActionReport.ExitCode.FAILURE;
if (rs.getMessage() == null) {
report.setMessage(localStrings.getLocalString("create.jndi.resource.fail", "jndi resource {0} creation failed", jndiName, ""));
}
if (rs.getException() != null)
report.setFailureCause(rs.getException());
}
if (rs.getMessage() != null) {
report.setMessage(rs.getMessage());
}
report.setActionExitCode(ec);
}
use of org.glassfish.api.ActionReport in project Payara by payara.
the class ListJndiResources 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();
try {
List<String> list = new ArrayList<String>();
Collection<ExternalJndiResource> jndiResources = domain.getResources().getResources(ExternalJndiResource.class);
for (ExternalJndiResource jndiResource : jndiResources) {
if (bindableResourcesHelper.resourceExists(jndiResource.getJndiName(), targetOperand)) {
list.add(jndiResource.getJndiName());
}
}
for (String jndiName : list) {
final ActionReport.MessagePart part = report.getTopMessagePart().addChild();
part.setMessage(jndiName);
}
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
} catch (Exception e) {
report.setMessage(localStrings.getLocalString("" + "list.jndi.resources.fail", "Unable to list jndi resources.") + " " + e.getLocalizedMessage());
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setFailureCause(e);
}
}
Aggregations