use of com.cosylab.acs.maci.Component in project ACS by ACS-Community.
the class ManagerImplTest method testComponentInfo.
public void testComponentInfo() {
/// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
if (false) {
try {
//TODO get ComponentInfo
manager.getComponentInfo(0, null, null, null, false);
manager.getComponentInfo(Integer.MAX_VALUE, null, null, null, false);
manager.getComponentInfo(dummyHandle, null, null, null, false);
manager.getComponentInfo(dummyHandle, null, "non-null", null, true);
manager.getComponentInfo(dummyHandle, null, null, "non-null", true);
manager.getComponentInfo(dummyHandle, new int[0], null, null, false);
manager.getComponentInfo(dummyHandle, new int[0], "non-null", null, true);
manager.getComponentInfo(dummyHandle, new int[0], null, "non-null", false);
} catch (AcsJNoPermissionEx e) {
fail("No permission");
}
}
try {
Administrator client = new TestAdministrator(clientName);
ClientInfo info = manager.login(client);
manager.getComponentInfo(info.getHandle(), new int[0], "*MOUNT*", "*", false);
manager.logout(info.getHandle());
} catch (Throwable e) {
e.printStackTrace();
fail(e.getMessage());
}
TestContainer container = new TestContainer("Container");
Map supportedComponents = new HashMap();
Component mount1COB = new TestComponent("MOUNT1");
supportedComponents.put("MOUNT1", mount1COB);
Component mount4COB = new TestComponent("MOUNT4");
supportedComponents.put("MOUNT4", mount4COB);
container.setSupportedComponents(supportedComponents);
ClientInfo containerInfo = null;
try {
containerInfo = manager.login(container);
} catch (AcsJNoPermissionEx e1) {
fail("No permission");
}
try {
Thread.sleep(STARTUP_COBS_SLEEP_TIME_MS);
} catch (InterruptedException ie) {
}
try {
Administrator client = new TestAdministrator(clientName);
ClientInfo info = manager.login(client);
ComponentInfo[] infos = manager.getComponentInfo(info.getHandle(), new int[0], "MOUNT1", "*", false);
assertEquals(1, infos.length);
} catch (Throwable e) {
e.printStackTrace();
fail(e.getMessage());
}
try {
manager.logout(containerInfo.getHandle());
} catch (AcsJNoPermissionEx e) {
fail("No permission");
}
}
use of com.cosylab.acs.maci.Component in project ACS by ACS-Community.
the class ManagerImplTest method testRestartComponent.
public void testRestartComponent() {
try {
try {
manager.restartComponent(0, null);
fail();
} catch (AcsJBadParameterEx bpe) {
System.out.println("This is OK: null parameter");
}
try {
manager.restartComponent(Integer.MAX_VALUE, null);
fail();
} catch (AcsJBadParameterEx bpe) {
System.out.println("This is OK: null parameter");
}
try {
manager.restartComponent(dummyHandle, dummyURI);
fail();
} catch (AcsJNoPermissionEx npe) {
System.out.println("This is OK: " + npe.toString());
} catch (AcsJBadParameterEx bpe) {
fail();
}
TestClient client = new TestClient(clientName);
ClientInfo info = manager.login(client);
assertTrue(info.getHandle() != 0);
try {
manager.restartComponent(info.getHandle(), null);
fail();
} catch (AcsJBadParameterEx bpe) {
System.out.println("This is OK: null parameter");
}
URI mount = null;
try {
mount = new URI("MOUNT3");
Component component = manager.restartComponent(info.getHandle(), mount);
assertEquals(null, component);
} catch (AcsJBadParameterEx bpe) {
fail();
} catch (URISyntaxException usi) {
fail();
}
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);
// activate
try {
StatusHolder status = new StatusHolder();
Component ref = manager.getComponent(info.getHandle(), mount, true, status);
assertEquals(mount3COB, ref);
assertEquals(ComponentStatus.COMPONENT_ACTIVATED, status.getStatus());
} catch (Exception ex) {
fail();
}
// restart
try {
Component returnedComponent = manager.restartComponent(info.getHandle(), mount);
assertEquals(mount3COB, returnedComponent);
} catch (Exception ex) {
fail();
}
// no owner client test
TestClient client2 = new TestClient("thief");
ClientInfo info2 = manager.login(client2);
assertTrue(info2.getHandle() != 0);
try {
manager.restartComponent(info2.getHandle(), mount);
fail();
} catch (AcsJNoPermissionEx npe) {
System.out.println("This is OK: " + npe.toString());
} catch (AcsJBadParameterEx bpe) {
fail();
}
} catch (AcsJNoPermissionEx e) {
fail("No permission");
}
}
use of com.cosylab.acs.maci.Component in project ACS by ACS-Community.
the class ManagerImplTest method testReleaseComponentAsync.
public void testReleaseComponentAsync() throws Throwable {
try {
try {
manager.releaseComponentAsync(0, null, null);
fail();
} catch (AcsJBadParameterEx bpe) {
System.out.println("This is OK: null parameter");
}
try {
manager.releaseComponentAsync(Integer.MAX_VALUE, null, null);
fail();
} catch (AcsJBadParameterEx bpe) {
System.out.println("This is OK: null parameter");
}
try {
manager.releaseComponentAsync(dummyHandle, dummyURI, null);
fail();
} catch (AcsJNoPermissionEx npe) {
System.out.println("This is OK: " + npe.toString());
} catch (AcsJBadParameterEx bpe) {
fail();
}
TestClient client = new TestClient(clientName);
ClientInfo info = manager.login(client);
TestClient client2 = new TestClient("anotherClient");
ClientInfo info2 = manager.login(client2);
TestContainer container = new TestContainer("Container");
Map supportedComponents = new HashMap();
Component mount1COB = new TestComponent("MOUNT1");
supportedComponents.put("MOUNT1", mount1COB);
Component mount4COB = new TestComponent("MOUNT4", false, true);
supportedComponents.put("MOUNT4", mount4COB);
container.setSupportedComponents(supportedComponents);
ClientInfo containerInfo = manager.login(container);
// here also parallel activation will be tested (autostart and activation bellow)
StatusHolder status = new StatusHolder();
Component ref = manager.getComponent(info.getHandle(), new URI("MOUNT1"), true, status);
assertEquals(mount1COB, ref);
assertEquals(ComponentStatus.COMPONENT_ACTIVATED, status.getStatus());
status = new StatusHolder();
ref = manager.getComponent(info2.getHandle(), new URI("MOUNT1"), true, status);
assertEquals(mount1COB, ref);
assertEquals(ComponentStatus.COMPONENT_ACTIVATED, status.getStatus());
ref = manager.getComponent(info.getHandle(), new URI("MOUNT4"), true, status);
assertEquals(mount4COB, ref);
assertEquals(ComponentStatus.COMPONENT_ACTIVATED, status.getStatus());
try {
LongCompletionCallbackTestImpl lcc = new LongCompletionCallbackTestImpl();
synchronized (lcc) {
manager.releaseComponentAsync(info2.getHandle(), new URI("MOUNT1"), lcc);
if (!lcc.doneFlag)
lcc.wait(SLEEP_TIME_MS);
if (!lcc.doneFlag)
fail("callback not called");
assertEquals(1, lcc.result);
assertNull(lcc.exception);
lcc.reset();
manager.releaseComponentAsync(info.getHandle(), new URI("MOUNT1"), lcc);
if (!lcc.doneFlag)
lcc.wait(SLEEP_TIME_MS);
if (!lcc.doneFlag)
fail("callback not called");
assertEquals(0, lcc.result);
assertNull(lcc.exception);
lcc.reset();
manager.releaseComponentAsync(info.getHandle(), new URI("MOUNT4"), lcc);
if (!lcc.doneFlag)
lcc.wait(SLEEP_TIME_MS);
if (!lcc.doneFlag)
fail("callback not called");
assertEquals(0, lcc.result);
assertNotNull(lcc.exception);
}
} catch (Exception ex) {
fail(ex.toString());
}
} catch (AcsJNoPermissionEx e) {
fail("No permission");
}
}
use of com.cosylab.acs.maci.Component in project ACS by ACS-Community.
the class ManagerImplTest method testContainerToManagerStateTransferComponents.
public void testContainerToManagerStateTransferComponents() {
TestComponent mount1COB = new TestComponent("MOUNT1");
TestComponent mount2COB = new TestComponent("MOUNT2");
Map supportedComponents = new HashMap();
supportedComponents.put("MOUNT1", mount1COB);
supportedComponents.put("MOUNT2", mount2COB);
try {
// dummy container
TestContainer dummyContainer = new TestContainer("Container", ClientType.CONTAINER, true);
ClientInfo dummyContainerInfo = manager.login(dummyContainer);
dummyContainer.setSupportedComponents(supportedComponents);
try {
Thread.sleep(STARTUP_COBS_SLEEP_TIME_MS);
} catch (InterruptedException ie) {
}
TestAdministrator client = new TestAdministrator(administratorName);
ClientInfo info = manager.login(client);
// activate MOUNT2
//
URI mount2URI;
try {
mount2URI = new URI("MOUNT2");
StatusHolder status = new StatusHolder();
Component ref = manager.getComponent(info.getHandle(), mount2URI, true, status);
assertEquals(mount2COB, ref);
assertEquals(ComponentStatus.COMPONENT_ACTIVATED, status.getStatus());
} catch (Exception ex) {
fail();
}
manager.logout(dummyContainerInfo.getHandle());
// try to confuse with recovery mode
TestContainer container = new TestContainer("Container", ClientType.CONTAINER, true);
container.setSupportedComponents(supportedComponents);
// add Components to container
ComponentInfo mount1COBInfo = new ComponentInfo(HandleConstants.COMPONENT_MASK + 1, "MOUNT1", "IDL:alma/MOUNT_ACS/Mount:1.0", "acsexmplMount", mount1COB);
mount1COBInfo.setInterfaces(mount1COB.implementedInterfaces());
mount1COBInfo.setContainer(dummyContainerInfo.getHandle());
mount1COBInfo.setContainerName(dummyContainerInfo.getName());
container.getActivatedComponents().put(new Integer(mount1COBInfo.getHandle()), mount1COBInfo);
ComponentInfo mount2COBInfo = new ComponentInfo(HandleConstants.COMPONENT_MASK + 2, "MOUNT2", "IDL:alma/MOUNT_ACS/Mount:1.0", "acsexmplMount", mount2COB);
mount2COBInfo.setInterfaces(mount2COB.implementedInterfaces());
mount2COBInfo.setContainer(dummyContainerInfo.getHandle());
mount2COBInfo.setContainerName(dummyContainerInfo.getName());
container.getActivatedComponents().put(new Integer(mount2COBInfo.getHandle()), mount2COBInfo);
// container login
ClientInfo containerInfo = manager.login(container);
try {
Thread.sleep(STARTUP_COBS_SLEEP_TIME_MS);
} catch (InterruptedException ie) {
}
// there should be 2 Components activated
ComponentInfo[] infos = manager.getComponentInfo(info.getHandle(), new int[0], "*", "*", true);
Arrays.sort(infos);
assertEquals(2, infos.length);
assertEquals("MOUNT1", infos[0].getName());
assertEquals("MOUNT2", infos[1].getName());
// container2 took over
assertEquals(containerInfo.getHandle(), infos[0].getContainer());
assertEquals(containerInfo.getHandle(), infos[1].getContainer());
// manager
assertEquals(1, infos[0].getClients().size());
assertTrue(infos[0].getClients().contains(HandleConstants.MANAGER_MASK));
// client only
assertEquals(1, infos[1].getClients().size());
assertTrue(infos[1].getClients().contains(info.getHandle()));
} catch (AcsJNoPermissionEx e) {
fail("No permission");
}
}
use of com.cosylab.acs.maci.Component in project ACS by ACS-Community.
the class ManagerImpl method internalRequestDefaultComponent.
/**
* Internal method for requesting default components.
* @param requestor requestor of the component.
* @param typr type of the component
* @return componentInfo <code>ComponentInfo</code> of requested default component.
*/
private ComponentInfo internalRequestDefaultComponent(int requestor, String type) throws NoDefaultComponentException {
String defaultComponentName = null;
ComponentInfo defaultComponentInfo = null;
// first check default components table
synchronized (defaultComponents) {
defaultComponentInfo = defaultComponents.get(type);
}
if (defaultComponentInfo != null)
defaultComponentName = defaultComponentInfo.getName();
// if not found, search for the default component in the CDB
if (defaultComponentName == null) {
DAOProxy componentsDAO = getComponentsDAOProxy();
if (componentsDAO != null) {
try {
// get names of all components
// @todo here to check if CDB is available
componentsDAO.get_field_data("");
/*String[] ids =*/
String[] ids = getComponentsList();
// test names
for (int i = 0; i < ids.length; i++) {
// read name
//readStringCharacteristics(componentsDAO, ids[i]+"/Name");
String name = ids[i];
if (name == null) {
logger.log(Level.WARNING, "Misconfigured CDB, there is no type of component '" + ids[i] + "' defined.");
continue;
}
// do not search dynamic components (they cannot be marked as default in CDB anyway)
if (!name.equals(ComponentSpec.COMPSPEC_ANY)) {
// read type
String componentType = readStringCharacteristics(componentsDAO, ids[i] + "/Type");
if (type == null) {
logger.log(Level.WARNING, "Misconfigured CDB, there is no type of component '" + name + "' defined.");
continue;
}
// test type
final String TRUE_STRING = "true";
if (type.equals(componentType)) {
// check if it is default, read silently
String isDefault = readStringCharacteristics(componentsDAO, ids[i] + "/Default", true);
if (isDefault == null || !isDefault.equalsIgnoreCase(TRUE_STRING))
continue;
// got the match
defaultComponentName = name;
break;
}
}
}
} catch (Throwable ex) {
CoreException ce = new CoreException("Failed to obtain component data from the CDB.", ex);
reportException(ce);
}
}
}
// if found get the component
if (defaultComponentInfo != null) {
try {
StatusHolder status = new StatusHolder();
ContainerInfo containerInfo = getContainerInfo(defaultComponentInfo.getContainer());
if (containerInfo == null) {
CoreException huse = new CoreException("Failed to return default component: '" + defaultComponentName + "', container with '" + HandleHelper.toString(defaultComponentInfo.getContainer()) + "' not logged in.");
reportException(huse);
return null;
}
ComponentInfo componentInfo = internalRequestComponent(requestor, defaultComponentInfo.getName(), defaultComponentInfo.getType(), defaultComponentInfo.getCode(), containerInfo.getName(), RELEASE_IMMEDIATELY, status, true);
if (componentInfo == null || status.getStatus() != ComponentStatus.COMPONENT_ACTIVATED) {
CoreException huse = new CoreException("Failed to obtain default component: '" + defaultComponentName + "'.");
reportException(huse);
// no error handling...
return null;
}
return componentInfo;
} catch (Throwable t) {
CoreException huse = new CoreException("Failed to return default component: '" + defaultComponentName + "'.", t);
reportException(huse);
return null;
}
} else if (defaultComponentName != null) {
// create CURL
URI curl = null;
try {
curl = CURLHelper.createURI(defaultComponentName);
} catch (URISyntaxException use) {
CoreException huse = new CoreException("Failed to create CURL from default component name: '" + defaultComponentName + "'.", use);
reportException(huse);
return null;
}
try {
// request for component
StatusHolder status = new StatusHolder();
Component component = internalRequestComponent(requestor, curl, status, true);
if (component == null || status.getStatus() != ComponentStatus.COMPONENT_ACTIVATED) {
CoreException huse = new CoreException("Failed to obtain default component: '" + defaultComponentName + "'.");
reportException(huse);
return null;
}
// return component info
ComponentInfo[] componentInfo = getComponentInfo(requestor, new int[0], defaultComponentName, type, true);
if (componentInfo == null || componentInfo.length != 1) {
CoreException huse = new CoreException("Failed to obtain activated default component ComponentInfo: '" + defaultComponentName + "'.");
reportException(huse);
return null;
} else
return componentInfo[0];
} catch (Throwable t) {
CoreException huse = new CoreException("Failed to return default component: '" + defaultComponentName + "'.", t);
reportException(huse);
return null;
}
}
// not found
NoDefaultComponentException ndce = new NoDefaultComponentException("No default component for type '" + type + "' found.");
throw ndce;
}
Aggregations