Search in sources :

Example 21 with StatusHolder

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

use of com.cosylab.acs.maci.StatusHolder 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)

Example 23 with StatusHolder

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

the class ManagerProxyImpl method get_service.

/**
	 * Get a service, activating it if necessary (components).
	 * The client represented by id (the handle) must have adequate access rights to access the service.
	 * NOTE: a component is also a service, i.e. a service activated by a container.
	 * 
	 * @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 service_url CURL of the service 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.
	 * @param status Status of the request. One of COMPONENT_ACTIVATED, COMPONENT_DOES_NO_EXIST and COMPONENT_NOT_ACTIVATED.
	 * @return Reference to the service. If the service could not be obtained, a nil reference is returned,
	 *		  and the status contains an error code detailing the cause of failure (one of the COMPONENT_* constants).
	 * @see #get_component
	 */
public Object get_service(int id, String service_url, boolean activate) throws NoPermissionEx, CannotGetComponentEx {
    pendingRequests.incrementAndGet();
    try {
        // returned value
        Object retVal = null;
        // returned status
        StatusHolder statusHolder = new StatusHolder();
        // transform to CORBA specific
        URI uri = null;
        if (service_url != null)
            uri = CURLHelper.createURI(service_url);
        Component component = manager.getService(id, uri, activate, statusHolder);
        if (component == null || (Object) component.getObject() == null)
            throw new AcsJCannotGetComponentEx();
        retVal = (Object) component.getObject();
        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 (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) 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) UNKNOWN(org.omg.CORBA.UNKNOWN) Component(com.cosylab.acs.maci.Component) NO_RESOURCES(org.omg.CORBA.NO_RESOURCES)

Example 24 with StatusHolder

use of com.cosylab.acs.maci.StatusHolder 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

StatusHolder (com.cosylab.acs.maci.StatusHolder)24 URI (java.net.URI)23 Component (com.cosylab.acs.maci.Component)19 URISyntaxException (java.net.URISyntaxException)19 AcsJNoPermissionEx (alma.maciErrType.wrappers.AcsJNoPermissionEx)18 BadParametersException (com.cosylab.acs.maci.BadParametersException)17 NoResourcesException (com.cosylab.acs.maci.NoResourcesException)17 ClientInfo (com.cosylab.acs.maci.ClientInfo)16 NoDefaultComponentException (com.cosylab.acs.maci.NoDefaultComponentException)16 RemoteException (com.cosylab.acs.maci.RemoteException)16 HashMap (java.util.HashMap)16 ComponentInfo (com.cosylab.acs.maci.ComponentInfo)15 Map (java.util.Map)15 AcsJCannotGetComponentEx (alma.maciErrType.wrappers.AcsJCannotGetComponentEx)8 AcsJBadParameterEx (alma.ACSErrTypeCommon.wrappers.AcsJBadParameterEx)6 CoreException (com.cosylab.acs.maci.CoreException)5 DAOProxy (com.cosylab.cdb.client.DAOProxy)4 AcsJComponentSpecIncompatibleWithActiveComponentEx (alma.maciErrType.wrappers.AcsJComponentSpecIncompatibleWithActiveComponentEx)3 AcsJIncompleteComponentSpecEx (alma.maciErrType.wrappers.AcsJIncompleteComponentSpecEx)3 AcsJInvalidComponentSpecEx (alma.maciErrType.wrappers.AcsJInvalidComponentSpecEx)3