Search in sources :

Example 1 with NoDefaultComponentException

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

the class ManagerImpl method internalRequestDefaultComponent.

/**
	 * Internal method for requesting default components.
	 * @param	requestor	requestor of the component.
	 * @param	typr		type of the component
	 * @return	componentInfo	<code>ComponentInfo</code> of requested default component.
	 */
private ComponentInfo internalRequestDefaultComponent(int requestor, String type) throws NoDefaultComponentException {
    String defaultComponentName = null;
    ComponentInfo defaultComponentInfo = null;
    // first check default components table
    synchronized (defaultComponents) {
        defaultComponentInfo = defaultComponents.get(type);
    }
    if (defaultComponentInfo != null)
        defaultComponentName = defaultComponentInfo.getName();
    // if not found, search for the default component in the CDB
    if (defaultComponentName == null) {
        DAOProxy componentsDAO = getComponentsDAOProxy();
        if (componentsDAO != null) {
            try {
                // get names of all components
                // @todo here to check if CDB is available
                componentsDAO.get_field_data("");
                /*String[] ids =*/
                String[] ids = getComponentsList();
                // test names
                for (int i = 0; i < ids.length; i++) {
                    // read name
                    //readStringCharacteristics(componentsDAO, ids[i]+"/Name");
                    String name = ids[i];
                    if (name == null) {
                        logger.log(Level.WARNING, "Misconfigured CDB, there is no type of component '" + ids[i] + "' defined.");
                        continue;
                    }
                    // do not search dynamic components (they cannot be marked as default in CDB anyway)
                    if (!name.equals(ComponentSpec.COMPSPEC_ANY)) {
                        // read type
                        String componentType = readStringCharacteristics(componentsDAO, ids[i] + "/Type");
                        if (type == null) {
                            logger.log(Level.WARNING, "Misconfigured CDB, there is no type of component '" + name + "' defined.");
                            continue;
                        }
                        // test type
                        final String TRUE_STRING = "true";
                        if (type.equals(componentType)) {
                            // check if it is default, read silently
                            String isDefault = readStringCharacteristics(componentsDAO, ids[i] + "/Default", true);
                            if (isDefault == null || !isDefault.equalsIgnoreCase(TRUE_STRING))
                                continue;
                            // got the match
                            defaultComponentName = name;
                            break;
                        }
                    }
                }
            } catch (Throwable ex) {
                CoreException ce = new CoreException("Failed to obtain component data from the CDB.", ex);
                reportException(ce);
            }
        }
    }
    // if found get the component
    if (defaultComponentInfo != null) {
        try {
            StatusHolder status = new StatusHolder();
            ContainerInfo containerInfo = getContainerInfo(defaultComponentInfo.getContainer());
            if (containerInfo == null) {
                CoreException huse = new CoreException("Failed to return default component: '" + defaultComponentName + "', container with '" + HandleHelper.toString(defaultComponentInfo.getContainer()) + "' not logged in.");
                reportException(huse);
                return null;
            }
            ComponentInfo componentInfo = internalRequestComponent(requestor, defaultComponentInfo.getName(), defaultComponentInfo.getType(), defaultComponentInfo.getCode(), containerInfo.getName(), RELEASE_IMMEDIATELY, status, true);
            if (componentInfo == null || status.getStatus() != ComponentStatus.COMPONENT_ACTIVATED) {
                CoreException huse = new CoreException("Failed to obtain default component: '" + defaultComponentName + "'.");
                reportException(huse);
                // no error handling...
                return null;
            }
            return componentInfo;
        } catch (Throwable t) {
            CoreException huse = new CoreException("Failed to return default component: '" + defaultComponentName + "'.", t);
            reportException(huse);
            return null;
        }
    } else if (defaultComponentName != null) {
        // create CURL
        URI curl = null;
        try {
            curl = CURLHelper.createURI(defaultComponentName);
        } catch (URISyntaxException use) {
            CoreException huse = new CoreException("Failed to create CURL from default component name: '" + defaultComponentName + "'.", use);
            reportException(huse);
            return null;
        }
        try {
            // request for component
            StatusHolder status = new StatusHolder();
            Component component = internalRequestComponent(requestor, curl, status, true);
            if (component == null || status.getStatus() != ComponentStatus.COMPONENT_ACTIVATED) {
                CoreException huse = new CoreException("Failed to obtain default component: '" + defaultComponentName + "'.");
                reportException(huse);
                return null;
            }
            // return component info
            ComponentInfo[] componentInfo = getComponentInfo(requestor, new int[0], defaultComponentName, type, true);
            if (componentInfo == null || componentInfo.length != 1) {
                CoreException huse = new CoreException("Failed to obtain activated default component ComponentInfo: '" + defaultComponentName + "'.");
                reportException(huse);
                return null;
            } else
                return componentInfo[0];
        } catch (Throwable t) {
            CoreException huse = new CoreException("Failed to return default component: '" + defaultComponentName + "'.", t);
            reportException(huse);
            return null;
        }
    }
    // not found
    NoDefaultComponentException ndce = new NoDefaultComponentException("No default component for type '" + type + "' found.");
    throw ndce;
}
Also used : URISyntaxException(java.net.URISyntaxException) DAOProxy(com.cosylab.cdb.client.DAOProxy) URI(java.net.URI) NoDefaultComponentException(com.cosylab.acs.maci.NoDefaultComponentException) StatusHolder(com.cosylab.acs.maci.StatusHolder) CoreException(com.cosylab.acs.maci.CoreException) ContainerInfo(com.cosylab.acs.maci.ContainerInfo) ComponentInfo(com.cosylab.acs.maci.ComponentInfo) Component(com.cosylab.acs.maci.Component)

