use of alma.maciErrType.wrappers.AcsJCannotGetComponentEx in project ACS by ACS-Community.
the class ManagerImpl method containerLogout.
/**
* Container specific logout method
* @param id handle of the container.
* @param pingFailed flag indicating that ping has failed (i.e. is the reason of this logout).
*/
private void containerLogout(int id, boolean pingFailed) {
TimerTaskContainerInfo containerInfo = null;
synchronized (containers) {
int handle = id & HANDLE_MASK;
// already logged out
if (!containers.isAllocated(handle))
return;
containerInfo = (TimerTaskContainerInfo) containers.get(handle);
// cancel all "old" container async request
AcsJCannotGetComponentEx acgcex = new AcsJCannotGetComponentEx();
acgcex.setReason("Request canceled due to container logout.");
cancelPendingContainerAsyncRequestWithException(containerInfo.getName(), acgcex);
// !!! ACID - RemoveContainerCommand
executeCommand(new ContainerCommandDeallocate(handle, id, pingFailed ? WhyUnloadedReason.DISAPPEARED : WhyUnloadedReason.REMOVED));
// remove
//containers.deallocate(handle);
}
// deregister container from the heartbeat manager
containerInfo.getTask().cancel();
// make all container components unavailable
markContainersComponentsUnavailable(containerInfo);
/// TODO !!!!!!!!!!!!!! no more handle -> componentInfo data
// notify administrators about the logout
notifyContainerLogout(containerInfo, System.currentTimeMillis());
Container container = containerInfo.getContainer();
if (container != null)
container.release();
logger.log(Level.INFO, "Container '" + containerInfo.getName() + "' logged out.");
}
use of alma.maciErrType.wrappers.AcsJCannotGetComponentEx in project ACS by ACS-Community.
the class ManagerImpl method internalRequestComponent.
/**
* Internal method for requesting components.
* @param requestor requestor of the component.
* @param name name of component to be requested, non-<code>null</code>.
* @param type type of component to be requested; if <code>null</code> CDB will be queried.
* @param code code of component to be requested; if <code>null</code> CDB will be queried.
* @param containerName container name of component to be requested; if <code>null</code> CDB will be queried.
* @param status returned completion status of the request.
* @param activate <code>true</code> if component has to be activated
* @return componentInfo <code>ComponentInfo</code> of requested component.
*/
private ComponentInfo internalRequestComponent(int requestor, String name, String type, String code, String containerName, int keepAliveTime, StatusHolder status, boolean activate) throws AcsJCannotGetComponentEx, AcsJSyncLockFailedEx, AcsJComponentSpecIncompatibleWithActiveComponentEx {
AcsJCannotGetComponentEx bcex = null;
if (name == null) {
bcex = new AcsJCannotGetComponentEx();
logger.log(Level.SEVERE, "Cannot activate component with NULL name.", bcex);
throw bcex;
}
if (status == null) {
bcex = new AcsJCannotGetComponentEx();
logger.log(Level.SEVERE, "Component " + name + " has NULL status.", bcex);
throw bcex;
}
try {
checkCyclicDependency(requestor, name);
} catch (AcsJCyclicDependencyDetectedEx e) {
AcsJCannotGetComponentEx cgce = new AcsJCannotGetComponentEx(e);
cgce.setCURL(name);
throw cgce;
}
// try to acquire lock
String lockNotAcquiredCause = acquireSynchronizationObject(name, getLockTimeout(), "request component " + name);
if (lockNotAcquiredCause == null) {
boolean releaseRWLock = true;
try {
// try to acquire activation readers lock first
// NOTE: the locks are NOT reentrant
activationPendingRWLock.readLock().lock();
// AcsJComponentSpecIncompatibleWithActiveComponentEx flies up
return internalNoSyncRequestComponent(requestor, name, type, code, containerName, keepAliveTime, status, activate);
} finally {
if (releaseRWLock)
activationPendingRWLock.readLock().unlock();
releaseSynchronizationObject(name);
}
} else {
AcsJSyncLockFailedEx slfe = new AcsJSyncLockFailedEx();
slfe.setCURL(name);
slfe.setRequestor(requestor);
slfe.setProperty("lockCause", lockNotAcquiredCause);
throw slfe;
}
}
use of alma.maciErrType.wrappers.AcsJCannotGetComponentEx in project ACS by ACS-Community.
the class ManagerImplTest method testGetCollocatedComponent.
/**
* Test getCollocatedComponent.
*/
public void testGetCollocatedComponent() {
try {
URI mountURI = null;
try {
mountURI = new URI("MOUNT1");
} catch (URISyntaxException e) {
fail();
}
try {
manager.getCollocatedComponent(0, null, false, null);
fail();
} catch (AcsJInvalidComponentSpecEx bpe) {
System.out.println("This is OK: " + bpe.toString());
}
final ComponentSpec allAsterixCompSpec = new ComponentSpec(ComponentSpec.COMPSPEC_ANY, ComponentSpec.COMPSPEC_ANY, ComponentSpec.COMPSPEC_ANY, ComponentSpec.COMPSPEC_ANY);
try {
manager.getCollocatedComponent(Integer.MAX_VALUE, allAsterixCompSpec, true, dummyURI);
fail();
} catch (AcsJNoPermissionEx npe) {
System.out.println("This is OK: " + npe.toString());
}
try {
manager.getCollocatedComponent(dummyHandle, allAsterixCompSpec, false, dummyURI);
fail();
} catch (AcsJNoPermissionEx npe) {
System.out.println("This is OK: " + npe.toString());
}
TestClient client = new TestClient(clientName);
ClientInfo info = manager.login(client);
assertTrue(info.getHandle() != 0);
try {
manager.getCollocatedComponent(info.getHandle(), null, true, dummyURI);
fail();
} catch (AcsJInvalidComponentSpecEx bpe) {
System.out.println("This is OK: " + bpe.toString());
}
try {
manager.getCollocatedComponent(info.getHandle(), allAsterixCompSpec, true, null);
fail();
} catch (AcsJInvalidComponentSpecEx bpe) {
System.out.println("This is OK: " + bpe.toString());
}
try {
manager.getCollocatedComponent(info.getHandle(), new ComponentSpec(null, null, null, null), false, mountURI);
fail();
} catch (AcsJInvalidComponentSpecEx ndce) {
System.out.println("This is OK: " + ndce.toString());
}
final ComponentSpec specifiedContainerCompSpec = new ComponentSpec(ComponentSpec.COMPSPEC_ANY, ComponentSpec.COMPSPEC_ANY, ComponentSpec.COMPSPEC_ANY, "someContainer");
try {
manager.getCollocatedComponent(info.getHandle(), specifiedContainerCompSpec, false, mountURI);
fail();
} catch (AcsJInvalidComponentSpecEx ndce) {
System.out.println("This is OK: " + ndce.toString());
}
// containers
TestContainer container = new TestContainer("Container");
Map supportedComponents = new HashMap();
TestComponent mount1COB = new TestComponent("MOUNT1");
supportedComponents.put("MOUNT1", mount1COB);
TestComponent mountCollCOB = new TestComponent("MOUNT_COLLOCATED");
supportedComponents.put("MOUNT_COLLOCATED", mountCollCOB);
TestComponent mountColl2COB = new TestComponent("MOUNT_COLLOCATED2");
supportedComponents.put("MOUNT_COLLOCATED2", mountCollCOB);
container.setSupportedComponents(supportedComponents);
ClientInfo containerInfo = manager.login(container);
TestContainer dynContainer = new TestDynamicContainer("DynContainer");
/*ClientInfo dynContainerInfo =*/
manager.login(dynContainer);
// wait containers to startup
try {
Thread.sleep(STARTUP_COBS_SLEEP_TIME_MS);
} catch (InterruptedException ie) {
}
// standard case
try {
ComponentInfo componentInfo = manager.getCollocatedComponent(info.getHandle(), new ComponentSpec("MOUNT_COLLOCATED", "java.lang.Object", "java.lang.Object", ComponentSpec.COMPSPEC_ANY), true, mountURI);
assertTrue(componentInfo != null);
assertTrue(componentInfo.getName().equals("MOUNT_COLLOCATED"));
assertEquals(containerInfo.getHandle(), componentInfo.getContainer());
} catch (Exception ex) {
ex.printStackTrace();
fail();
}
// from CDB
try {
URI mount2URI = new URI("MOUNT2");
ComponentInfo componentInfo = manager.getCollocatedComponent(info.getHandle(), new ComponentSpec("MOUNT_COLLOCATED2", "java.lang.Object", "java.lang.Object", ComponentSpec.COMPSPEC_ANY), true, mount2URI);
assertTrue(componentInfo != null);
assertTrue(componentInfo.getName().equals("MOUNT_COLLOCATED2"));
assertEquals(containerInfo.getHandle(), componentInfo.getContainer());
} catch (Exception ex) {
fail();
}
// from CDB, but there is not entry...
try {
URI noEntryURI = new URI("noEntry");
ComponentInfo componentInfo = manager.getCollocatedComponent(info.getHandle(), new ComponentSpec("MOUNT_COLLOCATED3", "java.lang.Object", "java.lang.Object", ComponentSpec.COMPSPEC_ANY), true, noEntryURI);
fail();
} catch (AcsJIncompleteComponentSpecEx icse) {
System.out.println("This is OK: " + icse.toString());
} catch (Exception ex) {
ex.printStackTrace();
fail();
}
} catch (AcsJCannotGetComponentEx e) {
// @todo Auto-generated catch block
e.printStackTrace();
} catch (AcsJIncompleteComponentSpecEx e) {
// @todo Auto-generated catch block
e.printStackTrace();
} catch (AcsJInvalidComponentSpecEx e) {
// @todo Auto-generated catch block
e.printStackTrace();
} catch (AcsJComponentSpecIncompatibleWithActiveComponentEx e) {
// @todo Auto-generated catch block
e.printStackTrace();
} catch (AcsJNoPermissionEx e) {
fail("No permission");
}
}
use of alma.maciErrType.wrappers.AcsJCannotGetComponentEx in project ACS by ACS-Community.
the class ManagerImplTest method testGetComponent.
public void testGetComponent() {
try {
try {
manager.getComponent(0, null, false, null);
fail();
} catch (AcsJCannotGetComponentEx bpe) {
System.out.println("This is OK: " + bpe.toString());
}
try {
manager.getComponent(Integer.MAX_VALUE, null, false, null);
fail();
} catch (AcsJCannotGetComponentEx bpe) {
System.out.println("This is OK: " + bpe.toString());
}
try {
StatusHolder status = null;
manager.getComponent(dummyHandle, dummyURI, false, status);
fail();
} catch (AcsJCannotGetComponentEx bpe) {
System.out.println("This is OK: " + bpe.toString());
}
try {
StatusHolder status = new StatusHolder();
manager.getComponent(dummyHandle, null, false, status);
fail();
} catch (AcsJCannotGetComponentEx bpe) {
System.out.println("This is OK: " + bpe.toString());
}
TestAdministrator client = new TestAdministrator(administratorName);
ClientInfo info = manager.login(client);
assertTrue(info.getHandle() != 0);
// get unexistant
try {
StatusHolder status = new StatusHolder();
Component ref = manager.getComponent(info.getHandle(), dummyURI, true, status);
fail();
} catch (AcsJCannotGetComponentEx e) {
System.out.println("This is OK: component does not exist " + e.toString());
} catch (Exception ex) {
fail();
}
// test no activation
URI mount = null;
try {
mount = new URI("MOUNT1");
StatusHolder status = new StatusHolder();
Component ref = manager.getComponent(info.getHandle(), mount, false, status);
} catch (AcsJCannotGetComponentEx e) {
fail();
} catch (Exception ex) {
fail();
}
// test activation w/o container
try {
StatusHolder status = new StatusHolder();
Component ref = manager.getComponent(info.getHandle(), mount, true, status);
fail();
} catch (AcsJCannotGetComponentEx e) {
System.out.println("This is OK: component not activated " + e.toString());
} catch (Exception ex) {
fail();
}
// there should be only no Components activated
ComponentInfo[] infos = manager.getComponentInfo(info.getHandle(), new int[0], "*", "*", true);
assertEquals(0, infos.length);
TestContainer container = new TestContainer("Container");
Map supportedComponents = new HashMap();
Component mount1COB = new TestComponent("MOUNT1");
supportedComponents.put("MOUNT1", mount1COB);
supportedComponents.put("MOUNT2", null);
supportedComponents.put("MOUNT3", new TestComponent("MOUNT3", true, false));
Component mount4COB = new TestComponent("MOUNT4", false, true);
supportedComponents.put("MOUNT4", mount4COB);
container.setSupportedComponents(supportedComponents);
ClientInfo containerInfo = manager.login(container);
// test ordinary activation
try {
StatusHolder status = new StatusHolder();
Component ref = manager.getComponent(info.getHandle(), mount, true, status);
assertEquals(mount1COB, ref);
assertEquals(ComponentStatus.COMPONENT_ACTIVATED, status.getStatus());
} catch (Exception ex) {
fail();
}
// test failed activation
try {
StatusHolder status;
Component ref;
URI mount2 = null;
mount2 = new URI("MOUNT2");
status = new StatusHolder();
ref = manager.getComponent(info.getHandle(), mount2, true, status);
fail();
} catch (AcsJCannotGetComponentEx e1) {
System.out.println("This is OK: " + e1.toString());
} catch (URISyntaxException e1) {
fail();
}
// client should be owner of only one component
ClientInfo[] ci = manager.getClientInfo(info.getHandle(), new int[] { info.getHandle() }, null);
assertNotNull(ci);
assertEquals(1, ci.length);
// only mount 1
assertEquals(1, ci[0].getComponents().size());
// test failed activation (construct failure)
URI mount3 = null;
try {
mount3 = new URI("MOUNT3");
StatusHolder status = new StatusHolder();
Component ref = manager.getComponent(info.getHandle(), mount3, true, status);
fail();
} catch (AcsJCannotGetComponentEx e) {
System.out.println("This is OK: component not activated " + e.toString());
} catch (Exception ex) {
fail();
}
// test no activation w/ activated component
try {
StatusHolder status = new StatusHolder();
Component ref = manager.getComponent(info.getHandle(), mount, false, status);
assertTrue(ref != null);
assertEquals(ComponentStatus.COMPONENT_ACTIVATED, status.getStatus());
} catch (Exception ex) {
fail();
}
// test failed destruction
// test will be affected in client logout
URI mount4 = null;
try {
mount4 = new URI("MOUNT4");
StatusHolder status = new StatusHolder();
Component ref = manager.getComponent(info.getHandle(), mount4, true, status);
assertEquals(mount4COB, 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 only two Components activated (MOUNT1 and MOUNT4)
infos = manager.getComponentInfo(info.getHandle(), new int[0], "*", "*", true);
Arrays.sort(infos);
assertEquals(2, infos.length);
assertEquals(mount.toString(), infos[0].getName());
// manager and client
assertEquals(2, infos[0].getClients().size());
assertTrue(infos[0].getClients().contains(info.getHandle()));
assertTrue(infos[0].getClients().contains(HandleConstants.MANAGER_MASK));
assertTrue(mount4.toString().equals(infos[1].getName()));
// client
assertEquals(1, infos[1].getClients().size());
assertTrue(infos[1].getClients().contains(info.getHandle()));
// test unavailable and startup
manager.logout(containerInfo.getHandle());
containerInfo = manager.login(container);
try {
Thread.sleep(STARTUP_COBS_SLEEP_TIME_MS);
} catch (InterruptedException ie) {
}
// test activated Components after activation
// there should be only two Components activated (MOUNT1 and MOUNT4)
infos = manager.getComponentInfo(info.getHandle(), new int[0], "*", "*", true);
Arrays.sort(infos);
assertEquals(2, infos.length);
assertEquals(mount.toString(), infos[0].getName());
// manager and client
assertEquals(2, infos[0].getClients().size());
assertTrue(infos[0].getClients().contains(info.getHandle()));
assertTrue(infos[0].getClients().contains(HandleConstants.MANAGER_MASK));
assertTrue(mount4.toString().equals(infos[1].getName()));
// client
assertEquals(1, infos[1].getClients().size());
assertTrue(infos[1].getClients().contains(info.getHandle()));
// client logout
manager.logout(info.getHandle());
client = new TestAdministrator(administratorName);
info = manager.login(client);
assertTrue(info.getHandle() != 0);
try {
Thread.sleep(SLEEP_TIME_MS);
} catch (InterruptedException ie) {
}
// there should be only one component activated (MOUNT1)
infos = manager.getComponentInfo(info.getHandle(), new int[0], "*", "*", true);
assertEquals(1, infos.length);
try {
Thread.sleep(SLEEP_TIME_MS);
} catch (InterruptedException ie) {
}
manager.logout(containerInfo.getHandle());
try {
Thread.sleep(SLEEP_TIME_MS);
} catch (InterruptedException ie) {
}
// there should be no components activated
infos = manager.getComponentInfo(info.getHandle(), new int[0], "*", "*", true);
assertEquals(0, infos.length);
//
// test wrong Container-Component ImplLang
//
TestContainer pycontainer = new TestContainer("PyContainer", ClientType.CONTAINER, ImplLang.py, false);
Map pysupportedComponents = new HashMap();
Component cppOnPy = new TestComponent("CPP_ON_PY");
pysupportedComponents.put("CPP_ON_PY", cppOnPy);
pycontainer.setSupportedComponents(pysupportedComponents);
manager.login(pycontainer);
try {
Thread.sleep(STARTUP_COBS_SLEEP_TIME_MS);
} catch (InterruptedException ie) {
}
try {
StatusHolder status = new StatusHolder();
URI cppOnPyURI = new URI("CPP_ON_PY");
manager.getComponent(info.getHandle(), cppOnPyURI, true, status);
fail();
} catch (AcsJCannotGetComponentEx e1) {
System.out.println("This is OK: " + e1.toString());
} catch (URISyntaxException e1) {
fail();
}
try {
manager.getDynamicComponent(info.getHandle(), new ComponentSpec("CPP_ON_PY", ComponentSpec.COMPSPEC_ANY, ComponentSpec.COMPSPEC_ANY, ComponentSpec.COMPSPEC_ANY), false);
fail();
} catch (AcsJCannotGetComponentEx e1) {
System.out.println("This is OK: " + e1.toString());
} catch (AcsJComponentSpecIncompatibleWithActiveComponentEx e1) {
fail();
} catch (AcsJIncompleteComponentSpecEx ex) {
fail();
} catch (AcsJInvalidComponentSpecEx ex) {
fail();
}
// client logout
manager.logout(info.getHandle());
} catch (AcsJNoPermissionEx e) {
fail("No permission");
}
}
use of alma.maciErrType.wrappers.AcsJCannotGetComponentEx in project ACS by ACS-Community.
the class ManagerProxyImpl method get_collocated_component.
/**
* Activation of an co-deployed component.
* @param id identification of the caller.
* @param c component to be obtained.
* @param mark_as_default mark component as default component of its type.
* @param target_component target co-deployed component.
* @return <code>ComponentInfo</code> of requested co-deployed component.
*/
public ComponentInfo get_collocated_component(int id, si.ijs.maci.ComponentSpec c, boolean mark_as_default, String target_component) throws NoPermissionEx, IncompleteComponentSpecEx, InvalidComponentSpecEx, ComponentSpecIncompatibleWithActiveComponentEx, CannotGetComponentEx {
pendingRequests.incrementAndGet();
try {
// returned value
ComponentInfo retVal = null;
/*
URI uri = null;
if (c.component_name != null)
uri = CURLHelper.createURI(c.component_name);
ComponentSpec componentSpec = new ComponentSpec(uri, c.component_type, c.component_code, c.container_name);
*/
URI targetComponentURI = null;
if (target_component != null)
targetComponentURI = CURLHelper.createURI(target_component);
/// @TODO si.ijs.maci.COMPONENT_SPEC_ANY -> ComponentSpec.COMPSPEC_ANY
ComponentSpec componentSpec = new ComponentSpec(c.component_name, c.component_type, c.component_code, c.container_name);
com.cosylab.acs.maci.ComponentInfo info = manager.getCollocatedComponent(id, componentSpec, mark_as_default, targetComponentURI);
// transform to CORBA specific
if (info == null || info.getComponent() == null)
throw new AcsJCannotGetComponentEx();
Object obj = null;
obj = (Object) info.getComponent().getObject();
String[] interfaces;
if (info.getInterfaces() != null)
interfaces = info.getInterfaces();
else
interfaces = new String[0];
retVal = new ComponentInfo(info.getType(), info.getCode(), obj, info.getName(), info.getClients().toArray(), info.getContainer(), info.getContainerName(), info.getHandle(), mapAccessRights(info.getAccessRights()), interfaces);
return retVal;
} catch (URISyntaxException usi) {
BadParametersException hbpe = new BadParametersException(usi.getMessage(), usi);
reportException(hbpe);
// rethrow CORBA specific
throw new BAD_PARAM(usi.getMessage());
} catch (AcsJInvalidComponentSpecEx ics) {
// rethrow CORBA specific
throw ics.toInvalidComponentSpecEx();
} catch (AcsJIncompleteComponentSpecEx ics) {
// rethrow CORBA specific
throw ics.toIncompleteComponentSpecEx();
} catch (AcsJComponentSpecIncompatibleWithActiveComponentEx cpiwac) {
// rethrow CORBA specific
throw cpiwac.toComponentSpecIncompatibleWithActiveComponentEx();
} catch (AcsJNoPermissionEx npe) {
// rethrow CORBA specific
throw npe.toNoPermissionEx();
} 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 (Throwable ex) {
CoreException hce = new CoreException(ex.getMessage(), ex);
reportException(hce);
// rethrow CORBA specific
throw new UNKNOWN(ex.getMessage());
} finally {
pendingRequests.decrementAndGet();
}
}
Aggregations