Search in sources :

Example 1 with RemoteException

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

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

the class ManagerImpl method login.

/**
	 * @see com.cosylab.acs.maci.Manager#login(Client)
	 */
public ClientInfo login(Client reference) throws AcsJNoPermissionEx {
    // check if already shutdown
    if (shutdown.get()) {
        // already shutdown
        AcsJNoPermissionEx npe = new AcsJNoPermissionEx();
        npe.setReason("Manager in shutdown state.");
        throw npe;
    }
    if (reference == null) {
        // BAD_PARAM
        BadParametersException af = new BadParametersException("Non-null 'reference' expected.");
        throw af;
    }
    /****************************************************************/
    ClientInfo info = null;
    try {
        long executionId = generateExecutionId();
        AuthenticationData reply = reference.authenticate(executionId, "Identify yourself");
        if (reply == null) {
            // BAD_PARAM
            BadParametersException af = new BadParametersException("Invalid response to 'Client::authenticate()' method - non-null structure expected.");
            throw af;
        } else if (reply.getClientType() == null) {
            // BAD_PARAM
            BadParametersException af = new BadParametersException("Invalid response to 'Client::authenticate()' method - non-null client type expected.");
            throw af;
        } else if (reply.getImplLang() == null) {
            // BAD_PARAM
            BadParametersException af = new BadParametersException("Invalid response to 'Client::authenticate()' method - no-null implementation language expected.");
            throw af;
        }
        // get client's name
        String name = reference.name();
        if (name == null) {
            // BAD_PARAM
            BadParametersException af = new BadParametersException("Invalid response to 'Client::name()' method - non-null string expected.");
            throw af;
        }
        logger.log(Level.FINE, "'" + name + "' is logging in.");
        final long timeStamp = reply.getTimeStamp() > 0 ? reply.getTimeStamp() : System.currentTimeMillis();
        if (reply.getExecutionId() != 0)
            executionId = generateExecutionId();
        // delegate
        switch(reply.getClientType()) {
            // container
            case CONTAINER:
                if (reference instanceof Container) {
                    info = containerLogin(name, reply, (Container) reference, timeStamp, executionId);
                } else {
                    // NO_PERMISSION
                    AcsJNoPermissionEx npe = new AcsJNoPermissionEx();
                    npe.setReason("Given reply to 'Client::authenticate()' method indicated container login, but given reference does not implement 'maci::Container' interface.");
                    npe.setID(name);
                    throw npe;
                }
                break;
            // client
            case CLIENT:
                info = clientLogin(name, reply, reference, timeStamp, executionId);
                break;
            // supervisor (administrator)
            case ADMINISTRATOR:
                if (reference instanceof Administrator) {
                    info = administratorLogin(name, reply, (Administrator) reference, timeStamp, executionId);
                } else {
                    // NO_PERMISSION
                    AcsJNoPermissionEx npe = new AcsJNoPermissionEx();
                    npe.setReason("Given reply to 'Client::authenticate()' method indicated administrator login, but given reference does not implement 'maci::Administrator' interface.");
                    npe.setID(name);
                    throw npe;
                }
                break;
            default:
                assert (false);
        }
    } catch (AcsJNoPermissionEx npe) {
        throw npe;
    } catch (BadParametersException bpe) {
        throw bpe;
    } catch (NoResourcesException nre) {
        throw nre;
    } catch (RemoteException re) {
        // TODO @todo exception
        RuntimeException rt = new RuntimeException("Exception caught while examining the client. Login rejected.", re);
        throw rt;
    } catch (Throwable ex) {
        // TODO @todo exception
        RuntimeException rt = new RuntimeException("Unexpected exception during login. Login rejected.", ex);
        throw rt;
    }
    /****************************************************************/
    logger.log(Level.FINE, "Client with handle '" + HandleHelper.toString(info.getHandle()) + "' has logged in.");
    return info;
}
Also used : NoResourcesException(com.cosylab.acs.maci.NoResourcesException) Container(com.cosylab.acs.maci.Container) SynchronousAdministrator(com.cosylab.acs.maci.SynchronousAdministrator) Administrator(com.cosylab.acs.maci.Administrator) AcsJNoPermissionEx(alma.maciErrType.wrappers.AcsJNoPermissionEx) AuthenticationData(com.cosylab.acs.maci.AuthenticationData) ClientInfo(com.cosylab.acs.maci.ClientInfo) RemoteException(com.cosylab.acs.maci.RemoteException) TimeoutRemoteException(com.cosylab.acs.maci.TimeoutRemoteException) BadParametersException(com.cosylab.acs.maci.BadParametersException)

Example 3 with RemoteException

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

the class ClientProxyImpl method message.

/**
	 * @see si.ijs.maci.ClientOperations#message(short, String)
	 */
public void message(short type, String message) {
    try {
        MessageType msgType;
        if (type == Client.MSG_ERROR)
            msgType = MessageType.MSG_ERROR;
        else
            msgType = MessageType.MSG_INFORMATION;
        client.message(msgType, message);
    } catch (RemoteException re) {
    // noop.
    }
}
Also used : RemoteException(com.cosylab.acs.maci.RemoteException) MessageType(com.cosylab.acs.maci.MessageType)

Example 4 with RemoteException

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

