コード例 #1
0
ファイル: CIManagerImpl.java プロジェクト: manoj-s/framework
 public void updateJob(ApplicationInfo appInfo, CIJob job) throws PhrescoException {
   if (debugEnabled) {
     S_LOGGER.debug(
         "Entering Method ProjectAdministratorImpl.updateJob(Project project, CIJob job)");
   }
   FileWriter writer = null;
   try {
     CIJobStatus jobStatus = configureJob(job, FrameworkConstants.CI_UPDATE_JOB_COMMAND);
     if (jobStatus.getCode() == -1) {
       throw new PhrescoException(jobStatus.getMessage());
     }
     if (debugEnabled) {
       S_LOGGER.debug("getCustomModules() ProjectInfo = " + appInfo);
     }
     updateJsonJob(appInfo, job);
   } catch (ClientHandlerException ex) {
     if (debugEnabled) {
       S_LOGGER.error(ex.getLocalizedMessage());
     }
     throw new PhrescoException(ex);
   } finally {
     if (writer != null) {
       try {
         writer.close();
       } catch (IOException e) {
         if (debugEnabled) {
           S_LOGGER.error(e.getLocalizedMessage());
         }
       }
     }
   }
 }
コード例 #2
0
ファイル: CIManagerImpl.java プロジェクト: manoj-s/framework
 private void writeJsonJobs(ApplicationInfo appInfo, List<CIJob> jobs, String status)
     throws PhrescoException {
   try {
     if (jobs == null) {
       return;
     }
     Gson gson = new Gson();
     List<CIJob> existingJobs = getJobs(appInfo);
     if (CI_CREATE_NEW_JOBS.equals(status) || existingJobs == null) {
       existingJobs = new ArrayList<CIJob>();
     }
     existingJobs.addAll(jobs);
     FileWriter writer = null;
     File ciJobFile = new File(getCIJobPath(appInfo));
     String jobJson = gson.toJson(existingJobs);
     writer = new FileWriter(ciJobFile);
     writer.write(jobJson);
     writer.flush();
   } catch (Exception e) {
     throw new PhrescoException(e);
   }
 }
コード例 #3
0
ファイル: CIManagerImpl.java プロジェクト: manoj-s/framework
 private boolean adaptExistingJobs(ApplicationInfo appInfo) {
   try {
     CIJob existJob = getJob(appInfo);
     S_LOGGER.debug("Going to get existing jobs to relocate!!!!!");
     if (existJob != null) {
       S_LOGGER.debug("Existing job found " + existJob.getName());
       boolean deleteExistJob = deleteCIJobFile(appInfo);
       Gson gson = new Gson();
       List<CIJob> existingJobs = new ArrayList<CIJob>();
       existingJobs.addAll(Arrays.asList(existJob));
       FileWriter writer = null;
       File ciJobFile = new File(getCIJobPath(appInfo));
       String jobJson = gson.toJson(existingJobs);
       writer = new FileWriter(ciJobFile);
       writer.write(jobJson);
       writer.flush();
       S_LOGGER.debug("Existing job moved to new type of project!!");
     }
     return true;
   } catch (Exception e) {
     S_LOGGER.debug("It is already adapted !!!!! ");
   }
   return false;
 }
