Search in sources :

Example 1 with AcsJIncompleteComponentSpecEx

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

the class ManagerImpl method internalRequestDynamicComponent.

/**
	 * Internal method for requesting dynamic components.
	 *
	 * Resolution:
	 * <code>component_name</code> and <code>component_type</code> can be considered as "determinator" fields,
	 * they play important role in search algorithm.
	 * <code>component_code</code> and <code>container_name</code> can be considered as "override" fields,
	 * they only help to find closest match.
	 * Rule: unspecified <code>component_name</code> case implies that a new component will be activated.
	 * Search points (8,4,2,1): <code>component_name</code>, <code>component_type</code>, <code>component_code</code>, <code>container_name</code>.
	 * <pre>
	 *
	 *  name | type | search criteria
	 * -----------------------------
	 *    *  |   *  | throw IncompleteComponentSpecException
	 *    X  |   *  | (equals, wildcard)
	 *    *  |   X  | (equals, equals) w/ name generation
	 *    X  |   X  | (wildcard, equals) - overriding type is not allowed
	 *
	 * </pre>
	 * 'name' can be also something like "ANT1/*" (ends with) and is threated just like "*".
	 *
	 * @param	requestor	requestor of the component.
	 * @param	componentSpec	requested component <code>ComponentSpec</code>
	 * @return	componentInfo	<code>ComponentInfo</code> of requested dynamic component.
	 */
