Search in sources :

Example 41 with ComponentInfo

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

the class ManagerImpl method getComponentNonSticky.

/**
	 * @see com.cosylab.acs.maci.Manager#getComponentNonSticky(int id, URI curl)
	 */
public Component getComponentNonSticky(int id, URI curl) throws AcsJCannotGetComponentEx, AcsJNoPermissionEx {
    // extract name
    String name = extractName(curl);
    // check if null
    try {
        checkCURL(curl);
    } catch (AcsJBadParameterEx e) {
        AcsJCannotGetComponentEx ex2 = new AcsJCannotGetComponentEx(e);
        ex2.setCURL(name);
        throw ex2;
    }
    /****************************************************************/
    // check handle and NONE permissions
    securityCheck(id, AccessRights.NONE);
    // log info
    String requestorName = getRequestorName(id);
    logger.log(Level.FINE, "'" + requestorName + "' requested non-sticky component '" + curl + "'.");
    Component component = null;
    componentsLock.lock();
    try {
        int h = components.first();
        while (h != 0) {
            ComponentInfo ci = (ComponentInfo) components.get(h);
            if (ci.getName().equals(name)) {
                component = ci.getComponent();
                break;
            }
            h = components.next(h);
        }
    } finally {
        componentsLock.unlock();
    }
    // log info
    if (component != null && component.getObject() != null)
        logger.log(Level.FINE, "Non-sticky component '" + curl + "' provided to '" + requestorName + "'.");
    else
        logger.log(Level.INFO, "Failed to provide non-sticky component '" + curl + "' to '" + requestorName + "'.");
    return component;
}
Also used : AcsJBadParameterEx(alma.ACSErrTypeCommon.wrappers.AcsJBadParameterEx) ComponentInfo(com.cosylab.acs.maci.ComponentInfo) Component(com.cosylab.acs.maci.Component) AcsJCannotGetComponentEx(alma.maciErrType.wrappers.AcsJCannotGetComponentEx)

Example 42 with ComponentInfo

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

the class ManagerImpl method securityCheck.

/**
	 * Performs security check on given handle and if check if owner has <code>rights</code> permissions granted.
	 *
	 * Validating means checking key part (KEY_MASK) of the handle.
	 *
	 * @param	id	handle to be checked.
	 * @param	rights	checks if owner of the handle has this permissions granted, can be 0.
	 * @throws	AcsJNoPermissionEx	thrown if handle is not valid or handle owner has not enough permissions
	 */
