Search in sources :

Example 11 with AcsJNoPermissionEx

use of alma.maciErrType.wrappers.AcsJNoPermissionEx in project ACS by ACS-Community.

the class ManagerImplTest method testAdministratorNotifications.

public void testAdministratorNotifications() {
    try {
        TestAdministrator admin = new TestAdministrator("admin", true);
        ClientInfo adminInfo = manager.login(admin);
        assertNotNull(adminInfo);
        TestAdministrator admin2 = new TestAdministrator("admin2", true);
        ClientInfo adminInfo2 = manager.login(admin2);
        assertNotNull(adminInfo2);
        checkForNotification(admin.getClientLoggedInNotifications(), adminInfo2);
        TestAdministrator admin3 = new TestAdministrator("admin3", true);
        ClientInfo adminInfo3 = manager.login(admin3);
        assertNotNull(adminInfo3);
        checkForNotification(admin.getClientLoggedInNotifications(), adminInfo3);
        checkForNotification(admin2.getClientLoggedInNotifications(), adminInfo3);
        // test client login notification
        Client client = new TestClient("client");
        ClientInfo clientInfo = manager.login(client);
        assertNotNull(clientInfo);
        checkForNotification(admin.getClientLoggedInNotifications(), clientInfo);
        checkForNotification(admin2.getClientLoggedInNotifications(), clientInfo);
        checkForNotification(admin3.getClientLoggedInNotifications(), clientInfo);
        // test container login notification
        Container container = new TestContainer("Container");
        ClientInfo containerInfo = manager.login(container);
        assertNotNull(containerInfo);
        Integer h = new Integer(containerInfo.getHandle());
        checkForNotification(admin.getContainerLoggedInNotifications(), h);
        checkForNotification(admin2.getContainerLoggedInNotifications(), h);
        checkForNotification(admin3.getContainerLoggedInNotifications(), h);
        manager.logout(containerInfo.getHandle());
        checkForNotification(admin.getContainerLoggedOutNotifications(), h);
        checkForNotification(admin2.getContainerLoggedOutNotifications(), h);
        checkForNotification(admin3.getContainerLoggedOutNotifications(), h);
        manager.logout(clientInfo.getHandle());
        h = new Integer(clientInfo.getHandle());
        checkForNotification(admin.getClientLoggedOutNotifications(), h);
        checkForNotification(admin2.getClientLoggedOutNotifications(), h);
        checkForNotification(admin3.getClientLoggedOutNotifications(), h);
        manager.logout(adminInfo3.getHandle());
        h = new Integer(adminInfo3.getHandle());
        checkForNotification(admin.getClientLoggedOutNotifications(), h);
        checkForNotification(admin2.getClientLoggedOutNotifications(), h);
        manager.logout(adminInfo2.getHandle());
        h = new Integer(adminInfo2.getHandle());
        checkForNotification(admin.getClientLoggedOutNotifications(), h);
        manager.logout(adminInfo.getHandle());
        // test
        assertEquals(0, admin.getClientLoggedInNotifications().size());
        assertEquals(0, admin.getClientLoggedOutNotifications().size());
        assertEquals(0, admin.getContainerLoggedInNotifications().size());
        assertEquals(0, admin.getContainerLoggedOutNotifications().size());
        assertEquals(0, admin2.getClientLoggedInNotifications().size());
        assertEquals(0, admin2.getClientLoggedOutNotifications().size());
        assertEquals(0, admin2.getContainerLoggedInNotifications().size());
        assertEquals(0, admin2.getContainerLoggedOutNotifications().size());
        assertEquals(0, admin3.getClientLoggedInNotifications().size());
        assertEquals(0, admin3.getClientLoggedOutNotifications().size());
        assertEquals(0, admin3.getContainerLoggedInNotifications().size());
        assertEquals(0, admin3.getContainerLoggedOutNotifications().size());
    } catch (AcsJNoPermissionEx e) {
        fail("No permission");
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Container(com.cosylab.acs.maci.Container) AcsJNoPermissionEx(alma.maciErrType.wrappers.AcsJNoPermissionEx) ClientInfo(com.cosylab.acs.maci.ClientInfo) Client(com.cosylab.acs.maci.Client)

Example 12 with AcsJNoPermissionEx

use of alma.maciErrType.wrappers.AcsJNoPermissionEx 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 13 with AcsJNoPermissionEx

use of alma.maciErrType.wrappers.AcsJNoPermissionEx 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 14 with AcsJNoPermissionEx

use of alma.maciErrType.wrappers.AcsJNoPermissionEx 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 15 with AcsJNoPermissionEx

use of alma.maciErrType.wrappers.AcsJNoPermissionEx 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

AcsJNoPermissionEx (alma.maciErrType.wrappers.AcsJNoPermissionEx)63 ClientInfo (com.cosylab.acs.maci.ClientInfo)39 BadParametersException (com.cosylab.acs.maci.BadParametersException)37 NoResourcesException (com.cosylab.acs.maci.NoResourcesException)33 URI (java.net.URI)25 Component (com.cosylab.acs.maci.Component)24 ComponentInfo (com.cosylab.acs.maci.ComponentInfo)24 URISyntaxException (java.net.URISyntaxException)24 HashMap (java.util.HashMap)21 Map (java.util.Map)21 NoDefaultComponentException (com.cosylab.acs.maci.NoDefaultComponentException)20 RemoteException (com.cosylab.acs.maci.RemoteException)18 StatusHolder (com.cosylab.acs.maci.StatusHolder)18 CoreException (com.cosylab.acs.maci.CoreException)14 AcsJCannotGetComponentEx (alma.maciErrType.wrappers.AcsJCannotGetComponentEx)13 BAD_PARAM (org.omg.CORBA.BAD_PARAM)13 UNKNOWN (org.omg.CORBA.UNKNOWN)13 NO_RESOURCES (org.omg.CORBA.NO_RESOURCES)12 AcsJBadParameterEx (alma.ACSErrTypeCommon.wrappers.AcsJBadParameterEx)10 Object (org.omg.CORBA.Object)9