Search in sources :

Example 1 with ComponentInfo

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

the class ManagerImpl method getComponentInfo.

/**
	 * @see com.cosylab.acs.maci.Manager#getComponentInfo(int, int[], String, String, boolean)
	 */
// TODO MF all (using wildchars match for domain names) interdomain queries
public ComponentInfo[] getComponentInfo(int id, int[] handles, String name_wc, String type_wc, boolean activeOnly) throws AcsJNoPermissionEx {
    if (handles == null) {
        // BAD_PARAM
        BadParametersException af = new BadParametersException("Non-null 'handles' sequence expected.");
        throw af;
    } else if (handles.length == 0 && (name_wc == null || type_wc == null)) {
        // BAD_PARAM
        BadParametersException af = new BadParametersException("Non-null 'names_wc' or' type_wc' sequence expected.");
        throw af;
    }
    /****************************************************************/
    // the caller must have INTROSPECT_MANAGER access rights,
    // or it must have adequate privileges to access the component (the same as with the get_component method).
    securityCheck(id, AccessRights.NONE);
    // info to be returned
    ComponentInfo[] info = null;
    // get info of requested handles
    if (handles.length > 0) {
        info = new ComponentInfo[handles.length];
        for (int i = 0; i < handles.length; i++) {
            // access rights to be checked here...
            info[i] = getComponentInfo(handles[i]);
            // filter out unavailable
            if (info[i] != null && info[i].getComponent() == null)
                info[i] = null;
        }
    } else // use name_wc and type_wc as search criteria
    {
        // check for inter-domain search
        if (name_wc.startsWith(CURL_URI_SCHEMA)) {
            URI curl = null;
            try {
                curl = CURLHelper.createURI(name_wc);
                if (curl.getAuthority() != null && curl.getAuthority().indexOf('*') >= 0)
                    throw new IllegalArgumentException("Wildchars not supported in domain names.");
            } catch (URISyntaxException e) {
                // BAD_PARAM
                BadParametersException af = new BadParametersException("Invalid CURL syntax in 'names_wc'.");
                throw af;
            }
            name_wc = extractName(curl);
            Manager remoteManager = null;
            // if not local do inter-domain query
            if (name_wc.startsWith(CURL_URI_SCHEMA)) {
                // TODO MF do the login?
                try {
                    String domainName = curl.getAuthority();
                    remoteManager = getManagerForDomain(domainName);
                    if (remoteManager == null)
                        throw new CoreException("Failed to obtain manager for domain '" + domainName + "'.");
                } catch (Throwable th) {
                    logger.log(Level.WARNING, "Failed to obtain non-local manager required by CURL '" + curl + "'.", th);
                    return null;
                }
            }
            try {
                // local name to be used
                String localName = curl.getPath();
                if (localName.charAt(0) == '/')
                    localName = localName.substring(1);
                ComponentInfo[] infos = remoteManager.getComponentInfo(INTERDOMAIN_MANAGER_HANDLE, handles, localName, type_wc, false);
                if (infos != null) {
                    // prefix names
                    final String prefix = CURL_URI_SCHEMA + curl.getAuthority() + "/";
                    for (int i = 0; i < infos.length; i++) {
                        if (!infos[i].getName().startsWith(CURL_URI_SCHEMA))
                            infos[i].setName(prefix + infos[i].getName());
                        String containerName = infos[i].getContainerName();
                        if (containerName != null && !containerName.startsWith(CURL_URI_SCHEMA))
                            infos[i].setContainerName(prefix + containerName);
                    }
                }
                return infos;
            } catch (Exception ex) {
                RemoteException re = new RemoteException("Failed to obtain component infos for CURL '" + curl + "' from remote manager.", ex);
                reportException(re);
                return null;
            }
        }
        // map of components to be returned
        Map<String, ComponentInfo> map = new HashMap<String, ComponentInfo>();
        // read active/registered components
        componentsLock.lock();
        try {
            int h = components.first();
            while (h != 0) {
                ComponentInfo componentInfo = (ComponentInfo) components.get(h);
                if (componentInfo.getComponent() != null && WildcharMatcher.match(name_wc, componentInfo.getName()) && WildcharMatcher.match(type_wc, componentInfo.getType())) {
                    // access rights to be checked here...
                    // found the match, add existing info to list
                    map.put(componentInfo.getName(), componentInfo);
                }
                h = components.next(h);
            }
        } finally {
            componentsLock.unlock();
        }
        // add also non-active, if requested
        if (!activeOnly) {
            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 name of component '" + ids[i] + "' defined.");
                            continue;
                        }
                        // add if not already added and matches criteria
                        if (!map.containsKey(name) && //!name.equals(ComponentSpec.COMPSPEC_ANY) &&
                        name.indexOf(ComponentSpec.COMPSPEC_ANY) != 0 && WildcharMatcher.match(name_wc, name)) {
                            // read type
                            String type = 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
                            if (!type.equals(ComponentSpec.COMPSPEC_ANY) && WildcharMatcher.match(type_wc, type)) {
                                // read code
                                String code = readStringCharacteristics(componentsDAO, ids[i] + "/Code");
                                if (code == null) {
                                    logger.log(Level.WARNING, "Misconfigured CDB, there is no code of component '" + name + "' defined.");
                                    continue;
                                }
                                // test code
                                if (code.equals(ComponentSpec.COMPSPEC_ANY))
                                    continue;
                                // read container
                                String container = readStringCharacteristics(componentsDAO, ids[i] + "/Container");
                                if (container == null) {
                                    logger.log(Level.WARNING, "Misconfigured CDB, there is no container name of component '" + name + "' defined.");
                                    continue;
                                }
                                // test container
                                if (container.equals(ComponentSpec.COMPSPEC_ANY))
                                    continue;
                                // got the match
                                // access rights to be checked here...
                                // create info and put it into list
                                ComponentInfo retInfo = new ComponentInfo(0, name, type, code, null);
                                retInfo.setContainerName(container);
                                map.put(name, retInfo);
                            }
                        }
                    }
                } catch (Exception ex) {
                    CoreException ce = new CoreException("Failed to obtain component data from the CDB.", ex);
                    reportException(ce);
                }
            }
        }
        // copy to array
        info = new ComponentInfo[map.size()];
        map.values().toArray(info);
    }
    return info;
}
Also used : LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) URISyntaxException(java.net.URISyntaxException) Manager(com.cosylab.acs.maci.Manager) DAOProxy(com.cosylab.cdb.client.DAOProxy) URI(java.net.URI) AcsJException(alma.acs.exceptions.AcsJException) NoDefaultComponentException(com.cosylab.acs.maci.NoDefaultComponentException) RemoteTransientException(com.cosylab.acs.maci.RemoteTransientException) NameNotFoundException(javax.naming.NameNotFoundException) NameAlreadyBoundException(javax.naming.NameAlreadyBoundException) IOException(java.io.IOException) NoResourcesException(com.cosylab.acs.maci.NoResourcesException) URISyntaxException(java.net.URISyntaxException) NamingException(javax.naming.NamingException) BadParametersException(com.cosylab.acs.maci.BadParametersException) CoreException(com.cosylab.acs.maci.CoreException) RemoteException(com.cosylab.acs.maci.RemoteException) TimeoutRemoteException(com.cosylab.acs.maci.TimeoutRemoteException) BadParametersException(com.cosylab.acs.maci.BadParametersException) CoreException(com.cosylab.acs.maci.CoreException) ComponentInfo(com.cosylab.acs.maci.ComponentInfo) RemoteException(com.cosylab.acs.maci.RemoteException) TimeoutRemoteException(com.cosylab.acs.maci.TimeoutRemoteException)

