Search in sources :

Example 6 with AcsJCannotGetComponentEx

use of alma.maciErrType.wrappers.AcsJCannotGetComponentEx in project ACS by ACS-Community.

the class ManagerImpl method containerLogout.

/**
	 * Container specific logout method
	 * @param	id	handle of the container.
	 * @param	pingFailed	flag indicating that ping has failed (i.e. is the reason of this logout).
	 */
private void containerLogout(int id, boolean pingFailed) {
    TimerTaskContainerInfo containerInfo = null;
    synchronized (containers) {
        int handle = id & HANDLE_MASK;
        // already logged out
        if (!containers.isAllocated(handle))
            return;
        containerInfo = (TimerTaskContainerInfo) containers.get(handle);
        // cancel all "old" container async request
        AcsJCannotGetComponentEx acgcex = new AcsJCannotGetComponentEx();
        acgcex.setReason("Request canceled due to container logout.");
        cancelPendingContainerAsyncRequestWithException(containerInfo.getName(), acgcex);
        // !!! ACID - RemoveContainerCommand
        executeCommand(new ContainerCommandDeallocate(handle, id, pingFailed ? WhyUnloadedReason.DISAPPEARED : WhyUnloadedReason.REMOVED));
    // remove
    //containers.deallocate(handle);
    }
    // deregister container from the heartbeat manager
    containerInfo.getTask().cancel();
    // make all container components unavailable
    markContainersComponentsUnavailable(containerInfo);
    /// TODO !!!!!!!!!!!!!! no more handle -> componentInfo data
    // notify administrators about the logout
    notifyContainerLogout(containerInfo, System.currentTimeMillis());
    Container container = containerInfo.getContainer();
    if (container != null)
        container.release();
    logger.log(Level.INFO, "Container '" + containerInfo.getName() + "' logged out.");
}
Also used : Container(com.cosylab.acs.maci.Container) ContainerCommandDeallocate(com.cosylab.acs.maci.manager.recovery.ContainerCommandDeallocate) AcsJCannotGetComponentEx(alma.maciErrType.wrappers.AcsJCannotGetComponentEx)

Example 7 with AcsJCannotGetComponentEx

use of alma.maciErrType.wrappers.AcsJCannotGetComponentEx in project ACS by ACS-Community.

the class ManagerImpl method internalRequestComponent.

/**
	 * Internal method for requesting components.
	 * @param	requestor		requestor of the component.
	 * @param	name			name of component to be requested, non-<code>null</code>.
	 * @param	type			type of component to be requested; if <code>null</code> CDB will be queried.
	 * @param	code			code of component to be requested; if <code>null</code> CDB will be queried.
	 * @param	containerName	container name of component to be requested; if <code>null</code> CDB will be queried.
	 * @param	status			returned completion status of the request.
	 * @param	activate		<code>true</code> if component has to be activated
	 * @return	componentInfo	<code>ComponentInfo</code> of requested component.
	 */
