Search in sources :

Example 41 with ClientInfo

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

the class ManagerImplTest method testClientInfo.

public void testClientInfo() {
    try {
        //test invalid
        try {
            manager.getClientInfo(0, null, null);
            fail();
        } catch (BadParametersException bpe) {
            System.out.println("This is OK: " + bpe.getMessage());
        }
        //test invalid
        try {
            manager.getClientInfo(Integer.MAX_VALUE, null, null);
            fail();
        } catch (BadParametersException bpe) {
            System.out.println("This is OK: " + bpe.getMessage());
        }
        //test invalid
        try {
            manager.getClientInfo(dummyHandle, null, null);
            fail();
        } catch (BadParametersException bpe) {
            System.out.println("This is OK: " + bpe.getMessage());
        }
        //test invalid
        try {
            manager.getClientInfo(dummyHandle, new int[0], null);
            fail();
        } catch (BadParametersException bpe) {
            System.out.println("This is OK: " + bpe.getMessage());
        }
        //test invalid
        try {
            manager.getClientInfo(dummyHandle, new int[0], "non-null");
            fail();
        } catch (AcsJNoPermissionEx npe) {
            System.out.println("This is OK: " + npe.toString());
        }
        /*
			//test invalid regular expression
			try {
				manager.getClientInfo(dummyHandle, new int[0], ")");		
				fail();
			}
			catch (BadParametersException bpe)
			{
	
				System.out.println("This is OK: "+bpe.getMessage());
			}
			*/
        //test valid
        ClientInfo info = manager.login(new TestClient(clientName));
        int[] handles = { info.getHandle() };
        ClientInfo[] infos = manager.getClientInfo(info.getHandle(), handles, null);
        assertNotNull(infos);
        assertEquals(infos.length, 1);
        assertEquals(infos[0], info);
        manager.logout(info.getHandle());
        //test inaccessible
        info = manager.login(new TestClient(clientName));
        handles[0] = info.getHandle();
        ClientInfo anotherInfo = manager.login(new TestClient(anotherName));
        try {
            manager.getClientInfo(anotherInfo.getHandle(), handles, null);
            fail();
        } catch (AcsJNoPermissionEx npe) {
            System.out.println("This is OK: " + npe.toString());
        }
        try {
            manager.getClientInfo(anotherInfo.getHandle(), new int[0], clientName);
            fail();
        } catch (AcsJNoPermissionEx npe) {
            System.out.println("This is OK: " + npe.toString());
        }
        manager.logout(info.getHandle());
        manager.logout(anotherInfo.getHandle());
        //test valid and invalid client info
        info = manager.login(new TestClient(clientName));
        handles = new int[2];
        handles[0] = info.getHandle();
        handles[1] = dummyHandle;
        try {
            infos = manager.getClientInfo(info.getHandle(), handles, null);
            fail();
        } catch (AcsJNoPermissionEx npe) {
            System.out.println("This is OK: " + npe.toString());
        }
        manager.logout(info.getHandle());
        //test invalid and inaccessible client info
        info = manager.login(new TestClient(clientName));
        anotherInfo = manager.login(new TestClient(anotherName));
        handles = new int[2];
        handles[0] = anotherInfo.getHandle();
        handles[1] = dummyHandle;
        try {
            infos = manager.getClientInfo(info.getHandle(), handles, null);
            fail();
        } catch (AcsJNoPermissionEx npe) {
            System.out.println("This is OK: " + npe.toString());
        }
        manager.logout(info.getHandle());
        manager.logout(anotherInfo.getHandle());
        //test valid and inaccessible client info
        info = manager.login(new TestClient(clientName));
        anotherInfo = manager.login(new TestClient(anotherName));
        handles = new int[2];
        handles[0] = info.getHandle();
        handles[1] = anotherInfo.getHandle();
        try {
            infos = manager.getClientInfo(info.getHandle(), handles, null);
            fail();
        } catch (AcsJNoPermissionEx npe) {
            System.out.println("This is OK: " + npe.toString());
        }
        manager.logout(info.getHandle());
        manager.logout(anotherInfo.getHandle());
        //test valid, invalid and inaccessible client info
        info = manager.login(new TestClient(clientName));
        anotherInfo = manager.login(new TestClient(anotherName));
        handles = new int[3];
        handles[0] = info.getHandle();
        handles[1] = anotherInfo.getHandle();
        handles[2] = dummyHandle;
        try {
            infos = manager.getClientInfo(info.getHandle(), handles, null);
            fail();
        } catch (AcsJNoPermissionEx npe) {
            System.out.println("This is OK: " + npe.toString());
        }
        manager.logout(info.getHandle());
        manager.logout(anotherInfo.getHandle());
        //test duplicating infos
        info = manager.login(new TestClient(clientName));
        handles = new int[2];
        handles[0] = info.getHandle();
        handles[1] = info.getHandle();
        try {
            infos = manager.getClientInfo(info.getHandle(), handles, null);
            fail();
        } catch (AcsJNoPermissionEx npe) {
            System.out.println("This is OK: " + npe.toString());
        }
        manager.logout(info.getHandle());
        //test with INTROSPECTION_MANAGER rights
        info = manager.login(new TestClient(clientName));
        ClientInfo adminInfo = manager.login(new TestAdministrator(administratorName));
        handles = new int[3];
        handles[0] = adminInfo.getHandle();
        handles[1] = info.getHandle();
        handles[2] = dummyHandle;
        infos = manager.getClientInfo(adminInfo.getHandle(), handles, null);
        assertNotNull(infos);
        assertEquals(infos[0].getHandle(), adminInfo.getHandle());
        assertEquals(infos[1].getHandle(), info.getHandle());
        //assertEquals(infos[2].getHandle(),0);
        assertNull(infos[2]);
        manager.logout(info.getHandle());
        manager.logout(adminInfo.getHandle());
        // test wildcard search		
        info = manager.login(new TestClient("client1"));
        assertNotNull(info);
        ClientInfo info2 = manager.login(new TestClient("client2a"));
        assertNotNull(info2);
        ClientInfo info3 = manager.login(new TestClient("client3aa"));
        assertNotNull(info3);
        ClientInfo info4 = manager.login(new TestClient("other4"));
        assertNotNull(info4);
        adminInfo = manager.login(new TestAdministrator("client55"));
        assertNotNull(adminInfo);
        //infos = manager.getClientInfo(adminInfo.getHandle(), new int[0], "client.*");
        infos = manager.getClientInfo(adminInfo.getHandle(), new int[0], "client*");
        assertNotNull(infos);
        assertEquals(4, infos.length);
        assertEquals(info.getHandle(), infos[0].getHandle());
        assertEquals(info2.getHandle(), infos[1].getHandle());
        assertEquals(info3.getHandle(), infos[2].getHandle());
        assertEquals(adminInfo.getHandle(), infos[3].getHandle());
        manager.logout(info.getHandle());
        manager.logout(info2.getHandle());
        manager.logout(info3.getHandle());
        manager.logout(info4.getHandle());
        manager.logout(adminInfo.getHandle());
    } catch (AcsJNoPermissionEx e) {
        fail("No permission");
    }
}
Also used : AcsJNoPermissionEx(alma.maciErrType.wrappers.AcsJNoPermissionEx) ClientInfo(com.cosylab.acs.maci.ClientInfo) BadParametersException(com.cosylab.acs.maci.BadParametersException)