private ComponentInfo internalRequestDynamicComponent(int requestor, ComponentSpec componentSpec) throws AcsJCannotGetComponentEx, AcsJSyncLockFailedEx, AcsJNoPermissionEx, AcsJIncompleteComponentSpecEx, AcsJInvalidComponentSpecEx, AcsJComponentSpecIncompatibleWithActiveComponentEx {
    boolean unspecifiedName = componentSpec.getName().endsWith(ComponentSpec.COMPSPEC_ANY);
    boolean unspecifiedType = componentSpec.getType().equals(ComponentSpec.COMPSPEC_ANY);
    //   *  |   *  | throw IncompleteComponentSpecException
    if (unspecifiedName && unspecifiedType) {
        AcsJInvalidComponentSpecEx ex = new AcsJInvalidComponentSpecEx();
        ex.setReason("'name' and 'type' cannot be both '" + ComponentSpec.COMPSPEC_ANY + "'.");
        throw ex;
    } else // all fields are fully specified, no search needed
    if (!unspecifiedName && !unspecifiedType && !componentSpec.getCode().equals(ComponentSpec.COMPSPEC_ANY) && !componentSpec.getContainer().equals(ComponentSpec.COMPSPEC_ANY)) {
        StatusHolder statusHolder = new StatusHolder();
        // We let exceptions occurring here fly up
        return internalRequestComponent(requestor, componentSpec.getName(), componentSpec.getType(), componentSpec.getCode(), componentSpec.getContainer(), RELEASE_TIME_UNDEFINED, statusHolder, true);
    }
    //
    // prepare search conditions
    //
    final String[] fieldNames = new String[] { "Name", "Type", "Code", "Container" };
    final String[] requiredValues = new String[] { componentSpec.getName(), componentSpec.getType(), componentSpec.getCode(), componentSpec.getContainer() };
    final int[] equalityPoints = new int[] { 8, 4, /* never used */
    2, 1 };
    boolean[] equalityRequired = null;
    boolean allowNameGeneration = false;
    boolean prohibitSearch = false;
    //   X  |   X  | (wildcard, equals)
    if (!unspecifiedName && !unspecifiedType) {
        equalityRequired = new boolean[] { false, true, false, false };
        allowNameGeneration = true;
    } else //   X  |   *  | (equals, wildcard)
    if (!unspecifiedName && unspecifiedType) {
        equalityRequired = new boolean[] { true, false, false, false };
    } else //  prefix* |   X  | (equals, equals) w/ name generation
    if (unspecifiedName && !unspecifiedType) {
        equalityRequired = new boolean[] { true, true, false, false };
        // no search needed case...
        if (!componentSpec.getCode().equals(ComponentSpec.COMPSPEC_ANY) && !componentSpec.getContainer().equals(ComponentSpec.COMPSPEC_ANY))
            prohibitSearch = true;
        allowNameGeneration = true;
    }
    // search
    IntHolder keepAliveTimeHolder = new IntHolder(RELEASE_TIME_UNDEFINED);
    String[] result = prohibitSearch ? null : searchDynamicComponent(fieldNames, requiredValues, equalityRequired, equalityPoints, keepAliveTimeHolder);
    // none found
    if (result == null) {
        boolean failed = true;
        // only name or container not speficied...
        if ((allowNameGeneration || !unspecifiedName) && !unspecifiedType && !componentSpec.getCode().equals(ComponentSpec.COMPSPEC_ANY)) {
            // container name already specified, i.e. name is *, which is OK
            if (!componentSpec.getContainer().equals(ComponentSpec.COMPSPEC_ANY)) {
                result = new String[] { componentSpec.getName(), componentSpec.getType(), componentSpec.getCode(), componentSpec.getContainer() };
                failed = false;
            } else // container name is *, use load balancing if available
            if (loadBalancingStrategy != null) {
                String containerName = loadBalancingStrategy.selectContainer(getClientInfo(requestor), getContainersInfo());
                if (containerName != null) {
                    result = new String[] { componentSpec.getName(), componentSpec.getType(), componentSpec.getCode(), containerName };
                    failed = false;
                }
            }
        }
        if (failed) {
            AcsJInvalidComponentSpecEx ex = new AcsJInvalidComponentSpecEx();
            ex.setReason("Requested ComponentSpec does not match any entry in the CDB.");
            throw ex;
        }
    }
    // override...
    for (int i = 0; i < result.length; i++) if (!requiredValues[i].equals(ComponentSpec.COMPSPEC_ANY))
        result[i] = requiredValues[i];
    // check completeness
    int i = 0;
    if (allowNameGeneration)
        i++;
    for (; i < result.length; i++) if (result[i].equals(ComponentSpec.COMPSPEC_ANY)) {
        // if load balancing strategy is registered, use it to determine container name
        if (fieldNames[i].equals("Container") && loadBalancingStrategy != null) {
            String containerName = loadBalancingStrategy.selectContainer(getClientInfo(requestor), getContainersInfo());
            if (containerName != null) {
                result[i] = containerName;
                continue;
            }
        }
        AcsJIncompleteComponentSpecEx ex = new AcsJIncompleteComponentSpecEx();
        ex.setReason("'" + fieldNames[i] + "' equals '" + ComponentSpec.COMPSPEC_ANY + "'.");
        throw ex;
    }
    // generate name if necessary
    if (allowNameGeneration && result[0].endsWith(ComponentSpec.COMPSPEC_ANY)) {
        synchronized (this) {
            /// @todo not perfect
            if (result[0].equals(ComponentSpec.COMPSPEC_ANY))
                result[0] = result[1] + "_" + System.currentTimeMillis();
            else
                // ends with case
                result[0] = result[0].substring(0, result[0].length() - 1) + "_" + System.currentTimeMillis();
            // flatten hierarchical name (remove IDL separators)
            if (result[0].indexOf('/') >= 0)
                result[0] = result[0].replaceAll("/", "_");
        }
    }
    StatusHolder statusHolder = new StatusHolder();
    // Same exceptions are let flying up
    return internalRequestComponent(requestor, result[0], result[1], result[2], result[3], keepAliveTimeHolder.value, statusHolder, true);
}
Also used : AcsJInvalidComponentSpecEx(alma.maciErrType.wrappers.AcsJInvalidComponentSpecEx) IntHolder(org.omg.CORBA.IntHolder) StatusHolder(com.cosylab.acs.maci.StatusHolder) AcsJIncompleteComponentSpecEx(alma.maciErrType.wrappers.AcsJIncompleteComponentSpecEx)

Example 2 with AcsJIncompleteComponentSpecEx

