Search in sources :

Example 16 with AgentPath

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

the class JobPusher method run.

@Override
public void run() {
    String tName = "Agent job pusher for " + itemPath + ":" + activity.getPath() + " to role " + myRole;
    Thread.currentThread().setName(tName);
    Logger.msg(7, "JobPusher.run() - Started:" + tName);
    try {
        for (AgentPath nextAgent : Gateway.getLookup().getAgents(myRole)) {
            Logger.msg(7, "JobPusher.run() - Calculating jobs for agent:" + nextAgent);
            try {
                // get joblist for agent
                JobArrayList jobList = new JobArrayList(this.activity.calculateJobs(nextAgent, itemPath, false));
                // push it to the agent
                String stringJobs = Gateway.getMarshaller().marshall(jobList);
                Agent thisAgent = AgentHelper.narrow(nextAgent.getIOR());
                Logger.msg(7, "JobPusher.run() - Calling refreshJobList() with " + jobList.list.size() + " jobs for agent " + nextAgent + " from " + activity.getPath());
                thisAgent.refreshJobList(itemPath.getSystemKey(), activity.getPath(), stringJobs);
            } catch (Exception ex) {
                Logger.error("JobPusher.run() - Agent " + nextAgent + " of role " + myRole + " could not be found to be informed of a change in " + itemPath);
                Logger.error(ex);
            }
        }
    } catch (ObjectNotFoundException e) {
        Logger.warning("JobPusher cannot push jobs, it did not find any agents for role:" + myRole);
    }
    Logger.msg(7, "JobPusher.run() - FINISHED:" + tName);
}
Also used : Agent(org.cristalise.kernel.entity.Agent) AgentPath(org.cristalise.kernel.lookup.AgentPath) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) JobArrayList(org.cristalise.kernel.entity.agent.JobArrayList) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException)

Example 17 with AgentPath

use of org.cristalise.kernel.lookup.AgentPath 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)

Example 18 with AgentPath

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

the class Gateway method login.

/**
 * Authenticates the agent using the configured {@link Authenticator}
 *
 * @param agentName the name of the agent
 * @param agentPassword the password of the agent
 * @param resource check {@link Authenticator#authenticate(String, String, String)}
 * @return AgentProxy representing the logged in user/agent
 *
 * @throws InvalidDataException - bad params
 * @throws ObjectNotFoundException - object not found
 */
public static AgentProxy login(String agentName, String agentPassword, String resource) throws InvalidDataException, ObjectNotFoundException {
    Authenticator auth = getAuthenticator();
    if (!auth.authenticate(agentName, agentPassword, resource))
        throw new InvalidDataException("Login failed");
    // find agent proxy
    AgentPath agentPath = mLookup.getAgentPath(agentName);
    AgentProxy agent = (AgentProxy) mProxyManager.getProxy(agentPath);
    agent.setAuthObj(auth);
    return agent;
}
Also used : AgentPath(org.cristalise.kernel.lookup.AgentPath) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) AgentProxy(org.cristalise.kernel.entity.proxy.AgentProxy) Authenticator(org.cristalise.kernel.process.auth.Authenticator)

Example 19 with AgentPath

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

the class StandardServer method resetAgentIORs.

public static void resetAgentIORs(RolePath root) throws ObjectNotFoundException, ObjectCannotBeUpdated, CannotManageException {
    Logger.msg("StandardServer.resetAgentIORs() - root:" + root);
    Iterator<Path> roles = Gateway.getLookup().getChildren(root);
    while (roles.hasNext()) {
        RolePath role = (RolePath) roles.next();
        resetAgentIORs(role);
        for (AgentPath agent : Gateway.getLookup().getAgents(role)) {
            Logger.msg("StandardServer.resetAgentIORs() - setting IOR for role:" + role + " agent:" + agent.getAgentName() + " " + agent.getItemPath());
            Gateway.getLookupManager().setIOR(agent.getItemPath(), Gateway.getORB().object_to_string(Gateway.getCorbaServer().getAgentIOR(agent)));
        }
    }
}
Also used : RolePath(org.cristalise.kernel.lookup.RolePath) DomainPath(org.cristalise.kernel.lookup.DomainPath) Path(org.cristalise.kernel.lookup.Path) AgentPath(org.cristalise.kernel.lookup.AgentPath) AgentPath(org.cristalise.kernel.lookup.AgentPath) RolePath(org.cristalise.kernel.lookup.RolePath)

Example 20 with AgentPath

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

the class BulkImport method importPath.

public void importPath(ItemPath item, Object locker) throws PersistencyException {
    String[] contents = importCluster.getClusterContents(item, PATH);
    AgentPath agentPath = null;
    String entity = "";
    if (Arrays.asList(contents).contains("Item"))
        entity = "Item";
    if (Arrays.asList(contents).contains("Agent"))
        entity = "Agent";
    if (StringUtils.isNotBlank(entity)) {
        if (entity.equals("Item"))
            importItemPath(item, locker);
        else if (entity.equals("Agent"))
            agentPath = importAgentPath(item, locker);
    } else
        Logger.warning("BulkImport.importPath() - WARNING: '" + item + "' has no Path.Item or Path.Agent files");
    ;
    for (String c : contents) {
        if (c.equals("Domain"))
            importDomainPath(item, locker);
        else if (c.equals("Role"))
            importRolePath(item, agentPath, locker);
    }
}
Also used : AgentPath(org.cristalise.kernel.lookup.AgentPath)

Aggregations

AgentPath (org.cristalise.kernel.lookup.AgentPath)23 InvalidDataException (org.cristalise.kernel.common.InvalidDataException)10 ObjectNotFoundException (org.cristalise.kernel.common.ObjectNotFoundException)10 InvalidItemPathException (org.cristalise.kernel.lookup.InvalidItemPathException)8 CannotManageException (org.cristalise.kernel.common.CannotManageException)6 PersistencyException (org.cristalise.kernel.common.PersistencyException)6 ObjectAlreadyExistsException (org.cristalise.kernel.common.ObjectAlreadyExistsException)5 ObjectCannotBeUpdated (org.cristalise.kernel.common.ObjectCannotBeUpdated)5 RolePath (org.cristalise.kernel.lookup.RolePath)5 InvalidAgentPathException (org.cristalise.kernel.lookup.InvalidAgentPathException)4 IOException (java.io.IOException)3 AccessRightsException (org.cristalise.kernel.common.AccessRightsException)3 AgentProxy (org.cristalise.kernel.entity.proxy.AgentProxy)3 CompositeActivity (org.cristalise.kernel.lifecycle.instance.CompositeActivity)3 Workflow (org.cristalise.kernel.lifecycle.instance.Workflow)3 DomainPath (org.cristalise.kernel.lookup.DomainPath)3 ItemPath (org.cristalise.kernel.lookup.ItemPath)3 Viewpoint (org.cristalise.kernel.persistency.outcome.Viewpoint)3 Property (org.cristalise.kernel.property.Property)3 PropertyArrayList (org.cristalise.kernel.property.PropertyArrayList)3