Example 42 with ClientInfo

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

the class ManagerImplTest method testGetCyclicHierachicalComponent.

/*
	This test was disabled, since construct() is not yet implemented as it should be,
	now it activation (named) lock is aquired also when construct() method is called!
	 
	public void testGetCyclicHierachicalComponentConstructCase()
	{
		// activation of subcomponents is requested in construct() method 
		testGetCyclicHierachicalComponent(false);
	}

	*/
private void testGetCyclicHierachicalComponent(boolean constructCase) {
    try {
        TestContainer container = new TestContainer("Container");
        Map supportedComponents = new HashMap();
        // MOUNT2 -> MOUNT2 cycle
        TestHierarchicalComponent mount2HierCOB = new TestHierarchicalComponent("CyclicHierarchical", manager, new String[] { "MOUNT2" }, true, constructCase);
        supportedComponents.put("MOUNT2", mount2HierCOB);
        // MOUNT3 -> MOUNT5 -> PBEND_B_01 -> MOUNT3 cycle
        TestHierarchicalComponent mount3HierCOB = new TestHierarchicalComponent("MOUNT3", manager, new String[] { "MOUNT4" }, true, constructCase);
        supportedComponents.put("MOUNT3", mount3HierCOB);
        TestHierarchicalComponent mount4HierCOB = new TestHierarchicalComponent("MOUNT4", manager, new String[] { "PBEND_B_01" }, true, constructCase);
        supportedComponents.put("MOUNT4", mount4HierCOB);
        TestHierarchicalComponent pbendHierCOB = new TestHierarchicalComponent("PBEND_B_01", manager, new String[] { "MOUNT3" }, true, constructCase);
        supportedComponents.put("PBEND_B_01", pbendHierCOB);
        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);
        long startTime = System.currentTimeMillis();
        // this will cause cyclic depedency...
        try {
            StatusHolder status;
            Component ref;
            URI mount2URI = new URI("MOUNT2");
            status = new StatusHolder();
            ref = manager.getComponent(info.getHandle(), mount2URI, true, status);
            fail();
        } catch (AcsJCannotGetComponentEx e) {
            System.out.println("This is OK: cyclic dependency " + e.toString());
        } catch (Exception ex) {
            fail();
        }
        long stopTime = System.currentTimeMillis();
        // cyclic dependency should be detected, not deadlock detected
        if (stopTime - startTime > 30000)
            fail("Cyclic dependency detection is too slow.");
        startTime = System.currentTimeMillis();
        // this will cause cyclic depedency...
        try {
            URI mount3URI = new URI("MOUNT3");
            StatusHolder status = new StatusHolder();
            Component ref = manager.getComponent(info.getHandle(), mount3URI, true, status);
            fail();
        } catch (AcsJCannotGetComponentEx e) {
            System.out.println("This is OK: cyclic dependency " + e.toString());
        } catch (Exception ex) {
            fail();
        }
        stopTime = System.currentTimeMillis();
        // cyclic dependency should be detected, not deadlock detected
        if (stopTime - startTime > 30000)
            fail("Cyclic dependency detection is too slow.");
    } catch (AcsJNoPermissionEx e) {
        fail("No permission");
    }
}
Also used : HashMap(java.util.HashMap) URI(java.net.URI) AcsJCannotGetComponentEx(alma.maciErrType.wrappers.AcsJCannotGetComponentEx) 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 43 with ClientInfo

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

