use of com.cosylab.acs.maci.NoResourcesException in project ACS by ACS-Community.
the class ManagerProxyImpl method restart_component.
/**
* Restarts an component.
* @param id identification of the caller. Called has to be an owner of the component.
* @param component_url CURL of the component to be restarted.
* @return CORBA reference of the restarted component, <code>null</code> if it fails.
*/
public Object restart_component(int id, String component_url) throws NoPermissionEx {
pendingRequests.incrementAndGet();
try {
// returned value
Object retVal = null;
// transform to CORBA specific
URI uri = null;
if (component_url != null)
uri = CURLHelper.createURI(component_url);
Component component = manager.restartComponent(id, uri);
// extract component CORBA reference
if (component != null)
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 (AcsJBadParameterEx bpe) {
reportException(bpe);
//throw bpe.toBadParameterEx();
throw new BAD_PARAM(bpe.getMessage());
} 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.NoResourcesException in project ACS by ACS-Community.
the class ManagerImplTest method testContainerShutdown.
public void testContainerShutdown() {
try {
manager.shutdownContainer(0, null, 0);
fail();
} catch (AcsJNoPermissionEx npe) {
fail("No permission");
} catch (BadParametersException bpe) {
System.out.println("This is OK: " + bpe.getMessage());
}
try {
manager.shutdownContainer(0, "test", 0);
fail();
} catch (AcsJNoPermissionEx npe) {
System.out.println("This is OK: " + npe.toString());
}
Client client = new TestClient(clientName);
ClientInfo info = null;
try {
info = manager.login(client);
} catch (AcsJNoPermissionEx e) {
fail();
}
try {
manager.shutdownContainer(info.getHandle(), "test", 0);
fail();
} catch (AcsJNoPermissionEx npe) {
System.out.println("This is OK: " + npe.toString());
}
Administrator admin = new TestAdministrator("shutdownAdmin");
ClientInfo info2 = null;
try {
info2 = manager.login(admin);
} catch (AcsJNoPermissionEx e) {
fail("No permission");
}
try {
manager.shutdownContainer(info2.getHandle(), null, 0);
fail();
} catch (AcsJNoPermissionEx npe) {
fail("No permission");
} catch (BadParametersException bpe) {
System.out.println("This is OK: " + bpe.getMessage());
}
try {
manager.shutdownContainer(info2.getHandle(), "invalid", 0);
fail();
} catch (AcsJNoPermissionEx npe) {
fail("No permission");
} catch (NoResourcesException nre) {
System.out.println("This is OK: " + nre.getMessage());
}
TestContainer container = new TestContainer("Container");
Map supportedComponents = new HashMap();
TestComponent mount1COB = new TestComponent("MOUNT1");
supportedComponents.put("MOUNT1", mount1COB);
container.setSupportedComponents(supportedComponents);
try {
ClientInfo containerInfo = manager.login(container);
} catch (AcsJNoPermissionEx e) {
fail("No permission");
}
try {
Thread.sleep(STARTUP_COBS_SLEEP_TIME_MS);
} catch (InterruptedException ie) {
}
// test activated Components
ComponentInfo[] infos = null;
try {
infos = manager.getComponentInfo(info.getHandle(), new int[0], "*", "*", true);
} catch (AcsJNoPermissionEx e) {
fail("No permission");
}
assertEquals(1, infos.length);
try {
manager.shutdownContainer(info.getHandle(), "Container", 0);
fail();
} catch (AcsJNoPermissionEx npe) {
System.out.println("This is OK: " + npe.toString());
}
try {
manager.shutdownContainer(info2.getHandle(), "Container", 1);
} catch (AcsJNoPermissionEx e) {
fail("No permission");
}
assertEquals(0, container.getActivatedComponents().size());
}
use of com.cosylab.acs.maci.NoResourcesException in project ACS by ACS-Community.
the class ManagerImpl method administratorLogin.
/**
* Administrator specific login method.
* @param name name of the administrator
* @param reply reply to authenticate method
* @param administrator administrator that is logging in
* @return ClientInfo client info. of newly logged administrator
*/
private ClientInfo administratorLogin(String name, AuthenticationData reply, Administrator administrator, long timeStamp, long executionId) throws AcsJNoPermissionEx {
assert (name != null);
assert (administrator != null);
TimerTaskClientInfo clientInfo = null;
synchronized (administrators) {
// check if administrator is already logged in,
// if it is, return existing info
int h = administrators.first();
while (h != 0) {
ClientInfo loggedAdministratorInfo = (ClientInfo) administrators.get(h);
if (administrator.equals(loggedAdministratorInfo.getClient()))
return loggedAdministratorInfo;
h = administrators.next(h);
}
// allocate new handle
// !!! ACID 2
Integer objHandle = (Integer) executeCommand(new AdministratorCommandAllocate());
int handle;
//int handle = administrators.allocate();
if (objHandle == null || (handle = objHandle.intValue()) == 0) {
NoResourcesException af = new NoResourcesException("Generation of new handle failed, too many administrators logged in.");
throw af;
}
// generate external handle
h = handle | ADMINISTRATOR_MASK;
// add generated key
h |= (random.nextInt(0x100)) << 16;
// create new client info
clientInfo = new TimerTaskClientInfo(h, name, administrator);
clientInfo.setAccessRights(AccessRights.REGISTER_COMPONENT | AccessRights.INTROSPECT_MANAGER | AccessRights.SHUTDOWN_SYSTEM);
// register administrator to the heartbeat manager
PingTimerTask task = new PingTimerTask(this, logger, clientInfo, null);
clientInfo.setTask(task);
heartbeatTask.schedule(task, administratorPingInterval, administratorPingInterval);
// !!! ACID - register AddAdministratorCommand
executeCommand(new AdministratorCommandSet(handle, clientInfo));
// store info
//administrators.set(handle, clientInfo);
}
// notify administrators about the login
notifyClientLogin(clientInfo, timeStamp, executionId);
logger.log(Level.INFO, "Administrator '" + name + "' logged in.");
return clientInfo;
}
use of com.cosylab.acs.maci.NoResourcesException in project ACS by ACS-Community.
the class ManagerImpl method login.
/**
* @see com.cosylab.acs.maci.Manager#login(Client)
*/
public ClientInfo login(Client reference) throws AcsJNoPermissionEx {
// check if already shutdown
if (shutdown.get()) {
// already shutdown
AcsJNoPermissionEx npe = new AcsJNoPermissionEx();
npe.setReason("Manager in shutdown state.");
throw npe;
}
if (reference == null) {
// BAD_PARAM
BadParametersException af = new BadParametersException("Non-null 'reference' expected.");
throw af;
}
/****************************************************************/
ClientInfo info = null;
try {
long executionId = generateExecutionId();
AuthenticationData reply = reference.authenticate(executionId, "Identify yourself");
if (reply == null) {
// BAD_PARAM
BadParametersException af = new BadParametersException("Invalid response to 'Client::authenticate()' method - non-null structure expected.");
throw af;
} else if (reply.getClientType() == null) {
// BAD_PARAM
BadParametersException af = new BadParametersException("Invalid response to 'Client::authenticate()' method - non-null client type expected.");
throw af;
} else if (reply.getImplLang() == null) {
// BAD_PARAM
BadParametersException af = new BadParametersException("Invalid response to 'Client::authenticate()' method - no-null implementation language expected.");
throw af;
}
// get client's name
String name = reference.name();
if (name == null) {
// BAD_PARAM
BadParametersException af = new BadParametersException("Invalid response to 'Client::name()' method - non-null string expected.");
throw af;
}
logger.log(Level.FINE, "'" + name + "' is logging in.");
final long timeStamp = reply.getTimeStamp() > 0 ? reply.getTimeStamp() : System.currentTimeMillis();
if (reply.getExecutionId() != 0)
executionId = generateExecutionId();
// delegate
switch(reply.getClientType()) {
// container
case CONTAINER:
if (reference instanceof Container) {
info = containerLogin(name, reply, (Container) reference, timeStamp, executionId);
} else {
// NO_PERMISSION
AcsJNoPermissionEx npe = new AcsJNoPermissionEx();
npe.setReason("Given reply to 'Client::authenticate()' method indicated container login, but given reference does not implement 'maci::Container' interface.");
npe.setID(name);
throw npe;
}
break;
// client
case CLIENT:
info = clientLogin(name, reply, reference, timeStamp, executionId);
break;
// supervisor (administrator)
case ADMINISTRATOR:
if (reference instanceof Administrator) {
info = administratorLogin(name, reply, (Administrator) reference, timeStamp, executionId);
} else {
// NO_PERMISSION
AcsJNoPermissionEx npe = new AcsJNoPermissionEx();
npe.setReason("Given reply to 'Client::authenticate()' method indicated administrator login, but given reference does not implement 'maci::Administrator' interface.");
npe.setID(name);
throw npe;
}
break;
default:
assert (false);
}
} catch (AcsJNoPermissionEx npe) {
throw npe;
} catch (BadParametersException bpe) {
throw bpe;
} catch (NoResourcesException nre) {
throw nre;
} catch (RemoteException re) {
// TODO @todo exception
RuntimeException rt = new RuntimeException("Exception caught while examining the client. Login rejected.", re);
throw rt;
} catch (Throwable ex) {
// TODO @todo exception
RuntimeException rt = new RuntimeException("Unexpected exception during login. Login rejected.", ex);
throw rt;
}
/****************************************************************/
logger.log(Level.FINE, "Client with handle '" + HandleHelper.toString(info.getHandle()) + "' has logged in.");
return info;
}
use of com.cosylab.acs.maci.NoResourcesException in project ACS by ACS-Community.
the class ManagerImpl method internalDeactivateComponent.
/**
* Internal method for deactivating components.
*
* @param name name of the component to be released.
*/
private void internalDeactivateComponent(String name) {
// try to acquire lock
String lockNotAcquiredCause = acquireSynchronizationObject(name, lockTimeout, "deactivate component " + name);
if (lockNotAcquiredCause == null) {
boolean releaseRWLock = false;
try {
// resolve componentInfo from curl
ComponentInfo componentInfo = null;
componentsLock.lock();
try {
int h = components.first();
while (h != 0) {
ComponentInfo ci = (ComponentInfo) components.get(h);
if (ci.getName().equals(name)) {
// a new owner detected, leave component activated
if (ci.getClients().size() > 0)
return;
componentInfo = ci;
break;
}
h = components.next(h);
}
} finally {
componentsLock.unlock();
}
// component is already gone, nothing to do
if (componentInfo == null)
return;
// try to acquire activation readers lock first
// NOTE: the locks are NOT reentrant
releaseRWLock = true;
activationPendingRWLock.readLock().lock();
try {
internalNoSyncDeactivateComponent(componentInfo);
} catch (Throwable th) {
// no handling, already logged
}
} finally {
if (releaseRWLock)
activationPendingRWLock.readLock().unlock();
releaseSynchronizationObject(name);
}
} else {
NoResourcesException nre = new NoResourcesException("Failed to obtain synchronization lock for component '" + name + "', possible deadlock; locked to '" + lockNotAcquiredCause + "'.");
throw nre;
}
}
Aggregations