/**
   * Activate Inactive Execution Plan Configurations
   *
   * @param tenantId the tenant id of the tenant which triggered this call
   * @param resolvedDependencyId the id of the dependency that was resolved which resulted in
   *     triggering this method call
   */
  public void activateInactiveExecutionPlanConfigurations(
      ExecutionPlanConfigurationFile.Status status, String resolvedDependencyId, int tenantId)
      throws ExecutionPlanConfigurationException {

    List<ExecutionPlanConfigurationFile> reloadFileList =
        new ArrayList<ExecutionPlanConfigurationFile>();

    if (tenantSpecificExecutionPlanFiles != null && tenantSpecificExecutionPlanFiles.size() > 0) {
      List<ExecutionPlanConfigurationFile> executionPlanConfigurationFiles =
          tenantSpecificExecutionPlanFiles.get(tenantId);

      if (executionPlanConfigurationFiles != null) {
        for (ExecutionPlanConfigurationFile executionPlanConfigurationFile :
            executionPlanConfigurationFiles) {
          if ((executionPlanConfigurationFile.getStatus().equals(status))
              && resolvedDependencyId.equalsIgnoreCase(
                  executionPlanConfigurationFile.getDependency())) {
            reloadFileList.add(executionPlanConfigurationFile);
          }
        }
      }
    }
    for (ExecutionPlanConfigurationFile executionPlanConfigurationFile : reloadFileList) {
      try {
        EventProcessorConfigurationFilesystemInvoker.reload(
            executionPlanConfigurationFile.getFileName(),
            executionPlanConfigurationFile.getAxisConfiguration());
      } catch (Exception e) {
        log.error(
            "Exception occurred while trying to deploy the Execution Plan configuration file : "
                + new File(executionPlanConfigurationFile.getFileName()).getName());
      }
    }
  }
  @Override
  public List<ExecutionPlanConfigurationFile> getAllInactiveExecutionPlanConfiguration(
      int tenantId) {
    List<ExecutionPlanConfigurationFile> executionPlanConfigurationFiles =
        this.tenantSpecificExecutionPlanFiles.get(tenantId);

    List<ExecutionPlanConfigurationFile> files = new ArrayList<ExecutionPlanConfigurationFile>();
    if (executionPlanConfigurationFiles != null) {
      for (ExecutionPlanConfigurationFile configFile : executionPlanConfigurationFiles) {
        if (configFile.getStatus() == ExecutionPlanConfigurationFile.Status.ERROR
            || configFile.getStatus()
                == ExecutionPlanConfigurationFile.Status.WAITING_FOR_DEPENDENCY
            || configFile.getStatus()
                == ExecutionPlanConfigurationFile.Status.WAITING_FOR_OSGI_SERVICE) {
          files.add(configFile);
        }
      }
    }
    return files;
  }
 // gets file by name.
 private ExecutionPlanConfigurationFile getExecutionPlanConfigurationFileByPlanName(
     String name, int tenantId) {
   List<ExecutionPlanConfigurationFile> executionPlanConfigurationFiles =
       tenantSpecificExecutionPlanFiles.get(tenantId);
   if (executionPlanConfigurationFiles != null) {
     for (ExecutionPlanConfigurationFile file : executionPlanConfigurationFiles) {
       if (name.equals(file.getExecutionPlanName())
           && file.getStatus().equals(ExecutionPlanConfigurationFile.Status.DEPLOYED)) {
         return file;
       }
     }
   }
   return null;
 }
 /**
  * Just removes the configuration file
  *
  * @param fileName the filename of the {@link ExecutionPlanConfigurationFile} to be removed
  * @param tenantId the tenantId of the tenant to which this configuration file belongs
  */
 public void removeExecutionPlanConfigurationFile(String fileName, int tenantId) {
   List<ExecutionPlanConfigurationFile> executionPlanConfigurationFiles =
       tenantSpecificExecutionPlanFiles.get(tenantId);
   for (Iterator<ExecutionPlanConfigurationFile> iterator =
           executionPlanConfigurationFiles.iterator();
       iterator.hasNext(); ) {
     ExecutionPlanConfigurationFile configurationFile = iterator.next();
     if (configurationFile.getFileName().equals(fileName)) {
       if (configurationFile.getStatus().equals(ExecutionPlanConfigurationFile.Status.DEPLOYED)) {
         removeExecutionPlanConfiguration(configurationFile.getExecutionPlanName(), tenantId);
       }
       iterator.remove();
       break;
     }
   }
 }
  private void validateToRemoveInactiveExecutionPlanConfiguration(
      String executionPlanName, AxisConfiguration axisConfiguration)
      throws ExecutionPlanConfigurationException {
    int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();

    String fileName = executionPlanName + EventProcessorConstants.EP_CONFIG_FILE_EXTENSION_WITH_DOT;
    List<ExecutionPlanConfigurationFile> executionPlanConfigurationFiles =
        tenantSpecificExecutionPlanFiles.get(tenantId);
    if (executionPlanConfigurationFiles != null) {
      for (ExecutionPlanConfigurationFile executionPlanConfigurationFile :
          executionPlanConfigurationFiles) {
        if ((executionPlanConfigurationFile.getFileName().equals(fileName))) {
          if (!(executionPlanConfigurationFile
              .getStatus()
              .equals(ExecutionPlanConfigurationFile.Status.DEPLOYED))) {
            EventProcessorConfigurationFilesystemInvoker.delete(fileName, axisConfiguration);
            break;
          }
        }
      }
    }
  }