the class ManagerImplTest method testGetDefaultComponent.

/**
	 * Test getDefaultComponent.
	 */
public void testGetDefaultComponent() {
    try {
        try {
            manager.getDefaultComponent(0, null);
            fail();
        } catch (BadParametersException bpe) {
            System.out.println("This is OK: " + bpe.getMessage());
        }
        try {
            manager.getDefaultComponent(Integer.MAX_VALUE, null);
            fail();
        } catch (BadParametersException bpe) {
            System.out.println("This is OK: " + bpe.getMessage());
        }
        try {
            manager.getDefaultComponent(dummyHandle, "dummyType");
            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.getDefaultComponent(info.getHandle(), null);
            fail();
        } catch (BadParametersException bpe) {
            System.out.println("This is OK: " + bpe.getMessage());
        }
        try {
            manager.getDefaultComponent(info.getHandle(), "invalid");
            fail();
        } catch (NoDefaultComponentException ndce) {
            System.out.println("This is OK: " + ndce.getMessage());
        }
        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);
        try {
            ComponentInfo componentInfo = manager.getDefaultComponent(info.getHandle(), "IDL:alma/MOUNT_ACS/Mount:1.0");
            assertTrue(componentInfo != null);
            assertEquals(componentInfo.getComponent(), mount3COB);
        } catch (NoDefaultComponentException ndce) {
            fail();
        }
    } catch (AcsJNoPermissionEx e) {
        fail("No permission");
    } catch (NoDefaultComponentException e) {
        fail();
    }
}
Also used : AcsJNoPermissionEx(alma.maciErrType.wrappers.AcsJNoPermissionEx) HashMap(java.util.HashMap) 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) NoDefaultComponentException(com.cosylab.acs.maci.NoDefaultComponentException) BadParametersException(com.cosylab.acs.maci.BadParametersException)

