Search in sources :

Example 46 with AcsJNoPermissionEx

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

the class ManagerImplTest method testGetDynamicComponent.

/**
	 * Test getDynamicComponent.
	 */
public void testGetDynamicComponent() {
    try {
        try {
            manager.getDynamicComponent(0, null, false);
            fail();
        } catch (AcsJInvalidComponentSpecEx bpe) {
            System.out.println("This is OK: " + bpe.toString());
        } catch (AcsJComponentSpecIncompatibleWithActiveComponentEx e) {
            fail("AcsJComponentSpecIncompatibleWithActiveComponentEx " + e.toString());
        }
        final ComponentSpec allAsterixCompSpec = new ComponentSpec(ComponentSpec.COMPSPEC_ANY, ComponentSpec.COMPSPEC_ANY, ComponentSpec.COMPSPEC_ANY, ComponentSpec.COMPSPEC_ANY);
        try {
            manager.getDynamicComponent(Integer.MAX_VALUE, allAsterixCompSpec, true);
            fail();
        } catch (AcsJNoPermissionEx npe) {
            System.out.println("This is OK: " + npe.toString());
        } catch (AcsJInvalidComponentSpecEx bpe) {
            fail();
        } catch (AcsJComponentSpecIncompatibleWithActiveComponentEx e) {
            fail("AcsJComponentSpecIncompatibleWithActiveComponentEx");
        }
        try {
            manager.getDynamicComponent(dummyHandle, allAsterixCompSpec, false);
            fail();
        } catch (AcsJNoPermissionEx npe) {
            System.out.println("This is OK: " + npe.toString());
        } catch (AcsJInvalidComponentSpecEx bpe) {
            fail();
        } catch (AcsJComponentSpecIncompatibleWithActiveComponentEx e) {
            fail("AcsJComponentSpecIncompatibleWithActiveComponentEx");
        }
        TestClient client = new TestClient(clientName);
        ClientInfo info = manager.login(client);
        assertTrue(info.getHandle() != 0);
        try {
            manager.getDynamicComponent(info.getHandle(), null, true);
            fail();
        } catch (AcsJInvalidComponentSpecEx bpe) {
            System.out.println("This is OK: " + bpe.toString());
        } catch (AcsJComponentSpecIncompatibleWithActiveComponentEx e) {
            fail("AcsJComponentSpecIncompatibleWithActiveComponentEx");
        }
        try {
            manager.getDynamicComponent(info.getHandle(), new ComponentSpec(null, null, null, null), false);
            fail();
        } catch (AcsJInvalidComponentSpecEx ndce) {
            System.out.println("This is OK: " + ndce.toString());
        } catch (AcsJComponentSpecIncompatibleWithActiveComponentEx e) {
            fail("AcsJComponentSpecIncompatibleWithActiveComponentEx");
        }
        try {
            manager.getDynamicComponent(info.getHandle(), allAsterixCompSpec, false);
            fail();
        } catch (AcsJInvalidComponentSpecEx bpe) {
            System.out.println("This is OK: " + bpe.toString());
        } catch (AcsJIncompleteComponentSpecEx icse) {
            fail();
        } catch (AcsJComponentSpecIncompatibleWithActiveComponentEx e) {
            fail("AcsJComponentSpecIncompatibleWithActiveComponentEx");
        }
        final ComponentSpec nameTypeIncomplete = new ComponentSpec(ComponentSpec.COMPSPEC_ANY, ComponentSpec.COMPSPEC_ANY, "PowerSupply", "IDL:acsexmpl/PS/PowerSupply:1.0");
        try {
            manager.getDynamicComponent(info.getHandle(), nameTypeIncomplete, false);
            fail();
        } catch (AcsJInvalidComponentSpecEx icse) {
            System.out.println("This is OK: " + icse.toString());
        } catch (AcsJIncompleteComponentSpecEx bpe) {
            fail();
        } catch (AcsJComponentSpecIncompatibleWithActiveComponentEx e) {
            fail("AcsJComponentSpecIncompatibleWithActiveComponentEx");
        }
        // decoy container
        TestContainer container = new TestContainer("Container");
        Map supportedComponents = new HashMap();
        TestComponent mount1COB = new TestComponent("MOUNT1");
        supportedComponents.put("MOUNT1", mount1COB);
        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) {
        }
        // Before ACS 6.0 this was expecting a null, now we get and exception
        try {
            ComponentInfo componentInfo = manager.getDynamicComponent(info.getHandle(), new ComponentSpec("dynComponent", "java.lang.Object", "java.lang.Object", "invalidContainer"), true);
            fail();
        } catch (AcsJCannotGetComponentEx ex) {
            System.out.println("This is OK: " + ex.toString());
        } catch (AcsJInvalidComponentSpecEx ex) {
            fail();
        } catch (AcsJComponentSpecIncompatibleWithActiveComponentEx e) {
            fail("AcsJComponentSpecIncompatibleWithActiveComponentEx");
        }
        // all dynamic case
        try {
            ComponentInfo componentInfo = manager.getDynamicComponent(info.getHandle(), new ComponentSpec("dynComponent", "java.lang.Object", "java.lang.Object", "DynContainer"), true);
            assertTrue(componentInfo != null);
            assertTrue(componentInfo.getName().equals("dynComponent"));
            assertEquals(dynContainerInfo.getHandle(), componentInfo.getContainer());
        } catch (Exception ex) {
            ex.printStackTrace();
            fail();
        }
        ClientInfo info2 = manager.login(new TestClient("TestClient2"));
        // obtain and release dynamic component in a normal way
        try {
            URI dynURI = new URI("dynComponent");
            // obtain
            StatusHolder status = new StatusHolder();
            Component component = manager.getComponent(info2.getHandle(), dynURI, true, status);
            assertNotNull(component);
            assertEquals(ComponentStatus.COMPONENT_ACTIVATED, status.getStatus());
            // release
            int owners = manager.releaseComponent(info2.getHandle(), dynURI);
            assertEquals(1, owners);
        } catch (Exception ex) {
            fail();
        }
        // override container case
        try {
            ComponentInfo componentInfo = manager.getDynamicComponent(info.getHandle(), new ComponentSpec("MOUNT2", ComponentSpec.COMPSPEC_ANY, ComponentSpec.COMPSPEC_ANY, "DynContainer"), true);
            assertTrue(componentInfo != null);
            assertTrue(componentInfo.getName().equals("MOUNT2"));
            assertEquals(dynContainerInfo.getHandle(), componentInfo.getContainer());
        } catch (Exception ex) {
            fail();
        }
        // override all other fields case but MOUNT2 is already activated
        try {
            manager.getDynamicComponent(info.getHandle(), new ComponentSpec("MOUNT2", "java.lang.Object", "java.lang.Object", "DynContainer"), true);
            fail();
        } catch (AcsJComponentSpecIncompatibleWithActiveComponentEx ciwace) {
            System.out.println("This is OK: " + ciwace.toString());
        } catch (AcsJInvalidComponentSpecEx bpe) {
            fail();
        }
        // ordinary activation case but MOUNT2 is already activated
        URI mount2 = null;
        try {
            mount2 = CURLHelper.createURI("MOUNT2");
            StatusHolder status = new StatusHolder();
            Component component = manager.getComponent(info.getHandle(), mount2, true, status);
            assertNotNull(null, component);
            assertEquals(ComponentStatus.COMPONENT_ACTIVATED, status.getStatus());
        } catch (Exception ex) {
            fail();
        }
        // default component test, should be overriden MOUNT2
        try {
            ComponentInfo componentInfo = manager.getDefaultComponent(info.getHandle(), "IDL:alma/MOUNT_ACS/Mount:1.0");
            assertTrue(componentInfo != null);
            assertTrue(componentInfo.getName().equals("MOUNT2"));
            assertEquals(dynContainerInfo.getHandle(), componentInfo.getContainer());
        } catch (Exception ex) {
            fail();
        }
        // release mount2
        try {
            manager.releaseComponent(info.getHandle(), mount2);
        } catch (AcsJBadParameterEx e) {
            fail();
        }
        // default component test, should still be overriden MOUNT2
        try {
            ComponentInfo componentInfo = manager.getDefaultComponent(info.getHandle(), "IDL:alma/MOUNT_ACS/Mount:1.0");
            assertTrue(componentInfo != null);
            assertTrue(componentInfo.getName().equals("MOUNT2"));
            assertEquals(dynContainerInfo.getHandle(), componentInfo.getContainer());
        } catch (Exception ex) {
            fail();
        }
        // release mount2
        try {
            manager.releaseComponent(info.getHandle(), mount2);
        } catch (AcsJBadParameterEx e) {
            fail();
        }
        // type override
        try {
            manager.getDynamicComponent(info.getHandle(), new ComponentSpec("MOUNT1", ComponentSpec.COMPSPEC_ANY, "java.lang.Object", ComponentSpec.COMPSPEC_ANY), true);
            fail();
        } catch (AcsJComponentSpecIncompatibleWithActiveComponentEx ciwace) {
            System.out.println("This is OK: " + ciwace.toString());
        } catch (AcsJInvalidComponentSpecEx ciwace) {
            fail();
        }
        // * name generation test w/o CDB lookup
        try {
            ComponentInfo componentInfo = manager.getDynamicComponent(info.getHandle(), new ComponentSpec(ComponentSpec.COMPSPEC_ANY, "IDL:alma/PS/PowerSupply:1.0", "java.lang.Object", "DynContainer"), false);
            assertTrue(componentInfo != null);
            //assertTrue(componentInfo.getName().startsWith("IDL:alma/PS/PowerSupply:1.0"));
            assertTrue(componentInfo.getName().startsWith("IDL:alma_PS_PowerSupply:1.0"));
            assertEquals(dynContainerInfo.getHandle(), componentInfo.getContainer());
            manager.releaseComponent(info.getHandle(), CURLHelper.createURI(componentInfo.getName()));
        } catch (Exception ex) {
            fail();
        }
        // prefix* name generation test w/o CDB lookup
        try {
            ComponentInfo componentInfo = manager.getDynamicComponent(info.getHandle(), new ComponentSpec("PREFIX" + ComponentSpec.COMPSPEC_ANY, "IDL:alma/PS/PowerSupply:1.0", "java.lang.Object", "DynContainer"), false);
            assertTrue(componentInfo != null);
            assertTrue(componentInfo.getName().startsWith("PREFIX"));
            assertEquals(dynContainerInfo.getHandle(), componentInfo.getContainer());
            manager.releaseComponent(info.getHandle(), CURLHelper.createURI(componentInfo.getName()));
        } catch (Exception ex) {
            fail();
        }
        // * name generation test w/o CDB lookup, * container -> should fail since there is no load balancing
        try {
            manager.getDynamicComponent(info.getHandle(), new ComponentSpec(ComponentSpec.COMPSPEC_ANY, "IDL:alma/newDevice/newPowerSupply:1.0", "java.lang.Object", ComponentSpec.COMPSPEC_ANY), false);
            fail();
        } catch (AcsJInvalidComponentSpecEx icsex) {
            System.out.println("This is OK: " + icsex.toString());
        } catch (Exception ex) {
            fail();
        }
        // (*, type) and name generation test w/ container override
        try {
            ComponentInfo componentInfo = manager.getDynamicComponent(info.getHandle(), new ComponentSpec(ComponentSpec.COMPSPEC_ANY, "IDL:alma/PS/PowerSupply:1.0", ComponentSpec.COMPSPEC_ANY, "DynContainer"), true);
            assertTrue(componentInfo != null);
            //assertTrue(componentInfo.getName().startsWith("IDL:alma/PS/PowerSupply:1.0"));
            assertTrue(componentInfo.getName().startsWith("IDL:alma_PS_PowerSupply:1.0"));
            assertEquals(dynContainerInfo.getHandle(), componentInfo.getContainer());
            manager.releaseComponent(info.getHandle(), CURLHelper.createURI(componentInfo.getName()));
        } catch (Exception ex) {
            fail();
        }
        // (name, type) - component with given name, name is exist in CDB; w/ container override
        try {
            ComponentInfo componentInfo = manager.getDynamicComponent(info.getHandle(), new ComponentSpec("PBEND_B_02", "IDL:alma/PS/PowerSupply:1.0", ComponentSpec.COMPSPEC_ANY, "DynContainer"), true);
            assertTrue(componentInfo != null);
            assertTrue(componentInfo.getName().equals("PBEND_B_02"));
            assertEquals(dynContainerInfo.getHandle(), componentInfo.getContainer());
            manager.releaseComponent(info.getHandle(), CURLHelper.createURI(componentInfo.getName()));
        } catch (Exception ex) {
            fail();
        }
        // (name, type) - component with given name, name does not exist in CDB; w/ container override
        try {
            ComponentInfo componentInfo = manager.getDynamicComponent(info.getHandle(), new ComponentSpec("NAME_OVERRIDE", "IDL:alma/PS/PowerSupply:1.0", ComponentSpec.COMPSPEC_ANY, "DynContainer"), true);
            assertTrue(componentInfo != null);
            assertTrue(componentInfo.getName().equals("NAME_OVERRIDE"));
            assertEquals(dynContainerInfo.getHandle(), componentInfo.getContainer());
            manager.releaseComponent(info.getHandle(), CURLHelper.createURI(componentInfo.getName()));
        } catch (Exception ex) {
            fail();
        }
        // (name, type) - but type does not exist in CDB (there is not type override)
        try {
            manager.getDynamicComponent(info.getHandle(), new ComponentSpec("NAME_OVERRIDE", "IDL:alma/PS/RampedPowerSupply:1.0", ComponentSpec.COMPSPEC_ANY, ComponentSpec.COMPSPEC_ANY), true);
            fail();
        } catch (AcsJInvalidComponentSpecEx icse) {
            System.out.println("This is OK: " + icse.toString());
        } catch (AcsJComponentSpecIncompatibleWithActiveComponentEx e) {
            fail("AcsJComponentSpecIncompatibleWithActiveComponentEx");
        }
        // (*, type) - but type does not exist in CDB (there is not type override)
        try {
            manager.getDynamicComponent(info.getHandle(), new ComponentSpec(ComponentSpec.COMPSPEC_ANY, "IDL:alma/PS/RampedPowerSupply:1.0", ComponentSpec.COMPSPEC_ANY, ComponentSpec.COMPSPEC_ANY), true);
            fail();
        } catch (AcsJInvalidComponentSpecEx icse) {
            System.out.println("This is OK: " + icse.toString());
        } catch (AcsJComponentSpecIncompatibleWithActiveComponentEx e) {
            fail("AcsJComponentSpecIncompatibleWithActiveComponentEx");
        }
        // activate_component_async that does not respond test
        dynContainer.setIgnoreActivateComponentAsync(true);
        // activate_component_async that does not respond test
        // timeout test
        manager.setLockTimeout(3 * SLEEP_TIME_MS);
        try {
            dynContainer.setIgnoreActivateComponentAsync(true);
            manager.getDynamicComponent(info.getHandle(), new ComponentSpec("activate_component_async_will_never_respond", "IDL:alma/PS/PowerSupply:1.0", "java.lang.Object", "DynContainer"), false);
            fail();
        } catch (AcsJCannotGetComponentEx cgc) {
        // ok
        } catch (Exception ex) {
            fail();
        }
        final AtomicLong logoutTime = new AtomicLong();
        // and container logs out
        // shoud react quicker
        manager.setLockTimeout(10 * SLEEP_TIME_MS);
        try {
            final ClientInfo dci = dynContainerInfo;
            new Thread(new Runnable() {

                @Override
                public void run() {
                    try {
                        Thread.sleep(SLEEP_TIME_MS);
                    } catch (InterruptedException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    logoutTime.set(System.currentTimeMillis());
                    try {
                        manager.logout(dci.getHandle());
                    } catch (AcsJNoPermissionEx e) {
                        fail();
                    }
                }
            }).start();
            manager.getDynamicComponent(info.getHandle(), new ComponentSpec("activate_component_async_will_never_respond_cont_logout", "IDL:alma/PS/PowerSupply:1.0", "java.lang.Object", "DynContainer"), false);
            fail();
        } catch (AcsJCannotGetComponentEx cgc) {
            long now = System.currentTimeMillis();
            long diff = now - logoutTime.get();
            // logout did not trigger component failed to activate
            assertTrue(diff < SLEEP_TIME_MS);
        } catch (Exception ex) {
            fail();
        }
        try {
            Thread.sleep(SLEEP_TIME_MS);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    } catch (AcsJNoPermissionEx e) {
        fail("No permission");
    /**
			 * @todo I would like to remove all these exceptions 
		     *       and catch them above
			 */
    } catch (AcsJCannotGetComponentEx e) {
        fail("AcsJCannotGetComponentEx");
    } catch (AcsJIncompleteComponentSpecEx e) {
        fail("AcsJIncompleteComponentSpecEx");
    }
}
Also used : AcsJBadParameterEx(alma.ACSErrTypeCommon.wrappers.AcsJBadParameterEx) HashMap(java.util.HashMap) AcsJComponentSpecIncompatibleWithActiveComponentEx(alma.maciErrType.wrappers.AcsJComponentSpecIncompatibleWithActiveComponentEx) ComponentSpec(com.cosylab.acs.maci.ComponentSpec) 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) AcsJIncompleteComponentSpecEx(alma.maciErrType.wrappers.AcsJIncompleteComponentSpecEx) StatusHolder(com.cosylab.acs.maci.StatusHolder) AcsJInvalidComponentSpecEx(alma.maciErrType.wrappers.AcsJInvalidComponentSpecEx) AtomicLong(java.util.concurrent.atomic.AtomicLong) 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 47 with AcsJNoPermissionEx

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

