use of com.sun.enterprise.config.serverbeans.Resource in project Payara by payara.
the class DeleteCustomResourceTest method tearDown.
@After
public void tearDown() throws TransactionFailure {
ConfigSupport.apply(new SingleConfigCode<Resources>() {
public Object run(Resources param) throws PropertyVetoException, TransactionFailure {
Resource target = null;
for (Resource resource : param.getResources()) {
if (resource instanceof CustomResource) {
CustomResource r = (CustomResource) resource;
if (r.getJndiName().equals("sample_custom_resource")) {
target = resource;
break;
}
}
}
if (target != null) {
param.getResources().remove(target);
}
return null;
}
}, resources);
parameters = new ParameterMap();
}
use of com.sun.enterprise.config.serverbeans.Resource in project Payara by payara.
the class DeleteConnectorResource 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();
if (jndiName == null) {
report.setMessage(localStrings.getLocalString("delete.connector.resource.noJndiName", "No JNDI name defined for connector resource."));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
// ensure we already have this resource
Resource r = ConnectorsUtil.getResourceByName(domain.getResources(), ConnectorResource.class, jndiName);
if (r == null) {
report.setMessage(localStrings.getLocalString("delete.connector.resource.notfound", "A connector resource named {0} does not exist.", jndiName));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
if ("system-all-req".equals(r.getObjectType())) {
report.setMessage(localStrings.getLocalString("delete.connector.resource.notAllowed", "The {0} resource cannot be deleted as it is required to be configured in the system.", 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.connector.resource.resource-ref.exist", "connector-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.connector.resource.no.resource-ref", "connector-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.connector.resource.multiple.resource-refs", "connector 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 connector-resource
if (ConfigSupport.apply(new SingleConfigCode<Resources>() {
public Object run(Resources param) throws PropertyVetoException, TransactionFailure {
ConnectorResource resource = (ConnectorResource) ConnectorsUtil.getResourceByName(domain.getResources(), ConnectorResource.class, jndiName);
return param.getResources().remove(resource);
}
}, domain.getResources()) == null) {
report.setMessage(localStrings.getLocalString("delete.connector.resource.fail", "Connector resource {0} delete failed ", jndiName));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
} catch (TransactionFailure tfe) {
report.setMessage(localStrings.getLocalString("delete.connector.resource.fail", "Connector resource {0} delete failed ", jndiName) + " " + tfe.getLocalizedMessage());
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setFailureCause(tfe);
}
report.setMessage(localStrings.getLocalString("delete.connector.resource.success", "Connector resource {0} deleted successfully", jndiName));
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
use of com.sun.enterprise.config.serverbeans.Resource in project Payara by payara.
the class CreateCustomResourceTest method testExecuteFailDuplicateResource.
/**
* Test of execute method, of class CreateCustomResource.
* asadmin create-custom-resource --restype=topic --factoryclass=javax.naming.spi.ObjectFactory
* dupRes
* asadmin create-custom-resource --restype=topic --factoryclass=javax.naming.spi.ObjectFactory
* dupRes
*/
@Test
public void testExecuteFailDuplicateResource() {
parameters.set("restype", "topic");
parameters.set("factoryclass", "javax.naming.spi.ObjectFactory");
parameters.set("jndi_name", "dupRes");
// Call CommandRunnerImpl.doCommand(..) to execute the command
cr.getCommandInvocation("create-custom-resource", context.getActionReport(), adminSubject()).parameters(parameters).execute(command);
// Check the exit code is SUCCESS
assertEquals(ActionReport.ExitCode.SUCCESS, context.getActionReport().getActionExitCode());
// Check that the resource was created
boolean isCreated = false;
for (Resource resource : resources.getResources()) {
if (resource instanceof CustomResource) {
CustomResource jr = (CustomResource) resource;
if (jr.getJndiName().equals("dupRes")) {
isCreated = true;
logger.fine("Custom Resource config bean dupRes is created.");
break;
}
}
}
assertTrue(isCreated);
// Try to create a duplicate resource dupRes. Get a new instance of the command.
org.glassfish.resources.admin.cli.CreateCustomResource command2 = habitat.getService(org.glassfish.resources.admin.cli.CreateCustomResource.class);
cr.getCommandInvocation("create-custom-resource", context.getActionReport(), adminSubject()).parameters(parameters).execute(command2);
// Check the exit code is FAILURE
assertEquals(ActionReport.ExitCode.FAILURE, context.getActionReport().getActionExitCode());
// Check that the 2nd resource was NOT created
int numDupRes = 0;
for (Resource resource : resources.getResources()) {
if (resource instanceof CustomResource) {
CustomResource jr = (CustomResource) resource;
if (jr.getJndiName().equals("dupRes")) {
numDupRes = numDupRes + 1;
}
}
}
assertEquals(1, numDupRes);
logger.fine("msg: " + context.getActionReport().getMessage());
}
use of com.sun.enterprise.config.serverbeans.Resource in project Payara by payara.
the class CreateCustomResourceTest method testExecuteWithOptionalValuesSet.
/**
* Test of execute method, of class CreateCustomResource.
* asadmin create-custom-resource --restype=topic --factoryclass=javax.naming.spi.ObjectFactory
* --enabled=false --description=Administered Object sample_custom_resource
*/
@Test
public void testExecuteWithOptionalValuesSet() {
parameters.set("restype", "topic");
parameters.set("factoryclass", "javax.naming.spi.ObjectFactory");
parameters.set("enabled", "false");
parameters.set("description", "Administered Object");
parameters.set("jndi_name", "sample_custom_resource");
// Call CommandRunnerImpl.doCommand(..) to execute the command
cr.getCommandInvocation("create-custom-resource", context.getActionReport(), adminSubject()).parameters(parameters).execute(command);
// Check the exit code is SUCCESS
assertEquals(ActionReport.ExitCode.SUCCESS, context.getActionReport().getActionExitCode());
// Check that the resource was created
boolean isCreated = false;
for (Resource resource : resources.getResources()) {
if (resource instanceof CustomResource) {
CustomResource r = (CustomResource) resource;
if (r.getJndiName().equals("sample_custom_resource")) {
assertEquals("topic", r.getResType());
assertEquals("javax.naming.spi.ObjectFactory", r.getFactoryClass());
// expect enabled for the resource to be true as resource-ref's enabled
// would be set to false
assertEquals("true", r.getEnabled());
assertEquals("Administered Object", r.getDescription());
isCreated = true;
logger.fine("Custom Resource config bean sample_custom_resource is created.");
break;
}
}
}
assertTrue(isCreated);
logger.fine("msg: " + context.getActionReport().getMessage());
}
use of com.sun.enterprise.config.serverbeans.Resource in project Payara by payara.
the class ConnectorService method loadResourcesAndItsRar.
/* public boolean checkAndLoadResource(Object resource, Object pool, String resourceType, String resourceName,
String raName)
throws ConnectorRuntimeException {
String resname = ConnectorAdminServiceUtils.getOriginalResourceName(resourceName);
if(_logger.isLoggable(Level.FINE)) {
_logger.fine("ConnectorService :: checkAndLoadResource resolved to load " + resname);
}
DeferredResourceConfig defResConfig = getResourcesUtil().getDeferredResourceConfig(resource, pool, resourceType, raName);
//DeferredResourceConfig defResConfig = resUtil.getDeferredResourceConfig(resname);
return loadResourcesAndItsRar(defResConfig);
}
*/
public boolean loadResourcesAndItsRar(DeferredResourceConfig defResConfig) {
if (defResConfig != null) {
try {
loadDeferredResources(defResConfig.getResourceAdapterConfig());
final String rarName = defResConfig.getRarName();
loadDeferredResourceAdapter(rarName);
final Resource[] resToLoad = defResConfig.getResourcesToLoad();
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
try {
loadDeferredResources(resToLoad);
} catch (Exception ex) {
Object[] params = new Object[] { rarName, ex };
_logger.log(Level.SEVERE, "failed.to.load.deferred.resources", params);
}
return null;
}
});
} catch (Exception ex) {
Object[] params = new Object[] { defResConfig.getRarName(), ex };
_logger.log(Level.SEVERE, "failed.to.load.deferred.ra", params);
return false;
}
return true;
}
return false;
}
Aggregations