Search in sources :

Example 1 with AcsJSyncLockFailedEx

use of alma.jmanagerErrType.wrappers.AcsJSyncLockFailedEx in project ACS by ACS-Community.

the class ManagerImpl method internalRequestComponent.

/**
	 * Internal method for requesting components.
	 * @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 internalRequestComponent(int requestor, String name, String type, String code, String containerName, int keepAliveTime, StatusHolder status, boolean activate) throws AcsJCannotGetComponentEx, AcsJSyncLockFailedEx, AcsJComponentSpecIncompatibleWithActiveComponentEx {
    AcsJCannotGetComponentEx bcex = null;
    if (name == null) {
        bcex = new AcsJCannotGetComponentEx();
        logger.log(Level.SEVERE, "Cannot activate component with NULL name.", bcex);
        throw bcex;
    }
    if (status == null) {
        bcex = new AcsJCannotGetComponentEx();
        logger.log(Level.SEVERE, "Component " + name + " has NULL status.", bcex);
        throw bcex;
    }
    try {
        checkCyclicDependency(requestor, name);
    } catch (AcsJCyclicDependencyDetectedEx e) {
        AcsJCannotGetComponentEx cgce = new AcsJCannotGetComponentEx(e);
        cgce.setCURL(name);
        throw cgce;
    }
    // try to acquire lock
    String lockNotAcquiredCause = acquireSynchronizationObject(name, getLockTimeout(), "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();
            // AcsJComponentSpecIncompatibleWithActiveComponentEx flies up
            return internalNoSyncRequestComponent(requestor, name, type, code, containerName, keepAliveTime, status, activate);
        } finally {
            if (releaseRWLock)
                activationPendingRWLock.readLock().unlock();
            releaseSynchronizationObject(name);
        }
    } else {
        AcsJSyncLockFailedEx slfe = new AcsJSyncLockFailedEx();
        slfe.setCURL(name);
        slfe.setRequestor(requestor);
        slfe.setProperty("lockCause", lockNotAcquiredCause);
        throw slfe;
    }
}
Also used : AcsJSyncLockFailedEx(alma.jmanagerErrType.wrappers.AcsJSyncLockFailedEx) AcsJCyclicDependencyDetectedEx(alma.jmanagerErrType.wrappers.AcsJCyclicDependencyDetectedEx) AcsJCannotGetComponentEx(alma.maciErrType.wrappers.AcsJCannotGetComponentEx)

Example 2 with AcsJSyncLockFailedEx

use of alma.jmanagerErrType.wrappers.AcsJSyncLockFailedEx 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)

Example 3 with AcsJSyncLockFailedEx

use of alma.jmanagerErrType.wrappers.AcsJSyncLockFailedEx in project ACS by ACS-Community.

the class ManagerImpl method getDynamicComponent.

/**
	 * @see com.cosylab.acs.maci.Manager#getDynamicComponent(int, com.cosylab.acs.maci.ComponentSpec, boolean)
	 */
// TODO MF not supported
public ComponentInfo getDynamicComponent(int id, ComponentSpec componentSpec, boolean markAsDefault) 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;
        }
    } 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);
    /****************************************************************/
    // Same exceptions fly up
    ComponentInfo componentInfo = null;
    try {
        componentInfo = internalRequestDynamicComponent(id, componentSpec);
    } catch (AcsJSyncLockFailedEx e) {
        AcsJCannotGetComponentEx ex = new AcsJCannotGetComponentEx();
        ex.setCURL(componentSpec.getName());
        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) {
        /**
             * @todo Is it OK to get here? Always? 
             *       This is a place where we have to check carefully.
             */
        AcsJCannotGetComponentEx ex = new AcsJCannotGetComponentEx();
        ex.setCURL(componentSpec.getName());
        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) AcsJCannotGetComponentEx(alma.maciErrType.wrappers.AcsJCannotGetComponentEx)

Aggregations

AcsJSyncLockFailedEx (alma.jmanagerErrType.wrappers.AcsJSyncLockFailedEx)3 AcsJCannotGetComponentEx (alma.maciErrType.wrappers.AcsJCannotGetComponentEx)3 AcsJBadParameterEx (alma.ACSErrTypeCommon.wrappers.AcsJBadParameterEx)2 AcsJNullPointerEx (alma.ACSErrTypeCommon.wrappers.AcsJNullPointerEx)2 AcsJInvalidComponentSpecEx (alma.maciErrType.wrappers.AcsJInvalidComponentSpecEx)2 ComponentInfo (com.cosylab.acs.maci.ComponentInfo)2 DefaultComponentCommandPut (com.cosylab.acs.maci.manager.recovery.DefaultComponentCommandPut)2 AcsJCyclicDependencyDetectedEx (alma.jmanagerErrType.wrappers.AcsJCyclicDependencyDetectedEx)1 AcsJIncompleteComponentSpecEx (alma.maciErrType.wrappers.AcsJIncompleteComponentSpecEx)1 DAOProxy (com.cosylab.cdb.client.DAOProxy)1