Search in sources :

Example 1 with ContainerInfo

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

the class ManagerImpl method getClients.

/**
	 * Get client info. for specified handles of <code>Client</code> or <code>Administrator</code>. For <code>Component</code>
	 * handles component's <code>Container</code> is returned.
	 *
	 * @param	excludeHandle	handle of client not to be included in the array, can be 0.
	 * @param	handles			handles of the clients whose info. should be returned, non-<code>null</code>.
	 * @param	returns			requested infos, <code>null</code> if none
	 */
private ClientInfo[] getClients(int excludeHandle, int[] handles) {
    assert (handles != null);
    // array of clients to be notified
    ClientInfo[] clients = null;
    ArrayList<ClientInfo> list = new ArrayList<ClientInfo>();
    for (int i = 0; i < handles.length; i++) if (handles[i] != excludeHandle) {
        if ((handles[i] & TYPE_MASK) == COMPONENT_MASK) {
            ComponentInfo componentInfo = getComponentInfo(handles[i]);
            if (componentInfo != null) {
                ContainerInfo containerInfo = getContainerInfo(componentInfo.getContainer());
                if (containerInfo != null) {
                    ClientInfo info = new ClientInfo(containerInfo.getHandle(), containerInfo.getName(), containerInfo.getContainer());
                    list.add(info);
                }
            }
        } else {
            ClientInfo info = getClientInfo(handles[i]);
            if (info != null)
                list.add(info);
        }
    }
    // copy to array
    if (list.size() > 0) {
        clients = new ClientInfo[list.size()];
        list.toArray(clients);
    }
    return clients;
}
Also used : ArrayList(java.util.ArrayList) ContainerInfo(com.cosylab.acs.maci.ContainerInfo) ClientInfo(com.cosylab.acs.maci.ClientInfo) ComponentInfo(com.cosylab.acs.maci.ComponentInfo)

Example 2 with ContainerInfo

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

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

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

the class ManagerImpl method internalRequestDefaultComponent.

/**
	 * Internal method for requesting default components.
	 * @param	requestor	requestor of the component.
	 * @param	typr		type of the component
	 * @return	componentInfo	<code>ComponentInfo</code> of requested default component.
	 */