コード例 #4
0
  public static void main(String[] argv) throws InterruptedException {
    // Arguments:
    // 1st = Mode
    // 2nd = Parent Path  -- (Parent path must have children /data  and /output

    System.out.println("+----------------------------------+");
    System.out.println("| Running Athena Pallas Processor  |");
    System.out.println("|             9/12/12              |");
    System.out.println("+----------------------------------+");

    Athena_Server_Obj = new ATHENA_Server_Local();

    BasicConfigurator.configure();
    Logger.getRootLogger().setLevel(Level.WARN);

    // Get and verify parameters
    if (argv.length < 2) {
      System.out.println("Not enough parameters.");
      System.out.println("Expected 2 parameters: 1st is MODE, 2nd is path to working directory.");
      System.out.println("Exiting.");
      System.exit(0);
    }

    String mode = argv[0];
    String parentPath = argv[1];
    File inFilePath = new File(parentPath + "astronautdata/");
    File outFilePath = new File(parentPath + "output/");
    File kbFilePath = new File(parentPath + "kbs/");

    if (mode.equals("")) {
      System.out.println("Parameter 1 is empty.  Should be RUNMODE (e.g. 'HTN'). Exiting");
      System.exit(0);
    }

    if (inFilePath.isDirectory() == false) {
      System.out.println(inFilePath.getName() + " directory is missing. Exiting");
      System.exit(0);
    }

    if (outFilePath.isDirectory() == false) {
      System.out.println(outFilePath.getName() + " directory is missing. Exiting");
      System.exit(0);
    }

    if (kbFilePath.isDirectory() == false) {
      System.out.println(kbFilePath.getName() + " directory is missing. Exiting");
      System.exit(0);
    }

    String kbID = "";
    TStringList IgnoredFileNames = new TStringList();

    // Main Loop
    while (mainLoopRunning) {
      if (Verbose == true) {
        // System.out.println("New Loop");
      }
      fileProcessed = false;
      if (Verbose == true) {
        // System.out.println("Ignoring #" + IgnoredFileNames.Count() + " files.");
      }

      // (re)load if needed
      if (loadKB == true) {
        String[] kbInfo = Athena_Server_Obj.loadKBInfo(mode, parentPath);
        String kbFilenamePath = kbInfo[0];
        kbID = kbInfo[1];

        Athena_Server_Obj.loadKB(kbFilenamePath, kbID);
        loadKB = false;
      }

      File[] listOfFiles = inFilePath.listFiles();
      // for (File child : inFilePath.listFiles()) {
      for (int i = 0; i < listOfFiles.length; i++) {
        File child = listOfFiles[i];
        if (".".equals(child.getName()) || "..".equals(child.getName())) {
          continue;
        }
        if (child.getName().toUpperCase().equals(mode + "-CMD.TXT")) {
          try {
            handleCommands(child.getPath(), outFilePath, mode);
            // fileProcessed = true;
            if (child.delete() == false) {
              System.out.println("Unable to delete: " + child.getPath());
              Thread.sleep(1000);
            }
          } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
          }
          // continue;
        }
        if (IgnoredFileNames.IndexOf(child.getName()) > -1) {
          // if (Verbose == true) {System.out.print("~");}
          continue;
        }
        if (Verbose == true) {
          System.out.println("Considering file: [" + child.getName() + "]");
        }
        String[] namePieces = child.getName().split("_");
        //  (should only open filenames with format of <MODE>_<DFN>.xml)
        if (Verbose == true) {
          System.out.println("File Name Is: " + child.getName());
        }
        String fileExt = GetFileExtension(child.getName());
        if (Verbose == true) {
          System.out.println("File Ext Is: " + fileExt);
        }
        // At times, there seems to be a race condition, where this java process
        //   tries to load in the file before the mump process is done writting
        // So I have modified the mumps process to that it outputs TWO files.
        //  1st the <MODE>_<DFN>.xml file
        //  2nd, after finished with above, it outputs <MODE>_<DFN>_READY.TXT
        // So the 2nd file must exist before opening the <MODE>_<DFN>.xml
        //  The 2nd file need not be opened or processed.  Just the fact that
        //  it exists on in the directory is signal that it is OK to process.
        if (fileExt.equals("xml") == false) {
          if (Verbose == true) {
            System.out.println("Skipping file due to wrong extension.");
          }
          IgnoredFileNames.Add(child.getName());
          continue;
        }
        if (((namePieces.length > 1) && (namePieces[0].equals(mode))) == false) {
          if (Verbose == true) {
            System.out.println("Skipping file due to wrong mode.");
          }
          IgnoredFileNames.Add(child.getName());
          continue;
        }
        Boolean finishFileExists = finishFileExist(child.getPath());
        if (Verbose == true) {
          System.out.println("Ready File Exists?: " + finishFileExists);
        }
        // NOTE: after processing the <MODE>_<DFN>.xml, both files should be deleted
        // NOTE: in java, one can't use '=' to compare strings -- that just compares a pointer to
        // the string.  Must use ".equals()"
        if (finishFileExists == true) {
          System.out.println("Found File to Process: [" + child.getName() + "]");
          fileProcessed = true;
          String patientID = namePieces[1];
          patientID = patientID.split("\\.")[0];
          File outFileName =
              new File(outFilePath.getPath() + "/" + mode + "_" + patientID + ".xml");
          String htmlFile = outFilePath.getPath() + "/" + mode + "_" + patientID + ".html";
          System.out.println("SENDING TO: [" + outFileName.getPath() + "]");
          String readyFileName;
          readyFileName = outFileName.getPath();
          try {
            processFile(patientID, child, outFileName, kbID, htmlFile);
          } catch (Throwable t) {
            try {
              FileWriter fwrite = new FileWriter(outFileName);
              fwrite.write(
                  "-1^CDSS/Clinical Decision Support Engine(Athena) Error. " + t.getMessage());
              fwrite.flush();
              fwrite.close();
            } catch (IOException e3) {
              System.out.println("Could not create error message");
            }
            System.out.println("Error Processing Recommendation: " + t.getMessage());
            // return;
          }
          System.out.println("Ready.TXT File Name Is: " + readyFileName); // Remove
          File readyFile = new File(readyFileName.replace(".xml", "_READY.TXT"));
          try {
            readyFile.createNewFile();
            FileWriter fstream = new FileWriter(readyFile);
            BufferedWriter out = new BufferedWriter(fstream);
            out.write("DONE");
            out.close();
            System.out.println("****SUCCESS****" + readyFile.getPath());
          } catch (java.io.IOException e0) {
            System.out.println("Error creating READY file");
          }
          if (child.delete() == false) {
            System.out.println("Unable to delete: " + child.getName());
            Thread.sleep(1000);
          }
          // Delete completed file
          File f = new File(getFinishFileName(child.getPath()));
          if (f.delete() == false) {
            System.out.println("Unable to delete: " + f.getName());
            Thread.sleep(1000);
          }
        }
      }
      if (fileProcessed == false) {
        Thread.sleep(1000);
        if (Verbose == true) {
          System.out.print(".");
        }
      } else {
        if (Verbose == true) {
          System.out.println("Found process, so won't sleep...");
        }
      }
      mainLoopRunning = false;
    } // for loop
    System.out.println("Finished with run.");
    System.exit(0);
  } // Main routine