Search in sources :

Example 1 with IntArray

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

the class ContainerProxy method activate_component.

/**
	 * @see com.cosylab.acs.maci.Container#activate_component(int, long, String, String, String)
	 */
public ComponentInfo activate_component(int handle, long executionId, String name, String exe, String type) throws AcsJCannotActivateComponentEx {
    try {
        ComponentInfo retVal = null;
        si.ijs.maci.ComponentInfo info;
        try {
            info = container.activate_component(handle, executionId, name, exe, type);
        } catch (CannotActivateComponentEx cannotActivateEx) {
            // and thus have to convert it to its JDK-style peer exception
            throw AcsJCannotActivateComponentEx.fromCannotActivateComponentEx(cannotActivateEx);
        }
        if (info != null) {
            retVal = new ComponentInfo(info.h, info.name, info.type, info.code, info.reference != null ? new ComponentProxy(info.name, info.reference) : null);
            retVal.setContainer(info.container);
            retVal.setContainerName(info.container_name);
            retVal.setAccessRights(inverseMapAccessRights(info.access));
            retVal.setClients(new IntArray(info.clients));
            retVal.setInterfaces(info.interfaces);
        }
        return retVal;
    } catch (TIMEOUT tex) {
        TimeoutRemoteException re = new TimeoutRemoteException("Timout occured while invoking 'activate_component()' method.", tex);
        throw re;
    } catch (org.omg.CORBA.MARSHAL marshalEx) {
        // see http://jira.alma.cl/browse/COMP-4371. Unclear if a parameter was null, or the returned struct was invalid.
        RemoteException re = new RemoteException("Failed to transform the paramters or return value of the container's 'activate_component' method " + "to/from the corba call, using parameters name=" + name + ", exe=" + exe + ", type=" + type, marshalEx);
        throw re;
    } catch (Exception ex) {
        RemoteException re = new RemoteException("Failed to invoke 'activate_component()' method.", ex);
        throw re;
    }
}
Also used : RemoteException(com.cosylab.acs.maci.RemoteException) IOException(java.io.IOException) TimeoutRemoteException(com.cosylab.acs.maci.TimeoutRemoteException) AcsJException(alma.acs.exceptions.AcsJException) AcsJCannotActivateComponentEx(alma.maciErrType.wrappers.AcsJCannotActivateComponentEx) CannotActivateComponentEx(alma.maciErrType.CannotActivateComponentEx) IntArray(com.cosylab.acs.maci.IntArray) TimeoutRemoteException(com.cosylab.acs.maci.TimeoutRemoteException) ComponentInfo(com.cosylab.acs.maci.ComponentInfo) CBComponentInfo(si.ijs.maci.CBComponentInfo) TIMEOUT(org.omg.CORBA.TIMEOUT) RemoteException(com.cosylab.acs.maci.RemoteException) TimeoutRemoteException(com.cosylab.acs.maci.TimeoutRemoteException)

Example 2 with IntArray

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

the class ManagerImpl method internalNoSyncDeactivateComponent.

/**
	 * Deactivate component, issue deactivate reeust to container (or other manager).
	 * @param componentInfo	info about component to be deactivated.
	 */
