use of com.cosylab.acs.maci.ComponentSpec in project ACS by ACS-Community.
the class ManagerImpl method initialize.
/**
* Initializes Manager.
* @param prevayler implementation of prevayler system
* @param context remote directory implementation
*/
public void initialize(Prevayler prevayler, CDBAccess cdbAccess, Context context, final Logger logger, ManagerContainerServices managerContainerServices) {
this.prevayler = prevayler;
this.remoteDirectory = context;
this.logger = logger;
// needs to be done here, since deserialization is used
initializeDefaultConfiguration();
if (cdbAccess != null)
setCDBAccess(cdbAccess);
readManagerConfiguration();
componentsLock = (ProfilingReentrantLock.isProfilingEnabled ? new ProfilingReentrantLock("componentsLock") : new ReentrantLock());
random = new Random();
heartbeatTask = new Timer(true);
delayedDeactivationTask = new Timer(true);
containerLoggedInMonitor = new Object();
activationSynchronization = new HashMap<String, ReferenceCountingLock>();
activationPendingRWLock = new ReaderPreferenceReadWriteLock();
shutdown = new AtomicBoolean(false);
threadPool = new ThreadPoolExecutor(poolThreads, poolThreads, Long.MAX_VALUE, TimeUnit.NANOSECONDS, new LinkedBlockingQueue(), new DaemonThreadFactory("managerThreadPool"));
managerCache = new HashMap<String, Manager>();
pendingActivations = new HashMap<String, ComponentInfo>();
pendingContainerShutdown = Collections.synchronizedSet(new HashSet<String>());
pendingContainerAsyncRequests = new HashMap<String, Deque<ComponentInfoCompletionCallback>>();
clientMessageQueue = new HashMap<Client, LinkedList<ClientMessageTask>>();
groupedNotifyTaskMap = new HashMap<Object, GroupedNotifyTask>();
threadsUsedPercentage = new AtomicInteger(0);
// create threads
threadPool.prestartAllCoreThreads();
// read CDB startup
try {
String componentSpec = System.getProperty(NAME_CDB_COMPONENTSPEC);
if (componentSpec != null) {
cdbActivation = new ComponentSpec(componentSpec);
logger.log(Level.INFO, "Using CDB component specification: '" + cdbActivation + "'.");
}
} catch (Throwable t) {
logger.log(Level.WARNING, "Failed to parse '" + NAME_CDB_COMPONENTSPEC + "' variable, " + t.getMessage(), t);
}
// check load balancing strategy
checkLoadBalancingStrategy();
// establish connect to the alarm system
try {
alarmSource = new AlarmSourceImpl(managerContainerServices);
alarmSource.start();
} catch (Throwable ex) {
logger.log(Level.SEVERE, "Failed to initialize Alarm System Interface " + ex.getMessage(), ex);
alarmSource = null;
}
// register ping tasks
initializePingTasks();
// handle monitoring removal task
final long timeInMs = enableHandleMonitoringDurationMins * 60L * 1000;
if (enableHandleMonitoring && enableHandleMonitoringDurationMins > 0) {
heartbeatTask.schedule(new TimerTask() {
@Override
public void run() {
try {
logHandleCleanup(timeInMs);
} catch (Throwable th) {
logger.log(Level.SEVERE, "Unexpected exception in handle log cleanup task.", th);
}
}
}, 0, timeInMs);
}
// start topology sort manager
topologySortManager = new ComponentInfoTopologicalSortManager(components, containers, activationPendingRWLock, pendingContainerShutdown, threadPool, logger);
if (prevayler == null)
statePersitenceFlag.set(false);
String enDis = statePersitenceFlag.get() ? "enabled" : "disabled";
logger.info("Manager initialized with state persistence " + enDis + ".");
}
use of com.cosylab.acs.maci.ComponentSpec 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 com.cosylab.acs.maci.ComponentSpec in project ACS by ACS-Community.
the class ManagerPrevaylerTest method dynamicComponentClientInstance.
private int dynamicComponentClientInstance(final String clientInstance) throws Throwable {
// simple trick to align all the threads
Thread.sleep(CLIENT_START_DELAY_MS);
TestClient client = new TestClient(clientInstance);
ClientInfo info = manager.login(client);
// all dynamic case
try {
for (int i = 0; i < COMPONENTS; i++) {
ComponentInfo componentInfo = manager.getDynamicComponent(info.getHandle(), new ComponentSpec(clientInstance + "-dynComponent-" + i, "java.lang.Object", "java.lang.Object", "DynContainer"), true);
assertTrue(componentInfo != null);
int nc = count.incrementAndGet();
if (nc % COUNT_REPORT_EVERY == 0)
System.out.println(nc + " components activated until now...");
}
} catch (Throwable ex) {
ex.printStackTrace();
fail();
}
return info.getHandle();
}
use of com.cosylab.acs.maci.ComponentSpec 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 com.cosylab.acs.maci.ComponentSpec 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