the class ManagerImplTest method testMakeComponentMortal.

public void testMakeComponentMortal() {
    try {
        manager.makeComponentImmortal(0, null, false);
        fail();
    } catch (AcsJBadParameterEx bpe) {
        System.out.println("This is OK");
    } catch (AcsJCannotGetComponentEx bpe) {
        fail();
    } catch (AcsJNoPermissionEx e) {
        fail("No permission");
    }
    try {
        manager.makeComponentImmortal(Integer.MAX_VALUE, null, false);
        fail();
    } catch (AcsJBadParameterEx bpe) {
        System.out.println("This is OK");
    } catch (AcsJCannotGetComponentEx bpe) {
        fail();
    } catch (AcsJNoPermissionEx e) {
        fail("No permission");
    }
    try {
        manager.makeComponentImmortal(dummyHandle, dummyURI, false);
        fail();
    } catch (AcsJCannotGetComponentEx bpe) {
        fail("CannotGetComponentE");
    } catch (AcsJBadParameterEx bpe) {
        fail("BadParameter");
    } catch (AcsJNoPermissionEx bpe) {
        System.out.println("This is OK");
    }
    ClientInfo adminInfo = null;
    ClientInfo info = null;
    Component mount2 = null;
    Component mount3 = null;
    try {
        TestAdministrator adminClient = new TestAdministrator(administratorName);
        adminInfo = manager.login(adminClient);
        TestClient client = new TestClient(clientName);
        info = manager.login(client);
        assertTrue(info.getHandle() != 0);
        TestContainer container = new TestContainer("Container");
        Map supportedComponents = new HashMap();
        Component mount1 = new TestComponent("MOUNT1");
        supportedComponents.put("MOUNT1", mount1);
        mount2 = new TestComponent("MOUNT2");
        supportedComponents.put("MOUNT2", mount2);
        mount3 = new TestComponent("MOUNT3");
        supportedComponents.put("MOUNT3", mount3);
        container.setSupportedComponents(supportedComponents);
        ClientInfo containerInfo = manager.login(container);
    } catch (AcsJNoPermissionEx e1) {
        fail("No permission");
    }
    URI mount2URL = null;
    try {
        mount2URL = new URI("MOUNT2");
        StatusHolder status = new StatusHolder();
        Component ref = manager.getComponent(info.getHandle(), mount2URL, true, status);
        assertEquals(mount2, ref);
    } catch (Exception ex) {
        fail();
    }
    // admin will activate it
    URI mount3URL = null;
    try {
        mount3URL = new URI("MOUNT3");
        StatusHolder status = new StatusHolder();
        Component ref = manager.getComponent(adminInfo.getHandle(), mount3URL, true, status);
        assertEquals(mount3, ref);
    } catch (Exception ex) {
        fail();
    }
    try {
        Thread.sleep(STARTUP_COBS_SLEEP_TIME_MS);
    } catch (InterruptedException ie) {
    }
    // test activated Components
    ComponentInfo[] infos;
    try {
        infos = manager.getComponentInfo(info.getHandle(), new int[0], "*", "*", true);
        assertEquals(3, infos.length);
    } catch (AcsJNoPermissionEx e1) {
        fail("No permission");
    }
    // make mount2 immortal (as admin which has all the rights)
    try {
        manager.makeComponentImmortal(adminInfo.getHandle(), mount2URL, true);
        infos = manager.getComponentInfo(info.getHandle(), new int[0], "MOUNT2", "*", true);
        assertEquals(1, infos.length);
        assertTrue(infos[0].getClients().contains(manager.getHandle()));
        manager.makeComponentImmortal(adminInfo.getHandle(), mount2URL, false);
        infos = manager.getComponentInfo(info.getHandle(), new int[0], "MOUNT2", "*", true);
        assertEquals(1, infos.length);
        assertTrue(!infos[0].getClients().contains(manager.getHandle()));
    } catch (AcsJCannotGetComponentEx e) {
        fail();
    } catch (AcsJBadParameterEx bpe) {
        fail();
    } catch (AcsJNoPermissionEx bpe) {
        fail();
    }
    // client does not own it, no permission exception expected
    try {
        manager.makeComponentImmortal(info.getHandle(), mount3URL, true);
        fail();
    } catch (AcsJCannotGetComponentEx npe) {
        fail();
    } catch (AcsJBadParameterEx bpe) {
        fail();
    } catch (AcsJNoPermissionEx bpe) {
        System.out.println("This is OK: " + bpe.toString());
    }
    // normal op.
    try {
        manager.makeComponentImmortal(info.getHandle(), mount2URL, true);
    } catch (AcsJCannotGetComponentEx e) {
        fail();
    } catch (AcsJBadParameterEx bpe) {
        fail();
    } catch (AcsJNoPermissionEx bpe) {
        fail();
    }
    try {
        manager.releaseComponent(info.getHandle(), mount2URL);
    } catch (AcsJBadParameterEx bpe) {
        fail();
    } catch (AcsJNoPermissionEx bpe) {
        fail();
    }
    try {
        // mount2 is immortal and stays active, has managers handle as an owner
        infos = manager.getComponentInfo(adminInfo.getHandle(), new int[0], "MOUNT2", "*", true);
        assertEquals(1, infos.length);
        assertTrue(infos[0].getClients().contains(manager.getHandle()));
        // mount2 should be released now
        try {
            manager.makeComponentImmortal(adminInfo.getHandle(), mount2URL, false);
        } catch (AcsJCannotGetComponentEx e) {
            fail();
        } catch (AcsJBadParameterEx bpe) {
            fail();
        }
        infos = manager.getComponentInfo(adminInfo.getHandle(), new int[0], "MOUNT2", "*", true);
        assertEquals(0, infos.length);
    } catch (AcsJNoPermissionEx e) {
        fail();
    }
}
Also used : AcsJBadParameterEx(alma.ACSErrTypeCommon.wrappers.AcsJBadParameterEx) 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) ComponentInfo(com.cosylab.acs.maci.ComponentInfo) Component(com.cosylab.acs.maci.Component) HashMap(java.util.HashMap) Map(java.util.Map)

