Search in sources :

Example 6 with NoResourcesException

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

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

the class ManagerImplTest method testContainerShutdown.

public void testContainerShutdown() {
    try {
        manager.shutdownContainer(0, null, 0);
        fail();
    } catch (AcsJNoPermissionEx npe) {
        fail("No permission");
    } catch (BadParametersException bpe) {
        System.out.println("This is OK: " + bpe.getMessage());
    }
    try {
        manager.shutdownContainer(0, "test", 0);
        fail();
    } catch (AcsJNoPermissionEx npe) {
        System.out.println("This is OK: " + npe.toString());
    }
    Client client = new TestClient(clientName);
    ClientInfo info = null;
    try {
        info = manager.login(client);
    } catch (AcsJNoPermissionEx e) {
        fail();
    }
    try {
        manager.shutdownContainer(info.getHandle(), "test", 0);
        fail();
    } catch (AcsJNoPermissionEx npe) {
        System.out.println("This is OK: " + npe.toString());
    }
    Administrator admin = new TestAdministrator("shutdownAdmin");
    ClientInfo info2 = null;
    try {
        info2 = manager.login(admin);
    } catch (AcsJNoPermissionEx e) {
        fail("No permission");
    }
    try {
        manager.shutdownContainer(info2.getHandle(), null, 0);
        fail();
    } catch (AcsJNoPermissionEx npe) {
        fail("No permission");
    } catch (BadParametersException bpe) {
        System.out.println("This is OK: " + bpe.getMessage());
    }
    try {
        manager.shutdownContainer(info2.getHandle(), "invalid", 0);
        fail();
    } catch (AcsJNoPermissionEx npe) {
        fail("No permission");
    } catch (NoResourcesException nre) {
        System.out.println("This is OK: " + nre.getMessage());
    }
    TestContainer container = new TestContainer("Container");
    Map supportedComponents = new HashMap();
    TestComponent mount1COB = new TestComponent("MOUNT1");
    supportedComponents.put("MOUNT1", mount1COB);
    container.setSupportedComponents(supportedComponents);
    try {
        ClientInfo containerInfo = manager.login(container);
    } catch (AcsJNoPermissionEx e) {
        fail("No permission");
    }
    try {
        Thread.sleep(STARTUP_COBS_SLEEP_TIME_MS);
    } catch (InterruptedException ie) {
    }
    // test activated Components
    ComponentInfo[] infos = null;
    try {
        infos = manager.getComponentInfo(info.getHandle(), new int[0], "*", "*", true);
    } catch (AcsJNoPermissionEx e) {
        fail("No permission");
    }
    assertEquals(1, infos.length);
    try {
        manager.shutdownContainer(info.getHandle(), "Container", 0);
        fail();
    } catch (AcsJNoPermissionEx npe) {
        System.out.println("This is OK: " + npe.toString());
    }
    try {
        manager.shutdownContainer(info2.getHandle(), "Container", 1);
    } catch (AcsJNoPermissionEx e) {
        fail("No permission");
    }
    assertEquals(0, container.getActivatedComponents().size());
}
Also used : HashMap(java.util.HashMap) BadParametersException(com.cosylab.acs.maci.BadParametersException) NoResourcesException(com.cosylab.acs.maci.NoResourcesException) Administrator(com.cosylab.acs.maci.Administrator) AcsJNoPermissionEx(alma.maciErrType.wrappers.AcsJNoPermissionEx) ClientInfo(com.cosylab.acs.maci.ClientInfo) ComponentInfo(com.cosylab.acs.maci.ComponentInfo) Client(com.cosylab.acs.maci.Client) HashMap(java.util.HashMap) Map(java.util.Map)

Example 8 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 9 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 10 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)

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