Search in sources :

Example 26 with BadParametersException

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

the class ManagerProxyImpl method release_component_async.

public void release_component_async(int id, String component_url, CBlong callback, CBDescIn desc) throws NoPermissionEx {
    pendingRequests.incrementAndGet();
    try {
        // simply release Component
        URI uri = null;
        if (component_url != null)
            uri = CURLHelper.createURI(component_url);
        final CBlong fcallback = callback;
        final CBDescOut descOut = new CBDescOut(0, desc.id_tag);
        LongCompletionCallback lcc = null;
        if (callback != null) {
            lcc = new LongCompletionCallback() {

                public void failed(int result, Throwable exception) {
                    if (exception instanceof AcsJException) {
                        AcsJException aex = (AcsJException) exception;
                        fcallback.done(result, aex.toAcsJCompletion().toCorbaCompletion(), descOut);
                    } else {
                        AcsJUnexpectedExceptionEx uex = new AcsJUnexpectedExceptionEx(exception);
                        fcallback.done(result, uex.toAcsJCompletion().toCorbaCompletion(), descOut);
                    }
                }

                public void done(int result) {
                    fcallback.done(result, new ACSErrOKAcsJCompletion().toCorbaCompletion(), descOut);
                }
            };
        }
        manager.releaseComponentAsync(id, uri, lcc);
    } catch (AcsJNoPermissionEx nop) {
        reportException(nop);
        // rethrow CORBA specific
        throw nop.toNoPermissionEx();
    } 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 (Throwable ex) {
        CoreException hce = new CoreException(ex.getMessage(), ex);
        reportException(hce);
        // rethrow CORBA specific
        throw new UNKNOWN(ex.getMessage());
    } finally {
        pendingRequests.decrementAndGet();
    }
}
Also used : CBDescOut(alma.ACS.CBDescOut) AcsJException(alma.acs.exceptions.AcsJException) BAD_PARAM(org.omg.CORBA.BAD_PARAM) URISyntaxException(java.net.URISyntaxException) LongCompletionCallback(com.cosylab.acs.maci.Manager.LongCompletionCallback) URI(java.net.URI) BadParametersException(com.cosylab.acs.maci.BadParametersException) NoResourcesException(com.cosylab.acs.maci.NoResourcesException) CBlong(alma.ACS.CBlong) AcsJNoPermissionEx(alma.maciErrType.wrappers.AcsJNoPermissionEx) CoreException(com.cosylab.acs.maci.CoreException) AcsJUnexpectedExceptionEx(alma.ACSErrTypeCommon.wrappers.AcsJUnexpectedExceptionEx) ACSErrOKAcsJCompletion(alma.ACSErrTypeOK.wrappers.ACSErrOKAcsJCompletion) UNKNOWN(org.omg.CORBA.UNKNOWN) NO_RESOURCES(org.omg.CORBA.NO_RESOURCES)

Example 27 with BadParametersException

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

the class ManagerProxyImpl method get_client_info.

/**
	 * Get all the information that the Manager has about its known clients.
	 * To invoke this method, the caller must have INTROSPECT_MANAGER access rights, or it must be the object whose info it is requesting.
	 * Calling this function does not affect the internal state of the Manager.
	 *
	 * @param id Identification of the caller.
	 * @param h Handles of the clients whose information is requested. If this is an empty sequence, the name_wc parameter is used.
	 * @param name_wc Wildcard that the clients's name must match in order for its information to be returned.
	 * @return A sequence of ClientInfo structures containing the entire Manager's knowledge about the containers.
	 *		  If access is denied to a subset of objects, the handles to those objects are set to 0.
	 */
