Search in sources :

Example 11 with BadParametersException

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

the class ManagerProxyImpl method get_container_info.

/**
	 * Get all the information that the Manager has about its known Containers.
	 * To invoke this method, the caller must have INTROSPECT_MANAGER access rights, or it must be the object whose info it is requesting.
	 * Calling this function does not affect the internal state of the Manager.
	 *
	 * @param id Identification of the caller.
	 * @param h Handles of the containers whose information is requested. If this is an empty sequence, the name_wc parameter is used.
	 * @param name_wc Wildcard that the container's name must match in order for its information to be returned.
	 * @return A sequence of ContainerInfo structures containing the entire Manager's knowledge about the containers.
	 *		  If access is denied to a subset of objects, the handles to those objects are set to 0.
	 */
public ContainerInfo[] get_container_info(int id, int[] h, String name_wc) throws NoPermissionEx {
    pendingRequests.incrementAndGet();
    try {
        // invalid info (replacement for null)
        final ContainerInfo invalidInfo = new ContainerInfo("<invalid>", 0, null, new int[0]);
        // returned value
        ContainerInfo[] retVal = null;
        // transform to CORBA specific
        com.cosylab.acs.maci.ContainerInfo[] infos = manager.getContainerInfo(id, h, name_wc);
        if (infos != null) {
            retVal = new ContainerInfo[infos.length];
            for (int i = 0; i < infos.length; i++) if (infos[i] == null)
                retVal[i] = invalidInfo;
            else
                retVal[i] = new ContainerInfo(infos[i].getName(), infos[i].getHandle(), (Container) ((ContainerProxy) infos[i].getContainer()).getClient(), infos[i].getComponents().toArray());
        } else
            retVal = new ContainerInfo[0];
        return retVal;
    } 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 (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 : BAD_PARAM(org.omg.CORBA.BAD_PARAM) BadParametersException(com.cosylab.acs.maci.BadParametersException) NoResourcesException(com.cosylab.acs.maci.NoResourcesException) Container(si.ijs.maci.Container) AcsJNoPermissionEx(alma.maciErrType.wrappers.AcsJNoPermissionEx) CoreException(com.cosylab.acs.maci.CoreException) ContainerInfo(si.ijs.maci.ContainerInfo) UNKNOWN(org.omg.CORBA.UNKNOWN) NO_RESOURCES(org.omg.CORBA.NO_RESOURCES)

Example 12 with BadParametersException

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

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

the class ManagerImpl method releaseComponents.

/**
	 * Release components (using manager handle)
	 * @param infos	components to release
	 */
private void releaseComponents(ComponentInfo[] infos) throws AcsJNoPermissionEx {
    if (infos.length > 0) {
        // map strings to CURLs
        URI[] uris = new URI[infos.length];
        for (int i = 0; i < infos.length; i++) {
            try {
                uris[i] = CURLHelper.createURI(infos[i].getName());
            } catch (URISyntaxException usi) {
                BadParametersException hbpe = new BadParametersException(usi.getMessage(), usi);
                reportException(hbpe);
            }
        }
        // release components
        releaseComponents(getHandle(), uris);
    }
}
Also used : URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) BadParametersException(com.cosylab.acs.maci.BadParametersException)

Example 14 with BadParametersException

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

the class ManagerImpl method getDefaultComponent.

/*****************************************************************************/
/*********************** [ Dynamic (de)activation ] **************************/
/*****************************************************************************/
/**
	 * @see com.cosylab.acs.maci.Manager#getDefaultComponent(int, java.lang.String)
	 */
// @todo MF not supported
public ComponentInfo getDefaultComponent(int id, String type) throws AcsJNoPermissionEx, NoDefaultComponentException {
    if (type == null) {
        // BAD_PARAM
        BadParametersException af = new BadParametersException("Non-null 'type' expected.");
        throw af;
    }
    /****************************************************************/
    // check handle and NONE permissions
    securityCheck(id, AccessRights.NONE);
    logger.log(Level.INFO, "Getting default component for type '" + type + "'.");
    ComponentInfo componentInfo = internalRequestDefaultComponent(id, type);
    return componentInfo;
}
Also used : ComponentInfo(com.cosylab.acs.maci.ComponentInfo) BadParametersException(com.cosylab.acs.maci.BadParametersException)

Example 15 with BadParametersException

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

the class ManagerImpl method internalNoSyncRestartComponent.

/**
	 * Internal method for restarting components.
	 *
	 * @param	owner	owner of the component.
	 * @param	h		handle of the component to be restarting.
	 * @return			Newly restarted component, <code>null</code> if failed.
	 */
// @todo MF not supported
private Component internalNoSyncRestartComponent(int owner, int h) throws AcsJNoPermissionEx {
    int handle = h & HANDLE_MASK;
    ComponentInfo componentInfo = null;
    componentsLock.lock();
    try {
        if (components.isAllocated(handle))
            componentInfo = (ComponentInfo) components.get(handle);
        if (componentInfo == null || componentInfo.getHandle() != h) {
            // invalid component handle
            BadParametersException af = new BadParametersException("Invalid component handle.");
            throw af;
        }
        // remove ownership of the component
        if (!componentInfo.getClients().contains(owner)) {
            // not an owner
            AcsJNoPermissionEx npe = new AcsJNoPermissionEx();
            npe.setReason("Restarting component that client does not own.");
            npe.setID(HandleHelper.toString(owner));
            npe.setProtectedResource(componentInfo.getName());
            throw npe;
        }
    } finally {
        componentsLock.unlock();
    }
    /****************** restart component ******************/
    //
    // get container
    //
    // search for container by its name
    Container container = null;
    ContainerInfo containerInfo = null;
    int containerHandle = componentInfo.getContainer();
    // if containerHandle equals 0, we have unavailable or registered component
    if (containerHandle != 0) {
        containerInfo = getContainerInfo(containerHandle);
        if (containerInfo != null) {
            checkContainerShutdownState(containerInfo);
            container = containerInfo.getContainer();
        }
        // required container is not logged in
        if (container == null) {
            // then simply do not do the restart
            String containerName;
            if (containerInfo != null)
                containerName = containerInfo.getName();
            else
                containerName = HandleHelper.toString(componentInfo.getContainer());
            logger.log(Level.WARNING, "Container '" + containerName + "' required by component '" + componentInfo.getName() + "' is not logged in.");
        }
    }
    // return value
    Component component = null;
    if (container != null) {
        // restart component
        try {
            component = container.restart_component(componentInfo.getHandle());
            if (component == null) {
                RemoteException re = new RemoteException("Failed to restart component '" + componentInfo.getName() + "', 'null' returned.");
                throw re;
            }
        // @todo what about notifying clients, marking component as available, updating reference...
        } catch (Throwable ex) {
            RemoteException re = new RemoteException("Failed to restart component '" + componentInfo.getName() + "' on container '" + containerInfo.getName() + "'.", ex);
            logger.log(Level.SEVERE, re.getMessage(), re);
        }
    }
    logger.log(Level.FINE, "Component '" + componentInfo.getName() + "' restarted.");
    return component;
}
Also used : Container(com.cosylab.acs.maci.Container) AcsJNoPermissionEx(alma.maciErrType.wrappers.AcsJNoPermissionEx) ContainerInfo(com.cosylab.acs.maci.ContainerInfo) ComponentInfo(com.cosylab.acs.maci.ComponentInfo) Component(com.cosylab.acs.maci.Component) RemoteException(com.cosylab.acs.maci.RemoteException) TimeoutRemoteException(com.cosylab.acs.maci.TimeoutRemoteException) BadParametersException(com.cosylab.acs.maci.BadParametersException)

Aggregations

BadParametersException (com.cosylab.acs.maci.BadParametersException)30 AcsJNoPermissionEx (alma.maciErrType.wrappers.AcsJNoPermissionEx)21 NoResourcesException (com.cosylab.acs.maci.NoResourcesException)20 CoreException (com.cosylab.acs.maci.CoreException)17 BAD_PARAM (org.omg.CORBA.BAD_PARAM)13 UNKNOWN (org.omg.CORBA.UNKNOWN)13 NO_RESOURCES (org.omg.CORBA.NO_RESOURCES)12 URISyntaxException (java.net.URISyntaxException)11 ComponentInfo (com.cosylab.acs.maci.ComponentInfo)9 URI (java.net.URI)9 Object (org.omg.CORBA.Object)8 ClientInfo (com.cosylab.acs.maci.ClientInfo)7 AcsJCannotGetComponentEx (alma.maciErrType.wrappers.AcsJCannotGetComponentEx)6 Component (com.cosylab.acs.maci.Component)6 NoDefaultComponentException (com.cosylab.acs.maci.NoDefaultComponentException)5 RemoteException (com.cosylab.acs.maci.RemoteException)5 TimeoutRemoteException (com.cosylab.acs.maci.TimeoutRemoteException)5 AcsJException (alma.acs.exceptions.AcsJException)4 ContainerInfo (com.cosylab.acs.maci.ContainerInfo)4 ComponentInfo (si.ijs.maci.ComponentInfo)4