Exemplo n.º 1
0
  public void scheduleProfile(Profile profile) throws AxisFault {
    try {
      TaskManager tm =
          JmxTaskServiceComponent.getTaskService()
              .getTaskManager(JmxConstant.JMX_SERVICE_TASK_TYPE);

      TaskInfo taskInfo = JmxTaskUtils.convert(profile);
      tm.registerTask(taskInfo);
      tm.scheduleTask(taskInfo.getName());
      log.info(profile.getName() + " enabled.");
    } catch (TaskException e) {
      log.error(e);
    }
  }
 public boolean schedule(TaskDescription taskDescription) {
   logger.debug("#schedule Scheduling task:" + taskDescription.getName());
   TaskInfo taskInfo;
   try {
     taskInfo = TaskBuilder.buildTaskInfo(taskDescription, properties);
   } catch (Exception e) {
     if (logger.isDebugEnabled()) {
       logger.debug(
           "#schedule Could not build task info object. Error:" + e.getLocalizedMessage(), e);
     }
     return false;
   }
   if (!isInitialized()) {
     // if cannot schedule yet, put in the pending tasks list.
     synchronized (lock) {
       logger.debug("#schedule Added pending task [" + taskInfo.getName() + "]");
       pendingTasks.add(taskInfo);
     }
     return false;
   }
   try {
     synchronized (lock) {
       taskManager.registerTask(taskInfo);
       taskManager.scheduleTask(taskInfo.getName());
     }
     logger.info(
         "Scheduled task ["
             + taskDescription.getName()
             + "::"
             + taskDescription.getTaskGroup()
             + "]");
   } catch (Exception e) {
     logger.error(
         "Scheduling task ["
             + taskDescription.getName()
             + "::"
             + taskDescription.getTaskGroup()
             + "] FAILED. Error: "
             + e.getLocalizedMessage(),
         e);
     return false;
   }
   return true;
 }
  public boolean init(Properties properties) {
    synchronized (lock) {
      try {
        TaskService taskService = NtaskService.getTaskService();
        if (taskService == null || NtaskService.getCcServiceInstance() == null) {
          // Cannot proceed with the initialization because the
          // TaskService is not yet
          // available. Register this as an observer so that this can
          // be reinitialized
          // within the NtaskService when the TaskService is
          // available.
          NtaskService.addObserver(this);
          return false;
        }
        boolean isSingleNode =
            NtaskService.getCcServiceInstance()
                    .getServerConfigContext()
                    .getAxisConfiguration()
                    .getClusteringAgent()
                == null;
        boolean isWorkerNode = !isSingleNode && CarbonUtils.isWorkerNode();
        logger.debug("#init Single-Node: " + isSingleNode + " Worker-Node: " + isWorkerNode);
        if (!isSingleNode && !isWorkerNode) {
          // Skip running tasks on the management node
          logger.debug("#init Skipping task registration");
          initialized = true;
          return true;
        }

        if ((taskManager = getTaskManager(false)) == null) {
          return false;
        }

        // Register pending tasks..
        Iterator tasks = pendingTasks.iterator();
        while (tasks.hasNext()) {
          TaskInfo taskInfo = (TaskInfo) tasks.next();
          try {
            List<TaskInfo> taskInfos = taskManager.getAllTasks();
            boolean hasTask = false;
            for (TaskInfo task : taskInfos) {
              if (task.getName().equals(taskInfo.getName())) {
                hasTask = true;
                break;
              }
            }
            if (hasTask) {
              logger.debug(
                  "#init Pending task ["
                      + taskInfo.getName()
                      + "] is already available in the registry.");
              continue;
            }
            taskManager.registerTask(taskInfo);
            taskManager.scheduleTask(taskInfo.getName());
            tasks.remove();
            logger.debug("#init Scheduled pending task [" + taskInfo.getName() + "] SUCCESSFUL.");
          } catch (TaskException e) {
            logger.error(
                "Could not schedule task ["
                    + taskInfo.getName()
                    + "]. Error: "
                    + e.getLocalizedMessage(),
                e);
          }
        }
        // Run already deployed tasks..
        taskService.registerTaskType(TaskBuilder.TASK_TYPE_USER);
        taskService.registerTaskType(TaskBuilder.TASK_TYPE_SYSTEM);
        initialized = true;
        logger.info("initialized");
        return true;
      } catch (Exception e) {
        logger.error("Cannot initialize task manager. Error: " + e.getLocalizedMessage(), e);
        initialized = false;
      }
    }
    return false;
  }