Search in sources :

Example 1 with ClientInfo

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

the class ManagerImpl method getClients.

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

Example 2 with ClientInfo

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

the class ManagerImpl method getClientInfo.

/**
	 * @see com.cosylab.acs.maci.Manager#getClientInfo(int, int[], String)
	 */
public ClientInfo[] getClientInfo(int id, int[] handles, String name_wc) 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) {
        // BAD_PARAM
        BadParametersException af = new BadParametersException("Non-null 'names_wc' sequence expected.");
        throw af;
    }
    /*
		Pattern pattern = null;
		if (handles.length == 0 && name_wc != null)
		{
			// test wildcard patten (try to compile it)
			try
			{
				pattern = Pattern.compile(name_wc);
			}
			catch (Exception ex)
			{
				// BAD_PARAM
				BadParametersException af = new BadParametersException("Failed to compile 'names_wc' reqular expression string '"+name_wc+"'.");
				af.caughtIn(this, "getClientInfo");
				af.putValue("name_wc", name_wc);
				throw af;
			}
		}
*/
    /****************************************************************/
    // info to be returned
    ClientInfo[] info = null;
    // requesting info. about itself
    if (handles.length == 1 && handles[0] == id) {
        // check handle, no special rights for own info
        securityCheck(id, 0);
        info = new ClientInfo[1];
        info[0] = getClientInfo(id);
    } else // get info of requested handles
    if (handles.length > 0) {
        // check handle, INTROSPECT_MANAGER rights needed
        securityCheck(id, AccessRights.INTROSPECT_MANAGER);
        info = new ClientInfo[handles.length];
        for (int i = 0; i < handles.length; i++) info[i] = getClientInfo(handles[i]);
    } else // get info requested using name wildcard
    {
        // check handle, INTROSPECT_MANAGER rights needed
        securityCheck(id, AccessRights.INTROSPECT_MANAGER);
        // list of clients matching search pattern
        ArrayList<ClientInfo> list = new ArrayList<ClientInfo>();
        // check clients
        synchronized (clients) {
            int h = clients.first();
            while (h != 0) {
                ClientInfo clientInfo = (ClientInfo) clients.get(h);
                /*
					Matcher m = pattern.matcher(clientInfo.getName());
					if (m.matches())
					*/
                if (WildcharMatcher.match(name_wc, clientInfo.getName()))
                    list.add(clientInfo);
                h = clients.next(h);
            }
        }
        // check administrators
        synchronized (administrators) {
            int h = administrators.first();
            while (h != 0) {
                ClientInfo clientInfo = (ClientInfo) administrators.get(h);
                /*
					Matcher m = pattern.matcher(clientInfo.getName());
					if (m.matches())
					*/
                if (WildcharMatcher.match(name_wc, clientInfo.getName()))
                    list.add(clientInfo);
                h = administrators.next(h);
            }
        }
        // copy to array
        info = new ClientInfo[list.size()];
        list.toArray(info);
    }
    return info;
}
Also used : ArrayList(java.util.ArrayList) ClientInfo(com.cosylab.acs.maci.ClientInfo) BadParametersException(com.cosylab.acs.maci.BadParametersException)

Example 3 with ClientInfo

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

the class ManagerImpl method administratorLogin.

/**
	 * Administrator specific login method.
	 * @param	name	name of the administrator
	 * @param	reply	reply to authenticate method
	 * @param	administrator	administrator that is logging in
	 * @return	ClientInfo	client info. of newly logged administrator
	 */
