use of com.sun.enterprise.config.serverbeans.Resource in project Payara by payara.
the class ResourcesDeployer method getResources.
/**
* Retrieve connector and non-connector resources from the archive.
*
* @param archive Archieve from which the resources to be retrieved.
* @param appName Name of the application
* @param connectorResources Connector resources will be added to this list.
* @param nonConnectorResources Non connector resources will be added to this list.
* @param resourceXmlParsers Resource xml parsers corresponding to both connector and non connector resources will be stored in this.
*/
public void getResources(ReadableArchive archive, String appName, List<org.glassfish.resources.api.Resource> connectorResources, List<org.glassfish.resources.api.Resource> nonConnectorResources, Map<org.glassfish.resources.api.Resource, ResourcesXMLParser> resourceXmlParsers) {
try {
if (ResourceUtil.hasResourcesXML(archive, locator)) {
Map<String, Map<String, List>> appScopedResources = new HashMap<String, Map<String, List>>();
Map<String, String> fileNames = new HashMap<String, String>();
// using appName as it is possible that "deploy --name=APPNAME" will
// be different than the archive name.
retrieveAllResourcesXMLs(fileNames, archive, appName);
for (Map.Entry<String, String> entry : fileNames.entrySet()) {
String moduleName = entry.getKey();
String fileName = entry.getValue();
debug("GlassFish Resources XML : " + fileName);
moduleName = org.glassfish.resourcebase.resources.util.ResourceUtil.getActualModuleNameWithExtension(moduleName);
String scope;
if (appName.equals(moduleName)) {
scope = JAVA_APP_SCOPE_PREFIX;
} else {
scope = JAVA_MODULE_SCOPE_PREFIX;
}
File file = new File(fileName);
ResourcesXMLParser parser = new ResourcesXMLParser(file, scope);
validateResourcesXML(file, parser);
List<org.glassfish.resources.api.Resource> resources = parser.getResourcesList();
if (nonConnectorResources != null) {
nonConnectorResources.addAll(ResourcesXMLParser.getNonConnectorResourcesList(resources, false, true));
}
if (connectorResources != null) {
connectorResources.addAll(ResourcesXMLParser.getConnectorResourcesList(resources, false, true));
}
if (resourceXmlParsers != null) {
for (org.glassfish.resources.api.Resource res : resources) {
resourceXmlParsers.put(res, parser);
}
}
}
}
} catch (Exception e) {
// in the event notification infrastructure
throw new DeploymentException("Failue while processing glassfish-resources.xml(s) in the archive ", e);
}
}
use of com.sun.enterprise.config.serverbeans.Resource in project Payara by payara.
the class JdbcRuntimeExtension method getDeferredResourceConfig.
@Override
public DeferredResourceConfig getDeferredResourceConfig(Object resource, Object pool, String resType, String raName) throws ConnectorRuntimeException {
String resourceAdapterName;
DeferredResourceConfig resConfig = null;
// TODO V3 (not to hold specific resource types)
if (resource instanceof JdbcResource || pool instanceof JdbcConnectionPool) {
JdbcConnectionPool jdbcPool = (JdbcConnectionPool) pool;
JdbcResource jdbcResource = (JdbcResource) resource;
resourceAdapterName = getRANameofJdbcConnectionPool((JdbcConnectionPool) pool);
resConfig = new DeferredResourceConfig(resourceAdapterName, null, jdbcPool, jdbcResource, null);
Resource[] resourcesToload = new Resource[] { jdbcPool, jdbcResource };
resConfig.setResourcesToLoad(resourcesToload);
} else {
throw new ConnectorRuntimeException("unsupported resource type : " + resource);
}
return resConfig;
}
use of com.sun.enterprise.config.serverbeans.Resource in project Payara by payara.
the class DeleteJMSResource 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
*/
@Override
public void execute(AdminCommandContext context) {
final ActionReport report = context.getActionReport();
if (jndiName == null) {
report.setMessage(localStrings.getLocalString("delete.jms.resource.noJndiName", "No JNDI name defined for JMS Resource."));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
jndiNameForConnectionPool = jndiName + JNDINAME_APPENDER;
ActionReport subReport = report.addSubActionsReport();
ConnectorResource cresource = null;
Resource res = ConnectorsUtil.getResourceByName(domain.getResources(), ConnectorResource.class, jndiName);
if (res instanceof ConnectorResource) {
cresource = (ConnectorResource) res;
}
/* for (ConnectorResource cr : connResources) {
if (cr.getJndiName().equals(jndiName))
cresource = cr;
} */
if (cresource == null) {
ParameterMap params = new ParameterMap();
params.set("jndi_name", jndiName);
params.set("DEFAULT", jndiName);
params.set("target", target);
commandRunner.getCommandInvocation("delete-admin-object", subReport, context.getSubject()).parameters(params).execute();
if (ActionReport.ExitCode.FAILURE.equals(subReport.getActionExitCode())) {
report.setMessage(localStrings.getLocalString("delete.jms.resource.cannotDeleteJMSAdminObject", "Unable to Delete Admin Object."));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
} else {
if (!cascade) {
Collection<ConnectorResource> connectorResources = domain.getResources().getResources(ConnectorResource.class);
String connPoolName = jndiName + JNDINAME_APPENDER;
int count = 0;
for (ConnectorResource resource : connectorResources) {
if (connPoolName.equals(resource.getPoolName())) {
count++;
if (count > 1)
break;
}
}
if (count > 1) {
report.setMessage(localStrings.getLocalString("found.more.connector.resources", "Some connector resources are referencing connection pool {0}. Use 'cascade' option to delete them", connPoolName));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
}
ActionReport listReport = habitat.getService(ActionReport.class);
ParameterMap listParams = new ParameterMap();
listParams.set("target", target);
commandRunner.getCommandInvocation("list-jms-resources", listReport, context.getSubject()).parameters(listParams).execute();
if (ActionReport.ExitCode.FAILURE.equals(listReport.getActionExitCode())) {
report.setMessage(localStrings.getLocalString("list.jms.resources.fail", "Unable to list JMS Resources"));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
Properties extraProps = listReport.getExtraProperties();
if (extraProps != null && extraProps.size() > 0) {
boolean resourceExist = false;
for (int i = 0; i < extraProps.size(); i++) {
List<Map<String, String>> nameList = (List) extraProps.get("jmsResources");
for (Map<String, String> m : nameList) {
String jndi = (String) m.get("name");
if (jndiName.equals(jndi)) {
resourceExist = true;
break;
}
}
if (resourceExist)
break;
}
if (!resourceExist) {
report.setMessage(localStrings.getLocalString("jms.resources.not.found", "JMS Resource {0} not found", jndiName));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
}
// Delete the connector resource and connector connection pool
String defPoolName = jndiNameForConnectionPool;
String poolName = cresource.getPoolName();
if (poolName != null && poolName.equals(defPoolName)) {
ParameterMap params = new ParameterMap();
params.set("DEFAULT", jndiName);
params.set("connector_resource_name", jndiName);
params.set("target", target);
commandRunner.getCommandInvocation("delete-connector-resource", subReport, context.getSubject()).parameters(params).execute();
if (ActionReport.ExitCode.FAILURE.equals(subReport.getActionExitCode())) {
report.setMessage(localStrings.getLocalString("delete.jms.resource.cannotDeleteJMSResource", "Unable to Delete Connector Resource."));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
params = new ParameterMap();
params.set("poolname", jndiName);
params.set("cascade", cascade.toString());
params.set("DEFAULT", jndiNameForConnectionPool);
commandRunner.getCommandInvocation("delete-connector-connection-pool", subReport, context.getSubject()).parameters(params).execute();
if (ActionReport.ExitCode.FAILURE.equals(subReport.getActionExitCode())) {
report.setMessage(localStrings.getLocalString("delete.jms.resource.cannotDeleteJMSPool", "Unable to Delete Connector Connection Pool."));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
// clear the message set by the delete-connector-connection-pool command this is to prevent the 'connection pool deleted' message from displaying
subReport.setMessage("");
} else {
// There is no connector pool with the default poolName.
// However, no need to throw exception as the connector
// resource might still be there. Try to delete the
// connector-resource without touching the ref. as
// ref. might have been deleted while deleting connector-connection-pool
// as the ref. is the same.
ParameterMap params = new ParameterMap();
params.set("DEFAULT", jndiName);
params.set("connector_resource_name", jndiName);
params.set("target", target);
commandRunner.getCommandInvocation("delete-connector-resource", subReport, context.getSubject()).parameters(params).execute();
if (ActionReport.ExitCode.FAILURE.equals(subReport.getActionExitCode())) {
report.setMessage(localStrings.getLocalString("delete.jms.resource.cannotDeleteJMSResource", "Unable to Delete Connector Resource."));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
}
}
ActionReport.ExitCode ec = ActionReport.ExitCode.SUCCESS;
report.setActionExitCode(ec);
}
use of com.sun.enterprise.config.serverbeans.Resource in project Payara by payara.
the class UniqueResourceNameValidator method isValid.
@Override
public boolean isValid(final Resource resource, final ConstraintValidatorContext constraintValidatorContext) {
if (domain != null) {
if (resource.getParent().getParent() instanceof Domain) {
for (Resource res : domain.getResources().getResources()) {
if (resource.getIdentity().equals(res.getIdentity())) {
Class[] resourceInterfaces = resource.getClass().getInterfaces();
Class[] resInterfaces = res.getClass().getInterfaces();
for (Class resourceClass : resourceInterfaces) {
for (Class resClass : resInterfaces) {
if (resClass.getName().equals(resourceClass.getName())) {
return true;
}
}
}
return false;
}
}
}
}
return true;
}
Aggregations