use of org.glassfish.concurrent.config.ContextService in project Payara by payara.
the class ListContextServices 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();
try {
Collection<ContextService> contextServices = domain.getResources().getResources(ContextService.class);
List<Map<String, String>> resourcesList = new ArrayList<Map<String, String>>();
List<DefaultResourceProxy> drps = habitat.getAllServices(DefaultResourceProxy.class);
for (ContextService contextService : contextServices) {
String jndiName = contextService.getJndiName();
if (bindableResourcesHelper.resourceExists(jndiName, target)) {
ActionReport.MessagePart part = report.getTopMessagePart().addChild();
part.setMessage(jndiName);
Map<String, String> resourceNameMap = new HashMap<String, String>();
String logicalName = DefaultResourceProxy.Util.getLogicalName(drps, jndiName);
if (logicalName != null) {
resourceNameMap.put("logical-jndi-name", logicalName);
}
resourceNameMap.put("name", jndiName);
resourcesList.add(resourceNameMap);
}
}
Properties extraProperties = new Properties();
extraProperties.put("contextServices", resourcesList);
report.setExtraProperties(extraProperties);
} catch (Exception e) {
report.setMessage(localStrings.getLocalString("list.context.service.failed", "List context services failed"));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setFailureCause(e);
return;
}
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
use of org.glassfish.concurrent.config.ContextService in project Payara by payara.
the class ContextServiceDeployer method deployResource.
@Override
public void deployResource(Object resource, String applicationName, String moduleName) throws Exception {
ContextService contextServiceRes = (ContextService) resource;
if (contextServiceRes == null) {
_logger.log(Level.WARNING, LogFacade.DEPLOY_ERROR_NULL_CONFIG, "ContextService");
return;
}
String jndiName = contextServiceRes.getJndiName();
String contextInfo = contextServiceRes.getContextInfo();
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, "ContextServiceDeployer.deployResource() : jndi-name [" + jndiName + "], " + " context-info [" + contextInfo + "]");
}
ResourceInfo resourceInfo = new ResourceInfo(contextServiceRes.getJndiName(), applicationName, moduleName);
ContextServiceConfig config = new ContextServiceConfig(contextServiceRes);
javax.naming.Reference ref = new javax.naming.Reference(javax.enterprise.concurrent.ContextService.class.getName(), "org.glassfish.concurrent.runtime.deployer.ConcurrentObjectFactory", null);
RefAddr addr = new SerializableObjectRefAddr(ContextServiceConfig.class.getName(), config);
ref.add(addr);
RefAddr resAddr = new SerializableObjectRefAddr(ResourceInfo.class.getName(), resourceInfo);
ref.add(resAddr);
try {
// Publish the object ref
namingService.publishObject(resourceInfo, ref, true);
} catch (NamingException ex) {
LogHelper.log(_logger, Level.SEVERE, LogFacade.UNABLE_TO_BIND_OBJECT, ex, "ContextService", jndiName);
}
}
use of org.glassfish.concurrent.config.ContextService in project Payara by payara.
the class ContextServiceDeployer method undeployResource.
@Override
public void undeployResource(Object resource) throws Exception {
ContextService contextServiceResource = (ContextService) resource;
ResourceInfo resourceInfo = ResourceUtil.getResourceInfo(contextServiceResource);
undeployResource(resource, resourceInfo.getApplicationName(), resourceInfo.getModuleName());
}
use of org.glassfish.concurrent.config.ContextService in project Payara by payara.
the class ContextServiceManager method delete.
public ResourceStatus delete(final Resources resources, final String jndiName, final String target) throws Exception {
if (jndiName == null) {
String msg = localStrings.getLocalString("context.service.noJndiName", "No JNDI name defined for context service.");
return new ResourceStatus(ResourceStatus.FAILURE, msg);
}
Resource resource = ConnectorsUtil.getResourceByName(resources, ContextService.class, jndiName);
// ensure we already have this resource
if (resource == null) {
String msg = localStrings.getLocalString("delete.context.service.notfound", "A context 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.context.service.resource-ref.exist", "This context 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.context.service.no.resource-ref", "This context 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.context.service.multiple.resource-refs", "This context 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 context-service
if (ConfigSupport.apply(new SingleConfigCode<Resources>() {
public Object run(Resources param) throws PropertyVetoException, TransactionFailure {
ContextService resource = (ContextService) ConnectorsUtil.getResourceByName(resources, ContextService.class, jndiName);
return param.getResources().remove(resource);
}
}, resources) == null) {
String msg = localStrings.getLocalString("delete.context.service.failed", "Context service {0} deletion failed", jndiName);
return new ResourceStatus(ResourceStatus.FAILURE, msg);
}
} catch (TransactionFailure tfe) {
String msg = localStrings.getLocalString("delete.context.service.failed", "Context service {0} deletion failed ", jndiName);
ResourceStatus status = new ResourceStatus(ResourceStatus.FAILURE, msg);
status.setException(tfe);
return status;
}
String msg = localStrings.getLocalString("delete.context.service.success", "Context service {0} deleted successfully", jndiName);
return new ResourceStatus(ResourceStatus.SUCCESS, msg);
}
use of org.glassfish.concurrent.config.ContextService in project Payara by payara.
the class ContextServiceManager method createConfigBean.
private ContextService createConfigBean(Resources param, Properties properties) throws PropertyVetoException, TransactionFailure {
ContextService contextService = param.createChild(ContextService.class);
contextService.setJndiName(jndiName);
if (description != null) {
contextService.setDescription(description);
}
contextService.setContextInfoEnabled(contextInfoEnabled);
contextService.setContextInfo(contextInfo);
contextService.setEnabled(enabled);
if (properties != null) {
for (Map.Entry e : properties.entrySet()) {
Property prop = contextService.createChild(Property.class);
prop.setName((String) e.getKey());
prop.setValue((String) e.getValue());
contextService.getProperty().add(prop);
}
}
return contextService;
}
Aggregations