Search in sources :

Example 36 with ClientInfo

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

the class ManagerImplTest method testSequentialContainersLogin.

public void testSequentialContainersLogin() {
    int counter = 0;
    final int SEQUENTAL_LOGINS = 100;
    try {
        for (int i = 0; i < SEQUENTAL_LOGINS; i++) {
            final String containerName = "Container" + (++counter);
            Container container = new TestContainer(containerName);
            ClientInfo info = manager.login(container);
            assertTrue(containerName + " failed to login.", info != null && info.getHandle() != 0);
        }
    } catch (AcsJNoPermissionEx e) {
        fail("No permission");
    }
}
Also used : Container(com.cosylab.acs.maci.Container) AcsJNoPermissionEx(alma.maciErrType.wrappers.AcsJNoPermissionEx) ClientInfo(com.cosylab.acs.maci.ClientInfo)

Example 37 with ClientInfo

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

the class ManagerImplTest method testManagerShutdownWithComponentDestruction.

public void testManagerShutdownWithComponentDestruction() {
    try {
        boolean activateOnActivation = true;
        TestContainer container = new TestContainer("Container");
        Map supportedComponents = new HashMap();
        TestContainer container2 = new TestContainer("Container2");
        Map supportedComponents2 = new HashMap();
        TestComponent mount1COB = new TestComponent("MOUNT1");
        TestHierarchicalComponent mount2HierCOB = new TestHierarchicalComponent("HierarchicalCOB2", manager, new String[] { "MOUNT3" }, true, activateOnActivation);
        TestHierarchicalComponent mount3HierCOB = new TestHierarchicalComponent("HierarchicalCOB3", manager, new String[] { "MOUNT5", "PBEND_B_01" }, true, activateOnActivation);
        TestComponent mount5COB = new TestComponent("MOUNT5");
        TestHierarchicalComponent mount4HierCOB = new TestHierarchicalComponent("HierarchicalCOB4", manager, new String[] { "MOUNT2" }, true, activateOnActivation);
        TestHierarchicalComponent psHierCOB = new TestHierarchicalComponent("HierarchicalPSCOB", manager, new String[] { "MOUNT5" }, true, activateOnActivation);
        supportedComponents.put("MOUNT1", mount1COB);
        supportedComponents.put("MOUNT2", mount2HierCOB);
        supportedComponents.put("MOUNT3", mount3HierCOB);
        supportedComponents2.put("MOUNT5", mount5COB);
        supportedComponents.put("MOUNT4", mount4HierCOB);
        supportedComponents.put("PBEND_B_01", psHierCOB);
        container.setSupportedComponents(supportedComponents);
        container2.setSupportedComponents(supportedComponents2);
        ClientInfo containerInfo = manager.login(container);
        ClientInfo containerInfo2 = manager.login(container2);
        TestAdministrator client = new TestAdministrator(administratorName);
        ClientInfo info = manager.login(client);
        try {
            Thread.sleep(STARTUP_COBS_SLEEP_TIME_MS);
        } catch (InterruptedException ie) {
        }
        // activate hier. components
        URI mount2URI;
        try {
            mount2URI = new URI("MOUNT2");
            StatusHolder status = new StatusHolder();
            Component ref = manager.getComponent(info.getHandle(), mount2URI, true, status);
            assertEquals(mount2HierCOB, ref);
            assertEquals(ComponentStatus.COMPONENT_ACTIVATED, status.getStatus());
        } catch (Exception ex) {
            fail();
        }
        // activate orphan component
        URI mount1URI;
        try {
            mount1URI = new URI("MOUNT1");
            StatusHolder status = new StatusHolder();
            Component ref = manager.getComponent(info.getHandle(), mount1URI, true, status);
            assertEquals(mount1COB, ref);
            assertEquals(ComponentStatus.COMPONENT_ACTIVATED, status.getStatus());
        } catch (Exception ex) {
            fail();
        }
        // activate mount4
        URI mount4URI;
        try {
            mount4URI = new URI("MOUNT4");
            StatusHolder status = new StatusHolder();
            Component ref = manager.getComponent(info.getHandle(), mount4URI, true, status);
            assertEquals(mount4HierCOB, 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 all three Components activated
        ComponentInfo[] infos = manager.getComponentInfo(info.getHandle(), new int[0], "*", "*", true);
        assertEquals(6, infos.length);
        // check container shutdown order
        int[] containerSolution = new int[] { mount4HierCOB.getHandle(), mount2HierCOB.getHandle(), mount3HierCOB.getHandle(), psHierCOB.getHandle(), mount1COB.getHandle() };
        int[] containerOrder = container.get_component_shutdown_order();
        assertNotNull(containerOrder);
        assertEquals(containerSolution.length, containerOrder.length);
        for (int i = 0; i < containerSolution.length; i++) assertEquals(containerSolution[i], containerOrder[i]);
        int[] container2Order = container2.get_component_shutdown_order();
        /*
			int[] container2Solution = new int[] {mount5COB.getHandle()}; 
			assertNotNull(container2Order);
			assertEquals(container2Solution.length, container2Order.length);
			for (int i = 0; i < container2Solution.length; i++)
				assertEquals(container2Solution[i], container2Order[i]);
			*/
        // optimization, no notification if sequence size is not less than 1
        assertNull(container2Order);
        // check shutdown
        try {
            manager.shutdown(manager.getHandle(), 1);
            try {
                Thread.sleep(STARTUP_COBS_SLEEP_TIME_MS);
            } catch (InterruptedException ie) {
            }
            assertEquals(0, container.getActivatedComponents().size());
            assertEquals(0, container2.getActivatedComponents().size());
        } finally {
            // tearDown should not shutdown
            manager = null;
        }
    } 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 38 with ClientInfo

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

the class ManagerImplTest method testOnDemandContainerStartupComponents.

public void testOnDemandContainerStartupComponents() throws Throwable {
    TestDaemon daemon = new TestDaemon(manager, false);
    transport.registerDeamon("test", daemon);
    // this one starts startup components on auto-start containers
    manager.initializationDone();
    try {
        Thread.sleep(STARTUP_COBS_SLEEP_TIME_MS * 3);
    } catch (InterruptedException ie) {
    }
    TestAdministrator client = new TestAdministrator(administratorName);
    ClientInfo info = manager.login(client);
    assertTrue(info.getHandle() != 0);
    // there should be one Component activated
    ComponentInfo[] infos = manager.getComponentInfo(info.getHandle(), new int[0], "*", "*", true);
    assertEquals(1, infos.length);
    assertEquals("DEMANDER2", infos[0].getName());
    // check if container is logged in
    ContainerInfo[] infos2 = manager.getContainerInfo(info.getHandle(), new int[0], "OnDemandContainer2");
    assertNotNull(infos2);
    assertEquals(1, infos2.length);
}
Also used : ContainerInfo(com.cosylab.acs.maci.ContainerInfo) ClientInfo(com.cosylab.acs.maci.ClientInfo) ComponentInfo(com.cosylab.acs.maci.ComponentInfo)

Example 39 with ClientInfo

use of com.cosylab.acs.maci.ClientInfo 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 40 with ClientInfo

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

the class ManagerImplTest method testOnDemandContainer.

public void testOnDemandContainer() throws Throwable {
    TestDaemon daemon = new TestDaemon(manager, false);
    transport.registerDeamon("test", daemon);
    TestAdministrator client = new TestAdministrator(administratorName);
    ClientInfo info = manager.login(client);
    assertTrue(info.getHandle() != 0);
    URI curl = null;
    // test on-demand activation
    curl = new URI("DEMANDER");
    StatusHolder status = new StatusHolder();
    Component ref = manager.getComponent(info.getHandle(), curl, true, status);
    assertNotNull(ref);
    assertEquals(ComponentStatus.COMPONENT_ACTIVATED, status.getStatus());
    // check if container is logged in
    ContainerInfo[] infos = manager.getContainerInfo(info.getHandle(), new int[0], "OnDemandContainer");
    assertNotNull(infos);
    assertEquals(1, infos.length);
    // release component
    manager.releaseComponent(info.getHandle(), curl);
    Thread.sleep(SLEEP_TIME_MS);
    // there should be no container
    infos = manager.getContainerInfo(info.getHandle(), new int[0], "OnDemandContainer");
    assertNotNull(infos);
    assertEquals(0, infos.length);
    // now fail to start container
    daemon = new TestDaemon(manager, true);
    transport.registerDeamon("test", daemon);
    try {
        status = new StatusHolder();
        ref = manager.getComponent(info.getHandle(), curl, true, status);
        fail();
    } catch (AcsJCannotGetComponentEx e) {
        System.out.println("This is OK: " + e.toString());
    }
    // no daemon case
    transport.registerDeamon("test", null);
    try {
        status = new StatusHolder();
        ref = manager.getComponent(info.getHandle(), curl, true, status);
        fail("Expected AcsJCannotGetComponentEx");
    } catch (AcsJCannotGetComponentEx e) {
        System.out.println("This is OK: " + e.toString());
    } catch (AcsJNoPermissionEx e) {
        fail();
    }
}
Also used : AcsJNoPermissionEx(alma.maciErrType.wrappers.AcsJNoPermissionEx) ContainerInfo(com.cosylab.acs.maci.ContainerInfo) ClientInfo(com.cosylab.acs.maci.ClientInfo) Component(com.cosylab.acs.maci.Component) URI(java.net.URI) AcsJCannotGetComponentEx(alma.maciErrType.wrappers.AcsJCannotGetComponentEx) StatusHolder(com.cosylab.acs.maci.StatusHolder)

Aggregations

ClientInfo (com.cosylab.acs.maci.ClientInfo)56 AcsJNoPermissionEx (alma.maciErrType.wrappers.AcsJNoPermissionEx)39 BadParametersException (com.cosylab.acs.maci.BadParametersException)23 ComponentInfo (com.cosylab.acs.maci.ComponentInfo)23 NoResourcesException (com.cosylab.acs.maci.NoResourcesException)21 HashMap (java.util.HashMap)21 Map (java.util.Map)21 Component (com.cosylab.acs.maci.Component)18 RemoteException (com.cosylab.acs.maci.RemoteException)18 URI (java.net.URI)18 NoDefaultComponentException (com.cosylab.acs.maci.NoDefaultComponentException)17 URISyntaxException (java.net.URISyntaxException)17 StatusHolder (com.cosylab.acs.maci.StatusHolder)16 AcsJBadParameterEx (alma.ACSErrTypeCommon.wrappers.AcsJBadParameterEx)8 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)8 AcsJCannotGetComponentEx (alma.maciErrType.wrappers.AcsJCannotGetComponentEx)7 ContainerInfo (com.cosylab.acs.maci.ContainerInfo)7 ArrayList (java.util.ArrayList)7 Client (com.cosylab.acs.maci.Client)6 Administrator (com.cosylab.acs.maci.Administrator)5