Search in sources :

Example 11 with ContainerInfo

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

the class ManagerImpl method getContainerInfo.

/**
	 * Get container info. for specified name of <code>Container</code>.
	 *
	 * @param	name	name of the container whose info. should be returned, non-<code>null</code>
	 * @param	returns	requested info, <code>null</code> if container with requested handle does not exits
	 */
private ContainerInfo getContainerInfo(String name) {
    assert (name != null);
    // info to be returned
    ContainerInfo info = null;
    synchronized (containers) {
        int h = containers.first();
        while (h != 0) {
            ContainerInfo containerInfo = (ContainerInfo) containers.get(h);
            if (name.equals(containerInfo.getName())) {
                info = containerInfo;
                break;
            }
            h = containers.next(h);
        }
    }
    return info;
}
Also used : ContainerInfo(com.cosylab.acs.maci.ContainerInfo)

Example 12 with ContainerInfo

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

Example 13 with ContainerInfo

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

the class ManagerImpl method containerLogin.

/*****************************************************************************/
/**************************** [ Login methods ] ******************************/
/*****************************************************************************/
/**
	 * Container specific login method.
	 * @param	name	name of the container, non-<code>null</code>.
	 * @param	reply	reply to authenticate method, non-<code>null</code>.
	 * @param	container	container that is logging in, non-<code>null</code>.
	 * @return	ClientInfo	client info. of newly logged container
	 */
private ClientInfo containerLogin(String name, AuthenticationData reply, Container container, long timeStamp, long executionId) throws AcsJNoPermissionEx {
    assert (name != null);
    assert (reply != null);
    assert (container != null);
    TimerTaskContainerInfo containerInfo = null;
    ClientInfo clientInfo = null;
    boolean existingLogin = false;
    synchronized (containers) {
        // check if container is already logged in,
        // if it is, return existing info
        int h = containers.first();
        while (h != 0) {
            ContainerInfo loggedContainerInfo = (ContainerInfo) containers.get(h);
            //if (container.equals(loggedContainerInfo.getContainer()))
            if (name.equals(loggedContainerInfo.getName())) {
                Container loggedContainer = loggedContainerInfo.getContainer();
                if (loggedContainer != null) {
                    // if same instance simply recover, if not...
                    if (!loggedContainer.equals(container)) {
                        // check if logged container is alive, if it is reject him
                        boolean alive = false;
                        try {
                            int lh = loggedContainer.get_handle();
                            if (lh != 0 && lh == loggedContainerInfo.getHandle())
                                alive = true;
                        } catch (Throwable th) {
                        // noop
                        }
                        if (alive) {
                            AcsJNoPermissionEx npe = new AcsJNoPermissionEx();
                            String address = "";
                            try {
                                address = " " + loggedContainer.getRemoteLocation();
                            } catch (Throwable th) {
                            /* noop */
                            }
                            npe.setReason("Rejecting container login, container with name '" + name + "'" + address + " already logged in.");
                            npe.setID(HandleHelper.toString(loggedContainerInfo.getHandle()));
                            npe.setProtectedResource(name);
                            throw npe;
                        } else
                            logger.log(Level.FINER, "Container '" + name + "' is no longer functional, new container is taking over.");
                    }
                }
                // !!! ACID 2
                // new reference is considered as better
                executeCommand(new ContainerCommandUpdate(h, container));
                //loggedContainerInfo.setContainer(container);
                existingLogin = true;
                // generate ClientInfo
                containerInfo = (TimerTaskContainerInfo) loggedContainerInfo;
                clientInfo = containerInfo.createClientInfo();
                break;
            }
            h = containers.next(h);
        }
        // new container
        if (h == 0) {
            long pingInterval = 0;
            DAOProxy dao = getContainersDAOProxy();
            if (dao != null) {
                String impLang = readStringCharacteristics(dao, name + "/ImplLang", true);
                ImplLang configuredImplLang = ImplLang.fromString(impLang);
                if (configuredImplLang != ImplLang.not_specified && configuredImplLang != reply.getImplLang()) {
                    AcsJNoPermissionEx npe = new AcsJNoPermissionEx();
                    npe.setReason("Rejecting container login, container reported '" + reply.getImplLang() + "' implementation language, but configured '" + configuredImplLang + "'.");
                    npe.setProtectedResource(name);
                    throw npe;
                }
                pingInterval = readLongCharacteristics(dao, name + "/PingInterval", -1, true) * 1000;
            }
            // allocate new handle
            // !!! ACID 2
            Integer objHandle = (Integer) executeCommand(new ContainerCommandAllocate());
            int handle;
            if (objHandle == null || (handle = objHandle.intValue()) == 0) {
                NoResourcesException af = new NoResourcesException("Generation of new handle failed, too many containers logged in.");
                throw af;
            }
            // generate external handle
            h = handle | CONTAINER_MASK;
            // add generated key
            h |= (random.nextInt(0x100)) << 16;
            // create new container info
            containerInfo = new TimerTaskContainerInfo(h, name, container, containerPingInterval);
            containerInfo.setImplLang(reply.getImplLang());
            if (// safety limit
            pingInterval >= 1000)
                containerInfo.setPingInterval(pingInterval);
            clientInfo = containerInfo.createClientInfo();
            // register container to the heartbeat manager
            PingTimerTask task = new PingTimerTask(this, logger, clientInfo, alarmSource);
            containerInfo.setTask(task);
            heartbeatTask.schedule(task, containerInfo.getPingInterval(), containerInfo.getPingInterval());
            // !!! ACID - register AddContainerCommand
            executeCommand(new ContainerCommandSet(handle, containerInfo));
        // store info
        //containers.set(handle, containerInfo);
        }
    }
    // cancel all "old" container async request
    AcsJCannotGetComponentEx acgcex = new AcsJCannotGetComponentEx();
    acgcex.setReason("Request canceled due to container re-login.");
    cancelPendingContainerAsyncRequestWithException(containerInfo.getName(), acgcex);
    final boolean recoverContainer = reply.isRecover();
    if (existingLogin) {
        // merge container's and manager's internal state
        containerInternalStateMerge(containerInfo, recoverContainer);
    }
    // notify administrators about the login
    notifyContainerLogin(containerInfo, timeStamp, executionId);
    // do container post login activation in separate thread
    final ContainerInfo finalInfo = containerInfo;
    threadPool.execute(new Runnable() {

        public void run() {
            containerPostLoginActivation(finalInfo, recoverContainer);
        }
    });
    logger.log(Level.INFO, "Container '" + name + "' logged in.");
    return clientInfo;
}
Also used : ContainerCommandAllocate(com.cosylab.acs.maci.manager.recovery.ContainerCommandAllocate) ContainerCommandSet(com.cosylab.acs.maci.manager.recovery.ContainerCommandSet) ContainerCommandUpdate(com.cosylab.acs.maci.manager.recovery.ContainerCommandUpdate) DAOProxy(com.cosylab.cdb.client.DAOProxy) AcsJCannotGetComponentEx(alma.maciErrType.wrappers.AcsJCannotGetComponentEx) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) NoResourcesException(com.cosylab.acs.maci.NoResourcesException) Container(com.cosylab.acs.maci.Container) AcsJNoPermissionEx(alma.maciErrType.wrappers.AcsJNoPermissionEx) ContainerInfo(com.cosylab.acs.maci.ContainerInfo) ClientInfo(com.cosylab.acs.maci.ClientInfo) ImplLang(com.cosylab.acs.maci.ImplLang)