private void internalNoSyncDeactivateComponent(ComponentInfo componentInfo) throws Throwable {
    // unbind from remote directory
    //unbind(convertToHiearachical(componentInfo.getName()), "O");
    int handle = componentInfo.getHandle() & HANDLE_MASK;
    int owners = componentInfo.getClients().size();
    try {
        //
        // get container/remote manager
        //
        String name = componentInfo.getName();
        boolean isOtherDomainComponent = name.startsWith(CURL_URI_SCHEMA);
        if (isOtherDomainComponent) {
            Manager remoteManager = null;
            // @todo MF do the login?
            try {
                String domainName = CURLHelper.createURI(name).getAuthority();
                remoteManager = getManagerForDomain(domainName);
                if (remoteManager == null)
                    throw new CoreException("Failed to obtain manager for domain '" + domainName + "'.");
            } catch (Throwable th) {
                logger.log(Level.WARNING, "Failed to obtain non-local manager required by component '" + name + "'.", th);
                throw th;
            }
            // release component
            try {
                URI curlName = CURLHelper.createURI(name);
                // @todo MF tmp (handle)
                remoteManager.releaseComponent(INTERDOMAIN_MANAGER_HANDLE, curlName);
            } catch (Throwable th) {
                logger.log(Level.WARNING, "Failed to release component '" + componentInfo.getName() + "' on remote manager.'", th);
                throw th;
            }
        } else {
            //
            // 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) {
                    // remove component from container component list
                    synchronized (containerInfo.getComponents()) {
                        // !!! ACID
                        if (containerInfo.getComponents().contains(componentInfo.getHandle()))
                            executeCommand(new ContainerInfoCommandComponentRemove(containerInfo.getHandle() & HANDLE_MASK, componentInfo.getHandle()));
                    //containerInfo.getComponents().remove(componentInfo.getHandle());
                    }
                    // we allow this (since releasing components is part of container shutdown procedure)
                    //checkContainerState(containerInfo);
                    container = containerInfo.getContainer();
                }
                // required container is not logged in
                if (container == null) {
                    // then simply do not do the deactivation
                    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.");
                }
            }
            if (container != null) {
                // log info
                logger.log(Level.INFO, "Deactivating component '" + componentInfo.getName() + "' (" + HandleHelper.toString(componentInfo.getHandle()) + ") on container '" + containerInfo.getName() + "'.");
                // destruct
                try {
                    componentInfo.getComponent().destruct();
                } catch (Throwable ex) {
                    RemoteException re = new RemoteException("Failed to destruct component '" + componentInfo.getName() + "', exception caught when invoking 'destruct()' method.", ex);
                    logger.log(Level.SEVERE, re.getMessage(), re);
                    throw ex;
                }
                long deactivationTime = 0;
                // deactivate component in anycase
                try {
                    container.deactivate_component(componentInfo.getHandle());
                    deactivationTime = System.currentTimeMillis();
                } catch (AcsJException aex) {
                    logger.log(Level.SEVERE, aex.getMessage(), aex);
                    throw aex;
                } catch (Throwable ex) {
                    RemoteException re = new RemoteException("Failed to deactivate component '" + componentInfo.getName() + "' (" + HandleHelper.toString(componentInfo.getHandle()) + ") on container '" + containerInfo.getName() + "'.", ex);
                    logger.log(Level.SEVERE, re.getMessage(), re);
                    throw ex;
                }
                // notify administrators about deactivation, but not if failed
                if (deactivationTime != 0)
                    notifyComponentDeactivated(componentInfo.getHandle(), deactivationTime);
                // shutdown container if required (and necessary)
                conditionalShutdownContainer(containerInfo);
            }
        }
    } finally {
        if (owners == 0) {
            // deallocate Component
            componentsLock.lock();
            try {
                executeCommand(new ComponentCommandDeallocate(handle, componentInfo.getHandle(), WhyUnloadedReason.REMOVED));
            //components.deallocate(handle);
            } finally {
                componentsLock.unlock();
            }
        }
    }
    // log info
    logger.log(Level.INFO, "Component '" + componentInfo.getName() + "' (" + HandleHelper.toString(componentInfo.getHandle()) + ") deactivated.");
    // release all subcomponents (just like client logoff)
    // component should have already done this by itself, but take care of clean cleanup
    // what about that: if subcomponent becomes unavailable, does component also becomes?!
    // no, it is notified and it handles situation by its own way (e.g. changes component state).
    // Just like it already handles activation (manager does not care for dependecy trees).
    int[] subcomponents = null;
    // no not hold the lock
    synchronized (componentInfo.getComponents()) {
        if (componentInfo.getComponents().size() > 0) {
            IntArray toCleanupList = new IntArray();
            IntArray comps = componentInfo.getComponents();
            for (int i = 0; i < comps.size(); i++) if (components.isAllocated(comps.get(i) & HANDLE_MASK))
                toCleanupList.add(comps.get(i));
            if (toCleanupList.size() > 0)
                subcomponents = toCleanupList.toArray();
        }
    //subcomponents = componentInfo.getComponents().toArray();
    }
    if (subcomponents != null && subcomponents.length > 0)
        new ReleaseComponentTask(componentInfo.getHandle(), subcomponents).run();
    // make unavailable (deactivation was forced)
    if (owners > 0)
        makeUnavailable(componentInfo);
}
Also used : AcsJException(alma.acs.exceptions.AcsJException) Manager(com.cosylab.acs.maci.Manager) URI(java.net.URI) Container(com.cosylab.acs.maci.Container) CoreException(com.cosylab.acs.maci.CoreException) IntArray(com.cosylab.acs.maci.IntArray) ContainerInfoCommandComponentRemove(com.cosylab.acs.maci.manager.recovery.ContainerInfoCommandComponentRemove) ComponentCommandDeallocate(com.cosylab.acs.maci.manager.recovery.ComponentCommandDeallocate) ContainerInfo(com.cosylab.acs.maci.ContainerInfo) RemoteException(com.cosylab.acs.maci.RemoteException) TimeoutRemoteException(com.cosylab.acs.maci.TimeoutRemoteException)