Example 2 with ComponentInfo

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

the class ManagerImpl method containerPostLoginActivation.

/**
	 * Container post login activation, activate startup and unavailable components.
	 * NOTE: to be run in separate thread.
	 *
	 * @param	containerInfo	container info for which to perform post login activation.
	 * @param	recoverContainer	recovery mode flag.
	 */
private void containerPostLoginActivation(final ContainerInfo containerInfo, boolean recoverContainer) {
    // give containers some time to fully initialize
    if (containerInfo.getImplLang() == ImplLang.cpp || containerInfo.getImplLang() == ImplLang.not_specified) {
        try {
            Thread.sleep(3000);
        } catch (InterruptedException ie) {
        }
    }
    // shutdown check
    if (isShuttingDown())
        return;
    // CDB startup
    if (cdbActivation != null && containerInfo.getName().equals(cdbActivation.getContainer())) {
        try {
            StatusHolder status = new StatusHolder();
            ComponentInfo cdbInfo = internalRequestComponent(this.getHandle(), cdbActivation.getName(), cdbActivation.getType(), cdbActivation.getCode(), cdbActivation.getContainer(), RELEASE_IMMEDIATELY, status, true);
            if (status.getStatus() != ComponentStatus.COMPONENT_ACTIVATED)
                logger.log(Level.SEVERE, "Failed to activate CDB, reason: '" + status.getStatus() + "'.");
            else if (cdbInfo == null || cdbInfo.getHandle() == 0 || cdbInfo.getComponent() == null)
                logger.log(Level.SEVERE, "Failed to activate CDB, invalid ComponentInfo returned: '" + cdbInfo + "'.");
            else {
                logger.log(Level.INFO, "CDB activated on container '" + containerInfo.getName() + "'.");
            }
        } catch (Throwable ex) {
            logger.log(Level.SEVERE, "Failed to activate CDB on container '" + containerInfo.getName() + "'.", ex);
        }
    }
    // used for fast lookups
    Map<String, Integer> activationRequests = new HashMap<String, Integer>();
    // order is important, preserve it
    ArrayList<URI> activationRequestsList = new ArrayList<URI>();
    // get CDB access daos
    DAOProxy dao = getManagerDAOProxy();
    DAOProxy componentsDAO = getComponentsDAOProxy();
    //
    if (dao != null && componentsDAO != null) {
        try {
            // query startup components
            String[] startup = dao.get_string_seq("Startup");
            final Integer managerHandle = new Integer(this.getHandle());
            for (int i = 0; i < startup.length; i++) {
                // TODO simulator test workaround
                if (startup[i].length() == 0)
                    continue;
                // read container field
                String containerName = readStringCharacteristics(componentsDAO, startup[i] + "/Container");
                if (containerName == null) {
                    logger.log(Level.WARNING, "Misconfigured CDB, there is no container of component '" + startup[i] + "' defined.");
                    continue;
                }
                // if container name matches, add activation request
                if (containerInfo.getName().equals(containerName)) {
                    try {
                        URI curl = CURLHelper.createURI(startup[i]);
                        // check CURL
                        try {
                            checkCURL(curl);
                        } catch (RuntimeException e) {
                            // @todo Auto-generated catch block
                            e.printStackTrace();
                        }
                        activationRequestsList.add(curl);
                        activationRequests.put(startup[i], managerHandle);
                    } catch (URISyntaxException usi) {
                        logger.log(Level.WARNING, "Failed to create URI from component name '" + startup[i] + "'.", usi);
                    }
                }
            }
        } catch (Throwable th) {
            logger.log(Level.WARNING, "Failed to retrieve list of startup components.", th);
        }
    }
    //
    // autostart components (<component>.Autostart attribute)
    //
    final String TRUE_STRING = "true";
    if (componentsDAO != null) {
        try {
            final Integer managerHandle = new Integer(this.getHandle());
            // 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 name of component '" + ids[i] + "' defined.");
                    continue;
                }
                // read autostart silently
                String autostart = readStringCharacteristics(componentsDAO, ids[i] + "/Autostart", true);
                if (autostart == null) {
                    logger.log(Level.WARNING, "Misconfigured CDB, there is no autostart attribute of component '" + ids[i] + "' defined.");
                    continue;
                } else if (autostart.equalsIgnoreCase(TRUE_STRING) && !activationRequests.containsKey(name)) /* TODO to be removed */
                {
                    // read container silently
                    String componentContainer = readStringCharacteristics(componentsDAO, ids[i] + "/Container", true);
                    if (componentContainer == null) {
                        logger.log(Level.WARNING, "Misconfigured CDB, there is no container attribute of component '" + ids[i] + "' defined.");
                        continue;
                    } else if (!containerInfo.getName().equals(componentContainer))
                        continue;
                    try {
                        URI curl = CURLHelper.createURI(name);
                        // check CURL, no non-local curls
                        try {
                            checkCURL(curl, false);
                        } catch (RuntimeException e) {
                            reportException(e);
                        }
                        activationRequestsList.add(curl);
                        activationRequests.put(name, managerHandle);
                    } catch (URISyntaxException usi) {
                        logger.log(Level.WARNING, "Failed to create URI from component name '" + name + "'.", usi);
                    }
                }
            }
        } catch (Throwable ex) {
            logger.log(Level.WARNING, "Failed to retrieve list of components.", ex);
        }
    }
    // list of componentInfo to be cleaned up (cannot be immediately, due to lock)
    ArrayList<ComponentInfo> cleanupList = new ArrayList<ComponentInfo>();
    // check unavailable components
    if (unavailableComponents.size() > 0) {
        if (componentsDAO != null) {
            try {
                final Integer reactivateHandle = new Integer(0);
                synchronized (unavailableComponents) {
                    String[] names = unavailableComponents.keySet().toArray(new String[unavailableComponents.size()]);
                    // reverse
                    for (int i = names.length - 1; i >= 0; i--) {
                        String name = names[i];
                        boolean reactivate = false;
                        // dynamic component check
                        ComponentInfo componentInfo = unavailableComponents.get(name);
                        if (componentInfo != null && componentInfo.isDynamic() && componentInfo.getDynamicContainerName() != null && componentInfo.getDynamicContainerName().equals(containerInfo.getName())) {
                            // reactivate dynamic component
                            reactivate = true;
                        } else {
                            // read container field
                            String containerName = readStringCharacteristics(componentsDAO, name + "/Container");
                            if (containerName == null) {
                                logger.log(Level.WARNING, "Misconfigured CDB, there is no container of component '" + name + "' defined.");
                            //continue;
                            } else // if container name matches, add (override) activation request
                            if (containerInfo.getName().equals(containerName)) {
                                reactivate = true;
                            }
                        }
                        if (reactivate) {
                            // clean up if in non-recovery mode
                            if (!recoverContainer) {
                                // and if not already in activation list (startup component)
                                if (!activationRequests.containsKey(name)) {
                                    cleanupList.add(componentInfo);
                                    continue;
                                }
                            }
                            // this Component needs reactivation
                            if (activationRequests.containsKey(name)) {
                                activationRequests.put(name, reactivateHandle);
                            } else // put to activation list
                            {
                                try {
                                    activationRequestsList.add(CURLHelper.createURI(name));
                                    activationRequests.put(name, reactivateHandle);
                                } catch (URISyntaxException usi) {
                                    logger.log(Level.WARNING, "Failed to create URI from component name '" + name + "'.", usi);
                                }
                            }
                        }
                    }
                }
            } catch (Throwable ex) {
                CoreException ce = new CoreException("Failed to obtain component data from the CDB.", ex);
                reportException(ce);
            }
        }
    }
    if (cleanupList.size() > 0) {
        Iterator<ComponentInfo> iter = cleanupList.iterator();
        while (iter.hasNext()) {
            ComponentInfo componentInfo = iter.next();
            componentsLock.lock();
            try {
                // remove from its owners list ...
                int[] owners = componentInfo.getClients().toArray();
                for (int j = 0; j < owners.length; j++) removeComponentOwner(componentInfo.getHandle(), owners[j]);
                // ... and deallocate
                executeCommand(new ComponentCommandDeallocate(componentInfo.getHandle() & HANDLE_MASK, componentInfo.getHandle(), WhyUnloadedReason.REMOVED));
                executeCommand(new UnavailableComponentCommandRemove(componentInfo.getName()));
                // remove component from container component list
                synchronized (containerInfo.getComponents()) {
                    if (containerInfo.getComponents().contains(componentInfo.getHandle()))
                        executeCommand(new ContainerInfoCommandComponentRemove(containerInfo.getHandle() & HANDLE_MASK, componentInfo.getHandle()));
                }
            } finally {
                componentsLock.unlock();
            }
        // unbind from remote directory
        //unbind(convertToHiearachical(componentInfo.getName()), "O");
        }
    }
    logger.log(Level.INFO, "Container '" + containerInfo.getName() + "' startup statistics: " + activationRequestsList.size() + " components queued to be activated.");
    // send message to the container
    sendMessage(containerInfo.getContainer(), "Startup statistics: " + activationRequestsList.size() + " components queued to be activated.", MessageType.MSG_INFORMATION, ClientOperations.MSGID_AUTOLOAD_START);
    // activate startup components
    int activated = 0;
    StatusHolder status = new StatusHolder();
    Iterator<URI> iterator = activationRequestsList.iterator();
    while (iterator.hasNext()) {
        URI uri = iterator.next();
        try {
            String name = extractName(uri);
            int requestor = activationRequests.get(name);
            internalRequestComponent(requestor, uri, status);
            if (status.getStatus() != ComponentStatus.COMPONENT_ACTIVATED)
                logger.log(Level.WARNING, "Failed to activate autostart component '" + uri + "', reason: '" + status.getStatus() + "'.");
            else
                activated++;
        } catch (Throwable ex) {
            logger.log(Level.WARNING, "Failed to activate autostart component '" + uri + "'.", ex);
        }
    }
    logger.log(Level.INFO, "Container '" + containerInfo.getName() + "' startup statistics: " + activated + " of " + activationRequestsList.size() + " components activated.");
    // send message to the container
    sendMessage(containerInfo.getContainer(), "Startup statistics: " + activated + " of " + activationRequestsList.size() + " components activated.", MessageType.MSG_INFORMATION, ClientOperations.MSGID_AUTOLOAD_END);
    // notify about new container login
    synchronized (containerLoggedInMonitor) {
        containerLoggedInMonitor.notifyAll();
    }
}
Also used : LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) UnavailableComponentCommandRemove(com.cosylab.acs.maci.manager.recovery.UnavailableComponentCommandRemove) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) StatusHolder(com.cosylab.acs.maci.StatusHolder) ContainerInfoCommandComponentRemove(com.cosylab.acs.maci.manager.recovery.ContainerInfoCommandComponentRemove) DAOProxy(com.cosylab.cdb.client.DAOProxy) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CoreException(com.cosylab.acs.maci.CoreException) ComponentCommandDeallocate(com.cosylab.acs.maci.manager.recovery.ComponentCommandDeallocate) ComponentInfo(com.cosylab.acs.maci.ComponentInfo)

