Search in sources :

Example 51 with ClientInfo

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

the class ManagerImplTest method testGetCyclicHierachicalComponentAllowWithPreactivated.

// if one component in a cycle is preactivated, that this is allowed
public void testGetCyclicHierachicalComponentAllowWithPreactivated() /*boolean constructCase*/
{
    boolean constructCase = false;
    try {
        TestContainer container = new TestContainer("Container");
        Map supportedComponents = new HashMap();
        // MOUNT3 -> (last will request MOUNT4)
        TestHierarchicalComponent mount3HierCOB = new TestHierarchicalComponent("MOUNT3", manager, new String[] {}, true, constructCase);
        supportedComponents.put("MOUNT3", mount3HierCOB);
        // MOUNT4 -> PBEND_B_01 -> MOUNT3 cycle
        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);
        // activate MOUNT3
        try {
            URI mount3URI = new URI("MOUNT3");
            StatusHolder status = new StatusHolder();
            Component ref = manager.getComponent(info.getHandle(), mount3URI, true, status);
            assertEquals(mount3HierCOB, ref);
            assertEquals(ComponentStatus.COMPONENT_ACTIVATED, status.getStatus());
        } catch (Exception ex) {
            fail();
        }
        // this should be allowed
        try {
            URI mount4URI = new URI("MOUNT4");
            StatusHolder status = new StatusHolder();
            Component ref = manager.getComponent(mount3HierCOB.getHandle(), mount4URI, true, status);
            assertEquals(mount4HierCOB, ref);
            assertEquals(ComponentStatus.COMPONENT_ACTIVATED, status.getStatus());
        } catch (Exception ex) {
            fail();
        }
        // test activated Components
        // there should be all three Components activated
        ComponentInfo[] infos = manager.getComponentInfo(info.getHandle(), new int[0], "*", "*", true);
        assertEquals(3, infos.length);
    } 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) 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 52 with ClientInfo

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

the class ManagerImplTest method testRegisterComponent.

