Пример #1
1
 private CIJobStatus deleteCI(CIJob job, List<String> builds) throws PhrescoException {
   S_LOGGER.debug("Entering Method CIManagerImpl.deleteCI(CIJob job)");
   S_LOGGER.debug("Job name " + job.getName());
   cli = getCLI(job);
   String deleteType = null;
   List<String> argList = new ArrayList<String>();
   S_LOGGER.debug("job name " + job.getName());
   S_LOGGER.debug("Builds " + builds);
   if (CollectionUtils.isEmpty(builds)) { // delete job
     S_LOGGER.debug("Job deletion started");
     S_LOGGER.debug("Command " + FrameworkConstants.CI_JOB_DELETE_COMMAND);
     deleteType = DELETE_TYPE_JOB;
     argList.add(FrameworkConstants.CI_JOB_DELETE_COMMAND);
     argList.add(job.getName());
   } else { // delete Build
     S_LOGGER.debug("Build deletion started");
     deleteType = DELETE_TYPE_BUILD;
     argList.add(FrameworkConstants.CI_BUILD_DELETE_COMMAND);
     argList.add(job.getName());
     StringBuilder result = new StringBuilder();
     for (String string : builds) {
       result.append(string);
       result.append(",");
     }
     String buildNos = result.substring(0, result.length() - 1);
     argList.add(buildNos);
     S_LOGGER.debug("Command " + FrameworkConstants.CI_BUILD_DELETE_COMMAND);
     S_LOGGER.debug("Build numbers " + buildNos);
   }
   try {
     int status = cli.execute(argList);
     String message = deleteType + " deletion started in jenkins";
     if (status == FrameworkConstants.JOB_STATUS_NOTOK) {
       deleteType = deleteType.substring(0, 1).toLowerCase() + deleteType.substring(1);
       message = "Error while deleting " + deleteType + " in jenkins";
     }
     S_LOGGER.debug("Delete CI Status " + status);
     S_LOGGER.debug("Delete CI Message " + message);
     return new CIJobStatus(status, message);
   } finally {
     if (cli != null) {
       try {
         cli.close();
       } catch (IOException e) {
         if (debugEnabled) {
           S_LOGGER.error(
               "Entered into catch block of CIManagerImpl.deleteCI(CIJob job) "
                   + e.getLocalizedMessage());
         }
       } catch (InterruptedException e) {
         if (debugEnabled) {
           S_LOGGER.error(
               "Entered into catch block of CIManagerImpl.deleteCI(CIJob job) "
                   + e.getLocalizedMessage());
         }
       }
     }
   }
 }
Пример #2
0
  private CIJobStatus buildJob(CIJob job) throws PhrescoException {
    if (debugEnabled) {
      S_LOGGER.debug("Entering Method CIManagerImpl.buildJob(CIJob job)");
    }
    cli = getCLI(job);

    List<String> argList = new ArrayList<String>();
    argList.add(FrameworkConstants.CI_BUILD_JOB_COMMAND);
    argList.add(job.getName());
    try {
      int status = cli.execute(argList);
      String message = FrameworkConstants.CI_BUILD_STARTED;
      if (status == FrameworkConstants.JOB_STATUS_NOTOK) {
        message = FrameworkConstants.CI_BUILD_STARTING_ERROR;
      }
      return new CIJobStatus(status, message);
    } finally {
      if (cli != null) {
        try {
          cli.close();
        } catch (IOException e) {
          if (debugEnabled) {
            S_LOGGER.error(e.getLocalizedMessage());
          }
        } catch (InterruptedException e) {
          if (debugEnabled) {
            S_LOGGER.error(e.getLocalizedMessage());
          }
        }
      }
    }
  }
Пример #3
0
 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());
         }
       }
     }
   }
 }
