Search in sources :

Example 1 with Component

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

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

the class ManagerImpl method restartComponent.

/**
	 * @see com.cosylab.acs.maci.Manager#restartComponent(int, URI)
	 */
public Component restartComponent(int id, URI curl) throws AcsJNoPermissionEx, AcsJBadParameterEx {
    // TODO MF tmp, reject non-local domains
    try {
        checkCURL(curl, false);
    } catch (AcsJBadParameterEx e) {
        throw e;
    }
    // check handle and NONE permissions
    securityCheck(id, AccessRights.NONE);
    /****************************************************************/
    Component component = internalRestartComponent(id, curl);
    if (component != null)
        logger.log(Level.INFO, "Component '" + curl + "' restarted.");
    else
        logger.log(Level.INFO, "Failed to restart component '" + curl + "'.");
    return component;
}
Also used : AcsJBadParameterEx(alma.ACSErrTypeCommon.wrappers.AcsJBadParameterEx) Component(com.cosylab.acs.maci.Component)

Example 3 with Component

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

the class ManagerImplTest method testRestartComponent.

public void testRestartComponent() {
    try {
        try {
            manager.restartComponent(0, null);
            fail();
        } catch (AcsJBadParameterEx bpe) {
            System.out.println("This is OK: null parameter");
        }
        try {
            manager.restartComponent(Integer.MAX_VALUE, null);
            fail();
        } catch (AcsJBadParameterEx bpe) {
            System.out.println("This is OK: null parameter");
        }
        try {
            manager.restartComponent(dummyHandle, dummyURI);
            fail();
        } catch (AcsJNoPermissionEx npe) {
            System.out.println("This is OK: " + npe.toString());
        } catch (AcsJBadParameterEx bpe) {
            fail();
        }
        TestClient client = new TestClient(clientName);
        ClientInfo info = manager.login(client);
        assertTrue(info.getHandle() != 0);
        try {
            manager.restartComponent(info.getHandle(), null);
            fail();
        } catch (AcsJBadParameterEx bpe) {
            System.out.println("This is OK: null parameter");
        }
        URI mount = null;
        try {
            mount = new URI("MOUNT3");
            Component component = manager.restartComponent(info.getHandle(), mount);
            assertEquals(null, component);
        } catch (AcsJBadParameterEx bpe) {
            fail();
        } catch (URISyntaxException usi) {
            fail();
        }
        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);
        // activate
        try {
            StatusHolder status = new StatusHolder();
            Component ref = manager.getComponent(info.getHandle(), mount, true, status);
            assertEquals(mount3COB, ref);
            assertEquals(ComponentStatus.COMPONENT_ACTIVATED, status.getStatus());
        } catch (Exception ex) {
            fail();
        }
        // restart 
        try {
            Component returnedComponent = manager.restartComponent(info.getHandle(), mount);
            assertEquals(mount3COB, returnedComponent);
        } catch (Exception ex) {
            fail();
        }
        // no owner client test
        TestClient client2 = new TestClient("thief");
        ClientInfo info2 = manager.login(client2);
        assertTrue(info2.getHandle() != 0);
        try {
            manager.restartComponent(info2.getHandle(), mount);
            fail();
        } catch (AcsJNoPermissionEx npe) {
            System.out.println("This is OK: " + npe.toString());
        } catch (AcsJBadParameterEx bpe) {
            fail();
        }
    } catch (AcsJNoPermissionEx e) {
        fail("No permission");
    }
}
Also used : AcsJBadParameterEx(alma.ACSErrTypeCommon.wrappers.AcsJBadParameterEx) HashMap(java.util.HashMap) URISyntaxException(java.net.URISyntaxException) 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) Component(com.cosylab.acs.maci.Component) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with Component

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

the class ManagerImplTest method testReleaseComponentAsync.