Example 2 with NoDefaultComponentException

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

the class ManagerProxyImpl method get_default_component.

/**
	 * Returns the default component of specific type.
	 * @param	id		identification of the caller.
	 * @param	type	component type, IDL ID.
	 * @return	<code>ComponentInfo</code> of requested component.
	 */
public ComponentInfo get_default_component(int id, String type) throws NoPermissionEx, NoDefaultComponentEx, CannotGetComponentEx {
    pendingRequests.incrementAndGet();
    try {
        // returned value
        ComponentInfo retVal = null;
        // transform to CORBA specific
        com.cosylab.acs.maci.ComponentInfo info = manager.getDefaultComponent(id, type);
        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 (NoDefaultComponentException ndce) {
        NoDefaultComponentException hndce = new NoDefaultComponentException(ndce.getMessage(), ndce);
        reportException(hndce);
        // rethrow CORBA specific
        throw new AcsJNoDefaultComponentEx().toNoDefaultComponentEx();
    } 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 (AcsJCannotGetComponentEx 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 : BAD_PARAM(org.omg.CORBA.BAD_PARAM) AcsJCannotGetComponentEx(alma.maciErrType.wrappers.AcsJCannotGetComponentEx) NoDefaultComponentException(com.cosylab.acs.maci.NoDefaultComponentException) BadParametersException(com.cosylab.acs.maci.BadParametersException) NoResourcesException(com.cosylab.acs.maci.NoResourcesException) AcsJNoDefaultComponentEx(alma.maciErrType.wrappers.AcsJNoDefaultComponentEx) 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)

Example 3 with NoDefaultComponentException

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

Aggregations

NoDefaultComponentException (com.cosylab.acs.maci.NoDefaultComponentException)3 AcsJNoPermissionEx (alma.maciErrType.wrappers.AcsJNoPermissionEx)2 BadParametersException (com.cosylab.acs.maci.BadParametersException)2 Component (com.cosylab.acs.maci.Component)2 ComponentInfo (com.cosylab.acs.maci.ComponentInfo)2 CoreException (com.cosylab.acs.maci.CoreException)2 AcsJCannotGetComponentEx (alma.maciErrType.wrappers.AcsJCannotGetComponentEx)1 AcsJNoDefaultComponentEx (alma.maciErrType.wrappers.AcsJNoDefaultComponentEx)1 ClientInfo (com.cosylab.acs.maci.ClientInfo)1 ContainerInfo (com.cosylab.acs.maci.ContainerInfo)1 NoResourcesException (com.cosylab.acs.maci.NoResourcesException)1 StatusHolder (com.cosylab.acs.maci.StatusHolder)1 DAOProxy (com.cosylab.cdb.client.DAOProxy)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 BAD_PARAM (org.omg.CORBA.BAD_PARAM)1 NO_RESOURCES (org.omg.CORBA.NO_RESOURCES)1 Object (org.omg.CORBA.Object)1