Search in sources :

Example 21 with ClientInfo

use of com.cosylab.acs.maci.ClientInfo 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");
    }
}
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) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) 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 22 with ClientInfo

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

the class ManagerPrevaylerTest method dynamicComponentClientInstance.

private int dynamicComponentClientInstance(final String clientInstance) throws Throwable {
    // simple trick to align all the threads
    Thread.sleep(CLIENT_START_DELAY_MS);
    TestClient client = new TestClient(clientInstance);
    ClientInfo info = manager.login(client);
    // all dynamic case
    try {
        for (int i = 0; i < COMPONENTS; i++) {
            ComponentInfo componentInfo = manager.getDynamicComponent(info.getHandle(), new ComponentSpec(clientInstance + "-dynComponent-" + i, "java.lang.Object", "java.lang.Object", "DynContainer"), true);
            assertTrue(componentInfo != null);
            int nc = count.incrementAndGet();
            if (nc % COUNT_REPORT_EVERY == 0)
                System.out.println(nc + " components activated until now...");
        }
    } catch (Throwable ex) {
        ex.printStackTrace();
        fail();
    }
    return info.getHandle();
}
Also used : ClientInfo(com.cosylab.acs.maci.ClientInfo) ComponentInfo(com.cosylab.acs.maci.ComponentInfo) ComponentSpec(com.cosylab.acs.maci.ComponentSpec)

Example 23 with ClientInfo

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

the class TestDaemon method startContainer.

/* (non-Javadoc)
	 * @see com.cosylab.acs.maci.Daemon#startContainer(java.lang.String, java.lang.String, short, java.lang.String)
	 */
public void startContainer(String containerType, final String containerName, short instanceNumber, String flags) throws RemoteException {
    if (alwaysFail)
        return;
    new Thread(new Runnable() {

        public void run() {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
            }
            TestDynamicContainer tdc = new TestDynamicContainer(containerName, manager);
            try {
                ClientInfo info = manager.login(tdc);
                tdc.setHandle(info.getHandle());
            } catch (AcsJNoPermissionEx e) {
                /// @todo Error handling when catching exceptions 
                e.printStackTrace();
            }
        }
    }, "Conatiner starter").start();
}
Also used : AcsJNoPermissionEx(alma.maciErrType.wrappers.AcsJNoPermissionEx) ClientInfo(com.cosylab.acs.maci.ClientInfo)

Example 24 with ClientInfo

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

the class ManagerImplTest method testShutdown.

/**
	 * 
	 * Test of ManagerImpl shutdown.
	 *
	 */
public void testShutdown() {
    try {
        manager.shutdown(0, 0);
        fail();
    } catch (AcsJNoPermissionEx npe) {
        System.out.println("This is OK: " + npe.toString());
    }
    Client client = new TestClient(clientName);
    ClientInfo info = null;
    try {
        info = manager.login(client);
    } catch (AcsJNoPermissionEx e) {
        fail("No permission");
    }
    try {
        manager.shutdown(info.getHandle(), 0);
        fail();
    } catch (AcsJNoPermissionEx npe) {
        System.out.println("This is OK: " + npe.toString());
    }
    Administrator admin = new TestAdministrator("shutdownAdmin");
    ClientInfo info2 = null;
    try {
        info2 = manager.login(admin);
        manager.shutdown(info2.getHandle(), 0);
    } catch (AcsJNoPermissionEx e) {
        fail("No permission");
    }
    // already shutdown
    try {
        manager.shutdown(info2.getHandle(), 0);
        fail();
    } catch (AcsJNoPermissionEx npe) {
        System.out.println("This is OK: " + npe.toString());
    }
    // already shutdown returns without exception
    try {
        manager.logout(info.getHandle());
        System.out.println("This is OK");
    } catch (AcsJNoPermissionEx npe) {
        System.out.println("This is NOT OK: " + npe.toString());
        npe.printStackTrace();
    }
    // already shutdown
    try {
        manager.login(client);
        fail();
    } catch (AcsJNoPermissionEx npe) {
        System.out.println("This is OK: " + npe.toString());
    }
    // tearDown should not shutdown
    manager = null;
}
Also used : Administrator(com.cosylab.acs.maci.Administrator) AcsJNoPermissionEx(alma.maciErrType.wrappers.AcsJNoPermissionEx) ClientInfo(com.cosylab.acs.maci.ClientInfo) Client(com.cosylab.acs.maci.Client)

Example 25 with ClientInfo

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

the class ManagerImplTest method testStartupComponents.

public void testStartupComponents() {
    try {
        TestContainer container = new TestContainer("Container");
        Map supportedComponents = new HashMap();
        TestComponent mount1COB = new TestComponent("MOUNT1");
        supportedComponents.put("MOUNT1", mount1COB);
        container.setSupportedComponents(supportedComponents);
        TestAdministrator client = new TestAdministrator(administratorName);
        ClientInfo info = manager.login(client);
        // test case when container is unable to activate startup Component - MOUNT1
        ClientInfo containerInfo = manager.login(container);
        try {
            Thread.sleep(STARTUP_COBS_SLEEP_TIME_MS);
        } catch (InterruptedException ie) {
        }
        // there should be only no Components activated
        ComponentInfo[] infos = manager.getComponentInfo(info.getHandle(), new int[0], "*", "*", true);
        assertEquals(1, infos.length);
        assertTrue("MOUNT1".equals(infos[0].getName()));
        // manager and client
        assertEquals(1, infos[0].getClients().size());
        assertTrue(infos[0].getClients().contains(HandleConstants.MANAGER_MASK));
        // container logout and login
        manager.logout(containerInfo.getHandle());
        try {
            Thread.sleep(SLEEP_TIME_MS);
        } catch (InterruptedException ie) {
        }
        infos = manager.getComponentInfo(info.getHandle(), new int[0], "*", "*", true);
        assertEquals(0, infos.length);
        manager.login(container);
        try {
            Thread.sleep(STARTUP_COBS_SLEEP_TIME_MS);
        } catch (InterruptedException ie) {
        }
        // there should be only no Components activated
        infos = manager.getComponentInfo(info.getHandle(), new int[0], "*", "*", true);
        assertEquals(1, infos.length);
        assertTrue("MOUNT1".equals(infos[0].getName()));
        // manager 
        assertEquals(1, infos[0].getClients().size());
        assertTrue(infos[0].getClients().contains(HandleConstants.MANAGER_MASK));
        manager.logout(info.getHandle());
        try {
            Thread.sleep(SLEEP_TIME_MS);
        } catch (InterruptedException ie) {
        }
    } catch (AcsJNoPermissionEx e) {
        fail("No permission");
    }
}
Also used : AcsJNoPermissionEx(alma.maciErrType.wrappers.AcsJNoPermissionEx) HashMap(java.util.HashMap) ClientInfo(com.cosylab.acs.maci.ClientInfo) ComponentInfo(com.cosylab.acs.maci.ComponentInfo) HashMap(java.util.HashMap) Map(java.util.Map)

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