Package org.apache.oodt.cas.workflow.structs

Examples of org.apache.oodt.cas.workflow.structs.WorkflowTask


                        if (taskElemList != null
                                && taskElemList.getLength() > 0) {
                            for (int j = 0; j < taskElemList.getLength(); j++) {
                                Element taskElem = (Element) taskElemList
                                        .item(j);
                                WorkflowTask task = XmlStructFactory
                                        .getWorkflowTask(taskElem, conditionMap);
                                if (task != null) {
                                    taskMap.put(task.getTaskId(), task);
                                }
                            }

                        }
                    }
View Full Code Here


  public TestXmlRpcWorkflowManagerClient() {

    testWrkInst = new WorkflowInstance();
    testWrkFlw = new Workflow();
    testTask = new WorkflowTask();
    testCond = new WorkflowCondition();
    Metadata sharedContext = new Metadata();

    // to check if the path already exists and to delete if it does exist
    if (new File(catalogPath).exists()) {
View Full Code Here

    private String tmpDirPath = null;

    public TestLuceneWorkflowInstanceRepository() {
        testInst = new WorkflowInstance();
        testWkflw = new Workflow();
        testTask = new WorkflowTask();
        testCond = new WorkflowCondition();
        testWkflw.setName("test.workflow");
        testWkflw.setId("test.id");
        List tasks = new Vector();
        List conds = new Vector();
View Full Code Here

   */
  public static WorkflowTask getWorkflowTask(Node node, HashMap conditions) {
    Element taskNode = (Element) node;

    String taskClassName = taskNode.getAttribute("class");
    WorkflowTask task = new WorkflowTask();
    task.setTaskInstanceClassName(taskClassName);

    task.setTaskId(taskNode.getAttribute("id"));
    task.setTaskName(taskNode.getAttribute("name"));

    // get the list of condition IDs for this task and then get the
    // conditions for them
    task.setConditions(getConditions(taskNode, conditions));

    Element reqMetFieldsElem = getFirstElement("requiredMetFields", taskNode);
    if (reqMetFieldsElem != null) {
      task.setRequiredMetFields(getRequiredMetFields(reqMetFieldsElem));
    }

    // load its configuration
    Element configElement = getFirstElement("configuration", taskNode);
    if (configElement != null) {
      task.setTaskConfig(new WorkflowTaskConfiguration(
          getConfiguration(configElement)));
    }

    return task;
  }
View Full Code Here

      workflowTasks = new Vector<WorkflowTask>(taskList.getLength());

      for (int i = 0; i < taskList.getLength(); i++) {
        Element taskElement = (Element) taskList.item(i);

        WorkflowTask t = (WorkflowTask) tasks.get(taskElement
            .getAttribute("id"));

        if (t != null) {
          WorkflowTask workflowTask = new WorkflowTask();
          workflowTask.setTaskInstanceClassName(t.getTaskInstanceClassName());
          workflowTask.setConditions(t.getConditions());
          workflowTask.setTaskId(t.getTaskId());
          workflowTask.setTaskConfig(t.getTaskConfig());
          workflowTask.setTaskName(t.getTaskName());
          workflowTask.setOrder(i + 1);
          workflowTask.setRequiredMetFields(t.getRequiredMetFields());
          workflowTasks.add(workflowTask);
        }
      }

    }
View Full Code Here

            "IterativeWorkflowProcessorThread: Skipping execution: Paused: CurrentTask: "
                + getTaskNameById(workflowInst.getCurrentTaskId()));
        continue;
      }

      WorkflowTask task = (WorkflowTask) taskIterator.next();
      workflowInst.setCurrentTaskId(task.getTaskId());

      // now persist it
      persistWorkflowInstance();

      // check to see if req met fields are present
      // if they aren't, set the status to METERROR, and then fail
      if (!checkTaskRequiredMetadata(task, this.workflowInst.getSharedContext())) {
        this.workflowInst.setStatus(METADATA_MISSING);
        persistWorkflowInstance();
        // now break out of this run loop
        return;
      }

      // this is where the pre-conditions come in
      // only execute the below code when it's passed all of its
      // pre-conditions
      if (task.getConditions() != null) {
        while (!satisfied(task.getConditions(), task.getTaskId())
            && !isStopped()) {

          // if we're not paused, go ahead and pause us now
          if (!isPaused()) {
            pause();
          }

          LOG.log(Level.FINEST,
              "Pre-conditions for task: " + task.getTaskName()
                  + " unsatisfied: waiting: " + waitForConditionSatisfy
                  + " seconds before checking again.");
          try {
            Thread.currentThread().sleep(waitForConditionSatisfy * 1000);
          } catch (InterruptedException ignore) {
          }

          // check to see if we've been resumed, if so, break
          // the loop and start
          if (!isPaused()) {
            break;
          }
        }

        // check to see if we've been killed
        if (isStopped()) {
          break;
        }

        // un pause us (if needed)
        if (isPaused()) {
          resume();
        }
      }

      // task execution
      LOG.log(
          Level.FINEST,
          "IterativeWorkflowProcessorThread: Executing task: "
              + task.getTaskName());

      WorkflowTaskInstance taskInstance = GenericWorkflowObjectFactory
          .getTaskObjectFromClassName(task.getTaskInstanceClassName());
      // add the TaskId and the JobId and ProcessingNode
      // TODO: unfake the JobId
      workflowInst.getSharedContext()
          .replaceMetadata(TASK_ID, task.getTaskId());
      workflowInst.getSharedContext().replaceMetadata(WORKFLOW_INST_ID,
          workflowInst.getId());
      workflowInst.getSharedContext().replaceMetadata(JOB_ID,
          workflowInst.getId());
      workflowInst.getSharedContext().replaceMetadata(PROCESSING_NODE,
          getHostname());
      workflowInst.getSharedContext().replaceMetadata(WORKFLOW_MANAGER_URL,
          this.wmgrParentUrl.toString());

      if (rClient != null) {
        // build up the Job
        // and the Job Input
        Job taskJob = new Job();
        taskJob.setName(task.getTaskId());
        taskJob
            .setJobInstanceClassName("org.apache.oodt.cas.workflow.structs.TaskJob");
        taskJob
            .setJobInputClassName("org.apache.oodt.cas.workflow.structs.TaskJobInput");
        taskJob.setLoadValue(task.getTaskConfig().getProperty(TASK_LOAD) != null ?
            Integer.parseInt(task.getTaskConfig().getProperty(TASK_LOAD)):new Integer(2));
        taskJob
            .setQueueName(task.getTaskConfig().getProperty(QUEUE_NAME) != null ? task
                .getTaskConfig().getProperty(QUEUE_NAME) : DEFAULT_QUEUE_NAME);

        TaskJobInput in = new TaskJobInput();
        in.setDynMetadata(workflowInst.getSharedContext());
        in.setTaskConfig(task.getTaskConfig());
        in.setWorkflowTaskInstanceClassName(task.getTaskInstanceClassName());

        workflowInst.setStatus(RESMGR_SUBMIT);
        persistWorkflowInstance();

        try {
          // this is * NOT * a blocking operation so when it returns
          // the job may not actually have finished executing
          // so we go into a waiting/sleep behavior using the passed
          // back job id to wait until the job has actually finished
          // executing

          this.currentJobId = rClient.submitJob(taskJob, in);

          while (!safeCheckJobComplete(this.currentJobId) && !isStopped()) {
            // sleep for 5 seconds then come back
            // and check again
            try {
              Thread.currentThread().sleep(pollingWaitTime * 1000);
            } catch (InterruptedException ignore) {
            }
          }

          // okay job is done: TODO: fix this hack
          // the task update time was set remotely
          // by remote task, so let's read it now
          // from the instRepo (which will have the updated
          // time)

          if (isStopped()) {
            // this means that this workflow was killed, so
            // gracefully exit
            break;
          }

          WorkflowInstance updatedInst = null;
          try {
            updatedInst = instanceRepository
                .getWorkflowInstanceById(workflowInst.getId());
            workflowInst = updatedInst;
          } catch (InstanceRepositoryException e) {
            e.printStackTrace();
            LOG.log(Level.WARNING, "Unable to get " + "updated workflow "
                + "instance record " + "when executing remote job: Message: "
                + e.getMessage());
          }

        } catch (JobExecutionException e) {
          LOG.log(Level.WARNING,
              "Job execution exception using resource manager to execute job: Message: "
                  + e.getMessage());
        }
      } else {
        // we started, so mark it
        workflowInst.setStatus(STARTED);
        // go ahead and persist the workflow instance, after we
        // save the current task start date time
        String currentTaskIsoStartDateTimeStr = DateConvert
            .isoFormat(new Date());
        workflowInst
            .setCurrentTaskStartDateTimeIsoStr(currentTaskIsoStartDateTimeStr);
        workflowInst.setCurrentTaskEndDateTimeIsoStr(null); /*
                                                             * clear this out
                                                             * until it's ready
                                                             */
        persistWorkflowInstance();
        executeTaskLocally(taskInstance, workflowInst.getSharedContext(),
            task.getTaskConfig(), task.getTaskName());
        String currentTaskIsoEndDateTimeStr = DateConvert.isoFormat(new Date());
        workflowInst
            .setCurrentTaskEndDateTimeIsoStr(currentTaskIsoEndDateTimeStr);
        persistWorkflowInstance();
      }

      LOG.log(
          Level.FINEST,
          "IterativeWorkflowProcessorThread: Completed task: "
              + task.getTaskName());

    }

    LOG.log(Level.FINEST,
        "IterativeWorkflowProcessorThread: Completed workflow: "
View Full Code Here

  }

  private String getTaskNameById(String taskId) {
    for (Iterator i = workflowInst.getWorkflow().getTasks().iterator(); i
        .hasNext();) {
      WorkflowTask task = (WorkflowTask) i.next();
      if (task.getTaskId().equals(taskId)) {
        return task.getTaskName();
      }
    }

    return null;
  }
