Ejemplo n.º 1
0
    RunInfo getRunInfo(BenchmarkDefinition benchDef) throws Exception {

      RunInfo runInfo = new RunInfo();
      String v = xp.evaluate("fa:scale", runConfigNode);
      if (v != null && v.length() > 0) {
        try {
          runInfo.scale = Integer.parseInt(v);
        } catch (NumberFormatException e) {
          throw new ConfigurationException("<scale> must be an integer.");
        }
      }

      v = xp.evaluate("fa:runControl/fa:rampUp", runConfigNode);
      if (v == null || v.length() == 0) {
        throw new ConfigurationException("Element <rampUp> not found.");
      }
      try {
        runInfo.rampUp = Integer.parseInt(v);
      } catch (NumberFormatException e) {
        throw new ConfigurationException("<rampUp> must be an integer.");
      }

      v = xp.evaluate("fa:runControl/fa:steadyState", runConfigNode);
      if (v == null || v.length() == 0) {
        throw new ConfigurationException("Element <steadyState> not found.");
      }
      try {
        runInfo.stdyState = Integer.parseInt(v);
      } catch (NumberFormatException e) {
        throw new ConfigurationException("<steadyState> must be an integer.");
      }

      v = xp.evaluate("fa:runControl/fa:rampDown", runConfigNode);
      if (v == null || v.length() == 0) {
        throw new ConfigurationException("Element <rampDown> not found.");
      }
      try {
        runInfo.rampDown = Integer.parseInt(v);
      } catch (NumberFormatException e) {
        throw new ConfigurationException("<rampDown> must be an integer.");
      }

      v = xp.evaluate("fa:runControl/fa:variableLoad", runConfigNode);
      if (v != null && v.length() > 0) {
        try {
          runInfo.variableLoad = relaxedParseBoolean(v);
        } catch (NumberFormatException e) {
          throw new ConfigurationException("<variableLoad> must be true or false.");
        }
      }

      if (runInfo.variableLoad) {
        runInfo.variableLoadFile = xp.evaluate("fa:runControl/fa:variableLoadFile", runConfigNode);
      }

      runInfo.resultsDir = xp.evaluate("fd:outputDir", runConfigNode);
      if (runInfo.resultsDir == null || runInfo.resultsDir.length() == 0) {
        throw new ConfigurationException("Element <outputDir> not found.");
      }

      v = xp.evaluate("fd:audit", runConfigNode);
      if (v != null && v.length() > 0) {
        try {
          runInfo.audit = relaxedParseBoolean(v);
        } catch (NumberFormatException e) {
          throw new ConfigurationException("<audit> must be true or false.");
        }
      }

      v = xp.evaluate("fd:threadStart/fd:delay", runConfigNode);
      if (v != null && v.length() > 0) {
        try {
          runInfo.msBetweenThreadStart = Integer.parseInt(v);
        } catch (NumberFormatException e) {
          throw new ConfigurationException("<delay> must be an integer.");
        }
      }

      v = xp.evaluate("fd:threadStart/fd:simultaneous", runConfigNode);
      if (v != null && v.length() > 0) {
        try {
          runInfo.simultaneousStart = relaxedParseBoolean(v);
        } catch (NumberFormatException e) {
          throw new ConfigurationException("<simultaneous> must be true or false.");
        }
      }

      v = xp.evaluate("fd:threadStart/fd:parallel", runConfigNode);
      if (v != null && v.length() > 0) {
        try {
          runInfo.parallelAgentThreadStart = relaxedParseBoolean(v);
        } catch (NumberFormatException e) {
          throw new ConfigurationException("<parallel> must be true or false.");
        }
      }

      v = xp.evaluate("fd:stats/fd:maxRunTime", runConfigNode);
      if (v != null && v.length() > 0) {
        try {
          runInfo.maxRunTime = Integer.parseInt(v);
        } catch (NumberFormatException e) {
          throw new ConfigurationException("<maxRunTime> must be an integer.");
        }
      }

      v = xp.evaluate("fd:stats/fd:interval", runConfigNode);
      if (v != null && v.length() > 0) {
        try {
          runInfo.graphInterval = Integer.parseInt(v);
        } catch (NumberFormatException e) {
          throw new ConfigurationException("<interval> must be an integer.");
        }
      }

      v = xp.evaluate("fd:runtimeStats/@enabled", runConfigNode);
      if (v != null && v.length() > 0) {
        try {
          runInfo.runtimeStatsEnabled = relaxedParseBoolean(v);
        } catch (Exception e) {
          throw new ConfigurationException("<runtimeStats enabled=[true|false]>");
        }
      }

      v = xp.evaluate("fd:runtimeStats/fd:interval", runConfigNode);
      if (v != null && v.length() > 0) {
        try {
          runInfo.runtimeStatsInterval = Integer.parseInt(v);
        } catch (NumberFormatException e) {
          throw new ConfigurationException("<interval> must be an integer.");
        }
      }

      runInfo.driverConfigs = new DriverConfig[benchDef.drivers.length];
      for (int i = 0; i < benchDef.drivers.length; i++) {
        DriverConfig driverConfig = new DriverConfig(benchDef.drivers[i]);
        Element driverConfigNode =
            (Element)
                xp.evaluate(
                    "fd:driverConfig[@name=\"" + driverConfig.name + "\"][1]",
                    runConfigNode,
                    XPathConstants.NODE);

        driverConfig.runControl = benchDef.runControl;
        if (driverConfigNode == null) {
          throw new ConfigurationException(
              "Element " + "<driverConfig name=\"" + driverConfig.name + "\"> not found.");
        }

        v = xp.evaluate("fd:agents", driverConfigNode);

        // Note that the agents field has two valid formats:
        // 1. A single integer
        // 2. One or more host:count fields
        // The harness is interested in the host/count. What we need
        // is a simple count. Just add'em up.
        if (v != null && v.length() > 0) {
          StringTokenizer t = new StringTokenizer(v, " ,");
          driverConfig.numAgents = 0;
          while (t.hasMoreTokens()) {
            v = t.nextToken().trim();
            if (v.length() == 0) {
              continue;
            }
            int idx = v.indexOf(':');
            if (++idx > 0) {
              v = v.substring(idx);
            }
            if (v.length() == 0) {
              continue;
            }
            try {
              driverConfig.numAgents += Integer.parseInt(v);
            } catch (NumberFormatException e) {

              throw new ConfigurationException(
                  "<agents> "
                      + "must be an integer or in the format "
                      + "host:agents where agents is an integer. "
                      + "Found: "
                      + v);
            }
          }
        }

        v = xp.evaluate("fd:threads", driverConfigNode);
        if (v != null && v.length() > 0) {
          try {
            driverConfig.numThreads = Integer.parseInt(v);
          } catch (NumberFormatException e) {
            throw new ConfigurationException("<threads> must be an integer.");
          }
        }

        v = xp.evaluate("fd:stats/fd:interval", driverConfigNode);
        if (v != null && v.length() > 0) {
          try {
            driverConfig.graphInterval = Integer.parseInt(v);
          } catch (NumberFormatException e) {
            throw new ConfigurationException("<interval> must be an integer.");
          }
        } else {
          driverConfig.graphInterval = runInfo.graphInterval;
        }

        if (runInfo.runtimeStatsEnabled) {
          driverConfig.runtimeStatsTarget =
              xp.evaluate("fd:runtimeStats/@target", driverConfigNode);
          if (driverConfig.runtimeStatsTarget != null) {
            driverConfig.runtimeStatsTarget = driverConfig.runtimeStatsTarget.trim();
            if (driverConfig.runtimeStatsTarget.length() == 0)
              driverConfig.runtimeStatsTarget = null;
          }
        }

        if (runInfo.variableLoad) {
          driverConfig.variableLoadFile = xp.evaluate("fd:variableLoadFile", driverConfigNode);
          if (driverConfig.variableLoadFile == null
              || driverConfig.variableLoadFile.length() == 0) {
            driverConfig.variableLoadFile = runInfo.variableLoadFile;
          }
          if (driverConfig.variableLoadFile == null
              || driverConfig.variableLoadFile.length() == 0) {
            throw new ConfigurationException("Element <variableLoadFile> not found.");
          }
        }

        driverConfig.rootElement = rootElement;
        driverConfig.properties =
            (Element) xp.evaluate("fd:properties", driverConfigNode, XPathConstants.NODE);
        driverConfig.mix[0].configure(driverConfigNode);
        driverConfig.mix[0].configureCycles(driverConfigNode);
        driverConfig.mix[0].normalize();
        runInfo.driverConfigs[i] = driverConfig;

        // need to store the class bytes for a remote agent
        // if the driver is an http driver

        InputStream is = null;
        String defClassName = getDefiningClassName();
        try {
          // check whether this class is defined in this class loader

          ClassLoader cl = this.getClass().getClassLoader();
          cl.loadClass(defClassName);

        } catch (ClassNotFoundException cnfe) {

          String tempDir = System.getProperty("faban.tmpdir");

          if (tempDir == null) {
            tempDir = System.getProperty("java.io.tmpdir");
          }

          File classFile = new File(tempDir);

          URL url[] = new URL[1];

          try {
            url[0] = classFile.toURI().toURL();
          } catch (MalformedURLException ex) {
            throw new ConfigurationException(ex);
          }

          URLClassLoader loader =
              new URLClassLoader(url, BenchmarkDefinition.class.getClassLoader());

          try {

            loader.loadClass(defClassName);
            is = loader.getResourceAsStream(defClassName + ".class");

            runInfo.defBytes = new byte[is.available()];
            is.read(runInfo.defBytes);
            is.close();
            System.out.println("Bytes Read from class :" + runInfo.defBytes.length);

          } catch (ClassNotFoundException cnfex) {
            throw new ConfigurationException(cnfex);
          } catch (IOException ioex) {
            throw new ConfigurationException(ioex);
          }
        }
      }
      return runInfo;
    }
