Search in sources :

Example 1 with DAOProxy

use of com.cosylab.cdb.client.DAOProxy 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 DAOProxy

use of com.cosylab.cdb.client.DAOProxy 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 DAOProxy

use of com.cosylab.cdb.client.DAOProxy in project ACS by ACS-Community.

the class ManagerImpl method searchDynamicComponent.

/**
	 * Searches for the best match in Components entry in the CDB.
	 *
	 * @param fieldNames		array of fields names to be searched.
	 * @param requiredValues	required values of fields, if <code>ComponentSpec.COMPSPEC_ANY</code> any value is accepted.
	 * @param equalityRequired	<code>true</code> if <code>requiredValues[i]</code> and <code>fieldNames[i]<code> value values must match,
	 * 							i.e. String.equals(String) is used.
	 * @param equalityPoints	array of points to be given to each field whose value is equal to the CDB value,
	 * 							used to determine best match.
	 * @return					best match found in the CDB, <code>null</code> on failure or if not found.
	 */
private String[] searchDynamicComponent(String[] fieldNames, String[] requiredValues, boolean[] equalityRequired, int[] equalityPoints, IntHolder keepAliveTimeHolder) {
    assert (fieldNames != null);
    assert (equalityRequired != null);
    assert (equalityPoints != null);
    assert (fieldNames.length == equalityRequired.length);
    assert (equalityRequired.length == equalityPoints.length);
    DAOProxy componentsDAO = getComponentsDAOProxy();
    if (componentsDAO == null)
        return null;
    // get field IDs for all components
    String[] fieldIDs = null;
    try {
        /// @todo here to check if CDB is available
        componentsDAO.get_field_data("");
        /*fieldIDs =*/
        fieldIDs = getComponentsList();
    } catch (Exception ex) {
        CoreException af = new CoreException("Failed to retrieve data from CDB.", ex);
        reportException(af);
        return null;
    }
    int len = fieldNames.length;
    int maxPoints = Integer.MIN_VALUE;
    String[] bestMatch = null;
    String[] currentMatch = new String[len];
    int bestMatchKeepAliveTime = RELEASE_TIME_UNDEFINED;
    // for each entry
    for (int fi = 0; fi < fieldIDs.length; fi++) {
        // for each field
        int i = 0;
        int points = 0;
        for (; i < len; i++) {
            /// @todo not nice way, but necessary to have hierarchical names
            //String fieldValue = readStringCharacteristics(componentsDAO, fieldIDs[fi]+"/"+fieldNames[i], true);
            boolean processingNameField = "Name".equals(fieldNames[i]);
            String fieldValue = null;
            if (processingNameField) {
                // problems are multiple "*" (or other duplicated names) -> "*<number>", so reading CDB is necessary
                if (Character.isDigit(fieldIDs[fi].charAt(fieldIDs[fi].length() - 1))) {
                    String readFieldValue = readStringCharacteristics(componentsDAO, fieldIDs[fi] + "/Name", true);
                    fieldValue = fieldIDs[fi].substring(0, fieldIDs[fi].indexOf(readFieldValue) + readFieldValue.length());
                } else
                    fieldValue = fieldIDs[fi];
            } else
                fieldValue = readStringCharacteristics(componentsDAO, fieldIDs[fi] + "/" + fieldNames[i], true);
            if (fieldValue == null)
                break;
            boolean equals = requiredValues[i].equals(fieldValue);
            // required equality
            if (equalityRequired[i]) {
                // reject entry
                if (!equals)
                    break;
                currentMatch[i] = fieldValue;
            } else // optional equality brings points
            {
                /* override
					// first check required value condition
					if (!equals &&
						!(requiredValues[i].equals(ComponentSpec.COMPSPEC_ANY) ||
						  fieldValue.equals(ComponentSpec.COMPSPEC_ANY)))
						break;
					*/
                currentMatch[i] = fieldValue;
                if (equals)
                    points += equalityPoints[i];
                else // note that name cannot be overriden
                if (processingNameField && (fieldValue.indexOf(ComponentSpec.COMPSPEC_ANY) == -1 || !WildcharMatcher.match(fieldValue, requiredValues[i])))
                    break;
            }
        }
        // if not rejected and best
        if (i == len && points > maxPoints) {
            maxPoints = points;
            if (bestMatch == null)
                bestMatch = new String[len];
            System.arraycopy(currentMatch, 0, bestMatch, 0, len);
            bestMatchKeepAliveTime = readLongCharacteristics(componentsDAO, fieldIDs[fi] + "/KeepAliveTime", RELEASE_TIME_UNDEFINED, true);
        }
    }
    keepAliveTimeHolder.value = bestMatchKeepAliveTime;
    return bestMatch;
}
Also used : CoreException(com.cosylab.acs.maci.CoreException) DAOProxy(com.cosylab.cdb.client.DAOProxy) 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)

