use of alma.maciErrType.wrappers.AcsJNoPermissionEx in project ACS by ACS-Community.
the class ManagerImplTest method testComponentInfoTopologicalSort.
public void testComponentInfoTopologicalSort() {
try {
boolean activateOnActivation = true;
TestContainer container = new TestContainer("Container");
Map supportedComponents = new HashMap();
TestContainer container2 = new TestContainer("Container2");
Map supportedComponents2 = new HashMap();
Component mount1COB = new TestComponent("MOUNT1");
TestHierarchicalComponent mount2HierCOB = new TestHierarchicalComponent("HierarchicalCOB2", manager, new String[] { "MOUNT3" }, true, activateOnActivation);
TestHierarchicalComponent mount3HierCOB = new TestHierarchicalComponent("HierarchicalCOB3", manager, new String[] { "MOUNT5", "PBEND_B_01" }, true, activateOnActivation);
Component mount5COB = new TestComponent("MOUNT5");
TestHierarchicalComponent mount4HierCOB = new TestHierarchicalComponent("HierarchicalCOB4", manager, new String[] { "MOUNT2" }, true, activateOnActivation);
TestHierarchicalComponent psHierCOB = new TestHierarchicalComponent("HierarchicalPSCOB", manager, new String[] { "MOUNT5" }, true, activateOnActivation);
supportedComponents.put("MOUNT1", mount1COB);
supportedComponents.put("MOUNT2", mount2HierCOB);
supportedComponents.put("MOUNT3", mount3HierCOB);
supportedComponents2.put("MOUNT5", mount5COB);
supportedComponents.put("MOUNT4", mount4HierCOB);
supportedComponents.put("PBEND_B_01", psHierCOB);
container.setSupportedComponents(supportedComponents);
container2.setSupportedComponents(supportedComponents2);
// test case when container is unable to activate startup Component - MOUNT1
ClientInfo containerInfo = manager.login(container);
ClientInfo containerInfo2 = manager.login(container2);
TestAdministrator client = new TestAdministrator(administratorName);
ClientInfo info = manager.login(client);
// activate hier. components
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();
}
// activate orphan component
URI mount1URI;
try {
mount1URI = new URI("MOUNT1");
StatusHolder status = new StatusHolder();
Component ref = manager.getComponent(info.getHandle(), mount1URI, true, status);
assertEquals(mount1COB, ref);
assertEquals(ComponentStatus.COMPONENT_ACTIVATED, status.getStatus());
} catch (Exception ex) {
fail();
}
// activate mount4
URI mount4URI;
try {
mount4URI = new URI("MOUNT4");
StatusHolder status = new StatusHolder();
Component ref = manager.getComponent(info.getHandle(), mount4URI, true, status);
assertEquals(mount4HierCOB, 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(6, infos.length);
// topological sort
ArrayList solution = new ArrayList(6);
solution.add(mount4HierCOB);
solution.add(mount2HierCOB);
solution.add(mount3HierCOB);
solution.add(psHierCOB);
solution.add(mount5COB);
solution.add(mount1COB);
List list = ComponentInfoTopologicalSort.sort(manager.getComponents());
assertEquals(solution.size(), list.size());
int len = solution.size();
for (int i = 0; i < len; i++) assertEquals(solution.get(i), ((ComponentInfo) list.get(i)).getComponent());
} catch (AcsJNoPermissionEx e) {
fail("No permission");
}
}
use of alma.maciErrType.wrappers.AcsJNoPermissionEx in project ACS by ACS-Community.
the class ManagerImplTest method testExpiredHandle.
public void testExpiredHandle() {
// test client login
Client client = new TestClient(clientName);
ClientInfo info = null;
try {
info = manager.login(client);
} catch (AcsJNoPermissionEx e) {
fail("No permission");
}
try {
manager.logout(info.getHandle());
} catch (AcsJNoPermissionEx e) {
fail("No permission");
}
// duplicate logout
try {
manager.logout(info.getHandle());
fail("No permission exception was not thrown");
} catch (AcsJNoPermissionEx e) {
// this should provide nice error message
System.out.println("This is OK: " + e);
}
}
use of alma.maciErrType.wrappers.AcsJNoPermissionEx in project ACS by ACS-Community.
the class ManagerImplTest method testComponentInfo.
public void testComponentInfo() {
/// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
if (false) {
try {
//TODO get ComponentInfo
manager.getComponentInfo(0, null, null, null, false);
manager.getComponentInfo(Integer.MAX_VALUE, null, null, null, false);
manager.getComponentInfo(dummyHandle, null, null, null, false);
manager.getComponentInfo(dummyHandle, null, "non-null", null, true);
manager.getComponentInfo(dummyHandle, null, null, "non-null", true);
manager.getComponentInfo(dummyHandle, new int[0], null, null, false);
manager.getComponentInfo(dummyHandle, new int[0], "non-null", null, true);
manager.getComponentInfo(dummyHandle, new int[0], null, "non-null", false);
} catch (AcsJNoPermissionEx e) {
fail("No permission");
}
}
try {
Administrator client = new TestAdministrator(clientName);
ClientInfo info = manager.login(client);
manager.getComponentInfo(info.getHandle(), new int[0], "*MOUNT*", "*", false);
manager.logout(info.getHandle());
} catch (Throwable e) {
e.printStackTrace();
fail(e.getMessage());
}
TestContainer container = new TestContainer("Container");
Map supportedComponents = new HashMap();
Component mount1COB = new TestComponent("MOUNT1");
supportedComponents.put("MOUNT1", mount1COB);
Component mount4COB = new TestComponent("MOUNT4");
supportedComponents.put("MOUNT4", mount4COB);
container.setSupportedComponents(supportedComponents);
ClientInfo containerInfo = null;
try {
containerInfo = manager.login(container);
} catch (AcsJNoPermissionEx e1) {
fail("No permission");
}
try {
Thread.sleep(STARTUP_COBS_SLEEP_TIME_MS);
} catch (InterruptedException ie) {
}
try {
Administrator client = new TestAdministrator(clientName);
ClientInfo info = manager.login(client);
ComponentInfo[] infos = manager.getComponentInfo(info.getHandle(), new int[0], "MOUNT1", "*", false);
assertEquals(1, infos.length);
} catch (Throwable e) {
e.printStackTrace();
fail(e.getMessage());
}
try {
manager.logout(containerInfo.getHandle());
} catch (AcsJNoPermissionEx e) {
fail("No permission");
}
}
use of alma.maciErrType.wrappers.AcsJNoPermissionEx in project ACS by ACS-Community.
the class ManagerImpl method registerComponent.
/**
* @see com.cosylab.acs.maci.Manager#registerComponent(int, URI, String, Component)
*/
public int registerComponent(int id, URI curl, String type, Component component) throws AcsJNoPermissionEx, AcsJBadParameterEx {
// check for null
if (curl == null) {
AcsJBadParameterEx af = new AcsJBadParameterEx();
af.setParameter("curl");
af.setParameterValue("null");
throw af;
}
if (type == null) {
AcsJBadParameterEx af = new AcsJBadParameterEx();
af.setParameter("type");
af.setParameterValue("null");
throw af;
}
if (component == null) {
AcsJBadParameterEx af = new AcsJBadParameterEx();
af.setParameter("component");
af.setParameterValue("null");
throw af;
}
// Just rethrow the exception
try {
checkCURL(curl, false);
} catch (AcsJBadParameterEx e) {
throw e;
}
// check handle and REGISTER_COMPONENT permissions
securityCheck(id, AccessRights.REGISTER_COMPONENT);
/****************************************************************/
// extract name
String name = extractName(curl);
int h = 0;
componentsLock.lock();
try {
// check if Component is already registred
// if it is, return existing info
h = components.first();
while (h != 0) {
ComponentInfo registeredComponentInfo = (ComponentInfo) components.get(h);
if (registeredComponentInfo.getName().equals(name)) {
if (registeredComponentInfo.getType().equals(type)) {
// it is already activated, add manager as an owner and return handle
if (!registeredComponentInfo.getClients().contains(this.getHandle())) {
// ACID - !!!
executeCommand(new ComponentCommandClientAdd(registeredComponentInfo.getHandle() & HANDLE_MASK, this.getHandle()));
//registredComponentInfo.getClients().add(this.getHandle());
}
return registeredComponentInfo.getHandle();
} else {
AcsJNoPermissionEx npe = new AcsJNoPermissionEx();
npe.setReason("Component with name '" + name + "' but different type already registered.");
npe.setID(HandleHelper.toString(id));
npe.setProtectedResource(name);
throw npe;
}
}
h = components.next(h);
}
// allocate new handle
// !!! ACID 2
Integer objHandle = (Integer) executeCommand(new ComponentCommandAllocate());
int handle;
//int handle = components.allocate();
if (objHandle == null || (handle = objHandle.intValue()) == 0) {
NoResourcesException af = new NoResourcesException("Generation of new handle failed, too many components registred.");
throw af;
}
// generate external handle
h = handle | COMPONENT_MASK;
// add generated key
h |= (random.nextInt(0x100)) << 16;
// create new component info
ComponentInfo componentInfo = new ComponentInfo(h, name, type, null, component);
// no container
componentInfo.setContainer(0);
componentInfo.setContainerName(null);
// components can register other components
componentInfo.setAccessRights(AccessRights.REGISTER_COMPONENT);
// set Manager as client of the Component (to keep it immortal)
componentInfo.getClients().add(this.getHandle());
// set interfaces
// NOTE: this could block since it is a remote call
componentInfo.setInterfaces(component.implementedInterfaces());
// !!! ACID - register AddComponentCommand
executeCommand(new ComponentCommandSet(handle, componentInfo));
// store info
//components.set(handle, componentInfo);
} finally {
componentsLock.unlock();
}
// bind to remote directory
// NOTE: this could block since it is a remote call
//bind(convertToHiearachical(name), "O", component);
logger.log(Level.INFO, "Component '" + name + "' registered.");
return h;
}
use of alma.maciErrType.wrappers.AcsJNoPermissionEx in project ACS by ACS-Community.
the class ManagerImpl method shutdown.
/**
* @see com.cosylab.acs.maci.Manager#shutdown(int, int)
*/
public void shutdown(int id, int containers) throws AcsJNoPermissionEx {
// check handle and SHUTDOWN_SYSTEM permissions
securityCheck(id, AccessRights.SHUTDOWN_SYSTEM);
if (id == MANAGER_MASK)
id = originalId;
else
originalId = id;
if (containers == 0)
containers = originalContainers;
else
originalContainers = containers;
// if application is not destroying already, destroy it
if (shutdownImplementation != null && !shutdownImplementation.isShutdownInProgress()) {
// spawn another thread
new Thread(new Runnable() {
public void run() {
// fire destroy application
if (!shutdownImplementation.isShutdownInProgress())
shutdownImplementation.shutdown(false);
}
}, "ManagerApplicationShutdown").start();
return;
}
// check if already shutdown
if (shutdown.getAndSet(true)) {
// already shutdown
AcsJNoPermissionEx npe = new AcsJNoPermissionEx();
npe.setReason("Manager already in shutdown state.");
npe.setID(HandleHelper.toString(id));
throw npe;
}
/****************************************************************/
logger.log(Level.INFO, "Manager is shutting down.");
logger.log(Level.FINER, "Canceling heartbeat task.");
// cancel hertbeat task
heartbeatTask.cancel();
topologySortManager.destroy();
// if not "silent" shutdown
if (containers != 0) {
logger.log(Level.FINER, "Releasing all components in the system.");
try {
topologySortManager.requestTopologicalSort();
releaseComponents(topologySortManager.getComponentShutdownOrder(null));
} catch (Throwable th) {
CoreException ce = new CoreException("Failed to release all components in the system.", th);
reportException(ce);
}
}
logger.log(Level.FINER, "Notifying containers to disconnect or shutdown.");
notifyContainerDisconnectShutdown(containers);
// finalizeFearation
finalizeFederation();
// process tasks in thread pool
// !!! NOTE: this could block (for a long time)
logger.log(Level.FINER, "Waiting for tasks in thread pool to complete...");
threadPool.shutdown();
try {
if (!threadPool.awaitTermination(3, TimeUnit.SECONDS))
threadPool.shutdownNow();
} catch (InterruptedException ie) {
/* noop */
}
if (alarmSource != null) {
alarmSource.tearDown();
}
// unbind Manager
unbind("Manager", null);
setCDBAccess(null);
// release CDB DAO daos
destroyComponetsDAOProxy();
destroyContainersDAOProxy();
destroyManagerDAOProxy();
logger.log(Level.INFO, "Manager shutdown completed.");
/****************************************************************/
}
Aggregations