Search in sources :

Example 11 with Component

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

the class ManagerImpl method restartComponent.

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

Example 12 with Component

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

the class ManagerImpl method internalNoSyncRestartComponent.

/**
	 * Internal method for restarting components.
	 *
	 * @param	owner	owner of the component.
	 * @param	h		handle of the component to be restarting.
	 * @return			Newly restarted component, <code>null</code> if failed.
	 */
// @todo MF not supported
private Component internalNoSyncRestartComponent(int owner, int h) throws AcsJNoPermissionEx {
    int handle = h & HANDLE_MASK;
    ComponentInfo componentInfo = null;
    componentsLock.lock();
    try {
        if (components.isAllocated(handle))
            componentInfo = (ComponentInfo) components.get(handle);
        if (componentInfo == null || componentInfo.getHandle() != h) {
            // invalid component handle
            BadParametersException af = new BadParametersException("Invalid component handle.");
            throw af;
        }
        // remove ownership of the component
        if (!componentInfo.getClients().contains(owner)) {
            // not an owner
            AcsJNoPermissionEx npe = new AcsJNoPermissionEx();
            npe.setReason("Restarting component that client does not own.");
            npe.setID(HandleHelper.toString(owner));
            npe.setProtectedResource(componentInfo.getName());
            throw npe;
        }
    } finally {
        componentsLock.unlock();
    }
    /****************** restart component ******************/
    //
    // get container
    //
    // search for container by its name
    Container container = null;
    ContainerInfo containerInfo = null;
    int containerHandle = componentInfo.getContainer();
    // if containerHandle equals 0, we have unavailable or registered component
    if (containerHandle != 0) {
        containerInfo = getContainerInfo(containerHandle);
        if (containerInfo != null) {
            checkContainerShutdownState(containerInfo);
            container = containerInfo.getContainer();
        }
        // required container is not logged in
        if (container == null) {
            // then simply do not do the restart
            String containerName;
            if (containerInfo != null)
                containerName = containerInfo.getName();
            else
                containerName = HandleHelper.toString(componentInfo.getContainer());
            logger.log(Level.WARNING, "Container '" + containerName + "' required by component '" + componentInfo.getName() + "' is not logged in.");
        }
    }
    // return value
    Component component = null;
    if (container != null) {
        // restart component
        try {
            component = container.restart_component(componentInfo.getHandle());
            if (component == null) {
                RemoteException re = new RemoteException("Failed to restart component '" + componentInfo.getName() + "', 'null' returned.");
                throw re;
            }
        // @todo what about notifying clients, marking component as available, updating reference...
        } catch (Throwable ex) {
            RemoteException re = new RemoteException("Failed to restart component '" + componentInfo.getName() + "' on container '" + containerInfo.getName() + "'.", ex);
            logger.log(Level.SEVERE, re.getMessage(), re);
        }
    }
    logger.log(Level.FINE, "Component '" + componentInfo.getName() + "' restarted.");
    return component;
}
Also used : Container(com.cosylab.acs.maci.Container) AcsJNoPermissionEx(alma.maciErrType.wrappers.AcsJNoPermissionEx) ContainerInfo(com.cosylab.acs.maci.ContainerInfo) ComponentInfo(com.cosylab.acs.maci.ComponentInfo) Component(com.cosylab.acs.maci.Component) RemoteException(com.cosylab.acs.maci.RemoteException) TimeoutRemoteException(com.cosylab.acs.maci.TimeoutRemoteException) BadParametersException(com.cosylab.acs.maci.BadParametersException)

Example 13 with Component

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

the class ManagerImpl method getComponent.

/**
	 * @see #getComponent
	 */