public ClientInfo[] get_client_info(int id, int[] h, String name_wc) throws NoPermissionEx {
    pendingRequests.incrementAndGet();
    try {
        // invalid info (replacement for null)
        final ClientInfo invalidInfo = new ClientInfo(0, null, new int[0], "<invalid>", 0);
        // returned value
        ClientInfo[] retVal = null;
        // transform to CORBA specific
        com.cosylab.acs.maci.ClientInfo[] infos = manager.getClientInfo(id, h, name_wc);
        if (infos != null) {
            retVal = new ClientInfo[infos.length];
            for (int i = 0; i < infos.length; i++) if (infos[i] == null)
                retVal[i] = invalidInfo;
            else
                retVal[i] = new ClientInfo(infos[i].getHandle(), ((ClientProxy) infos[i].getClient()).getClient(), infos[i].getComponents().toArray(), infos[i].getName(), mapAccessRights(infos[i].getAccessRights()));
        } else
            retVal = new ClientInfo[0];
        return retVal;
    } 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 (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) BadParametersException(com.cosylab.acs.maci.BadParametersException) NoResourcesException(com.cosylab.acs.maci.NoResourcesException) AcsJNoPermissionEx(alma.maciErrType.wrappers.AcsJNoPermissionEx) CoreException(com.cosylab.acs.maci.CoreException) ClientInfo(si.ijs.maci.ClientInfo) UNKNOWN(org.omg.CORBA.UNKNOWN) NO_RESOURCES(org.omg.CORBA.NO_RESOURCES)

Example 28 with BadParametersException

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

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

the class ManagerImplTest method testContainerInfo.

public void testContainerInfo() {
    try {
        //test invalid
        try {
            manager.getContainerInfo(0, null, null);
            fail();
        } catch (BadParametersException bpe) {
            System.out.println("This is OK: " + bpe.getMessage());
        }
        //test invalid
        try {
            manager.getContainerInfo(Integer.MAX_VALUE, null, null);
            fail();
        } catch (BadParametersException bpe) {
            System.out.println("This is OK: " + bpe.getMessage());
        }
        //test invalid
        try {
            manager.getContainerInfo(dummyHandle, null, null);
            fail();
        } catch (BadParametersException bpe) {
            System.out.println("This is OK: " + bpe.getMessage());
        }
        //test invalid
        try {
            manager.getContainerInfo(dummyHandle, new int[0], null);
            fail();
        } catch (BadParametersException bpe) {
            System.out.println("This is OK: " + bpe.getMessage());
        }
        //test invalid
        try {
            manager.getContainerInfo(dummyHandle, new int[0], "non-null");
            fail();
        } catch (AcsJNoPermissionEx npe) {
            System.out.println("This is OK: " + npe.toString());
        }
        /*
			//test invalid regular expression
			try {
				manager.getContainerInfo(dummyHandle, new int[0], ")");		
				fail();
			}
			catch (BadParametersException bpe)
			{
	
				System.out.println("This is OK: "+bpe.getMessage());
			}
			*/
        //test valid
        ClientInfo info = manager.login(new TestContainer(containerName));
        int[] handles = { info.getHandle() };
        ContainerInfo[] infos = manager.getContainerInfo(info.getHandle(), handles, null);
        assertNotNull(infos);
        assertEquals(infos.length, 1);
        assertEquals(infos[0].getHandle(), info.getHandle());
        manager.logout(info.getHandle());
        //test inaccessible
        info = manager.login(new TestContainer(containerName));
        ClientInfo anotherInfo = manager.login(new TestContainer(anotherName));
        handles[0] = anotherInfo.getHandle();
        try {
            infos = manager.getContainerInfo(info.getHandle(), handles, null);
            fail();
        } catch (AcsJNoPermissionEx npe) {
            System.out.println("This is OK: " + npe.toString());
        }
        try {
            manager.getClientInfo(info.getHandle(), new int[0], anotherName);
            fail();
        } catch (AcsJNoPermissionEx npe) {
            System.out.println("This is OK: " + npe.toString());
        }
        manager.logout(info.getHandle());
        manager.logout(anotherInfo.getHandle());
        //test with INTROSPECTION_MANAGER rights
        info = manager.login(new TestContainer(containerName));
        ClientInfo adminInfo = manager.login(new TestAdministrator(administratorName));
        handles = new int[3];
        handles[0] = adminInfo.getHandle();
        handles[1] = info.getHandle();
        handles[2] = dummyHandle;
        infos = manager.getContainerInfo(adminInfo.getHandle(), handles, null);
        assertNotNull(infos);
        assertNull(infos[0]);
        assertEquals(infos[1].getHandle(), info.getHandle());
        assertNull(infos[2]);
        manager.logout(info.getHandle());
        manager.logout(adminInfo.getHandle());
        // test wildcard search		
        info = manager.login(new TestContainer("container1"));
        assertNotNull(info);
        ClientInfo info2 = manager.login(new TestContainer("container2a"));
        assertNotNull(info2);
        ClientInfo info3 = manager.login(new TestContainer("container3aa"));
        assertNotNull(info3);
        ClientInfo info4 = manager.login(new TestContainer("other4"));
        assertNotNull(info4);
        adminInfo = manager.login(new TestAdministrator("admin"));
        assertNotNull(adminInfo);
        //infos = manager.getContainerInfo(adminInfo.getHandle(), new int[0], "container.*");
        infos = manager.getContainerInfo(adminInfo.getHandle(), new int[0], "container*");
        assertNotNull(infos);
        assertEquals(3, infos.length);
        assertEquals(info.getHandle(), infos[0].getHandle());
        assertEquals(info2.getHandle(), infos[1].getHandle());
        assertEquals(info3.getHandle(), infos[2].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) ContainerInfo(com.cosylab.acs.maci.ContainerInfo) ClientInfo(com.cosylab.acs.maci.ClientInfo) BadParametersException(com.cosylab.acs.maci.BadParametersException)

Example 30 with BadParametersException

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

the class ManagerProxyImpl method get_dynamic_component.

/**
	 * Activation of an dynamic component.
	 * @param	id 	identification of the caller.
	 * @param	c	component to be obtained.
	 * @param	mark_as_default	mark component as default component of its type.
	 * @return	<code>ComponentInfo</code> of requested component.
	 */
public ComponentInfo get_dynamic_component(int id, si.ijs.maci.ComponentSpec c, boolean mark_as_default) throws NoPermissionEx, IncompleteComponentSpecEx, InvalidComponentSpecEx, ComponentSpecIncompatibleWithActiveComponentEx, CannotGetComponentEx {
    pendingRequests.incrementAndGet();
    try {
        // returned value
        ComponentInfo retVal = null;
        /*
			URI uri = null;
			if (c.component_name != null)
				uri = CURLHelper.createURI(c.component_name);
			ComponentSpec componentSpec = new ComponentSpec(uri, c.component_type, c.component_code, c.container_name);
			*/
        // @todo si.ijs.maci.COMPONENT_SPEC_ANY -> ComponentSpec.COMPSPEC_ANY
        ComponentSpec componentSpec = new ComponentSpec(c.component_name, c.component_type, c.component_code, c.container_name);
        com.cosylab.acs.maci.ComponentInfo info = manager.getDynamicComponent(id, componentSpec, mark_as_default);
        // transform to CORBA specific
        if (info == null || info.getComponent() == null)
            throw new AcsJCannotGetComponentEx();
        Object obj = null;
        obj = (Object) info.getComponent().getObject();
        String[] interfaces;
        if (info.getInterfaces() != null)
            interfaces = info.getInterfaces();
        else
            interfaces = new String[0];
        retVal = new ComponentInfo(info.getType(), info.getCode(), obj, info.getName(), info.getClients().toArray(), info.getContainer(), info.getContainerName(), info.getHandle(), mapAccessRights(info.getAccessRights()), interfaces);
        return retVal;
    }/*
		catch (URISyntaxException usi)
		{
			BadParametersException hbpe = new BadParametersException(usi.getMessage(), usi);
			hbpe.caughtIn(this, "get_dynamic_component");
			hbpe.putValue("c.component_name", c.component_name);
			// exception service will handle this
			reportException(hbpe);
	
			// rethrow CORBA specific
			throw new BAD_PARAM(usi.getMessage());
		}*/
     catch (AcsJInvalidComponentSpecEx ics) {
        // rethrow CORBA specific
        throw ics.toInvalidComponentSpecEx();
    } catch (AcsJIncompleteComponentSpecEx ics) {
        // rethrow CORBA specific
        throw ics.toIncompleteComponentSpecEx();
    } catch (AcsJComponentSpecIncompatibleWithActiveComponentEx cpiwac) {
        // rethrow CORBA specific
        throw cpiwac.toComponentSpecIncompatibleWithActiveComponentEx();
    } catch (AcsJNoPermissionEx npe) {
        // rethrow CORBA specific
        throw npe.toNoPermissionEx();
    } 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) {
        reportException(cgce);
        // rethrow CORBA specific
        throw cgce.toCannotGetComponentEx();
    } 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 : AcsJComponentSpecIncompatibleWithActiveComponentEx(alma.maciErrType.wrappers.AcsJComponentSpecIncompatibleWithActiveComponentEx) BAD_PARAM(org.omg.CORBA.BAD_PARAM) ComponentSpec(com.cosylab.acs.maci.ComponentSpec) AcsJCannotGetComponentEx(alma.maciErrType.wrappers.AcsJCannotGetComponentEx) AcsJIncompleteComponentSpecEx(alma.maciErrType.wrappers.AcsJIncompleteComponentSpecEx) BadParametersException(com.cosylab.acs.maci.BadParametersException) NoResourcesException(com.cosylab.acs.maci.NoResourcesException) AcsJInvalidComponentSpecEx(alma.maciErrType.wrappers.AcsJInvalidComponentSpecEx) AcsJNoPermissionEx(alma.maciErrType.wrappers.AcsJNoPermissionEx) CoreException(com.cosylab.acs.maci.CoreException) Object(org.omg.CORBA.Object) ComponentInfo(si.ijs.maci.ComponentInfo) UNKNOWN(org.omg.CORBA.UNKNOWN) NO_RESOURCES(org.omg.CORBA.NO_RESOURCES)

Aggregations

BadParametersException (com.cosylab.acs.maci.BadParametersException)30 AcsJNoPermissionEx (alma.maciErrType.wrappers.AcsJNoPermissionEx)21 NoResourcesException (com.cosylab.acs.maci.NoResourcesException)20 CoreException (com.cosylab.acs.maci.CoreException)17 BAD_PARAM (org.omg.CORBA.BAD_PARAM)13 UNKNOWN (org.omg.CORBA.UNKNOWN)13 NO_RESOURCES (org.omg.CORBA.NO_RESOURCES)12 URISyntaxException (java.net.URISyntaxException)11 ComponentInfo (com.cosylab.acs.maci.ComponentInfo)9 URI (java.net.URI)9 Object (org.omg.CORBA.Object)8 ClientInfo (com.cosylab.acs.maci.ClientInfo)7 AcsJCannotGetComponentEx (alma.maciErrType.wrappers.AcsJCannotGetComponentEx)6 Component (com.cosylab.acs.maci.Component)6 NoDefaultComponentException (com.cosylab.acs.maci.NoDefaultComponentException)5 RemoteException (com.cosylab.acs.maci.RemoteException)5 TimeoutRemoteException (com.cosylab.acs.maci.TimeoutRemoteException)5 AcsJException (alma.acs.exceptions.AcsJException)4 ContainerInfo (com.cosylab.acs.maci.ContainerInfo)4 ComponentInfo (si.ijs.maci.ComponentInfo)4