use of alma.maciErrType.wrappers.AcsJNoPermissionEx in project ACS by ACS-Community.
the class ContainerServicesImpl method findComponents.
/**
* @see alma.acs.container.ContainerServices#findComponents(java.lang.String, java.lang.String)
*/
@Override
public String[] findComponents(String curlWildcard, String typeWildcard) throws AcsJContainerServicesEx {
if (curlWildcard == null) {
curlWildcard = "*";
}
if (typeWildcard == null) {
typeWildcard = "*";
}
String msgSpec = "curlWildcard='" + curlWildcard + "' and typeWildcard='" + typeWildcard + "'.";
if (m_logger.isLoggable(Level.FINER)) {
m_logger.finer("about to call Manager#get_component_info with " + msgSpec);
}
ComponentInfo[] components = null;
try {
components = m_acsManagerProxy.get_component_info(new int[0], curlWildcard, typeWildcard, false);
} catch (AcsJNoPermissionEx ex) {
m_logger.log(Level.FINE, "No permission to find components with " + msgSpec, ex);
AcsJContainerServicesEx ex2 = new AcsJContainerServicesEx(ex);
ex2.setContextInfo(msgSpec);
throw ex2;
} catch (Throwable thr) {
m_logger.log(Level.FINE, "Unexpected failure calling 'get_component_info' with " + msgSpec, thr);
AcsJContainerServicesEx ex = new AcsJContainerServicesEx(thr);
ex.setContextInfo(msgSpec);
throw ex;
}
ArrayList<String> curls = new ArrayList<String>();
if (components != null) {
for (int i = 0; i < components.length; i++) {
curls.add(components[i].name);
}
}
if (m_logger.isLoggable(Level.FINER)) {
m_logger.finer("received " + curls.size() + " curls from get_component_info.");
}
return curls.toArray(new String[curls.size()]);
}
use of alma.maciErrType.wrappers.AcsJNoPermissionEx 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 alma.maciErrType.wrappers.AcsJNoPermissionEx 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 alma.maciErrType.wrappers.AcsJNoPermissionEx 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 alma.maciErrType.wrappers.AcsJNoPermissionEx 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();
}
}
Aggregations