private Component getComponent(int id, URI curl, boolean activate, StatusHolder status, boolean allowServices) throws AcsJCannotGetComponentEx, AcsJNoPermissionEx {
    AcsJCannotGetComponentEx ex2 = null;
    // extract name
    String name = extractName(curl);
    // check if null
    try {
        checkCURL(curl);
    } catch (AcsJBadParameterEx e) {
        e.setParameter("curl");
        ex2 = new AcsJCannotGetComponentEx(e);
        ex2.setCURL(name);
        throw ex2;
    }
    if (status == null) {
        AcsJNullPointerEx ex = new AcsJNullPointerEx();
        ex.setVariable("status");
        ex2 = new AcsJCannotGetComponentEx(ex);
        ex2.setCURL(name);
        throw ex2;
    }
    /****************************************************************/
    // log info
    String requestorName = null;
    if (id != 0) {
        requestorName = getRequestorName(id);
        logger.log(Level.INFO, "'" + requestorName + "' requested component '" + curl + "'.");
    } else
        logger.log(Level.INFO, "Request for component '" + curl + "' issued.");
    // no login required for predefined objects (services)
    Component component = null;
    // "Manager" is a special service Component
    if (allowServices && name.equals("Manager")) {
        if (managerComponentReference != null)
            status.setStatus(ComponentStatus.COMPONENT_ACTIVATED);
        else
            status.setStatus(ComponentStatus.COMPONENT_DOES_NO_EXIST);
        component = new ServiceComponent(managerComponentReference);
    } else // "NameService" is also a special service Component
    if (allowServices && name.equals("NameService")) {
        if (remoteDirectoryComponentReference != null)
            status.setStatus(ComponentStatus.COMPONENT_ACTIVATED);
        else
            status.setStatus(ComponentStatus.COMPONENT_DOES_NO_EXIST);
        component = new ServiceComponent(remoteDirectoryComponentReference);
    } else if (allowServices && !name.startsWith(CURL_URI_SCHEMA) && isServiceComponent(name)) {
        Object obj = lookup(name, null);
        // set status
        if (obj != null)
            status.setStatus(ComponentStatus.COMPONENT_ACTIVATED);
        else
            status.setStatus(ComponentStatus.COMPONENT_DOES_NO_EXIST);
        component = new ServiceComponent(obj);
    } else {
        // check handle and NONE permissions
        securityCheck(id, AccessRights.NONE);
        try {
            component = internalRequestComponent(id, curl, status, activate);
        } catch (Throwable ce) {
            ex2 = new AcsJCannotGetComponentEx(ce);
        }
    }
    // log info
    if (component != null && component.getObject() != null) {
        if (requestorName != null)
            logger.log(Level.INFO, "Component '" + curl + "' provided to '" + requestorName + "'.");
        else
            logger.log(Level.INFO, "Component '" + curl + "' provided.");
    } else if (ex2 == null && !activate && status.getStatus() == ComponentStatus.COMPONENT_NOT_ACTIVATED) {
        if (requestorName != null)
            logger.log(Level.INFO, "Request from '" + requestorName + "' for component '" + curl + "' completed sucessfully, but component not activated.");
        else
            logger.log(Level.INFO, "Request for component '" + curl + "' completed sucessfully, but component not activated.");
    } else /**
		 * @todo GCH 2006.09.25
		 *       This last case should never happen, because 
		 *       there should be and exception thrown instead.
		 */
    {
        if (ex2 == null)
            ex2 = new AcsJCannotGetComponentEx();
        // it's clients responibility to handle the exception
        if (requestorName != null) {
            if (logger.isLoggable(Level.FINE))
                logger.log(Level.WARNING, "Failed to provide component '" + curl + "' to '" + requestorName + "'.", ex2);
            else
                logger.log(Level.WARNING, "Failed to provide component '" + curl + "' to '" + requestorName + "'.");
        } else {
            if (logger.isLoggable(Level.FINE))
                logger.log(Level.WARNING, "Failed to provide component '" + curl + "'.", ex2);
            else
                logger.log(Level.FINE, "Failed to provide component '" + curl + "'.");
        }
    }
    if (ex2 != null) {
        ex2.setCURL(name);
        throw ex2;
    }
    return component;
}
Also used : AcsJBadParameterEx(alma.ACSErrTypeCommon.wrappers.AcsJBadParameterEx) AcsJNullPointerEx(alma.ACSErrTypeCommon.wrappers.AcsJNullPointerEx) Component(com.cosylab.acs.maci.Component) AcsJCannotGetComponentEx(alma.maciErrType.wrappers.AcsJCannotGetComponentEx)

Example 14 with Component

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

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

Aggregations

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