Example 3 with IntArray

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

the class IntArrayTest method testIntArraySerialization.

/**
	 */
public void testIntArraySerialization() {
    IntArray ia = new IntArray();
    final int TEST_LEN = 12;
    for (int i = 0; i < TEST_LEN; i++) ia.add(i);
    testSerialization(ia);
}
Also used : IntArray(com.cosylab.acs.maci.IntArray)

Example 4 with IntArray

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

the class IntArrayTest method testRemoval.

/**
	 */
public void testRemoval() {
    IntArray ia = new IntArray();
    int i = 0;
    for (; i <= 12345; i++) {
        ia.add(i);
        assertEquals(i, ia.get(i));
    }
    for (--i; i >= 0; i--) {
        ia.removeAt(i);
    }
    assertEquals(0, ia.size());
}
Also used : IntArray(com.cosylab.acs.maci.IntArray)

Example 5 with IntArray

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

the class IntArrayTest method testAllocation.

/**
	 */
public void testAllocation() {
    IntArray ia = new IntArray();
    int i = 0;
    for (; i <= 10000; i++) {
        ia.add(i);
        assertEquals(i, ia.get(i));
    }
    assertEquals(i, ia.size());
}
Also used : IntArray(com.cosylab.acs.maci.IntArray)

Aggregations

IntArray (com.cosylab.acs.maci.IntArray)14 ComponentInfo (com.cosylab.acs.maci.ComponentInfo)7 RemoteException (com.cosylab.acs.maci.RemoteException)6 AcsJException (alma.acs.exceptions.AcsJException)4 TimeoutRemoteException (com.cosylab.acs.maci.TimeoutRemoteException)4 IOException (java.io.IOException)4 AcsJNoPermissionEx (alma.maciErrType.wrappers.AcsJNoPermissionEx)3 NoDefaultComponentException (com.cosylab.acs.maci.NoDefaultComponentException)3 ComponentCommandDeallocate (com.cosylab.acs.maci.manager.recovery.ComponentCommandDeallocate)3 BadParametersException (com.cosylab.acs.maci.BadParametersException)2 ContainerInfo (com.cosylab.acs.maci.ContainerInfo)2 CoreException (com.cosylab.acs.maci.CoreException)2 NoResourcesException (com.cosylab.acs.maci.NoResourcesException)2 ComponentCommandAllocateHandle (com.cosylab.acs.maci.manager.recovery.ComponentCommandAllocateHandle)2 ComponentCommandSet (com.cosylab.acs.maci.manager.recovery.ComponentCommandSet)2 ContainerInfoCommandComponentAdd (com.cosylab.acs.maci.manager.recovery.ContainerInfoCommandComponentAdd)2 ContainerInfoCommandComponentRemove (com.cosylab.acs.maci.manager.recovery.ContainerInfoCommandComponentRemove)2 UnavailableComponentCommandRemove (com.cosylab.acs.maci.manager.recovery.UnavailableComponentCommandRemove)2 URI (java.net.URI)2 URISyntaxException (java.net.URISyntaxException)2