Package com.sun.faban.driver

Examples of com.sun.faban.driver.ConfigurationException


        int sleepTime = runInfo.benchStartTime - timer.getTime();
        if (sleepTime <= 0) {
            String msg = "Threads are not done initializing by start time.\n" +
                    "Possibly too high latency between agents.";
            logger.severe(msg);
            throw new ConfigurationException(msg);
        }

        if (runAborted) { // If aborted during thread start, we discontinue.
            try {
                Thread.sleep(10000); // But wait for some cleanup before we do
View Full Code Here


        for (int i = 0; i < size0; i++) {
            Element opMix = (Element) operationList.item(i);
            NodeList nl = opMix.getElementsByTagNameNS(
                                                    RunInfo.DRIVERURI, "name");
            if (nl.getLength() == 0) {
        throw new ConfigurationException("Element <name> not found " +
                        "inside <operationMix>.");
      }

            if (nl.getLength() > 1) {
        throw new ConfigurationException("Only one operation name " +
                        "allowed in each operation mix");
      }

            String name = nl.item(0).getFirstChild().getNodeValue();
            positionMap.put(name, i);
            nl = opMix.getElementsByTagNameNS(RunInfo.DRIVERURI, "r");
            int size1 = nl.getLength();
            if (size1 != operations.length) {
                throw new ConfigurationException("@MatrixMix for " + name +
                        " requires " + operations.length +
                        " ratio <r> elements, found " + size1 + '.');
            }
            double[] ratios = new double[size1];
            for (int j = 0; j < ratios.length; j++) {
        ratios[j] = Double.parseDouble(nl.item(j).
                        getFirstChild().getNodeValue());
      }
            ratioMap.put(name, ratios);
        }

        // If no configuration specified, we just don't override
        if (ratioMap.size() <= 0) {
      return;
    }

        // Then we have to extract the ratio map based on the defined name list
        double[][] ratios = new double[operations.length][];
        for (int i = 0; i < operations.length; i++) {
            ratios[i] = ratioMap.remove(operations[i].name);
            if (ratios[i] == null) {
        throw new ConfigurationException("Configured ratio for " +
                        "operation " + operations[i].name + " not found");
      }
        }

        // By now, the map should be empty
        if (ratioMap.size() > 0) {
            String msg = "";
            for (Iterator<String> i = ratioMap.keySet().iterator();
                 i.hasNext();) {
                if (msg.length() > 0) {
          msg += ", ";
        }
                msg += i.next();
            }
            throw new ConfigurationException("Invalid operation name(s) in " +
                    "operationMix configuration: " + msg + '.');
        }

        // But the ratios are still sorted by the configured list which
        // may not be in the same order as the defined list. So we need to
View Full Code Here

      } else {
        runConfigNode = xp.evaluate("fa:runConfig", rootElement,
                        XPathConstants.NODE);
      }
            if (runConfigNode == null) {
        throw new ConfigurationException(
                        "Cannot find <fa:runConfig> element.");
      }
            definingClassName = xp.evaluate("@definition", runConfigNode);
           
            //if the defining class is null, the benchmark definition needs
View Full Code Here

                return "";
            }
            String requestLagType = rltNode.getLocalName();
            String namespace = rltNode.getNamespaceURI();
            if (!DRIVERURI.equals(namespace)) {
        throw new ConfigurationException("Namespace " + namespace +
                            " unexpected under element fd:requestLagTime");
      }

            StringBuilder sb = new StringBuilder();
           