Example 4 with DAOProxy

use of com.cosylab.cdb.client.DAOProxy in project ACS by ACS-Community.

the class ManagerImpl method internalNoSyncReleaseComponent.

/**
	 * Internal method for releasing components.
	 *
	 * @param	owner	owner of the component.
	 * @param	h		handle of the component to be released.
	 * @param	force	force deactivate, if still has owners then component will be made unavailable.
	 * @return			Number of clients that are still using the component after the operation completed.
	 */
private ReleaseComponentResult internalNoSyncReleaseComponent(int owner, int h, boolean force) throws AcsJNoPermissionEx {
    int handle = h & HANDLE_MASK;
    int owners = 0;
    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)) {
            if (!force) {
                // not an owner
                AcsJNoPermissionEx npe = new AcsJNoPermissionEx();
                npe.setReason("Unregistering component that client does not own.");
                npe.setID(HandleHelper.toString(owner));
                npe.setProtectedResource(componentInfo.getName());
                throw npe;
            }
        } else {
            // ACID - !!!
            // remove client/component as an owner
            executeCommand(new ComponentCommandClientRemove(componentInfo.getHandle() & HANDLE_MASK, owner));
            // remove component from client component list
            if (owner != this.getHandle())
                removeComponentOwner(componentInfo.getHandle(), owner);
        }
        owners = componentInfo.getClients().size();
        if (owners == 0) {
            // there is not owner to be unavailable for
            synchronized (unavailableComponents) {
                if (unavailableComponents.containsKey(componentInfo.getName())) {
                    // !!! ACID
                    executeCommand(new UnavailableComponentCommandRemove(componentInfo.getName()));
                //unavailableComponents.remove(componentInfo.getName());
                }
            }
        }
    } finally {
        componentsLock.unlock();
    }
    /****************** component deactivation ******************/
    ReleaseComponentResult result = new ReleaseComponentResult(owners, null);
    // there is no owners of the component, deactivate it
    if (force) {
        try {
            internalNoSyncDeactivateComponent(componentInfo);
        } catch (Throwable th) {
            result.exception = th;
        }
    } else if (owners == 0) {
        int keepAliveTime = RELEASE_IMMEDIATELY;
        String name = componentInfo.getName();
        boolean isOtherDomainComponent = name.startsWith(CURL_URI_SCHEMA);
        if (!isOtherDomainComponent) {
            keepAliveTime = componentInfo.getKeepAliveTime();
            if (keepAliveTime == RELEASE_TIME_UNDEFINED) {
                // when info is passed from the container
                DAOProxy dao = getComponentsDAOProxy();
                if (dao != null)
                    keepAliveTime = readLongCharacteristics(dao, name + "/KeepAliveTime", RELEASE_IMMEDIATELY, true);
                else
                    keepAliveTime = RELEASE_IMMEDIATELY;
            }
        }
        if (keepAliveTime == 0) {
            try {
                internalNoSyncDeactivateComponent(componentInfo);
            } catch (Throwable th) {
                result.exception = th;
            }
        } else if (keepAliveTime > 0)
            delayedDeactivationTask.schedule(new DeactivateComponentTask(name), keepAliveTime * 1000);
    // negative means immortal, however this could not happen since immortal
    // components have manager as an owner
    }
    /// TODO !!!!!!!!!!!!!! no more handle -> componentInfo data
    // notify administrators about the release request
    notifyComponentReleased(new int[] { owner }, new int[] { h }, System.currentTimeMillis());
    logger.log(Level.FINE, "Component '" + componentInfo.getName() + "' (" + HandleHelper.toString(componentInfo.getHandle()) + ") released.");
    // component deactivated
    if (owners == 0 || force) {
        topologySortManager.notifyTopologyChange(componentInfo.getContainer());
    } else if ((owner & TYPE_MASK) == COMPONENT_MASK) {
        // component dependency changed...
        // notify about the change (only if on the same container)...
        // on complete system shutdown sort will be done anyway
        ComponentInfo ownerComponentInfo = getComponentInfo(owner);
        if (ownerComponentInfo != null && ownerComponentInfo.getContainerName() != null && ownerComponentInfo.getContainerName().equals(componentInfo.getContainerName()))
            topologySortManager.notifyTopologyChange(componentInfo.getContainer());
    }
    return result;
}
Also used : AcsJNoPermissionEx(alma.maciErrType.wrappers.AcsJNoPermissionEx) UnavailableComponentCommandRemove(com.cosylab.acs.maci.manager.recovery.UnavailableComponentCommandRemove) ComponentInfo(com.cosylab.acs.maci.ComponentInfo) ComponentCommandClientRemove(com.cosylab.acs.maci.manager.recovery.ComponentCommandClientRemove) DAOProxy(com.cosylab.cdb.client.DAOProxy) BadParametersException(com.cosylab.acs.maci.BadParametersException)

