Search in sources :

Example 11 with NoResourcesException

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

the class ManagerImpl method startUpContainer.

/**
	 * Start-up container (if it has a deploy info).
	 * @param containerName	name of the container to start up.
	 * @return container info of container, <code>null</code> if failed to start.
	 */
private ContainerInfo startUpContainer(String containerName) {
    // not to mess with same component name
    final String LOCK_NAME = "container-" + containerName;
    // try to acquire lock
    String lockNotAcquiredCause = acquireSynchronizationObject(LOCK_NAME, lockTimeout, "start-up container " + containerName);
    if (lockNotAcquiredCause == null) {
        try {
            // double check pattern
            ContainerInfo info = getContainerInfo(containerName);
            if (info != null)
                return info;
            return internalNoSyncStartUpContainer(containerName);
        } finally {
            releaseSynchronizationObject(LOCK_NAME);
        }
    } else {
        NoResourcesException nre = new NoResourcesException("Failed to obtain synchronization lock for container '" + containerName + "', possible deadlock; locked to '" + lockNotAcquiredCause + "'.");
        throw nre;
    }
}
Also used : NoResourcesException(com.cosylab.acs.maci.NoResourcesException) ContainerInfo(com.cosylab.acs.maci.ContainerInfo)

Example 12 with NoResourcesException

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

the class ManagerImpl method shutdownContainer.

/**
	 * @see com.cosylab.acs.maci.Manager#shutdownContainer(int, java.lang.String, int)
	 */
public void shutdownContainer(int id, String containerName, int action) throws AcsJNoPermissionEx {
    // check if null
    if (containerName == null) {
        // BAD_PARAM
        BadParametersException af = new BadParametersException("Non-null 'containerName' expected.");
        throw af;
    }
    /****************************************************************/
    // the caller must have SHUTDOWN_SYSTEM access rights,
    securityCheck(id, AccessRights.SHUTDOWN_SYSTEM);
    Container container;
    ContainerInfo containerInfo = getContainerInfo(containerName);
    if (containerInfo == null || (container = containerInfo.getContainer()) == null) {
        // NO_RESOURCES
        NoResourcesException nre = new NoResourcesException("Container '" + containerName + "' not logged in.");
        throw nre;
    }
    pendingContainerShutdown.add(containerInfo.getName());
    try {
        // release components
        try {
            // get shutdown order
            ComponentInfo[] infos = topologySortManager.getComponentShutdownOrder(containerInfo);
            releaseComponents(infos);
        } catch (Throwable th) {
            CoreException ce = new CoreException("Failed to release components on container '" + containerName + "'.", th);
            reportException(ce);
        }
        // shutdown (or disconnect)
        try {
            if (action == 0)
                container.disconnect();
            else
                container.shutdown(action);
        } catch (Throwable th) {
            // NO_RESOURCES
            NoResourcesException nre = new NoResourcesException("Failed to shutdown container '" + containerName + "'.", th);
            throw nre;
        }
    } finally {
        pendingContainerShutdown.remove(containerInfo.getName());
    }
/****************************************************************/
}
Also used : NoResourcesException(com.cosylab.acs.maci.NoResourcesException) Container(com.cosylab.acs.maci.Container) CoreException(com.cosylab.acs.maci.CoreException) ContainerInfo(com.cosylab.acs.maci.ContainerInfo) ComponentInfo(com.cosylab.acs.maci.ComponentInfo) BadParametersException(com.cosylab.acs.maci.BadParametersException)

Example 13 with NoResourcesException

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

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

the class ManagerImpl method internalReleaseComponent.

/**
	 * Internal method for releasing components.
	 *
	 * @param	owner	owner of the component.
	 * @param	h		handle of the component to be released.
	 * @param	force	force deactivate, if still has owners then component will be made unavailable.
	 * @return			Number of clients that are still using the component after the operation completed.
	 */
