public boolean resumeAll() {
   if (!isInitialized()) {
     return false;
   }
   try {
     synchronized (lock) {
       List<TaskInfo> taskList = taskManager.getAllTasks();
       for (TaskInfo taskInfo : taskList) {
         taskManager.resumeTask(taskInfo.getName());
       }
     }
     return true;
   } catch (Exception e) {
     logger.error("Cannot resume all tasks. Error: " + e.getLocalizedMessage(), e);
   }
   return false;
 }
 public String[] getTaskNames() {
   if (!isInitialized()) {
     return new String[0];
   }
   try {
     List<TaskInfo> taskList;
     synchronized (lock) {
       taskList = taskManager.getAllTasks();
     }
     List<String> result = new ArrayList<String>();
     for (TaskInfo taskInfo : taskList) {
       result.add(taskInfo.getName());
     }
     return result.toArray(new String[result.size()]);
   } catch (Exception e) {
     logger.error("Cannot return task list. Error: " + e.getLocalizedMessage(), e);
   }
   return new String[0];
 }
예제 #3
0
  public boolean profileExists(String profileName) {
    try {
      TaskManager tm =
          JmxTaskServiceComponent.getTaskService()
              .getTaskManager(JmxConstant.JMX_SERVICE_TASK_TYPE);

      List<TaskInfo> taskInfoList = tm.getAllTasks();
      for (TaskInfo taskInfo : taskInfoList) {
        if (taskInfo.getName().equalsIgnoreCase(profileName)) {
          return true;
        }
      }

    } catch (TaskException e) {
      log.error(e);
    }

    return false;
  }
  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;
  }