use of com.sun.enterprise.config.serverbeans.Resource in project Payara by payara.
the class ResourcesDeployer method createConfig.
private Collection<Resource> createConfig(Resources resources, Collection<org.glassfish.resources.api.Resource> resourcesToRegister, boolean embedded) throws ResourceException {
List<Resource> resourceConfigs = new ArrayList<Resource>();
for (org.glassfish.resources.api.Resource resource : resourcesToRegister) {
final HashMap attrList = resource.getAttributes();
final Properties props = resource.getProperties();
String desc = resource.getDescription();
if (desc != null) {
attrList.put("description", desc);
}
try {
final ResourceManager rm = resourceFactory.getResourceManager(resource);
if (embedded && isEmbeddedResource(resource, resourcesToRegister)) {
Resource configBeanResource = rm.createConfigBean(resources, attrList, props, false);
resources.getResources().add(configBeanResource);
resourceConfigs.add(configBeanResource);
} else if (!embedded && !isEmbeddedResource(resource, resourcesToRegister)) {
com.sun.enterprise.config.serverbeans.Resource configBeanResource = rm.createConfigBean(resources, attrList, props, true);
resources.getResources().add(configBeanResource);
resourceConfigs.add(configBeanResource);
}
} catch (Exception e) {
throw new ResourceException(e);
}
}
return resourceConfigs;
}
use of com.sun.enterprise.config.serverbeans.Resource in project Payara by payara.
the class ResourcesDeployer method processArchive.
private void processArchive(DeploymentContext dc) {
try {
ReadableArchive archive = dc.getSource();
if (ResourceUtil.hasResourcesXML(archive, locator)) {
Map<String, Map<String, List>> appScopedResources = new HashMap<>();
Map<String, List<String>> jndiNames = new HashMap<>();
List<Map.Entry<String, String>> raNames = new ArrayList<>();
Map<String, String> fileNames = new HashMap<>();
String appName = getAppNameFromDeployCmdParams(dc);
// 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("Sun 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 list = parser.getResourcesList();
Map<String, List> resourcesList = new HashMap<>();
List<String> jndiNamesList = new ArrayList<>();
List<org.glassfish.resources.api.Resource> nonConnectorResources = ResourcesXMLParser.getNonConnectorResourcesList(list, false, true);
resourcesList.put(NON_CONNECTOR_RESOURCES, nonConnectorResources);
for (org.glassfish.resources.api.Resource resource : nonConnectorResources) {
String jndiName = extractJNDIName(resource);
if (hasRAName(resource)) {
raNames.add(new AbstractMap.SimpleEntry<>(extractRAName(resource), resource.getType()));
}
if (jndiName != null) {
jndiNamesList.add(jndiName);
}
}
List<org.glassfish.resources.api.Resource> connectorResources = ResourcesXMLParser.getConnectorResourcesList(list, false, true);
resourcesList.put(CONNECTOR_RESOURCES, connectorResources);
for (org.glassfish.resources.api.Resource resource : connectorResources) {
String jndiName = extractJNDIName(resource);
if (hasRAName(resource)) {
raNames.add(new AbstractMap.SimpleEntry<>(extractRAName(resource), resource.getType()));
}
if (jndiName != null) {
jndiNamesList.add(jndiName);
}
}
jndiNames.put(moduleName, jndiNamesList);
appScopedResources.put(moduleName, resourcesList);
}
dc.addTransientAppMetaData(APP_SCOPED_RESOURCES_JNDI_NAMES, jndiNames);
dc.addTransientAppMetaData(APP_SCOPED_RESOURCES_RA_NAMES, raNames);
dc.addTransientAppMetaData(APP_SCOPED_RESOURCES_MAP, appScopedResources);
ApplicationInfo appInfo = appRegistry.get(appName);
if (appInfo != null) {
Application app = dc.getTransientAppMetaData(ServerTags.APPLICATION, Application.class);
appInfo.addTransientAppMetaData(ServerTags.APPLICATION, app);
}
}
} 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 ResourcesDeployer method validatePreservedResources.
/**
* Validates the old resource configuration against new archive's modules.
* @param allResources all resources (app scoped, module scoped)
* @param oldApp Old Application config
* @param newApp New Applicatoin config
* @throws org.glassfish.resourcebase.resources.api.ResourceConflictException when it is not possible to map any of the resource(s) to
* new application/its modules
*/
private void validatePreservedResources(Map<String, Resources> allResources, Application oldApp, Application newApp) throws ResourceConflictException {
String appName = newApp.getName();
Resources appScopedResources = allResources.get(appName);
if (appScopedResources != null) {
for (Resource resource : appScopedResources.getResources()) {
getResourceDeployer(resource).validatePreservedResource(oldApp, newApp, resource, appScopedResources);
}
}
List<Module> newModules = newApp.getModule();
for (Module newModule : newModules) {
Module oldModule = oldApp.getModule(newModule.getName());
if (oldModule != null) {
Resources oldModuleResources = oldModule.getResources();
if (oldModuleResources != null) {
for (Resource resource : oldModuleResources.getResources()) {
getResourceDeployer(resource).validatePreservedResource(oldApp, newApp, resource, oldModuleResources);
}
}
}
// else its a new module in the archive being redeployed.
}
}
use of com.sun.enterprise.config.serverbeans.Resource in project Payara by payara.
the class CreateJavaMailResourceTest method testExecuteSuccess.
/**
* Test of execute method, of class CreateJavaMailResource.
* asadmin create-javamail-resource --mailuser=test --mailhost=localhost
* --fromaddress=test@sun.com mail/MyMailSession
*/
@Test
public void testExecuteSuccess() {
parameters.set("mailhost", "localhost");
parameters.set("mailuser", "test");
parameters.set("fromaddress", "test@sun.com");
parameters.set("jndi_name", "mail/MyMailSession");
org.glassfish.resources.javamail.admin.cli.CreateJavaMailResource command = habitat.getService(org.glassfish.resources.javamail.admin.cli.CreateJavaMailResource.class);
assertTrue(command != null);
cr.getCommandInvocation("create-javamail-resource", context.getActionReport(), adminSubject()).parameters(parameters).execute(command);
assertEquals(ActionReport.ExitCode.SUCCESS, context.getActionReport().getActionExitCode());
boolean isCreated = false;
for (Resource resource : resources.getResources()) {
if (resource instanceof MailResource) {
MailResource r = (MailResource) resource;
if (r.getJndiName().equals("mail/MyMailSession")) {
assertEquals("localhost", r.getHost());
assertEquals("test", r.getUser());
assertEquals("test@sun.com", r.getFrom());
assertEquals("true", r.getEnabled());
assertEquals("false", r.getDebug());
assertEquals("imap", r.getStoreProtocol());
assertEquals("com.sun.mail.imap.IMAPStore", r.getStoreProtocolClass());
assertEquals("smtp", r.getTransportProtocol());
assertEquals("com.sun.mail.smtp.SMTPTransport", r.getTransportProtocolClass());
isCreated = true;
logger.fine("MailResource config bean mail/MyMailSession is created.");
break;
}
}
}
assertTrue(isCreated);
logger.fine("msg: " + context.getActionReport().getMessage());
Servers servers = habitat.getService(Servers.class);
boolean isRefCreated = false;
for (Server server : servers.getServer()) {
if (server.getName().equals(SystemPropertyConstants.DEFAULT_SERVER_INSTANCE_NAME)) {
for (ResourceRef ref : server.getResourceRef()) {
if (ref.getRef().equals("mail/MyMailSession")) {
assertEquals("true", ref.getEnabled());
isRefCreated = true;
break;
}
}
}
}
assertTrue(isRefCreated);
}
use of com.sun.enterprise.config.serverbeans.Resource in project Payara by payara.
the class DeleteJavaMailResourceTest method testExecuteSuccessDefaultTarget.
/**
* Test of execute method, of class DeleteJavaMailResource.
* asadmin create-javamail-resource --mailuser=test --mailhost=localhost
* --fromaddress=test@sun.com mail/MyMailSession
* delete-javamail-resource mail/MyMailSession
*/
@Test
public void testExecuteSuccessDefaultTarget() {
parameters.set("mailhost", "localhost");
parameters.set("mailuser", "test");
parameters.set("fromaddress", "test@sun.com");
parameters.set("jndi_name", "mail/MyMailSession");
org.glassfish.resources.javamail.admin.cli.CreateJavaMailResource createCommand = habitat.getService(org.glassfish.resources.javamail.admin.cli.CreateJavaMailResource.class);
assertTrue(createCommand != null);
cr.getCommandInvocation("create-javamail-resource", context.getActionReport(), adminSubject()).parameters(parameters).execute(createCommand);
assertEquals(ActionReport.ExitCode.SUCCESS, context.getActionReport().getActionExitCode());
parameters = new ParameterMap();
parameters.set("jndi_name", "mail/MyMailSession");
org.glassfish.resources.javamail.admin.cli.DeleteJavaMailResource deleteCommand = habitat.getService(org.glassfish.resources.javamail.admin.cli.DeleteJavaMailResource.class);
assertTrue(deleteCommand != null);
cr.getCommandInvocation("delete-javamail-resource", context.getActionReport(), adminSubject()).parameters(parameters).execute(deleteCommand);
assertEquals(ActionReport.ExitCode.SUCCESS, context.getActionReport().getActionExitCode());
boolean isDeleted = true;
for (Resource resource : resources.getResources()) {
if (resource instanceof MailResource) {
MailResource jr = (MailResource) resource;
if (jr.getJndiName().equals("mail/MyMailSession")) {
isDeleted = false;
logger.fine("JavaMailResource config bean mail/MyMailSession is deleted.");
break;
}
}
}
assertTrue(isDeleted);
logger.fine("msg: " + context.getActionReport().getMessage());
assertEquals(ActionReport.ExitCode.SUCCESS, context.getActionReport().getActionExitCode());
Servers servers = habitat.getService(Servers.class);
boolean isRefDeleted = true;
for (Server server : servers.getServer()) {
if (server.getName().equals(SystemPropertyConstants.DEFAULT_SERVER_INSTANCE_NAME)) {
for (ResourceRef ref : server.getResourceRef()) {
if (ref.getRef().equals("mail/MyMailSession")) {
isRefDeleted = false;
break;
}
}
}
}
assertTrue(isRefDeleted);
}
Aggregations