Search in sources :

Example 6 with LookupManager

use of org.cristalise.kernel.lookup.LookupManager in project kernel by cristal-ise.

the class Bootstrap method checkAgent.

/**
 * Checks for the existence of a agents so it can be used
 *
 * @param name
 * @param pass
 * @param rolePath
 * @param uuid
 * @return the Proxy representing the Agent
 * @throws Exception
 */
private static AgentProxy checkAgent(String name, String pass, RolePath rolePath, String uuid) throws Exception {
    Logger.msg(1, "Bootstrap.checkAgent() - Checking for existence of '" + name + "' agent.");
    LookupManager lookup = Gateway.getLookupManager();
    try {
        AgentProxy agentProxy = Gateway.getProxyManager().getAgentProxy(lookup.getAgentPath(name));
        systemAgents.put(name, agentProxy);
        Logger.msg(3, "Bootstrap.checkAgent() - Agent '" + name + "' found.");
        return agentProxy;
    } catch (ObjectNotFoundException ex) {
    }
    Logger.msg("Bootstrap.checkAgent() - Agent '" + name + "' not found. Creating.");
    try {
        AgentPath agentPath = new AgentPath(new ItemPath(uuid), name);
        Gateway.getCorbaServer().createAgent(agentPath);
        lookup.add(agentPath);
        if (StringUtils.isNotBlank(pass))
            lookup.setAgentPassword(agentPath, pass);
        // assign admin role
        Logger.msg("Bootstrap.checkAgent() - Assigning role '" + rolePath.getName() + "'");
        Gateway.getLookupManager().addRole(agentPath, rolePath);
        Gateway.getStorage().put(agentPath, new Property(NAME, name, true), null);
        Gateway.getStorage().put(agentPath, new Property(TYPE, "Agent", false), null);
        AgentProxy agentProxy = Gateway.getProxyManager().getAgentProxy(agentPath);
        // TODO: properly init agent here with wf, props and colls
        // agentProxy.initialise(agentId, itemProps, workflow, colls);
        systemAgents.put(name, agentProxy);
        return agentProxy;
    } catch (Exception ex) {
        Logger.error("Unable to create '" + name + "' Agent.");
        throw ex;
    }
}
Also used : AgentPath(org.cristalise.kernel.lookup.AgentPath) LookupManager(org.cristalise.kernel.lookup.LookupManager) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) AgentProxy(org.cristalise.kernel.entity.proxy.AgentProxy) Property(org.cristalise.kernel.property.Property) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) InvalidItemPathException(org.cristalise.kernel.lookup.InvalidItemPathException) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) PersistencyException(org.cristalise.kernel.common.PersistencyException) ItemPath(org.cristalise.kernel.lookup.ItemPath)

Aggregations

LookupManager (org.cristalise.kernel.lookup.LookupManager)6 ObjectNotFoundException (org.cristalise.kernel.common.ObjectNotFoundException)5 InvalidDataException (org.cristalise.kernel.common.InvalidDataException)4 Property (org.cristalise.kernel.property.Property)3 PersistencyException (org.cristalise.kernel.common.PersistencyException)2 ItemProxy (org.cristalise.kernel.entity.proxy.ItemProxy)2 AgentPath (org.cristalise.kernel.lookup.AgentPath)2 DomainPath (org.cristalise.kernel.lookup.DomainPath)2 ItemPath (org.cristalise.kernel.lookup.ItemPath)2 Viewpoint (org.cristalise.kernel.persistency.outcome.Viewpoint)2 MalformedURLException (java.net.MalformedURLException)1 CannotManageException (org.cristalise.kernel.common.CannotManageException)1 ObjectCannotBeUpdated (org.cristalise.kernel.common.ObjectCannotBeUpdated)1 CorbaServer (org.cristalise.kernel.entity.CorbaServer)1 AgentProxy (org.cristalise.kernel.entity.proxy.AgentProxy)1 ProxyServer (org.cristalise.kernel.entity.proxy.ProxyServer)1 CompositeActivityDef (org.cristalise.kernel.lifecycle.CompositeActivityDef)1 CompositeActivity (org.cristalise.kernel.lifecycle.instance.CompositeActivity)1 InvalidItemPathException (org.cristalise.kernel.lookup.InvalidItemPathException)1 RolePath (org.cristalise.kernel.lookup.RolePath)1