Example 14 with ContainerInfo

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

the class ManagerImpl method hasCDBEntry.

/**
	 * Search for CDB entry of given component.
	 * @param	componentInfo	component info of CDB entry to be found, non-<code>null</code>.
	 * @return	if CDB entry of has been found <code>true</code>, or if it does not exist or
	 * 		     there is no CDB available <code>false</code>.
	 */
private boolean hasCDBEntry(ComponentInfo componentInfo) {
    assert (componentInfo != null);
    try {
        // check component entry
        DAOProxy dao = getComponentsDAOProxy();
        if (dao == null || readStringCharacteristics(dao, componentInfo.getName(), true) == null)
            return false;
        // check type
        String type = readStringCharacteristics(dao, componentInfo.getName() + "/Type", true);
        if (type == null || !type.equals(componentInfo.getType()))
            return false;
        // check code
        String code = readStringCharacteristics(dao, componentInfo.getName() + "/Code", true);
        if (code == null || !code.equals(componentInfo.getCode()))
            return false;
        // check container
        String container = readStringCharacteristics(dao, componentInfo.getName() + "/Container", true);
        if (container == null)
            return false;
        else {
            // dynamic component case
            if (componentInfo.isDynamic()) {
                if (componentInfo.getDynamicContainerName() != null && !container.equals(componentInfo.getDynamicContainerName()))
                    return false;
            } else // static component case
            {
                ContainerInfo containerInfo = (ContainerInfo) getContainerInfo(componentInfo.getContainer());
                if (containerInfo != null && !containerInfo.getName().equals(container))
                    return false;
            }
        }
        // there is an entry in CDB
        return true;
    } catch (Throwable t) {
        return false;
    }
}
Also used : ContainerInfo(com.cosylab.acs.maci.ContainerInfo) DAOProxy(com.cosylab.cdb.client.DAOProxy)

