Search in sources :

Example 21 with CoreException

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

the class ManagerImpl method shutdown.

/**
	 * @see com.cosylab.acs.maci.Manager#shutdown(int, int)
	 */
public void shutdown(int id, int containers) throws AcsJNoPermissionEx {
    // check handle and SHUTDOWN_SYSTEM permissions
    securityCheck(id, AccessRights.SHUTDOWN_SYSTEM);
    if (id == MANAGER_MASK)
        id = originalId;
    else
        originalId = id;
    if (containers == 0)
        containers = originalContainers;
    else
        originalContainers = containers;
    // if application is not destroying already, destroy it
    if (shutdownImplementation != null && !shutdownImplementation.isShutdownInProgress()) {
        // spawn another thread
        new Thread(new Runnable() {

            public void run() {
                // fire destroy application
                if (!shutdownImplementation.isShutdownInProgress())
                    shutdownImplementation.shutdown(false);
            }
        }, "ManagerApplicationShutdown").start();
        return;
    }
    // check if already shutdown
    if (shutdown.getAndSet(true)) {
        // already shutdown
        AcsJNoPermissionEx npe = new AcsJNoPermissionEx();
        npe.setReason("Manager already in shutdown state.");
        npe.setID(HandleHelper.toString(id));
        throw npe;
    }
    /****************************************************************/
    logger.log(Level.INFO, "Manager is shutting down.");
    logger.log(Level.FINER, "Canceling heartbeat task.");
    // cancel hertbeat task
    heartbeatTask.cancel();
    topologySortManager.destroy();
    // if not "silent" shutdown
    if (containers != 0) {
        logger.log(Level.FINER, "Releasing all components in the system.");
        try {
            topologySortManager.requestTopologicalSort();
            releaseComponents(topologySortManager.getComponentShutdownOrder(null));
        } catch (Throwable th) {
            CoreException ce = new CoreException("Failed to release all components in the system.", th);
            reportException(ce);
        }
    }
    logger.log(Level.FINER, "Notifying containers to disconnect or shutdown.");
    notifyContainerDisconnectShutdown(containers);
    // finalizeFearation
    finalizeFederation();
    // process tasks in thread pool
    // !!! NOTE: this could block (for a long time)
    logger.log(Level.FINER, "Waiting for tasks in thread pool to complete...");
    threadPool.shutdown();
    try {
        if (!threadPool.awaitTermination(3, TimeUnit.SECONDS))
            threadPool.shutdownNow();
    } catch (InterruptedException ie) {
    /* noop */
    }
    if (alarmSource != null) {
        alarmSource.tearDown();
    }
    // unbind Manager
    unbind("Manager", null);
    setCDBAccess(null);
    // release CDB DAO daos
    destroyComponetsDAOProxy();
    destroyContainersDAOProxy();
    destroyManagerDAOProxy();
    logger.log(Level.INFO, "Manager shutdown completed.");
/****************************************************************/
}
Also used : AcsJNoPermissionEx(alma.maciErrType.wrappers.AcsJNoPermissionEx) CoreException(com.cosylab.acs.maci.CoreException)

Example 22 with CoreException

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

the class ManagerImpl method rebind.

/**
     * @param remoteDirectory	parent context of parentContext.
     * @param parent			name of context to bind.
     * @param parentContext		context to bind.
     * @throws NamingException
     *
    private void generateHiearchyContexts(Context remoteDirectory, String parent, Context parentContext) throws NamingException
    {
        /// @todo CORBA specific
        if (remoteDirectory instanceof com.sun.jndi.cosnaming.CNCtx)
        {
            boolean isParentDomain = remoteDirectory.getNameInNamespace().length() == 0 ||
            						 remoteDirectory.getNameInNamespace().endsWith(".D");

            org.omg.CORBA.Object parentRepresentation = ((com.sun.jndi.cosnaming.CNCtx)remoteDirectory)._nc;
            if (parent.endsWith(".D"))
            {
                // domain binding
                parentContext.rebind("Parent.D", parentRepresentation);
            }
            else if (parent.endsWith(".F"))
            {
                // hierarchical component binding
                if (isParentDomain)
                    parentContext.rebind("Domain.D", parentRepresentation);
                else
                    parentContext.rebind("Domain.D", remoteDirectory.lookup("Domain.D"));
                parentContext.rebind("Parent.F", parentRepresentation);
            }
        }
        else if (remoteDirectory instanceof InitialContext)
            generateHiearchyContexts((Context)((InitialContext)remoteDirectory).lookup(""), parent, parentContext);
        else
            new MessageLogEntry(this, "generateHiearchyContexts", "Unsupported remote directory, class '" + remoteDirectory.getClass().getName() + "'.", Level.WARNING).dispatch();
    }*/
