Search in sources :

Example 41 with AcsJNoPermissionEx

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

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

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

Example 44 with AcsJNoPermissionEx

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

the class ManagerProxy method getComponent.

/**
     * @see com.cosylab.acs.maci.Manager#getComponent(int, java.net.URI, boolean, com.cosylab.acs.maci.StatusHolder)
     */
public Component getComponent(int id, URI curl, boolean activate, StatusHolder status) throws AcsJNoPermissionEx {
    try {
        Component retVal = null;
        org.omg.CORBA.Object object = manager.get_component(id, curl.toString(), activate);
        if (object != null) {
            retVal = new ComponentProxy(curl.toString(), object);
        }
        return retVal;
    } catch (NoPermissionEx npex) {
        AcsJNoPermissionEx npe = new AcsJNoPermissionEx();
        npe.setReason("Remote manager has thrown no permission exception.");
        npe.setID(HandleHelper.toString(id));
        npe.setProtectedResource(curl.toString());
        throw npe;
    } catch (Exception ex) {
        //throw re;
        return null;
    }
}
Also used : AcsJNoPermissionEx(alma.maciErrType.wrappers.AcsJNoPermissionEx) Object(org.omg.CORBA.Object) NoPermissionEx(alma.maciErrType.NoPermissionEx) AcsJNoPermissionEx(alma.maciErrType.wrappers.AcsJNoPermissionEx) Component(com.cosylab.acs.maci.Component) IOException(java.io.IOException) NoDefaultComponentException(com.cosylab.acs.maci.NoDefaultComponentException)

Example 45 with AcsJNoPermissionEx

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

the class ManagerProxy method getComponentInfo.

/**
     * @see com.cosylab.acs.maci.Manager#getComponentInfo(int, int[], java.lang.String, java.lang.String, boolean)
     */
public ComponentInfo[] getComponentInfo(int id, int[] handles, String name_wc, String type_wc, boolean activeOnly) throws AcsJNoPermissionEx {
    try {
        // returned value
        ComponentInfo[] retVal = null;
        // transform to CORBA specific 
        si.ijs.maci.ComponentInfo[] infos = manager.get_component_info(id, handles, name_wc, type_wc, activeOnly);
        if (infos != null) {
            retVal = new ComponentInfo[infos.length];
            for (int i = 0; i < infos.length; i++) {
                ComponentInfo componentInfo = new ComponentInfo(infos[i].h, infos[i].name, infos[i].type, infos[i].code, new ComponentProxy(infos[i].name, infos[i].reference));
                componentInfo.setContainer(infos[i].container);
                componentInfo.setContainerName(infos[i].container_name);
                componentInfo.setAccessRights(ContainerProxy.inverseMapAccessRights(infos[i].access));
                componentInfo.setClients(new IntArray(infos[i].clients));
                componentInfo.setInterfaces(infos[i].interfaces);
                retVal[i] = componentInfo;
            }
        }
        return retVal;
    } catch (NoPermissionEx npex) {
        AcsJNoPermissionEx npe = new AcsJNoPermissionEx();
        npe.setReason("Remote manager has thrown no permission exception.");
        npe.setID(HandleHelper.toString(id));
        throw npe;
    } catch (Exception ex) {
        //throw re;
        return null;
    }
}
Also used : IntArray(com.cosylab.acs.maci.IntArray) AcsJNoPermissionEx(alma.maciErrType.wrappers.AcsJNoPermissionEx) NoPermissionEx(alma.maciErrType.NoPermissionEx) AcsJNoPermissionEx(alma.maciErrType.wrappers.AcsJNoPermissionEx) ComponentInfo(com.cosylab.acs.maci.ComponentInfo) IOException(java.io.IOException) NoDefaultComponentException(com.cosylab.acs.maci.NoDefaultComponentException)

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