Package sos.spooler

Examples of sos.spooler.Variable_set


                outputFile = new File(this.getOutputDirectory());
            }
            getLogger().debug8("merging parameters...");
            mergedVariables = spooler.create_variable_set();
           
            Variable_set env = spooler_task.create_subprocess().env();
            //this merge doesn't work:
            //mergedVariables.merge(env);
            String[] envVars = env.names().split(";");
            for (int i =0; i<envVars.length; i++){
              String currentName = envVars[i];
              mergedVariables.set_var(currentName, env.value(currentName));
            }
            mergedVariables.merge(spooler_task.params());           
            // classic or order driven
            if (spooler_task.job().order_queue() == null) {
                if (!this.inputFileListIterator.hasNext()) return true;
View Full Code Here


     */
    public void cleanup() throws Exception {

        try {
            if (this.orderParameterKeys != null) {
                Variable_set resultParameters = spooler.create_variable_set();
                String[] parameterNames = spooler_task.order().params().names().split(";");
                for(int i=0; i<parameterNames.length; i++) {
                    if (!this.orderParameterKeys.contains(parameterNames[i])) {
                        resultParameters.set_var(parameterNames[i], spooler_task.order().params().value(parameterNames[i]));
                    }
                }
                spooler_task.order().set_params(resultParameters);
            }
        } catch (Exception e) {
View Full Code Here

             || (OS.indexOf("windows 9")> -1)) {
            win=true;
        }

     
        Variable_set env = spooler_task.create_subprocess().env();
        this.getLogger().debug9(env.names());
        StringTokenizer t = new StringTokenizer(env.names(), ";");
        while (t.hasMoreTokens()) {
            String envname = t.nextToken();
            if (envname != null) {
                String envvalue = env.value(envname);
                if (win) {
                    this.getLogger().debug9(envname.toUpperCase() + "=" + envvalue);
                    this.envvars.put(envname.toUpperCase(), envvalue);
                } else {
                    this.envvars.put(envname, envvalue);
View Full Code Here

                    }
                }

              getLogger().debug3("Looking for global parameters from scheduler variables");

                Variable_set globalVariables = spooler.create_variable_set();
                globalVariables.merge(spooler.variables());
                globalVariables.merge(spooler_task.params());
                if (globalVariables.value("global_configuration_params")!=null && globalVariables.value("global_configuration_params").length()>0){
                  String globalFile = globalVariables.value("global_configuration_params");
                  getLogger().debug3("Reading global parameters from "+globalFile);
                  SOSXMLXPath globalXPath = new SOSXMLXPath(globalFile);
                  NodeList globalParams = globalXPath.selectNodeList("//params/param");
                  for (int i=0; i<globalParams.getLength(); i++) {
                        Node node = globalParams.item(i);                       
                        if (node.getNodeName().equalsIgnoreCase("param")) {
                            NamedNodeMap nodeMap = node.getAttributes();
                            boolean hidden = false;
                            if (nodeMap.getNamedItem("hidden")!=null && nodeMap.getNamedItem("hidden").getNodeValue().equalsIgnoreCase("true")) hidden = true;
                            if (nodeMap != null && nodeMap.getNamedItem("name") != null) {
                              String value="";
                                if (nodeMap.getNamedItem("value") != null) {
                                  value = nodeMap.getNamedItem("value").getNodeValue()
                                } else {
                                    NodeList children = node.getChildNodes();
                                    for (int j=0; j<children.getLength(); j++) {
                                        Node item = children.item(j);
                                        switch (item.getNodeType())
                                        {
                                            case Node.TEXT_NODE:
                                            case Node.CDATA_SECTION_NODE:
                                                value += item.getNodeValue();
                                        }
                                    }
                                }
                                if (hidden){
                                  this.getLogger().debug3(".. configuration parameter [" + nodeMap.getNamedItem("name").getNodeValue() + "]: *****");
                                }else{
                                  this.getLogger().debug3(".. configuration parameter [" + nodeMap.getNamedItem("name").getNodeValue() + "]: "  + value);
                                }
                                globalVariables.set_var(nodeMap.getNamedItem("name").getNodeValue(), value);
                               
                                // set additional environment variables for parameters of this state
                                if (globalEnv || nodeMap.getNamedItem("env") != null) {
                                  if (nodeMap.getNamedItem("env") != null) env = nodeMap.getNamedItem("env").getNodeValue();

                                    boolean setEnv = globalEnv || (env.equalsIgnoreCase("yes") || env.equals("1") || env.equalsIgnoreCase("on") || env.equalsIgnoreCase("true"));                           
                                  if (setEnv) {
                                    if (this.additional_envvars == null) this.additional_envvars = new TreeMap();
                                       this.additional_envvars.put(nodeMap.getNamedItem("name").getNodeValue(), value);                                
                                  }
                                }
                            }
                        }
                    }
                  //globalParams
                }
                String[] parameterNames = spooler_task.order().params().names().split(";");
                Pattern paramPattern = Pattern.compile("(?m)^.*\\$\\{.*\\}.*$");
                int metaTrials=0;
                while (metaTrials<=1){
                  for(int i=0; i<parameterNames.length; i++) {// iterate over parameters and try to substitute
                    String currParam = String.valueOf ( spooler_task.order().params().value(parameterNames[i]) );
                    //if ( currParam != null && currParam.matches("^.*\\$\\{.*\\}.*$")) {
                    if ( currParam != null && paramPattern.matcher(currParam).find()) {
                      boolean parameterFound = false;
                      boolean globalParameterFound = false;
                      boolean envFound = false;
                      boolean additionalEnvFound = false;
                      String parameterValue = spooler_task.order().params().value(parameterNames[i]);
                      int trials=0;
                      while (parameterValue.indexOf("${") != -1 && trials <= 1) {
                        this.getLogger().debug6("substitution trials: " + trials + " --> " + parameterValue);
                        for(int j=0; j<parameterNames.length; j++) {// iterate over other parameters and try to replace
                          this.getLogger().debug9("parameterNames[j]=" + parameterNames[j] + " -->" + contains(parameterValue,"${" + parameterNames[j] + "}", false));

                          if (!parameterNames[i].equals(parameterNames[j]) && (contains(parameterValue,"${" + parameterNames[j].toUpperCase() + "}",false) || contains(parameterValue,"${basename:" + parameterNames[j] + "}",false) || contains(parameterValue,"${file_content:" + parameterNames[j] + "}",false))) {
                            String jParameterValue = spooler_task.order().params().value(parameterNames[j]);
                            if (parameterValue.indexOf("${basename:"+parameterNames[j]+"}") != -1) {
                              parameterValue = myReplaceAll(parameterValue,"(?i)\\$\\{basename:" + parameterNames[j] + "\\}", new File(spooler_task.order().params().value(parameterNames[j])).getName().replaceAll("[\\\\]", "\\\\\\\\"));
                              parameterFound = true;
                                trials=0;
                            } else if(parameterValue.indexOf("${file_content:"+parameterNames[j]+"}") != -1){
                              if (jParameterValue.indexOf("${") != -1){
                                getLogger().debug9("file_content parameter still contains other parameters.");
                                metaTrials=0;
                              }else{
                                File contentFile = new File(spooler_task.order().params().value(parameterNames[j]));
                                String fileContent = "";
                                try{
                                  fileContent = SOSFile.readFile(contentFile);
                                } catch(Exception e){
                                  getLogger().warn("Failed to read file: "+contentFile.getAbsolutePath());
                                }
                                parameterValue = myReplaceAll(parameterValue,"(?i)\\$\\{file_content:" + parameterNames[j] + "\\}", fileContent.replaceAll("[\\\\]", "\\\\\\\\"));
                                parameterFound = true;
                                    trials=0;
                              }
                            } else {
                              parameterValue = myReplaceAll(parameterValue,"(?i)\\$\\{" + parameterNames[j] + "\\}", spooler_task.order().params().value(parameterNames[j]).replaceAll("[\\\\]", "\\\\\\\\"));
                              parameterFound = true;
                                trials=0;
                            }
                           
                          }
                        }
                        trials++;
                      }

                      if (globalVariables.count()>0){
                        String[] globalNames = globalVariables.names().split(";");
                        for (int j = 0; j < globalNames.length; j++) {
                          String globalName = globalNames[j];
                          String jParameterValue = globalVariables.value(globalName);
                          this.getLogger().debug9("globalNames[j]=" + globalNames[j] + " -->" + contains(parameterValue,"${" + globalNames[j] + "}", false));
                          if ((contains(parameterValue,"${" + globalName.toUpperCase() + "}",false) || contains(parameterValue,"${basename:" + globalName + "}",false) || contains(parameterValue,"${file_content:" + globalName + "}",false))) {
                            if (parameterValue.indexOf("${basename:") != -1) {
                              parameterValue = myReplaceAll(parameterValue,"(?i)\\$\\{basename:" + globalName + "\\}", new File(globalVariables.value(globalName)).getName().replaceAll("[\\\\]", "\\\\\\\\"));
                            } else if(parameterValue.indexOf("${file_content:"+globalName+"}") != -1){
                              if (jParameterValue.indexOf("${") != -1){
                                getLogger().debug9("file_content parameter still contains other parameters.");
                                metaTrials=0;
                              }else{
                                File contentFile = new File(globalVariables.value(globalName));
                                String fileContent = "";
                                try{
                                  fileContent = SOSFile.readFile(contentFile);
                                } catch(Exception e){
                                  getLogger().warn("Failed to read file: "+contentFile.getAbsolutePath());
                                }
                                parameterValue = myReplaceAll(parameterValue,"(?i)\\$\\{file_content:" + globalName + "\\}", fileContent.replaceAll("[\\\\]", "\\\\\\\\"));
                              }
                            } else {
                              parameterValue = myReplaceAll(parameterValue,"(?i)\\$\\{" + globalName + "\\}", globalVariables.value(globalName).replaceAll("[\\\\]", "\\\\\\\\"));
                            }
                            globalParameterFound = true;
                          }
                        }

View Full Code Here

     */
    public void cleanupConfiguration() throws Exception {

        try {
            if (this.orderParameterKeys != null) {
                Variable_set resultParameters = spooler.create_variable_set();
                String[] parameterNames = spooler_task.order().params().names().split(";");
                for(int i=0; i<parameterNames.length; i++) {
                    if (!this.orderParameterKeys.contains(parameterNames[i])) {
                        resultParameters.set_var(parameterNames[i], spooler_task.order().params().value(parameterNames[i]));
                    }
                }
                spooler_task.order().set_params(resultParameters);
            }
        } catch (Exception e) {
View Full Code Here

        || (OS.indexOf("windows") > -1)) {
          win=true;
          envVarsCaseSensitive = false;
      }
   
      Variable_set env = spooler_task.create_subprocess().env();
      this.getLogger().debug9("environment variable names: " + env.names());
      StringTokenizer t = new StringTokenizer(env.names(), ";");
      while (t.hasMoreTokens()) {
          String envname = t.nextToken();
          if (envname != null) {
              String envvalue = env.value(envname);
              if (win) {
                  this.getLogger().debug9("set environment variable: " + envname.toUpperCase() + "=" + envvalue);
                  this.envvars.put(envname.toUpperCase(), envvalue);
              } else {
                  this.getLogger().debug9("set environment variable: " + envname + "=" + envvalue);
View Full Code Here

 
 
  private HashMap getKeys(String keys) throws Exception{
    try {
      HashMap retval = new HashMap();
      Variable_set set = getParameters();     
      String[] split = keys.split(",");
     
      for(int i = 0; i < split.length; i++) {
        String name = split[i];
        String value = set.value(split[i]);
        retval.put(name, value);         
      }
     
      return retval;
    } catch (Exception e) {
View Full Code Here

 
 
  private String replaceAllParameter(String query) throws Exception{
    try {
      String retval = query;
      Variable_set set = getParameters();
      String[] split = set.names().split(";");
      //System.out.println("-------------------------------------- ");
      //System.out.println("before: " + query);
      getLogger().debug("query before replace: " + query);
      for(int i = 0; i < split.length; i++) {
        String name = "\\$\\{"+split[i]+"\\}";
        String value = set.value(split[i]);
        retval = retval.replaceAll(name, value);
        retval = retval.replaceAll(name.toLowerCase(), value);
        retval = retval.replaceAll(name.toUpperCase(), value);
       
      }
View Full Code Here

     *
     */
    public void getBaseParameters() throws Exception {

        Order order = null;
        Variable_set params = null;
       
        try { // to fetch parameters, order parameters have precedence to job parameters
             
            params = spooler_task.params();
               
            if (spooler_task.job().order_queue() != null) {
                order = spooler_task.order();
                if ( order.params() != null)
                  params.merge(order.params());
            }
               
            if (params.value("host") != null && params.value("host").toString().length() > 0) {
                 this.setHost(params.value("host"));
                 spooler_log.info(".. parameter [host]: " + this.getHost());
            } else {
                throw new Exception("no host name or ip address was specified as parameter [host]");
            }
                       
            if (params.value("port") != null && params.value("port").length() > 0) {
                try {
                    this.setPort(Integer.parseInt(params.value("port")));
                    spooler_log.info(".. parameter [port]: " + this.getPort());
                } catch (Exception ex) {
                    throw new Exception("illegal non-numeric value for parameter [port]: " + params.value("port"));
                }
            } else {
                this.setPort(22);
            }
               
            if (params.value("user") != null && params.value("user").length() > 0) {
                this.setUser(params.value("user"));
                spooler_log.info(".. parameter [user]: " + this.getUser());
            } else {
                throw new Exception("no user name was specified as parameter [user]");
            }
               
            if (params.value("password") != null && params.value("password").length() > 0) {
                this.setPassword(params.value("password"));
                spooler_log.info(".. parameter [password]: ********");
            } else {
                this.setPassword("");
            }
           

            if (params.value("proxy_host") != null && params.value("proxy_host").toString().length() > 0) {
                this.setProxyHost(params.value("proxy_host"));
                spooler_log.info(".. parameter [proxy_host]: " + this.getProxyHost());
           } else {
               this.setProxyHost("");
           }
                      
           if (params.value("proxy_port") != null && params.value("proxy_port").length() > 0) {
               try {
                   this.setProxyPort(Integer.parseInt(params.value("proxy_port")));
                   spooler_log.info(".. parameter [proxy_port]: " + this.getProxyPort());
               } catch (Exception ex) {
                   throw new Exception("illegal non-numeric value for parameter [proxy_port]: " + params.value("proxy_port"));
               }
           } else {
               this.setProxyPort(3128);
           }
              
           if (params.value("proxy_user") != null && params.value("proxy_user").length() > 0) {
               this.setProxyUser(params.value("proxy_user"));
               spooler_log.info(".. parameter [proxy_user]: " + this.getProxyUser());
           } else {
               this.setProxyUser("");
           }
              
           if (params.value("proxy_password") != null && params.value("proxy_password").length() > 0) {
               this.setProxyPassword(params.value("proxy_password"));
               spooler_log.info(".. parameter [proxy_password]: ********");
           } else {
               this.setProxyPassword("");
           }
              
               
           if (params.value("auth_method") != null && params.value("auth_method").length() > 0) {
               if (params.value("auth_method").equalsIgnoreCase("publickey") || params.value("auth_method").equalsIgnoreCase("password")) {
                   this.setAuthenticationMethod(params.value("auth_method"));
                   spooler_log.info(".. parameter [auth_method]: " + this.getAuthenticationMethod());
               } else {
                   throw new Exception("invalid authentication method [publickey, password] specified: " + params.value("auth_method"));
               }
           } else {
               this.setAuthenticationMethod("publickey");
           }
                   
           if (params.value("auth_file") != null && params.value("auth_file").length() > 0) {
               this.setAuthenticationFilename(params.value("auth_file"));
               spooler_log.info(".. parameter [auth_file]: " + this.getAuthenticationFilename());
           } else {
               if (this.getAuthenticationMethod().equalsIgnoreCase("publickey"))
                   throw new Exception("no authentication filename was specified as parameter [auth_file");
           }
View Full Code Here

            eventDocument.appendChild(eventDocument.createElement("events"));
           
            JobSchedulerEventJob.readEventsFromDB(getConnection(), spooler, eventDocument, getLogger());
           
            // merge params
      Variable_set params = spooler.create_variable_set();
      if (spooler_task.params() != null) params.merge(spooler_task.params());
      if (spooler_job.order_queue() != null && spooler_task.order().params() != null)
        params.merge(spooler_task.order().params());
     
      String eventSpec ="";
     
      if (params.var("scheduler_event_spec")!=null && params.var("scheduler_event_spec").length()>0){
        eventSpec = params.var("scheduler_event_spec");
      }else{
        throw new Exception("parameter scheduler_event_spec is missing");
      }
      getLogger().debug3(".. job parameter [scheduler_event_spec]: " + eventSpec);
     
View Full Code Here

TOP

Related Classes of sos.spooler.Variable_set

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.