Example #1
0
  public void loadProperty() {

    try {

      File file = new File(confFileName);

      log.debug("file=" + file.getAbsolutePath());

      confProperties = new Properties();
      confProperties.loadFromXML(new FileInputStream(file));

      bonitaApiHost = confProperties.getProperty("bonita.api.host");
      bonitaApiUsername = confProperties.getProperty("bonita.api.username");
      bonitaApiPassword = confProperties.getProperty("bonita.api.password");
      bonitaApiHttpUsername = confProperties.getProperty("bonita.api.http.username");
      bonitaApiHttpPassword = confProperties.getProperty("bonita.api.http.password");
      bonitaApiPath = confProperties.getProperty("bonita.api.path");

      rallyApiHost = confProperties.getProperty("rally.api.host");
      rallyApiHttpUsername = confProperties.getProperty("rally.api.http.username");
      rallyApiHttpPassword = confProperties.getProperty("rally.api.http.password");
      rallyProjectIds = confProperties.getProperty("rally.project.ids");

      // bonitaProcessId=properties.getProperty("bonita.process.xp_code.id");

      workflowServiceUrl = confProperties.getProperty("service.url");

    } catch (Exception e) {
      log.error("", e);
    }
  }
Example #2
0
  // Grabs assets off the intarwebz and saves them to a local store/jail for hydration.
  private void fetch(JSONArray args) {
    String url;
    String username;
    String password;
    String id;
    try {
      id = args.getString(0);
      url = args.getString(1);
      username = args.getString(2);
      password = args.getString(3);

      // Create directory for app.
      local_path = "/data/data/" + ctx.getPackageName() + "/remote_app/" + id + "/";
      File fp = new File(local_path);
      fp.mkdirs();

      if (fetchApp(url, username, password)) {
        this.success(
            new PluginResult(PluginResult.Status.OK, "file://" + local_path + "index.html"),
            this.callback);
      } else {
        this.error(
            new PluginResult(
                PluginResult.Status.ERROR,
                "Error during app saving or fetching; protocol or IO error likely."),
            this.callback);
      }
    } catch (JSONException e) {
      this.error(
          new PluginResult(
              PluginResult.Status.JSON_EXCEPTION,
              "JSON exception during argument parsing; make sure the app ID, URL, username and password were passed as an argument."),
          this.callback);
    }
  }
Example #3
0
  // function to do the compute use case
  public static void compute() throws Exception {
    HttpPost method = new HttpPost(url + "/compute");

    method.setEntity(new StringEntity(username, "UTF-8"));

    try {
      ResponseHandler<String> responseHandler = new BasicResponseHandler();
      connIp = client.execute(method, responseHandler);
    } catch (IOException e) {
      System.err.println("Fatal transport error: " + e.getMessage());
      e.printStackTrace();
    }

    System.out.println("Give the file name which has to be put in the grid for computation");

    // input of the file name to be computed
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String name = in.readLine();

    // get the absolute path of the current working directory
    File directory = new File(".");
    String pwd = directory.getAbsolutePath();

    // get present time
    date = new Date();
    long start = date.getTime();

    String cmd = "java -classpath " + pwd + "/vishwa/JVishwa.jar:. " + name + " " + connIp;
    System.out.println(cmd);

    // Execute the vishwa compute process
    Process p = Runtime.getRuntime().exec(cmd);

    // wait till the compute process is completed
    // check for the status code (0 for successful termination)
    int status = p.waitFor();

    if (status == 0) {
      System.out.println("Compute operation successful. Check the directory for results");
    }

    date = new Date();
    long end = date.getTime();
    long durationInt = end - start;

    String duration = String.valueOf(durationInt);
    method = new HttpPost(url + "/computeAck");
    method.setEntity(new StringEntity(username + ";" + duration, "UTF-8"));
    try {
      client.execute(method);
    } catch (IOException e) {
      System.err.println("Fatal transport error: " + e.getMessage());
      e.printStackTrace();
    }
  }
