use of org.glassfish.batch.spi.impl.BatchRuntimeConfiguration 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.batch.spi.impl.BatchRuntimeConfiguration in project Payara by payara.
the class ListBatchRuntimeConfiguration method executeCommand.
@Override
protected void executeCommand(AdminCommandContext context, Properties extraProps) {
Config config = targetUtil.getConfig(target);
if (config == null) {
context.getActionReport().setMessage("No such config named: " + target);
context.getActionReport().setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
BatchRuntimeConfiguration batchRuntimeConfiguration = config.getExtensionByType(BatchRuntimeConfiguration.class);
Map<String, Object> map = new HashMap<>();
map.put(DATA_SOURCE_NAME, batchRuntimeConfiguration.getDataSourceLookupName());
map.put(EXECUTOR_SERVICE_NAME, batchRuntimeConfiguration.getExecutorServiceLookupName());
map.put(SCHEMA_NAME, batchRuntimeConfiguration.getSchemaName());
map.put(TABLE_PREFIX, batchRuntimeConfiguration.getTablePrefix());
map.put(TABLE_SUFFIX, batchRuntimeConfiguration.getTableSuffix());
extraProps.put("listBatchRuntimeConfiguration", map);
ColumnFormatter columnFormatter = new ColumnFormatter(getDisplayHeaders());
Object[] data = new Object[getOutputHeaders().length];
for (int index = 0; index < getOutputHeaders().length; index++) {
switch(getOutputHeaders()[index]) {
case DATA_SOURCE_NAME:
String val = batchRuntimeConfiguration.getDataSourceLookupName();
data[index] = (val == null || val.trim().length() == 0) ? BatchRuntimeHelper.getDefaultDataSourceLookupNameForTarget(target) : val;
break;
case EXECUTOR_SERVICE_NAME:
data[index] = batchRuntimeConfiguration.getExecutorServiceLookupName();
break;
case SCHEMA_NAME:
data[index] = batchRuntimeConfiguration.getSchemaName();
break;
case TABLE_PREFIX:
data[index] = batchRuntimeConfiguration.getTablePrefix();
break;
case TABLE_SUFFIX:
data[index] = batchRuntimeConfiguration.getTableSuffix();
break;
default:
throw new IllegalArgumentException("Unknown header: " + getOutputHeaders()[index]);
}
}
columnFormatter.addRow(data);
context.getActionReport().setMessage(columnFormatter.toString());
}
Aggregations