use of com.sun.enterprise.config.serverbeans.Resource in project Payara by payara.
the class ManagedThreadFactoryManager method delete.
public ResourceStatus delete(final Resources resources, final String jndiName, final String target) throws Exception {
if (jndiName == null) {
String msg = localStrings.getLocalString("managed.thread.factory.noJndiName", "No JNDI name defined for managed thread factory.");
return new ResourceStatus(ResourceStatus.FAILURE, msg);
}
Resource resource = ConnectorsUtil.getResourceByName(resources, ManagedThreadFactory.class, jndiName);
// ensure we already have this resource
if (resource == null) {
String msg = localStrings.getLocalString("delete.managed.thread.factory.notfound", "A managed thread factory 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.thread.factory.resource-ref.exist", "This managed thread factory [ {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.thread.factory.no.resource-ref", "This managed thread factory [ {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.thread.factory.multiple.resource-refs", "This managed thread factory [ {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-thread-factory
if (ConfigSupport.apply(new SingleConfigCode<Resources>() {
public Object run(Resources param) throws PropertyVetoException, TransactionFailure {
ManagedThreadFactory resource = (ManagedThreadFactory) ConnectorsUtil.getResourceByName(resources, ManagedThreadFactory.class, jndiName);
return param.getResources().remove(resource);
}
}, resources) == null) {
String msg = localStrings.getLocalString("delete.managed.thread.factory.failed", "Managed thread factory {0} deletion failed", jndiName);
return new ResourceStatus(ResourceStatus.FAILURE, msg);
}
} catch (TransactionFailure tfe) {
String msg = localStrings.getLocalString("delete.managed.thread.factory.failed", "Managed thread factory {0} deletion failed ", jndiName);
ResourceStatus status = new ResourceStatus(ResourceStatus.FAILURE, msg);
status.setException(tfe);
return status;
}
String msg = localStrings.getLocalString("delete.managed.thread.factory.success", "Managed thread factory {0} deleted successfully", jndiName);
return new ResourceStatus(ResourceStatus.SUCCESS, msg);
}
use of com.sun.enterprise.config.serverbeans.Resource in project Payara by payara.
the class ConcurrentModificationsTest method collectionTest.
@Test(expected = TransactionFailure.class)
public void collectionTest() throws TransactionFailure {
ServiceLocator habitat = super.getHabitat();
final Resources resources = habitat.<Domain>getService(Domain.class).getResources();
assertTrue(resources != null);
ConfigSupport.apply(new SingleConfigCode<Resources>() {
public Object run(Resources writeableResources) throws PropertyVetoException, TransactionFailure {
assertTrue(writeableResources != null);
JdbcResource newResource = writeableResources.createChild(JdbcResource.class);
newResource.setJndiName("foo");
newResource.setDescription("Random ");
newResource.setPoolName("bar");
newResource.setEnabled("true");
writeableResources.getResources().add(newResource);
// now let's check I have my copy...
boolean found = false;
for (Resource resource : writeableResources.getResources()) {
if (resource instanceof JdbcResource) {
JdbcResource jdbc = (JdbcResource) resource;
if (jdbc.getJndiName().equals("foo")) {
found = true;
break;
}
}
}
assertTrue(found);
// now let's check that my readonly copy does not see it...
boolean shouldNot = false;
for (Resource resource : resources.getResources()) {
if (resource instanceof JdbcResource) {
JdbcResource jdbc = (JdbcResource) resource;
if (jdbc.getJndiName().equals("foo")) {
shouldNot = true;
break;
}
}
}
assertFalse(shouldNot);
// now I am throwing a transaction failure since I don't care about saving it
throw new TransactionFailure("Test passed", null);
}
}, resources);
}
use of com.sun.enterprise.config.serverbeans.Resource in project Payara by payara.
the class ResourcesDeployer method deployResources.
public void deployResources(String applicationName, String moduleName, Collection<com.sun.enterprise.config.serverbeans.Resource> resources, boolean postDeployPhase) throws Exception {
for (Resource resource : resources) {
if (resource instanceof BindableResource) {
BindableResource bindableResource = (BindableResource) resource;
ResourceInfo resourceInfo = new ResourceInfo(bindableResource.getJndiName(), applicationName, moduleName);
if (getResourceDeployer(bindableResource).canDeploy(postDeployPhase, resources, bindableResource)) {
resourcesBinder.deployResource(resourceInfo, bindableResource);
}
} else {
if (getResourceDeployer(resource).canDeploy(postDeployPhase, resources, resource)) {
getResourceDeployer(resource).deployResource(resource, applicationName, moduleName);
}
}
}
}
use of com.sun.enterprise.config.serverbeans.Resource in project Payara by payara.
the class ListJndiResourcesTest method setUp.
@Before
public void setUp() {
habitat = getHabitat();
cr = habitat.getService(CommandRunner.class);
context = new AdminCommandContextImpl(LogDomains.getLogger(ListJndiResourcesTest.class, LogDomains.ADMIN_LOGGER), new PropsFileActionReporter());
parameters = new ParameterMap();
Resources resources = habitat.<Domain>getService(Domain.class).getResources();
for (Resource resource : resources.getResources()) {
if (resource instanceof org.glassfish.resources.config.ExternalJndiResource) {
origNum = origNum + 1;
}
}
}
use of com.sun.enterprise.config.serverbeans.Resource in project Payara by payara.
the class CreateJavaMailResourceTest method testExecuteFailDuplicateResource.
/**
* Test of execute method, of class CreateJavaMailResource.
* asadmin create-javamail-resource --mailuser=test --mailhost=localhost
* --fromaddress=test@sun.com dupRes
* asadmin create-javamail-resource --mailuser=test --mailhost=localhost
* --fromaddress=test@sun.com dupRes
*/
@Test
public void testExecuteFailDuplicateResource() {
parameters.set("mailhost", "localhost");
parameters.set("mailuser", "test");
parameters.set("fromaddress", "test@sun.com");
parameters.set("jndi_name", "dupRes");
org.glassfish.resources.javamail.admin.cli.CreateJavaMailResource command1 = habitat.getService(org.glassfish.resources.javamail.admin.cli.CreateJavaMailResource.class);
assertTrue(command1 != null);
cr.getCommandInvocation("create-javamail-resource", context.getActionReport(), adminSubject()).parameters(parameters).execute(command1);
assertEquals(ActionReport.ExitCode.SUCCESS, context.getActionReport().getActionExitCode());
boolean isCreated = false;
for (Resource resource : resources.getResources()) {
if (resource instanceof MailResource) {
MailResource jr = (MailResource) resource;
if (jr.getJndiName().equals("dupRes")) {
isCreated = true;
logger.fine("MailResource config bean dupRes is created.");
break;
}
}
}
assertTrue(isCreated);
org.glassfish.resources.javamail.admin.cli.CreateJavaMailResource command2 = habitat.getService(org.glassfish.resources.javamail.admin.cli.CreateJavaMailResource.class);
cr.getCommandInvocation("create-javamail-resource", context.getActionReport(), adminSubject()).parameters(parameters).execute(command2);
assertEquals(ActionReport.ExitCode.FAILURE, context.getActionReport().getActionExitCode());
int numDupRes = 0;
for (Resource resource : resources.getResources()) {
if (resource instanceof MailResource) {
MailResource jr = (MailResource) resource;
if (jr.getJndiName().equals("dupRes")) {
numDupRes = numDupRes + 1;
}
}
}
assertEquals(1, numDupRes);
logger.fine("msg: " + context.getActionReport().getMessage());
}
Aggregations