Example 5 with DAOProxy

use of com.cosylab.cdb.client.DAOProxy in project ACS by ACS-Community.

the class ManagerImpl method readManagerConfiguration.

/**
	 * Read manager configuration.
	 */
private void readManagerConfiguration() {
    enableHandleMonitoring = System.getProperties().containsKey(NAME_HANDLE_MONITORING);
    enableHandleMonitoringDurationMins = Integer.getInteger(NAME_HANDLE_MONITORING_TIME, HANDLE_MONITORING_TIME_MIN);
    DAOProxy managerDAO = getManagerDAOProxy();
    if (managerDAO == null)
        return;
    clientPingInterval = (int) (readDoubleCharacteristics(managerDAO, "ClientPingInterval", clientPingInterval / (double) 1000, true) * 1000);
    clientPingInterval = Math.max(1000, clientPingInterval);
    administratorPingInterval = (int) (readDoubleCharacteristics(managerDAO, "AdministratorPingInterval", administratorPingInterval / (double) 1000, true) * 1000);
    administratorPingInterval = Math.max(1000, administratorPingInterval);
    containerPingInterval = (int) (readDoubleCharacteristics(managerDAO, "ContainerPingInterval", containerPingInterval / (double) 1000, true) * 1000);
    containerPingInterval = Math.max(1000, containerPingInterval);
    try {
        String strTimeOut = System.getProperty("jacorb.connection.client.pending_reply_timeout");
        if (strTimeOut != null) {
            long t = Long.valueOf(strTimeOut);
            if (t > 0) {
                // add 1 minute
                lockTimeout = t + 60000;
                // check for overflow
                if (lockTimeout < 0)
                    lockTimeout = Long.MAX_VALUE;
            }
        }
    } catch (Throwable th) {
    // noop (left default)
    }
    poolThreads = readLongCharacteristics(managerDAO, "ServerThreads", poolThreads, true);
    poolThreads = Math.max(3, poolThreads);
}
Also used : DAOProxy(com.cosylab.cdb.client.DAOProxy)

Aggregations

DAOProxy (com.cosylab.cdb.client.DAOProxy)19 ComponentInfo (com.cosylab.acs.maci.ComponentInfo)6 CoreException (com.cosylab.acs.maci.CoreException)6 ContainerInfo (com.cosylab.acs.maci.ContainerInfo)5 URI (java.net.URI)5 StatusHolder (com.cosylab.acs.maci.StatusHolder)4 TimeoutRemoteException (com.cosylab.acs.maci.TimeoutRemoteException)4 URISyntaxException (java.net.URISyntaxException)4 AcsJCannotGetComponentEx (alma.maciErrType.wrappers.AcsJCannotGetComponentEx)3 BadParametersException (com.cosylab.acs.maci.BadParametersException)3 NoDefaultComponentException (com.cosylab.acs.maci.NoDefaultComponentException)3 LinkedHashSet (java.util.LinkedHashSet)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 AcsJException (alma.acs.exceptions.AcsJException)2 Container (com.cosylab.acs.maci.Container)2 ImplLang (com.cosylab.acs.maci.ImplLang)2 NoResourcesException (com.cosylab.acs.maci.NoResourcesException)2 RemoteException (com.cosylab.acs.maci.RemoteException)2 RemoteTransientException (com.cosylab.acs.maci.RemoteTransientException)2 UnavailableComponentCommandRemove (com.cosylab.acs.maci.manager.recovery.UnavailableComponentCommandRemove)2