public ArtifactData getCandidateAsync(String arg) throws Exception {
    reporter.trace("coordinate %s", arg);
    if (isUrl(arg))
      try {
        ArtifactData data = putAsync(new URI(arg));
        data.local = true;
        return data;
      } catch (Exception e) {
        reporter.trace("hmm, not a valid url %s, will try the server", arg);
      }

    Coordinate c = new Coordinate(arg);

    if (c.isSha()) {
      ArtifactData r = get(c.getSha());
      if (r != null) return r;
    }

    Revision revision = library.getRevisionByCoordinate(c);
    if (revision == null) return null;

    reporter.trace("revision %s", Hex.toHexString(revision._id));

    ArtifactData ad = get(revision._id);
    if (ad != null) {
      reporter.trace("found in cache");
      return ad;
    }

    URI url = revision.urls.iterator().next();
    ArtifactData artifactData = putAsync(url);
    artifactData.coordinate = c;
    return artifactData;
  }
  private void checkStartup(
      Map<String, ServiceData> map,
      List<ServiceData> start,
      ServiceData sd,
      Set<ServiceData> cyclic) {
    if (sd.after.isEmpty() || start.contains(sd)) return;

    if (cyclic.contains(sd)) {
      reporter.error("Cyclic dependency for " + sd.name);
      return;
    }

    cyclic.add(sd);

    for (String dependsOn : sd.after) {
      if (dependsOn.equals("boot")) continue;

      ServiceData deps = map.get(dependsOn);
      if (deps == null) {
        reporter.error("No such service " + dependsOn + " but " + sd.name + " depends on it");
      } else {
        checkStartup(map, start, deps, cyclic);
      }
    }
    start.add(sd);
  }
Example #3
0
  /*
   * Fetch a file that is in a Hadoop file system. Return a local File.
   * Interruptible.
   */
  private File hdfsFetch(Path fromPath, Reporter reporter)
      throws IOException, InterruptedException {
    UUID uniqueId = UUID.randomUUID();
    File toFile = new File(tempDir, uniqueId.toString() + "/" + fromPath.getName());
    File toDir = new File(toFile.getParent());
    if (toDir.exists()) {
      FileUtils.deleteDirectory(toDir);
    }
    toDir.mkdirs();
    Path toPath = new Path(toFile.getCanonicalPath());

    FileSystem fS = fromPath.getFileSystem(hadoopConf);
    FileSystem tofS = FileSystem.getLocal(hadoopConf);

    Throttler throttler = new Throttler((double) bytesPerSecThrottle);
    try {
      for (FileStatus fStatus : fS.globStatus(fromPath)) {
        log.info("Copying " + fStatus.getPath() + " to " + toPath);
        long bytesSoFar = 0;

        FSDataInputStream iS = fS.open(fStatus.getPath());
        FSDataOutputStream oS = tofS.create(toPath);

        byte[] buffer = new byte[downloadBufferSize];

        int nRead;
        while ((nRead = iS.read(buffer, 0, buffer.length)) != -1) {
          // Needed to being able to be interrupted at any moment.
          if (Thread.interrupted()) {
            iS.close();
            oS.close();
            cleanDirNoExceptions(toDir);
            throw new InterruptedException();
          }
          bytesSoFar += nRead;
          oS.write(buffer, 0, nRead);
          throttler.incrementAndThrottle(nRead);
          if (bytesSoFar >= bytesToReportProgress) {
            reporter.progress(bytesSoFar);
            bytesSoFar = 0l;
          }
        }

        if (reporter != null) {
          reporter.progress(bytesSoFar);
        }

        oS.close();
        iS.close();
      }

      return toDir;
    } catch (ClosedByInterruptException e) {
      // This can be thrown by the method read.
      cleanDirNoExceptions(toDir);
      throw new InterruptedIOException();
    }
  }
  /**
   * This is called when JPM runs in the background to start jobs
   *
   * @throws Exception
   */
  public void daemon() throws Exception {
    Runtime.getRuntime()
        .addShutdownHook(
            new Thread("Daemon shutdown") {
              public void run() {

                for (Service service : startedByDaemon) {
                  try {
                    reporter.error("Stopping " + service);
                    service.stop();
                    reporter.error("Stopped " + service);
                  } catch (Exception e) {
                    // Ignore
                  }
                }
              }
            });
    List<ServiceData> services = getServices();
    Map<String, ServiceData> map = new HashMap<String, ServiceData>();
    for (ServiceData d : services) {
      map.put(d.name, d);
    }
    List<ServiceData> start = new ArrayList<ServiceData>();
    Set<ServiceData> set = new HashSet<ServiceData>();
    for (ServiceData sd : services) {
      checkStartup(map, start, sd, set);
    }

    if (start.isEmpty()) reporter.warning("No services to start");

    for (ServiceData sd : start) {
      try {
        Service service = getService(sd.name);
        reporter.trace("Starting " + service);
        String result = service.start();
        if (result != null) reporter.error("Started error " + result);
        else startedByDaemon.add(service);
        reporter.trace("Started " + service);
      } catch (Exception e) {
        reporter.error("Cannot start daemon %s, due to %s", sd.name, e);
      }
    }

    while (true) {
      for (Service sd : startedByDaemon) {
        try {
          if (!sd.isRunning()) {
            reporter.error("Starting due to failure " + sd);
            String result = sd.start();
            if (result != null) reporter.error("Started error " + result);
          }
        } catch (Exception e) {
          reporter.error("Cannot start daemon %s, due to %s", sd, e);
        }
      }
      Thread.sleep(10000);
    }
  }