View Full Code Here

                is = cl.getResourceAsStream("driver_template");
                br = new BufferedReader(new InputStreamReader(is));
            }catch(Exception ex){
                //what to do?
                ex.printStackTrace();
                throw new ConfigurationException(ex);
            }

            StringBuilder sb = new StringBuilder();

            while((line=br.readLine())!=null){
                if(!line.equals("\n")){
                    sb.append(line).append("\n");
                }
            }

            String template = sb.toString();

            is.close();

            // Obtain the provider.
            TransportProvider provider = TransportProvider.getProvider();

            /**Get the operation token out of the template.
             * Use this to create multiple operations/functions that will
             * replace the token in the java file
             **/
            String opTemplate = template.substring(
                    (template.indexOf("#operation")+10),
                    template.indexOf("operation#"));
            StringBuilder operations = new StringBuilder();

            Element operationNode = null;
            int i=1;

            while( (operationNode=(Element)xp.evaluate(
                    ("fd:driverConfig/fd:operation["+ i +"]"),
                    runConfigNode, XPathConstants.NODE)) != null){

                /*
                * There are many different options here. First, the operation
                * is either POST or GET. In either case, the subst element
                * indicates whether or not random strings are present in the
                * payload data (for backward compatibility, it is assumed
                * that random data is present).
                *
                * For POST, we can read the data from a file, and we can
                * encode the data as form-encoded or binary (octet-stream)
                */
                boolean isPost = false;
                boolean isBinary = false;
                boolean isFile = false;
                boolean doSubst = true;

                String requestLagTimeOverride = getRequestLagTime(operationNode);
                String operationName = xp.evaluate("fd:name", operationNode);
                String url = xp.evaluate("fd:url", operationNode);
                String max90th = xp.evaluate("fd:max90th", operationNode);
        String kbps = xp.evaluate("fd:kbps", operationNode);
                String accept = xp.evaluate("fd:accept", operationNode);

                String requestString="";

                Element requestNode = (Element)xp.evaluate("fd:get",
                        operationNode, XPathConstants.NODE);

                if (requestNode == null) {
                    //Can't have both post & get either, but if both are there,
                    // will assume you meant GET.

                    requestNode = (Element) xp.evaluate("fd:post",
                            operationNode, XPathConstants.NODE);

                    if (requestNode != null) {
                        isPost = true;
                        if ("true".equalsIgnoreCase(
                                requestNode.getAttributeNS(null, "file"))) {
              isFile = true;
            }
                        if ("true".equalsIgnoreCase(
                                requestNode.getAttributeNS(null, "binary"))) {
              isBinary = true;
            }
                    } else {
                        throw new ConfigurationException("<operation> " +
                                            "must have a either a get/post");
                    }
                    //Can't have both post & get either, but if there,
                    // will assume you meant GET.
                }
                if ("false".equalsIgnoreCase(
                                    requestNode.getAttributeNS(null, "subst"))) {
          doSubst = false;
        }
                if (isBinary && doSubst) {
          throw new ConfigurationException("<operation> " +
                            "cannot be both binary and perform substitution");
        }
                requestString = requestNode.getNodeValue();
                if (requestString == null) {
                    CDATASection cDataNode =
                            (CDATASection)requestNode.getFirstChild();
                    if(cDataNode!=null){
                        requestString = cDataNode.getNodeValue();
                    }
                }
                if (requestString == null) {
          requestString = "";
        }

                if(requestLagTimeOverride==null) {
          requestLagTimeOverride="";
        }
                if(operationName==null) {
          throw new ConfigurationException(
                            "<operation> must have a <name> ");
        }
                if(url==null) {
          throw new ConfigurationException(
                            "<operation> must have a <url>");
        }


                RunInfoDefinition rid;
                if (isPost) {
                    if (isFile) {
                        rid = new RunInfoPostFileDefinition();
                    } else {
            rid = new RunInfoPostDataDefinition();
          }
                } else {
          rid = new RunInfoGetDefinition();
        }
                rid.init(doSubst, isBinary, url, requestString, kbps, accept);

                //Create the benchmark Operation annotation
                StringBuilder bmop = new StringBuilder(
                        "@BenchmarkOperation(name = \"").append(operationName);
                bmop.append("\", percentileLimits={ ").
                     append(max90th).append(", ").
                     append(max90th).append(", ").
                     append(max90th).append("}, ");
        if (provider == TransportProvider.SUN &&
                        url.startsWith("https"))
          bmop.append("timing = com.sun.faban.driver.Timing.MANUAL");
        else
                    bmop.append("timing = com.sun.faban.driver.Timing.AUTO");
                bmop.append(")");

                String opTemplateClone =  new String(opTemplate);
                //replace tokens with actual content
                opTemplateClone = opTemplateClone.replaceAll(
                        "@RequestLagTime@", requestLagTimeOverride);
                opTemplateClone = opTemplateClone.replaceAll(
                        "@Operations@", bmop.toString());
                opTemplateClone = opTemplateClone.replaceAll(
                        "@operationName@", operationName);
                opTemplateClone = opTemplateClone.replaceAll(
                        "@url@", rid.getURL(i));
                opTemplateClone = opTemplateClone.replaceAll(
                        "@postRequest@", rid.getPostRequest(i));
                opTemplateClone = opTemplateClone.replaceAll(
                        "@Statics@", rid.getStatics(i));
        opTemplateClone = opTemplateClone.replaceAll(
            "@doKbps@", rid.getKbps(i));
        opTemplateClone = opTemplateClone.replaceAll(
            "@doHeaders@", rid.getHeaders(i));
        opTemplateClone = opTemplateClone.replaceAll(
             "@doTiming@", rid.doTiming(i, provider));
               
                operations.append(opTemplateClone);
               
                i++;
            }
           
            String benchmarkDef = getBenchmarkDefinition(benchDefNode);
           
            //replace tokens in template
            template = template.replaceFirst("#operation(.*\\n*)*operation#",
                    operations.toString());
            template = template.replaceFirst("@RequestLagTime@",
                    requestLagTime);
            template = template.replaceFirst("@BenchmarkDefinition@",
                    benchmarkDef);
            template = template.replaceAll("@DriverClassName@",
                    definingClassName);
            template = template.replaceFirst("@ProviderClass@",
                                             provider.providerClass);
            template = template.replaceFirst("@BenchmarkDriverName@",
                    definingClassName);
           
            String tmpDir = System.getProperty("faban.tmpdir");
           
            if(tmpDir==null){
                tmpDir = System.getProperty("java.io.tmpdir");
            }
           
            if(!tmpDir.endsWith(File.separator)){
                tmpDir = tmpDir+File.separator;
            }
               
            String className = new StringBuilder(tmpDir).
                    append(definingClassName).append(".java").toString();
           
            try{
                //convert class name to filename?
                PrintWriter pw = new PrintWriter(new BufferedWriter(
                        new FileWriter(className)));
                pw.print(template);
                pw.flush();
            }catch(Exception ex){
                ex.printStackTrace();
                throw new ConfigurationException(ex);
            }

            String classpath = System.getProperty("java.class.path");
           
            String arg[] = new String[] { "-classpath", classpath, className };
            int errorCode = com.sun.tools.javac.Main.compile(arg);
           
            if(errorCode != 0){
                throw new ConfigurationException(
                        "unable to compile generated driver file. " +
                        "check output for errors");
            }

           
View Full Code Here

            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;
        }
View Full Code Here

TOP

Related Classes of com.sun.faban.driver.ConfigurationException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.