Example 48 with AcsJNoPermissionEx

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

the class ManagerImplTest method testComponentKeepAliveTime.

public void testComponentKeepAliveTime() {
    TestClient client = new TestClient(clientName);
    ClientInfo info = null;
    try {
        info = manager.login(client);
    } catch (AcsJNoPermissionEx e) {
        fail("No permission");
    }
    assertTrue(info.getHandle() != 0);
    TestContainer container = new TestContainer("Container");
    Map supportedComponents = new HashMap();
    Component immortal = new TestComponent("IMMORTAL");
    supportedComponents.put("IMMORTAL", immortal);
    Component persistent = new TestComponent("PERSISTENT");
    supportedComponents.put("PERSISTENT", persistent);
    container.setSupportedComponents(supportedComponents);
    try {
        ClientInfo containerInfo = manager.login(container);
    } catch (AcsJNoPermissionEx e) {
        fail("No permission");
    }
    URI immortalURL = null;
    try {
        immortalURL = new URI("IMMORTAL");
        StatusHolder status = new StatusHolder();
        Component ref = manager.getComponent(info.getHandle(), immortalURL, true, status);
        assertEquals(immortal, ref);
    } catch (Exception ex) {
        fail();
    }
    URI persistentURL = null;
    try {
        persistentURL = new URI("PERSISTENT");
        StatusHolder status = new StatusHolder();
        Component ref = manager.getComponent(info.getHandle(), persistentURL, true, status);
        assertEquals(persistent, ref);
    } catch (Exception ex) {
        fail();
    }
    try {
        // test activated Components
        ComponentInfo[] infos = manager.getComponentInfo(info.getHandle(), new int[0], "*", "*", true);
        assertEquals(2, infos.length);
        // IMMORTAL has to have manager as a client
        for (ComponentInfo cInfo : infos) {
            if (cInfo.getName().equals("IMMORTAL")) {
                assertTrue(cInfo.getClients().contains(manager.getHandle()));
            } else {
                assertTrue(!cInfo.getClients().contains(manager.getHandle()));
            }
        }
        // check immortality
        try {
            manager.releaseComponent(info.getHandle(), immortalURL);
        } catch (AcsJBadParameterEx e) {
            fail();
        }
        infos = manager.getComponentInfo(info.getHandle(), new int[0], "*", "*", true);
        assertEquals(2, infos.length);
        for (ComponentInfo cInfo : infos) {
            if (cInfo.getName().equals("IMMORTAL")) {
                assertTrue(cInfo.getClients().contains(manager.getHandle()));
            }
        }
        final int KEEP_ALIVE_TIME = 5000 + 2000;
        // check keepAliveTime
        try {
            manager.releaseComponent(info.getHandle(), persistentURL);
        } catch (AcsJBadParameterEx e) {
            fail();
        }
        // both alive
        infos = manager.getComponentInfo(info.getHandle(), new int[0], "*", "*", true);
        assertEquals(2, infos.length);
        // another request for component
        try {
            persistentURL = new URI("PERSISTENT");
            StatusHolder status = new StatusHolder();
            Component ref = manager.getComponent(info.getHandle(), persistentURL, true, status);
            assertEquals(persistent, ref);
        } catch (Exception ex) {
            fail();
        }
        // sleep
        try {
            Thread.sleep(KEEP_ALIVE_TIME);
        } catch (InterruptedException ie) {
        }
        // still both should be activated
        infos = manager.getComponentInfo(info.getHandle(), new int[0], "*", "*", true);
        assertEquals(2, infos.length);
        try {
            manager.releaseComponent(info.getHandle(), persistentURL);
        } catch (AcsJBadParameterEx e) {
            fail();
        }
        // both alive
        infos = manager.getComponentInfo(info.getHandle(), new int[0], "*", "*", true);
        assertEquals(2, infos.length);
        // sleep
        try {
            Thread.sleep(KEEP_ALIVE_TIME);
        } catch (InterruptedException ie) {
        }
        // only IMMORTAL should be alive
        infos = manager.getComponentInfo(info.getHandle(), new int[0], "*", "*", true);
        assertEquals(1, infos.length);
        assertEquals(immortal, infos[0].getComponent());
    } catch (AcsJNoPermissionEx e) {
        fail("No permission");
    }
    // keep alive time of dynamic component
    try {
        TestContainer dynContainer = new TestDynamicContainer("DynContainer");
        ClientInfo dynContainerInfo = manager.login(dynContainer);
        // wait container to startup
        try {
            Thread.sleep(STARTUP_COBS_SLEEP_TIME_MS);
        } catch (InterruptedException ie) {
        }
        ComponentInfo componentInfo = manager.getDynamicComponent(info.getHandle(), new ComponentSpec("DELAYED*", "IDL:alma/PS/PowerSupply:1.0", ComponentSpec.COMPSPEC_ANY, "DynContainer"), true);
        assertTrue(componentInfo != null);
        assertTrue(componentInfo.getName().startsWith("DELAYED"));
        assertEquals(dynContainerInfo.getHandle(), componentInfo.getContainer());
        // now we release the component
        manager.releaseComponent(info.getHandle(), CURLHelper.createURI(componentInfo.getName()));
        // both alive
        ComponentInfo[] infos = manager.getComponentInfo(info.getHandle(), new int[0], "*", "*", true);
        assertEquals(2, infos.length);
        // sleep
        final int KEEP_ALIVE_TIME = 5000 + 2000;
        try {
            Thread.sleep(KEEP_ALIVE_TIME);
        } catch (InterruptedException ie) {
        }
        // only IMMORTAL should be alive
        infos = manager.getComponentInfo(info.getHandle(), new int[0], "*", "*", true);
        assertEquals(1, infos.length);
        assertEquals(immortal, infos[0].getComponent());
    } catch (Exception ex) {
        ex.printStackTrace();
        fail();
    }
}
Also used : AcsJBadParameterEx(alma.ACSErrTypeCommon.wrappers.AcsJBadParameterEx) HashMap(java.util.HashMap) 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) 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 49 with AcsJNoPermissionEx

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

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