private void securityCheck(int id, int requiredRights) throws AcsJNoPermissionEx {
    try {
        // check if already shutdown
        if (id != this.getHandle() && shutdown.get()) {
            // already shutdown
            AcsJNoPermissionEx npe = new AcsJNoPermissionEx();
            npe.setID(HandleHelper.toString(id));
            npe.setReason("Manager in shutdown state.");
            throw npe;
        }
        // parse handle part
        int handle = id & HANDLE_MASK;
        int grantedRights = 0;
        boolean invalidHandle = true;
        switch(id & TYPE_MASK) {
            case CONTAINER_MASK:
                synchronized (containers) {
                    if (containers.isAllocated(handle)) {
                        ContainerInfo info = (ContainerInfo) containers.get(handle);
                        if (info.getHandle() == id)
                            invalidHandle = false;
                        grantedRights = CONTAINER_RIGHTS;
                    }
                }
                break;
            case CLIENT_MASK:
                synchronized (clients) {
                    if (clients.isAllocated(handle)) {
                        ClientInfo info = (ClientInfo) clients.get(handle);
                        if (info.getHandle() == id)
                            invalidHandle = false;
                        grantedRights = info.getAccessRights();
                    }
                }
                break;
            case ADMINISTRATOR_MASK:
                synchronized (administrators) {
                    if (administrators.isAllocated(handle)) {
                        ClientInfo info = (ClientInfo) administrators.get(handle);
                        if (info.getHandle() == id)
                            invalidHandle = false;
                        grantedRights = info.getAccessRights();
                    }
                }
                break;
            case COMPONENT_MASK:
                componentsLock.lock();
                try {
                    if (components.isAllocated(handle)) {
                        ComponentInfo info = (ComponentInfo) components.get(handle);
                        if (info != null && info.getHandle() == id)
                            invalidHandle = false;
                        grantedRights = AccessRights.REGISTER_COMPONENT;
                    }
                } finally {
                    componentsLock.unlock();
                }
                break;
            case MANAGER_MASK:
                invalidHandle = false;
                grantedRights = AccessRights.REGISTER_COMPONENT | AccessRights.SHUTDOWN_SYSTEM | AccessRights.INTROSPECT_MANAGER;
                break;
        }
        if (invalidHandle) {
            // NO_PERMISSION
            AcsJNoPermissionEx npe = new AcsJNoPermissionEx();
            npe.setID(HandleHelper.toString(id));
            HandleMonitorEntry hme = getHandleReleaseLog(id);
            if (hme != null) {
                final String timeISO = IsoDateFormat.formatDate(new Date(hme.timestamp));
                switch(hme.reason) {
                    case REMOVED:
                        npe.setReason("Invalid handle, handle was properly removed at " + timeISO + ".");
                        break;
                    case TIMEOUT:
                        npe.setReason("Invalid handle, handle was removed due to timeout at " + timeISO + ".");
                        break;
                    case DISAPPEARED:
                        npe.setReason("Invalid handle, handle was removed due to client/container/component disappearing at " + timeISO + ".");
                        break;
                }
            } else {
                if (enableHandleMonitoringDurationMins <= 0)
                    npe.setReason("Invalid handle, handle was never known.");
                else
                    npe.setReason("Invalid handle, handle is not known for the last " + enableHandleMonitoringDurationMins + " minutes.");
            }
            throw npe;
        }
        if ((grantedRights & requiredRights) != requiredRights) {
            // NO_PERMISSION
            AcsJNoPermissionEx npe = new AcsJNoPermissionEx();
            npe.setID(HandleHelper.toString(id));
            npe.setReason("Insufficient rights.");
            throw npe;
        }
    } catch (AcsJNoPermissionEx ex) {
        logger.log(AcsLogLevel.DELOUSE, "securityCheck fails with AcsJNoPermissionEx:", ex);
        throw ex;
    }
}
Also used : AcsJNoPermissionEx(alma.maciErrType.wrappers.AcsJNoPermissionEx) ContainerInfo(com.cosylab.acs.maci.ContainerInfo) ClientInfo(com.cosylab.acs.maci.ClientInfo) ComponentInfo(com.cosylab.acs.maci.ComponentInfo) Date(java.util.Date)

Example 43 with ComponentInfo

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

the class ManagerImpl method getComponentInfo.

/**
	 * Get component info. for specified id of <code>Component</code>.
	 *
	 * @param	id	handle of the component whose info. should be returned
	 * @param	returns	requested info, <code>null</code> if component with requested handle does not exits
	 */
public ComponentInfo getComponentInfo(int id) {
    // parse handle part
    int handle = id & HANDLE_MASK;
    // info to be returned
    ComponentInfo info = null;
    componentsLock.lock();
    try {
        if (components.isAllocated(handle))
            info = (ComponentInfo) components.get(handle);
    } finally {
        componentsLock.unlock();
    }
    return info;
}
Also used : ComponentInfo(com.cosylab.acs.maci.ComponentInfo)

Example 44 with ComponentInfo

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

the class ManagerImplTest method testManagerShutdownWithComponentDestruction.

