Search in sources :

Example 1 with AcsJComponentSpecIncompatibleWithActiveComponentEx

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

the class ManagerImplTest method testGetCollocatedComponent.

/**
	 * Test getCollocatedComponent.
	 */
public void testGetCollocatedComponent() {
    try {
        URI mountURI = null;
        try {
            mountURI = new URI("MOUNT1");
        } catch (URISyntaxException e) {
            fail();
        }
        try {
            manager.getCollocatedComponent(0, null, false, null);
            fail();
        } catch (AcsJInvalidComponentSpecEx bpe) {
            System.out.println("This is OK: " + bpe.toString());
        }
        final ComponentSpec allAsterixCompSpec = new ComponentSpec(ComponentSpec.COMPSPEC_ANY, ComponentSpec.COMPSPEC_ANY, ComponentSpec.COMPSPEC_ANY, ComponentSpec.COMPSPEC_ANY);
        try {
            manager.getCollocatedComponent(Integer.MAX_VALUE, allAsterixCompSpec, true, dummyURI);
            fail();
        } catch (AcsJNoPermissionEx npe) {
            System.out.println("This is OK: " + npe.toString());
        }
        try {
            manager.getCollocatedComponent(dummyHandle, allAsterixCompSpec, false, dummyURI);
            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.getCollocatedComponent(info.getHandle(), null, true, dummyURI);
            fail();
        } catch (AcsJInvalidComponentSpecEx bpe) {
            System.out.println("This is OK: " + bpe.toString());
        }
        try {
            manager.getCollocatedComponent(info.getHandle(), allAsterixCompSpec, true, null);
            fail();
        } catch (AcsJInvalidComponentSpecEx bpe) {
            System.out.println("This is OK: " + bpe.toString());
        }
        try {
            manager.getCollocatedComponent(info.getHandle(), new ComponentSpec(null, null, null, null), false, mountURI);
            fail();
        } catch (AcsJInvalidComponentSpecEx ndce) {
            System.out.println("This is OK: " + ndce.toString());
        }
        final ComponentSpec specifiedContainerCompSpec = new ComponentSpec(ComponentSpec.COMPSPEC_ANY, ComponentSpec.COMPSPEC_ANY, ComponentSpec.COMPSPEC_ANY, "someContainer");
        try {
            manager.getCollocatedComponent(info.getHandle(), specifiedContainerCompSpec, false, mountURI);
            fail();
        } catch (AcsJInvalidComponentSpecEx ndce) {
            System.out.println("This is OK: " + ndce.toString());
        }
        // containers
        TestContainer container = new TestContainer("Container");
        Map supportedComponents = new HashMap();
        TestComponent mount1COB = new TestComponent("MOUNT1");
        supportedComponents.put("MOUNT1", mount1COB);
        TestComponent mountCollCOB = new TestComponent("MOUNT_COLLOCATED");
        supportedComponents.put("MOUNT_COLLOCATED", mountCollCOB);
        TestComponent mountColl2COB = new TestComponent("MOUNT_COLLOCATED2");
        supportedComponents.put("MOUNT_COLLOCATED2", mountCollCOB);
        container.setSupportedComponents(supportedComponents);
        ClientInfo containerInfo = manager.login(container);
        TestContainer dynContainer = new TestDynamicContainer("DynContainer");
        /*ClientInfo dynContainerInfo =*/
        manager.login(dynContainer);
        // wait containers to startup
        try {
            Thread.sleep(STARTUP_COBS_SLEEP_TIME_MS);
        } catch (InterruptedException ie) {
        }
        // standard case
        try {
            ComponentInfo componentInfo = manager.getCollocatedComponent(info.getHandle(), new ComponentSpec("MOUNT_COLLOCATED", "java.lang.Object", "java.lang.Object", ComponentSpec.COMPSPEC_ANY), true, mountURI);
            assertTrue(componentInfo != null);
            assertTrue(componentInfo.getName().equals("MOUNT_COLLOCATED"));
            assertEquals(containerInfo.getHandle(), componentInfo.getContainer());
        } catch (Exception ex) {
            ex.printStackTrace();
            fail();
        }
        // from CDB
        try {
            URI mount2URI = new URI("MOUNT2");
            ComponentInfo componentInfo = manager.getCollocatedComponent(info.getHandle(), new ComponentSpec("MOUNT_COLLOCATED2", "java.lang.Object", "java.lang.Object", ComponentSpec.COMPSPEC_ANY), true, mount2URI);
            assertTrue(componentInfo != null);
            assertTrue(componentInfo.getName().equals("MOUNT_COLLOCATED2"));
            assertEquals(containerInfo.getHandle(), componentInfo.getContainer());
        } catch (Exception ex) {
            fail();
        }
        // from CDB, but there is not entry...
        try {
            URI noEntryURI = new URI("noEntry");
            ComponentInfo componentInfo = manager.getCollocatedComponent(info.getHandle(), new ComponentSpec("MOUNT_COLLOCATED3", "java.lang.Object", "java.lang.Object", ComponentSpec.COMPSPEC_ANY), true, noEntryURI);
            fail();
        } catch (AcsJIncompleteComponentSpecEx icse) {
            System.out.println("This is OK: " + icse.toString());
        } catch (Exception ex) {
            ex.printStackTrace();
            fail();
        }
    } catch (AcsJCannotGetComponentEx e) {
        // @todo Auto-generated catch block
        e.printStackTrace();
    } catch (AcsJIncompleteComponentSpecEx e) {
        // @todo Auto-generated catch block
        e.printStackTrace();
    } catch (AcsJInvalidComponentSpecEx e) {
        // @todo Auto-generated catch block
        e.printStackTrace();
    } catch (AcsJComponentSpecIncompatibleWithActiveComponentEx e) {
        // @todo Auto-generated catch block
        e.printStackTrace();
    } catch (AcsJNoPermissionEx e) {
        fail("No permission");
    }
}
Also used : HashMap(java.util.HashMap) AcsJComponentSpecIncompatibleWithActiveComponentEx(alma.maciErrType.wrappers.AcsJComponentSpecIncompatibleWithActiveComponentEx) URISyntaxException(java.net.URISyntaxException) ComponentSpec(com.cosylab.acs.maci.ComponentSpec) 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) AcsJCannotGetComponentEx(alma.maciErrType.wrappers.AcsJCannotGetComponentEx) AcsJIncompleteComponentSpecEx(alma.maciErrType.wrappers.AcsJIncompleteComponentSpecEx) AcsJInvalidComponentSpecEx(alma.maciErrType.wrappers.AcsJInvalidComponentSpecEx) AcsJNoPermissionEx(alma.maciErrType.wrappers.AcsJNoPermissionEx) ClientInfo(com.cosylab.acs.maci.ClientInfo) ComponentInfo(com.cosylab.acs.maci.ComponentInfo) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with AcsJComponentSpecIncompatibleWithActiveComponentEx

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

