Search in sources :

Example 6 with CoreException

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

the class ManagerProxyImpl method restart_component.

/**
	 * Restarts an component.
	 * @param	id 	identification of the caller. Called has to be an owner of the component.
	 * @param	component_url	CURL of the component to be restarted.
	 * @return	CORBA reference of the restarted component, <code>null</code> if it fails.
	 */
public Object restart_component(int id, String component_url) throws NoPermissionEx {
    pendingRequests.incrementAndGet();
    try {
        // returned value
        Object retVal = null;
        // transform to CORBA specific
        URI uri = null;
        if (component_url != null)
            uri = CURLHelper.createURI(component_url);
        Component component = manager.restartComponent(id, uri);
        // extract component CORBA reference
        if (component != null)
            retVal = (Object) component.getObject();
        return retVal;
    } catch (URISyntaxException usi) {
        BadParametersException hbpe = new BadParametersException(usi.getMessage(), usi);
        reportException(hbpe);
        // rethrow CORBA specific
        throw new BAD_PARAM(usi.getMessage());
    } catch (BadParametersException bpe) {
        BadParametersException hbpe = new BadParametersException(bpe.getMessage(), bpe);
        reportException(hbpe);
        // rethrow CORBA specific
        throw new BAD_PARAM(bpe.getMessage());
    } catch (NoResourcesException nre) {
        NoResourcesException hnre = new NoResourcesException(nre.getMessage(), nre);
        reportException(hnre);
        // rethrow CORBA specific
        throw new NO_RESOURCES(nre.getMessage());
    } catch (AcsJBadParameterEx bpe) {
        reportException(bpe);
        //throw bpe.toBadParameterEx();
        throw new BAD_PARAM(bpe.getMessage());
    } catch (AcsJNoPermissionEx npe) {
        // rethrow CORBA specific
        throw npe.toNoPermissionEx();
    } catch (Throwable ex) {
        CoreException hce = new CoreException(ex.getMessage(), ex);
        reportException(hce);
        // rethrow CORBA specific
        throw new UNKNOWN(ex.getMessage());
    } finally {
        pendingRequests.decrementAndGet();
    }
}
Also used : AcsJBadParameterEx(alma.ACSErrTypeCommon.wrappers.AcsJBadParameterEx) BAD_PARAM(org.omg.CORBA.BAD_PARAM) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) BadParametersException(com.cosylab.acs.maci.BadParametersException) NoResourcesException(com.cosylab.acs.maci.NoResourcesException) AcsJNoPermissionEx(alma.maciErrType.wrappers.AcsJNoPermissionEx) CoreException(com.cosylab.acs.maci.CoreException) Object(org.omg.CORBA.Object) UNKNOWN(org.omg.CORBA.UNKNOWN) Component(com.cosylab.acs.maci.Component) NO_RESOURCES(org.omg.CORBA.NO_RESOURCES)

Example 7 with CoreException

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

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

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

the class ManagerImpl method bind.

/**
	 * Bind object to remote directory.
	 *
	 * Use INS syntax specified in the INS specification.
	 * In short, the syntax is that components are left-to-right slash ('/') separated and case-sensitive.
	 * The id and kind of each component are separated by the period character ('.').
	 *
	 * @param	remoteDirectory	remote directory context to be used.
	 * @param	name	name of the object, code non-<code>null</code>
	 * @param	object	object to be binded
	 */
private void bind(Context remoteDirectory, String name, String type, Object object) {
    assert (name != null);
    // do not bind interdomain names
    if (name.startsWith(CURL_URI_SCHEMA))
        return;
    if (remoteDirectory != null) {
        try {
            // hierarchical name check
            int pos = name.indexOf('/');
            if (pos != -1) {
                if (pos == 0 || pos == name.length())
                    throw new IllegalArgumentException("Invalid hierarchical name '" + name + "'.");
                String parent = name.substring(0, pos);
                String child = name.substring(pos + 1);
                // lookup for subcontext, if not found create one
                Context parentContext = null;
                try {
                    parentContext = (Context) remoteDirectory.lookup(parent);
                } catch (NameNotFoundException nnfe) {
                // noop
                }
                if (parentContext == null) {
                    parentContext = remoteDirectory.createSubcontext(parent);
                /// @todo temp. commented out
                //generateHiearchyContexts(remoteDirectory, parent, parentContext);
                }
                // delegate
                bind(parentContext, child, type, object);
                return;
            }
            NameParser parser = remoteDirectory.getNameParser("");
            Name n;
            if (type != null)
                n = parser.parse(name + "." + type);
            else
                n = parser.parse(name);
            // special case
            if (name.endsWith(".D")) {
                remoteDirectory.rebind(n, object);
            /// @todo temp. commented out
            //generateHiearchyContexts(remoteDirectory, name, (Context)remoteDirectory.lookup(name));
            } else
                remoteDirectory.bind(n, object);
        } catch (NameAlreadyBoundException nabe) {
            rebind(remoteDirectory, name, type, object);
        } catch (NamingException ne) {
            CoreException ce = new CoreException("Failed to bind name '" + name + "' to the remote directory.", ne);
            logger.log(Level.FINE, ce.getMessage(), ce);
        }
    }
}
Also used : InitialContext(javax.naming.InitialContext) Context(javax.naming.Context) NameAlreadyBoundException(javax.naming.NameAlreadyBoundException) CoreException(com.cosylab.acs.maci.CoreException) NameNotFoundException(javax.naming.NameNotFoundException) NamingException(javax.naming.NamingException) NameParser(javax.naming.NameParser) Name(javax.naming.Name)

Example 10 with CoreException

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

Aggregations

CoreException (com.cosylab.acs.maci.CoreException)33 BadParametersException (com.cosylab.acs.maci.BadParametersException)18 NoResourcesException (com.cosylab.acs.maci.NoResourcesException)18 AcsJNoPermissionEx (alma.maciErrType.wrappers.AcsJNoPermissionEx)14 URISyntaxException (java.net.URISyntaxException)13 BAD_PARAM (org.omg.CORBA.BAD_PARAM)13 UNKNOWN (org.omg.CORBA.UNKNOWN)13 URI (java.net.URI)12 NO_RESOURCES (org.omg.CORBA.NO_RESOURCES)12 NamingException (javax.naming.NamingException)8 Object (org.omg.CORBA.Object)8 AcsJException (alma.acs.exceptions.AcsJException)6 AcsJCannotGetComponentEx (alma.maciErrType.wrappers.AcsJCannotGetComponentEx)6 NoDefaultComponentException (com.cosylab.acs.maci.NoDefaultComponentException)6 DAOProxy (com.cosylab.cdb.client.DAOProxy)6 Component (com.cosylab.acs.maci.Component)5 ComponentInfo (com.cosylab.acs.maci.ComponentInfo)5 RemoteException (com.cosylab.acs.maci.RemoteException)5 StatusHolder (com.cosylab.acs.maci.StatusHolder)5 TimeoutRemoteException (com.cosylab.acs.maci.TimeoutRemoteException)5