Example 44 with ClientInfo

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

the class ManagerImplTest method testUnregisterComponent.

public void testUnregisterComponent() {
    //test invalid
    try {
        manager.unregisterComponent(0, 0);
        fail();
    } catch (AcsJNoPermissionEx npe) {
        System.out.println("This is OK: " + npe.toString());
    } catch (AcsJBadParameterEx bpe) {
        fail();
    }
    //test invalid
    try {
        manager.unregisterComponent(Integer.MAX_VALUE, 0);
        fail();
    } catch (AcsJNoPermissionEx npe) {
        System.out.println("This is OK: " + npe.toString());
    } catch (AcsJBadParameterEx bpe) {
        fail();
    }
    //test invalid
    try {
        manager.unregisterComponent(dummyHandle, 0);
        fail();
    } catch (AcsJNoPermissionEx npe) {
        System.out.println("This is OK: " + npe.toString());
    } catch (AcsJBadParameterEx bpe) {
        fail();
    }
    //test invalid
    try {
        manager.unregisterComponent(dummyHandle, Integer.MAX_VALUE);
        fail();
    } catch (AcsJNoPermissionEx npe) {
        System.out.println("This is OK: " + npe.toString());
    } catch (AcsJBadParameterEx bpe) {
        fail();
    }
    try {
        //unregister valid
        ClientInfo info = manager.login(new TestClient(anotherName));
        int handle = 0;
        try {
            handle = manager.registerComponent(info.getHandle(), dummyURI, type, new TestComponent(cobName));
        } catch (AcsJBadParameterEx e) {
            fail();
        }
        try {
            manager.unregisterComponent(info.getHandle(), handle);
        } catch (AcsJBadParameterEx e) {
            fail();
        }
        //duplicate unregistration		
        try {
            manager.unregisterComponent(info.getHandle(), handle);
            fail();
        } catch (AcsJBadParameterEx bpe) {
            System.out.println("This is OK: duplicate unregistration " + bpe.toString());
        }
        manager.logout(info.getHandle());
    } catch (AcsJNoPermissionEx e) {
        e.printStackTrace();
        fail("No permission");
    }
}
Also used : AcsJBadParameterEx(alma.ACSErrTypeCommon.wrappers.AcsJBadParameterEx) AcsJNoPermissionEx(alma.maciErrType.wrappers.AcsJNoPermissionEx) ClientInfo(com.cosylab.acs.maci.ClientInfo)

Example 45 with ClientInfo

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

the class ManagerImplTest method testForceReleaseComponent.

