Search in sources :

Example 6 with ClientInfo

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

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

the class ManagerImplTest method testRestartComponent.

public void testRestartComponent() {
    try {
        try {
            manager.restartComponent(0, null);
            fail();
        } catch (AcsJBadParameterEx bpe) {
            System.out.println("This is OK: null parameter");
        }
        try {
            manager.restartComponent(Integer.MAX_VALUE, null);
            fail();
        } catch (AcsJBadParameterEx bpe) {
            System.out.println("This is OK: null parameter");
        }
        try {
            manager.restartComponent(dummyHandle, dummyURI);
            fail();
        } catch (AcsJNoPermissionEx npe) {
            System.out.println("This is OK: " + npe.toString());
        } catch (AcsJBadParameterEx bpe) {
            fail();
        }
        TestClient client = new TestClient(clientName);
        ClientInfo info = manager.login(client);
        assertTrue(info.getHandle() != 0);
        try {
            manager.restartComponent(info.getHandle(), null);
            fail();
        } catch (AcsJBadParameterEx bpe) {
            System.out.println("This is OK: null parameter");
        }
        URI mount = null;
        try {
            mount = new URI("MOUNT3");
            Component component = manager.restartComponent(info.getHandle(), mount);
            assertEquals(null, component);
        } catch (AcsJBadParameterEx bpe) {
            fail();
        } catch (URISyntaxException usi) {
            fail();
        }
        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);
        // activate
        try {
            StatusHolder status = new StatusHolder();
            Component ref = manager.getComponent(info.getHandle(), mount, true, status);
            assertEquals(mount3COB, ref);
            assertEquals(ComponentStatus.COMPONENT_ACTIVATED, status.getStatus());
        } catch (Exception ex) {
            fail();
        }
        // restart 
        try {
            Component returnedComponent = manager.restartComponent(info.getHandle(), mount);
            assertEquals(mount3COB, returnedComponent);
        } catch (Exception ex) {
            fail();
        }
        // no owner client test
        TestClient client2 = new TestClient("thief");
        ClientInfo info2 = manager.login(client2);
        assertTrue(info2.getHandle() != 0);
        try {
            manager.restartComponent(info2.getHandle(), mount);
            fail();
        } catch (AcsJNoPermissionEx npe) {
            System.out.println("This is OK: " + npe.toString());
        } catch (AcsJBadParameterEx bpe) {
            fail();
        }
    } catch (AcsJNoPermissionEx e) {
        fail("No permission");
    }
}
Also used : AcsJBadParameterEx(alma.ACSErrTypeCommon.wrappers.AcsJBadParameterEx) HashMap(java.util.HashMap) URISyntaxException(java.net.URISyntaxException) 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) Component(com.cosylab.acs.maci.Component) HashMap(java.util.HashMap) Map(java.util.Map)

Example 8 with ClientInfo

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

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

the class ManagerImplTest method testBadAdministratorNotifications.

// first two callback blocks
// this means that third should not happen before first two
// and all calls should be done from the same thread
public void testBadAdministratorNotifications() {
    try {
        final long BLOCK_TIMEOUT_MS = 3000;
        TestAdministrator admin = new TestAdministrator("admin", true) {

            private AtomicInteger counter = new AtomicInteger(0);

            private AtomicLong threadId = new AtomicLong(-1);

            public void clientLoggedIn(ClientInfo info, long timeStamp, long executionId) {
                // same as last thread check (transitive)
                // positive
                long thisThreadId = Thread.currentThread().getId();
                long previousId = threadId.getAndSet(thisThreadId);
                if (previousId != thisThreadId && previousId >= 0)
                    fail("notification called from other thread");
                // only first two block for a while
                if (counter.incrementAndGet() < 3) {
                    try {
                        Thread.sleep(BLOCK_TIMEOUT_MS);
                    } catch (InterruptedException e) {
                    // noop
                    }
                }
                super.clientLoggedIn(info, timeStamp, executionId);
            }
        };
        ClientInfo adminInfo = manager.login(admin);
        assertNotNull(adminInfo);
        // now we login 3 clients
        Client client1 = new TestClient("client1");
        Client client2 = new TestClient("client2");
        Client client3 = new TestClient("client3");
        // even if admin is blocking, this should not block this
        // notification are async (not a SyncAdmin)
        long startTS = System.currentTimeMillis();
        ClientInfo clientInfo1 = manager.login(client1);
        assertNotNull(clientInfo1);
        ClientInfo clientInfo2 = manager.login(client2);
        assertNotNull(clientInfo2);
        ClientInfo clientInfo3 = manager.login(client3);
        assertNotNull(clientInfo3);
        long stopTS = System.currentTimeMillis();
        assertTrue((stopTS - startTS) < BLOCK_TIMEOUT_MS);
        ArrayList notifications = admin.getClientLoggedInNotifications();
        synchronized (notifications) {
            int count = 0;
            while (notifications.size() < 3) {
                // wait max up to 3*BLOCK_TIMEOUT_MS (must be careful about spurious wakeups)
                if ((System.currentTimeMillis() - stopTS) > 3 * BLOCK_TIMEOUT_MS) {
                    fail("expected 3 notifications, got " + notifications.size());
                }
                try {
                    notifications.wait(3 * BLOCK_TIMEOUT_MS);
                } catch (InterruptedException e) {
                /* noop */
                }
            }
            assertEquals(3, notifications.size());
            assertEquals(clientInfo1, notifications.get(0));
            assertEquals(clientInfo2, notifications.get(1));
            assertEquals(clientInfo3, notifications.get(2));
        }
    } catch (AcsJNoPermissionEx e) {
        fail("No permission");
    }
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) AcsJNoPermissionEx(alma.maciErrType.wrappers.AcsJNoPermissionEx) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ArrayList(java.util.ArrayList) ClientInfo(com.cosylab.acs.maci.ClientInfo) Client(com.cosylab.acs.maci.Client)

