use of com.cosylab.acs.maci.BadParametersException 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.BadParametersException 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();
}
}
use of com.cosylab.acs.maci.BadParametersException in project ACS by ACS-Community.
the class ManagerProxyImpl method login.
/**
* Login to MACI.
* Containers, Clients and Administrative clients call this function
* first to identify themselves with the Manager. The Manager authenticates them
* (through the authenticate function), and assigns them access rights and a handle,
* through which they will identify themselves at subsequent calls to the Manager.
*
* @param reference A reference to the Client.
* @return A ClientInfo structure with handle (h) and access fields filled-in.
* If the client with this name did not logout prior to calling login,
* the components sequence in ClientInfo contains the handles of all components that
* the client was using. (For Containers, the components sequence contains
* handles of all components previously hosted by the Container.)
*/
public ClientInfo login(Client reference) throws NoPermissionEx {
pendingRequests.incrementAndGet();
try {
// client proxy
com.cosylab.acs.maci.Client clientProxy = null;
// create approperiate proxies
if (reference != null) {
if (reference._is_a(ContainerHelper.id())) {
clientProxy = new ContainerProxy(ContainerHelper.narrow(reference));
} else if (reference._is_a(SynchronousAdministratorHelper.id())) {
clientProxy = new SynchronousAdministratorProxy(SynchronousAdministratorHelper.narrow(reference));
} else if (reference._is_a(AdministratorHelper.id())) {
clientProxy = new AdministratorProxy(AdministratorHelper.narrow(reference));
} else if (reference._is_a(ClientHelper.id())) {
clientProxy = new ClientProxy(reference);
} else {
// this should never happen, but we are carefuly anyway
BadParametersException af = new BadParametersException("Given reference does not implement 'maci::Client' interface.");
reportException(af);
throw new BAD_PARAM(af.getMessage());
}
}
ClientInfo retVal = null;
com.cosylab.acs.maci.ClientInfo info = manager.login(clientProxy);
if (info != null)
retVal = new ClientInfo(info.getHandle(), ((ClientProxy) info.getClient()).getClient(), info.getComponents().toArray(), info.getName(), mapAccessRights(info.getAccessRights()));
return retVal;
} 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 (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.BadParametersException in project ACS by ACS-Community.
the class ManagerProxyImpl method get_default_component.
/**
* Returns the default component of specific type.
* @param id identification of the caller.
* @param type component type, IDL ID.
* @return <code>ComponentInfo</code> of requested component.
*/
public ComponentInfo get_default_component(int id, String type) throws NoPermissionEx, NoDefaultComponentEx, CannotGetComponentEx {
pendingRequests.incrementAndGet();
try {
// returned value
ComponentInfo retVal = null;
// transform to CORBA specific
com.cosylab.acs.maci.ComponentInfo info = manager.getDefaultComponent(id, type);
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 (NoDefaultComponentException ndce) {
NoDefaultComponentException hndce = new NoDefaultComponentException(ndce.getMessage(), ndce);
reportException(hndce);
// rethrow CORBA specific
throw new AcsJNoDefaultComponentEx().toNoDefaultComponentEx();
} 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 (AcsJNoPermissionEx npe) {
// rethrow CORBA specific
throw npe.toNoPermissionEx();
} 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();
}
}
use of com.cosylab.acs.maci.BadParametersException in project ACS by ACS-Community.
the class ManagerProxyImpl method get_component_non_sticky.
/**
* Get a component, do not activate it and also do not do any reference counting.
* The client represented by id (the handle)
* must have adequate access rights to access the Component. This is untrue of components:
* components always have unlimited access rights to other components.
*
* @param id Identification of the caller. If this is an invalid handle, or if the caller does not have enough access rights, a maciErrType::NoPermissionEx exception is raised.
* @param component_url CURL of the Component whose reference is to be retrieved.
* @return Reference to the Component.
*/
public Object get_component_non_sticky(int id, String component_url) throws NoPermissionEx, CannotGetComponentEx, ComponentNotAlreadyActivatedEx {
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.getComponentNonSticky(id, uri);
// extract Component CORBA reference
if (component != null)
retVal = (Object) component.getObject();
// @todo
if (component == null)
throw new AcsJComponentNotAlreadyActivatedEx();
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 (AcsJCannotGetComponentEx cgce) {
// rethrow CORBA specific
throw cgce.toCannotGetComponentEx();
} catch (AcsJComponentNotAlreadyActivatedEx cnaae) {
// rethrow CORBA specific
throw cnaae.toComponentNotAlreadyActivatedEx();
} 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();
}
}
Aggregations