public void testForceReleaseComponent() {
    try {
        try {
            manager.forceReleaseComponent(0, null);
            fail();
        } catch (AcsJBadParameterEx bpe) {
            System.out.println("This is OK: null parameter");
        }
        try {
            manager.forceReleaseComponent(Integer.MAX_VALUE, null);
            fail();
        } catch (AcsJBadParameterEx bpe) {
            System.out.println("This is OK: null parameter");
        }
        try {
            manager.forceReleaseComponent(dummyHandle, dummyURI);
            fail();
        } catch (AcsJNoPermissionEx npe) {
            System.out.println("This is OK: " + npe.toString());
        } catch (AcsJBadParameterEx bpe) {
            fail();
        }
        TestAdministrator admin = new TestAdministrator(administratorName);
        ClientInfo adminInfo = manager.login(admin);
        assertTrue(adminInfo.getHandle() != 0);
        TestClient client = new TestClient(clientName);
        ClientInfo info = manager.login(client);
        assertTrue(info.getHandle() != 0);
        TestClient client2 = new TestClient(clientName + "2");
        ClientInfo info2 = manager.login(client2);
        assertTrue(info2.getHandle() != 0);
        TestContainer container = new TestContainer("Container");
        Map supportedComponents = new HashMap();
        Component mount1COB = new TestComponent("MOUNT1");
        Component mount4COB = new TestComponent("MOUNT4");
        supportedComponents.put("MOUNT1", mount1COB);
        supportedComponents.put("MOUNT4", mount4COB);
        container.setSupportedComponents(supportedComponents);
        ClientInfo containerInfo = manager.login(container);
        // client activate 
        URI mount4 = null;
        try {
            mount4 = new URI("MOUNT4");
            StatusHolder status = new StatusHolder();
            Component ref = manager.getComponent(info.getHandle(), mount4, true, status);
            assertEquals(mount4COB, ref);
            assertEquals(ComponentStatus.COMPONENT_ACTIVATED, status.getStatus());
        } catch (Exception ex) {
            fail();
        }
        // client2 activate 
        try {
            StatusHolder status = new StatusHolder();
            Component ref = manager.getComponent(info2.getHandle(), mount4, true, status);
            assertEquals(mount4COB, 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 only two Components activated (MOUNT1 and MOUNT4)
        ComponentInfo[] infos = manager.getComponentInfo(info.getHandle(), new int[0], "*", "*", true);
        assertEquals(2, infos.length);
        /*
			// test forceful release (no permission - no admin)
			try
			{
				manager.forceReleaseComponent(info.getHandle(), mount4);
				fail();
			}
			catch (AcsJNoPermissionEx npe)
			{
	
				System.out.println("This is OK: "+npe.toString());
			}
			*/
        // TODO tmp - due to Heiko's hack
        System.out.println("This is OK: Insufficient rights.");
        // test forceful release
        int clients;
        try {
            clients = manager.forceReleaseComponent(adminInfo.getHandle(), mount4);
            assertEquals(2, clients);
        } catch (AcsJBadParameterEx e) {
            fail();
        }
        // there should be only one component activated (MOUNT1)
        infos = manager.getComponentInfo(info.getHandle(), new int[0], "*", "*", true);
        assertEquals(1, infos.length);
        // admin activate 
        try {
            StatusHolder status = new StatusHolder();
            Component ref = manager.getComponent(adminInfo.getHandle(), mount4, true, status);
            assertEquals(mount4COB, ref);
            assertEquals(ComponentStatus.COMPONENT_ACTIVATED, status.getStatus());
        } catch (Exception ex) {
            fail();
        }
        // there should be two components activated (MOUNT1 and MOUNT4)
        infos = manager.getComponentInfo(info.getHandle(), new int[0], "*", "*", true);
        assertEquals(2, infos.length);
        try {
            clients = manager.releaseComponent(adminInfo.getHandle(), mount4);
            assertEquals(2, clients);
        } catch (AcsJBadParameterEx e) {
            fail();
        }
        // there should be two components activated (MOUNT1 and MOUNT4)
        infos = manager.getComponentInfo(info.getHandle(), new int[0], "*", "*", true);
        assertEquals(2, infos.length);
        // there should be two components activated (MOUNT1 and MOUNT4)
        infos = manager.getComponentInfo(info.getHandle(), new int[0], "MOUNT4", "*", true);
        assertEquals(1, infos.length);
        IntArray compClients = infos[0].getClients();
        assertEquals(2, compClients.size());
        assertTrue(compClients.contains(info.getHandle()));
        assertTrue(compClients.contains(info2.getHandle()));
    } 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) IntArray(com.cosylab.acs.maci.IntArray) 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)

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