private ComponentInfo internalRequestComponent(int requestor, String name, String type, String code, String containerName, int keepAliveTime, StatusHolder status, boolean activate) throws AcsJCannotGetComponentEx, AcsJSyncLockFailedEx, AcsJComponentSpecIncompatibleWithActiveComponentEx {
    AcsJCannotGetComponentEx bcex = null;
    if (name == null) {
        bcex = new AcsJCannotGetComponentEx();
        logger.log(Level.SEVERE, "Cannot activate component with NULL name.", bcex);
        throw bcex;
    }
    if (status == null) {
        bcex = new AcsJCannotGetComponentEx();
        logger.log(Level.SEVERE, "Component " + name + " has NULL status.", bcex);
        throw bcex;
    }
    try {
        checkCyclicDependency(requestor, name);
    } catch (AcsJCyclicDependencyDetectedEx e) {
        AcsJCannotGetComponentEx cgce = new AcsJCannotGetComponentEx(e);
        cgce.setCURL(name);
        throw cgce;
    }
    // try to acquire lock
    String lockNotAcquiredCause = acquireSynchronizationObject(name, getLockTimeout(), "request component " + name);
    if (lockNotAcquiredCause == null) {
        boolean releaseRWLock = true;
        try {
            // try to acquire activation readers lock first
            // NOTE: the locks are NOT reentrant
            activationPendingRWLock.readLock().lock();
            // AcsJComponentSpecIncompatibleWithActiveComponentEx flies up
            return internalNoSyncRequestComponent(requestor, name, type, code, containerName, keepAliveTime, status, activate);
        } finally {
            if (releaseRWLock)
                activationPendingRWLock.readLock().unlock();
            releaseSynchronizationObject(name);
        }
    } else {
        AcsJSyncLockFailedEx slfe = new AcsJSyncLockFailedEx();
        slfe.setCURL(name);
        slfe.setRequestor(requestor);
        slfe.setProperty("lockCause", lockNotAcquiredCause);
        throw slfe;
    }
}
Also used : AcsJSyncLockFailedEx(alma.jmanagerErrType.wrappers.AcsJSyncLockFailedEx) AcsJCyclicDependencyDetectedEx(alma.jmanagerErrType.wrappers.AcsJCyclicDependencyDetectedEx) AcsJCannotGetComponentEx(alma.maciErrType.wrappers.AcsJCannotGetComponentEx)

Example 8 with AcsJCannotGetComponentEx

use of alma.maciErrType.wrappers.AcsJCannotGetComponentEx in project ACS by ACS-Community.

the class CategoryClient method connect.

/**
	 * Connects to the passed categories of the alarm system
	 * 
	 * @param listener The lister to notify of the alarms received from the categories
	 * @param categories The categories to connect to
	 * @throws AcsJCannotGetComponentEx In case the AlarmService is not available
	 * @throws AlarmClientException In case of failure connecting the client
	 */
public void connect(AlarmSelectionListener listener, Category[] categories) throws AlarmClientException, AcsJCannotGetComponentEx {
    if (listener == null) {
        throw new IllegalArgumentException("The listener can't be null");
    }
    if (closed) {
        throw new IllegalStateException("SourceClient is closed!");
    }
    try {
        CernAlarmServiceUtils alarmUtils = new CernAlarmServiceUtils(orb, logger);
        alarm = alarmUtils.getCernAlarmService();
    } catch (Throwable t) {
        AcsJCannotGetComponentEx ex = new AcsJCannotGetComponentEx(t);
        ex.setReason("Alarm service unavailable");
        throw ex;
    }
    try {
        userHandler = new UserHandlerImpl(orb, logger);
        logger.log(AcsLogLevel.DEBUG, "UserHandler succesfully built");
        testUser = userHandler.getUser("test", orb, logger);
        logger.log(AcsLogLevel.DEBUG, "User generated");
        defaultConf = testUser.getDefaultConfiguration();
        logger.log(AcsLogLevel.DEBUG, "Getting the selection handler");
        jms_selectionHandler = AlarmSelectionHandler.get(orb, logger);
        addCategories(defaultConf, categories);
        // Get the active alarms (they are received by the listener)
        java.util.Map<String, Alarm> alreadyActive = jms_selectionHandler.select(defaultConf.getSelection(), listener);
        if (alreadyActive != null && alreadyActive.size() > 0) {
            Set<String> keys = alreadyActive.keySet();
            for (String key : keys) {
                listener.onAlarm(alreadyActive.get(key));
            }
        }
    } catch (Throwable t) {
        throw new AlarmClientException("Exception connecting the category client", t);
    }
}
Also used : Alarm(cern.laser.client.data.Alarm) AlarmClientException(alma.alarmsystem.clients.alarm.AlarmClientException) AcsJCannotGetComponentEx(alma.maciErrType.wrappers.AcsJCannotGetComponentEx) CernAlarmServiceUtils(alma.alarmsystem.corbaservice.CernAlarmServiceUtils) UserHandlerImpl(cern.laser.console.impl.UserHandlerImpl)

Example 9 with AcsJCannotGetComponentEx