the class ContainerProxy method activate_component.

/**
	 * @see com.cosylab.acs.maci.Container#activate_component(int, long, String, String, String)
	 */
public ComponentInfo activate_component(int handle, long executionId, String name, String exe, String type) throws AcsJCannotActivateComponentEx {
    try {
        ComponentInfo retVal = null;
        si.ijs.maci.ComponentInfo info;
        try {
            info = container.activate_component(handle, executionId, name, exe, type);
        } catch (CannotActivateComponentEx cannotActivateEx) {
            // and thus have to convert it to its JDK-style peer exception
            throw AcsJCannotActivateComponentEx.fromCannotActivateComponentEx(cannotActivateEx);
        }
        if (info != null) {
            retVal = new ComponentInfo(info.h, info.name, info.type, info.code, info.reference != null ? new ComponentProxy(info.name, info.reference) : null);
            retVal.setContainer(info.container);
            retVal.setContainerName(info.container_name);
            retVal.setAccessRights(inverseMapAccessRights(info.access));
            retVal.setClients(new IntArray(info.clients));
            retVal.setInterfaces(info.interfaces);
        }
        return retVal;
    } catch (TIMEOUT tex) {
        TimeoutRemoteException re = new TimeoutRemoteException("Timout occured while invoking 'activate_component()' method.", tex);
        throw re;
    } catch (org.omg.CORBA.MARSHAL marshalEx) {
        // see http://jira.alma.cl/browse/COMP-4371. Unclear if a parameter was null, or the returned struct was invalid.
        RemoteException re = new RemoteException("Failed to transform the paramters or return value of the container's 'activate_component' method " + "to/from the corba call, using parameters name=" + name + ", exe=" + exe + ", type=" + type, marshalEx);
        throw re;
    } catch (Exception ex) {
        RemoteException re = new RemoteException("Failed to invoke 'activate_component()' method.", ex);
        throw re;
    }
}
Also used : RemoteException(com.cosylab.acs.maci.RemoteException) IOException(java.io.IOException) TimeoutRemoteException(com.cosylab.acs.maci.TimeoutRemoteException) AcsJException(alma.acs.exceptions.AcsJException) AcsJCannotActivateComponentEx(alma.maciErrType.wrappers.AcsJCannotActivateComponentEx) CannotActivateComponentEx(alma.maciErrType.CannotActivateComponentEx) IntArray(com.cosylab.acs.maci.IntArray) TimeoutRemoteException(com.cosylab.acs.maci.TimeoutRemoteException) ComponentInfo(com.cosylab.acs.maci.ComponentInfo) CBComponentInfo(si.ijs.maci.CBComponentInfo) TIMEOUT(org.omg.CORBA.TIMEOUT) RemoteException(com.cosylab.acs.maci.RemoteException) TimeoutRemoteException(com.cosylab.acs.maci.TimeoutRemoteException)

Example 5 with RemoteException

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

the class DaemonProxy method startContainer.

/**
	 * @see com.cosylab.acs.maci.Daemon#startContainer(java.lang.String, java.lang.String, short, java.lang.String)
	 */
public void startContainer(String containerType, String containerName, short instanceNumber, String flags) throws RemoteException {
    try {
        // @TODO: get typeModifiers from the CDB, 
        // see http://www.eso.org/projects/alma/develop/acs/OnlineDocs/ACS_docs/schemas/urn_schemas-cosylab-com_Container_1.0/complexType/DeployInfo.html
        String[] typeModifiers = new String[0];
        daemon.start_container(containerType, containerName, instanceNumber, typeModifiers, flags);
    } catch (Exception ex) {
        RemoteException re = new RemoteException("Failed to invoke 'start_container()' method.", ex);
        throw re;
    }
}
Also used : RemoteException(com.cosylab.acs.maci.RemoteException) RemoteException(com.cosylab.acs.maci.RemoteException) IOException(java.io.IOException)

Aggregations

RemoteException (com.cosylab.acs.maci.RemoteException)21 TimeoutRemoteException (com.cosylab.acs.maci.TimeoutRemoteException)8 ComponentInfo (com.cosylab.acs.maci.ComponentInfo)7 RemoteTransientException (com.cosylab.acs.maci.RemoteTransientException)7 TIMEOUT (org.omg.CORBA.TIMEOUT)7 RemoteTimeoutException (com.cosylab.acs.maci.RemoteTimeoutException)6 IOException (java.io.IOException)6 TRANSIENT (org.omg.CORBA.TRANSIENT)6 AcsJException (alma.acs.exceptions.AcsJException)5 ContainerInfo (com.cosylab.acs.maci.ContainerInfo)4 IntArray (com.cosylab.acs.maci.IntArray)4 BadParametersException (com.cosylab.acs.maci.BadParametersException)3 Container (com.cosylab.acs.maci.Container)3 URI (java.net.URI)3 AcsJNoPermissionEx (alma.maciErrType.wrappers.AcsJNoPermissionEx)2 ClientInfo (com.cosylab.acs.maci.ClientInfo)2 Component (com.cosylab.acs.maci.Component)2 CoreException (com.cosylab.acs.maci.CoreException)2 Manager (com.cosylab.acs.maci.Manager)2 MessageType (com.cosylab.acs.maci.MessageType)2