Package sos.connection

Examples of sos.connection.SOSConnection

user=<username>

password=<password>

Copyright: Copyright (c) 2003

Company: SOS GmbH

@author Ghassan Beydoun @resource ojdbc14.jar sos.util.jar$Id: SOSConnection.java 14692 2011-06-28 10:32:06Z al $

public class JobSchedulerMySQLMaintenanceMonitor extends JobSchedulerJob {

 
  public boolean spooler_process() throws Exception {
    boolean new_connection=false;
    SOSConnection connection = this.getConnection();
    String database="";
    String[] operations=null;
    String[] tables=null;
    String[] attributes=null;
   
    this.setLogger(new SOSSchedulerLogger(spooler_log));
    try{
      if (getJobProperties().getProperty("config") != null) {
            connection = sos.connection.SOSConnection.createInstance(getJobProperties().getProperty("config"));
              connection.connect();
            new_connection = true;
        } else if (getJobProperties().getProperty("database") != null) {
              database = getJobProperties().getProperty("database").toString();
              if (database != null && database.length()>0) connection.execute("USE " + database);
              getLogger().info("database changed to: " + database);
          }
      if (!(connection instanceof SOSMySQLConnection)){
            getLogger().warn("This Job only works with MySQL databases.");
            return false;
          }
        SOSConnectionVersionLimiter limiter = new SOSConnectionVersionLimiter();
        limiter.setExcludedThroughVersion(3,999);
        for (int i=0; i<13; i++){
          limiter.addExcludedVersion("4.0."+i);
        }
        limiter.check(connection, getLogger());
        if (getJobProperties().getProperty("operations") != null) {
              operations = getJobProperties().getProperty("operations").toString().split(",");
          }
          if (operations == null) {
              operations = new String[3];
              operations[0] = "ANALYZE";
              operations[1] = "OPTIMIZE";
              operations[2] = "REPAIR@QUICK";
          }
         
          if (getJobProperties().getProperty("tables") != null) {
              tables = getJobProperties().getProperty("tables").split(",");
          }
         
          if (tables == null) {
              ArrayList result = connection.getArrayValue("SHOW TABLES");
              if (result != null && !result.isEmpty()) {
                  tables = new String[result.size()];
                  for(int i=0; i<result.size(); i++) {
                      tables[i] = result.get(i).toString();
                  }
              }
          }

          if (tables == null) throw new Exception("no tables found for this database");
    } catch (Exception e){
      this.getLogger().error("Error reading Settings: "+e);
      return false;
    }
   
    try{
      for (int i=0; i<tables.length; i++) {
              attributes = tables[i].split(":");
              if (attributes == null || attributes.length == 1) {
                  attributes = new String[operations.length+1];
                  attributes[0] = tables[i];
                  for(int j=0; j<operations.length; j++) {
                      attributes[j+1] = operations[j];
                  }
              }
           
              for (int j=1; j<attributes.length; j++) {
                String statement_suffix = "";
                String statement;
                  attributes[j] = attributes[j].trim();               
                  if (attributes[j].indexOf("@") > 0) {
                      statement_suffix = " " + attributes[j].substring(attributes[j].indexOf("@")+1);
                      attributes[j] = attributes[j].substring(0, attributes[j].indexOf("@"));
                  } else {
                      statement_suffix = "";
                  }

                  if (attributes[j].equalsIgnoreCase("ANALYZE")) statement = "ANALYZE TABLE " + attributes[0] + statement_suffix;
                  else if (attributes[j].equalsIgnoreCase("OPTIMIZE")) statement = "OPTIMIZE TABLE " + attributes[0] + statement_suffix;
                  else if (attributes[j].equalsIgnoreCase("REPAIR")) statement = "REPAIR TABLE " + attributes[0] + statement_suffix;
                    else if (attributes[j].equalsIgnoreCase("NOP")) statement = "";
                  else{
                    getLogger().error("illegal operation was given for table [" + attributes[0] + "]: " + attributes[j]);
                        return false;
                  }
                  
                    if (statement.length() > 0) {
                        getLogger().debug3("processing statement: " + statement);
                        HashMap result = connection.getSingle(statement);
                        if (result == null || result.isEmpty()) {
                            getLogger().error("database returned no result for statement: " + statement);
                            return false;
                        }
                        getLogger().info("table: " + result.get("table").toString() + ", operation: " + result.get("op").toString()
                        + ", Message Type: " + result.get("msg_type").toString() + ", Message Text: " + result.get("msg_text").toString() );
                    }
              }
          }
     
      if (getJobProperties().getProperty("flush_tables") != null
                && getJobProperties().getProperty("flush_tables").toString().equalsIgnoreCase("yes")) {
                getLogger().info("tables will be flushed to publish optimizations");
                connection.execute("FLUSH TABLES");
        }
     
    } catch (Exception e){
      getLogger().error ("maintenance monitor failed: " + e);
          return false;
    }finally {
          if (new_connection && (connection != null)) {
              connection.disconnect();
              connection = null;
          }
      }

      return false;
View Full Code Here


   
   
    public boolean spooler_process() {
     
        Properties slaveProperties       = null;
        SOSConnection slaveConnection     = null;
        HashMap result                   = null;
        boolean hasSlaveSettingsFile      = false;
        String connectionSettingsFilename   = null;

        try { // to read slave settings
            slaveProperties = this.sosSettings.getSection("mysqld" + (++this.sosCounter));
            if (slaveProperties.isEmpty()) {
                slaveProperties = this.sosSettings.getSection("job " + spooler_job.name());
                if (!slaveProperties.isEmpty())
                    connectionSettingsFilename = slaveProperties.getProperty("slave_config_" + this.sosCounter);
                if (connectionSettingsFilename == null || connectionSettingsFilename.length() == 0) return false;
                hasSlaveSettingsFile = true;
            }
            if (slaveProperties.isEmpty()) return false;
        }
        catch (Exception e) {
            sosLogger.error("error occurred reading settings for slave no. " + this.sosCounter + ": " + e.getMessage());
            return false;
        }


        try { // to connect to slave database
            if (!hasSlaveSettingsFile) {
                slaveConnection = new SOSMySQLConnection( masterProperties.getProperty("driver"),
                                                      slaveProperties.getProperty("url"),
                                                      slaveProperties.getProperty("user"),
                                                      slaveProperties.getProperty("password") );
            } else {
                slaveConnection = SOSConnection.createInstance(connectionSettingsFilename, (SOSLogger) new SOSSchedulerLogger(spooler_log));
                slaveProperties.setProperty("url", slaveConnection.getUrl());
            }
            slaveConnection.connect();
        }
        catch (Exception e) {
            sosLogger.error("connect to database failed for slave no. " + this.sosCounter + ": " + e.getMessage());
            return true; // proceed with next slave instance
        }


        try { // to retrieve slave status
            result = slaveConnection.getSingle("SHOW SLAVE STATUS");
            if (result == null || result.isEmpty()) {
                sosLogger.error("slave no. " + this.sosCounter + " returned no result for query: SHOW SLAVE STATUS");
                return true;
            }

            sosLogger.info("\n");
            sosLogger.info("status for slave no. " + sosCounter + ": " + slaveProperties.getProperty("url"));
            sosLogger.info("Slave_IO_State: " + result.get("slave_io_state").toString());
            sosLogger.info("Master_Host: " + result.get("master_host").toString());
            sosLogger.info("Master_User: " + result.get("master_user").toString());
            sosLogger.info("Connect_Retry: " + result.get("connect_retry").toString());
            sosLogger.info("Master_Log_File: " + result.get("master_log_file").toString());
            sosLogger.info("Read_Master_Log_Pos: " + result.get("read_master_log_pos").toString());
            sosLogger.info("Relay_Log_File: " + result.get("relay_log_file").toString());
            sosLogger.info("Relay_Log_Pos: " + result.get("relay_log_pos").toString());
            sosLogger.info("Relay_Master_Log_File: " + result.get("relay_master_log_file").toString());
            sosLogger.info("Slave_IO_Running: " + result.get("slave_io_running").toString());
            sosLogger.info("Slave_SQL_Running: " + result.get("slave_sql_running").toString());
            sosLogger.info("Replicate_Do_DB: " + result.get("replicate_do_db").toString());
            sosLogger.info("Replicate_Ignore_DB: " + result.get("replicate_ignore_db").toString());
            sosLogger.info("Replicate_Do_Table: " + result.get("replicate_do_table").toString());
            sosLogger.info("Replicate_Ignore_Table: " + result.get("replicate_ignore_table").toString());
            sosLogger.info("Replicate_Wild_Do_Table: " + result.get("replicate_wild_do_table").toString());
            sosLogger.info("Replicate_Wild_Ignore_Table: " + result.get("replicate_wild_ignore_table").toString());
            sosLogger.info("Last_Errno: " + result.get("last_errno").toString());
            sosLogger.info("Last_Error: " + result.get("last_error").toString());
            sosLogger.info("Skip_Counter: " + result.get("skip_counter").toString());
            sosLogger.info("Exec_Master_Log_Pos: " + result.get("exec_master_log_pos").toString());
            sosLogger.info("Relay_Log_Space: " + result.get("relay_log_space").toString());
            sosLogger.info("Until_Condition: " + result.get("until_condition").toString());
            sosLogger.info("Until_Log_File: " + result.get("until_log_file").toString());
            sosLogger.info("Until_Log_Pos: " + result.get("until_log_pos").toString());
            sosLogger.info("Master_SSL_Allowed: " + result.get("master_ssl_allowed").toString());
            sosLogger.info("Master_SSL_CA_File: " + result.get("master_ssl_ca_file").toString());
            sosLogger.info("Master_SSL_CA_Path: " + result.get("master_ssl_ca_path").toString());
            sosLogger.info("Master_SSL_Cert: " + result.get("master_ssl_cert").toString());
            sosLogger.info("Master_SSL_Cipher: " + result.get("master_ssl_cipher").toString());
            sosLogger.info("Master_SSL_Key: " + result.get("master_ssl_key").toString());
            sosLogger.info("Seconds_Behind_Master: " + result.get("seconds_behind_master").toString());
        }
        catch (Exception e) {
            sosLogger.error("error retrieving status from database for slave no. " + this.sosCounter + ": " + e.getMessage());
            return true;
        }
        finally {
            if (slaveConnection != null) {
                try { slaveConnection.disconnect(); } catch (Exception ex) {}
                slaveConnection = null;
            }
        }

View Full Code Here

   */
  public boolean spooler_process_after(boolean arg0) throws Exception {
   
    if (!arg0) return arg0;
   
    SOSConnection       conn        = null;
    SOSSchedulerLogger  log         = null;
    Variable_set        parameters  = null;
    String              host        = null;
    String              remoteDir   = null;
   
    try{
      parameters = spooler.create_variable_set();
      if(spooler_task.params() != null) parameters.merge(spooler_task.params());
      if (spooler_job.order_queue() != null)parameters.merge(spooler_task.order().params());
           
      SOSFTPHistory.debugParams(parameters, spooler_log);
           
      if(parameters != null && parameters.count() > 0){
        if (parameters.value("ftp_result_files") == "0"){
          spooler_log.debug9("no files were received");    
        }
        else{
          host      = parameters.value("ftp_host");
          remoteDir = parameters.value("ftp_remote_dir");
           
          if(host != null && host.length() > 0 && remoteDir != null && remoteDir.length() > 0){
            try{
              String[] files  = parameters.value("ftp_result_filepaths").split( ";" );
       
              log             = new SOSSchedulerLogger(spooler_log);
              conn            = SOSFTPHistory.getConnection(spooler, conn, parameters, log);
             
              for (int i=0; i<files.length; i++){
                fillPosition(conn,host,remoteDir,files[i]);
              }
            }
            catch(Exception e){
              spooler_log.info("ERROR : cannot found position : "+e.getMessage());
            }
            finally{
              try{
                if(conn != null){
                  conn.disconnect();
                }
              }
              catch(Exception e){}
            }
          }
View Full Code Here

            spooler_log.debug1(".. job parameter [db_class]: " + this.getDbClass());
        }

        SOSArguments arguments = new SOSArguments(this.getDbProperty());

        SOSConnection conn;
       
        if (sosLogger!=null){
            conn = getSchedulerConnection(this.getJobSettings(),sosLogger);
        }else{
            conn = getSchedulerConnection(this.getJobSettings());
View Full Code Here

        String dbProperty = schedulerSettings.getSection("spooler").getProperty("db").replaceAll("jdbc:", "-url=jdbc:");
        dbProperty = dbProperty.substring(dbProperty.indexOf('-'));
        if (dbProperty.endsWith("-password=")) dbProperty=dbProperty.substring(0, dbProperty.length()-10);
        SOSArguments arguments = new SOSArguments(dbProperty);

        SOSConnection conn;
        if (log!=null){
            conn = SOSConnection.createInstance
                                            schedulerSettings.getSection("spooler").getProperty("db_class"),
                                            arguments.as_string("-class=", ""),
                                            arguments.as_string("-url=", ""),
View Full Code Here

    /**
     * processing
     */
    public boolean spooler_process() {

        SOSConnection localConnection = null;
        Order order = null;
        String command = "";
        orderPayload = null;
        Variable_set realOrderParams = null;
    boolean rc = true;
    boolean resultsetAsWarning = false;
    boolean resultsetAsParameters = false;
    boolean resultsetNameValue = false;
    boolean execReturnsResultSet = false;
    autoCommit = false;
       
        try {
         
          this.setLogger(new SOSSchedulerLogger(spooler_log));
         
          super.prepareParams();         
         
         
          if(orderPayload!=null && orderPayload.var("scheduler_order_is_user_job")!=null && orderPayload.var("scheduler_order_is_user_job").equals("1")){
            userJob = true;
          }
          if(orderPayload!=null && orderPayload.var("resultset_as_warning")!=null && (orderPayload.var("resultset_as_warning").equals("1") || orderPayload.var("resultset_as_warning").equalsIgnoreCase("true"))){
            resultsetAsWarning = true;
          }
          if(orderPayload!=null && orderPayload.var("exec_returns_resultset")!=null && (orderPayload.var("exec_returns_resultset").equals("1") || orderPayload.var("exec_returns_resultset").equalsIgnoreCase("true"))){
            execReturnsResultSet = true;
          }
          if(orderPayload!=null && orderPayload.var("resultset_as_parameters")!=null && (orderPayload.var("resultset_as_parameters").equals("1") || orderPayload.var("resultset_as_parameters").equalsIgnoreCase("true") || orderPayload.var("resultset_as_parameters").equalsIgnoreCase("name_value"))){
            resultsetAsParameters = true;
            if (orderPayload.var("resultset_as_parameters").equalsIgnoreCase("name_value")){
              resultsetNameValue = true;
            }
          }
          if(orderPayload!=null && orderPayload.var("auto_commit")!=null && (orderPayload.var("auto_commit").equals("1") || orderPayload.var("auto_commit").equalsIgnoreCase("true"))){
            autoCommit = true;
          }
         
          try{
            if(userJob){
              checkOldTempUsers();
              localConnection=this.getUserConnection(orderPayload.var("scheduler_order_user_name"), orderPayload.var("scheduler_order_schema"));
            }else{
              localConnection = JobSchedulerManagedObject.getOrderConnection(this.getConnection(), this);
              localConnection.connect();
            }
          } catch (Exception e) {
            throw new Exception("error occurred establishing database connection: " + e.getMessage());
          }
         
          localConnection.setExecReturnsResultSet(execReturnsResultSet);
          try {
            if (orderJob) command = JobSchedulerManagedObject.getOrderCommand(this.getConnection(), this);
        if (command == null || command.length() == 0) {
            command = JobSchedulerManagedObject.getJobCommand(this.getConnection(), this);
        }
       
        if (command == null || command.length() == 0) throw new Exception("command is empty");
      } catch(Exception e){
        throw (new Exception("no database command found: " + e));
      }

      // replace job-specific placeholders
      command = command.replaceAll("\\$\\{scheduler_order_job_name\\}" , this.getJobName());
      command = command.replaceAll("\\$\\{scheduler_order_job_id\\}" , Integer.toString(this.getJobId()));
      command = command.replaceAll("\\$\\{scheduler_id\\}" , spooler.id());

      // replace parameters
      if (orderPayload != null)
      command = JobSchedulerManagedObject.replaceVariablesInCommand(command, orderPayload, getLogger());

            // replace order-specific placeholders
      if(orderJob) {       
        order = spooler_task.order();
        realOrderParams = order.params();
        command = command.replaceAll("\\$\\{scheduler_order_id\\}" , order.id());
        command = command.replaceAll("\\$\\{scheduler_order_managed_id\\}" , "0");
        this.getLogger().info("executing database statement(s) for managed order [" + order.id() + "]: " + command);
      } else {
        this.getLogger().info("executing database statement(s): " + command);
      }
               
      executeStatements(localConnection, command);     
     
      this.getLogger().info("database statement(s) executed.");
      if ((resultsetAsWarning || resultsetAsParameters) && localConnection.getResultSet() != null){
        String warning = "";
              HashMap result = null;
              while( !(result = localConnection.get()).isEmpty()) {
                String orderParamKey = "";
                int columnCount =0;
                warning = "execution terminated with warning:";
                Iterator resultIterator = result.keySet().iterator();
                boolean resultParametersSet = false;               
                while(resultIterator.hasNext()) {
                  columnCount++;
                  String key = (String) resultIterator.next();
                  if (key == null || key.length() == 0) continue;
                  String value = result.get(key).toString();
                  warning += " " + key + "=" + value;
                  if (resultsetAsParameters && order!=null && !resultParametersSet){
                    if (resultsetNameValue){ // name/value pairs from two columns
                      if (columnCount==1){
                        orderParamKey = value;
                      }
                      if (columnCount==2){
                        if (realOrderParams.value(orderParamKey)==null || realOrderParams.value(orderParamKey).length()==0){
                          realOrderParams.set_var(orderParamKey, value);
                        }
                      }
                    }else if (realOrderParams.value(key)==null || realOrderParams.value(key).length()==0){
                      // column name = name, value=value
                      realOrderParams.set_var(key, value);
                      resultParametersSet = true;
                    }
                  }
                }
              }
              if (warning!=null && warning.length()>0 && resultsetAsWarning){
                rc = false;
                this.getLogger().warn(warning);
              }
      }
   
            if (getLogger().hasWarnings() || getLogger().hasErrors()) spooler_task.end();
            return rc && orderJob;
           
        }   
        catch (Exception e) {
          spooler_log.warn("error occurred processing managed order [" + ((order != null) ? "Job Chain: " + order.job_chain().name() + ", ID:"+ order.id() : "(none)") + "] : " + e);
        if (userJob) writeError(e, order);
        spooler_task.end();
        return false;
        }
        finally {
            //try { if (localConnection !=  null) localConnection.rollback(); } catch (Exception ex) {} // ignore this errror
            try { if (localConnection !=  null && !userJob) localConnection.disconnect(); } catch (Exception ex) {} // ignore this errror
            if(userJob) {
        closeUserConnection(localConnection);
        updateRunTime(order, getLogger(), getConnection());       
      }
            try{getConnection().commit();} catch (Exception e){}
View Full Code Here

            " SET \"STATUS\"='CREATED', \"MODIFIED\"= %now WHERE "+
          "\"NAME\"='"+revokeUserQuoted+"'");
      } catch (Exception e) {}
    getConnection().commit();
    // als neuer user connecten
    SOSConnection userConnection;
    Properties spoolerProp = this.getJobSettings().getSection("spooler");
   
    String dbProperty = spoolerProp.getProperty("db").replaceAll("jdbc:", "-url=jdbc:");
        dbProperty = dbProperty.substring(dbProperty.indexOf('-'));
    SOSArguments arguments = new SOSArguments(dbProperty);
   
    try {
            spooler_log.debug6("..creating user connection object");
           
            userConnection = SOSConnection.createInstance
                spoolerProp.getProperty("db_class"),
                arguments.as_string("-class=", ""),
          arguments.as_string("-url=", ""),
          newUserName,
          password,
          getLogger() );
           
      }   
      catch (Exception e) {
          throw new Exception("error occurred establishing database connection: " + e.getMessage());
      }
      userConnection.connect();
      if (schema!=null && schema.length()>0) userConnection.execute("use "+schema);
      userConnection.commit();
    return userConnection;
   
  }
View Full Code Here

    SOSLogger logger = new SOSStandardLogger(9);
   
    //db= jdbc -class=com.microsoft.sqlserver.jdbc.SQLServerDriver jdbc:sqlserver://8of9:2433;sendStringParametersAsUnicode=false;selectMethod=cursor;databaseName=ehp_bkk -user=ehp_bkk -password=ehp_bkk
   
    //SOSConnection conn = SOSConnection.createInstance("SOSMySQLConnection","com.mysql.jdbc.Driver","jdbc:mysql://wilma.sos:3305/scheduler", "scheduler", "scheduler",logger);
    SOSConnection conn = SOSConnection.createInstance("SOSMSSQLConnection","com.microsoft.sqlserver.jdbc.SQLServerDriver","jdbc:sqlserver://8of9:2433;sendStringParametersAsUnicode=false;selectMethod=cursor;databaseName=ehp_bkk", "ehp_bkk", "ehp_bkk",logger);
    conn.connect();
    SOSSettings settings = new SOSConnectionSettings(conn,"SETTINGS", logger);
    SOSMailOrder order = new SOSMailOrder(settings, conn);   
    order.setSOSLogger(logger);
    order.addRecipient(mailto);
    order.setLanguage("en");
    order.setSubjectTemplate("default_subject");
    order.setSubjectTemplateType(TEMPLATE_TYPE_PLAIN);
    order.setBodyTemplate("default_body");
    order.setBodyTemplateType(TEMPLATE_TYPE_PLAIN);
    order.send();
    conn.disconnect();
  }
View Full Code Here

  }
   
    private void testDocumentation() throws Exception{
      startscript=false;
      SOSLogger log = new SOSStandardLogger(SOSLogger.DEBUG9);
      SOSConnection conn = SOSConnection.createInstance("j:/e/java/al/sos.scheduler/config/sos_setup_settings.ini", log);
      //setLogger(log);
      try{
     
      conn.connect();
    String xml = conn.getClob("SELECT \"XML\" FROM SCHEDULER_MANAGED_OBJECTS WHERE \"ID\" = 347");
   
      try  {
        updateSchedulerFile(xml, "New_job_documentation.xml", SOSDate.getCurrentTimeAsString(), "documentation");
         
      }catch(Exception e){
          e.printStackTrace();
      }
      } catch(Exception e){
        e.printStackTrace();
      } finally{
        if (conn!=null) conn.disconnect();
      }
  }
View Full Code Here

           
            // template sample with settings
            // .. create logger
            SOSStandardLogger logger = new SOSStandardLogger(9);
            // .. create connection
            SOSConnection connection = SOSConnection.createInstance("/scheduler/config/sos_settings.ini", logger);
            connection.connect();
            // .. create settings instance from connection
            SOSConnectionSettings settings = new
            SOSConnectionSettings( connection,          // connection instance
                                  "SETTINGS",           // settings table
                                  logger);
View Full Code Here

TOP

Related Classes of sos.connection.SOSConnection

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.