private ClientInfo administratorLogin(String name, AuthenticationData reply, Administrator administrator, long timeStamp, long executionId) throws AcsJNoPermissionEx {
    assert (name != null);
    assert (administrator != null);
    TimerTaskClientInfo clientInfo = null;
    synchronized (administrators) {
        // check if administrator is already logged in,
        // if it is, return existing info
        int h = administrators.first();
        while (h != 0) {
            ClientInfo loggedAdministratorInfo = (ClientInfo) administrators.get(h);
            if (administrator.equals(loggedAdministratorInfo.getClient()))
                return loggedAdministratorInfo;
            h = administrators.next(h);
        }
        // allocate new handle
        // !!! ACID 2
        Integer objHandle = (Integer) executeCommand(new AdministratorCommandAllocate());
        int handle;
        //int handle = administrators.allocate();
        if (objHandle == null || (handle = objHandle.intValue()) == 0) {
            NoResourcesException af = new NoResourcesException("Generation of new handle failed, too many administrators logged in.");
            throw af;
        }
        // generate external handle
        h = handle | ADMINISTRATOR_MASK;
        // add generated key
        h |= (random.nextInt(0x100)) << 16;
        // create new client info
        clientInfo = new TimerTaskClientInfo(h, name, administrator);
        clientInfo.setAccessRights(AccessRights.REGISTER_COMPONENT | AccessRights.INTROSPECT_MANAGER | AccessRights.SHUTDOWN_SYSTEM);
        // register administrator to the heartbeat manager
        PingTimerTask task = new PingTimerTask(this, logger, clientInfo, null);
        clientInfo.setTask(task);
        heartbeatTask.schedule(task, administratorPingInterval, administratorPingInterval);
        // !!! ACID - register AddAdministratorCommand
        executeCommand(new AdministratorCommandSet(handle, clientInfo));
    // store info
    //administrators.set(handle, clientInfo);
    }
    // notify administrators about the login
    notifyClientLogin(clientInfo, timeStamp, executionId);
    logger.log(Level.INFO, "Administrator '" + name + "' logged in.");
    return clientInfo;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AdministratorCommandAllocate(com.cosylab.acs.maci.manager.recovery.AdministratorCommandAllocate) NoResourcesException(com.cosylab.acs.maci.NoResourcesException) AdministratorCommandSet(com.cosylab.acs.maci.manager.recovery.AdministratorCommandSet) ClientInfo(com.cosylab.acs.maci.ClientInfo)

Example 4 with ClientInfo

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

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

the class ManagerImpl method initializePingTasks.

/**
	 * Initialized (registers) all ping tasks (to completely recover).
	 */
private void initializePingTasks() {
    // go through all the containers, clients, administrators and register ping tasks,
    // reference of classes are already in TimerTaskContainerInfo/TimerTaskClientInfo
    // TODO some admin references can be null !!!
    // containers
    TimerTaskContainerInfo containerInfo = null;
    int h = containers.first();
    while (h != 0) {
        containerInfo = (TimerTaskContainerInfo) containers.get(h);
        h = containers.next(h);
        // if deserialization failed, logout container
        ClientInfo clientInfo = containerInfo.createClientInfo();
        // register container to the heartbeat manager
        PingTimerTask task = new PingTimerTask(this, logger, clientInfo, alarmSource);
        containerInfo.setTask(task);
        heartbeatTask.schedule(task, 0, containerInfo.getPingInterval());
    }
    // administrators
    TimerTaskClientInfo adminInfo = null;
    h = administrators.first();
    while (h != 0) {
        adminInfo = (TimerTaskClientInfo) administrators.get(h);
        h = administrators.next(h);
        // register administrator to the heartbeat manager
        PingTimerTask task = new PingTimerTask(this, logger, adminInfo, null);
        adminInfo.setTask(task);
        heartbeatTask.schedule(task, 0, administratorPingInterval);
    }
    // clients
    TimerTaskClientInfo clientInfo = null;
    h = clients.first();
    while (h != 0) {
        clientInfo = (TimerTaskClientInfo) clients.get(h);
        h = clients.next(h);
        // register client to the heartbeat manager
        PingTimerTask task = new PingTimerTask(this, logger, clientInfo, null);
        clientInfo.setTask(task);
        heartbeatTask.schedule(task, 0, clientPingInterval);
    }
}
Also used : ClientInfo(com.cosylab.acs.maci.ClientInfo)

Aggregations

ClientInfo (com.cosylab.acs.maci.ClientInfo)56 AcsJNoPermissionEx (alma.maciErrType.wrappers.AcsJNoPermissionEx)39 BadParametersException (com.cosylab.acs.maci.BadParametersException)23 ComponentInfo (com.cosylab.acs.maci.ComponentInfo)23 NoResourcesException (com.cosylab.acs.maci.NoResourcesException)21 HashMap (java.util.HashMap)21 Map (java.util.Map)21 Component (com.cosylab.acs.maci.Component)18 RemoteException (com.cosylab.acs.maci.RemoteException)18 URI (java.net.URI)18 NoDefaultComponentException (com.cosylab.acs.maci.NoDefaultComponentException)17 URISyntaxException (java.net.URISyntaxException)17 StatusHolder (com.cosylab.acs.maci.StatusHolder)16 AcsJBadParameterEx (alma.ACSErrTypeCommon.wrappers.AcsJBadParameterEx)8 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)8 AcsJCannotGetComponentEx (alma.maciErrType.wrappers.AcsJCannotGetComponentEx)7 ContainerInfo (com.cosylab.acs.maci.ContainerInfo)7 ArrayList (java.util.ArrayList)7 Client (com.cosylab.acs.maci.Client)6 Administrator (com.cosylab.acs.maci.Administrator)5