Search in sources :

Example 46 with ComponentInfo

use of com.cosylab.acs.maci.ComponentInfo in project ACS by ACS-Community.

the class ManagerImplTest method testManagerToContainerStateTransferComponents.

public void testManagerToContainerStateTransferComponents() {
    TestComponent mount1COB = new TestComponent("MOUNT1");
    TestComponent mount2COB = new TestComponent("MOUNT2");
    Map supportedComponents = new HashMap();
    supportedComponents.put("MOUNT1", mount1COB);
    supportedComponents.put("MOUNT2", mount2COB);
    TestContainer container = new TestContainer("Container");
    container.setSupportedComponents(supportedComponents);
    // recovery mode
    TestContainer container2 = new TestContainer("Container", ClientType.CONTAINER, true);
    container2.setSupportedComponents(supportedComponents);
    try {
        // container login
        ClientInfo containerInfo = manager.login(container);
        TestAdministrator client = new TestAdministrator(administratorName);
        ClientInfo info = manager.login(client);
        // activate MOUNT2
        //
        URI mount1URI;
        URI mount2URI;
        try {
            mount1URI = new URI("MOUNT1");
            mount2URI = new URI("MOUNT2");
            StatusHolder status = new StatusHolder();
            Component ref = manager.getComponent(info.getHandle(), mount1URI, true, status);
            assertEquals(mount1COB, ref);
            assertEquals(ComponentStatus.COMPONENT_ACTIVATED, status.getStatus());
            ref = manager.getComponent(info.getHandle(), mount2URI, true, status);
            assertEquals(mount2COB, ref);
            assertEquals(ComponentStatus.COMPONENT_ACTIVATED, status.getStatus());
        } catch (Exception ex) {
            fail();
        }
        try {
            Thread.sleep(STARTUP_COBS_SLEEP_TIME_MS);
        } catch (InterruptedException ie) {
        }
        manager.logout(containerInfo.getHandle());
        // now do the trick, make container2 to login
        // this will assime container is down
        ClientInfo containerInfo2 = manager.login(container2);
        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(containerInfo2.getHandle(), infos[0].getContainer());
        assertEquals(containerInfo2.getHandle(), infos[1].getContainer());
        // manager and client
        assertEquals(2, infos[0].getClients().size());
        assertTrue(infos[0].getClients().contains(info.getHandle()));
        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");
    }
}
Also used : HashMap(java.util.HashMap) URI(java.net.URI) RemoteException(com.cosylab.acs.maci.RemoteException) URISyntaxException(java.net.URISyntaxException) BadParametersException(com.cosylab.acs.maci.BadParametersException) NoResourcesException(com.cosylab.acs.maci.NoResourcesException) NoDefaultComponentException(com.cosylab.acs.maci.NoDefaultComponentException) StatusHolder(com.cosylab.acs.maci.StatusHolder) AcsJNoPermissionEx(alma.maciErrType.wrappers.AcsJNoPermissionEx) ClientInfo(com.cosylab.acs.maci.ClientInfo) ComponentInfo(com.cosylab.acs.maci.ComponentInfo) Component(com.cosylab.acs.maci.Component) HashMap(java.util.HashMap) Map(java.util.Map)

Example 47 with ComponentInfo

use of com.cosylab.acs.maci.ComponentInfo in project ACS by ACS-Community.

the class TestContainer method get_component_info.

/**
	 * @see com.cosylab.acs.maci.Container#get_COB_info(int[])
	 */
public ComponentInfo[] get_component_info(int[] handles) throws RemoteException {
    ArrayList list = new ArrayList();
    synchronized (activatedComponents) {
        if (handles.length > 0) {
            // add only requested
            for (int i = 0; i < handles.length; i++) {
                Integer key = new Integer(handles[i]);
                if (activatedComponents.containsKey(key))
                    list.add(activatedComponents.get(key));
            }
        } else {
            // add all
            list.addAll(activatedComponents.values());
        }
    }
    ComponentInfo[] infos = new ComponentInfo[list.size()];
    list.toArray(infos);
    return infos;
}
Also used : ArrayList(java.util.ArrayList) ComponentInfo(com.cosylab.acs.maci.ComponentInfo)

Example 48 with ComponentInfo

use of com.cosylab.acs.maci.ComponentInfo in project ACS by ACS-Community.

the class TestContainer method activate_component.

/**
	 * @see com.cosylab.acs.maci.Container#activate_COB(int, long executionId, java.lang.String, java.lang.String, java.lang.String)
	 */