Example #5
0
 public static void main(String... args) {
   System.out.println("-- JSR 363 TCK started --");
   List<XmlSuite> suites = new ArrayList<>();
   suites.add(new TCKRunner());
   TestNG tng = new TestNG();
   tng.setXmlSuites(suites);
   tng.setOutputDirectory("./target/tck-results");
   //        tng.addListener(new VerboseReporter());
   File file = new File(System.getProperty("java.io.tmpdir"), "tck-results.txt");
   Reporter rep = new Reporter(file);
   System.out.println("Writing to file " + file.getAbsolutePath() + " ...");
   tng.addListener(rep);
   tng.run();
   rep.writeSummary();
   System.out.println("-- JSR 363 TCK finished --");
 }
Example #6
0
 @Override
 public void parameter(int p) {
   for (ClassDataCollector cd : shortlist)
     try {
       cd.parameter(p);
     } catch (Exception e) {
       reporter.error("Fail to class parameter on %s", cd);
     }
 }
Example #7
0
 @Override
 public void classBegin(int access, TypeRef name) {
   for (ClassDataCollector cd : delegates)
     try {
       cd.classBegin(access, name);
     } catch (Exception e) {
       reporter.error("Fail to class classBegin on %s", cd);
     }
 }
Example #8
0
 @Override
 public void referenceMethod(int access, TypeRef className, String method, String descriptor) {
   for (ClassDataCollector cd : shortlist)
     try {
       cd.referenceMethod(access, className, method, descriptor);
     } catch (Exception e) {
       reporter.error("Fail to call referenceMethod on %s", cd);
     }
 }
Example #9
0
 @Override
 public void version(int minor, int major) {
   for (ClassDataCollector cd : shortlist)
     try {
       cd.version(minor, major);
     } catch (Exception e) {
       reporter.error("Fail to call version on %s", cd);
     }
 }
Example #10
0
 @Override
 public void addReference(TypeRef ref) {
   for (ClassDataCollector cd : shortlist)
     try {
       cd.addReference(ref);
     } catch (Exception e) {
       reporter.error("Fail to class addReference on %s", cd);
     }
 }
Example #11
0
 @Override
 public void constant(Object object) {
   for (ClassDataCollector cd : shortlist)
     try {
       cd.constant(object);
     } catch (Exception e) {
       reporter.error("Fail to call constant on %s", cd);
     }
 }
Example #12
0
 @Override
 public void signature(String signature) {
   for (ClassDataCollector cd : shortlist)
     try {
       cd.signature(signature);
     } catch (Exception e) {
       reporter.error("Fail to call innerClass on %s", cd);
     }
 }
Example #13
0
 @Override
 public void enclosingMethod(TypeRef cName, String mName, String mDescriptor) {
   for (ClassDataCollector cd : shortlist)
     try {
       cd.enclosingMethod(cName, mName, mDescriptor);
     } catch (Exception e) {
       reporter.error("Fail to call enclosingMethod on %s", cd);
     }
 }