use of alma.maciErrType.wrappers.AcsJIncompleteComponentSpecEx 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 3 with AcsJIncompleteComponentSpecEx

use of alma.maciErrType.wrappers.AcsJIncompleteComponentSpecEx 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 4 with AcsJIncompleteComponentSpecEx

use of alma.maciErrType.wrappers.AcsJIncompleteComponentSpecEx 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 5 with AcsJIncompleteComponentSpecEx

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

the class ManagerImpl method getCollocatedComponent.

/**
	 * @see com.cosylab.acs.maci.Manager#getCollocatedComponent(int, com.cosylab.acs.maci.ComponentSpec, boolean, URI)
	 */
/// @todo MF not supported
public ComponentInfo getCollocatedComponent(int id, ComponentSpec componentSpec, boolean markAsDefault, URI targetComponentURI) throws AcsJCannotGetComponentEx, AcsJNoPermissionEx, AcsJIncompleteComponentSpecEx, AcsJInvalidComponentSpecEx, AcsJComponentSpecIncompatibleWithActiveComponentEx {
    try {
        // check if null
        if (componentSpec == null) {
            AcsJNullPointerEx ex = new AcsJNullPointerEx();
            ex.setVariable("componentSpec");
            throw ex;
        }
        // check componentSpec components are null
        if (componentSpec.getName() == null) {
            AcsJNullPointerEx ex = new AcsJNullPointerEx();
            ex.setVariable("componentSpec.Name");
            throw ex;
        }
        if (componentSpec.getType() == null) {
            AcsJNullPointerEx ex = new AcsJNullPointerEx();
            ex.setVariable("componentSpec.Type");
            throw ex;
        }
        if (componentSpec.getCode() == null) {
            AcsJNullPointerEx ex = new AcsJNullPointerEx();
            ex.setVariable("componentSpec.Code");
            throw ex;
        }
        if (componentSpec.getContainer() == null) {
            AcsJNullPointerEx ex = new AcsJNullPointerEx();
            ex.setVariable("componentSpec.Container");
            throw ex;
        }
        // check for empty componentSpec.name
        if (componentSpec.getName().length() == 0) {
            AcsJBadParameterEx ex = new AcsJBadParameterEx();
            ex.setParameter("componentSpec.Name");
            ex.setParameterValue("EMPTY");
            ex.setReason("Non empty Component Name expected");
            throw ex;
        }
        // check if null
        if (targetComponentURI == null) {
            AcsJNullPointerEx ex = new AcsJNullPointerEx();
            ex.setVariable("targetComponentURI");
            throw ex;
        }
        if (!componentSpec.getContainer().equals(ComponentSpec.COMPSPEC_ANY)) {
            AcsJBadParameterEx ex = new AcsJBadParameterEx();
            ex.setParameter("componentSpec.Container");
            ex.setParameterValue(componentSpec.getContainer());
            ex.setReason("COMPSPEC_ANY expected");
            throw ex;
        }
    } catch (AcsJNullPointerEx e) {
        AcsJInvalidComponentSpecEx ex = new AcsJInvalidComponentSpecEx(e);
        throw ex;
    } catch (AcsJBadParameterEx e) {
        AcsJInvalidComponentSpecEx ex = new AcsJInvalidComponentSpecEx(e);
        throw ex;
    }
    // check handle and NONE permissions
    // Throws AcsJNoPermissionEx that is let flying up
    securityCheck(id, AccessRights.NONE);
    /****************************************************************/
    /// @todo temporary quick implementation (does not look in the CDB if component is not activated)
    String name = extractName(targetComponentURI);
    int h = 0;
    ComponentInfo targetComponentInfo = null;
    componentsLock.lock();
    try {
        h = components.first();
        while (h != 0) {
            ComponentInfo componentInfo = (ComponentInfo) components.get(h);
            if (componentInfo.getName().equals(name)) {
                targetComponentInfo = componentInfo;
                break;
            }
            h = components.next(h);
        }
    } finally {
        componentsLock.unlock();
    }
    // if not found, check the CDB
    if (targetComponentInfo == null) {
        DAOProxy componentsDAO = getComponentsDAOProxy();
        if (componentsDAO != null) {
            // read container name
            String containerName = readStringCharacteristics(componentsDAO, name + "/Container", true);
            if (containerName != null)
                componentSpec.setContainer(containerName);
        }
    } else
        componentSpec.setContainer(targetComponentInfo.getContainerName());
    // failed to detemine a target container
    if (componentSpec.getContainer().equals(ComponentSpec.COMPSPEC_ANY)) {
        AcsJIncompleteComponentSpecEx ex = new AcsJIncompleteComponentSpecEx();
        ex.setCURL(name);
        ex.setContainerName(componentSpec.getContainer());
        throw ex;
    }
    // request for component
    // same exceptions are let flying up.
    ComponentInfo componentInfo = null;
    try {
        componentInfo = internalRequestDynamicComponent(id, componentSpec);
    } catch (AcsJSyncLockFailedEx e) {
        AcsJCannotGetComponentEx ex = new AcsJCannotGetComponentEx();
        ex.setCURL(name);
        ex.setReason("Failed to get Synchronisation lock");
        throw ex;
    }
    // update default components table
    if (componentInfo != null && markAsDefault) {
        synchronized (defaultComponents) {
            // !!! ACID 3
            executeCommand(new DefaultComponentCommandPut(componentInfo.getType(), componentInfo));
        //defaultComponents.put(componentInfo.getType(), componentInfo.getName());
        }
        logger.log(Level.INFO, "'" + componentInfo.getName() + "' has been marked as a default component of type '" + componentInfo.getType() + "'.");
    }
    if (componentInfo == null) {
        AcsJCannotGetComponentEx ex = new AcsJCannotGetComponentEx();
        ex.setCURL(name);
        throw ex;
    }
    return componentInfo;
}
Also used : AcsJBadParameterEx(alma.ACSErrTypeCommon.wrappers.AcsJBadParameterEx) DefaultComponentCommandPut(com.cosylab.acs.maci.manager.recovery.DefaultComponentCommandPut) AcsJInvalidComponentSpecEx(alma.maciErrType.wrappers.AcsJInvalidComponentSpecEx) AcsJNullPointerEx(alma.ACSErrTypeCommon.wrappers.AcsJNullPointerEx) AcsJSyncLockFailedEx(alma.jmanagerErrType.wrappers.AcsJSyncLockFailedEx) ComponentInfo(com.cosylab.acs.maci.ComponentInfo) DAOProxy(com.cosylab.cdb.client.DAOProxy) AcsJCannotGetComponentEx(alma.maciErrType.wrappers.AcsJCannotGetComponentEx) AcsJIncompleteComponentSpecEx(alma.maciErrType.wrappers.AcsJIncompleteComponentSpecEx)

Aggregations

AcsJIncompleteComponentSpecEx (alma.maciErrType.wrappers.AcsJIncompleteComponentSpecEx)7 AcsJInvalidComponentSpecEx (alma.maciErrType.wrappers.AcsJInvalidComponentSpecEx)7 AcsJCannotGetComponentEx (alma.maciErrType.wrappers.AcsJCannotGetComponentEx)6 AcsJComponentSpecIncompatibleWithActiveComponentEx (alma.maciErrType.wrappers.AcsJComponentSpecIncompatibleWithActiveComponentEx)5 AcsJNoPermissionEx (alma.maciErrType.wrappers.AcsJNoPermissionEx)5 BadParametersException (com.cosylab.acs.maci.BadParametersException)5 ComponentSpec (com.cosylab.acs.maci.ComponentSpec)5 NoResourcesException (com.cosylab.acs.maci.NoResourcesException)5 ComponentInfo (com.cosylab.acs.maci.ComponentInfo)4 URI (java.net.URI)4 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 AcsJBadParameterEx (alma.ACSErrTypeCommon.wrappers.AcsJBadParameterEx)2 Component (com.cosylab.acs.maci.Component)2 CoreException (com.cosylab.acs.maci.CoreException)2