Example 3 with ComponentInfo

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

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

the class ManagerImpl method initialize.

/**
	 * Initializes Manager.
	 * @param	prevayler			implementation of prevayler system
	 * @param	context				remote directory implementation
	 */
public void initialize(Prevayler prevayler, CDBAccess cdbAccess, Context context, final Logger logger, ManagerContainerServices managerContainerServices) {
    this.prevayler = prevayler;
    this.remoteDirectory = context;
    this.logger = logger;
    // needs to be done here, since deserialization is used
    initializeDefaultConfiguration();
    if (cdbAccess != null)
        setCDBAccess(cdbAccess);
    readManagerConfiguration();
    componentsLock = (ProfilingReentrantLock.isProfilingEnabled ? new ProfilingReentrantLock("componentsLock") : new ReentrantLock());
    random = new Random();
    heartbeatTask = new Timer(true);
    delayedDeactivationTask = new Timer(true);
    containerLoggedInMonitor = new Object();
    activationSynchronization = new HashMap<String, ReferenceCountingLock>();
    activationPendingRWLock = new ReaderPreferenceReadWriteLock();
    shutdown = new AtomicBoolean(false);
    threadPool = new ThreadPoolExecutor(poolThreads, poolThreads, Long.MAX_VALUE, TimeUnit.NANOSECONDS, new LinkedBlockingQueue(), new DaemonThreadFactory("managerThreadPool"));
    managerCache = new HashMap<String, Manager>();
    pendingActivations = new HashMap<String, ComponentInfo>();
    pendingContainerShutdown = Collections.synchronizedSet(new HashSet<String>());
    pendingContainerAsyncRequests = new HashMap<String, Deque<ComponentInfoCompletionCallback>>();
    clientMessageQueue = new HashMap<Client, LinkedList<ClientMessageTask>>();
    groupedNotifyTaskMap = new HashMap<Object, GroupedNotifyTask>();
    threadsUsedPercentage = new AtomicInteger(0);
    // create threads
    threadPool.prestartAllCoreThreads();
    // read CDB startup
    try {
        String componentSpec = System.getProperty(NAME_CDB_COMPONENTSPEC);
        if (componentSpec != null) {
            cdbActivation = new ComponentSpec(componentSpec);
            logger.log(Level.INFO, "Using CDB component specification: '" + cdbActivation + "'.");
        }
    } catch (Throwable t) {
        logger.log(Level.WARNING, "Failed to parse '" + NAME_CDB_COMPONENTSPEC + "' variable, " + t.getMessage(), t);
    }
    // check load balancing strategy
    checkLoadBalancingStrategy();
    // establish connect to the alarm system
    try {
        alarmSource = new AlarmSourceImpl(managerContainerServices);
        alarmSource.start();
    } catch (Throwable ex) {
        logger.log(Level.SEVERE, "Failed to initialize Alarm System Interface " + ex.getMessage(), ex);
        alarmSource = null;
    }
    // register ping tasks
    initializePingTasks();
    // handle monitoring removal task
    final long timeInMs = enableHandleMonitoringDurationMins * 60L * 1000;
    if (enableHandleMonitoring && enableHandleMonitoringDurationMins > 0) {
        heartbeatTask.schedule(new TimerTask() {

            @Override
            public void run() {
                try {
                    logHandleCleanup(timeInMs);
                } catch (Throwable th) {
                    logger.log(Level.SEVERE, "Unexpected exception in handle log cleanup task.", th);
                }
            }
        }, 0, timeInMs);
    }
    // start topology sort manager
    topologySortManager = new ComponentInfoTopologicalSortManager(components, containers, activationPendingRWLock, pendingContainerShutdown, threadPool, logger);
    if (prevayler == null)
        statePersitenceFlag.set(false);
    String enDis = statePersitenceFlag.get() ? "enabled" : "disabled";
    logger.info("Manager initialized with state persistence " + enDis + ".");
}
Also used : DaemonThreadFactory(alma.acs.concurrent.DaemonThreadFactory) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) Manager(com.cosylab.acs.maci.Manager) Random(java.util.Random) TimerTask(java.util.TimerTask) AlarmSourceImpl(alma.acs.alarmsystem.source.AlarmSourceImpl) Client(com.cosylab.acs.maci.Client) LinkedHashSet(java.util.LinkedHashSet) HashSet(java.util.HashSet) ReentrantLock(java.util.concurrent.locks.ReentrantLock) ComponentSpec(com.cosylab.acs.maci.ComponentSpec) ArrayDeque(java.util.ArrayDeque) Deque(java.util.Deque) LinkedList(java.util.LinkedList) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Timer(java.util.Timer) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) ComponentInfo(com.cosylab.acs.maci.ComponentInfo)