public ComponentInfo activate_component(int handle, long executionId, String name, String exe, String type) throws RemoteException {
    if (supportedComponents.containsKey(name)) {
        // simulate activation
        try {
            Thread.sleep(activationTime);
        } catch (InterruptedException ie) {
        }
        Component cob = (Component) supportedComponents.get(name);
        if (cob instanceof TestComponent) {
            TestComponent tc = (TestComponent) cob;
            tc.setHandle(handle);
            try {
                tc.activate();
            } catch (Exception ex) {
                throw new RemoteException("Failed to construct(), error: " + ex.toString(), ex);
            }
        }
        ComponentInfo cobInfo = new ComponentInfo(handle, name, type, exe, cob);
        cobInfo.setContainer(this.handle);
        cobInfo.setContainerName(this.name);
        if (cob != null)
            cobInfo.setInterfaces(new String[] { cob.getClass().getName() });
        synchronized (activatedComponents) {
            activatedComponents.put(new Integer(handle), cobInfo);
        }
        return cobInfo;
    } else
        return null;
}
Also used : ComponentInfo(com.cosylab.acs.maci.ComponentInfo) Component(com.cosylab.acs.maci.Component) RemoteException(com.cosylab.acs.maci.RemoteException) RemoteException(com.cosylab.acs.maci.RemoteException)

Example 49 with ComponentInfo

use of com.cosylab.acs.maci.ComponentInfo 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();
    }
}
Also used : AcsJNoPermissionEx(alma.maciErrType.wrappers.AcsJNoPermissionEx) HashMap(java.util.HashMap) ClientInfo(com.cosylab.acs.maci.ClientInfo) ComponentInfo(com.cosylab.acs.maci.ComponentInfo) Component(com.cosylab.acs.maci.Component) HashMap(java.util.HashMap) Map(java.util.Map) NoDefaultComponentException(com.cosylab.acs.maci.NoDefaultComponentException) BadParametersException(com.cosylab.acs.maci.BadParametersException)

Example 50 with ComponentInfo

use of com.cosylab.acs.maci.ComponentInfo 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");
    }
}
Also used : AcsJBadParameterEx(alma.ACSErrTypeCommon.wrappers.AcsJBadParameterEx) HashMap(java.util.HashMap) URI(java.net.URI) RemoteException(com.cosylab.acs.maci.RemoteException) URISyntaxException(java.net.URISyntaxException) BadParametersException(com.cosylab.acs.maci.BadParametersException) NoResourcesException(com.cosylab.acs.maci.NoResourcesException) NoDefaultComponentException(com.cosylab.acs.maci.NoDefaultComponentException) StatusHolder(com.cosylab.acs.maci.StatusHolder) AcsJNoPermissionEx(alma.maciErrType.wrappers.AcsJNoPermissionEx) IntArray(com.cosylab.acs.maci.IntArray) ClientInfo(com.cosylab.acs.maci.ClientInfo) ComponentInfo(com.cosylab.acs.maci.ComponentInfo) Component(com.cosylab.acs.maci.Component) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

ComponentInfo (com.cosylab.acs.maci.ComponentInfo)66 AcsJNoPermissionEx (alma.maciErrType.wrappers.AcsJNoPermissionEx)24 NoResourcesException (com.cosylab.acs.maci.NoResourcesException)24 BadParametersException (com.cosylab.acs.maci.BadParametersException)23 ClientInfo (com.cosylab.acs.maci.ClientInfo)23 RemoteException (com.cosylab.acs.maci.RemoteException)22 HashMap (java.util.HashMap)20 NoDefaultComponentException (com.cosylab.acs.maci.NoDefaultComponentException)19 Component (com.cosylab.acs.maci.Component)18 URISyntaxException (java.net.URISyntaxException)18 Map (java.util.Map)18 URI (java.net.URI)17 StatusHolder (com.cosylab.acs.maci.StatusHolder)15 AcsJBadParameterEx (alma.ACSErrTypeCommon.wrappers.AcsJBadParameterEx)10 AcsJCannotGetComponentEx (alma.maciErrType.wrappers.AcsJCannotGetComponentEx)10 ContainerInfo (com.cosylab.acs.maci.ContainerInfo)9 ArrayList (java.util.ArrayList)8 TimeoutRemoteException (com.cosylab.acs.maci.TimeoutRemoteException)7 ComponentSpec (com.cosylab.acs.maci.ComponentSpec)6 CoreException (com.cosylab.acs.maci.CoreException)6