Search in sources :

Example 1 with NoResourcesException

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

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

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

the class ManagerImpl method internalDeactivateComponent.

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

Example 4 with NoResourcesException

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

the class ManagerImpl method startUpContainer.

/**
	 * Start-up container (if it has a deploy info).
	 * @param containerName	name of the container to start up.
	 * @return container info of container, <code>null</code> if failed to start.
	 */
private ContainerInfo startUpContainer(String containerName) {
    // not to mess with same component name
    final String LOCK_NAME = "container-" + containerName;
    // try to acquire lock
    String lockNotAcquiredCause = acquireSynchronizationObject(LOCK_NAME, lockTimeout, "start-up container " + containerName);
    if (lockNotAcquiredCause == null) {
        try {
            // double check pattern
            ContainerInfo info = getContainerInfo(containerName);
            if (info != null)
                return info;
            return internalNoSyncStartUpContainer(containerName);
        } finally {
            releaseSynchronizationObject(LOCK_NAME);
        }
    } else {
        NoResourcesException nre = new NoResourcesException("Failed to obtain synchronization lock for container '" + containerName + "', possible deadlock; locked to '" + lockNotAcquiredCause + "'.");
        throw nre;
    }
}
Also used : NoResourcesException(com.cosylab.acs.maci.NoResourcesException) ContainerInfo(com.cosylab.acs.maci.ContainerInfo)

Example 5 with NoResourcesException

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

the class ManagerImpl method shutdownContainer.

/**
	 * @see com.cosylab.acs.maci.Manager#shutdownContainer(int, java.lang.String, int)
	 */
public void shutdownContainer(int id, String containerName, int action) throws AcsJNoPermissionEx {
    // check if null
    if (containerName == null) {
        // BAD_PARAM
        BadParametersException af = new BadParametersException("Non-null 'containerName' expected.");
        throw af;
    }
    /****************************************************************/
    // the caller must have SHUTDOWN_SYSTEM access rights,
    securityCheck(id, AccessRights.SHUTDOWN_SYSTEM);
    Container container;
    ContainerInfo containerInfo = getContainerInfo(containerName);
    if (containerInfo == null || (container = containerInfo.getContainer()) == null) {
        // NO_RESOURCES
        NoResourcesException nre = new NoResourcesException("Container '" + containerName + "' not logged in.");
        throw nre;
    }
    pendingContainerShutdown.add(containerInfo.getName());
    try {
        // release components
        try {
            // get shutdown order
            ComponentInfo[] infos = topologySortManager.getComponentShutdownOrder(containerInfo);
            releaseComponents(infos);
        } catch (Throwable th) {
            CoreException ce = new CoreException("Failed to release components on container '" + containerName + "'.", th);
            reportException(ce);
        }
        // shutdown (or disconnect)
        try {
            if (action == 0)
                container.disconnect();
            else
                container.shutdown(action);
        } catch (Throwable th) {
            // NO_RESOURCES
            NoResourcesException nre = new NoResourcesException("Failed to shutdown container '" + containerName + "'.", th);
            throw nre;
        }
    } finally {
        pendingContainerShutdown.remove(containerInfo.getName());
    }
/****************************************************************/
}
Also used : NoResourcesException(com.cosylab.acs.maci.NoResourcesException) Container(com.cosylab.acs.maci.Container) CoreException(com.cosylab.acs.maci.CoreException) ContainerInfo(com.cosylab.acs.maci.ContainerInfo) ComponentInfo(com.cosylab.acs.maci.ComponentInfo) BadParametersException(com.cosylab.acs.maci.BadParametersException)

Aggregations

NoResourcesException (com.cosylab.acs.maci.NoResourcesException)28 AcsJNoPermissionEx (alma.maciErrType.wrappers.AcsJNoPermissionEx)17 BadParametersException (com.cosylab.acs.maci.BadParametersException)17 CoreException (com.cosylab.acs.maci.CoreException)14 BAD_PARAM (org.omg.CORBA.BAD_PARAM)13 UNKNOWN (org.omg.CORBA.UNKNOWN)13 NO_RESOURCES (org.omg.CORBA.NO_RESOURCES)12 AcsJCannotGetComponentEx (alma.maciErrType.wrappers.AcsJCannotGetComponentEx)8 ComponentInfo (com.cosylab.acs.maci.ComponentInfo)8 Object (org.omg.CORBA.Object)8 URI (java.net.URI)7 URISyntaxException (java.net.URISyntaxException)7 ClientInfo (com.cosylab.acs.maci.ClientInfo)5 AcsJBadParameterEx (alma.ACSErrTypeCommon.wrappers.AcsJBadParameterEx)4 Component (com.cosylab.acs.maci.Component)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 ComponentInfo (si.ijs.maci.ComponentInfo)4 AcsJComponentNotAlreadyActivatedEx (alma.maciErrType.wrappers.AcsJComponentNotAlreadyActivatedEx)3 AcsJComponentSpecIncompatibleWithActiveComponentEx (alma.maciErrType.wrappers.AcsJComponentSpecIncompatibleWithActiveComponentEx)3 Container (com.cosylab.acs.maci.Container)3