use of com.cosylab.acs.maci.BadParametersException in project ACS by ACS-Community.
the class ManagerImpl method getContainerInfo.
/**
* @see com.cosylab.acs.maci.Manager#getContainerInfo(int, int[], String)
*/
public ContainerInfo[] getContainerInfo(int id, int[] handles, String name_wc) throws AcsJNoPermissionEx {
if (handles == null) {
// BAD_PARAM
BadParametersException af = new BadParametersException("Non-null 'handles' sequence expected.");
throw af;
} else if (handles.length == 0 && name_wc == null) {
// BAD_PARAM
BadParametersException af = new BadParametersException("Non-null 'names_wc' sequence expected.");
throw af;
}
/*
Pattern pattern = null;
if (handles.length == 0 && name_wc != null)
{
// test wildcard patten (try to compile it)
try
{
pattern = Pattern.compile(name_wc);
}
catch (Exception ex)
{
// BAD_PARAM
BadParametersException af = new BadParametersException("Failed to compile 'names_wc' reqular expression string '"+name_wc+"'.");
af.caughtIn(this, "getContainerInfo");
af.putValue("name_wc", name_wc);
throw af;
}
}
*/
/****************************************************************/
// info to be returned
ContainerInfo[] info = null;
// requesting info. about itself
if (handles.length == 1 && handles[0] == id) {
// check handle, no special rights for own info
securityCheck(id, 0);
info = new ContainerInfo[1];
info[0] = getContainerInfo(id);
} else // get info of requested handles
if (handles.length > 0) {
// check handle, INTROSPECT_MANAGER rights needed
securityCheck(id, AccessRights.INTROSPECT_MANAGER);
info = new ContainerInfo[handles.length];
for (int i = 0; i < handles.length; i++) info[i] = getContainerInfo(handles[i]);
} else // get info requested using name wildcard
{
// check handle, INTROSPECT_MANAGER rights needed
securityCheck(id, AccessRights.INTROSPECT_MANAGER);
// list of client matching search pattern
ArrayList<ContainerInfo> list = new ArrayList<ContainerInfo>();
// check clients
synchronized (containers) {
int h = containers.first();
while (h != 0) {
ContainerInfo containerInfo = (ContainerInfo) containers.get(h);
/*Matcher m = pattern.matcher(containerInfo.getName());
if (m.matches())*/
if (WildcharMatcher.match(name_wc, containerInfo.getName()))
list.add(containerInfo);
h = containers.next(h);
}
}
// copy to array
info = new ContainerInfo[list.size()];
list.toArray(info);
}
return info;
}
use of com.cosylab.acs.maci.BadParametersException in project ACS by ACS-Community.
the class ManagerImpl method releaseComponents.
/**
* @see com.cosylab.acs.maci.Manager#releaseComponents(int, URI[])
*/
public void releaseComponents(int id, URI[] curls) throws AcsJNoPermissionEx {
// check if null
if (curls == null) {
// BAD_PARAM
BadParametersException af = new BadParametersException("Non-null CURLs expected.");
throw af;
}
// check handle and NONE permissions
securityCheck(id, AccessRights.NONE);
/****************************************************************/
int released = 0;
for (int i = 0; i < curls.length; i++) {
try {
releaseComponent(id, curls[i]);
released++;
} catch (Exception ex) {
CoreException ce = new CoreException("Failed to release component '" + curls[i] + "'.", ex);
reportException(ce);
}
}
logger.log(Level.INFO, released + " of " + curls.length + " components released.");
/****************************************************************/
}
use of com.cosylab.acs.maci.BadParametersException in project ACS by ACS-Community.
the class ManagerImplTest method testClientInfo.
public void testClientInfo() {
try {
//test invalid
try {
manager.getClientInfo(0, null, null);
fail();
} catch (BadParametersException bpe) {
System.out.println("This is OK: " + bpe.getMessage());
}
//test invalid
try {
manager.getClientInfo(Integer.MAX_VALUE, null, null);
fail();
} catch (BadParametersException bpe) {
System.out.println("This is OK: " + bpe.getMessage());
}
//test invalid
try {
manager.getClientInfo(dummyHandle, null, null);
fail();
} catch (BadParametersException bpe) {
System.out.println("This is OK: " + bpe.getMessage());
}
//test invalid
try {
manager.getClientInfo(dummyHandle, new int[0], null);
fail();
} catch (BadParametersException bpe) {
System.out.println("This is OK: " + bpe.getMessage());
}
//test invalid
try {
manager.getClientInfo(dummyHandle, new int[0], "non-null");
fail();
} catch (AcsJNoPermissionEx npe) {
System.out.println("This is OK: " + npe.toString());
}
/*
//test invalid regular expression
try {
manager.getClientInfo(dummyHandle, new int[0], ")");
fail();
}
catch (BadParametersException bpe)
{
System.out.println("This is OK: "+bpe.getMessage());
}
*/
//test valid
ClientInfo info = manager.login(new TestClient(clientName));
int[] handles = { info.getHandle() };
ClientInfo[] infos = manager.getClientInfo(info.getHandle(), handles, null);
assertNotNull(infos);
assertEquals(infos.length, 1);
assertEquals(infos[0], info);
manager.logout(info.getHandle());
//test inaccessible
info = manager.login(new TestClient(clientName));
handles[0] = info.getHandle();
ClientInfo anotherInfo = manager.login(new TestClient(anotherName));
try {
manager.getClientInfo(anotherInfo.getHandle(), handles, null);
fail();
} catch (AcsJNoPermissionEx npe) {
System.out.println("This is OK: " + npe.toString());
}
try {
manager.getClientInfo(anotherInfo.getHandle(), new int[0], clientName);
fail();
} catch (AcsJNoPermissionEx npe) {
System.out.println("This is OK: " + npe.toString());
}
manager.logout(info.getHandle());
manager.logout(anotherInfo.getHandle());
//test valid and invalid client info
info = manager.login(new TestClient(clientName));
handles = new int[2];
handles[0] = info.getHandle();
handles[1] = dummyHandle;
try {
infos = manager.getClientInfo(info.getHandle(), handles, null);
fail();
} catch (AcsJNoPermissionEx npe) {
System.out.println("This is OK: " + npe.toString());
}
manager.logout(info.getHandle());
//test invalid and inaccessible client info
info = manager.login(new TestClient(clientName));
anotherInfo = manager.login(new TestClient(anotherName));
handles = new int[2];
handles[0] = anotherInfo.getHandle();
handles[1] = dummyHandle;
try {
infos = manager.getClientInfo(info.getHandle(), handles, null);
fail();
} catch (AcsJNoPermissionEx npe) {
System.out.println("This is OK: " + npe.toString());
}
manager.logout(info.getHandle());
manager.logout(anotherInfo.getHandle());
//test valid and inaccessible client info
info = manager.login(new TestClient(clientName));
anotherInfo = manager.login(new TestClient(anotherName));
handles = new int[2];
handles[0] = info.getHandle();
handles[1] = anotherInfo.getHandle();
try {
infos = manager.getClientInfo(info.getHandle(), handles, null);
fail();
} catch (AcsJNoPermissionEx npe) {
System.out.println("This is OK: " + npe.toString());
}
manager.logout(info.getHandle());
manager.logout(anotherInfo.getHandle());
//test valid, invalid and inaccessible client info
info = manager.login(new TestClient(clientName));
anotherInfo = manager.login(new TestClient(anotherName));
handles = new int[3];
handles[0] = info.getHandle();
handles[1] = anotherInfo.getHandle();
handles[2] = dummyHandle;
try {
infos = manager.getClientInfo(info.getHandle(), handles, null);
fail();
} catch (AcsJNoPermissionEx npe) {
System.out.println("This is OK: " + npe.toString());
}
manager.logout(info.getHandle());
manager.logout(anotherInfo.getHandle());
//test duplicating infos
info = manager.login(new TestClient(clientName));
handles = new int[2];
handles[0] = info.getHandle();
handles[1] = info.getHandle();
try {
infos = manager.getClientInfo(info.getHandle(), handles, null);
fail();
} catch (AcsJNoPermissionEx npe) {
System.out.println("This is OK: " + npe.toString());
}
manager.logout(info.getHandle());
//test with INTROSPECTION_MANAGER rights
info = manager.login(new TestClient(clientName));
ClientInfo adminInfo = manager.login(new TestAdministrator(administratorName));
handles = new int[3];
handles[0] = adminInfo.getHandle();
handles[1] = info.getHandle();
handles[2] = dummyHandle;
infos = manager.getClientInfo(adminInfo.getHandle(), handles, null);
assertNotNull(infos);
assertEquals(infos[0].getHandle(), adminInfo.getHandle());
assertEquals(infos[1].getHandle(), info.getHandle());
//assertEquals(infos[2].getHandle(),0);
assertNull(infos[2]);
manager.logout(info.getHandle());
manager.logout(adminInfo.getHandle());
// test wildcard search
info = manager.login(new TestClient("client1"));
assertNotNull(info);
ClientInfo info2 = manager.login(new TestClient("client2a"));
assertNotNull(info2);
ClientInfo info3 = manager.login(new TestClient("client3aa"));
assertNotNull(info3);
ClientInfo info4 = manager.login(new TestClient("other4"));
assertNotNull(info4);
adminInfo = manager.login(new TestAdministrator("client55"));
assertNotNull(adminInfo);
//infos = manager.getClientInfo(adminInfo.getHandle(), new int[0], "client.*");
infos = manager.getClientInfo(adminInfo.getHandle(), new int[0], "client*");
assertNotNull(infos);
assertEquals(4, infos.length);
assertEquals(info.getHandle(), infos[0].getHandle());
assertEquals(info2.getHandle(), infos[1].getHandle());
assertEquals(info3.getHandle(), infos[2].getHandle());
assertEquals(adminInfo.getHandle(), infos[3].getHandle());
manager.logout(info.getHandle());
manager.logout(info2.getHandle());
manager.logout(info3.getHandle());
manager.logout(info4.getHandle());
manager.logout(adminInfo.getHandle());
} catch (AcsJNoPermissionEx e) {
fail("No permission");
}
}
use of com.cosylab.acs.maci.BadParametersException in project ACS by ACS-Community.
the class ManagerImplTest method testGetDefaultComponent.
/**
* Test getDefaultComponent.
*/
public void testGetDefaultComponent() {
try {
try {
manager.getDefaultComponent(0, null);
fail();
} catch (BadParametersException bpe) {
System.out.println("This is OK: " + bpe.getMessage());
}
try {
manager.getDefaultComponent(Integer.MAX_VALUE, null);
fail();
} catch (BadParametersException bpe) {
System.out.println("This is OK: " + bpe.getMessage());
}
try {
manager.getDefaultComponent(dummyHandle, "dummyType");
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.getDefaultComponent(info.getHandle(), null);
fail();
} catch (BadParametersException bpe) {
System.out.println("This is OK: " + bpe.getMessage());
}
try {
manager.getDefaultComponent(info.getHandle(), "invalid");
fail();
} catch (NoDefaultComponentException ndce) {
System.out.println("This is OK: " + ndce.getMessage());
}
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);
try {
ComponentInfo componentInfo = manager.getDefaultComponent(info.getHandle(), "IDL:alma/MOUNT_ACS/Mount:1.0");
assertTrue(componentInfo != null);
assertEquals(componentInfo.getComponent(), mount3COB);
} catch (NoDefaultComponentException ndce) {
fail();
}
} catch (AcsJNoPermissionEx e) {
fail("No permission");
} catch (NoDefaultComponentException e) {
fail();
}
}
use of com.cosylab.acs.maci.BadParametersException in project ACS by ACS-Community.
the class ManagerImpl method getDynamicComponents.
/**
* @see com.cosylab.acs.maci.Manager#getDynamicComponents(int, com.cosylab.acs.maci.ComponentSpec[])
* @todo this method still returns null in case of errors and only throws AcsJNoPermissions or
* a couple of runtime exceptions.
* Needs to be refactored or, probably better, deprecated.
*/
public ComponentInfo[] getDynamicComponents(int id, ComponentSpec[] components) throws AcsJNoPermissionEx {
// check if null
if (components == null) {
// BAD_PARAM
BadParametersException af = new BadParametersException("Non-null 'components' expected.");
throw af;
}
// check handle and NONE permissions
securityCheck(id, AccessRights.NONE);
/****************************************************************/
int obtained = 0;
ComponentInfo[] componentInfos = new ComponentInfo[components.length];
for (int i = 0; i < components.length; i++) {
try {
componentInfos[i] = getDynamicComponent(id, components[i], false);
obtained++;
} catch (Exception ex) {
componentInfos[i] = null;
CoreException ce = new CoreException("Failed to get dynamic component '" + components[i] + "'.", ex);
reportException(ce);
}
}
logger.log(Level.INFO, obtained + " of " + components.length + " dynamic components obtained.");
return componentInfos;
}
Aggregations