use of alma.maciErrType.wrappers.AcsJCannotGetComponentEx in project ACS by ACS-Community.

the class CernSysPanel method connect.

/**
	 * Connect
	 */
public void connect() {
    if (connecting || closed) {
        return;
    }
    connecting = true;
    connectionListener.connecting();
    notAvaiPnl.addMessage("Connecting to the alarm service");
    notAvaiPnl.addMessage("Instantiating the category client");
    try {
        categoryClient = new AlarmCategoryClient(orb, logger);
    } catch (Throwable t) {
        System.err.println("Error instantiating the CategoryClient: " + t.getMessage());
        notAvaiPnl.addMessage("Error instantiating the CategoryClient: " + t.getMessage());
        t.printStackTrace(System.err);
        connectionListener.disconnected();
        categoryClient = null;
        connecting = false;
        return;
    }
    /**
		 * Try to connect to the alarm service until it becomes available
		 */
    categoryClient.addAlarmListener((AlarmSelectionListener) model);
    while (true && !closed) {
        notAvaiPnl.addMessage("Connecting to the categories");
        try {
            categoryClient.connect();
            notAvaiPnl.addMessage("CategoryClient connected");
            // If the connection succeeded then exit the loop
            break;
        } catch (AcsJCannotGetComponentEx cgc) {
            // Wait 30 secs before retrying
            // but checks if it is closed every second.
            int t = 0;
            while (t < 30) {
                if (closed) {
                    return;
                }
                try {
                    Thread.sleep(1000);
                } catch (Exception e) {
                }
                t++;
            }
            cgc.printStackTrace();
            // Try again
            continue;
        } catch (Throwable t) {
            System.err.println("Error connecting CategoryClient: " + t.getMessage() + ", " + t.getClass().getName());
            notAvaiPnl.addMessage("Error connecting CategoryClient: " + t.getMessage() + ", " + t.getClass().getName());
            t.printStackTrace(System.err);
            connectionListener.disconnected();
            connecting = false;
            return;
        }
    }
    if (closed) {
        model.setCategoryClient(null);
        return;
    }
    notAvaiPnl.addMessage("Connected to the alarm service");
    connecting = false;
    connectionListener.connected();
    statusLine.start();
    model.setCategoryClient(categoryClient);
    alarmPanel.showPanel(AlarmPanel.cernSysName);
}
Also used : AlarmCategoryClient(alma.alarmsystem.clients.AlarmCategoryClient) AcsJCannotGetComponentEx(alma.maciErrType.wrappers.AcsJCannotGetComponentEx) AlarmClientException(alma.alarmsystem.clients.alarm.AlarmClientException)

Example 10 with AcsJCannotGetComponentEx

use of alma.maciErrType.wrappers.AcsJCannotGetComponentEx in project ACS by ACS-Community.

the class ManagerImpl method internalNoSyncRequestComponentPhase2.