public void testReleaseComponentAsync() throws Throwable {
    try {
        try {
            manager.releaseComponentAsync(0, null, null);
            fail();
        } catch (AcsJBadParameterEx bpe) {
            System.out.println("This is OK: null parameter");
        }
        try {
            manager.releaseComponentAsync(Integer.MAX_VALUE, null, null);
            fail();
        } catch (AcsJBadParameterEx bpe) {
            System.out.println("This is OK: null parameter");
        }
        try {
            manager.releaseComponentAsync(dummyHandle, dummyURI, null);
            fail();
        } catch (AcsJNoPermissionEx npe) {
            System.out.println("This is OK: " + npe.toString());
        } catch (AcsJBadParameterEx bpe) {
            fail();
        }
        TestClient client = new TestClient(clientName);
        ClientInfo info = manager.login(client);
        TestClient client2 = new TestClient("anotherClient");
        ClientInfo info2 = manager.login(client2);
        TestContainer container = new TestContainer("Container");
        Map supportedComponents = new HashMap();
        Component mount1COB = new TestComponent("MOUNT1");
        supportedComponents.put("MOUNT1", mount1COB);
        Component mount4COB = new TestComponent("MOUNT4", false, true);
        supportedComponents.put("MOUNT4", mount4COB);
        container.setSupportedComponents(supportedComponents);
        ClientInfo containerInfo = manager.login(container);
        // here also parallel activation will be tested (autostart and activation bellow)
        StatusHolder status = new StatusHolder();
        Component ref = manager.getComponent(info.getHandle(), new URI("MOUNT1"), true, status);
        assertEquals(mount1COB, ref);
        assertEquals(ComponentStatus.COMPONENT_ACTIVATED, status.getStatus());
        status = new StatusHolder();
        ref = manager.getComponent(info2.getHandle(), new URI("MOUNT1"), true, status);
        assertEquals(mount1COB, ref);
        assertEquals(ComponentStatus.COMPONENT_ACTIVATED, status.getStatus());
        ref = manager.getComponent(info.getHandle(), new URI("MOUNT4"), true, status);
        assertEquals(mount4COB, ref);
        assertEquals(ComponentStatus.COMPONENT_ACTIVATED, status.getStatus());
        try {
            LongCompletionCallbackTestImpl lcc = new LongCompletionCallbackTestImpl();
            synchronized (lcc) {
                manager.releaseComponentAsync(info2.getHandle(), new URI("MOUNT1"), lcc);
                if (!lcc.doneFlag)
                    lcc.wait(SLEEP_TIME_MS);
                if (!lcc.doneFlag)
                    fail("callback not called");
                assertEquals(1, lcc.result);
                assertNull(lcc.exception);
                lcc.reset();
                manager.releaseComponentAsync(info.getHandle(), new URI("MOUNT1"), lcc);
                if (!lcc.doneFlag)
                    lcc.wait(SLEEP_TIME_MS);
                if (!lcc.doneFlag)
                    fail("callback not called");
                assertEquals(0, lcc.result);
                assertNull(lcc.exception);
                lcc.reset();
                manager.releaseComponentAsync(info.getHandle(), new URI("MOUNT4"), lcc);
                if (!lcc.doneFlag)
                    lcc.wait(SLEEP_TIME_MS);
                if (!lcc.doneFlag)
                    fail("callback not called");
                assertEquals(0, lcc.result);
                assertNotNull(lcc.exception);
            }
        } catch (Exception ex) {
            fail(ex.toString());
        }
    } 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) ClientInfo(com.cosylab.acs.maci.ClientInfo) Component(com.cosylab.acs.maci.Component) HashMap(java.util.HashMap) Map(java.util.Map)

Example 5 with Component

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

the class ManagerImplTest method testContainerToManagerStateTransferComponents.