private ComponentInfo internalRequestDefaultComponent(int requestor, String type) throws NoDefaultComponentException {
    String defaultComponentName = null;
    ComponentInfo defaultComponentInfo = null;
    // first check default components table
    synchronized (defaultComponents) {
        defaultComponentInfo = defaultComponents.get(type);
    }
    if (defaultComponentInfo != null)
        defaultComponentName = defaultComponentInfo.getName();
    // if not found, search for the default component in the CDB
    if (defaultComponentName == null) {
        DAOProxy componentsDAO = getComponentsDAOProxy();
        if (componentsDAO != null) {
            try {
                // get names of all components
                // @todo here to check if CDB is available
                componentsDAO.get_field_data("");
                /*String[] ids =*/
                String[] ids = getComponentsList();
                // test names
                for (int i = 0; i < ids.length; i++) {
                    // read name
                    //readStringCharacteristics(componentsDAO, ids[i]+"/Name");
                    String name = ids[i];
                    if (name == null) {
                        logger.log(Level.WARNING, "Misconfigured CDB, there is no type of component '" + ids[i] + "' defined.");
                        continue;
                    }
                    // do not search dynamic components (they cannot be marked as default in CDB anyway)
                    if (!name.equals(ComponentSpec.COMPSPEC_ANY)) {
                        // read type
                        String componentType = readStringCharacteristics(componentsDAO, ids[i] + "/Type");
                        if (type == null) {
                            logger.log(Level.WARNING, "Misconfigured CDB, there is no type of component '" + name + "' defined.");
                            continue;
                        }
                        // test type
                        final String TRUE_STRING = "true";
                        if (type.equals(componentType)) {
                            // check if it is default, read silently
                            String isDefault = readStringCharacteristics(componentsDAO, ids[i] + "/Default", true);
                            if (isDefault == null || !isDefault.equalsIgnoreCase(TRUE_STRING))
                                continue;
                            // got the match
                            defaultComponentName = name;
                            break;
                        }
                    }
                }
            } catch (Throwable ex) {
                CoreException ce = new CoreException("Failed to obtain component data from the CDB.", ex);
                reportException(ce);
            }
        }
    }
    // if found get the component
    if (defaultComponentInfo != null) {
        try {
            StatusHolder status = new StatusHolder();
            ContainerInfo containerInfo = getContainerInfo(defaultComponentInfo.getContainer());
            if (containerInfo == null) {
                CoreException huse = new CoreException("Failed to return default component: '" + defaultComponentName + "', container with '" + HandleHelper.toString(defaultComponentInfo.getContainer()) + "' not logged in.");
                reportException(huse);
                return null;
            }
            ComponentInfo componentInfo = internalRequestComponent(requestor, defaultComponentInfo.getName(), defaultComponentInfo.getType(), defaultComponentInfo.getCode(), containerInfo.getName(), RELEASE_IMMEDIATELY, status, true);
            if (componentInfo == null || status.getStatus() != ComponentStatus.COMPONENT_ACTIVATED) {
                CoreException huse = new CoreException("Failed to obtain default component: '" + defaultComponentName + "'.");
                reportException(huse);
                // no error handling...
                return null;
            }
            return componentInfo;
        } catch (Throwable t) {
            CoreException huse = new CoreException("Failed to return default component: '" + defaultComponentName + "'.", t);
            reportException(huse);
            return null;
        }
    } else if (defaultComponentName != null) {
        // create CURL
        URI curl = null;
        try {
            curl = CURLHelper.createURI(defaultComponentName);
        } catch (URISyntaxException use) {
            CoreException huse = new CoreException("Failed to create CURL from default component name: '" + defaultComponentName + "'.", use);
            reportException(huse);
            return null;
        }
        try {
            // request for component
            StatusHolder status = new StatusHolder();
            Component component = internalRequestComponent(requestor, curl, status, true);
            if (component == null || status.getStatus() != ComponentStatus.COMPONENT_ACTIVATED) {
                CoreException huse = new CoreException("Failed to obtain default component: '" + defaultComponentName + "'.");
                reportException(huse);
                return null;
            }
            // return component info
            ComponentInfo[] componentInfo = getComponentInfo(requestor, new int[0], defaultComponentName, type, true);
            if (componentInfo == null || componentInfo.length != 1) {
                CoreException huse = new CoreException("Failed to obtain activated default component ComponentInfo: '" + defaultComponentName + "'.");
                reportException(huse);
                return null;
            } else
                return componentInfo[0];
        } catch (Throwable t) {
            CoreException huse = new CoreException("Failed to return default component: '" + defaultComponentName + "'.", t);
            reportException(huse);
            return null;
        }
    }
    // not found
    NoDefaultComponentException ndce = new NoDefaultComponentException("No default component for type '" + type + "' found.");
    throw ndce;
}
Also used : URISyntaxException(java.net.URISyntaxException) DAOProxy(com.cosylab.cdb.client.DAOProxy) URI(java.net.URI) NoDefaultComponentException(com.cosylab.acs.maci.NoDefaultComponentException) StatusHolder(com.cosylab.acs.maci.StatusHolder) CoreException(com.cosylab.acs.maci.CoreException) ContainerInfo(com.cosylab.acs.maci.ContainerInfo) ComponentInfo(com.cosylab.acs.maci.ComponentInfo) Component(com.cosylab.acs.maci.Component)

Example 5 with ContainerInfo

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

the class ManagerImpl method getContainerInfo.

/**
	 * Get container info. for specified id of <code>Container</code>.
	 *
	 * @param	id	handle of the container whose info. should be returned
	 * @param	returns	requested info, <code>null</code> if container with requested handle does not exits
	 */
private ContainerInfo getContainerInfo(int id) {
    // parse handle part
    int handle = id & HANDLE_MASK;
    // info to be returned
    ContainerInfo info = null;
    synchronized (containers) {
        if (containers.isAllocated(handle))
            info = (ContainerInfo) containers.get(handle);
    }
    return info;
}
Also used : ContainerInfo(com.cosylab.acs.maci.ContainerInfo)

Aggregations

ContainerInfo (com.cosylab.acs.maci.ContainerInfo)24 ComponentInfo (com.cosylab.acs.maci.ComponentInfo)9 ClientInfo (com.cosylab.acs.maci.ClientInfo)7 AcsJNoPermissionEx (alma.maciErrType.wrappers.AcsJNoPermissionEx)5 Container (com.cosylab.acs.maci.Container)5 DAOProxy (com.cosylab.cdb.client.DAOProxy)5 BadParametersException (com.cosylab.acs.maci.BadParametersException)4 RemoteException (com.cosylab.acs.maci.RemoteException)4 TimeoutRemoteException (com.cosylab.acs.maci.TimeoutRemoteException)4 URI (java.net.URI)4 ArrayList (java.util.ArrayList)4 AcsJCannotGetComponentEx (alma.maciErrType.wrappers.AcsJCannotGetComponentEx)3 Component (com.cosylab.acs.maci.Component)3 CoreException (com.cosylab.acs.maci.CoreException)3 NoResourcesException (com.cosylab.acs.maci.NoResourcesException)3 StatusHolder (com.cosylab.acs.maci.StatusHolder)3 ManagerImpl (com.cosylab.acs.maci.manager.ManagerImpl)3 ImplLang (com.cosylab.acs.maci.ImplLang)2 IntArray (com.cosylab.acs.maci.IntArray)2 Manager (com.cosylab.acs.maci.Manager)2