use of alma.maciErrType.wrappers.AcsJInvalidComponentSpecEx in project ACS by ACS-Community.
the class ManagerImpl method getDynamicComponent.
/**
* @see com.cosylab.acs.maci.Manager#getDynamicComponent(int, com.cosylab.acs.maci.ComponentSpec, boolean)
*/
// TODO MF not supported
public ComponentInfo getDynamicComponent(int id, ComponentSpec componentSpec, boolean markAsDefault) throws AcsJCannotGetComponentEx, AcsJNoPermissionEx, AcsJIncompleteComponentSpecEx, AcsJInvalidComponentSpecEx, AcsJComponentSpecIncompatibleWithActiveComponentEx {
try {
// check if null
if (componentSpec == null) {
AcsJNullPointerEx ex = new AcsJNullPointerEx();
ex.setVariable("componentSpec");
throw ex;
}
// check componentSpec components are null
if (componentSpec.getName() == null) {
AcsJNullPointerEx ex = new AcsJNullPointerEx();
ex.setVariable("componentSpec.Name");
throw ex;
}
if (componentSpec.getType() == null) {
AcsJNullPointerEx ex = new AcsJNullPointerEx();
ex.setVariable("componentSpec.Type");
throw ex;
}
if (componentSpec.getCode() == null) {
AcsJNullPointerEx ex = new AcsJNullPointerEx();
ex.setVariable("componentSpec.Code");
throw ex;
}
if (componentSpec.getContainer() == null) {
AcsJNullPointerEx ex = new AcsJNullPointerEx();
ex.setVariable("componentSpec.Container");
throw ex;
}
// check for empty componentSpec.name
if (componentSpec.getName().length() == 0) {
AcsJBadParameterEx ex = new AcsJBadParameterEx();
ex.setParameter("componentSpec.Name");
ex.setParameterValue("EMPTY");
ex.setReason("Non empty Component Name expected");
throw ex;
}
} catch (AcsJNullPointerEx e) {
AcsJInvalidComponentSpecEx ex = new AcsJInvalidComponentSpecEx(e);
throw ex;
} catch (AcsJBadParameterEx e) {
AcsJInvalidComponentSpecEx ex = new AcsJInvalidComponentSpecEx(e);
throw ex;
}
// check handle and NONE permissions
// Throws AcsJNoPermissionEx that is let flying up
securityCheck(id, AccessRights.NONE);
/****************************************************************/
// Same exceptions fly up
ComponentInfo componentInfo = null;
try {
componentInfo = internalRequestDynamicComponent(id, componentSpec);
} catch (AcsJSyncLockFailedEx e) {
AcsJCannotGetComponentEx ex = new AcsJCannotGetComponentEx();
ex.setCURL(componentSpec.getName());
ex.setReason("Failed to get Synchronisation lock");
throw ex;
}
// update default components table
if (componentInfo != null && markAsDefault) {
synchronized (defaultComponents) {
// !!! ACID 3
executeCommand(new DefaultComponentCommandPut(componentInfo.getType(), componentInfo));
//defaultComponents.put(componentInfo.getType(), componentInfo.getName());
}
logger.log(Level.INFO, "'" + componentInfo.getName() + "' has been marked as a default component of type '" + componentInfo.getType() + "'.");
}
if (componentInfo == null) {
/**
* @todo Is it OK to get here? Always?
* This is a place where we have to check carefully.
*/
AcsJCannotGetComponentEx ex = new AcsJCannotGetComponentEx();
ex.setCURL(componentSpec.getName());
throw ex;
}
return componentInfo;
}
use of alma.maciErrType.wrappers.AcsJInvalidComponentSpecEx in project ACS by ACS-Community.
the class ManagerImplTest method testGetDynamicComponent.
/**
* Test getDynamicComponent.
*/
public void testGetDynamicComponent() {
try {
try {
manager.getDynamicComponent(0, null, false);
fail();
} catch (AcsJInvalidComponentSpecEx bpe) {
System.out.println("This is OK: " + bpe.toString());
} catch (AcsJComponentSpecIncompatibleWithActiveComponentEx e) {
fail("AcsJComponentSpecIncompatibleWithActiveComponentEx " + e.toString());
}
final ComponentSpec allAsterixCompSpec = new ComponentSpec(ComponentSpec.COMPSPEC_ANY, ComponentSpec.COMPSPEC_ANY, ComponentSpec.COMPSPEC_ANY, ComponentSpec.COMPSPEC_ANY);
try {
manager.getDynamicComponent(Integer.MAX_VALUE, allAsterixCompSpec, true);
fail();
} catch (AcsJNoPermissionEx npe) {
System.out.println("This is OK: " + npe.toString());
} catch (AcsJInvalidComponentSpecEx bpe) {
fail();
} catch (AcsJComponentSpecIncompatibleWithActiveComponentEx e) {
fail("AcsJComponentSpecIncompatibleWithActiveComponentEx");
}
try {
manager.getDynamicComponent(dummyHandle, allAsterixCompSpec, false);
fail();
} catch (AcsJNoPermissionEx npe) {
System.out.println("This is OK: " + npe.toString());
} catch (AcsJInvalidComponentSpecEx bpe) {
fail();
} catch (AcsJComponentSpecIncompatibleWithActiveComponentEx e) {
fail("AcsJComponentSpecIncompatibleWithActiveComponentEx");
}
TestClient client = new TestClient(clientName);
ClientInfo info = manager.login(client);
assertTrue(info.getHandle() != 0);
try {
manager.getDynamicComponent(info.getHandle(), null, true);
fail();
} catch (AcsJInvalidComponentSpecEx bpe) {
System.out.println("This is OK: " + bpe.toString());
} catch (AcsJComponentSpecIncompatibleWithActiveComponentEx e) {
fail("AcsJComponentSpecIncompatibleWithActiveComponentEx");
}
try {
manager.getDynamicComponent(info.getHandle(), new ComponentSpec(null, null, null, null), false);
fail();
} catch (AcsJInvalidComponentSpecEx ndce) {
System.out.println("This is OK: " + ndce.toString());
} catch (AcsJComponentSpecIncompatibleWithActiveComponentEx e) {
fail("AcsJComponentSpecIncompatibleWithActiveComponentEx");
}
try {
manager.getDynamicComponent(info.getHandle(), allAsterixCompSpec, false);
fail();
} catch (AcsJInvalidComponentSpecEx bpe) {
System.out.println("This is OK: " + bpe.toString());
} catch (AcsJIncompleteComponentSpecEx icse) {
fail();
} catch (AcsJComponentSpecIncompatibleWithActiveComponentEx e) {
fail("AcsJComponentSpecIncompatibleWithActiveComponentEx");
}
final ComponentSpec nameTypeIncomplete = new ComponentSpec(ComponentSpec.COMPSPEC_ANY, ComponentSpec.COMPSPEC_ANY, "PowerSupply", "IDL:acsexmpl/PS/PowerSupply:1.0");
try {
manager.getDynamicComponent(info.getHandle(), nameTypeIncomplete, false);
fail();
} catch (AcsJInvalidComponentSpecEx icse) {
System.out.println("This is OK: " + icse.toString());
} catch (AcsJIncompleteComponentSpecEx bpe) {
fail();
} catch (AcsJComponentSpecIncompatibleWithActiveComponentEx e) {
fail("AcsJComponentSpecIncompatibleWithActiveComponentEx");
}
// decoy container
TestContainer container = new TestContainer("Container");
Map supportedComponents = new HashMap();
TestComponent mount1COB = new TestComponent("MOUNT1");
supportedComponents.put("MOUNT1", mount1COB);
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) {
}
// Before ACS 6.0 this was expecting a null, now we get and exception
try {
ComponentInfo componentInfo = manager.getDynamicComponent(info.getHandle(), new ComponentSpec("dynComponent", "java.lang.Object", "java.lang.Object", "invalidContainer"), true);
fail();
} catch (AcsJCannotGetComponentEx ex) {
System.out.println("This is OK: " + ex.toString());
} catch (AcsJInvalidComponentSpecEx ex) {
fail();
} catch (AcsJComponentSpecIncompatibleWithActiveComponentEx e) {
fail("AcsJComponentSpecIncompatibleWithActiveComponentEx");
}
// all dynamic case
try {
ComponentInfo componentInfo = manager.getDynamicComponent(info.getHandle(), new ComponentSpec("dynComponent", "java.lang.Object", "java.lang.Object", "DynContainer"), true);
assertTrue(componentInfo != null);
assertTrue(componentInfo.getName().equals("dynComponent"));
assertEquals(dynContainerInfo.getHandle(), componentInfo.getContainer());
} catch (Exception ex) {
ex.printStackTrace();
fail();
}
ClientInfo info2 = manager.login(new TestClient("TestClient2"));
// obtain and release dynamic component in a normal way
try {
URI dynURI = new URI("dynComponent");
// obtain
StatusHolder status = new StatusHolder();
Component component = manager.getComponent(info2.getHandle(), dynURI, true, status);
assertNotNull(component);
assertEquals(ComponentStatus.COMPONENT_ACTIVATED, status.getStatus());
// release
int owners = manager.releaseComponent(info2.getHandle(), dynURI);
assertEquals(1, owners);
} catch (Exception ex) {
fail();
}
// override container case
try {
ComponentInfo componentInfo = manager.getDynamicComponent(info.getHandle(), new ComponentSpec("MOUNT2", ComponentSpec.COMPSPEC_ANY, ComponentSpec.COMPSPEC_ANY, "DynContainer"), true);
assertTrue(componentInfo != null);
assertTrue(componentInfo.getName().equals("MOUNT2"));
assertEquals(dynContainerInfo.getHandle(), componentInfo.getContainer());
} catch (Exception ex) {
fail();
}
// override all other fields case but MOUNT2 is already activated
try {
manager.getDynamicComponent(info.getHandle(), new ComponentSpec("MOUNT2", "java.lang.Object", "java.lang.Object", "DynContainer"), true);
fail();
} catch (AcsJComponentSpecIncompatibleWithActiveComponentEx ciwace) {
System.out.println("This is OK: " + ciwace.toString());
} catch (AcsJInvalidComponentSpecEx bpe) {
fail();
}
// ordinary activation case but MOUNT2 is already activated
URI mount2 = null;
try {
mount2 = CURLHelper.createURI("MOUNT2");
StatusHolder status = new StatusHolder();
Component component = manager.getComponent(info.getHandle(), mount2, true, status);
assertNotNull(null, component);
assertEquals(ComponentStatus.COMPONENT_ACTIVATED, status.getStatus());
} catch (Exception ex) {
fail();
}
// default component test, should be overriden MOUNT2
try {
ComponentInfo componentInfo = manager.getDefaultComponent(info.getHandle(), "IDL:alma/MOUNT_ACS/Mount:1.0");
assertTrue(componentInfo != null);
assertTrue(componentInfo.getName().equals("MOUNT2"));
assertEquals(dynContainerInfo.getHandle(), componentInfo.getContainer());
} catch (Exception ex) {
fail();
}
// release mount2
try {
manager.releaseComponent(info.getHandle(), mount2);
} catch (AcsJBadParameterEx e) {
fail();
}
// default component test, should still be overriden MOUNT2
try {
ComponentInfo componentInfo = manager.getDefaultComponent(info.getHandle(), "IDL:alma/MOUNT_ACS/Mount:1.0");
assertTrue(componentInfo != null);
assertTrue(componentInfo.getName().equals("MOUNT2"));
assertEquals(dynContainerInfo.getHandle(), componentInfo.getContainer());
} catch (Exception ex) {
fail();
}
// release mount2
try {
manager.releaseComponent(info.getHandle(), mount2);
} catch (AcsJBadParameterEx e) {
fail();
}
// type override
try {
manager.getDynamicComponent(info.getHandle(), new ComponentSpec("MOUNT1", ComponentSpec.COMPSPEC_ANY, "java.lang.Object", ComponentSpec.COMPSPEC_ANY), true);
fail();
} catch (AcsJComponentSpecIncompatibleWithActiveComponentEx ciwace) {
System.out.println("This is OK: " + ciwace.toString());
} catch (AcsJInvalidComponentSpecEx ciwace) {
fail();
}
// * name generation test w/o CDB lookup
try {
ComponentInfo componentInfo = manager.getDynamicComponent(info.getHandle(), new ComponentSpec(ComponentSpec.COMPSPEC_ANY, "IDL:alma/PS/PowerSupply:1.0", "java.lang.Object", "DynContainer"), false);
assertTrue(componentInfo != null);
//assertTrue(componentInfo.getName().startsWith("IDL:alma/PS/PowerSupply:1.0"));
assertTrue(componentInfo.getName().startsWith("IDL:alma_PS_PowerSupply:1.0"));
assertEquals(dynContainerInfo.getHandle(), componentInfo.getContainer());
manager.releaseComponent(info.getHandle(), CURLHelper.createURI(componentInfo.getName()));
} catch (Exception ex) {
fail();
}
// prefix* name generation test w/o CDB lookup
try {
ComponentInfo componentInfo = manager.getDynamicComponent(info.getHandle(), new ComponentSpec("PREFIX" + ComponentSpec.COMPSPEC_ANY, "IDL:alma/PS/PowerSupply:1.0", "java.lang.Object", "DynContainer"), false);
assertTrue(componentInfo != null);
assertTrue(componentInfo.getName().startsWith("PREFIX"));
assertEquals(dynContainerInfo.getHandle(), componentInfo.getContainer());
manager.releaseComponent(info.getHandle(), CURLHelper.createURI(componentInfo.getName()));
} catch (Exception ex) {
fail();
}
// * name generation test w/o CDB lookup, * container -> should fail since there is no load balancing
try {
manager.getDynamicComponent(info.getHandle(), new ComponentSpec(ComponentSpec.COMPSPEC_ANY, "IDL:alma/newDevice/newPowerSupply:1.0", "java.lang.Object", ComponentSpec.COMPSPEC_ANY), false);
fail();
} catch (AcsJInvalidComponentSpecEx icsex) {
System.out.println("This is OK: " + icsex.toString());
} catch (Exception ex) {
fail();
}
// (*, type) and name generation test w/ container override
try {
ComponentInfo componentInfo = manager.getDynamicComponent(info.getHandle(), new ComponentSpec(ComponentSpec.COMPSPEC_ANY, "IDL:alma/PS/PowerSupply:1.0", ComponentSpec.COMPSPEC_ANY, "DynContainer"), true);
assertTrue(componentInfo != null);
//assertTrue(componentInfo.getName().startsWith("IDL:alma/PS/PowerSupply:1.0"));
assertTrue(componentInfo.getName().startsWith("IDL:alma_PS_PowerSupply:1.0"));
assertEquals(dynContainerInfo.getHandle(), componentInfo.getContainer());
manager.releaseComponent(info.getHandle(), CURLHelper.createURI(componentInfo.getName()));
} catch (Exception ex) {
fail();
}
// (name, type) - component with given name, name is exist in CDB; w/ container override
try {
ComponentInfo componentInfo = manager.getDynamicComponent(info.getHandle(), new ComponentSpec("PBEND_B_02", "IDL:alma/PS/PowerSupply:1.0", ComponentSpec.COMPSPEC_ANY, "DynContainer"), true);
assertTrue(componentInfo != null);
assertTrue(componentInfo.getName().equals("PBEND_B_02"));
assertEquals(dynContainerInfo.getHandle(), componentInfo.getContainer());
manager.releaseComponent(info.getHandle(), CURLHelper.createURI(componentInfo.getName()));
} catch (Exception ex) {
fail();
}
// (name, type) - component with given name, name does not exist in CDB; w/ container override
try {
ComponentInfo componentInfo = manager.getDynamicComponent(info.getHandle(), new ComponentSpec("NAME_OVERRIDE", "IDL:alma/PS/PowerSupply:1.0", ComponentSpec.COMPSPEC_ANY, "DynContainer"), true);
assertTrue(componentInfo != null);
assertTrue(componentInfo.getName().equals("NAME_OVERRIDE"));
assertEquals(dynContainerInfo.getHandle(), componentInfo.getContainer());
manager.releaseComponent(info.getHandle(), CURLHelper.createURI(componentInfo.getName()));
} catch (Exception ex) {
fail();
}
// (name, type) - but type does not exist in CDB (there is not type override)
try {
manager.getDynamicComponent(info.getHandle(), new ComponentSpec("NAME_OVERRIDE", "IDL:alma/PS/RampedPowerSupply:1.0", ComponentSpec.COMPSPEC_ANY, ComponentSpec.COMPSPEC_ANY), true);
fail();
} catch (AcsJInvalidComponentSpecEx icse) {
System.out.println("This is OK: " + icse.toString());
} catch (AcsJComponentSpecIncompatibleWithActiveComponentEx e) {
fail("AcsJComponentSpecIncompatibleWithActiveComponentEx");
}
// (*, type) - but type does not exist in CDB (there is not type override)
try {
manager.getDynamicComponent(info.getHandle(), new ComponentSpec(ComponentSpec.COMPSPEC_ANY, "IDL:alma/PS/RampedPowerSupply:1.0", ComponentSpec.COMPSPEC_ANY, ComponentSpec.COMPSPEC_ANY), true);
fail();
} catch (AcsJInvalidComponentSpecEx icse) {
System.out.println("This is OK: " + icse.toString());
} catch (AcsJComponentSpecIncompatibleWithActiveComponentEx e) {
fail("AcsJComponentSpecIncompatibleWithActiveComponentEx");
}
// activate_component_async that does not respond test
dynContainer.setIgnoreActivateComponentAsync(true);
// activate_component_async that does not respond test
// timeout test
manager.setLockTimeout(3 * SLEEP_TIME_MS);
try {
dynContainer.setIgnoreActivateComponentAsync(true);
manager.getDynamicComponent(info.getHandle(), new ComponentSpec("activate_component_async_will_never_respond", "IDL:alma/PS/PowerSupply:1.0", "java.lang.Object", "DynContainer"), false);
fail();
} catch (AcsJCannotGetComponentEx cgc) {
// ok
} catch (Exception ex) {
fail();
}
final AtomicLong logoutTime = new AtomicLong();
// and container logs out
// shoud react quicker
manager.setLockTimeout(10 * SLEEP_TIME_MS);
try {
final ClientInfo dci = dynContainerInfo;
new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(SLEEP_TIME_MS);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
logoutTime.set(System.currentTimeMillis());
try {
manager.logout(dci.getHandle());
} catch (AcsJNoPermissionEx e) {
fail();
}
}
}).start();
manager.getDynamicComponent(info.getHandle(), new ComponentSpec("activate_component_async_will_never_respond_cont_logout", "IDL:alma/PS/PowerSupply:1.0", "java.lang.Object", "DynContainer"), false);
fail();
} catch (AcsJCannotGetComponentEx cgc) {
long now = System.currentTimeMillis();
long diff = now - logoutTime.get();
// logout did not trigger component failed to activate
assertTrue(diff < SLEEP_TIME_MS);
} catch (Exception ex) {
fail();
}
try {
Thread.sleep(SLEEP_TIME_MS);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (AcsJNoPermissionEx e) {
fail("No permission");
/**
* @todo I would like to remove all these exceptions
* and catch them above
*/
} catch (AcsJCannotGetComponentEx e) {
fail("AcsJCannotGetComponentEx");
} catch (AcsJIncompleteComponentSpecEx e) {
fail("AcsJIncompleteComponentSpecEx");
}
}
use of alma.maciErrType.wrappers.AcsJInvalidComponentSpecEx in project ACS by ACS-Community.
the class ManagerProxyImpl method get_dynamic_component.
/**
* Activation of an dynamic 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.
* @return <code>ComponentInfo</code> of requested component.
*/
public ComponentInfo get_dynamic_component(int id, si.ijs.maci.ComponentSpec c, boolean mark_as_default) 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);
*/
// @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.getDynamicComponent(id, componentSpec, mark_as_default);
// 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);
hbpe.caughtIn(this, "get_dynamic_component");
hbpe.putValue("c.component_name", c.component_name);
// exception service will handle this
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) {
reportException(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