Example 15 with ContainerInfo

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

the class ManagerImpl method getContainerInfo.

/**
	 * @see com.cosylab.acs.maci.Manager#getContainerInfo(int, int[], String)
	 */
public ContainerInfo[] getContainerInfo(int id, int[] handles, String name_wc) throws AcsJNoPermissionEx {
    if (handles == null) {
        // BAD_PARAM
        BadParametersException af = new BadParametersException("Non-null 'handles' sequence expected.");
        throw af;
    } else if (handles.length == 0 && name_wc == null) {
        // BAD_PARAM
        BadParametersException af = new BadParametersException("Non-null 'names_wc' sequence expected.");
        throw af;
    }
    /*
		Pattern pattern = null;
		if (handles.length == 0 && name_wc != null)
		{
			// test wildcard patten (try to compile it)
			try
			{
				pattern = Pattern.compile(name_wc);
			}
			catch (Exception ex)
			{
				// BAD_PARAM
				BadParametersException af = new BadParametersException("Failed to compile 'names_wc' reqular expression string '"+name_wc+"'.");
				af.caughtIn(this, "getContainerInfo");
				af.putValue("name_wc", name_wc);
				throw af;
			}
		}
*/
    /****************************************************************/
    // info to be returned
    ContainerInfo[] info = null;
    // requesting info. about itself
    if (handles.length == 1 && handles[0] == id) {
        // check handle, no special rights for own info
        securityCheck(id, 0);
        info = new ContainerInfo[1];
        info[0] = getContainerInfo(id);
    } else // get info of requested handles
    if (handles.length > 0) {
        // check handle, INTROSPECT_MANAGER rights needed
        securityCheck(id, AccessRights.INTROSPECT_MANAGER);
        info = new ContainerInfo[handles.length];
        for (int i = 0; i < handles.length; i++) info[i] = getContainerInfo(handles[i]);
    } else // get info requested using name wildcard
    {
        // check handle, INTROSPECT_MANAGER rights needed
        securityCheck(id, AccessRights.INTROSPECT_MANAGER);
        // list of client matching search pattern
        ArrayList<ContainerInfo> list = new ArrayList<ContainerInfo>();
        // check clients
        synchronized (containers) {
            int h = containers.first();
            while (h != 0) {
                ContainerInfo containerInfo = (ContainerInfo) containers.get(h);
                /*Matcher m = pattern.matcher(containerInfo.getName());
					if (m.matches())*/
                if (WildcharMatcher.match(name_wc, containerInfo.getName()))
                    list.add(containerInfo);
                h = containers.next(h);
            }
        }
        // copy to array
        info = new ContainerInfo[list.size()];
        list.toArray(info);
    }
    return info;
}
Also used : ContainerInfo(com.cosylab.acs.maci.ContainerInfo) ArrayList(java.util.ArrayList) BadParametersException(com.cosylab.acs.maci.BadParametersException)

Aggregations

ContainerInfo (com.cosylab.acs.maci.ContainerInfo)24 ComponentInfo (com.cosylab.acs.maci.ComponentInfo)9 ClientInfo (com.cosylab.acs.maci.ClientInfo)7 AcsJNoPermissionEx (alma.maciErrType.wrappers.AcsJNoPermissionEx)5 Container (com.cosylab.acs.maci.Container)5 DAOProxy (com.cosylab.cdb.client.DAOProxy)5 BadParametersException (com.cosylab.acs.maci.BadParametersException)4 RemoteException (com.cosylab.acs.maci.RemoteException)4 TimeoutRemoteException (com.cosylab.acs.maci.TimeoutRemoteException)4 URI (java.net.URI)4 ArrayList (java.util.ArrayList)4 AcsJCannotGetComponentEx (alma.maciErrType.wrappers.AcsJCannotGetComponentEx)3 Component (com.cosylab.acs.maci.Component)3 CoreException (com.cosylab.acs.maci.CoreException)3 NoResourcesException (com.cosylab.acs.maci.NoResourcesException)3 StatusHolder (com.cosylab.acs.maci.StatusHolder)3 ManagerImpl (com.cosylab.acs.maci.manager.ManagerImpl)3 ImplLang (com.cosylab.acs.maci.ImplLang)2 IntArray (com.cosylab.acs.maci.IntArray)2 Manager (com.cosylab.acs.maci.Manager)2