private ReleaseComponentResult internalReleaseComponent(int owner, int h, boolean force) throws AcsJNoPermissionEx, AcsJBadParameterEx {
    // extract name
    String name = null;
    componentsLock.lock();
    try {
        int handle = h & HANDLE_MASK;
        ComponentInfo componentInfo = null;
        if (components.isAllocated(handle))
            componentInfo = (ComponentInfo) components.get(handle);
        if (componentInfo == null) {
            // invalid Component handle
            AcsJBadParameterEx ex = new AcsJBadParameterEx();
            ex.setParameter("componentInfo");
            ex.setParameterValue("null");
            throw ex;
        }
        if (componentInfo.getHandle() != h) {
            // invalid Component handle
            AcsJBadParameterEx ex = new AcsJBadParameterEx();
            ex.setParameter("h");
            throw ex;
        }
        name = componentInfo.getName();
    } finally {
        componentsLock.unlock();
    }
    // try to acquire lock
    String lockNotAcquiredCause = acquireSynchronizationObject(name, lockTimeout, "release 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();
            return internalNoSyncReleaseComponent(owner, h, force);
        } finally {
            if (releaseRWLock)
                activationPendingRWLock.readLock().unlock();
            releaseSynchronizationObject(name);
        }
    } else {
        NoResourcesException nre = new NoResourcesException("Failed to obtain synchronization lock for component '" + name + "', possible deadlock; locked to '" + lockNotAcquiredCause + "'.");
        throw nre;
    }
}
Also used : AcsJBadParameterEx(alma.ACSErrTypeCommon.wrappers.AcsJBadParameterEx) NoResourcesException(com.cosylab.acs.maci.NoResourcesException) ComponentInfo(com.cosylab.acs.maci.ComponentInfo)

Example 15 with NoResourcesException

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

the class ManagerImpl method registerComponent.

/**
	 * @see com.cosylab.acs.maci.Manager#registerComponent(int, URI, String, Component)
	 */
