use of alma.ACSErrTypeCommon.wrappers.AcsJBadParameterEx in project ACS by ACS-Community.
the class ManagerImplTest method testUnregisterComponent.
public void testUnregisterComponent() {
//test invalid
try {
manager.unregisterComponent(0, 0);
fail();
} catch (AcsJNoPermissionEx npe) {
System.out.println("This is OK: " + npe.toString());
} catch (AcsJBadParameterEx bpe) {
fail();
}
//test invalid
try {
manager.unregisterComponent(Integer.MAX_VALUE, 0);
fail();
} catch (AcsJNoPermissionEx npe) {
System.out.println("This is OK: " + npe.toString());
} catch (AcsJBadParameterEx bpe) {
fail();
}
//test invalid
try {
manager.unregisterComponent(dummyHandle, 0);
fail();
} catch (AcsJNoPermissionEx npe) {
System.out.println("This is OK: " + npe.toString());
} catch (AcsJBadParameterEx bpe) {
fail();
}
//test invalid
try {
manager.unregisterComponent(dummyHandle, Integer.MAX_VALUE);
fail();
} catch (AcsJNoPermissionEx npe) {
System.out.println("This is OK: " + npe.toString());
} catch (AcsJBadParameterEx bpe) {
fail();
}
try {
//unregister valid
ClientInfo info = manager.login(new TestClient(anotherName));
int handle = 0;
try {
handle = manager.registerComponent(info.getHandle(), dummyURI, type, new TestComponent(cobName));
} catch (AcsJBadParameterEx e) {
fail();
}
try {
manager.unregisterComponent(info.getHandle(), handle);
} catch (AcsJBadParameterEx e) {
fail();
}
//duplicate unregistration
try {
manager.unregisterComponent(info.getHandle(), handle);
fail();
} catch (AcsJBadParameterEx bpe) {
System.out.println("This is OK: duplicate unregistration " + bpe.toString());
}
manager.logout(info.getHandle());
} catch (AcsJNoPermissionEx e) {
e.printStackTrace();
fail("No permission");
}
}
use of alma.ACSErrTypeCommon.wrappers.AcsJBadParameterEx in project ACS by ACS-Community.
the class ManagerImplTest method testForceReleaseComponent.
public void testForceReleaseComponent() {
try {
try {
manager.forceReleaseComponent(0, null);
fail();
} catch (AcsJBadParameterEx bpe) {
System.out.println("This is OK: null parameter");
}
try {
manager.forceReleaseComponent(Integer.MAX_VALUE, null);
fail();
} catch (AcsJBadParameterEx bpe) {
System.out.println("This is OK: null parameter");
}
try {
manager.forceReleaseComponent(dummyHandle, dummyURI);
fail();
} catch (AcsJNoPermissionEx npe) {
System.out.println("This is OK: " + npe.toString());
} catch (AcsJBadParameterEx bpe) {
fail();
}
TestAdministrator admin = new TestAdministrator(administratorName);
ClientInfo adminInfo = manager.login(admin);
assertTrue(adminInfo.getHandle() != 0);
TestClient client = new TestClient(clientName);
ClientInfo info = manager.login(client);
assertTrue(info.getHandle() != 0);
TestClient client2 = new TestClient(clientName + "2");
ClientInfo info2 = manager.login(client2);
assertTrue(info2.getHandle() != 0);
TestContainer container = new TestContainer("Container");
Map supportedComponents = new HashMap();
Component mount1COB = new TestComponent("MOUNT1");
Component mount4COB = new TestComponent("MOUNT4");
supportedComponents.put("MOUNT1", mount1COB);
supportedComponents.put("MOUNT4", mount4COB);
container.setSupportedComponents(supportedComponents);
ClientInfo containerInfo = manager.login(container);
// client activate
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();
}
// client2 activate
try {
StatusHolder status = new StatusHolder();
Component ref = manager.getComponent(info2.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)
ComponentInfo[] infos = manager.getComponentInfo(info.getHandle(), new int[0], "*", "*", true);
assertEquals(2, infos.length);
/*
// test forceful release (no permission - no admin)
try
{
manager.forceReleaseComponent(info.getHandle(), mount4);
fail();
}
catch (AcsJNoPermissionEx npe)
{
System.out.println("This is OK: "+npe.toString());
}
*/
// TODO tmp - due to Heiko's hack
System.out.println("This is OK: Insufficient rights.");
// test forceful release
int clients;
try {
clients = manager.forceReleaseComponent(adminInfo.getHandle(), mount4);
assertEquals(2, clients);
} catch (AcsJBadParameterEx e) {
fail();
}
// there should be only one component activated (MOUNT1)
infos = manager.getComponentInfo(info.getHandle(), new int[0], "*", "*", true);
assertEquals(1, infos.length);
// admin activate
try {
StatusHolder status = new StatusHolder();
Component ref = manager.getComponent(adminInfo.getHandle(), mount4, true, status);
assertEquals(mount4COB, ref);
assertEquals(ComponentStatus.COMPONENT_ACTIVATED, status.getStatus());
} catch (Exception ex) {
fail();
}
// there should be two components activated (MOUNT1 and MOUNT4)
infos = manager.getComponentInfo(info.getHandle(), new int[0], "*", "*", true);
assertEquals(2, infos.length);
try {
clients = manager.releaseComponent(adminInfo.getHandle(), mount4);
assertEquals(2, clients);
} catch (AcsJBadParameterEx e) {
fail();
}
// there should be two components activated (MOUNT1 and MOUNT4)
infos = manager.getComponentInfo(info.getHandle(), new int[0], "*", "*", true);
assertEquals(2, infos.length);
// there should be two components activated (MOUNT1 and MOUNT4)
infos = manager.getComponentInfo(info.getHandle(), new int[0], "MOUNT4", "*", true);
assertEquals(1, infos.length);
IntArray compClients = infos[0].getClients();
assertEquals(2, compClients.size());
assertTrue(compClients.contains(info.getHandle()));
assertTrue(compClients.contains(info2.getHandle()));
} catch (AcsJNoPermissionEx e) {
fail("No permission");
}
}
use of alma.ACSErrTypeCommon.wrappers.AcsJBadParameterEx in project ACS by ACS-Community.
the class AnyAide method complexObjectToCorbaAny.
/**
* Converts a complex CORBA-based object to a CORBA any.
*
* @param obj
* A complex CORBA-based object such as a user-defined IDL struct.
* @return A CORBA any containing obj.
* @throws AcsJException
* if any problem occurs with the conversion.
*/
public Any complexObjectToCorbaAny(IDLEntity obj) throws AcsJException {
if (obj == null) {
Throwable cause = new Throwable("Method arg 'obj' was null");
throw new AcsJBadParameterEx(cause);
}
Any retVal = m_containerServices.getAdvancedContainerServices().getAny();
// ------
Class structHelperClass = null;
// actually looks like a CORBA type.
try {
// This is the CORBA helper class which is capable of inserting/extracting data from CORBA Anys.
structHelperClass = Class.forName(obj.getClass().getName() + "Helper");
} catch (Exception e) {
// If what's above fails...then the developer has specified a native Java
// class which has nothing to do with CORBA.
String msg = "The non-CORBA class '" + obj.getClass().getName() + "' cannot be converted to a CORBA Any.";
Throwable cause = new Throwable(msg);
m_logger.warning(msg);
throw new alma.ACSErrTypeCommon.wrappers.AcsJTypeNotFoundEx(cause);
}
try {
// get at the static insert method defined for all IDL structures and sequences.
// TODO: Cache it in a struct - method map, perhaps using weak references.
Method insert = structHelperClass.getMethod("insert", new Class[] { Any.class, obj.getClass() });
// arguments to insert method are just the newly created Any and the
// IDL struct instance passed to this method.
Object[] args = { retVal, obj };
insert.invoke(null, args);
return retVal;
} catch (NoSuchMethodException e) {
// we got a Helper class, but it seems to be not the CORBA-generated kind
Throwable cause = new Throwable("Class '" + structHelperClass.getName() + "' associated with the given object of type '" + obj.getClass().getName() + "' is incompatiable with CORBA: " + e.getMessage());
throw new AcsJBadParameterEx(cause);
} catch (java.lang.reflect.InvocationTargetException e) {
Throwable realEx = e.getCause();
String reason = "Failed to insert the given CORBA object into a CORBA Any: the helper class insert method threw an exception.";
m_logger.log(Level.FINE, reason, realEx);
Throwable cause = new Throwable(reason + realEx.getMessage());
// todo: NC-specific exception type
throw new alma.ACSErrTypeJavaNative.wrappers.AcsJJavaLangEx(cause);
} catch (Throwable thr) {
String reason = "Failed to insert the given CORBA object into a CORBA Any.";
m_logger.log(Level.FINE, reason, thr);
Throwable cause = new Throwable(reason + thr.getMessage());
throw new AcsJUnexpectedExceptionEx(cause);
}
}
use of alma.ACSErrTypeCommon.wrappers.AcsJBadParameterEx in project ACS by ACS-Community.
the class AnyAide method objectToCorbaAny.
/**
* Converts a generic Java object to a CORBA Any. May fail.
*
* @param obj
* Object to be converted to a CORBA any
* @return A CORBA any with obj's data embedded within it.
* @throws AcsJException
* Thrown if there's some problem converting the object to an
* any. TODO: make sure this works with enumerations.
*/
public Any objectToCorbaAny(Object obj) throws AcsJException {
if (obj != null && obj.getClass().isArray()) {
return internalArrayToCorbaAny(obj);
}
Any retVal = m_containerServices.getAdvancedContainerServices().getAny();
// null case
if (obj == null) {
retVal.insert_Object(null);
} else // check against string
if (obj instanceof String) {
retVal.insert_string((String) obj);
} else // check against double
if (obj instanceof Double) {
double value = ((Double) obj).doubleValue();
retVal.insert_double(value);
} else // check against long - CORBA long long and unsigned long long
if (obj instanceof Long) {
long value = ((Long) obj).longValue();
retVal.insert_longlong(value);
} else // check against integer - CORBA long or unsigned long
if (obj instanceof Integer) {
int value = ((Integer) obj).intValue();
retVal.insert_long(value);
} else // check against float
if (obj instanceof Float) {
float value = ((Float) obj).floatValue();
retVal.insert_float(value);
} else if (obj instanceof IDLEntity) {
// and that this method will work.
return complexObjectToCorbaAny((IDLEntity) obj);
} else {
Throwable cause = new Throwable("Bad arg of type " + obj.getClass().getName());
throw new AcsJBadParameterEx(cause);
}
return retVal;
}
use of alma.ACSErrTypeCommon.wrappers.AcsJBadParameterEx in project ACS by ACS-Community.
the class ManagerImpl method checkCURL.
/**
* Verifies URI if it is valid, in CURL format; also checks if it belongs to this domain.
* If URI is not valid, <code>BadParametersException</code> exception is thrown.
*
* @param uri uri to be check to be a valid curl
* @param allowNonLocalDomains allow non-local domains
*/
private void checkCURL(URI curl, boolean allowNonLocalDomains) throws AcsJBadParameterEx {
// check if null
if (curl == null) {
// BAD_PARAM
AcsJBadParameterEx af = new AcsJBadParameterEx();
af.setParameter("curl");
af.setParameterValue("null");
throw af;
}
if (curl.getPath() == null || curl.getPath().length() == 0 || ((curl.getScheme() != null && curl.getScheme().startsWith(CURL_URI_SCHEMA)))) {
// BAD_PARAM
AcsJBadParameterEx af = new AcsJBadParameterEx();
af.setParameter("curl");
af.setParameterValue(curl.toString());
throw af;
}
// check if CURL belongs to this domain
if (!allowNonLocalDomains && !isLocalDomainCURL(curl)) {
// BAD_PARAM
String domain = curl.getAuthority();
AcsJBadParameterEx af = new AcsJBadParameterEx();
af.setParameter("curl");
af.setParameterValue("CURL does not belong to this domain ('" + domain + "' not one of '" + domains + "').");
throw af;
}
}
Aggregations