Search in sources :

Example 36 with ComponentInfo

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

the class ManagerImpl method getDefaultComponent.

/*****************************************************************************/
/*********************** [ Dynamic (de)activation ] **************************/
/*****************************************************************************/
/**
	 * @see com.cosylab.acs.maci.Manager#getDefaultComponent(int, java.lang.String)
	 */
// @todo MF not supported
public ComponentInfo getDefaultComponent(int id, String type) throws AcsJNoPermissionEx, NoDefaultComponentException {
    if (type == null) {
        // BAD_PARAM
        BadParametersException af = new BadParametersException("Non-null 'type' expected.");
        throw af;
    }
    /****************************************************************/
    // check handle and NONE permissions
    securityCheck(id, AccessRights.NONE);
    logger.log(Level.INFO, "Getting default component for type '" + type + "'.");
    ComponentInfo componentInfo = internalRequestDefaultComponent(id, type);
    return componentInfo;
}
Also used : ComponentInfo(com.cosylab.acs.maci.ComponentInfo) BadParametersException(com.cosylab.acs.maci.BadParametersException)

Example 37 with ComponentInfo

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

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

the class ComponentInfoTopologicalSortManager method run.

/**
	 * (Sync is clean since activationPendingRWLock is acquired and all
	 * notify request is issued only from its reader lock).
	 * @see java.lang.Runnable#run()
	 */
public void run() {
    while (!destroyed) {
        synchronized (this) {
            int dirtyContainersCount;
            synchronized (dirtyContainerMap) {
                dirtyContainersCount = dirtyContainerMap.size();
            }
            if (dirtyContainersCount == 0) {
                try {
                    this.wait();
                } catch (InterruptedException e) {
                    return;
                }
            }
        }
        if (destroyed)
            return;
        // aquire writer lock to prevent activation/deactivation
        activationPendingRWLock.writeLock().lock();
        try {
            Integer[] conts;
            synchronized (dirtyContainerMap) {
                conts = new Integer[dirtyContainerMap.size()];
                dirtyContainerMap.toArray(conts);
                dirtyContainerMap.clear();
            }
            ComponentInfo[] orderedList;
            synchronized (components) {
                List list = ComponentInfoTopologicalSort.sort(components);
                orderedList = new ComponentInfo[list.size()];
                list.toArray(orderedList);
            }
            synchronized (listLock) {
                currentTSList = orderedList;
            }
            for (int i = 0; i < conts.length; i++) {
                int handle = conts[i].intValue() & HandleConstants.HANDLE_MASK;
                ContainerInfo containerInfo = null;
                synchronized (containers) {
                    if (containers.isAllocated(handle))
                        containerInfo = (ContainerInfo) containers.get(handle);
                }
                if (containerInfo == null || containerInfo.getName() == null)
                    break;
                String containerName = containerInfo.getName();
                // check if shutdown state
                if (pendingContainerShutdown.contains(containerName))
                    break;
                IntArray containerOrderdList = new IntArray(10);
                for (int j = 0; j < orderedList.length; j++) {
                    // if component already deactivated, skip it
                    if (orderedList[j].getContainer() == 0)
                        continue;
                    // this is null proof
                    if (containerName.equals(orderedList[j].getContainerName())) {
                        containerOrderdList.add(orderedList[j].getHandle());
                    }
                }
                // optimization
                if (containerOrderdList.size() > 1)
                    notifyContainerShutdownOrder(containerInfo, containerOrderdList.toArray());
            }
        } finally {
            activationPendingRWLock.writeLock().unlock();
        }
        try {
            Thread.sleep(100);
        } catch (InterruptedException ex) {
            logger.log(Level.WARNING, "Exception caught while waiting in run() method");
            ex.printStackTrace();
        }
    }
}
Also used : IntArray(com.cosylab.acs.maci.IntArray) ContainerInfo(com.cosylab.acs.maci.ContainerInfo) ArrayList(java.util.ArrayList) List(java.util.List) ComponentInfo(com.cosylab.acs.maci.ComponentInfo)

Example 39 with ComponentInfo

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

the class ManagerImpl method getRequestorName.

/*****************************************************************************/
/*************************** [ Utility methods ] *****************************/
/*****************************************************************************/
/**
	 * Returns human-readable and meaningful name of handle.
	 *
	 * @param	id	handle to stringifys
	 * @return	human-readable and meaningful name of handle.
	 */
private String getRequestorName(int id) {
    // parse handle part
    int reqHandle = id & HANDLE_MASK;
    boolean invalidHandle = true;
    StringBuffer name = new StringBuffer(30);
    switch(id & TYPE_MASK) {
        case CONTAINER_MASK:
            //name.append("Container ");
            synchronized (containers) {
                if (containers.isAllocated(reqHandle)) {
                    ContainerInfo info = (ContainerInfo) containers.get(reqHandle);
                    if (info.getHandle() == id) {
                        invalidHandle = false;
                        name.append(info.getName());
                    }
                }
            }
            break;
        case CLIENT_MASK:
            //name.append("Client ");
            synchronized (clients) {
                if (clients.isAllocated(reqHandle)) {
                    ClientInfo info = (ClientInfo) clients.get(reqHandle);
                    if (info.getHandle() == id) {
                        invalidHandle = false;
                        name.append(info.getName());
                    }
                }
            }
            break;
        case ADMINISTRATOR_MASK:
            //name.append("Administrator ");
            synchronized (administrators) {
                if (administrators.isAllocated(reqHandle)) {
                    ClientInfo info = (ClientInfo) administrators.get(reqHandle);
                    if (info.getHandle() == id) {
                        invalidHandle = false;
                        name.append(info.getName());
                    }
                }
            }
            break;
        case COMPONENT_MASK:
            //name.append("Component ");
            componentsLock.lock();
            try {
                if (components.isAllocated(reqHandle)) {
                    ComponentInfo info = (ComponentInfo) components.get(reqHandle);
                    // do additional preallocation check
                    if (info != null && info.getHandle() == id) {
                        invalidHandle = false;
                        name.append(info.getName());
                    }
                }
            } finally {
                componentsLock.unlock();
            }
            break;
        case MANAGER_MASK:
            //name.append("Manager ");
            name.append("Manager");
            invalidHandle = false;
            break;
    }
    if (invalidHandle)
        name.append("<unknown>");
    return name.toString();
}
Also used : ContainerInfo(com.cosylab.acs.maci.ContainerInfo) ClientInfo(com.cosylab.acs.maci.ClientInfo) ComponentInfo(com.cosylab.acs.maci.ComponentInfo)

Example 40 with ComponentInfo

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

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