public void testRegisterComponent() {
    try {
        //test invalid
        try {
            manager.registerComponent(0, null, null, null);
            fail();
        } catch (AcsJBadParameterEx bpe) {
            System.out.println("This is OK " + bpe.toString());
        }
        //test invalid
        try {
            manager.registerComponent(dummyHandle, null, type, null);
            fail();
        } catch (AcsJBadParameterEx bpe) {
            System.out.println("This is OK " + bpe.toString());
        }
        //test invalid
        try {
            manager.registerComponent(dummyHandle, dummyURI, type, null);
            fail();
        } catch (AcsJBadParameterEx bpe) {
            System.out.println("This is OK " + bpe.toString());
        }
        //test invalid
        try {
            manager.registerComponent(dummyHandle, null, null, new TestComponent(cobName));
            fail();
        } catch (AcsJBadParameterEx bpe) {
            System.out.println("This is OK " + bpe.toString());
        }
        //register with empty curl
        ClientInfo cinfo = manager.login(new TestClient(clientName));
        try {
            manager.registerComponent(cinfo.getHandle(), new URI(""), type, new TestComponent(cobName));
            fail();
        } catch (AcsJBadParameterEx bpe) {
            System.out.println("This is OK: empty URI " + bpe.toString());
        } catch (URISyntaxException e) {
            fail();
        }
        //register with wrong domain
        try {
            manager.registerComponent(cinfo.getHandle(), new URI("curl://other/KIKI"), type, new TestComponent(cobName));
            fail();
        } catch (AcsJBadParameterEx bpe) {
            System.out.println("This is OK: URI does not exist " + bpe.toString());
        } catch (URISyntaxException e) {
            fail();
        }
        // wrong schema
        try {
            manager.registerComponent(cinfo.getHandle(), new URI("KIKI://other/KIKI"), type, new TestComponent(cobName));
            fail();
        } catch (AcsJBadParameterEx bpe) {
            System.out.println("This is OK: invalid URI " + bpe.toString());
        } catch (URISyntaxException e) {
            fail();
        }
        // no path
        try {
            manager.registerComponent(cinfo.getHandle(), new URI("KIKI://other/"), type, new TestComponent(cobName));
            fail();
        } catch (AcsJBadParameterEx bpe) {
            System.out.println("This is OK: invalid URI " + bpe.toString());
        } catch (URISyntaxException e) {
            fail();
        }
        //register valid but from other domain
        try {
            manager.registerComponent(cinfo.getHandle(), new URI("curl://other/GIZMO1"), type, new TestComponent(cobName));
            fail();
        } catch (AcsJBadParameterEx bpe) {
            System.out.println("This is OK: invalid URI " + bpe.toString());
        } catch (URISyntaxException e) {
            fail();
        }
        //register valid
        try {
            int handle = manager.registerComponent(cinfo.getHandle(), new URI("curl:///GIZMO1"), type, new TestComponent(cobName));
            assertTrue(handle != 0);
            assertTrue((handle & HandleConstants.COMPONENT_MASK) == HandleConstants.COMPONENT_MASK);
        } catch (AcsJBadParameterEx bpe) {
            fail();
        } catch (URISyntaxException e) {
            fail();
        }
        try {
            int handle = manager.registerComponent(cinfo.getHandle(), new URI("curl:///GIZMO2"), type, new TestComponent(cobName));
            assertTrue(handle != 0);
            assertTrue((handle & HandleConstants.COMPONENT_MASK) == HandleConstants.COMPONENT_MASK);
        } catch (AcsJBadParameterEx bpe) {
            fail();
        } catch (URISyntaxException e) {
            fail();
        }
        try {
            int handle = manager.registerComponent(cinfo.getHandle(), new URI("GIZMO3"), type, new TestComponent(cobName));
            assertTrue(handle != 0);
            assertTrue((handle & HandleConstants.COMPONENT_MASK) == HandleConstants.COMPONENT_MASK);
        } catch (AcsJBadParameterEx bpe) {
            fail();
        } catch (URISyntaxException e) {
            fail();
        }
        // duplicate
        try {
            TestComponent cob = new TestComponent(cobName);
            int handle1 = manager.registerComponent(cinfo.getHandle(), new URI("curl:///GIZMO4"), type, cob);
            assertTrue(handle1 != 0);
            assertTrue((handle1 & HandleConstants.COMPONENT_MASK) == HandleConstants.COMPONENT_MASK);
            int handle2 = manager.registerComponent(cinfo.getHandle(), new URI("GIZMO4"), type, cob);
            assertTrue(handle2 != 0);
            assertTrue((handle2 & HandleConstants.COMPONENT_MASK) == HandleConstants.COMPONENT_MASK);
            assertEquals(handle1, handle2);
        } catch (AcsJBadParameterEx bpe) {
            fail();
        } catch (URISyntaxException e) {
            fail();
        }
        // duplicate name, different type
        try {
            TestComponent cob = new TestComponent(cobName);
            int handle1 = manager.registerComponent(cinfo.getHandle(), new URI("curl:///GIZMO4"), type, cob);
            assertTrue(handle1 != 0);
            assertTrue((handle1 & HandleConstants.COMPONENT_MASK) == HandleConstants.COMPONENT_MASK);
            manager.registerComponent(cinfo.getHandle(), new URI("GIZMO4"), type + "!", cob);
            fail();
        } catch (AcsJNoPermissionEx npe) {
            System.out.println("This is OK: " + npe.toString());
        } catch (AcsJBadParameterEx bpe) {
            fail();
        } catch (URISyntaxException e) {
            fail();
        }
        manager.logout(cinfo.getHandle());
    } catch (AcsJNoPermissionEx e) {
        fail("No permission");
    }
}
Also used : AcsJBadParameterEx(alma.ACSErrTypeCommon.wrappers.AcsJBadParameterEx) AcsJNoPermissionEx(alma.maciErrType.wrappers.AcsJNoPermissionEx) ClientInfo(com.cosylab.acs.maci.ClientInfo) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 53 with ClientInfo

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