Example #4
0
 // When already existing adapted project is created , need to move to new adapted project
 private boolean deleteCIJobFile(ApplicationInfo appInfo) throws PhrescoException {
   S_LOGGER.debug("Entering Method ProjectAdministratorImpl.deleteCI()");
   try {
     File ciJobInfo = new File(getCIJobPath(appInfo));
     return ciJobInfo.delete();
   } catch (ClientHandlerException ex) {
     S_LOGGER.error(
         "Entered into catch block of ProjectAdministratorImpl.deleteCI()"
             + ex.getLocalizedMessage());
     throw new PhrescoException(ex);
   }
 }
 /*.................................................................................................................*/
 public void processOutputFiles(String jobURL) {
   if (rootDir != null) {
     downloadWorkingResults(jobURL, rootDir, true);
     if (outputFileProcessor != null && outputFilePaths != null && lastModified != null) {
       String[] paths = outputFileProcessor.modifyOutputPaths(outputFilePaths);
       for (int i = 0; i < paths.length && i < lastModified.length; i++) {
         File file = new File(paths[i]);
         long lastMod = file.lastModified();
         if (!MesquiteLong.isCombinable(lastModified[i]) || lastMod > lastModified[i]) {
           outputFileProcessor.processOutputFile(paths, i);
           lastModified[i] = lastMod;
         }
       }
     }
   }
 }
Example #6
0
 private boolean deleteDirectory(File path) {
   File[] files = path.listFiles();
   for (int i = 0; i < files.length; i++) {
     File f = files[i];
     if (f.isFile()) {
       if (!f.delete()) {
         return false;
       }
     } else {
       if (!deleteDirectory(f)) {
         return false;
       }
     }
   }
   if (path.delete()) {
     return true;
   } else {
     return false;
   }
 }
Example #7
0
  public void getFilesFromFolder(List filesAndFolders, String savePath) {
    // create a File object for the parent directory
    File downloadsDirectory = new File(savePath);
    // create the folder if needed.
    downloadsDirectory.mkdir();

    for (int i = 0; i < filesAndFolders.size(); i++) {
      Object links = filesAndFolders.get(i);
      List linksArray = (ArrayList) links;
      if (i == 0) {
        for (int j = 0; j < linksArray.size(); j += 2) {
          // We've got an array of file urls so download each one to a directory with the folder
          // name
          String fileURL = linksArray.get(j).toString();
          String fileName = linksArray.get(j + 1).toString();
          downloadFile(fileURL, savePath, fileName);
          progress++;
          Message msg = mHandler.obtainMessage();
          msg.arg1 = progress;
          mHandler.sendMessage(msg);
        }
      } else if (i == 1) {
        // we've got an array of folders so recurse down the levels, extracting subfolders and files
        // until we've downloaded everything.
        for (int j = 0; j < linksArray.size(); j += 2) {
          String folderURL = linksArray.get(j).toString();
          String folderName = linksArray.get(j + 1).toString();

          String page = getData(folderURL);
          List newFilesAndFolders = parsePage(page);
          String dlDirPath = savePath + folderName + "/";

          getFilesFromFolder(newFilesAndFolders, dlDirPath);
        }
      }
    }
  }
Example #8
0
  private boolean saveAndVerify(ZipInputStream data) throws IOException {
    try {
      ZipEntry ze;
      while ((ze = data.getNextEntry()) != null) {
        // Filename + reference to file.
        String filename = ze.getName();
        File output = new File(local_path + filename);

        if (filename.endsWith("/")) {
          output.mkdirs();
        } else {
          if (output.exists()) {
            // Delete the file if it already exists.
            if (!output.delete()) {
              return false;
            }
          }
          if (output.createNewFile()) {
            FileOutputStream out = new FileOutputStream(output);
            byte[] buffer = new byte[1024];
            int count;
            while ((count = data.read(buffer)) != -1) {
              out.write(buffer, 0, count);
            }
          } else {
            return false;
          }
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
      return false;
    } finally {
      data.close();
    }
    return true;
  }