public void testManagerShutdownWithComponentDestruction() {
    try {
        boolean activateOnActivation = true;
        TestContainer container = new TestContainer("Container");
        Map supportedComponents = new HashMap();
        TestContainer container2 = new TestContainer("Container2");
        Map supportedComponents2 = new HashMap();
        TestComponent mount1COB = new TestComponent("MOUNT1");
        TestHierarchicalComponent mount2HierCOB = new TestHierarchicalComponent("HierarchicalCOB2", manager, new String[] { "MOUNT3" }, true, activateOnActivation);
        TestHierarchicalComponent mount3HierCOB = new TestHierarchicalComponent("HierarchicalCOB3", manager, new String[] { "MOUNT5", "PBEND_B_01" }, true, activateOnActivation);
        TestComponent mount5COB = new TestComponent("MOUNT5");
        TestHierarchicalComponent mount4HierCOB = new TestHierarchicalComponent("HierarchicalCOB4", manager, new String[] { "MOUNT2" }, true, activateOnActivation);
        TestHierarchicalComponent psHierCOB = new TestHierarchicalComponent("HierarchicalPSCOB", manager, new String[] { "MOUNT5" }, true, activateOnActivation);
        supportedComponents.put("MOUNT1", mount1COB);
        supportedComponents.put("MOUNT2", mount2HierCOB);
        supportedComponents.put("MOUNT3", mount3HierCOB);
        supportedComponents2.put("MOUNT5", mount5COB);
        supportedComponents.put("MOUNT4", mount4HierCOB);
        supportedComponents.put("PBEND_B_01", psHierCOB);
        container.setSupportedComponents(supportedComponents);
        container2.setSupportedComponents(supportedComponents2);
        ClientInfo containerInfo = manager.login(container);
        ClientInfo containerInfo2 = manager.login(container2);
        TestAdministrator client = new TestAdministrator(administratorName);
        ClientInfo info = manager.login(client);
        try {
            Thread.sleep(STARTUP_COBS_SLEEP_TIME_MS);
        } catch (InterruptedException ie) {
        }
        // activate hier. components
        URI mount2URI;
        try {
            mount2URI = new URI("MOUNT2");
            StatusHolder status = new StatusHolder();
            Component ref = manager.getComponent(info.getHandle(), mount2URI, true, status);
            assertEquals(mount2HierCOB, ref);
            assertEquals(ComponentStatus.COMPONENT_ACTIVATED, status.getStatus());
        } catch (Exception ex) {
            fail();
        }
        // activate orphan component
        URI mount1URI;
        try {
            mount1URI = new URI("MOUNT1");
            StatusHolder status = new StatusHolder();
            Component ref = manager.getComponent(info.getHandle(), mount1URI, true, status);
            assertEquals(mount1COB, ref);
            assertEquals(ComponentStatus.COMPONENT_ACTIVATED, status.getStatus());
        } catch (Exception ex) {
            fail();
        }
        // activate mount4
        URI mount4URI;
        try {
            mount4URI = new URI("MOUNT4");
            StatusHolder status = new StatusHolder();
            Component ref = manager.getComponent(info.getHandle(), mount4URI, true, status);
            assertEquals(mount4HierCOB, ref);
            assertEquals(ComponentStatus.COMPONENT_ACTIVATED, status.getStatus());
        } catch (Exception ex) {
            fail();
        }
        try {
            Thread.sleep(STARTUP_COBS_SLEEP_TIME_MS);
        } catch (InterruptedException ie) {
        }
        // test activated Components
        // there should be all three Components activated
        ComponentInfo[] infos = manager.getComponentInfo(info.getHandle(), new int[0], "*", "*", true);
        assertEquals(6, infos.length);
        // check container shutdown order
        int[] containerSolution = new int[] { mount4HierCOB.getHandle(), mount2HierCOB.getHandle(), mount3HierCOB.getHandle(), psHierCOB.getHandle(), mount1COB.getHandle() };
        int[] containerOrder = container.get_component_shutdown_order();
        assertNotNull(containerOrder);
        assertEquals(containerSolution.length, containerOrder.length);
        for (int i = 0; i < containerSolution.length; i++) assertEquals(containerSolution[i], containerOrder[i]);
        int[] container2Order = container2.get_component_shutdown_order();
        /*
			int[] container2Solution = new int[] {mount5COB.getHandle()}; 
			assertNotNull(container2Order);
			assertEquals(container2Solution.length, container2Order.length);
			for (int i = 0; i < container2Solution.length; i++)
				assertEquals(container2Solution[i], container2Order[i]);
			*/
        // optimization, no notification if sequence size is not less than 1
        assertNull(container2Order);
        // check shutdown
        try {
            manager.shutdown(manager.getHandle(), 1);
            try {
                Thread.sleep(STARTUP_COBS_SLEEP_TIME_MS);
            } catch (InterruptedException ie) {
            }
            assertEquals(0, container.getActivatedComponents().size());
            assertEquals(0, container2.getActivatedComponents().size());
        } finally {
            // tearDown should not shutdown
            manager = null;
        }
    } catch (AcsJNoPermissionEx e) {
        fail("No permission");
    }
}
Also used : HashMap(java.util.HashMap) URI(java.net.URI) RemoteException(com.cosylab.acs.maci.RemoteException) URISyntaxException(java.net.URISyntaxException) BadParametersException(com.cosylab.acs.maci.BadParametersException) NoResourcesException(com.cosylab.acs.maci.NoResourcesException) NoDefaultComponentException(com.cosylab.acs.maci.NoDefaultComponentException) StatusHolder(com.cosylab.acs.maci.StatusHolder) AcsJNoPermissionEx(alma.maciErrType.wrappers.AcsJNoPermissionEx) ClientInfo(com.cosylab.acs.maci.ClientInfo) ComponentInfo(com.cosylab.acs.maci.ComponentInfo) Component(com.cosylab.acs.maci.Component) HashMap(java.util.HashMap) Map(java.util.Map)

