Search in sources :

Example 16 with ComponentInfo

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

the class ManagerImplTest method testContainerShutdown.

public void testContainerShutdown() {
    try {
        manager.shutdownContainer(0, null, 0);
        fail();
    } catch (AcsJNoPermissionEx npe) {
        fail("No permission");
    } catch (BadParametersException bpe) {
        System.out.println("This is OK: " + bpe.getMessage());
    }
    try {
        manager.shutdownContainer(0, "test", 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();
    }
    try {
        manager.shutdownContainer(info.getHandle(), "test", 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);
    } catch (AcsJNoPermissionEx e) {
        fail("No permission");
    }
    try {
        manager.shutdownContainer(info2.getHandle(), null, 0);
        fail();
    } catch (AcsJNoPermissionEx npe) {
        fail("No permission");
    } catch (BadParametersException bpe) {
        System.out.println("This is OK: " + bpe.getMessage());
    }
    try {
        manager.shutdownContainer(info2.getHandle(), "invalid", 0);
        fail();
    } catch (AcsJNoPermissionEx npe) {
        fail("No permission");
    } catch (NoResourcesException nre) {
        System.out.println("This is OK: " + nre.getMessage());
    }
    TestContainer container = new TestContainer("Container");
    Map supportedComponents = new HashMap();
    TestComponent mount1COB = new TestComponent("MOUNT1");
    supportedComponents.put("MOUNT1", mount1COB);
    container.setSupportedComponents(supportedComponents);
    try {
        ClientInfo containerInfo = manager.login(container);
    } catch (AcsJNoPermissionEx e) {
        fail("No permission");
    }
    try {
        Thread.sleep(STARTUP_COBS_SLEEP_TIME_MS);
    } catch (InterruptedException ie) {
    }
    // test activated Components
    ComponentInfo[] infos = null;
    try {
        infos = manager.getComponentInfo(info.getHandle(), new int[0], "*", "*", true);
    } catch (AcsJNoPermissionEx e) {
        fail("No permission");
    }
    assertEquals(1, infos.length);
    try {
        manager.shutdownContainer(info.getHandle(), "Container", 0);
        fail();
    } catch (AcsJNoPermissionEx npe) {
        System.out.println("This is OK: " + npe.toString());
    }
    try {
        manager.shutdownContainer(info2.getHandle(), "Container", 1);
    } catch (AcsJNoPermissionEx e) {
        fail("No permission");
    }
    assertEquals(0, container.getActivatedComponents().size());
}
Also used : HashMap(java.util.HashMap) BadParametersException(com.cosylab.acs.maci.BadParametersException) NoResourcesException(com.cosylab.acs.maci.NoResourcesException) Administrator(com.cosylab.acs.maci.Administrator) AcsJNoPermissionEx(alma.maciErrType.wrappers.AcsJNoPermissionEx) ClientInfo(com.cosylab.acs.maci.ClientInfo) ComponentInfo(com.cosylab.acs.maci.ComponentInfo) Client(com.cosylab.acs.maci.Client) HashMap(java.util.HashMap) Map(java.util.Map)

Example 17 with ComponentInfo

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

the class ManagerImplTest method testGetCollocatedComponent.

/**
	 * Test getCollocatedComponent.
	 */
public void testGetCollocatedComponent() {
    try {
        URI mountURI = null;
        try {
            mountURI = new URI("MOUNT1");
        } catch (URISyntaxException e) {
            fail();
        }
        try {
            manager.getCollocatedComponent(0, null, false, null);
            fail();
        } catch (AcsJInvalidComponentSpecEx bpe) {
            System.out.println("This is OK: " + bpe.toString());
        }
        final ComponentSpec allAsterixCompSpec = new ComponentSpec(ComponentSpec.COMPSPEC_ANY, ComponentSpec.COMPSPEC_ANY, ComponentSpec.COMPSPEC_ANY, ComponentSpec.COMPSPEC_ANY);
        try {
            manager.getCollocatedComponent(Integer.MAX_VALUE, allAsterixCompSpec, true, dummyURI);
            fail();
        } catch (AcsJNoPermissionEx npe) {
            System.out.println("This is OK: " + npe.toString());
        }
        try {
            manager.getCollocatedComponent(dummyHandle, allAsterixCompSpec, false, dummyURI);
            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.getCollocatedComponent(info.getHandle(), null, true, dummyURI);
            fail();
        } catch (AcsJInvalidComponentSpecEx bpe) {
            System.out.println("This is OK: " + bpe.toString());
        }
        try {
            manager.getCollocatedComponent(info.getHandle(), allAsterixCompSpec, true, null);
            fail();
        } catch (AcsJInvalidComponentSpecEx bpe) {
            System.out.println("This is OK: " + bpe.toString());
        }
        try {
            manager.getCollocatedComponent(info.getHandle(), new ComponentSpec(null, null, null, null), false, mountURI);
            fail();
        } catch (AcsJInvalidComponentSpecEx ndce) {
            System.out.println("This is OK: " + ndce.toString());
        }
        final ComponentSpec specifiedContainerCompSpec = new ComponentSpec(ComponentSpec.COMPSPEC_ANY, ComponentSpec.COMPSPEC_ANY, ComponentSpec.COMPSPEC_ANY, "someContainer");
        try {
            manager.getCollocatedComponent(info.getHandle(), specifiedContainerCompSpec, false, mountURI);
            fail();
        } catch (AcsJInvalidComponentSpecEx ndce) {
            System.out.println("This is OK: " + ndce.toString());
        }
        // containers
        TestContainer container = new TestContainer("Container");
        Map supportedComponents = new HashMap();
        TestComponent mount1COB = new TestComponent("MOUNT1");
        supportedComponents.put("MOUNT1", mount1COB);
        TestComponent mountCollCOB = new TestComponent("MOUNT_COLLOCATED");
        supportedComponents.put("MOUNT_COLLOCATED", mountCollCOB);
        TestComponent mountColl2COB = new TestComponent("MOUNT_COLLOCATED2");
        supportedComponents.put("MOUNT_COLLOCATED2", mountCollCOB);
        container.setSupportedComponents(supportedComponents);
        ClientInfo containerInfo = manager.login(container);
        TestContainer dynContainer = new TestDynamicContainer("DynContainer");
        /*ClientInfo dynContainerInfo =*/
        manager.login(dynContainer);
        // wait containers to startup
        try {
            Thread.sleep(STARTUP_COBS_SLEEP_TIME_MS);
        } catch (InterruptedException ie) {
        }
        // standard case
        try {
            ComponentInfo componentInfo = manager.getCollocatedComponent(info.getHandle(), new ComponentSpec("MOUNT_COLLOCATED", "java.lang.Object", "java.lang.Object", ComponentSpec.COMPSPEC_ANY), true, mountURI);
            assertTrue(componentInfo != null);
            assertTrue(componentInfo.getName().equals("MOUNT_COLLOCATED"));
            assertEquals(containerInfo.getHandle(), componentInfo.getContainer());
        } catch (Exception ex) {
            ex.printStackTrace();
            fail();
        }
        // from CDB
        try {
            URI mount2URI = new URI("MOUNT2");
            ComponentInfo componentInfo = manager.getCollocatedComponent(info.getHandle(), new ComponentSpec("MOUNT_COLLOCATED2", "java.lang.Object", "java.lang.Object", ComponentSpec.COMPSPEC_ANY), true, mount2URI);
            assertTrue(componentInfo != null);
            assertTrue(componentInfo.getName().equals("MOUNT_COLLOCATED2"));
            assertEquals(containerInfo.getHandle(), componentInfo.getContainer());
        } catch (Exception ex) {
            fail();
        }
        // from CDB, but there is not entry...
        try {
            URI noEntryURI = new URI("noEntry");
            ComponentInfo componentInfo = manager.getCollocatedComponent(info.getHandle(), new ComponentSpec("MOUNT_COLLOCATED3", "java.lang.Object", "java.lang.Object", ComponentSpec.COMPSPEC_ANY), true, noEntryURI);
            fail();
        } catch (AcsJIncompleteComponentSpecEx icse) {
            System.out.println("This is OK: " + icse.toString());
        } catch (Exception ex) {
            ex.printStackTrace();
            fail();
        }
    } catch (AcsJCannotGetComponentEx e) {
        // @todo Auto-generated catch block
        e.printStackTrace();
    } catch (AcsJIncompleteComponentSpecEx e) {
        // @todo Auto-generated catch block
        e.printStackTrace();
    } catch (AcsJInvalidComponentSpecEx e) {
        // @todo Auto-generated catch block
        e.printStackTrace();
    } catch (AcsJComponentSpecIncompatibleWithActiveComponentEx e) {
        // @todo Auto-generated catch block
        e.printStackTrace();
    } catch (AcsJNoPermissionEx e) {
        fail("No permission");
    }
}
Also used : HashMap(java.util.HashMap) AcsJComponentSpecIncompatibleWithActiveComponentEx(alma.maciErrType.wrappers.AcsJComponentSpecIncompatibleWithActiveComponentEx) URISyntaxException(java.net.URISyntaxException) ComponentSpec(com.cosylab.acs.maci.ComponentSpec) 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) AcsJCannotGetComponentEx(alma.maciErrType.wrappers.AcsJCannotGetComponentEx) AcsJIncompleteComponentSpecEx(alma.maciErrType.wrappers.AcsJIncompleteComponentSpecEx) AcsJInvalidComponentSpecEx(alma.maciErrType.wrappers.AcsJInvalidComponentSpecEx) AcsJNoPermissionEx(alma.maciErrType.wrappers.AcsJNoPermissionEx) ClientInfo(com.cosylab.acs.maci.ClientInfo) ComponentInfo(com.cosylab.acs.maci.ComponentInfo) HashMap(java.util.HashMap) Map(java.util.Map)

Example 18 with ComponentInfo

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

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

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

the class TestContainer method deactivate_component.

/**
	 * @see com.cosylab.acs.maci.Container#deactivate_component(int)
	 */
public void deactivate_component(int handle) throws RemoteException {
    synchronized (activatedComponents) {
        Integer key = new Integer(handle);
        if (activatedComponents.containsKey(key)) {
            ComponentInfo cobInfo = (ComponentInfo) activatedComponents.get(key);
            // simulate deactivation
            try {
                Thread.sleep(deactivationTime);
            } catch (InterruptedException ie) {
            }
            if (cobInfo.getComponent() instanceof TestComponent) {
                TestComponent tc = (TestComponent) cobInfo.getComponent();
                tc.deactivate();
                tc.setHandle(0);
            }
            activatedComponents.remove(key);
        }
    }
}
Also used : ComponentInfo(com.cosylab.acs.maci.ComponentInfo)

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