/**
	 * Rebind object to the root of 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 ('.').
	 * NOTE: Does not support hierarchical names.
	 *
	 * @param	name	name of the object, code non-<code>null</code>
	 * @param	type	type of the object
	 * @param	object	object to be binded
	 *
	private void rebind(String name, String type, Object object)
	{
	    rebind(remoteDirectory, name, type, object);
	}*/
/**
	 * Rebind 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 ('.').
	 * NOTE: Does not support hierarchical names.
	 *
	 * @param	remoteDirectory	remote directory context to be used.
	 * @param	name	name of the object, code non-<code>null</code>
	 * @param	type	type of the object
	 * @param	object	object to be binded
	 */
private void rebind(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 {
            NameParser parser = remoteDirectory.getNameParser("");
            Name n;
            if (type != null)
                n = parser.parse(name + "." + type);
            else
                n = parser.parse(name);
            remoteDirectory.rebind(n, object);
        } catch (NamingException ne) {
            CoreException ce = new CoreException("Failed to rebind name '" + name + "' to the remote directory.", ne);
            logger.log(Level.FINE, ce.getMessage(), ce);
        }
    }
}
Also used : CoreException(com.cosylab.acs.maci.CoreException) NamingException(javax.naming.NamingException) NameParser(javax.naming.NameParser) Name(javax.naming.Name)

Example 23 with CoreException

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

the class ManagerImpl method unbind.

/**
	 * Unbind 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	type	type of the object
	 */
private void unbind(Context remoteDirectory, String name, String type) {
    assert (name != null);
    // do not unbind interdomain names
    if (name.startsWith(CURL_URI_SCHEMA))
        return;
    if (remoteDirectory != null) {
        try {
            NameParser parser = remoteDirectory.getNameParser("");
            Name n;
            if (type != null)
                n = parser.parse(name + "." + type);
            else
                n = parser.parse(name);
            remoteDirectory.unbind(n);
            // NOTE: cleaning up the empty context nodes is not implemented
            // since access NS cannot provide quantum actions (transactions)
            // cleanup only empty ".F" contexts - only local manager
            // should modify local NS
            cleanupEmptyFContext(remoteDirectory, name);
        } catch (NamingException ne) {
            CoreException ce = new CoreException("Failed to unbind name '" + name + "' from the remote directory.", ne);
            logger.log(Level.FINE, ce.getMessage(), ce);
        }
    }
}
Also used : CoreException(com.cosylab.acs.maci.CoreException) NamingException(javax.naming.NamingException) NameParser(javax.naming.NameParser) Name(javax.naming.Name)

Example 24 with CoreException

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

the class ManagerImpl method cleanupEmptyFContext.

/**
	 * Removes empty ".F" context(s) (recirsive).
	 * @param remoteDirectory	directory root.
	 * @param name	name of the child object being just removed from the potential empty parent context.
	 */
private void cleanupEmptyFContext(Context remoteDirectory, String name) {
    try {
        // hierarchical name check
        int pos = name.lastIndexOf('/');
        if (pos != -1) {
            if (pos == 0 || pos == name.length())
                throw new IllegalArgumentException("Invalid hierarchical name '" + name + "'.");
            String parent = name.substring(0, pos);
            if (parent.endsWith(".F") && !remoteDirectory.list(parent).hasMore()) {
                remoteDirectory.unbind(parent);
                cleanupEmptyFContext(remoteDirectory, parent);
            }
        }
    } catch (Throwable th) {
        CoreException ce = new CoreException("Failed to unbind (potential) empty context for '" + name + "'.", th);
        logger.log(Level.FINE, ce.getMessage(), ce);
    }
}
Also used : CoreException(com.cosylab.acs.maci.CoreException)

Example 25 with CoreException

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

the class ManagerImpl method releaseComponents.

/**
	 * @see com.cosylab.acs.maci.Manager#releaseComponents(int, URI[])
	 */
public void releaseComponents(int id, URI[] curls) throws AcsJNoPermissionEx {
    // check if null
    if (curls == null) {
        // BAD_PARAM
        BadParametersException af = new BadParametersException("Non-null CURLs expected.");
        throw af;
    }
    // check handle and NONE permissions
    securityCheck(id, AccessRights.NONE);
    /****************************************************************/
    int released = 0;
    for (int i = 0; i < curls.length; i++) {
        try {
            releaseComponent(id, curls[i]);
            released++;
        } catch (Exception ex) {
            CoreException ce = new CoreException("Failed to release component '" + curls[i] + "'.", ex);
            reportException(ce);
        }
    }
    logger.log(Level.INFO, released + " of " + curls.length + " components released.");
/****************************************************************/
}
Also used : CoreException(com.cosylab.acs.maci.CoreException) 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)

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