private ComponentInfo internalNoSyncRequestComponentPhase2(int requestor, String name, String type, String code, String containerName, int keepAliveTime, StatusHolder status, AcsJCannotGetComponentEx bcex, boolean isOtherDomainComponent, boolean isDynamicComponent, int h, boolean reactivate, ComponentInfo componentInfo, Container container, ContainerInfo containerInfo, long executionId, long activationTime, boolean timeoutError) throws AcsJCannotGetComponentEx {
    // remove component from client component list, will be added later (first lots of checks has to be done)
    if ((requestor & TYPE_MASK) == COMPONENT_MASK) {
        removeComponentOwner(h | COMPONENT_MASK, requestor);
    }
    // remove from pending activation list
    synchronized (pendingActivations) {
        pendingActivations.remove(name);
    }
    // failed to activate
    if (componentInfo == null || componentInfo.getHandle() == 0 || componentInfo.getComponent() == null) {
        if (bcex == null)
            logger.log(Level.SEVERE, "Failed to activate component '" + name + "' (" + HandleHelper.toString(h | COMPONENT_MASK) + ").");
        else
            bcex.setReason("Failed to activate component '" + name + "' (" + HandleHelper.toString(h | COMPONENT_MASK) + ").");
        componentsLock.lock();
        try {
            // !!! ACID 3
            if (!reactivate)
                executeCommand(new ComponentCommandDeallocate(h, h | COMPONENT_MASK, timeoutError ? WhyUnloadedReason.TIMEOUT : WhyUnloadedReason.REMOVED, true));
        //components.deallocate(h, true);
        } finally {
            componentsLock.unlock();
        }
        status.setStatus(ComponentStatus.COMPONENT_NOT_ACTIVATED);
        if (bcex == null)
            return null;
        else
            throw bcex;
    }
    // log info
    logger.log(Level.INFO, "Component '" + name + "' (" + HandleHelper.toString(h | COMPONENT_MASK) + ") activated successfully.");
    //
    if (!isOtherDomainComponent && !componentInfo.getComponent().doesImplement(type)) {
        // just output SEVERE message
        logger.log(Level.SEVERE, "Activated component '" + name + "' does not implement specified type '" + type + "'.");
    }
    // component info (to get type and code, container - prefix name)
    if (isOtherDomainComponent) {
        // @todo MF tmp (for testing)
        componentInfo.setHandle(h | COMPONENT_MASK);
        componentInfo.setClients(new IntArray());
        componentInfo.setComponents(new IntArray(0));
        componentInfo.setContainer(0);
        // set variables
        type = componentInfo.getType();
        code = componentInfo.getCode();
    }
    int[] clients;
    componentsLock.lock();
    try {
        //
        if (componentInfo.getHandle() != (h | COMPONENT_MASK)) {
            // container returned different handle
            // (it seems it has already activated this Component)
            // check if we can accept it
            int componentHandle = componentInfo.getHandle() & HANDLE_MASK;
            if (components.isAllocated(componentHandle)) {
                // cancel preallocation
                if (!reactivate)
                    executeCommand(new ComponentCommandDeallocate(h, componentInfo.getHandle(), WhyUnloadedReason.REMOVED, true));
                //components.deallocate(h, true);
                bcex = new AcsJCannotGetComponentEx();
                bcex.setReason("Container '" + containerName + "' returned another '" + name + "' component handle than given, failed to fix handle since returned handle is already allocated.");
                // log this anyway, since it's an error of a global nature
                logger.log(Level.SEVERE, "Container '" + containerName + "' returned another '" + name + "' component handle than given, failed to fix handle since returned handle is already allocated.", bcex);
                // component is activated, but cannot be managed by the Manager
                status.setStatus(ComponentStatus.COMPONENT_ACTIVATED);
                throw bcex;
            } else {
                // handle is free, relocate handle
                ComponentInfo existingData = null;
                // deallocate old
                if (!reactivate)
                    executeCommand(new ComponentCommandDeallocate(h, componentInfo.getHandle(), WhyUnloadedReason.REPLACED, true));
                else //components.deallocate(h, true);
                {
                    // !!! ACID 3
                    existingData = (ComponentInfo) components.get(h);
                    executeCommand(new ComponentCommandDeallocate(h, componentInfo.getHandle(), WhyUnloadedReason.REPLACED));
                //components.deallocate(h);
                }
                // !!! ACID 3
                // preallocate new
                Integer objHandle = (Integer) executeCommand(new ComponentCommandAllocateHandle(componentHandle, true));
                //h = components.allocate(componentHandle, true);
                if (objHandle == null || (h = objHandle.intValue()) == 0) {
                    // failed to allocate new
                    bcex = new AcsJCannotGetComponentEx();
                    bcex.setReason("Container '" + containerName + "' returned another '" + name + "' component handle than given, failed to fix handle due to handle relocation failure.");
                    // log this anyway, since it's an error of a global nature
                    logger.log(Level.SEVERE, "Container '" + containerName + "' returned another '" + name + "' component handle than given, failed to fix handle due to handle relocation failure.", bcex);
                    // Component is activated, but cannot be managed by the Manager
                    status.setStatus(ComponentStatus.COMPONENT_ACTIVATED);
                    throw bcex;
                } else // !!! ACID 3
                if (existingData != null)
                    executeCommand(new ComponentCommandSet(h, existingData));
                //components.set(h, existingData);
                logger.log(Level.WARNING, "Container '" + containerName + "' returned another '" + name + "' component handle than given, handle fixed.");
            }
        }
        //
        // pre-store data
        //
        ComponentInfo existingData = (ComponentInfo) components.get(h);
        // create a new ComponentInfo - do not trust containers
        ComponentInfo data = new ComponentInfo(componentInfo.getHandle(), name, type, code, componentInfo.getComponent());
        if (existingData != null) {
            data.setClients(existingData.getClients());
            data.setComponents(existingData.getComponents());
        }
        if (requestor != 0)
            if (// hierarchical components need this check
            !data.getClients().contains(requestor))
                data.getClients().add(requestor);
        if (keepAliveTime <= RELEASE_NEVER)
            if (// make component immortal
            !data.getClients().contains(this.getHandle()))
                data.getClients().add(this.getHandle());
        // remember keep alive time
        data.setKeepAliveTime(keepAliveTime);
        if (isOtherDomainComponent) {
            data.setContainer(0);
            data.setContainerName(componentInfo.getContainerName());
        } else {
            data.setContainer(containerInfo.getHandle());
            data.setContainerName(containerInfo.getName());
        }
        data.setAccessRights(0);
        data.setInterfaces(componentInfo.getInterfaces());
        // mark as dynamic component and store its container
        if (isDynamicComponent) {
            data.setDynamic(true);
            data.setDynamicContainerName(containerName);
        }
        // !!! ACID
        executeCommand(new ComponentCommandSet(h, data));
        // acknowledge allocation
        if (!reactivate)
            // !!! ACID 2
            executeCommand(new ComponentCommandAckAlloc(h));
        //components.ackAllocation(h);
        componentInfo = data;
        clients = componentInfo.getClients().toArray();
    } finally {
        componentsLock.unlock();
    }
    if (!isOtherDomainComponent) {
        // add component to client component list to allow dependency checks
        if ((requestor & TYPE_MASK) == COMPONENT_MASK)
            addComponentOwner(componentInfo.getHandle(), requestor);
        //
        // call construct
        //
        boolean constructed = false;
        try {
            componentInfo.getComponent().construct();
            constructed = true;
        } catch (Throwable ex) {
            bcex = new AcsJCannotGetComponentEx(ex);
            bcex.setReason("Failed to construct component '" + name + "', exception caught when invoking 'construct()' method.");
        }
        // remove component from client component list, will be added later
        if ((requestor & TYPE_MASK) == COMPONENT_MASK)
            removeComponentOwner(componentInfo.getHandle(), requestor);
        if (!constructed) {
            // release Component
            componentsLock.lock();
            try {
                // !!! ACID 3
                if (!reactivate)
                    executeCommand(new ComponentCommandDeallocate(h, componentInfo.getHandle(), WhyUnloadedReason.REMOVED));
                // deactivate
                try {
                    container.deactivate_component(componentInfo.getHandle());
                } catch (Exception ex) {
                    bcex = new AcsJCannotGetComponentEx(ex);
                    bcex.setReason("Failed to deactivate component '" + name + "' on container '" + containerName + "'.");
                }
                status.setStatus(ComponentStatus.COMPONENT_NOT_ACTIVATED);
                throw bcex;
            } finally {
                componentsLock.unlock();
            }
        }
    }
    // add component to client component list
    if (requestor != this.getHandle() && requestor != 0)
        addComponentOwner(componentInfo.getHandle(), requestor);
    // add component to container component list
    if (!isOtherDomainComponent)
        synchronized (containerInfo.getComponents()) {
            if (!containerInfo.getComponents().contains(componentInfo.getHandle()))
                executeCommand(new ContainerInfoCommandComponentAdd(containerInfo.getHandle() & HANDLE_MASK, componentInfo.getHandle()));
        //containerInfo.getComponents().add(componentInfo.getHandle());
        }
    // remove component from unavailable list
    if (reactivate) {
        synchronized (unavailableComponents) {
            executeCommand(new UnavailableComponentCommandRemove(name));
        //unavailableComponents.remove(name);
        }
    }
    //
    if (!isOtherDomainComponent)
        notifyComponentActivated(componentInfo, activationTime, executionId);
    //
    if (reactivate) {
        notifyComponentAvailable(requestor, clients, new ComponentInfo[] { componentInfo });
    }
    //
    // notify administrators about the activation
    //
    notifyComponentRequested(new int[] { requestor }, new int[] { componentInfo.getHandle() }, activationTime);
    if (reactivate)
        logger.log(Level.FINE, "Component '" + name + "' (" + HandleHelper.toString(componentInfo.getHandle()) + ") reactivated.");
    else
        logger.log(Level.FINE, "Component '" + name + "' (" + HandleHelper.toString(componentInfo.getHandle()) + ") activated.");
    // notify about the change (only this-domain container which activated the component)...
    if (containerInfo != null)
        topologySortManager.notifyTopologyChange(containerInfo.getHandle());
    status.setStatus(ComponentStatus.COMPONENT_ACTIVATED);
    return componentInfo;
}
Also used : ComponentCommandAllocateHandle(com.cosylab.acs.maci.manager.recovery.ComponentCommandAllocateHandle) UnavailableComponentCommandRemove(com.cosylab.acs.maci.manager.recovery.UnavailableComponentCommandRemove) AcsJCannotGetComponentEx(alma.maciErrType.wrappers.AcsJCannotGetComponentEx) ComponentCommandAckAlloc(com.cosylab.acs.maci.manager.recovery.ComponentCommandAckAlloc) 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) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ContainerInfoCommandComponentAdd(com.cosylab.acs.maci.manager.recovery.ContainerInfoCommandComponentAdd) IntArray(com.cosylab.acs.maci.IntArray) ComponentCommandDeallocate(com.cosylab.acs.maci.manager.recovery.ComponentCommandDeallocate) ComponentCommandSet(com.cosylab.acs.maci.manager.recovery.ComponentCommandSet) ComponentInfo(com.cosylab.acs.maci.ComponentInfo)