Example 45 with ComponentInfo

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

the class ManagerImplTest method testOnDemandContainerStartupComponents.

public void testOnDemandContainerStartupComponents() throws Throwable {
    TestDaemon daemon = new TestDaemon(manager, false);
    transport.registerDeamon("test", daemon);
    // this one starts startup components on auto-start containers
    manager.initializationDone();
    try {
        Thread.sleep(STARTUP_COBS_SLEEP_TIME_MS * 3);
    } catch (InterruptedException ie) {
    }
    TestAdministrator client = new TestAdministrator(administratorName);
    ClientInfo info = manager.login(client);
    assertTrue(info.getHandle() != 0);
    // there should be one Component activated
    ComponentInfo[] infos = manager.getComponentInfo(info.getHandle(), new int[0], "*", "*", true);
    assertEquals(1, infos.length);
    assertEquals("DEMANDER2", infos[0].getName());
    // check if container is logged in
    ContainerInfo[] infos2 = manager.getContainerInfo(info.getHandle(), new int[0], "OnDemandContainer2");
    assertNotNull(infos2);
    assertEquals(1, infos2.length);
}
Also used : ContainerInfo(com.cosylab.acs.maci.ContainerInfo) ClientInfo(com.cosylab.acs.maci.ClientInfo) ComponentInfo(com.cosylab.acs.maci.ComponentInfo)

Aggregations

ComponentInfo (com.cosylab.acs.maci.ComponentInfo)66 AcsJNoPermissionEx (alma.maciErrType.wrappers.AcsJNoPermissionEx)24 NoResourcesException (com.cosylab.acs.maci.NoResourcesException)24 BadParametersException (com.cosylab.acs.maci.BadParametersException)23 ClientInfo (com.cosylab.acs.maci.ClientInfo)23 RemoteException (com.cosylab.acs.maci.RemoteException)22 HashMap (java.util.HashMap)20 NoDefaultComponentException (com.cosylab.acs.maci.NoDefaultComponentException)19 Component (com.cosylab.acs.maci.Component)18 URISyntaxException (java.net.URISyntaxException)18 Map (java.util.Map)18 URI (java.net.URI)17 StatusHolder (com.cosylab.acs.maci.StatusHolder)15 AcsJBadParameterEx (alma.ACSErrTypeCommon.wrappers.AcsJBadParameterEx)10 AcsJCannotGetComponentEx (alma.maciErrType.wrappers.AcsJCannotGetComponentEx)10 ContainerInfo (com.cosylab.acs.maci.ContainerInfo)9 ArrayList (java.util.ArrayList)8 TimeoutRemoteException (com.cosylab.acs.maci.TimeoutRemoteException)7 ComponentSpec (com.cosylab.acs.maci.ComponentSpec)6 CoreException (com.cosylab.acs.maci.CoreException)6