Пример #4
0
 private void send(Message m) {
   try {
     moteIF.send(MoteIF.TOS_BCAST_ADDR, m);
   } catch (IOException e) {
     e.printStackTrace();
     System.out.println("ERROR: Can't send message");
     System.exit(1);
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
Пример #5
0
 private CIJob getJob(ApplicationInfo appInfo) throws PhrescoException {
   Gson gson = new Gson();
   try {
     BufferedReader br = new BufferedReader(new FileReader(getCIJobPath(appInfo)));
     CIJob job = gson.fromJson(br, CIJob.class);
     br.close();
     return job;
   } catch (FileNotFoundException e) {
     S_LOGGER.debug(e.getLocalizedMessage());
     return null;
   } catch (com.google.gson.JsonParseException e) {
     S_LOGGER.debug("it is already adpted project !!!!! " + e.getLocalizedMessage());
     return null;
   } catch (IOException e) {
     S_LOGGER.debug(e.getLocalizedMessage());
     return null;
   }
 }
Пример #6
0
  private String[] loadKBInfo(String mode, String parentPath) {
    // Results:  [0] = kbFilePath
    //			[1] = kbID

    String[] results = new String[2];
    results[0] = "";
    results[1] = "";
    String configFilePath = parentPath + "config/";
    File configFileDir = new File(configFilePath);
    if (configFileDir.isDirectory() == false) {
      System.out.println(configFileDir.getName() + " directory is missing. Exiting");
      System.exit(0);
    }

    String configFName = parentPath + "config/KB MAP.txt";
    TStringList sl = new TStringList();
    try {
      sl.ReadFromFile(configFName);
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    for (int i = 0; i < sl.Count(); i++) {
      String s = sl.getString(i);
      String lbl = s.split("=")[0];
      if (lbl.equals("")) continue;
      String[] lblParts = lbl.split(":");
      if (lblParts.length < 2) continue;
      if (lblParts[0].equals(mode) == false) continue;
      if (lblParts[1].equals("KB")) {
        String kbFilePath = parentPath + "kbs/" + s.split("=")[1].trim();
        results[0] = kbFilePath;
      } else if (lblParts[1].equals("ID")) {
        results[1] = s.split("=")[1].trim(); // kb ID string
      }
    }
    return results;
  }
Пример #7
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
Пример #8
0
  public static Data getHTTPData(
      HttpServletRequest req, HttpServletResponse res, String surl, long since)
      throws DataSourceException, IOException {

    int tries = 1;

    // timeout msecs of time we're allowed in this routine
    // we must return or throw an exception.  0 means infinite.
    int timeout = mTimeout;
    if (req != null) {
      String timeoutParm = req.getParameter("timeout");
      if (timeoutParm != null) {
        timeout = Integer.parseInt(timeoutParm);
      }
    }

    long t1 = System.currentTimeMillis();
    long elapsed = 0;
    if (surl == null) {
      surl = getURL(req);
    }

    while (true) {
      String m = null;

      long tout;
      if (timeout > 0) {
        tout = timeout - elapsed;
        if (tout <= 0) {
          throw new InterruptedIOException(
              /* (non-Javadoc)
               * @i18n.test
               * @org-mes=p[0] + " timed out"
               */
              org.openlaszlo.i18n.LaszloMessages.getMessage(
                  HTTPDataSource.class.getName(), "051018-194", new Object[] {surl}));
        }
      } else {
        tout = 0;
      }

      try {
        HttpData data = getDataOnce(req, res, since, surl, 0, (int) tout);
        if (data.code >= 400) {
          data.release();
          throw new DataSourceException(errorMessage(data.code));
        }
        return data;
      } catch (HttpRecoverableException e) {
        // This type of exception should be retried.
        if (tries++ > mMaxRetries) {
          throw new InterruptedIOException(
              /* (non-Javadoc)
               * @i18n.test
               * @org-mes="too many retries, exception: " + p[0]
               */
              org.openlaszlo.i18n.LaszloMessages.getMessage(
                  HTTPDataSource.class.getName(), "051018-217", new Object[] {e.getMessage()}));
        }
        mLogger.warn(
            /* (non-Javadoc)
             * @i18n.test
             * @org-mes="retrying a recoverable exception: " + p[0]
             */
            org.openlaszlo.i18n.LaszloMessages.getMessage(
                HTTPDataSource.class.getName(), "051018-226", new Object[] {e.getMessage()}));
      } catch (HttpException e) {
        String msg =
            /* (non-Javadoc)
             * @i18n.test
             * @org-mes="HttpException: " + p[0]
             */
            org.openlaszlo.i18n.LaszloMessages.getMessage(
                HTTPDataSource.class.getName(), "051018-235", new Object[] {e.getMessage()});
        throw new IOException(
            /* (non-Javadoc)
             * @i18n.test
             * @org-mes="HttpException: " + p[0]
             */
            org.openlaszlo.i18n.LaszloMessages.getMessage(
                HTTPDataSource.class.getName(), "051018-235", new Object[] {e.getMessage()}));
      } catch (IOException e) {

        try {
          Class ssle = Class.forName("javax.net.ssl.SSLException");
          if (ssle.isAssignableFrom(e.getClass())) {
            throw new DataSourceException(
                /* (non-Javadoc)
                 * @i18n.test
                 * @org-mes="SSL exception: " + p[0]
                 */
                org.openlaszlo.i18n.LaszloMessages.getMessage(
                    HTTPDataSource.class.getName(), "051018-256", new Object[] {e.getMessage()}));
          }
        } catch (ClassNotFoundException cfne) {
        }

        throw e;
      }

      long t2 = System.currentTimeMillis();
      elapsed = (t2 - t1);
    }
  }
Пример #9
0
  private CIJobStatus configureJob(CIJob job, String jobType) throws PhrescoException {
    if (debugEnabled) {
      S_LOGGER.debug("Entering Method CIManagerImpl.createJob(CIJob job)");
    }
    try {
      cli = getCLI(job);
      List<String> argList = new ArrayList<String>();
      argList.add(jobType);
      argList.add(job.getName());

      String jenkinsTemplateDir = Utility.getJenkinsTemplateDir();
      String configFilePath = jenkinsTemplateDir + job.getRepoType() + HYPHEN + CONFIG_XML;
      if (debugEnabled) {
        S_LOGGER.debug("configFilePath ...  " + configFilePath);
      }

      File configFile = new File(configFilePath);
      ConfigProcessor processor = new ConfigProcessor(configFile);
      customizeNodes(processor, job);

      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      if (debugEnabled) {
        S_LOGGER.debug("argList " + argList.toString());
      }
      int result = cli.execute(argList, processor.getConfigAsStream(), System.out, baos);

      String message = "Job created successfully";
      if (result == -1) {
        byte[] byteArray = baos.toByteArray();
        message = new String(byteArray);
      }
      if (debugEnabled) {
        S_LOGGER.debug("message " + message);
      }
      // when svn is selected credential value has to set
      if (SVN.equals(job.getRepoType())) {
        setSvnCredential(job);
      }

      setMailCredential(job);
      return new CIJobStatus(result, message);
    } catch (IOException e) {
      throw new PhrescoException(e);
    } catch (JDOMException e) {
      throw new PhrescoException(e);
    } finally {
      if (cli != null) {
        try {
          cli.close();
        } catch (IOException e) {
          if (debugEnabled) {
            S_LOGGER.error(e.getLocalizedMessage());
          }
        } catch (InterruptedException e) {
          if (debugEnabled) {
            S_LOGGER.error(e.getLocalizedMessage());
          }
        }
      }
    }
  }