public void testContainerToManagerStateTransferComponents() {
    TestComponent mount1COB = new TestComponent("MOUNT1");
    TestComponent mount2COB = new TestComponent("MOUNT2");
    Map supportedComponents = new HashMap();
    supportedComponents.put("MOUNT1", mount1COB);
    supportedComponents.put("MOUNT2", mount2COB);
    try {
        // dummy container
        TestContainer dummyContainer = new TestContainer("Container", ClientType.CONTAINER, true);
        ClientInfo dummyContainerInfo = manager.login(dummyContainer);
        dummyContainer.setSupportedComponents(supportedComponents);
        try {
            Thread.sleep(STARTUP_COBS_SLEEP_TIME_MS);
        } catch (InterruptedException ie) {
        }
        TestAdministrator client = new TestAdministrator(administratorName);
        ClientInfo info = manager.login(client);
        // activate MOUNT2
        //
        URI mount2URI;
        try {
            mount2URI = new URI("MOUNT2");
            StatusHolder status = new StatusHolder();
            Component ref = manager.getComponent(info.getHandle(), mount2URI, true, status);
            assertEquals(mount2COB, ref);
            assertEquals(ComponentStatus.COMPONENT_ACTIVATED, status.getStatus());
        } catch (Exception ex) {
            fail();
        }
        manager.logout(dummyContainerInfo.getHandle());
        // try to confuse with recovery mode
        TestContainer container = new TestContainer("Container", ClientType.CONTAINER, true);
        container.setSupportedComponents(supportedComponents);
        // add Components to container
        ComponentInfo mount1COBInfo = new ComponentInfo(HandleConstants.COMPONENT_MASK + 1, "MOUNT1", "IDL:alma/MOUNT_ACS/Mount:1.0", "acsexmplMount", mount1COB);
        mount1COBInfo.setInterfaces(mount1COB.implementedInterfaces());
        mount1COBInfo.setContainer(dummyContainerInfo.getHandle());
        mount1COBInfo.setContainerName(dummyContainerInfo.getName());
        container.getActivatedComponents().put(new Integer(mount1COBInfo.getHandle()), mount1COBInfo);
        ComponentInfo mount2COBInfo = new ComponentInfo(HandleConstants.COMPONENT_MASK + 2, "MOUNT2", "IDL:alma/MOUNT_ACS/Mount:1.0", "acsexmplMount", mount2COB);
        mount2COBInfo.setInterfaces(mount2COB.implementedInterfaces());
        mount2COBInfo.setContainer(dummyContainerInfo.getHandle());
        mount2COBInfo.setContainerName(dummyContainerInfo.getName());
        container.getActivatedComponents().put(new Integer(mount2COBInfo.getHandle()), mount2COBInfo);
        // container login
        ClientInfo containerInfo = manager.login(container);
        try {
            Thread.sleep(STARTUP_COBS_SLEEP_TIME_MS);
        } catch (InterruptedException ie) {
        }
        // there should be 2 Components activated
        ComponentInfo[] infos = manager.getComponentInfo(info.getHandle(), new int[0], "*", "*", true);
        Arrays.sort(infos);
        assertEquals(2, infos.length);
        assertEquals("MOUNT1", infos[0].getName());
        assertEquals("MOUNT2", infos[1].getName());
        // container2 took over
        assertEquals(containerInfo.getHandle(), infos[0].getContainer());
        assertEquals(containerInfo.getHandle(), infos[1].getContainer());
        // manager
        assertEquals(1, infos[0].getClients().size());
        assertTrue(infos[0].getClients().contains(HandleConstants.MANAGER_MASK));
        // client only
        assertEquals(1, infos[1].getClients().size());
        assertTrue(infos[1].getClients().contains(info.getHandle()));
    } 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) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) 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

Component (com.cosylab.acs.maci.Component)29 AcsJNoPermissionEx (alma.maciErrType.wrappers.AcsJNoPermissionEx)24 BadParametersException (com.cosylab.acs.maci.BadParametersException)21 URI (java.net.URI)21 URISyntaxException (java.net.URISyntaxException)20 NoResourcesException (com.cosylab.acs.maci.NoResourcesException)19 StatusHolder (com.cosylab.acs.maci.StatusHolder)19 ClientInfo (com.cosylab.acs.maci.ClientInfo)18 ComponentInfo (com.cosylab.acs.maci.ComponentInfo)18 NoDefaultComponentException (com.cosylab.acs.maci.NoDefaultComponentException)18 RemoteException (com.cosylab.acs.maci.RemoteException)17 HashMap (java.util.HashMap)17 Map (java.util.Map)17 AcsJBadParameterEx (alma.ACSErrTypeCommon.wrappers.AcsJBadParameterEx)10 AcsJCannotGetComponentEx (alma.maciErrType.wrappers.AcsJCannotGetComponentEx)10 CoreException (com.cosylab.acs.maci.CoreException)5 Object (org.omg.CORBA.Object)5 BAD_PARAM (org.omg.CORBA.BAD_PARAM)4 NO_RESOURCES (org.omg.CORBA.NO_RESOURCES)4 UNKNOWN (org.omg.CORBA.UNKNOWN)4