use of alma.maciErrType.wrappers.AcsJNoPermissionEx 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 alma.maciErrType.wrappers.AcsJNoPermissionEx in project ACS by ACS-Community.
the class ManagerImpl method internalNoSyncReleaseComponent.
/**
* Internal method for releasing components.
*
* @param owner owner of the component.
* @param h handle of the component to be released.
* @param force force deactivate, if still has owners then component will be made unavailable.
* @return Number of clients that are still using the component after the operation completed.
*/
private ReleaseComponentResult internalNoSyncReleaseComponent(int owner, int h, boolean force) throws AcsJNoPermissionEx {
int handle = h & HANDLE_MASK;
int owners = 0;
ComponentInfo componentInfo = null;
componentsLock.lock();
try {
if (components.isAllocated(handle))
componentInfo = (ComponentInfo) components.get(handle);
if (componentInfo == null || componentInfo.getHandle() != h) {
// invalid component handle
BadParametersException af = new BadParametersException("Invalid component handle.");
throw af;
}
// remove ownership of the component
if (!componentInfo.getClients().contains(owner)) {
if (!force) {
// not an owner
AcsJNoPermissionEx npe = new AcsJNoPermissionEx();
npe.setReason("Unregistering component that client does not own.");
npe.setID(HandleHelper.toString(owner));
npe.setProtectedResource(componentInfo.getName());
throw npe;
}
} else {
// ACID - !!!
// remove client/component as an owner
executeCommand(new ComponentCommandClientRemove(componentInfo.getHandle() & HANDLE_MASK, owner));
// remove component from client component list
if (owner != this.getHandle())
removeComponentOwner(componentInfo.getHandle(), owner);
}
owners = componentInfo.getClients().size();
if (owners == 0) {
// there is not owner to be unavailable for
synchronized (unavailableComponents) {
if (unavailableComponents.containsKey(componentInfo.getName())) {
// !!! ACID
executeCommand(new UnavailableComponentCommandRemove(componentInfo.getName()));
//unavailableComponents.remove(componentInfo.getName());
}
}
}
} finally {
componentsLock.unlock();
}
/****************** component deactivation ******************/
ReleaseComponentResult result = new ReleaseComponentResult(owners, null);
// there is no owners of the component, deactivate it
if (force) {
try {
internalNoSyncDeactivateComponent(componentInfo);
} catch (Throwable th) {
result.exception = th;
}
} else if (owners == 0) {
int keepAliveTime = RELEASE_IMMEDIATELY;
String name = componentInfo.getName();
boolean isOtherDomainComponent = name.startsWith(CURL_URI_SCHEMA);
if (!isOtherDomainComponent) {
keepAliveTime = componentInfo.getKeepAliveTime();
if (keepAliveTime == RELEASE_TIME_UNDEFINED) {
// when info is passed from the container
DAOProxy dao = getComponentsDAOProxy();
if (dao != null)
keepAliveTime = readLongCharacteristics(dao, name + "/KeepAliveTime", RELEASE_IMMEDIATELY, true);
else
keepAliveTime = RELEASE_IMMEDIATELY;
}
}
if (keepAliveTime == 0) {
try {
internalNoSyncDeactivateComponent(componentInfo);
} catch (Throwable th) {
result.exception = th;
}
} else if (keepAliveTime > 0)
delayedDeactivationTask.schedule(new DeactivateComponentTask(name), keepAliveTime * 1000);
// negative means immortal, however this could not happen since immortal
// components have manager as an owner
}
/// TODO !!!!!!!!!!!!!! no more handle -> componentInfo data
// notify administrators about the release request
notifyComponentReleased(new int[] { owner }, new int[] { h }, System.currentTimeMillis());
logger.log(Level.FINE, "Component '" + componentInfo.getName() + "' (" + HandleHelper.toString(componentInfo.getHandle()) + ") released.");
// component deactivated
if (owners == 0 || force) {
topologySortManager.notifyTopologyChange(componentInfo.getContainer());
} else if ((owner & TYPE_MASK) == COMPONENT_MASK) {
// component dependency changed...
// notify about the change (only if on the same container)...
// on complete system shutdown sort will be done anyway
ComponentInfo ownerComponentInfo = getComponentInfo(owner);
if (ownerComponentInfo != null && ownerComponentInfo.getContainerName() != null && ownerComponentInfo.getContainerName().equals(componentInfo.getContainerName()))
topologySortManager.notifyTopologyChange(componentInfo.getContainer());
}
return result;
}
use of alma.maciErrType.wrappers.AcsJNoPermissionEx 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 alma.maciErrType.wrappers.AcsJNoPermissionEx in project ACS by ACS-Community.
the class ManagerImplTest method testRestartComponent.
public void testRestartComponent() {
try {
try {
manager.restartComponent(0, null);
fail();
} catch (AcsJBadParameterEx bpe) {
System.out.println("This is OK: null parameter");
}
try {
manager.restartComponent(Integer.MAX_VALUE, null);
fail();
} catch (AcsJBadParameterEx bpe) {
System.out.println("This is OK: null parameter");
}
try {
manager.restartComponent(dummyHandle, dummyURI);
fail();
} catch (AcsJNoPermissionEx npe) {
System.out.println("This is OK: " + npe.toString());
} catch (AcsJBadParameterEx bpe) {
fail();
}
TestClient client = new TestClient(clientName);
ClientInfo info = manager.login(client);
assertTrue(info.getHandle() != 0);
try {
manager.restartComponent(info.getHandle(), null);
fail();
} catch (AcsJBadParameterEx bpe) {
System.out.println("This is OK: null parameter");
}
URI mount = null;
try {
mount = new URI("MOUNT3");
Component component = manager.restartComponent(info.getHandle(), mount);
assertEquals(null, component);
} catch (AcsJBadParameterEx bpe) {
fail();
} catch (URISyntaxException usi) {
fail();
}
TestContainer container = new TestContainer("Container");
Map supportedComponents = new HashMap();
Component mount3COB = new TestComponent("MOUNT3");
supportedComponents.put("MOUNT3", mount3COB);
container.setSupportedComponents(supportedComponents);
/*ClientInfo containerInfo = */
manager.login(container);
// activate
try {
StatusHolder status = new StatusHolder();
Component ref = manager.getComponent(info.getHandle(), mount, true, status);
assertEquals(mount3COB, ref);
assertEquals(ComponentStatus.COMPONENT_ACTIVATED, status.getStatus());
} catch (Exception ex) {
fail();
}
// restart
try {
Component returnedComponent = manager.restartComponent(info.getHandle(), mount);
assertEquals(mount3COB, returnedComponent);
} catch (Exception ex) {
fail();
}
// no owner client test
TestClient client2 = new TestClient("thief");
ClientInfo info2 = manager.login(client2);
assertTrue(info2.getHandle() != 0);
try {
manager.restartComponent(info2.getHandle(), mount);
fail();
} catch (AcsJNoPermissionEx npe) {
System.out.println("This is OK: " + npe.toString());
} catch (AcsJBadParameterEx bpe) {
fail();
}
} catch (AcsJNoPermissionEx e) {
fail("No permission");
}
}
use of alma.maciErrType.wrappers.AcsJNoPermissionEx 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");
}
}
Aggregations