use of org.jvnet.hk2.annotations.Service in project Payara by payara.
the class ManagedExecutorServiceBaseManager method create.
public ResourceStatus create(Resources resources, HashMap attributes, final Properties properties, String target) throws Exception {
setAttributes(attributes, target);
ResourceStatus validationStatus = isValid(resources, true, target);
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);
resourceUtil.createResourceRef(jndiName, enabledValueForTarget, target);
} catch (TransactionFailure tfe) {
String msg = localStrings.getLocalString("create.managed.executor.service.failed", "Managed executor service {0} creation failed", jndiName) + " " + tfe.getLocalizedMessage();
if (getResourceType().equals(ServerTags.MANAGED_SCHEDULED_EXECUTOR_SERVICE)) {
msg = localStrings.getLocalString("create.managed.scheduled.executor.service.failed", "Managed scheduled executor service {0} creation failed", jndiName) + " " + tfe.getLocalizedMessage();
}
ResourceStatus status = new ResourceStatus(ResourceStatus.FAILURE, msg);
status.setException(tfe);
return status;
}
String msg = localStrings.getLocalString("create.managed.executor.service.success", "Managed executor service {0} created successfully", jndiName);
if (getResourceType().equals(ServerTags.MANAGED_SCHEDULED_EXECUTOR_SERVICE)) {
msg = localStrings.getLocalString("create.managed.scheduled.executor.service.success", "Managed scheduled executor service {0} created successfully", jndiName);
}
return new ResourceStatus(ResourceStatus.SUCCESS, msg);
}
use of org.jvnet.hk2.annotations.Service in project Payara by payara.
the class ManagedExecutorServiceBaseManager method delete.
public ResourceStatus delete(final Resources resources, final String jndiName, final String target) throws Exception {
if (jndiName == null) {
String msg = localStrings.getLocalString("managed.executor.service.noJndiName", "No JNDI name defined for managed executor service.");
if (getResourceType().equals(ServerTags.MANAGED_SCHEDULED_EXECUTOR_SERVICE)) {
msg = localStrings.getLocalString("managed.scheduled.executor.service.noJndiName", "No JNDI name defined for managed scheduled executor service.");
}
return new ResourceStatus(ResourceStatus.FAILURE, msg);
}
Resource resource = null;
if (getResourceType().equals(ServerTags.MANAGED_EXECUTOR_SERVICE)) {
resource = ConnectorsUtil.getResourceByName(resources, ManagedExecutorService.class, jndiName);
} else if (getResourceType().equals(ServerTags.MANAGED_SCHEDULED_EXECUTOR_SERVICE)) {
resource = ConnectorsUtil.getResourceByName(resources, ManagedScheduledExecutorService.class, jndiName);
}
// ensure we already have this resource
if (resource == null) {
String msg = localStrings.getLocalString("delete.managed.executor.service.notfound", "A managed executor service named {0} does not exist.", jndiName);
if (getResourceType().equals(ServerTags.MANAGED_SCHEDULED_EXECUTOR_SERVICE)) {
msg = localStrings.getLocalString("delete.managed.scheduled.executor.service.notfound", "A managed scheduled executor service named {0} does not exist.", jndiName);
}
return new ResourceStatus(ResourceStatus.FAILURE, msg);
}
if (SYSTEM_ALL_REQ.equals(resource.getObjectType())) {
String msg = localStrings.getLocalString("delete.concurrent.resource.notAllowed", "The {0} resource cannot be deleted as it is required to be configured in the system.", jndiName);
return new ResourceStatus(ResourceStatus.FAILURE, msg);
}
if (environment.isDas()) {
if ("domain".equals(target)) {
if (resourceUtil.getTargetsReferringResourceRef(jndiName).size() > 0) {
String msg = localStrings.getLocalString("delete.managed.executor.service.resource-ref.exist", "This managed executor service [ {0} ] is referenced in an instance/cluster target, use delete-resource-ref on appropriate target", jndiName);
if (getResourceType().equals(ServerTags.MANAGED_SCHEDULED_EXECUTOR_SERVICE)) {
msg = localStrings.getLocalString("delete.managed.scheduled.executor.service.resource-ref.exist", "This managed scheduled executor service [ {0} ] is referenced in an instance/cluster target, use delete-resource-ref on appropriate target", jndiName);
}
return new ResourceStatus(ResourceStatus.FAILURE, msg);
}
} else {
if (!resourceUtil.isResourceRefInTarget(jndiName, target)) {
String msg = localStrings.getLocalString("delete.managed.executor.service.no.resource-ref", "This managed executor service [ {0} ] is not referenced in target [ {1} ]", jndiName, target);
if (getResourceType().equals(ServerTags.MANAGED_SCHEDULED_EXECUTOR_SERVICE)) {
msg = localStrings.getLocalString("delete.managed.scheduled.executor.service.no.resource-ref", "This managed scheduled executor service [ {0} ] is not referenced in target [ {1} ]", jndiName, target);
}
return new ResourceStatus(ResourceStatus.FAILURE, msg);
}
if (resourceUtil.getTargetsReferringResourceRef(jndiName).size() > 1) {
String msg = localStrings.getLocalString("delete.managed.executor.service.multiple.resource-refs", "This managed executor service [ {0} ] is referenced in multiple instance/cluster targets, Use delete-resource-ref on appropriate target", jndiName);
if (getResourceType().equals(ServerTags.MANAGED_SCHEDULED_EXECUTOR_SERVICE)) {
msg = localStrings.getLocalString("delete.managed.scheduled.executor.service.multiple.resource-refs", "This managed scheduled executor service [ {0} ] is referenced in multiple instance/cluster targets, Use delete-resource-ref on appropriate target", jndiName);
}
return new ResourceStatus(ResourceStatus.FAILURE, msg);
}
}
}
try {
// delete resource-ref
resourceUtil.deleteResourceRef(jndiName, target);
// delete managed executor service
if (ConfigSupport.apply(new SingleConfigCode<Resources>() {
public Object run(Resources param) throws PropertyVetoException, TransactionFailure {
ManagedExecutorServiceBase resource = null;
if (getResourceType().equals(ServerTags.MANAGED_EXECUTOR_SERVICE)) {
resource = (ManagedExecutorService) ConnectorsUtil.getResourceByName(resources, ManagedExecutorService.class, jndiName);
} else {
resource = (ManagedScheduledExecutorService) ConnectorsUtil.getResourceByName(resources, ManagedScheduledExecutorService.class, jndiName);
}
return param.getResources().remove(resource);
}
}, resources) == null) {
String msg = localStrings.getLocalString("delete.managed.executor.service.failed", "Managed executor service {0} deletion failed", jndiName);
if (getResourceType().equals(ServerTags.MANAGED_SCHEDULED_EXECUTOR_SERVICE)) {
msg = localStrings.getLocalString("delete.managed.scheduled.executor.service.failed", "Managed scheduled executor service {0} deletion failed", jndiName);
}
return new ResourceStatus(ResourceStatus.FAILURE, msg);
}
} catch (TransactionFailure tfe) {
String msg = localStrings.getLocalString("delete.managed.executor.service.failed", "Managed executor service {0} deletion failed ", jndiName);
if (getResourceType().equals(ServerTags.MANAGED_SCHEDULED_EXECUTOR_SERVICE)) {
msg = localStrings.getLocalString("delete.managed.scheduled.executor.service.failed", "Managed scheduled executor service {0} deletion failed ", jndiName);
}
ResourceStatus status = new ResourceStatus(ResourceStatus.FAILURE, msg);
status.setException(tfe);
return status;
}
String msg = localStrings.getLocalString("delete.managed.executor.service.success", "Managed executor service {0} deleted successfully", jndiName);
if (getResourceType().equals(ServerTags.MANAGED_SCHEDULED_EXECUTOR_SERVICE)) {
msg = localStrings.getLocalString("delete.managed.scheduled.executor.service.success", "Managed scheduled executor service {0} deleted successfully", jndiName);
}
return new ResourceStatus(ResourceStatus.SUCCESS, msg);
}
use of org.jvnet.hk2.annotations.Service in project Payara by payara.
the class SetEjbInvokerConfigurationCommand method execute.
@Override
public void execute(AdminCommandContext context) {
ActionReport actionReport = context.getActionReport();
Subject subject = context.getSubject();
Config targetConfig = targetUtil.getConfig(target);
EjbInvokerConfiguration config = targetConfig.getExtensionByType(EjbInvokerConfiguration.class);
try {
ConfigSupport.apply(configProxy -> {
if (enabled != null) {
configProxy.setEnabled(enabled.toString());
}
if (endpoint != null) {
configProxy.setEndpoint(endpoint);
}
if (virtualServers != null) {
configProxy.setVirtualServers(virtualServers);
}
if (securityEnabled != null) {
configProxy.setSecurityEnabled(securityEnabled.toString());
}
if (realmName != null) {
configProxy.setRealmName(realmName);
}
if (authType != null) {
configProxy.setAuthType(authType);
}
if (authModule != null) {
configProxy.setAuthModule(authModule);
}
if (authModuleClass != null) {
if (StringUtils.ok(authModuleClass) && authModuleClass.indexOf('.') == -1) {
actionReport.failure(LOGGER, "authModuleClass parameter value must be fully qualified class name.");
}
configProxy.setAuthModuleClass(authModuleClass);
}
if (roles != null) {
configProxy.setRoles(roles);
}
actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
return configProxy;
}, config);
} catch (TransactionFailure ex) {
actionReport.failure(LOGGER, "Failed to update EJB Invoker configuration", ex);
}
if (Boolean.parseBoolean(config.getSecurityEnabled())) {
// If the required message security provider is not present, create it
if (StringUtils.ok(config.getAuthModuleClass())) {
String moduleClass = config.getAuthModuleClass();
String moduleId = moduleClass.substring(moduleClass.lastIndexOf('.') + 1);
ActionReport checkSecurityProviderReport = actionReport.addSubActionsReport();
ActionReport createSecurityProviderReport = actionReport.addSubActionsReport();
if (!messageSecurityProviderExists(moduleId, checkSecurityProviderReport, context.getSubject())) {
createRequiredMessageSecurityProvider(moduleId, moduleClass, createSecurityProviderReport, subject);
}
if (checkSecurityProviderReport.hasFailures() || createSecurityProviderReport.hasFailures()) {
actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
}
// Create the default user if it doesn't exist
if (!StringUtils.ok(config.getRealmName()) || config.getRealmName().equals("file")) {
ActionReport checkUserReport = actionReport.addSubActionsReport();
ActionReport createUserReport = actionReport.addSubActionsReport();
if (!defaultUserExists(config, checkUserReport, subject) && !checkUserReport.hasFailures()) {
createDefaultUser(config, createUserReport, subject);
}
if (checkUserReport.hasFailures() || createUserReport.hasFailures()) {
actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
}
}
if (enabled != null) {
if (enabled) {
enableEjbInvoker(actionReport);
} else {
disableEjbInvoker(actionReport);
}
} else if (Boolean.parseBoolean(config.getEnabled())) {
actionReport.setMessage("Restart server or re-enable the ejb-invoker service for the change to take effect.");
}
// If everything has passed, scrap the subaction reports as we don't want to print them out
if (!actionReport.hasFailures() && !actionReport.hasWarnings()) {
actionReport.getSubActionsReport().clear();
}
}
use of org.jvnet.hk2.annotations.Service 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.annotations.Service in project Payara by payara.
the class MessageSecurityConfigEventListenerImpl method handleCreate.
/**
* @param event Event to be processed.
* @throws AdminEventListenerException when the listener is unable to process the event.
*/
public <T extends ConfigBeanProxy> NotProcessed handleCreate(T instance) {
NotProcessed notProcessed = null;
logger.fine("MessageSecurityConfigEventListenerImpl - handleCreate called");
if (instance instanceof MessageSecurityConfig) {
GFServerConfigProvider.loadConfigContext(service);
} else {
notProcessed = new NotProcessed("unimplemented: unknown instance: " + instance.getClass().getName());
}
return notProcessed;
}
Aggregations