public static void main(String[] args) throws Exception { if (args.length < 5) { System.out.println( " You must specify the following parameters Carte_host Carte_port " + "Carte_login Carte_password job_name"); System.out.println(" For example 127.0.0.1 8088 cluster cluster my_job"); System.exit(1); } // building target url String realHostname = args[0]; String port = args[1]; String urlString = "http://" + realHostname + ":" + port + GetTransStatusServlet.CONTEXT_PATH + "?xml=Y&name=" + args[4]; urlString = Const.replace(urlString, " ", "%20"); // building auth token String plainAuth = args[2] + ":" + args[3]; String auth = "Basic " + Base64.encodeBase64String(plainAuth.getBytes()); sendGetTransStatusRequest(urlString, auth); }
public Result execute(Result previousResult, int nr) { String LimitNbrLignes = ""; String ListOfColumn = "*"; String strHighPriority = ""; String OutDumpText = ""; String OptionEnclosed = ""; String FieldSeparator = ""; String LinesTerminated = ""; Result result = previousResult; result.setResult(false); // Let's check the filename ... if (filename != null) { // User has specified a file, We can continue ... String realFilename = getRealFilename(); File file = new File(realFilename); if (file.exists() && iffileexists == 2) { // the file exists and user want to Fail result.setResult(false); result.setNrErrors(1); logError( BaseMessages.getString(PKG, "JobMysqlBulkFile.FileExists1.Label") + realFilename + BaseMessages.getString(PKG, "JobMysqlBulkFile.FileExists2.Label")); } else if (file.exists() && iffileexists == 1) { // the file exists and user want to do nothing result.setResult(true); if (log.isDetailed()) logDetailed( BaseMessages.getString(PKG, "JobMysqlBulkFile.FileExists1.Label") + realFilename + BaseMessages.getString(PKG, "JobMysqlBulkFile.FileExists2.Label")); } else { if (file.exists() && iffileexists == 0) { // File exists and user want to renamme it with unique name // Format Date // Try to clean filename (without wildcard) String wildcard = realFilename.substring(realFilename.length() - 4, realFilename.length()); if (wildcard.substring(0, 1).equals(".")) { // Find wildcard realFilename = realFilename.substring(0, realFilename.length() - 4) + "_" + StringUtil.getFormattedDateTimeNow(true) + wildcard; } else { // did not find wildcard realFilename = realFilename + "_" + StringUtil.getFormattedDateTimeNow(true); } logDebug( BaseMessages.getString(PKG, "JobMysqlBulkFile.FileNameChange1.Label") + realFilename + BaseMessages.getString(PKG, "JobMysqlBulkFile.FileNameChange1.Label")); } // User has specified an existing file, We can continue ... if (log.isDetailed()) logDetailed( BaseMessages.getString(PKG, "JobMysqlBulkFile.FileExists1.Label") + realFilename + BaseMessages.getString(PKG, "JobMysqlBulkFile.FileExists2.Label")); if (connection != null) { // User has specified a connection, We can continue ... Database db = new Database(this, connection); db.shareVariablesWith(this); try { db.connect(parentJob.getTransactionId(), null); // Get schemaname String realSchemaname = environmentSubstitute(schemaname); // Get tablename String realTablename = environmentSubstitute(tablename); if (db.checkTableExists(realTablename)) { // The table existe, We can continue ... if (log.isDetailed()) logDetailed( BaseMessages.getString(PKG, "JobMysqlBulkFile.TableExists1.Label") + realTablename + BaseMessages.getString(PKG, "JobMysqlBulkFile.TableExists2.Label")); // Add schemaname (Most the time Schemaname.Tablename) if (schemaname != null) { realTablename = realSchemaname + "." + realTablename; } // Set the Limit lines if (Const.toInt(getRealLimitlines(), 0) > 0) { LimitNbrLignes = "LIMIT " + getRealLimitlines(); } // Set list of Column, if null get all columns (*) if (getRealListColumn() != null) { ListOfColumn = MysqlString(getRealListColumn()); } // Fields separator if (getRealSeparator() != null && outdumpvalue == 0) { FieldSeparator = "FIELDS TERMINATED BY '" + Const.replace(getRealSeparator(), "'", "''") + "'"; } // Lines Terminated by if (getRealLineterminated() != null && outdumpvalue == 0) { LinesTerminated = "LINES TERMINATED BY '" + Const.replace(getRealLineterminated(), "'", "''") + "'"; } // High Priority ? if (isHighPriority()) { strHighPriority = "HIGH_PRIORITY"; } if (getRealEnclosed() != null && outdumpvalue == 0) { if (isOptionEnclosed()) { OptionEnclosed = "OPTIONALLY "; } OptionEnclosed = OptionEnclosed + "ENCLOSED BY '" + Const.replace(getRealEnclosed(), "'", "''") + "'"; } // OutFile or Dumpfile if (outdumpvalue == 0) { OutDumpText = "INTO OUTFILE"; } else { OutDumpText = "INTO DUMPFILE"; } String FILEBulkFile = "SELECT " + strHighPriority + " " + ListOfColumn + " " + OutDumpText + " '" + realFilename + "' " + FieldSeparator + " " + OptionEnclosed + " " + LinesTerminated + " FROM " + realTablename + " " + LimitNbrLignes + " LOCK IN SHARE MODE"; try { if (log.isDetailed()) logDetailed(FILEBulkFile); // Run the SQL PreparedStatement ps = db.prepareSQL(FILEBulkFile); ps.execute(); // Everything is OK...we can disconnect now db.disconnect(); if (isAddFileToResult()) { // Add filename to output files ResultFile resultFile = new ResultFile( ResultFile.FILE_TYPE_GENERAL, KettleVFS.getFileObject(realFilename, this), parentJob.getJobname(), toString()); result.getResultFiles().put(resultFile.getFile().toString(), resultFile); } result.setResult(true); } catch (SQLException je) { db.disconnect(); result.setNrErrors(1); logError( BaseMessages.getString(PKG, "JobMysqlBulkFile.Error.Label") + " " + je.getMessage()); } catch (KettleFileException e) { logError( BaseMessages.getString(PKG, "JobMysqlBulkFile.Error.Label") + e.getMessage()); result.setNrErrors(1); } } else { // Of course, the table should have been created already before the bulk load // operation db.disconnect(); result.setNrErrors(1); if (log.isDetailed()) logDetailed( BaseMessages.getString(PKG, "JobMysqlBulkFile.TableNotExists1.Label") + realTablename + BaseMessages.getString(PKG, "JobMysqlBulkFile.TableNotExists2.Label")); } } catch (KettleDatabaseException dbe) { db.disconnect(); result.setNrErrors(1); logError( BaseMessages.getString(PKG, "JobMysqlBulkFile.Error.Label") + " " + dbe.getMessage()); } } else { // No database connection is defined result.setNrErrors(1); logError(BaseMessages.getString(PKG, "JobMysqlBulkFile.Nodatabase.Label")); } } } else { // No file was specified result.setNrErrors(1); logError(BaseMessages.getString(PKG, "JobMysqlBulkFile.Nofilename.Label")); } return result; }