Search in sources :

Example 1 with DefaultComponentCommandPut

use of com.cosylab.acs.maci.manager.recovery.DefaultComponentCommandPut 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 2 with DefaultComponentCommandPut

use of com.cosylab.acs.maci.manager.recovery.DefaultComponentCommandPut 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

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