Example #14
0
 @Override
 public void deprecated() throws Exception {
   for (ClassDataCollector cd : shortlist)
     try {
       cd.deprecated();
     } catch (Exception e) {
       reporter.error("Fail to call deprecated on %s", cd);
     }
 }
Example #15
0
 @Override
 public void field(FieldDef defined) {
   for (ClassDataCollector cd : shortlist)
     try {
       cd.field(defined);
     } catch (Exception e) {
       reporter.error("Fail to call field on %s", cd);
     }
 }
Example #16
0
 @Override
 public void extendsClass(TypeRef zuper) throws Exception {
   for (ClassDataCollector cd : shortlist)
     try {
       cd.extendsClass(zuper);
     } catch (Exception e) {
       reporter.error("Fail to class extendsClass on %s", cd);
     }
 }
Example #17
0
 @Override
 public void implementsInterfaces(TypeRef[] interfaces) throws Exception {
   for (ClassDataCollector cd : shortlist)
     try {
       cd.implementsInterfaces(interfaces);
     } catch (Exception e) {
       reporter.error("Fail to class implementsInterfaces on %s", cd);
     }
 }
Example #18
0
 @Override
 public void memberEnd() {
   for (ClassDataCollector cd : shortlist)
     try {
       cd.memberEnd();
     } catch (Exception e) {
       reporter.error("Fail to call memberEnd on %s", cd);
     }
 }
Example #19
0
 @Override
 public void referTo(TypeRef typeRef, int modifiers) {
   for (ClassDataCollector cd : shortlist)
     try {
       cd.referTo(typeRef, modifiers);
     } catch (Exception e) {
       reporter.error("Fail to call referTo on %s", cd);
     }
 }
Example #20
0
 @Override
 public void annotation(Annotation annotation) {
   for (ClassDataCollector cd : shortlist)
     try {
       cd.annotation(annotation);
     } catch (Exception e) {
       reporter.error("Fail to class annotation on %s", cd);
     }
 }
Example #21
0
 @Override
 public void classEnd() throws Exception {
   for (ClassDataCollector cd : shortlist)
     try {
       cd.classEnd();
     } catch (Exception e) {
       reporter.error("Fail to call classEnd on %s", cd);
     }
   shortlist.clear();
 }
Example #22
0
 public void close() {
   for (ClassDataCollector cd : delegates)
     try {
       if (cd instanceof Closeable) ((Closeable) cd).close();
     } catch (Exception e) {
       reporter.error("Fail to call close on %s", cd);
     }
   delegates.clear();
   shortlist.clear();
 }
Example #23
0
 @Override
 public void innerClass(
     TypeRef innerClass, TypeRef outerClass, String innerName, int innerClassAccessFlags)
     throws Exception {
   for (ClassDataCollector cd : shortlist)
     try {
       cd.innerClass(innerClass, outerClass, innerName, innerClassAccessFlags);
     } catch (Exception e) {
       reporter.error("Fail to call innerClass on %s", cd);
     }
 }
  public void map(
      LongWritable key, Point value, OutputCollector<LongWritable, Point> output, Reporter reporter)
      throws IOException {
    double min = value.sumOfSquares(centers.get(0));
    int best = 0;

    for (int index = 1; index < numberOfCenters; ++index) {
      double current = value.sumOfSquares(centers.get(index));

      if (current < min) {
        min = current;
        best = index;
      }
    }

    reporter.incrCounter("NUMBER", "NODES", 1);
    reporter.incrCounter("CENTER", "" + best, 1);

    output.collect(new LongWritable(best), value);
  }
 void put(final URI uri, ArtifactData data) throws Exception {
   reporter.trace("put %s %s", uri, data);
   File tmp = createTempFile(repoDir, "mtp", ".whatever");
   tmp.deleteOnExit();
   try {
     copy(uri.toURL(), tmp);
     byte[] sha = SHA1.digest(tmp).digest();
     reporter.trace("SHA %s %s", uri, Hex.toHexString(sha));
     ArtifactData existing = get(sha);
     if (existing != null) {
       reporter.trace("existing");
       xcopy(existing, data);
       return;
     }
     File meta = new File(repoDir, Hex.toHexString(sha) + ".json");
     File file = new File(repoDir, Hex.toHexString(sha));
     rename(tmp, file);
     reporter.trace("file %s", file);
     data.file = file.getAbsolutePath();
     data.sha = sha;
     data.busy = false;
     CommandData cmddata = parseCommandData(data);
     if (cmddata.bsn != null) {
       data.name = cmddata.bsn + "-" + cmddata.version;
     } else data.name = Strings.display(cmddata.title, cmddata.bsn, cmddata.name, uri);
     codec.enc().to(meta).put(data);
     reporter.trace("TD = " + data);
   } finally {
     tmp.delete();
     reporter.trace("puted %s %s", uri, data);
   }
 }
