use of com.cosylab.acs.maci.Component in project ACS by ACS-Community.
the class ManagerImplTest method testGetCyclicHierachicalComponentAllowWithPreactivated.
// if one component in a cycle is preactivated, that this is allowed
public void testGetCyclicHierachicalComponentAllowWithPreactivated() /*boolean constructCase*/
{
boolean constructCase = false;
try {
TestContainer container = new TestContainer("Container");
Map supportedComponents = new HashMap();
// MOUNT3 -> (last will request MOUNT4)
TestHierarchicalComponent mount3HierCOB = new TestHierarchicalComponent("MOUNT3", manager, new String[] {}, true, constructCase);
supportedComponents.put("MOUNT3", mount3HierCOB);
// MOUNT4 -> PBEND_B_01 -> MOUNT3 cycle
TestHierarchicalComponent mount4HierCOB = new TestHierarchicalComponent("MOUNT4", manager, new String[] { "PBEND_B_01" }, true, constructCase);
supportedComponents.put("MOUNT4", mount4HierCOB);
TestHierarchicalComponent pbendHierCOB = new TestHierarchicalComponent("PBEND_B_01", manager, new String[] { "MOUNT3" }, true, constructCase);
supportedComponents.put("PBEND_B_01", pbendHierCOB);
container.setSupportedComponents(supportedComponents);
TestAdministrator client = new TestAdministrator(administratorName);
ClientInfo info = manager.login(client);
// test case when container is unable to activate startup Component - MOUNT1
ClientInfo containerInfo = manager.login(container);
// activate MOUNT3
try {
URI mount3URI = new URI("MOUNT3");
StatusHolder status = new StatusHolder();
Component ref = manager.getComponent(info.getHandle(), mount3URI, true, status);
assertEquals(mount3HierCOB, ref);
assertEquals(ComponentStatus.COMPONENT_ACTIVATED, status.getStatus());
} catch (Exception ex) {
fail();
}
// this should be allowed
try {
URI mount4URI = new URI("MOUNT4");
StatusHolder status = new StatusHolder();
Component ref = manager.getComponent(mount3HierCOB.getHandle(), mount4URI, true, status);
assertEquals(mount4HierCOB, ref);
assertEquals(ComponentStatus.COMPONENT_ACTIVATED, status.getStatus());
} catch (Exception ex) {
fail();
}
// test activated Components
// there should be all three Components activated
ComponentInfo[] infos = manager.getComponentInfo(info.getHandle(), new int[0], "*", "*", true);
assertEquals(3, infos.length);
} catch (AcsJNoPermissionEx e) {
fail("No permission");
}
}
use of com.cosylab.acs.maci.Component in project ACS by ACS-Community.
the class ManagerProxyImpl method get_component.
/**
* Get a Component, activating it if necessary.
* The client represented by id (the handle)
* must have adequate access rights to access the Component. This is untrue of components:
* components always have unlimited access rights to other components.
*
* @param id Identification of the caller. If this is an invalid handle, or if the caller does not have enough access rights, a maciErrType::NoPermissionEx exception is raised.
* @param component_url CURL of the Component whose reference is to be retrieved.
* @param activate True if the Component is to be activated in case it does not exist. If set to False, and the Component does not exist, a nil reference is returned and status is set to COMPONENT_NOT_ACTIVATED.
* @return Reference to the Component. If the Component could not be activated, an exception is throw.
*/
public Object get_component(int id, String component_url, boolean activate) throws NoPermissionEx, CannotGetComponentEx, ComponentNotAlreadyActivatedEx, ComponentConfigurationNotFoundEx {
pendingRequests.incrementAndGet();
try {
// returned value
Object retVal = null;
// returned status
StatusHolder statusHolder = new StatusHolder();
// transform to CORBA specific
URI uri = null;
if (component_url != null)
uri = CURLHelper.createURI(component_url);
Component component = manager.getComponent(id, uri, activate, statusHolder);
// extract Component CORBA reference
if (component != null)
retVal = (Object) component.getObject();
/**
* @todo GCH 2006.10.11
* notice that we can get a ComponentStatus != COMPONENT_ACTIVATED
* also if the component is properly returned.
* There is an incoherence here in the interfaces that shall be resolved.
* We have to cleanup here or go back to return a status
* to the caller.
* My point is: the caller is interested in more than just
* getting the component of an indication of failure if not?
* Is it interesting to know that the component was not activated,
* presumably because already active?
*/
if (component == null || component.getObject() == null) {
if (statusHolder.getStatus() == ComponentStatus.COMPONENT_NOT_ACTIVATED && !activate) {
AcsJComponentNotAlreadyActivatedEx ex = new AcsJComponentNotAlreadyActivatedEx();
ex.setCURL(component_url);
throw ex;
}
if (statusHolder.getStatus() == ComponentStatus.COMPONENT_DOES_NO_EXIST) {
AcsJComponentConfigurationNotFoundEx ex = new AcsJComponentConfigurationNotFoundEx();
ex.setCURL(component_url);
throw ex;
} else {
AcsJCannotGetComponentEx ex = new AcsJCannotGetComponentEx();
ex.setCURL(component_url);
throw ex;
}
}
return retVal;
} catch (URISyntaxException usi) {
BadParametersException hbpe = new BadParametersException(usi.getMessage(), usi);
reportException(hbpe);
// rethrow CORBA specific
throw new BAD_PARAM(usi.getMessage());
} catch (BadParametersException bpe) {
BadParametersException hbpe = new BadParametersException(bpe.getMessage(), bpe);
reportException(hbpe);
// rethrow CORBA specific
throw new BAD_PARAM(bpe.getMessage());
} catch (NoResourcesException nre) {
NoResourcesException hnre = new NoResourcesException(nre.getMessage(), nre);
reportException(hnre);
// rethrow CORBA specific
throw new NO_RESOURCES(nre.getMessage());
} catch (AcsJCannotGetComponentEx cgce) {
// rethrow CORBA specific
throw cgce.toCannotGetComponentEx();
} catch (AcsJComponentNotAlreadyActivatedEx cnaae) {
// rethrow CORBA specific
throw cnaae.toComponentNotAlreadyActivatedEx();
} catch (AcsJComponentConfigurationNotFoundEx ccnfe) {
// rethrow CORBA specific
throw ccnfe.toComponentConfigurationNotFoundEx();
} catch (AcsJNoPermissionEx npe) {
// rethrow CORBA specific
throw npe.toNoPermissionEx();
} catch (Throwable ex) {
CoreException hce = new CoreException(ex.getMessage(), ex);
reportException(hce);
// rethrow CORBA specific
throw new UNKNOWN(ex.getMessage());
} finally {
pendingRequests.decrementAndGet();
}
}
use of com.cosylab.acs.maci.Component in project ACS by ACS-Community.
the class ManagerProxyImpl method get_service.
/**
* Get a service, activating it if necessary (components).
* The client represented by id (the handle) must have adequate access rights to access the service.
* NOTE: a component is also a service, i.e. a service activated by a container.
*
* @param id Identification of the caller. If this is an invalid handle, or if the caller does not have enough access rights, a maciErrType::NoPermissionEx exception is raised.
* @param service_url CURL of the service whose reference is to be retrieved.
* @param activate True if the component is to be activated in case it does not exist. If set to False, and the Component does not exist, a nil reference is returned and status is set to COMPONENT_NOT_ACTIVATED.
* @param status Status of the request. One of COMPONENT_ACTIVATED, COMPONENT_DOES_NO_EXIST and COMPONENT_NOT_ACTIVATED.
* @return Reference to the service. If the service could not be obtained, a nil reference is returned,
* and the status contains an error code detailing the cause of failure (one of the COMPONENT_* constants).
* @see #get_component
*/
public Object get_service(int id, String service_url, boolean activate) throws NoPermissionEx, CannotGetComponentEx {
pendingRequests.incrementAndGet();
try {
// returned value
Object retVal = null;
// returned status
StatusHolder statusHolder = new StatusHolder();
// transform to CORBA specific
URI uri = null;
if (service_url != null)
uri = CURLHelper.createURI(service_url);
Component component = manager.getService(id, uri, activate, statusHolder);
if (component == null || (Object) component.getObject() == null)
throw new AcsJCannotGetComponentEx();
retVal = (Object) component.getObject();
return retVal;
} catch (URISyntaxException usi) {
BadParametersException hbpe = new BadParametersException(usi.getMessage(), usi);
reportException(hbpe);
// rethrow CORBA specific
throw new BAD_PARAM(usi.getMessage());
} catch (BadParametersException bpe) {
BadParametersException hbpe = new BadParametersException(bpe.getMessage(), bpe);
reportException(hbpe);
// rethrow CORBA specific
throw new BAD_PARAM(bpe.getMessage());
} catch (NoResourcesException nre) {
NoResourcesException hnre = new NoResourcesException(nre.getMessage(), nre);
reportException(hnre);
// rethrow CORBA specific
throw new NO_RESOURCES(nre.getMessage());
} catch (AcsJCannotGetComponentEx cgce) {
// rethrow CORBA specific
throw cgce.toCannotGetComponentEx();
} catch (AcsJNoPermissionEx npe) {
// rethrow CORBA specific
throw npe.toNoPermissionEx();
} catch (Throwable ex) {
CoreException hce = new CoreException(ex.getMessage(), ex);
reportException(hce);
// rethrow CORBA specific
throw new UNKNOWN(ex.getMessage());
} finally {
pendingRequests.decrementAndGet();
}
}
use of com.cosylab.acs.maci.Component in project ACS by ACS-Community.
the class ManagerImplTest method internalTestGetHierarchicalComponent.
public void internalTestGetHierarchicalComponent(boolean activateOnActivation) {
try {
TestContainer container = new TestContainer("Container");
Map supportedComponents = new HashMap();
TestHierarchicalComponent mount2HierCOB = new TestHierarchicalComponent("HierarchicalCOB2", manager, new String[] { "MOUNT3" }, false, activateOnActivation);
TestHierarchicalComponent mount3HierCOB = new TestHierarchicalComponent("HierarchicalCOB3", manager, new String[] { "MOUNT4" }, false, activateOnActivation);
Component mount4COB = new TestComponent("MOUNT4");
supportedComponents.put("MOUNT2", mount2HierCOB);
supportedComponents.put("MOUNT3", mount3HierCOB);
supportedComponents.put("MOUNT4", mount4COB);
container.setSupportedComponents(supportedComponents);
// test case when container is unable to activate startup Component - MOUNT1
ClientInfo containerInfo = manager.login(container);
TestAdministrator client = new TestAdministrator(administratorName);
ClientInfo info = manager.login(client);
// test ordinary activation
URI mount2URI;
try {
mount2URI = new URI("MOUNT2");
StatusHolder status = new StatusHolder();
Component ref = manager.getComponent(info.getHandle(), mount2URI, true, status);
assertEquals(mount2HierCOB, ref);
assertEquals(ComponentStatus.COMPONENT_ACTIVATED, status.getStatus());
} catch (Exception ex) {
fail();
}
try {
Thread.sleep(STARTUP_COBS_SLEEP_TIME_MS);
} catch (InterruptedException ie) {
}
// test activated Components
// there should be all three Components activated
ComponentInfo[] infos = manager.getComponentInfo(info.getHandle(), new int[0], "*", "*", true);
assertEquals(3, infos.length);
// container logout and login
manager.logout(containerInfo.getHandle());
try {
Thread.sleep(SLEEP_TIME_MS);
} catch (InterruptedException ie) {
}
// test activated Components
// there should be no Components activated
infos = manager.getComponentInfo(info.getHandle(), new int[0], "*", "*", true);
assertEquals(0, infos.length);
manager.login(container);
try {
Thread.sleep(STARTUP_COBS_SLEEP_TIME_MS);
} catch (InterruptedException ie) {
}
// test activated Components
// there should be all three Components activated
infos = manager.getComponentInfo(info.getHandle(), new int[0], "*", "*", true);
assertEquals(3, infos.length);
// logout client
manager.logout(info.getHandle());
try {
Thread.sleep(SLEEP_TIME_MS);
} catch (InterruptedException ie) {
}
} catch (AcsJNoPermissionEx e) {
fail("No permission");
}
}
Aggregations