use of com.cosylab.acs.maci.Client 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.Client in project ACS by ACS-Community.
the class ManagerImpl method administratorLogout.
/**
* Administrator specific logout method
* @param id handle of the administrators.
* @param pingFailed flag indicating that ping has failed (i.e. is the reason of this logout).
*/
private void administratorLogout(int id, boolean pingFailed) {
TimerTaskClientInfo clientInfo = null;
int[] componentsArray = null;
synchronized (administrators) {
int handle = id & HANDLE_MASK;
// already logged out
if (!administrators.isAllocated(handle))
return;
clientInfo = (TimerTaskClientInfo) administrators.get(handle);
// !!! ACID - RemoveAdministratorCommand
executeCommand(new AdministratorCommandDeallocate(handle, id, pingFailed ? WhyUnloadedReason.DISAPPEARED : WhyUnloadedReason.REMOVED));
// remove
//administrators.deallocate(handle);
componentsArray = clientInfo.getComponents().toArray();
}
// deregister client from the heartbeat manager
clientInfo.getTask().cancel();
// spawn another task which will release all clientInfo.getComponents()
threadPool.execute(new ReleaseComponentTask(clientInfo.getHandle(), componentsArray));
/// TODO !!!!!!!!!!!!!! no more handle -> componentInfo data
// notify administrators about the logout
notifyClientLogout(clientInfo, System.currentTimeMillis());
Client client = clientInfo.getClient();
if (client != null)
client.release();
logger.log(Level.INFO, "Administrator '" + clientInfo.getName() + "' logged out.");
}
use of com.cosylab.acs.maci.Client in project ACS by ACS-Community.
the class ManagerImpl method clientLogout.
/**
* Client specific logout method
* @param id handle of the client.
* @param pingFailed flag indicating that ping has failed (i.e. is the reason of this logout).
*/
private void clientLogout(int id, boolean pingFailed) {
TimerTaskClientInfo clientInfo = null;
int[] componentsArray = null;
synchronized (clients) {
int handle = id & HANDLE_MASK;
// already logged out
if (!clients.isAllocated(handle))
return;
clientInfo = (TimerTaskClientInfo) clients.get(handle);
// !!! ACID - RemoveClientCommand
executeCommand(new ClientCommandDeallocate(handle, id, pingFailed ? WhyUnloadedReason.DISAPPEARED : WhyUnloadedReason.REMOVED));
// remove
//clients.deallocate(handle);
componentsArray = clientInfo.getComponents().toArray();
}
// deregister client from the heartbeat manager
clientInfo.getTask().cancel();
// spawn another task which will release all clientInfo.getComponents()
threadPool.execute(new ReleaseComponentTask(clientInfo.getHandle(), componentsArray));
//internalReleaseComponents(components to be released, owners IntArray)
//internalReleaseComponents(clientInfo.getComponents(), clientInfo.getComponents())
/// TODO !!!!!!!!!!!!!! no more handle -> componentInfo data
// notify administrators about the logout
notifyClientLogout(clientInfo, System.currentTimeMillis());
Client client = clientInfo.getClient();
if (client != null)
client.release();
logger.log(Level.INFO, "Client '" + clientInfo.getName() + "' logged out.");
}
use of com.cosylab.acs.maci.Client in project ACS by ACS-Community.
the class ManagerImplTest method testLogin.
public void testLogin() {
// test null
try {
manager.login(null);
fail();
} catch (AcsJNoPermissionEx npe) {
fail("No permission");
} catch (BadParametersException bpe) {
System.out.println("This is OK: " + bpe.getMessage());
}
// test null name
try {
manager.login(new TestClient(null));
fail();
} catch (AcsJNoPermissionEx npe) {
fail("No permission");
} catch (BadParametersException bpe) {
System.out.println("This is OK: " + bpe.getMessage());
}
// test null autheticate
try {
manager.login(new TestClient("null-auth", null));
fail();
} catch (AcsJNoPermissionEx npe) {
fail("No permission");
} catch (BadParametersException bpe) {
System.out.println("This is OK: " + bpe.getMessage());
}
// test invalid autheticate
try {
manager.login(new TestClient("container-invalid-auth", ClientType.ADMINISTRATOR));
fail();
} catch (AcsJNoPermissionEx npe) {
System.out.println("This is OK: " + npe.toString());
}
// test wrong container ImplLang (CDB vs reported by authenticate method)
try {
manager.login(new TestContainer("PyContainer", ClientType.CONTAINER, ImplLang.cpp, false));
fail();
} catch (AcsJNoPermissionEx npe) {
System.out.println("This is OK: " + npe.toString());
}
//test client login
Client client = new TestClient(clientName);
ClientInfo info = null;
try {
info = manager.login(client);
} catch (AcsJNoPermissionEx e) {
fail("No permission");
}
assertNotNull(info);
assertTrue((info.getHandle() & HandleConstants.CLIENT_MASK) == HandleConstants.CLIENT_MASK);
assertEquals(info.getClient(), client);
//test duplicate login
ClientInfo info2 = null;
try {
info2 = manager.login(client);
} catch (AcsJNoPermissionEx e) {
fail("No permission");
}
assertNotNull(info2);
assertEquals(info, info2);
/*
// THIS TAKES WAY TOO MUCH TIME
// DoS attack, there should be no handle left...
try
{
Client differentClient = new TestAlwaysNotEqualClient("different");
for (int i=0; i<HandleConstants.HANDLE_MASK-1; i++)
{
System.out.println(i);
manager.login(differentClient);
}
fail();
}
catch (NoResourcesException nre)
{
System.out.println("This is OK: "+nre.getMessage());
}
*/
//test administrator login
Administrator administrator = new TestAdministrator(administratorName);
try {
info = manager.login(administrator);
} catch (AcsJNoPermissionEx e) {
fail("No permission");
}
assertNotNull(info);
assertTrue((info.getHandle() & HandleConstants.ADMINISTRATOR_MASK) == HandleConstants.ADMINISTRATOR_MASK);
assertEquals(info.getClient(), administrator);
//test duplicate login
try {
info2 = manager.login(administrator);
} catch (AcsJNoPermissionEx e) {
fail("No permission");
}
assertNotNull(info2);
assertEquals(info, info2);
//test container login
TestContainer container = new TestContainer(containerName);
try {
info = manager.login(container);
} catch (AcsJNoPermissionEx e) {
fail("No permission");
}
assertNotNull(info);
assertTrue((info.getHandle() & HandleConstants.CONTAINER_MASK) == HandleConstants.CONTAINER_MASK);
assertEquals(info.getClient(), container);
//test duplicate login (same instance) - allowed
try {
info2 = manager.login(container);
} catch (AcsJNoPermissionEx e) {
fail("No permission");
}
assertNotNull(info2);
assertEquals(info.getHandle(), info2.getHandle());
container.setHandle(info2.getHandle());
//test duplicate login (same instance name, previous container alive) - reject
TestContainer containerSameName = new TestContainer(containerName);
try {
info2 = manager.login(containerSameName);
fail("No permission expected");
} catch (AcsJNoPermissionEx e) {
System.out.println("This is OK: " + e.toString());
}
// ... now make first instance return handle 0
// this should allow the login
container.setHandle(0);
try {
info2 = manager.login(containerSameName);
} catch (AcsJNoPermissionEx e) {
fail("No permission");
}
assertNotNull(info2);
assertEquals(info.getHandle(), info2.getHandle());
// wait for some time, so that manager reports passes postponed start-up component activation
try {
Thread.sleep(STARTUP_COBS_SLEEP_TIME_MS);
} catch (InterruptedException ie) {
}
}
Aggregations