View Full Code Here

    Thread worker = new Thread() {

      @Override
      public void run() {
        WorkflowLifecycle lifecycle = getLifecycle(taskProcessor);
        WorkflowTask workflowTask = getTaskFromProcessor(taskProcessor);
        WorkflowTaskInstance inst = GenericWorkflowObjectFactory
            .getTaskObjectFromClassName(workflowTask.getTaskInstanceClassName());
        try {
          inst.run(taskProcessor.getWorkflowInstance().getSharedContext(),
              workflowTask.getTaskConfig());
          String msg = "Task: [" + workflowTask.getTaskName()
              + "] for instance id: ["
              + taskProcessor.getWorkflowInstance().getId()
              + "] completed successfully";
          LOG.log(Level.INFO, msg);
          WorkflowState state = lifecycle.createState("ExecutionComplete", "transition", msg);
          taskProcessor.getWorkflowInstance().setState(state);
          persist(taskProcessor.getWorkflowInstance());
        } catch (Exception e) {
          e.printStackTrace();
          String msg = "Exception executing task: ["
              + workflowTask.getTaskName() + "]: Message: " + e.getMessage();
          LOG.log(Level.WARNING, msg);
          WorkflowState state = lifecycle.createState("Failure", "done", msg);
          taskProcessor.getWorkflowInstance().setState(state);
          persist(taskProcessor.getWorkflowInstance());
        }
View Full Code Here

    if (tasks == null) {
      return wTasks;
    }

    for (Iterator i = tasks.iterator(); i.hasNext();) {
      WorkflowTask t = (WorkflowTask) i.next();
      Hashtable task = getXmlRpcWorkflowTask(t);
      wTasks.add(task);
    }

    return wTasks;
View Full Code Here

   *          The XML-RPC Hashtable version of the WorkflowTask.
   * @return a {@link WorkflowTask} from an XML-RPC {@link Hashtable} sent over
   *         the wire.
   */
  public static WorkflowTask getWorkflowTaskFromXmlRpc(Hashtable task) {
    WorkflowTask t = new WorkflowTask();
    t.setTaskInstanceClassName((String) task.get("class"));
    t.setTaskId((String) task.get("id"));
    t.setTaskName((String) task.get("name"));
    t.setOrder(Integer.valueOf((String) task.get("order")).intValue());
    t.setTaskConfig(getWorkflowTaskConfigurationFromXmlRpc((Hashtable) task
        .get("configuration")));
    t.setConditions(getWorkflowConditionsFromXmlRpc((Vector) task
        .get("conditions")));
    t.setRequiredMetFields(getWorkflowTaskReqMetFieldsFromXmlRpc((Vector) task
        .get("requiredMetFields")));

    return t;
  }
View Full Code Here

TOP

Related Classes of org.apache.oodt.cas.workflow.structs.WorkflowTask

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.