the class ManagerImplTest method testAllComponentNames.

public void testAllComponentNames() {
    TestContainer container = new TestContainer("Container");
    Map supportedComponents = new HashMap();
    TestComponent mount1COB = new TestComponent("Default");
    supportedComponents.put("Default", 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
    try {
        TestAdministrator client = new TestAdministrator(administratorName);
        ClientInfo info = manager.login(client);
        ComponentInfo[] infos = manager.getComponentInfo(info.getHandle(), new int[0], "*", "*", false);
        assertEquals(14, infos.length);
        boolean thereisDefault = false;
        for (int i = 0; i < infos.length; i++) if (infos[i].getName().equals("Default")) {
            thereisDefault = true;
            break;
        }
        if (!thereisDefault)
            fail();
    } catch (AcsJNoPermissionEx e) {
        fail("No permission 2");
    }
}
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)

Example 54 with ClientInfo

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

the class ManagerImplTest method testLogin.

public void testLogin() {
    // test null
    try {
        manager.login(null);
        fail();
    } catch (AcsJNoPermissionEx npe) {
        fail("No permission");
    } catch (BadParametersException bpe) {
        System.out.println("This is OK: " + bpe.getMessage());
    }
    // test null name
    try {
        manager.login(new TestClient(null));
        fail();
    } catch (AcsJNoPermissionEx npe) {
        fail("No permission");
    } catch (BadParametersException bpe) {
        System.out.println("This is OK: " + bpe.getMessage());
    }
    // test null autheticate
    try {
        manager.login(new TestClient("null-auth", null));
        fail();
    } catch (AcsJNoPermissionEx npe) {
        fail("No permission");
    } catch (BadParametersException bpe) {
        System.out.println("This is OK: " + bpe.getMessage());
    }
    // test invalid autheticate
    try {
        manager.login(new TestClient("container-invalid-auth", ClientType.ADMINISTRATOR));
        fail();
    } catch (AcsJNoPermissionEx npe) {
        System.out.println("This is OK: " + npe.toString());
    }
    // test wrong container ImplLang (CDB vs reported by authenticate method)
    try {
        manager.login(new TestContainer("PyContainer", ClientType.CONTAINER, ImplLang.cpp, false));
        fail();
    } catch (AcsJNoPermissionEx npe) {
        System.out.println("This is OK: " + npe.toString());
    }
    //test client login
    Client client = new TestClient(clientName);
    ClientInfo info = null;
    try {
        info = manager.login(client);
    } catch (AcsJNoPermissionEx e) {
        fail("No permission");
    }
    assertNotNull(info);
    assertTrue((info.getHandle() & HandleConstants.CLIENT_MASK) == HandleConstants.CLIENT_MASK);
    assertEquals(info.getClient(), client);
    //test duplicate login
    ClientInfo info2 = null;
    try {
        info2 = manager.login(client);
    } catch (AcsJNoPermissionEx e) {
        fail("No permission");
    }
    assertNotNull(info2);
    assertEquals(info, info2);
    /* 
		// THIS TAKES WAY TOO MUCH TIME
		// DoS attack, there should be no handle left...
		try
		{
			Client differentClient = new TestAlwaysNotEqualClient("different");
			for (int i=0; i<HandleConstants.HANDLE_MASK-1; i++)
			{
				System.out.println(i);
				manager.login(differentClient);			
			}
			
			fail();
		}
		catch (NoResourcesException nre)
		{

			System.out.println("This is OK: "+nre.getMessage());
		}
		*/
    //test administrator login
    Administrator administrator = new TestAdministrator(administratorName);
    try {
        info = manager.login(administrator);
    } catch (AcsJNoPermissionEx e) {
        fail("No permission");
    }
    assertNotNull(info);
    assertTrue((info.getHandle() & HandleConstants.ADMINISTRATOR_MASK) == HandleConstants.ADMINISTRATOR_MASK);
    assertEquals(info.getClient(), administrator);
    //test duplicate login
    try {
        info2 = manager.login(administrator);
    } catch (AcsJNoPermissionEx e) {
        fail("No permission");
    }
    assertNotNull(info2);
    assertEquals(info, info2);
    //test container login
    TestContainer container = new TestContainer(containerName);
    try {
        info = manager.login(container);
    } catch (AcsJNoPermissionEx e) {
        fail("No permission");
    }
    assertNotNull(info);
    assertTrue((info.getHandle() & HandleConstants.CONTAINER_MASK) == HandleConstants.CONTAINER_MASK);
    assertEquals(info.getClient(), container);
    //test duplicate login (same instance) - allowed
    try {
        info2 = manager.login(container);
    } catch (AcsJNoPermissionEx e) {
        fail("No permission");
    }
    assertNotNull(info2);
    assertEquals(info.getHandle(), info2.getHandle());
    container.setHandle(info2.getHandle());
    //test duplicate login (same instance name, previous container alive) - reject
    TestContainer containerSameName = new TestContainer(containerName);
    try {
        info2 = manager.login(containerSameName);
        fail("No permission expected");
    } catch (AcsJNoPermissionEx e) {
        System.out.println("This is OK: " + e.toString());
    }
    // ... now make first instance return handle 0
    // this should allow the login
    container.setHandle(0);
    try {
        info2 = manager.login(containerSameName);
    } catch (AcsJNoPermissionEx e) {
        fail("No permission");
    }
    assertNotNull(info2);
    assertEquals(info.getHandle(), info2.getHandle());
    // wait for some time, so that manager reports passes postponed start-up component activation
    try {
        Thread.sleep(STARTUP_COBS_SLEEP_TIME_MS);
    } catch (InterruptedException ie) {
    }
}
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) BadParametersException(com.cosylab.acs.maci.BadParametersException)