the class ManagerProxyImpl method get_component.

/**
	 * Get a Component, activating it if necessary.
	 * The client represented by id (the handle)
	 * must have adequate access rights to access the Component. This is untrue of components:
	 * components always have unlimited access rights to other components.
	 *
	 * @param id Identification of the caller. If this is an invalid handle, or if the caller does not have enough access rights, a maciErrType::NoPermissionEx exception is raised.
	 * @param component_url CURL of the Component whose reference is to be retrieved.
	 * @param activate True if the Component is to be activated in case it does not exist. If set to False, and the Component does not exist, a nil reference is returned and status is set to COMPONENT_NOT_ACTIVATED.
	 * @return Reference to the Component. If the Component could not be activated, an exception is throw.
	 */
public Object get_component(int id, String component_url, boolean activate) throws NoPermissionEx, CannotGetComponentEx, ComponentNotAlreadyActivatedEx, ComponentConfigurationNotFoundEx {
    pendingRequests.incrementAndGet();
    try {
        // returned value
        Object retVal = null;
        // returned status
        StatusHolder statusHolder = new StatusHolder();
        // transform to CORBA specific
        URI uri = null;
        if (component_url != null)
            uri = CURLHelper.createURI(component_url);
        Component component = manager.getComponent(id, uri, activate, statusHolder);
        // extract Component CORBA reference
        if (component != null)
            retVal = (Object) component.getObject();
        /**
			 * @todo GCH 2006.10.11
			 *       notice that we can get a ComponentStatus != COMPONENT_ACTIVATED
			 *       also if the component is properly returned.
			 *       There is an incoherence here in the interfaces that shall be resolved.
			 *       We have to cleanup here or go back to return a status
			 *       to the caller.
			 *       My point is: the caller is interested in more than just 
			 *       getting the component of an indication of failure if not?
			 *       Is it interesting to know that the component was not activated,
			 *       presumably because already active? 
			 */
        if (component == null || component.getObject() == null) {
            if (statusHolder.getStatus() == ComponentStatus.COMPONENT_NOT_ACTIVATED && !activate) {
                AcsJComponentNotAlreadyActivatedEx ex = new AcsJComponentNotAlreadyActivatedEx();
                ex.setCURL(component_url);
                throw ex;
            }
            if (statusHolder.getStatus() == ComponentStatus.COMPONENT_DOES_NO_EXIST) {
                AcsJComponentConfigurationNotFoundEx ex = new AcsJComponentConfigurationNotFoundEx();
                ex.setCURL(component_url);
                throw ex;
            } else {
                AcsJCannotGetComponentEx ex = new AcsJCannotGetComponentEx();
                ex.setCURL(component_url);
                throw ex;
            }
        }
        return retVal;
    } catch (URISyntaxException usi) {
        BadParametersException hbpe = new BadParametersException(usi.getMessage(), usi);
        reportException(hbpe);
        // rethrow CORBA specific
        throw new BAD_PARAM(usi.getMessage());
    } catch (BadParametersException bpe) {
        BadParametersException hbpe = new BadParametersException(bpe.getMessage(), bpe);
        reportException(hbpe);
        // rethrow CORBA specific
        throw new BAD_PARAM(bpe.getMessage());
    } catch (NoResourcesException nre) {
        NoResourcesException hnre = new NoResourcesException(nre.getMessage(), nre);
        reportException(hnre);
        // rethrow CORBA specific
        throw new NO_RESOURCES(nre.getMessage());
    } catch (AcsJCannotGetComponentEx cgce) {
        // rethrow CORBA specific
        throw cgce.toCannotGetComponentEx();
    } catch (AcsJComponentNotAlreadyActivatedEx cnaae) {
        // rethrow CORBA specific
        throw cnaae.toComponentNotAlreadyActivatedEx();
    } catch (AcsJComponentConfigurationNotFoundEx ccnfe) {
        // rethrow CORBA specific
        throw ccnfe.toComponentConfigurationNotFoundEx();
    } catch (AcsJNoPermissionEx npe) {
        // rethrow CORBA specific
        throw npe.toNoPermissionEx();
    } catch (Throwable ex) {
        CoreException hce = new CoreException(ex.getMessage(), ex);
        reportException(hce);
        // rethrow CORBA specific
        throw new UNKNOWN(ex.getMessage());
    } finally {
        pendingRequests.decrementAndGet();
    }
}
Also used : BAD_PARAM(org.omg.CORBA.BAD_PARAM) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) AcsJCannotGetComponentEx(alma.maciErrType.wrappers.AcsJCannotGetComponentEx) StatusHolder(com.cosylab.acs.maci.StatusHolder) AcsJComponentNotAlreadyActivatedEx(alma.maciErrType.wrappers.AcsJComponentNotAlreadyActivatedEx) BadParametersException(com.cosylab.acs.maci.BadParametersException) NoResourcesException(com.cosylab.acs.maci.NoResourcesException) AcsJNoPermissionEx(alma.maciErrType.wrappers.AcsJNoPermissionEx) CoreException(com.cosylab.acs.maci.CoreException) Object(org.omg.CORBA.Object) AcsJComponentConfigurationNotFoundEx(alma.maciErrType.wrappers.AcsJComponentConfigurationNotFoundEx) UNKNOWN(org.omg.CORBA.UNKNOWN) Component(com.cosylab.acs.maci.Component) NO_RESOURCES(org.omg.CORBA.NO_RESOURCES)

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