use of com.sun.enterprise.config.serverbeans.Resources 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.Resources in project Payara by payara.
the class ManagedConnectionImpl method getJdbcConnectionPool.
private JdbcConnectionPool getJdbcConnectionPool(javax.resource.spi.ManagedConnectionFactory mcf) {
if (Globals.getDefaultHabitat().getService(ProcessEnvironment.class).getProcessType() != ProcessEnvironment.ProcessType.Server) {
// otherwise we bave no domain to draw upon
return null;
}
JdbcConnectionPool jdbcConnectionPool = null;
ManagedConnectionFactoryImpl spiMCF = (ManagedConnectionFactoryImpl) mcf;
Resources resources = Globals.getDefaultHabitat().getService(Domain.class).getResources();
ResourcePool pool = (ResourcePool) ConnectorsUtil.getResourceByName(resources, ResourcePool.class, spiMCF.getPoolName());
if (pool instanceof JdbcConnectionPool) {
jdbcConnectionPool = (JdbcConnectionPool) pool;
}
return jdbcConnectionPool;
}
use of com.sun.enterprise.config.serverbeans.Resources in project Payara by payara.
the class JdbcResourceDeployer method checkAndDeletePool.
/**
* Checks if no more resource-refs to resources exists for the
* JDBC connection pool and then deletes the pool
*
* @param cr Jdbc Resource Config bean
* @throws Exception if unable to access configuration/undeploy resource.
* @since 8.1 pe/se/ee
*/
private void checkAndDeletePool(JdbcResource cr) throws Exception {
String poolName = cr.getPoolName();
ResourceInfo resourceInfo = ConnectorsUtil.getResourceInfo(cr);
PoolInfo poolInfo = new PoolInfo(poolName, resourceInfo.getApplicationName(), resourceInfo.getModuleName());
Resources resources = (Resources) cr.getParent();
// Its possible that the JdbcResource here is a DataSourceDefinition. Ignore optimization.
if (resources != null) {
try {
boolean poolReferred = JdbcResourcesUtil.createInstance().isJdbcPoolReferredInServerInstance(poolInfo);
if (!poolReferred) {
if (_logger.isLoggable(Level.FINE)) {
_logger.fine("Deleting JDBC pool [" + poolName + " ] as there are no more " + "resource-refs to the pool in this server instance");
}
JdbcConnectionPool jcp = (JdbcConnectionPool) ConnectorsUtil.getResourceByName(resources, JdbcConnectionPool.class, poolName);
// Delete/Undeploy Pool
runtime.getResourceDeployer(jcp).undeployResource(jcp);
}
} catch (Exception ce) {
_logger.warning(ce.getMessage());
if (_logger.isLoggable(Level.FINE)) {
_logger.fine("Exception while deleting pool [ " + poolName + " ] : " + ce);
}
throw ce;
}
}
}
use of com.sun.enterprise.config.serverbeans.Resources 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.Resources in project Payara by payara.
the class DeleteCustomResource method execute.
/**
* Executes the command with the command parameters passed as Properties
* where the keys are the paramter names and the values the parameter values
*
* @param context information
*/
public void execute(AdminCommandContext context) {
final ActionReport report = context.getActionReport();
// ensure we already have this resource
if (domain.getResources().getResourceByName(CustomResource.class, jndiName) == null) {
report.setMessage(localStrings.getLocalString("delete.custom.resource.notfound", "A custom resource named {0} does not exist.", jndiName));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
if (environment.isDas()) {
if ("domain".equals(target)) {
if (resourceUtil.getTargetsReferringResourceRef(jndiName).size() > 0) {
report.setMessage(localStrings.getLocalString("delete.custom.resource.resource-ref.exist", "custom-resource [ {0} ] is referenced in an" + "instance/cluster target, Use delete-resource-ref on appropriate target", jndiName));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
} else {
if (!resourceUtil.isResourceRefInTarget(jndiName, target)) {
report.setMessage(localStrings.getLocalString("delete.custom.resource.no.resource-ref", "custom-resource [ {0} ] is not referenced in target [ {1} ]", jndiName, target));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
if (resourceUtil.getTargetsReferringResourceRef(jndiName).size() > 1) {
report.setMessage(localStrings.getLocalString("delete.custom.resource.multiple.resource-refs", "custom-resource [ {0} ] is referenced in multiple " + "instance/cluster targets, Use delete-resource-ref on appropriate target", jndiName));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
}
}
try {
// delete resource-ref
resourceUtil.deleteResourceRef(jndiName, target);
// delete custom-resource
ConfigSupport.apply(new SingleConfigCode<Resources>() {
public Object run(Resources param) throws PropertyVetoException, TransactionFailure {
CustomResource resource = (CustomResource) domain.getResources().getResourceByName(CustomResource.class, jndiName);
if (resource != null && resource.getJndiName().equals(jndiName)) {
return param.getResources().remove(resource);
}
return null;
}
}, domain.getResources());
report.setMessage(localStrings.getLocalString("delete.custom.resource.success", "Custom resource {0} deleted", jndiName));
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
} catch (TransactionFailure tfe) {
report.setMessage(localStrings.getLocalString("delete.custom.resource.fail", "Unable to delete custom resource {0}", jndiName) + " " + tfe.getLocalizedMessage());
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setFailureCause(tfe);
}
}
Aggregations