public int registerComponent(int id, URI curl, String type, Component component) throws AcsJNoPermissionEx, AcsJBadParameterEx {
    // check for null
    if (curl == null) {
        AcsJBadParameterEx af = new AcsJBadParameterEx();
        af.setParameter("curl");
        af.setParameterValue("null");
        throw af;
    }
    if (type == null) {
        AcsJBadParameterEx af = new AcsJBadParameterEx();
        af.setParameter("type");
        af.setParameterValue("null");
        throw af;
    }
    if (component == null) {
        AcsJBadParameterEx af = new AcsJBadParameterEx();
        af.setParameter("component");
        af.setParameterValue("null");
        throw af;
    }
    // Just rethrow the exception
    try {
        checkCURL(curl, false);
    } catch (AcsJBadParameterEx e) {
        throw e;
    }
    // check handle and REGISTER_COMPONENT permissions
    securityCheck(id, AccessRights.REGISTER_COMPONENT);
    /****************************************************************/
    // extract name
    String name = extractName(curl);
    int h = 0;
    componentsLock.lock();
    try {
        // check if Component is already registred
        // if it is, return existing info
        h = components.first();
        while (h != 0) {
            ComponentInfo registeredComponentInfo = (ComponentInfo) components.get(h);
            if (registeredComponentInfo.getName().equals(name)) {
                if (registeredComponentInfo.getType().equals(type)) {
                    // it is already activated, add manager as an owner and return handle
                    if (!registeredComponentInfo.getClients().contains(this.getHandle())) {
                        // ACID - !!!
                        executeCommand(new ComponentCommandClientAdd(registeredComponentInfo.getHandle() & HANDLE_MASK, this.getHandle()));
                    //registredComponentInfo.getClients().add(this.getHandle());
                    }
                    return registeredComponentInfo.getHandle();
                } else {
                    AcsJNoPermissionEx npe = new AcsJNoPermissionEx();
                    npe.setReason("Component with name '" + name + "' but different type already registered.");
                    npe.setID(HandleHelper.toString(id));
                    npe.setProtectedResource(name);
                    throw npe;
                }
            }
            h = components.next(h);
        }
        // allocate new handle
        // !!! ACID 2
        Integer objHandle = (Integer) executeCommand(new ComponentCommandAllocate());
        int handle;
        //int handle = components.allocate();
        if (objHandle == null || (handle = objHandle.intValue()) == 0) {
            NoResourcesException af = new NoResourcesException("Generation of new handle failed, too many components registred.");
            throw af;
        }
        // generate external handle
        h = handle | COMPONENT_MASK;
        // add generated key
        h |= (random.nextInt(0x100)) << 16;
        // create new component info
        ComponentInfo componentInfo = new ComponentInfo(h, name, type, null, component);
        // no container
        componentInfo.setContainer(0);
        componentInfo.setContainerName(null);
        // components can register other components
        componentInfo.setAccessRights(AccessRights.REGISTER_COMPONENT);
        // set Manager as client of the Component (to keep it immortal)
        componentInfo.getClients().add(this.getHandle());
        // set interfaces
        // NOTE: this could block since it is a remote call
        componentInfo.setInterfaces(component.implementedInterfaces());
        // !!! ACID - register AddComponentCommand
        executeCommand(new ComponentCommandSet(handle, componentInfo));
    // store info
    //components.set(handle, componentInfo);
    } finally {
        componentsLock.unlock();
    }
    // bind to remote directory
    // NOTE: this could block since it is a remote call
    //bind(convertToHiearachical(name), "O", component);
    logger.log(Level.INFO, "Component '" + name + "' registered.");
    return h;
}
Also used : AcsJBadParameterEx(alma.ACSErrTypeCommon.wrappers.AcsJBadParameterEx) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) NoResourcesException(com.cosylab.acs.maci.NoResourcesException) AcsJNoPermissionEx(alma.maciErrType.wrappers.AcsJNoPermissionEx) ComponentCommandClientAdd(com.cosylab.acs.maci.manager.recovery.ComponentCommandClientAdd) ComponentCommandSet(com.cosylab.acs.maci.manager.recovery.ComponentCommandSet) ComponentInfo(com.cosylab.acs.maci.ComponentInfo) ComponentCommandAllocate(com.cosylab.acs.maci.manager.recovery.ComponentCommandAllocate)

Aggregations

NoResourcesException (com.cosylab.acs.maci.NoResourcesException)28 AcsJNoPermissionEx (alma.maciErrType.wrappers.AcsJNoPermissionEx)17 BadParametersException (com.cosylab.acs.maci.BadParametersException)17 CoreException (com.cosylab.acs.maci.CoreException)14 BAD_PARAM (org.omg.CORBA.BAD_PARAM)13 UNKNOWN (org.omg.CORBA.UNKNOWN)13 NO_RESOURCES (org.omg.CORBA.NO_RESOURCES)12 AcsJCannotGetComponentEx (alma.maciErrType.wrappers.AcsJCannotGetComponentEx)8 ComponentInfo (com.cosylab.acs.maci.ComponentInfo)8 Object (org.omg.CORBA.Object)8 URI (java.net.URI)7 URISyntaxException (java.net.URISyntaxException)7 ClientInfo (com.cosylab.acs.maci.ClientInfo)5 AcsJBadParameterEx (alma.ACSErrTypeCommon.wrappers.AcsJBadParameterEx)4 Component (com.cosylab.acs.maci.Component)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 ComponentInfo (si.ijs.maci.ComponentInfo)4 AcsJComponentNotAlreadyActivatedEx (alma.maciErrType.wrappers.AcsJComponentNotAlreadyActivatedEx)3 AcsJComponentSpecIncompatibleWithActiveComponentEx (alma.maciErrType.wrappers.AcsJComponentSpecIncompatibleWithActiveComponentEx)3 Container (com.cosylab.acs.maci.Container)3