Example #26
0
 protected void waitForOpenSlot(int maxProcessesOnNode, Reporter reporter)
     throws IOException, InterruptedException {
   while (true) {
     // sleep for a random length of time between 0 and 60 seconds
     long sleepTime = (long) (Math.random() * 1000 * 60);
     logger.info("sleeping for " + sleepTime);
     Thread.sleep(sleepTime);
     int numRunningMappers = getNumRunningMappers();
     logger.info("num running mappers: " + numRunningMappers);
     if (numRunningMappers < maxProcessesOnNode) return;
     reporter.progress();
   }
 }
Example #27
0
 @Override
 public boolean classStart(Clazz clazz) {
   boolean start = false;
   for (ClassDataCollector cd : delegates)
     try {
       if (cd.classStart(clazz)) {
         shortlist.add(cd);
         start = true;
       }
     } catch (Exception e) {
       reporter.error("Fail to class classStart on %s", cd);
     }
   return start;
 }
  /**
   * @param data
   * @param target
   * @throws Exception
   * @throws IOException
   */
  public String createCommand(CommandData data, boolean force) throws Exception, IOException {

    // TODO
    // if (Data.validate(data) != null)
    // return "Invalid command data: " + Data.validate(data);

    Map<String, String> map = null;
    if (data.trace) {
      map = new HashMap<String, String>();
      map.put("java.security.manager", "aQute.jpm.service.TraceSecurityManager");
      reporter.trace("tracing");
    }
    String s = platform.createCommand(data, map, force, service.getAbsolutePath());
    if (s == null) storeData(new File(commandDir, data.name), data);
    return s;
  }
Example #29
0
  public void map(
      LongWritable key, Text value, OutputCollector<Text, Text> output, Reporter reporter)
      throws IOException {
    if (this.output == null) {
      this.output = output;
    }
    if (this.reporter == null) {
      this.reporter = reporter;
    }

    String line = value.toString();
    String[] reads = line.split("\n");
    splitRead(key, reads[0], s1FileWriter);
    splitRead(key, reads[1], getRead2FileWriter());

    reporter.progress();
  }
 private void write2LogFile(ITestResult iTestResult, File testFolder) {
   BufferedWriter out = null;
   try {
     if (testFolder == null) {
       LogUtils.log("Can not write to file test folder is null");
       return;
     }
     String output = SGTestNGReporter.getOutput();
     if (StringUtils.isEmpty(output)) {
       LogUtils.log("nothing to write to log file");
       return;
     }
     String parameters = TestNGUtils.extractParameters(iTestResult);
     File testLogFile =
         new File(
             testFolder.getAbsolutePath()
                 + "/"
                 + iTestResult.getName()
                 + "("
                 + parameters
                 + ").log");
     if (!testLogFile.createNewFile()) {
       LogUtils.log(
           "Failed to create log file ["
               + testLogFile
               + "];\n log output: "
               + Reporter.getOutput());
       return;
     }
     FileWriter fstream = new FileWriter(testLogFile);
     out = new BufferedWriter(fstream);
     out.write(output);
   } catch (Exception e) {
     LogUtils.log("Failed to write to log file result - " + iTestResult, e);
   } finally {
     SGTestNGReporter.reset();
     if (out != null) {
       try {
         out.close();
       } catch (IOException e) {
         LogUtils.log("Failed closing stream", e);
         // ignore
       }
     }
   }
 }