the class ManagerImplTest method testGetComponent.

public void testGetComponent() {
    try {
        try {
            manager.getComponent(0, null, false, null);
            fail();
        } catch (AcsJCannotGetComponentEx bpe) {
            System.out.println("This is OK: " + bpe.toString());
        }
        try {
            manager.getComponent(Integer.MAX_VALUE, null, false, null);
            fail();
        } catch (AcsJCannotGetComponentEx bpe) {
            System.out.println("This is OK: " + bpe.toString());
        }
        try {
            StatusHolder status = null;
            manager.getComponent(dummyHandle, dummyURI, false, status);
            fail();
        } catch (AcsJCannotGetComponentEx bpe) {
            System.out.println("This is OK: " + bpe.toString());
        }
        try {
            StatusHolder status = new StatusHolder();
            manager.getComponent(dummyHandle, null, false, status);
            fail();
        } catch (AcsJCannotGetComponentEx bpe) {
            System.out.println("This is OK: " + bpe.toString());
        }
        TestAdministrator client = new TestAdministrator(administratorName);
        ClientInfo info = manager.login(client);
        assertTrue(info.getHandle() != 0);
        // get unexistant
        try {
            StatusHolder status = new StatusHolder();
            Component ref = manager.getComponent(info.getHandle(), dummyURI, true, status);
            fail();
        } catch (AcsJCannotGetComponentEx e) {
            System.out.println("This is OK: component does not exist " + e.toString());
        } catch (Exception ex) {
            fail();
        }
        // test no activation 
        URI mount = null;
        try {
            mount = new URI("MOUNT1");
            StatusHolder status = new StatusHolder();
            Component ref = manager.getComponent(info.getHandle(), mount, false, status);
        } catch (AcsJCannotGetComponentEx e) {
            fail();
        } catch (Exception ex) {
            fail();
        }
        // test activation w/o container
        try {
            StatusHolder status = new StatusHolder();
            Component ref = manager.getComponent(info.getHandle(), mount, true, status);
            fail();
        } catch (AcsJCannotGetComponentEx e) {
            System.out.println("This is OK: component not activated " + e.toString());
        } catch (Exception ex) {
            fail();
        }
        // there should be only no Components activated
        ComponentInfo[] infos = manager.getComponentInfo(info.getHandle(), new int[0], "*", "*", true);
        assertEquals(0, infos.length);
        TestContainer container = new TestContainer("Container");
        Map supportedComponents = new HashMap();
        Component mount1COB = new TestComponent("MOUNT1");
        supportedComponents.put("MOUNT1", mount1COB);
        supportedComponents.put("MOUNT2", null);
        supportedComponents.put("MOUNT3", new TestComponent("MOUNT3", true, false));
        Component mount4COB = new TestComponent("MOUNT4", false, true);
        supportedComponents.put("MOUNT4", mount4COB);
        container.setSupportedComponents(supportedComponents);
        ClientInfo containerInfo = manager.login(container);
        // test ordinary activation
        try {
            StatusHolder status = new StatusHolder();
            Component ref = manager.getComponent(info.getHandle(), mount, true, status);
            assertEquals(mount1COB, ref);
            assertEquals(ComponentStatus.COMPONENT_ACTIVATED, status.getStatus());
        } catch (Exception ex) {
            fail();
        }
        // test failed activation
        try {
            StatusHolder status;
            Component ref;
            URI mount2 = null;
            mount2 = new URI("MOUNT2");
            status = new StatusHolder();
            ref = manager.getComponent(info.getHandle(), mount2, true, status);
            fail();
        } catch (AcsJCannotGetComponentEx e1) {
            System.out.println("This is OK: " + e1.toString());
        } catch (URISyntaxException e1) {
            fail();
        }
        // client should be owner of only one component
        ClientInfo[] ci = manager.getClientInfo(info.getHandle(), new int[] { info.getHandle() }, null);
        assertNotNull(ci);
        assertEquals(1, ci.length);
        // only mount 1
        assertEquals(1, ci[0].getComponents().size());
        // test failed activation (construct failure)
        URI mount3 = null;
        try {
            mount3 = new URI("MOUNT3");
            StatusHolder status = new StatusHolder();
            Component ref = manager.getComponent(info.getHandle(), mount3, true, status);
            fail();
        } catch (AcsJCannotGetComponentEx e) {
            System.out.println("This is OK: component not activated " + e.toString());
        } catch (Exception ex) {
            fail();
        }
        // test no activation w/ activated component
        try {
            StatusHolder status = new StatusHolder();
            Component ref = manager.getComponent(info.getHandle(), mount, false, status);
            assertTrue(ref != null);
            assertEquals(ComponentStatus.COMPONENT_ACTIVATED, status.getStatus());
        } catch (Exception ex) {
            fail();
        }
        // test failed destruction
        // test will be affected in client logout
        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();
        }
        try {
            Thread.sleep(STARTUP_COBS_SLEEP_TIME_MS);
        } catch (InterruptedException ie) {
        }
        // test activated Components
        // there should be only two Components activated (MOUNT1 and MOUNT4)
        infos = manager.getComponentInfo(info.getHandle(), new int[0], "*", "*", true);
        Arrays.sort(infos);
        assertEquals(2, infos.length);
        assertEquals(mount.toString(), infos[0].getName());
        // manager and client
        assertEquals(2, infos[0].getClients().size());
        assertTrue(infos[0].getClients().contains(info.getHandle()));
        assertTrue(infos[0].getClients().contains(HandleConstants.MANAGER_MASK));
        assertTrue(mount4.toString().equals(infos[1].getName()));
        // client
        assertEquals(1, infos[1].getClients().size());
        assertTrue(infos[1].getClients().contains(info.getHandle()));
        // test unavailable and startup
        manager.logout(containerInfo.getHandle());
        containerInfo = manager.login(container);
        try {
            Thread.sleep(STARTUP_COBS_SLEEP_TIME_MS);
        } catch (InterruptedException ie) {
        }
        // test activated Components after activation
        // there should be only two Components activated (MOUNT1 and MOUNT4)
        infos = manager.getComponentInfo(info.getHandle(), new int[0], "*", "*", true);
        Arrays.sort(infos);
        assertEquals(2, infos.length);
        assertEquals(mount.toString(), infos[0].getName());
        // manager and client
        assertEquals(2, infos[0].getClients().size());
        assertTrue(infos[0].getClients().contains(info.getHandle()));
        assertTrue(infos[0].getClients().contains(HandleConstants.MANAGER_MASK));
        assertTrue(mount4.toString().equals(infos[1].getName()));
        // client
        assertEquals(1, infos[1].getClients().size());
        assertTrue(infos[1].getClients().contains(info.getHandle()));
        // client logout
        manager.logout(info.getHandle());
        client = new TestAdministrator(administratorName);
        info = manager.login(client);
        assertTrue(info.getHandle() != 0);
        try {
            Thread.sleep(SLEEP_TIME_MS);
        } catch (InterruptedException ie) {
        }
        // there should be only one component activated (MOUNT1)
        infos = manager.getComponentInfo(info.getHandle(), new int[0], "*", "*", true);
        assertEquals(1, infos.length);
        try {
            Thread.sleep(SLEEP_TIME_MS);
        } catch (InterruptedException ie) {
        }
        manager.logout(containerInfo.getHandle());
        try {
            Thread.sleep(SLEEP_TIME_MS);
        } catch (InterruptedException ie) {
        }
        // there should be no components activated
        infos = manager.getComponentInfo(info.getHandle(), new int[0], "*", "*", true);
        assertEquals(0, infos.length);
        //
        // test wrong Container-Component ImplLang
        //
        TestContainer pycontainer = new TestContainer("PyContainer", ClientType.CONTAINER, ImplLang.py, false);
        Map pysupportedComponents = new HashMap();
        Component cppOnPy = new TestComponent("CPP_ON_PY");
        pysupportedComponents.put("CPP_ON_PY", cppOnPy);
        pycontainer.setSupportedComponents(pysupportedComponents);
        manager.login(pycontainer);
        try {
            Thread.sleep(STARTUP_COBS_SLEEP_TIME_MS);
        } catch (InterruptedException ie) {
        }
        try {
            StatusHolder status = new StatusHolder();
            URI cppOnPyURI = new URI("CPP_ON_PY");
            manager.getComponent(info.getHandle(), cppOnPyURI, true, status);
            fail();
        } catch (AcsJCannotGetComponentEx e1) {
            System.out.println("This is OK: " + e1.toString());
        } catch (URISyntaxException e1) {
            fail();
        }
        try {
            manager.getDynamicComponent(info.getHandle(), new ComponentSpec("CPP_ON_PY", ComponentSpec.COMPSPEC_ANY, ComponentSpec.COMPSPEC_ANY, ComponentSpec.COMPSPEC_ANY), false);
            fail();
        } catch (AcsJCannotGetComponentEx e1) {
            System.out.println("This is OK: " + e1.toString());
        } catch (AcsJComponentSpecIncompatibleWithActiveComponentEx e1) {
            fail();
        } catch (AcsJIncompleteComponentSpecEx ex) {
            fail();
        } catch (AcsJInvalidComponentSpecEx ex) {
            fail();
        }
        // client logout
        manager.logout(info.getHandle());
    } catch (AcsJNoPermissionEx e) {
        fail("No permission");
    }
}
Also used : HashMap(java.util.HashMap) AcsJComponentSpecIncompatibleWithActiveComponentEx(alma.maciErrType.wrappers.AcsJComponentSpecIncompatibleWithActiveComponentEx) URISyntaxException(java.net.URISyntaxException) ComponentSpec(com.cosylab.acs.maci.ComponentSpec) URI(java.net.URI) AcsJCannotGetComponentEx(alma.maciErrType.wrappers.AcsJCannotGetComponentEx) 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) AcsJIncompleteComponentSpecEx(alma.maciErrType.wrappers.AcsJIncompleteComponentSpecEx) AcsJInvalidComponentSpecEx(alma.maciErrType.wrappers.AcsJInvalidComponentSpecEx) 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 3 with AcsJComponentSpecIncompatibleWithActiveComponentEx

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