Aggregations

AcsJCannotGetComponentEx (alma.maciErrType.wrappers.AcsJCannotGetComponentEx)24 NoResourcesException (com.cosylab.acs.maci.NoResourcesException)14 AcsJNoPermissionEx (alma.maciErrType.wrappers.AcsJNoPermissionEx)13 BadParametersException (com.cosylab.acs.maci.BadParametersException)12 URI (java.net.URI)11 Component (com.cosylab.acs.maci.Component)10 ComponentInfo (com.cosylab.acs.maci.ComponentInfo)10 URISyntaxException (java.net.URISyntaxException)10 StatusHolder (com.cosylab.acs.maci.StatusHolder)8 AcsJComponentSpecIncompatibleWithActiveComponentEx (alma.maciErrType.wrappers.AcsJComponentSpecIncompatibleWithActiveComponentEx)7 AcsJInvalidComponentSpecEx (alma.maciErrType.wrappers.AcsJInvalidComponentSpecEx)7 ClientInfo (com.cosylab.acs.maci.ClientInfo)7 CoreException (com.cosylab.acs.maci.CoreException)7 NoDefaultComponentException (com.cosylab.acs.maci.NoDefaultComponentException)7 AcsJBadParameterEx (alma.ACSErrTypeCommon.wrappers.AcsJBadParameterEx)6 AcsJIncompleteComponentSpecEx (alma.maciErrType.wrappers.AcsJIncompleteComponentSpecEx)6 RemoteException (com.cosylab.acs.maci.RemoteException)6 BAD_PARAM (org.omg.CORBA.BAD_PARAM)6 NO_RESOURCES (org.omg.CORBA.NO_RESOURCES)6 Object (org.omg.CORBA.Object)6