Ejemplo n.º 2
0
  /**
   * The method postDeserialize re-establishes the non-serializable fields.
   *
   * @throws ClassNotFoundException
   */
  public void postDeserialize() throws ClassNotFoundException {
    if (instance == null) {
      instance = this;
    }

    if (driverConfig.driverClass == null) {
      try {
        // first try the default class loader
        ClassLoader cl = this.getClass().getClassLoader();
        driverConfig.driverClass = cl.loadClass(driverConfig.className);

      } catch (ClassNotFoundException cnfe) {
        // do nothing, check defBytes
      }
    }
    // If we couldn't load the class, driverClass is still null
    // Try again, this time check defBytes
    if (driverConfig.driverClass == null) {

      String tempDir = System.getProperty("faban.tmpdir");

      if (tempDir == null) {
        tempDir = System.getProperty("java.io.tmpdir");
      }

      File classFileDir = new File(tempDir);

      String classFileName =
          new StringBuilder(tempDir).append(driverConfig.className).append(".class").toString();

      FileOutputStream fos = null;

      try {

        File classFile = new File(classFileName);
        fos = new FileOutputStream(classFile);
        fos.write(this.defBytes);
        fos.flush();
        fos.close();

        URL url[] = new URL[1];

        url[0] = classFileDir.toURI().toURL();

        URLClassLoader loader = new URLClassLoader(url, this.getClass().getClassLoader());

        driverConfig.driverClass = loader.loadClass(driverConfig.className);

      } catch (MalformedURLException ex) {
        throw new ClassNotFoundException(ex.getMessage());
      } catch (IOException ioex) {
        throw new ClassNotFoundException(ioex.getMessage());
      } finally {
        try {
          fos.close();
        } catch (Exception ex) {
          // if fos cannot be closed, leave it alone.
        }
      }
    }
    BenchmarkDefinition.refillMethod(driverConfig.driverClass, driverConfig.preRun);
    BenchmarkDefinition.refillMethod(driverConfig.driverClass, driverConfig.postRun);

    BenchmarkDefinition.refillOperations(driverConfig.driverClass, driverConfig.mix[0].operations);
    if (driverConfig.mix[1] != null) {
      BenchmarkDefinition.refillOperations(
          driverConfig.driverClass, driverConfig.mix[1].operations);
    }
  }