Example 55 with ClientInfo

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

the class ManagerImplTest method internalTestGetHierarchicalComponent.

public void internalTestGetHierarchicalComponent(boolean activateOnActivation) {
    try {
        TestContainer container = new TestContainer("Container");
        Map supportedComponents = new HashMap();
        TestHierarchicalComponent mount2HierCOB = new TestHierarchicalComponent("HierarchicalCOB2", manager, new String[] { "MOUNT3" }, false, activateOnActivation);
        TestHierarchicalComponent mount3HierCOB = new TestHierarchicalComponent("HierarchicalCOB3", manager, new String[] { "MOUNT4" }, false, activateOnActivation);
        Component mount4COB = new TestComponent("MOUNT4");
        supportedComponents.put("MOUNT2", mount2HierCOB);
        supportedComponents.put("MOUNT3", mount3HierCOB);
        supportedComponents.put("MOUNT4", mount4COB);
        container.setSupportedComponents(supportedComponents);
        // test case when container is unable to activate startup Component - MOUNT1
        ClientInfo containerInfo = manager.login(container);
        TestAdministrator client = new TestAdministrator(administratorName);
        ClientInfo info = manager.login(client);
        // test ordinary activation
        URI mount2URI;
        try {
            mount2URI = new URI("MOUNT2");
            StatusHolder status = new StatusHolder();
            Component ref = manager.getComponent(info.getHandle(), mount2URI, true, status);
            assertEquals(mount2HierCOB, 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 all three Components activated
        ComponentInfo[] infos = manager.getComponentInfo(info.getHandle(), new int[0], "*", "*", true);
        assertEquals(3, infos.length);
        // container logout and login
        manager.logout(containerInfo.getHandle());
        try {
            Thread.sleep(SLEEP_TIME_MS);
        } catch (InterruptedException ie) {
        }
        // test activated Components
        // there should be no Components activated
        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) {
        }
        // test activated Components
        // there should be all three Components activated
        infos = manager.getComponentInfo(info.getHandle(), new int[0], "*", "*", true);
        assertEquals(3, infos.length);
        // logout client
        manager.logout(info.getHandle());
        try {
            Thread.sleep(SLEEP_TIME_MS);
        } catch (InterruptedException ie) {
        }
    } 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) 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)

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