Example 5 with ComponentInfo

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

the class ManagerImpl method internalDeactivateComponent.

/**
	 * Internal method for deactivating components.
	 *
	 * @param	name	name of the component to be released.
	 */
private void internalDeactivateComponent(String name) {
    // try to acquire lock
    String lockNotAcquiredCause = acquireSynchronizationObject(name, lockTimeout, "deactivate component " + name);
    if (lockNotAcquiredCause == null) {
        boolean releaseRWLock = false;
        try {
            // resolve componentInfo from curl
            ComponentInfo componentInfo = null;
            componentsLock.lock();
            try {
                int h = components.first();
                while (h != 0) {
                    ComponentInfo ci = (ComponentInfo) components.get(h);
                    if (ci.getName().equals(name)) {
                        // a new owner detected, leave component activated
                        if (ci.getClients().size() > 0)
                            return;
                        componentInfo = ci;
                        break;
                    }
                    h = components.next(h);
                }
            } finally {
                componentsLock.unlock();
            }
            // component is already gone, nothing to do
            if (componentInfo == null)
                return;
            // try to acquire activation readers lock first
            // NOTE: the locks are NOT reentrant
            releaseRWLock = true;
            activationPendingRWLock.readLock().lock();
            try {
                internalNoSyncDeactivateComponent(componentInfo);
            } catch (Throwable th) {
            // no handling, already logged
            }
        } 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 : NoResourcesException(com.cosylab.acs.maci.NoResourcesException) ComponentInfo(com.cosylab.acs.maci.ComponentInfo)

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