Example 10 with ClientInfo

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

the class ManagerImplTest method testReleaseComponentAsync.

public void testReleaseComponentAsync() throws Throwable {
    try {
        try {
            manager.releaseComponentAsync(0, null, null);
            fail();
        } catch (AcsJBadParameterEx bpe) {
            System.out.println("This is OK: null parameter");
        }
        try {
            manager.releaseComponentAsync(Integer.MAX_VALUE, null, null);
            fail();
        } catch (AcsJBadParameterEx bpe) {
            System.out.println("This is OK: null parameter");
        }
        try {
            manager.releaseComponentAsync(dummyHandle, dummyURI, null);
            fail();
        } catch (AcsJNoPermissionEx npe) {
            System.out.println("This is OK: " + npe.toString());
        } catch (AcsJBadParameterEx bpe) {
            fail();
        }
        TestClient client = new TestClient(clientName);
        ClientInfo info = manager.login(client);
        TestClient client2 = new TestClient("anotherClient");
        ClientInfo info2 = manager.login(client2);
        TestContainer container = new TestContainer("Container");
        Map supportedComponents = new HashMap();
        Component mount1COB = new TestComponent("MOUNT1");
        supportedComponents.put("MOUNT1", mount1COB);
        Component mount4COB = new TestComponent("MOUNT4", false, true);
        supportedComponents.put("MOUNT4", mount4COB);
        container.setSupportedComponents(supportedComponents);
        ClientInfo containerInfo = manager.login(container);
        // here also parallel activation will be tested (autostart and activation bellow)
        StatusHolder status = new StatusHolder();
        Component ref = manager.getComponent(info.getHandle(), new URI("MOUNT1"), true, status);
        assertEquals(mount1COB, ref);
        assertEquals(ComponentStatus.COMPONENT_ACTIVATED, status.getStatus());
        status = new StatusHolder();
        ref = manager.getComponent(info2.getHandle(), new URI("MOUNT1"), true, status);
        assertEquals(mount1COB, ref);
        assertEquals(ComponentStatus.COMPONENT_ACTIVATED, status.getStatus());
        ref = manager.getComponent(info.getHandle(), new URI("MOUNT4"), true, status);
        assertEquals(mount4COB, ref);
        assertEquals(ComponentStatus.COMPONENT_ACTIVATED, status.getStatus());
        try {
            LongCompletionCallbackTestImpl lcc = new LongCompletionCallbackTestImpl();
            synchronized (lcc) {
                manager.releaseComponentAsync(info2.getHandle(), new URI("MOUNT1"), lcc);
                if (!lcc.doneFlag)
                    lcc.wait(SLEEP_TIME_MS);
                if (!lcc.doneFlag)
                    fail("callback not called");
                assertEquals(1, lcc.result);
                assertNull(lcc.exception);
                lcc.reset();
                manager.releaseComponentAsync(info.getHandle(), new URI("MOUNT1"), lcc);
                if (!lcc.doneFlag)
                    lcc.wait(SLEEP_TIME_MS);
                if (!lcc.doneFlag)
                    fail("callback not called");
                assertEquals(0, lcc.result);
                assertNull(lcc.exception);
                lcc.reset();
                manager.releaseComponentAsync(info.getHandle(), new URI("MOUNT4"), lcc);
                if (!lcc.doneFlag)
                    lcc.wait(SLEEP_TIME_MS);
                if (!lcc.doneFlag)
                    fail("callback not called");
                assertEquals(0, lcc.result);
                assertNotNull(lcc.exception);
            }
        } catch (Exception ex) {
            fail(ex.toString());
        }
    } 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) ClientInfo(com.cosylab.acs.maci.ClientInfo) Component(com.cosylab.acs.maci.Component) 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