the class ManagerProxyImpl method get_collocated_component.

/**
	 * Activation of an co-deployed 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.
	 * @param	target_component	target co-deployed component.
	 * @return	<code>ComponentInfo</code> of requested co-deployed component.
	 */
public ComponentInfo get_collocated_component(int id, si.ijs.maci.ComponentSpec c, boolean mark_as_default, String target_component) 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);
			*/
        URI targetComponentURI = null;
        if (target_component != null)
            targetComponentURI = CURLHelper.createURI(target_component);
        /// @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.getCollocatedComponent(id, componentSpec, mark_as_default, targetComponentURI);
        // 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);
        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) {
        // 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) URISyntaxException(java.net.URISyntaxException) ComponentSpec(com.cosylab.acs.maci.ComponentSpec) URI(java.net.URI) AcsJCannotGetComponentEx(alma.maciErrType.wrappers.AcsJCannotGetComponentEx) BadParametersException(com.cosylab.acs.maci.BadParametersException) AcsJIncompleteComponentSpecEx(alma.maciErrType.wrappers.AcsJIncompleteComponentSpecEx) 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)

Example 4 with AcsJComponentSpecIncompatibleWithActiveComponentEx

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

the class ManagerImpl method internalRequestComponent.

/**
	 * Internal method for requesting components.
	 * @param	requestor	requestor of the component.
	 * @param	curl	curl of the component to be requested.
	 * @param	status	status of the component.
	 * @param	activate	<code>true</code> if component has to be activated
	 * @return	component		requested component.
	 */
private Component internalRequestComponent(int requestor, URI curl, StatusHolder status, boolean activate) throws AcsJCannotGetComponentEx {
    // extract unique name
    String name = extractName(curl);
    try {
        checkCyclicDependency(requestor, name);
    } catch (AcsJCyclicDependencyDetectedEx e) {
        AcsJCannotGetComponentEx cgce = new AcsJCannotGetComponentEx(e);
        cgce.setCURL(name);
        throw cgce;
    }
    // try to acquire lock
    long lockTimeoutMillis = getLockTimeout();
    String lockNotAcquiredCause = acquireSynchronizationObject(name, lockTimeoutMillis, "request component " + name);
    if (lockNotAcquiredCause == null) {
        boolean releaseRWLock = true;
        try {
            // try to acquire activation readers lock first
            // NOTE: the locks are NOT reentrant
            activationPendingRWLock.readLock().lock();
            // Let AcsJCannotGetComponentEx fly up
            ComponentInfo componentInfo = null;
            try {
                componentInfo = internalNoSyncRequestComponent(requestor, name, null, null, null, RELEASE_TIME_UNDEFINED, status, activate);
            } catch (AcsJComponentSpecIncompatibleWithActiveComponentEx ciwace) {
                status.setStatus(ComponentStatus.COMPONENT_NOT_ACTIVATED);
                AcsJCannotGetComponentEx cgce = new AcsJCannotGetComponentEx(ciwace);
                cgce.setCURL(name);
                throw cgce;
            }
            if (componentInfo != null) {
                return componentInfo.getComponent();
            } else {
                return null;
            }
        } finally {
            if (releaseRWLock) {
                activationPendingRWLock.readLock().unlock();
            }
            releaseSynchronizationObject(name);
        }
    } else {
        String msg = "Failed to obtain synchronization lock for component '" + name + "' within '" + lockTimeoutMillis + "' ms, possible deadlock; locked to '" + lockNotAcquiredCause + "'.";
        logger.fine(msg);
        NoResourcesException nre = new NoResourcesException(msg);
        throw nre;
    }
}
Also used : NoResourcesException(com.cosylab.acs.maci.NoResourcesException) AcsJComponentSpecIncompatibleWithActiveComponentEx(alma.maciErrType.wrappers.AcsJComponentSpecIncompatibleWithActiveComponentEx) AcsJCyclicDependencyDetectedEx(alma.jmanagerErrType.wrappers.AcsJCyclicDependencyDetectedEx) ComponentInfo(com.cosylab.acs.maci.ComponentInfo) AcsJCannotGetComponentEx(alma.maciErrType.wrappers.AcsJCannotGetComponentEx)

Example 5 with AcsJComponentSpecIncompatibleWithActiveComponentEx

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

the class ManagerImpl method internalNoSyncRequestComponent.

/**
	 * Internal method for requesting components (non sync).
	 * @param	requestor		requestor of the component.
	 * @param	name			name of component to be requested, non-<code>null</code>.
	 * @param	type			type of component to be requested; if <code>null</code> CDB will be queried.
	 * @param	code			code of component to be requested; if <code>null</code> CDB will be queried.
	 * @param	containerName	container name of component to be requested; if <code>null</code> CDB will be queried.
	 * @param	status			returned completion status of the request.
	 * @param	activate		<code>true</code> if component has to be activated
	 * @return	componentInfo	<code>ComponentInfo</code> of requested component.
	 */
private ComponentInfo internalNoSyncRequestComponent(int requestor, String name, String type, String code, String containerName, int keepAliveTime, StatusHolder status, boolean activate) throws AcsJCannotGetComponentEx, AcsJComponentSpecIncompatibleWithActiveComponentEx {
    AcsJCannotGetComponentEx bcex = null;
    if (name == null) {
        bcex = new AcsJCannotGetComponentEx();
        bcex.setReason("Cannot activate component with NULL name.");
        throw bcex;
    }
    if (status == null) {
        bcex = new AcsJCannotGetComponentEx();
        bcex.setReason("Component " + name + " has NULL status.");
        throw bcex;
    }
    boolean isOtherDomainComponent = name.startsWith(CURL_URI_SCHEMA);
    boolean isDynamicComponent = isOtherDomainComponent ? false : (type != null || code != null || containerName != null);
    //
    // check if component is already activated
    //
    int h;
    // if true, component with handle h will be reactivated
    boolean reactivate = false;
    ComponentInfo componentInfo = null;
    componentsLock.lock();
    try {
        h = components.first();
        while (h != 0) {
            componentInfo = (ComponentInfo) components.get(h);
            if (componentInfo.getName().equals(name)) {
                // check if component is unavailable
                synchronized (unavailableComponents) {
                    if (unavailableComponents.containsKey(name)) {
                        // try to reactivate, possible component reallocation
                        reactivate = true;
                    }
                }
                // check for consistency
                ContainerInfo containerInfo = getContainerInfo(componentInfo.getContainer());
                if ((type != null && !componentInfo.getType().equals(type)) || (code != null && componentInfo.getCode() != null && !componentInfo.getCode().equals(code)) || (!reactivate && containerInfo != null && containerName != null && !containerInfo.getName().equals(containerName))) {
                    AcsJComponentSpecIncompatibleWithActiveComponentEx ciwace = new AcsJComponentSpecIncompatibleWithActiveComponentEx();
                    ciwace.setCURL(componentInfo.getName());
                    ciwace.setComponentType(componentInfo.getType());
                    ciwace.setComponentCode(componentInfo.getCode() != null ? componentInfo.getCode() : "<unknown>");
                    ciwace.setContainerName(containerInfo != null ? containerInfo.getName() : "<none>");
                    throw ciwace;
                }
                if (activate) {
                    // bail out and reactivate
                    if (reactivate)
                        break;
                    // add client/component as an owner (if requestor is not 'reactivation')
                    if (requestor != 0) {
                        // !!! ACID
                        if (!componentInfo.getClients().contains(requestor))
                            executeCommand(new ComponentCommandClientAdd(componentInfo.getHandle() & HANDLE_MASK, requestor));
                    //componentInfo.getClients().add(requestor);
                    }
                    // add component to client component list (if requestor is not manager or 'reactivation')
                    if (requestor != this.getHandle() && requestor != 0)
                        addComponentOwner(componentInfo.getHandle(), requestor);
                    // inform administrators about component request
                    notifyComponentRequested(new int[] { requestor }, new int[] { componentInfo.getHandle() }, System.currentTimeMillis());
                    // on complete system shutdown sort will be done anyway
                    if ((requestor & TYPE_MASK) == COMPONENT_MASK) {
                        ComponentInfo requestorComponentInfo = getComponentInfo(requestor);
                        if (requestorComponentInfo != null && requestorComponentInfo.getContainerName() != null && requestorComponentInfo.getContainerName().equals(componentInfo.getContainerName()))
                            topologySortManager.notifyTopologyChange(componentInfo.getContainer());
                    }
                    // return info
                    status.setStatus(ComponentStatus.COMPONENT_ACTIVATED);
                    return componentInfo;
                } else {
                    if (reactivate)
                        status.setStatus(ComponentStatus.COMPONENT_NOT_ACTIVATED);
                    else
                        status.setStatus(ComponentStatus.COMPONENT_ACTIVATED);
                    return componentInfo;
                }
            }
            h = components.next(h);
        }
    } finally {
        componentsLock.unlock();
    }
    // and do not touch CDB
    if (reactivate && componentInfo.isDynamic()) {
        if (componentInfo.getType() == null || componentInfo.getCode() == null || componentInfo.getDynamicContainerName() == null) {
            // failed
            bcex = new AcsJCannotGetComponentEx();
            bcex.setReason("Failed to reactivate dynamic component '" + componentInfo + "'.");
            status.setStatus(ComponentStatus.COMPONENT_DOES_NO_EXIST);
            throw bcex;
        } else {
            // reread info
            type = componentInfo.getType();
            code = componentInfo.getCode();
            containerName = componentInfo.getDynamicContainerName();
            keepAliveTime = componentInfo.getKeepAliveTime();
        }
    } else // is CDB lookup needed
    if (!isOtherDomainComponent && (type == null || code == null || containerName == null)) {
        //
        // read component info from CDB / remote directory lookup
        //
        DAOProxy dao = getComponentsDAOProxy();
        if (dao == null || readStringCharacteristics(dao, name, true) == null) {
            // component with this name does not exists,
            // make a remote directory lookup
            Object ref = lookup(name, null);
            if (ref != null) {
                // found
                status.setStatus(ComponentStatus.COMPONENT_ACTIVATED);
                return new ComponentInfo(0, name, null, null, new ServiceComponent(ref));
            } else {
                // not found
                bcex = new AcsJCannotGetComponentEx();
                bcex.setReason("Component " + name + " not found in CDB.");
                status.setStatus(ComponentStatus.COMPONENT_DOES_NO_EXIST);
                throw bcex;
            }
        }
        if (code == null) {
            code = readStringCharacteristics(dao, name + "/Code");
            if (code == null) {
                bcex = new AcsJCannotGetComponentEx();
                bcex.setReason("Misconfigured CDB, there is no code of component '" + name + "' defined.");
                status.setStatus(ComponentStatus.COMPONENT_DOES_NO_EXIST);
                throw bcex;
            }
        }
        if (type == null) {
            type = readStringCharacteristics(dao, name + "/Type");
            if (type == null) {
                bcex = new AcsJCannotGetComponentEx();
                bcex.setReason("Misconfigured CDB, there is no type of component '" + name + "' defined.");
                status.setStatus(ComponentStatus.COMPONENT_DOES_NO_EXIST);
                throw bcex;
            }
        }
        if (containerName == null) {
            containerName = readStringCharacteristics(dao, name + "/Container");
            if (containerName == null) {
                bcex = new AcsJCannotGetComponentEx();
                bcex.setReason("Misconfigured CDB, there is no container of component '" + name + "' defined.");
                status.setStatus(ComponentStatus.COMPONENT_DOES_NO_EXIST);
                throw bcex;
            }
        }
        if (keepAliveTime == RELEASE_TIME_UNDEFINED) {
            // defaults to 0 == RELEASE_IMMEDIATELY
            keepAliveTime = readLongCharacteristics(dao, name + "/KeepAliveTime", RELEASE_IMMEDIATELY, true);
        }
    }
    // we have keepAlive missing, try to get it
    if (keepAliveTime == RELEASE_TIME_UNDEFINED) {
        DAOProxy dao = getComponentsDAOProxy();
        if (dao != null) {
            // defaults to 0 == RELEASE_IMMEDIATELY
            keepAliveTime = readLongCharacteristics(dao, name + "/KeepAliveTime", RELEASE_IMMEDIATELY, true);
        } else {
            // this is a case where all data for dynamic component is specified and there is not entry in CDB
            keepAliveTime = RELEASE_IMMEDIATELY;
        }
    }
    // read impl. language.
    DAOProxy dao = getComponentsDAOProxy();
    String componentImplLang = null;
    if (dao != null) {
        // silent read
        componentImplLang = readStringCharacteristics(dao, name + "/ImplLang", true);
    }
    // if requestor did not request activation we are finished
    if (!activate) {
        status.setStatus(ComponentStatus.COMPONENT_NOT_ACTIVATED);
        return null;
    }
    /****************** component activation ******************/
    //
    // get container/remote manager
    //
    Container container = null;
    ContainerInfo containerInfo = null;
    Manager remoteManager = null;
    if (isOtherDomainComponent) {
        // @todo MF do the login?
        try {
            String domainName = CURLHelper.createURI(name).getAuthority();
            remoteManager = getManagerForDomain(domainName);
            if (remoteManager == null) {
                bcex = new AcsJCannotGetComponentEx();
                bcex.setReason("Failed to obtain manager for domain '" + domainName + "'.");
                throw bcex;
            }
        } catch (Throwable th) {
            bcex = new AcsJCannotGetComponentEx(th);
            bcex.setReason("Failed to obtain non-local manager required by component '" + name + "'.'");
            status.setStatus(ComponentStatus.COMPONENT_NOT_ACTIVATED);
            throw bcex;
        }
    } else {
        // search for container by its name
        containerInfo = getContainerInfo(containerName);
        // try to start-up container
        if (containerInfo == null)
            containerInfo = startUpContainer(containerName);
        // check state and get container
        if (containerInfo != null) {
            checkContainerShutdownState(containerInfo);
            container = containerInfo.getContainer();
        }
        // required container is not logged in
        if (container == null) {
            bcex = new AcsJCannotGetComponentEx();
            bcex.setReason("Container '" + containerName + "' required by component '" + name + "' is not logged in.");
            status.setStatus(ComponentStatus.COMPONENT_NOT_ACTIVATED);
            throw bcex;
        }
    }
    // check container vs component ImplLang
    ImplLang containerImplLang = containerInfo.getImplLang();
    if (containerImplLang != null && containerImplLang != ImplLang.not_specified) {
        if (componentImplLang != null && ImplLang.fromString(componentImplLang) != containerImplLang) {
            AcsJCannotGetComponentEx af = new AcsJCannotGetComponentEx();
            af.setReason("Component and container implementation language do not match (" + componentImplLang + " != " + containerImplLang.name() + ")");
            throw af;
        }
    }
    //
    // get handle
    //
    // obtain handle
    componentsLock.lock();
    try {
        // only preallocate (if necessary)
        if (!reactivate) {
            // !!! ACID 2
            Integer objHandle = (Integer) executeCommand(new ComponentCommandPreallocate());
            h = (objHandle == null) ? 0 : objHandle.intValue();
        //h = components.preallocate();
        }
        // failed to obtain handle
        if (h == 0) {
            AcsJCannotGetComponentEx af = new AcsJCannotGetComponentEx();
            af.setReason("Preallocation of new handle failed, too many registered components.");
            throw af;
        }
        // create temporary ComponentInfo - to allow hierarchical components
        if (!reactivate) {
            ComponentInfo data = new ComponentInfo(h | COMPONENT_MASK, name, type, code, null);
            data.setKeepAliveTime(keepAliveTime);
            // !!! ACID
            executeCommand(new ComponentCommandSet(h, data));
            // add to pending activation list
            synchronized (pendingActivations) {
                pendingActivations.put(name, data);
            }
            // add component to client component list to allow dependency checks
            if ((requestor & TYPE_MASK) == COMPONENT_MASK)
                addComponentOwner(data.getHandle(), requestor);
        }
    } finally {
        componentsLock.unlock();
    }
    //
    // invoke get_component
    //
    componentInfo = null;
    long executionId = 0;
    long activationTime = 0;
    boolean timeoutError = false;
    if (isOtherDomainComponent) {
        try {
            URI curlName = CURLHelper.createURI(name);
            StatusHolder statusHolder = new StatusHolder();
            // @todo MF tmp (handle)
            remoteManager.getComponent(INTERDOMAIN_MANAGER_HANDLE, curlName, true, statusHolder);
            activationTime = System.currentTimeMillis();
            if (statusHolder.getStatus() == ComponentStatus.COMPONENT_ACTIVATED) {
                // local name to be used
                String localName = curlName.getPath();
                if (localName.charAt(0) == '/')
                    localName = localName.substring(1);
                /// @TODO MF tmp (handle)
                ComponentInfo[] infos = remoteManager.getComponentInfo(INTERDOMAIN_MANAGER_HANDLE, new int[0], localName, "*", true);
                if (infos != null && infos.length == 1) {
                    componentInfo = infos[0];
                    // fix container name
                    componentInfo.setContainerName(CURL_URI_SCHEMA + curlName.getAuthority() + "/" + componentInfo.getContainerName());
                }
            //else
            //    throw new RemoteException("Failed to obtain component info for '"+name+"' from remote manager.");
            }
        //else
        //    throw new RemoteException("Failed to obtain component '"+name+"' from remote manager, status: " + statusHolder.getStatus() + ".");
        } catch (Throwable ex) {
            bcex = new AcsJCannotGetComponentEx(ex);
            bcex.setReason("Failed to obtain component '" + name + "' from remote manager.");
            timeoutError = (ex instanceof TimeoutRemoteException);
        }
    } else {
        //
        // invoke get_component on container
        //
        // log info
        String handleReadable = HandleHelper.toString(h | COMPONENT_MASK);
        logger.log(Level.INFO, "Activating component '" + name + "' (" + handleReadable + ") on container '" + containerInfo.getName() + "'.");
        boolean callSyncActivate = System.getProperties().containsKey(NAME_SYNC_ACTIVATE);
        if (callSyncActivate) {
            // sync
            try {
                executionId = generateExecutionId();
                activationTime = System.currentTimeMillis();
                componentInfo = container.activate_component(h | COMPONENT_MASK, executionId, name, code, type);
            } catch (Throwable ex) {
                bcex = new AcsJCannotGetComponentEx(ex);
                bcex.setReason("Failed to activate component '" + name + "' on container '" + containerName + "'.");
                timeoutError = (ex instanceof TimeoutRemoteException);
            }
        } else {
            // async
            try {
                executionId = generateExecutionId();
                activationTime = System.currentTimeMillis();
                ComponentInfoCompletionCallbackImpl callback = new ComponentInfoCompletionCallbackImpl(requestor, name, type, code, containerName, keepAliveTime, status, isOtherDomainComponent, isDynamicComponent, h, reactivate, container, containerInfo, executionId, activationTime);
                addPendingContainerAsyncRequest(containerName, callback);
                try {
                    container.activate_component_async(h | COMPONENT_MASK, executionId, name, code, type, callback);
                } catch (Throwable t) {
                    // failed call, remove async request from the list
                    removePendingContainerAsyncRequest(containerName, callback);
                    throw t;
                }
                logger.log(AcsLogLevel.DELOUSE, "Asynchronous activation of component '" + name + "' (" + handleReadable + ") is running on container '" + containerInfo.getName() + "'.");
                ComponentInfo ret;
                try {
                    ret = callback.waitUntilActivated(getLockTimeout());
                } catch (Throwable t) {
                    // failed call (most likely timeout), remove async request from the list
                    removePendingContainerAsyncRequest(containerName, callback);
                    throw t;
                }
                logger.log(AcsLogLevel.DELOUSE, "Asynchronous activation of component '" + name + "' (" + handleReadable + ") has finished on container '" + containerInfo.getName() + "'.");
                return ret;
            } catch (Throwable ex) {
                bcex = new AcsJCannotGetComponentEx(ex);
                bcex.setReason("Failed to activate component '" + name + "' on container '" + containerName + "'.");
                throw bcex;
            }
        }
    }
    // call this immediately if bcex != null or sync call
    return internalNoSyncRequestComponentPhase2(requestor, name, type, code, containerName, keepAliveTime, status, bcex, isOtherDomainComponent, isDynamicComponent, h, reactivate, componentInfo, container, containerInfo, executionId, activationTime, timeoutError);
}
Also used : AcsJComponentSpecIncompatibleWithActiveComponentEx(alma.maciErrType.wrappers.AcsJComponentSpecIncompatibleWithActiveComponentEx) ComponentCommandClientAdd(com.cosylab.acs.maci.manager.recovery.ComponentCommandClientAdd) DAOProxy(com.cosylab.cdb.client.DAOProxy) Manager(com.cosylab.acs.maci.Manager) URI(java.net.URI) AcsJCannotGetComponentEx(alma.maciErrType.wrappers.AcsJCannotGetComponentEx) StatusHolder(com.cosylab.acs.maci.StatusHolder) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Container(com.cosylab.acs.maci.Container) ComponentCommandSet(com.cosylab.acs.maci.manager.recovery.ComponentCommandSet) ContainerInfo(com.cosylab.acs.maci.ContainerInfo) TimeoutRemoteException(com.cosylab.acs.maci.TimeoutRemoteException) ComponentInfo(com.cosylab.acs.maci.ComponentInfo) ImplLang(com.cosylab.acs.maci.ImplLang) ComponentCommandPreallocate(com.cosylab.acs.maci.manager.recovery.ComponentCommandPreallocate)

Aggregations

AcsJCannotGetComponentEx (alma.maciErrType.wrappers.AcsJCannotGetComponentEx)7 AcsJComponentSpecIncompatibleWithActiveComponentEx (alma.maciErrType.wrappers.AcsJComponentSpecIncompatibleWithActiveComponentEx)7 NoResourcesException (com.cosylab.acs.maci.NoResourcesException)6 AcsJIncompleteComponentSpecEx (alma.maciErrType.wrappers.AcsJIncompleteComponentSpecEx)5 AcsJInvalidComponentSpecEx (alma.maciErrType.wrappers.AcsJInvalidComponentSpecEx)5 AcsJNoPermissionEx (alma.maciErrType.wrappers.AcsJNoPermissionEx)5 BadParametersException (com.cosylab.acs.maci.BadParametersException)5 ComponentInfo (com.cosylab.acs.maci.ComponentInfo)5 ComponentSpec (com.cosylab.acs.maci.ComponentSpec)5 URI (java.net.URI)5 URISyntaxException (java.net.URISyntaxException)4 ClientInfo (com.cosylab.acs.maci.ClientInfo)3 NoDefaultComponentException (com.cosylab.acs.maci.NoDefaultComponentException)3 RemoteException (com.cosylab.acs.maci.RemoteException)3 StatusHolder (com.cosylab.acs.maci.StatusHolder)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Component (com.cosylab.acs.maci.Component)2 CoreException (com.cosylab.acs.maci.CoreException)2 BAD_PARAM (org.omg.CORBA.BAD_PARAM)2