Advertisement
Guest User

Untitled

a guest
Oct 8th, 2018
513
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 41.10 KB | None | 0 0
  1. package local_project.ftpjob_0_1;
  2.  
  3. import routines.DataOperation;
  4. import routines.TalendDataGenerator;
  5. import routines.DataQuality;
  6. import routines.Relational;
  7. import routines.DataQualityDependencies;
  8. import routines.Mathematical;
  9. import routines.SQLike;
  10. import routines.Numeric;
  11. import routines.TalendStringUtil;
  12. import routines.TalendString;
  13. import routines.DQTechnical;
  14. import routines.MDM;
  15. import routines.StringHandling;
  16. import routines.DataMasking;
  17. import routines.TalendDate;
  18. import routines.DqStringHandling;
  19. import routines.system.*;
  20. import routines.system.api.*;
  21. import java.text.ParseException;
  22. import java.text.SimpleDateFormat;
  23. import java.util.Date;
  24. import java.util.List;
  25. import java.math.BigDecimal;
  26. import java.io.ByteArrayOutputStream;
  27. import java.io.ByteArrayInputStream;
  28. import java.io.DataInputStream;
  29. import java.io.DataOutputStream;
  30. import java.io.ObjectOutputStream;
  31. import java.io.ObjectInputStream;
  32. import java.io.IOException;
  33. import java.util.Comparator;
  34.  
  35. @SuppressWarnings("unused")
  36. /**
  37. * Job: ftpjob Purpose: <br>
  38. * Description: <br>
  39. * @author user@talend.com
  40. * @version 7.1.1.20181002_1932-SNAPSHOT
  41. * @status
  42. */
  43. public class ftpjob implements TalendJob {
  44. static {
  45. System.setProperty("TalendJob.log", "ftpjob.log");
  46. }
  47. private static org.apache.log4j.Logger log = org.apache.log4j.Logger
  48. .getLogger(ftpjob.class);
  49.  
  50. protected static void logIgnoredError(String message, Throwable cause) {
  51. log.error(message, cause);
  52.  
  53. }
  54.  
  55. public final Object obj = new Object();
  56.  
  57. // for transmiting parameters purpose
  58. private Object valueObject = null;
  59.  
  60. public Object getValueObject() {
  61. return this.valueObject;
  62. }
  63.  
  64. public void setValueObject(Object valueObject) {
  65. this.valueObject = valueObject;
  66. }
  67.  
  68. private final static String defaultCharset = java.nio.charset.Charset
  69. .defaultCharset().name();
  70.  
  71. private final static String utf8Charset = "UTF-8";
  72.  
  73. // contains type for every context property
  74. public class PropertiesWithType extends java.util.Properties {
  75. private static final long serialVersionUID = 1L;
  76. private java.util.Map<String, String> propertyTypes = new java.util.HashMap<>();
  77.  
  78. public PropertiesWithType(java.util.Properties properties) {
  79. super(properties);
  80. }
  81.  
  82. public PropertiesWithType() {
  83. super();
  84. }
  85.  
  86. public void setContextType(String key, String type) {
  87. propertyTypes.put(key, type);
  88. }
  89.  
  90. public String getContextType(String key) {
  91. return propertyTypes.get(key);
  92. }
  93. }
  94.  
  95. // create and load default properties
  96. private java.util.Properties defaultProps = new java.util.Properties();
  97.  
  98. // create application properties with default
  99. public class ContextProperties extends PropertiesWithType {
  100.  
  101. private static final long serialVersionUID = 1L;
  102.  
  103. public ContextProperties(java.util.Properties properties) {
  104. super(properties);
  105. }
  106.  
  107. public ContextProperties() {
  108. super();
  109. }
  110.  
  111. public void synchronizeContext() {
  112.  
  113. }
  114.  
  115. }
  116.  
  117. private ContextProperties context = new ContextProperties();
  118.  
  119. public ContextProperties getContext() {
  120. return this.context;
  121. }
  122.  
  123. private final String jobVersion = "0.1";
  124. private final String jobName = "ftpjob";
  125. private final String projectName = "LOCAL_PROJECT";
  126. public Integer errorCode = null;
  127. private String currentComponent = "";
  128.  
  129. private final java.util.Map<String, Object> globalMap = new java.util.HashMap<String, Object>();
  130. private final static java.util.Map<String, Object> junitGlobalMap = new java.util.HashMap<String, Object>();
  131.  
  132. private final java.util.Map<String, Long> start_Hash = new java.util.HashMap<String, Long>();
  133. private final java.util.Map<String, Long> end_Hash = new java.util.HashMap<String, Long>();
  134. private final java.util.Map<String, Boolean> ok_Hash = new java.util.HashMap<String, Boolean>();
  135. public final java.util.List<String[]> globalBuffer = new java.util.ArrayList<String[]>();
  136.  
  137. private RunStat runStat = new RunStat();
  138.  
  139. // OSGi DataSource
  140. private final static String KEY_DB_DATASOURCES = "KEY_DB_DATASOURCES";
  141.  
  142. private final static String KEY_DB_DATASOURCES_RAW = "KEY_DB_DATASOURCES_RAW";
  143.  
  144. public void setDataSources(
  145. java.util.Map<String, javax.sql.DataSource> dataSources) {
  146. java.util.Map<String, routines.system.TalendDataSource> talendDataSources = new java.util.HashMap<String, routines.system.TalendDataSource>();
  147. for (java.util.Map.Entry<String, javax.sql.DataSource> dataSourceEntry : dataSources
  148. .entrySet()) {
  149. talendDataSources.put(
  150. dataSourceEntry.getKey(),
  151. new routines.system.TalendDataSource(dataSourceEntry
  152. .getValue()));
  153. }
  154. globalMap.put(KEY_DB_DATASOURCES, talendDataSources);
  155. globalMap
  156. .put(KEY_DB_DATASOURCES_RAW,
  157. new java.util.HashMap<String, javax.sql.DataSource>(
  158. dataSources));
  159. }
  160.  
  161. private final java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream();
  162. private final java.io.PrintStream errorMessagePS = new java.io.PrintStream(
  163. new java.io.BufferedOutputStream(baos));
  164.  
  165. public String getExceptionStackTrace() {
  166. if ("failure".equals(this.getStatus())) {
  167. errorMessagePS.flush();
  168. return baos.toString();
  169. }
  170. return null;
  171. }
  172.  
  173. private Exception exception;
  174.  
  175. public Exception getException() {
  176. if ("failure".equals(this.getStatus())) {
  177. return this.exception;
  178. }
  179. return null;
  180. }
  181.  
  182. private class TalendException extends Exception {
  183.  
  184. private static final long serialVersionUID = 1L;
  185.  
  186. private java.util.Map<String, Object> globalMap = null;
  187. private Exception e = null;
  188. private String currentComponent = null;
  189. private String virtualComponentName = null;
  190.  
  191. public void setVirtualComponentName(String virtualComponentName) {
  192. this.virtualComponentName = virtualComponentName;
  193. }
  194.  
  195. private TalendException(Exception e, String errorComponent,
  196. final java.util.Map<String, Object> globalMap) {
  197. this.currentComponent = errorComponent;
  198. this.globalMap = globalMap;
  199. this.e = e;
  200. }
  201.  
  202. public Exception getException() {
  203. return this.e;
  204. }
  205.  
  206. public String getCurrentComponent() {
  207. return this.currentComponent;
  208. }
  209.  
  210. public String getExceptionCauseMessage(Exception e) {
  211. Throwable cause = e;
  212. String message = null;
  213. int i = 10;
  214. while (null != cause && 0 < i--) {
  215. message = cause.getMessage();
  216. if (null == message) {
  217. cause = cause.getCause();
  218. } else {
  219. break;
  220. }
  221. }
  222. if (null == message) {
  223. message = e.getClass().getName();
  224. }
  225. return message;
  226. }
  227.  
  228. @Override
  229. public void printStackTrace() {
  230. if (!(e instanceof TalendException || e instanceof TDieException)) {
  231. if (virtualComponentName != null
  232. && currentComponent.indexOf(virtualComponentName + "_") == 0) {
  233. globalMap.put(virtualComponentName + "_ERROR_MESSAGE",
  234. getExceptionCauseMessage(e));
  235. }
  236. globalMap.put(currentComponent + "_ERROR_MESSAGE",
  237. getExceptionCauseMessage(e));
  238. System.err.println("Exception in component " + currentComponent
  239. + " (" + jobName + ")");
  240. }
  241. if (!(e instanceof TDieException)) {
  242. if (e instanceof TalendException) {
  243. e.printStackTrace();
  244. } else {
  245. e.printStackTrace();
  246. e.printStackTrace(errorMessagePS);
  247. ftpjob.this.exception = e;
  248. }
  249. }
  250. if (!(e instanceof TalendException)) {
  251. try {
  252. for (java.lang.reflect.Method m : this.getClass()
  253. .getEnclosingClass().getMethods()) {
  254. if (m.getName().compareTo(currentComponent + "_error") == 0) {
  255. m.invoke(ftpjob.this, new Object[] { e,
  256. currentComponent, globalMap });
  257. break;
  258. }
  259. }
  260.  
  261. if (!(e instanceof TDieException)) {
  262. }
  263. } catch (Exception e) {
  264. this.e.printStackTrace();
  265. }
  266. }
  267. }
  268. }
  269.  
  270. public void tFTPConnection_1_error(Exception exception,
  271. String errorComponent, final java.util.Map<String, Object> globalMap)
  272. throws TalendException {
  273.  
  274. end_Hash.put(errorComponent, System.currentTimeMillis());
  275.  
  276. status = "failure";
  277.  
  278. tFTPConnection_1_onSubJobError(exception, errorComponent, globalMap);
  279. }
  280.  
  281. public void tDBConnection_1_error(Exception exception,
  282. String errorComponent, final java.util.Map<String, Object> globalMap)
  283. throws TalendException {
  284.  
  285. end_Hash.put(errorComponent, System.currentTimeMillis());
  286.  
  287. status = "failure";
  288.  
  289. tDBConnection_1_onSubJobError(exception, errorComponent, globalMap);
  290. }
  291.  
  292. public void tFTPConnection_1_onSubJobError(Exception exception,
  293. String errorComponent, final java.util.Map<String, Object> globalMap)
  294. throws TalendException {
  295.  
  296. resumeUtil.addLog("SYSTEM_LOG", "NODE:" + errorComponent, "", Thread
  297. .currentThread().getId() + "", "FATAL", "",
  298. exception.getMessage(),
  299. ResumeUtil.getExceptionStackTrace(exception), "");
  300.  
  301. }
  302.  
  303. public void tDBConnection_1_onSubJobError(Exception exception,
  304. String errorComponent, final java.util.Map<String, Object> globalMap)
  305. throws TalendException {
  306.  
  307. resumeUtil.addLog("SYSTEM_LOG", "NODE:" + errorComponent, "", Thread
  308. .currentThread().getId() + "", "FATAL", "",
  309. exception.getMessage(),
  310. ResumeUtil.getExceptionStackTrace(exception), "");
  311.  
  312. }
  313.  
  314. public void tFTPConnection_1Process(
  315. final java.util.Map<String, Object> globalMap)
  316. throws TalendException {
  317. globalMap.put("tFTPConnection_1_SUBPROCESS_STATE", 0);
  318.  
  319. final boolean execStat = this.execStat;
  320.  
  321. String iterateId = "";
  322.  
  323. String currentComponent = "";
  324. java.util.Map<String, Object> resourceMap = new java.util.HashMap<String, Object>();
  325.  
  326. try {
  327. // TDI-39566 avoid throwing an useless Exception
  328. boolean resumeIt = true;
  329. if (globalResumeTicket == false && resumeEntryMethodName != null) {
  330. String currentMethodName = new java.lang.Exception()
  331. .getStackTrace()[0].getMethodName();
  332. resumeIt = resumeEntryMethodName.equals(currentMethodName);
  333. }
  334. if (resumeIt || globalResumeTicket) { // start the resume
  335. globalResumeTicket = true;
  336.  
  337. /**
  338. * [tFTPConnection_1 begin ] start
  339. */
  340.  
  341. ok_Hash.put("tFTPConnection_1", false);
  342. start_Hash.put("tFTPConnection_1", System.currentTimeMillis());
  343.  
  344. currentComponent = "tFTPConnection_1";
  345.  
  346. int tos_count_tFTPConnection_1 = 0;
  347.  
  348. if (log.isDebugEnabled())
  349. log.debug("tFTPConnection_1 - " + ("Start to work."));
  350. if (log.isDebugEnabled()) {
  351. class BytesLimit65535_tFTPConnection_1 {
  352. public void limitLog4jByte() throws Exception {
  353. StringBuilder log4jParamters_tFTPConnection_1 = new StringBuilder();
  354. log4jParamters_tFTPConnection_1
  355. .append("Parameters:");
  356. log4jParamters_tFTPConnection_1.append("HOST"
  357. + " = " + "\"127.0.0.1\"");
  358. log4jParamters_tFTPConnection_1.append(" | ");
  359. log4jParamters_tFTPConnection_1.append("FTPS_PORT"
  360. + " = " + "21");
  361. log4jParamters_tFTPConnection_1.append(" | ");
  362. log4jParamters_tFTPConnection_1.append("USER"
  363. + " = " + "\"test\"");
  364. log4jParamters_tFTPConnection_1.append(" | ");
  365. log4jParamters_tFTPConnection_1.append("PASS"
  366. + " = "
  367. + String.valueOf("f3e656537b1a4d67")
  368. .substring(0, 4) + "...");
  369. log4jParamters_tFTPConnection_1.append(" | ");
  370. log4jParamters_tFTPConnection_1.append("FTPS"
  371. + " = " + "true");
  372. log4jParamters_tFTPConnection_1.append(" | ");
  373. log4jParamters_tFTPConnection_1
  374. .append("KEYSTORE_FILE"
  375. + " = "
  376. + "\"C:/Program Files/Java/jre1.8.0_181/lib/security/cacerts\"");
  377. log4jParamters_tFTPConnection_1.append(" | ");
  378. log4jParamters_tFTPConnection_1
  379. .append("KEYSTORE_PASS"
  380. + " = "
  381. + String.valueOf(
  382. "8f24fd5aa89bb403f4f7aba1746784ea")
  383. .substring(0, 4) + "...");
  384. log4jParamters_tFTPConnection_1.append(" | ");
  385. log4jParamters_tFTPConnection_1
  386. .append("CONNECT_MODE" + " = " + "PASSIVE");
  387. log4jParamters_tFTPConnection_1.append(" | ");
  388. log4jParamters_tFTPConnection_1
  389. .append("SECURITY_MODE" + " = "
  390. + "EXPLICIT");
  391. log4jParamters_tFTPConnection_1.append(" | ");
  392. log4jParamters_tFTPConnection_1.append("ENCODING"
  393. + " = " + "\"ISO-8859-15\"");
  394. log4jParamters_tFTPConnection_1.append(" | ");
  395. log4jParamters_tFTPConnection_1.append("USE_PROXY"
  396. + " = " + "true");
  397. log4jParamters_tFTPConnection_1.append(" | ");
  398. log4jParamters_tFTPConnection_1.append("PROXY_HOST"
  399. + " = " + "\"192.168.99.100\"");
  400. log4jParamters_tFTPConnection_1.append(" | ");
  401. log4jParamters_tFTPConnection_1.append("PROXY_PORT"
  402. + " = " + "\"1080\"");
  403. log4jParamters_tFTPConnection_1.append(" | ");
  404. log4jParamters_tFTPConnection_1
  405. .append("PROXY_USERNAME" + " = "
  406. + "\"dijedodol\"");
  407. log4jParamters_tFTPConnection_1.append(" | ");
  408. log4jParamters_tFTPConnection_1
  409. .append("PROXY_PASSWORD"
  410. + " = "
  411. + String.valueOf("a54db575c9da1a0e")
  412. .substring(0, 4) + "...");
  413. log4jParamters_tFTPConnection_1.append(" | ");
  414. log4jParamters_tFTPConnection_1.append("FTPS_PROT"
  415. + " = " + "\"P\"");
  416. log4jParamters_tFTPConnection_1.append(" | ");
  417. log4jParamters_tFTPConnection_1
  418. .append("FTPS_PROTECTION_BUFF_SIZE" + " = "
  419. + "0");
  420. log4jParamters_tFTPConnection_1.append(" | ");
  421. log4jParamters_tFTPConnection_1
  422. .append("REMOTE_VERIFICATION" + " = "
  423. + "true");
  424. log4jParamters_tFTPConnection_1.append(" | ");
  425. if (log.isDebugEnabled())
  426. log.debug("tFTPConnection_1 - "
  427. + (log4jParamters_tFTPConnection_1));
  428. }
  429. }
  430. new BytesLimit65535_tFTPConnection_1().limitLog4jByte();
  431. }
  432.  
  433. java.util.Properties props_tFTPConnection_1 = System
  434. .getProperties();
  435. props_tFTPConnection_1.put("socksProxyPort", "1080");
  436. props_tFTPConnection_1.put("socksProxyHost", "192.168.99.100");
  437. props_tFTPConnection_1.put("java.net.socks.username",
  438. "dijedodol");
  439.  
  440. String decryptedProxyPassword_tFTPConnection_1 = routines.system.PasswordEncryptUtil
  441. .decryptPassword("a54db575c9da1a0e");
  442.  
  443. props_tFTPConnection_1.put("java.net.socks.password",
  444. decryptedProxyPassword_tFTPConnection_1);
  445. java.net.Authenticator.setDefault(new java.net.Authenticator() {
  446. public java.net.PasswordAuthentication getPasswordAuthentication() {
  447. return new java.net.PasswordAuthentication("dijedodol",
  448. decryptedProxyPassword_tFTPConnection_1
  449. .toCharArray());
  450. }
  451. });
  452.  
  453. class MyTrust_tFTPConnection_1 {
  454.  
  455. private javax.net.ssl.TrustManager[] getTrustManagers()
  456. throws java.security.KeyStoreException,
  457. java.security.NoSuchAlgorithmException,
  458. java.security.cert.CertificateException,
  459. java.security.UnrecoverableKeyException,
  460. java.io.IOException {
  461. java.security.KeyStore ks = java.security.KeyStore
  462. .getInstance("JKS");
  463.  
  464. String decryptedKeyStorePassword_tFTPConnection_1 = routines.system.PasswordEncryptUtil
  465. .decryptPassword("8f24fd5aa89bb403f4f7aba1746784ea");
  466. ks.load(new java.io.FileInputStream(
  467. "C:/Program Files/Java/jre1.8.0_181/lib/security/cacerts"),
  468. decryptedKeyStorePassword_tFTPConnection_1
  469. .toCharArray());
  470. javax.net.ssl.TrustManagerFactory tmf = javax.net.ssl.TrustManagerFactory
  471. .getInstance(javax.net.ssl.KeyManagerFactory
  472. .getDefaultAlgorithm());
  473. tmf.init(ks);
  474. return tmf.getTrustManagers();
  475. }
  476. }
  477.  
  478. class SSLSessionReuseFTPSClient_tFTPConnection_1 extends
  479. org.apache.commons.net.ftp.FTPSClient {
  480.  
  481. public SSLSessionReuseFTPSClient_tFTPConnection_1(
  482. boolean isImplicit, javax.net.ssl.SSLContext context) {
  483. super(isImplicit, context);
  484. }
  485.  
  486. // changed to support TLS session resumption
  487. @Override
  488. protected void _prepareDataSocket_(
  489. final java.net.Socket socket) throws IOException {
  490. if (socket instanceof javax.net.ssl.SSLSocket) {
  491. final javax.net.ssl.SSLSession session = ((javax.net.ssl.SSLSocket) _socket_)
  492. .getSession();
  493. final javax.net.ssl.SSLSessionContext context = session
  494. .getSessionContext();
  495. try {
  496. final java.lang.reflect.Field sessionHostPortCache = context
  497. .getClass().getDeclaredField(
  498. "sessionHostPortCache");
  499. sessionHostPortCache.setAccessible(true);
  500. final Object cache = sessionHostPortCache
  501. .get(context);
  502. final java.lang.reflect.Method putMethod = cache
  503. .getClass().getDeclaredMethod("put",
  504. Object.class, Object.class);
  505. putMethod.setAccessible(true);
  506. final java.lang.reflect.Method getHostMethod = socket
  507. .getClass()
  508. .getDeclaredMethod("getHost");
  509. getHostMethod.setAccessible(true);
  510. Object host = getHostMethod.invoke(socket);
  511. final String key = String.format("%s:%s", host,
  512. String.valueOf(socket.getPort()))
  513. .toLowerCase(java.util.Locale.ROOT);
  514. putMethod.invoke(cache, key, session);
  515. } catch (Exception e) {
  516. log.error("Can't adapt ftps client to support TLS session resumption");
  517. throw new RuntimeException(e);
  518. }
  519. }
  520. }
  521. }
  522. javax.net.ssl.SSLContext sslContext_tFTPConnection_1 = null;
  523. javax.net.ssl.TrustManager[] trustManager_tFTPConnection_1 = null;
  524. javax.net.ssl.SSLSocketFactory sslSocketFactory_tFTPConnection_1 = null;
  525. org.apache.commons.net.ftp.FTPSClient ftp_tFTPConnection_1 = null;
  526. MyTrust_tFTPConnection_1 myTrust_tFTPConnection_1 = null;
  527.  
  528. try {
  529. sslContext_tFTPConnection_1 = javax.net.ssl.SSLContext
  530. .getInstance("SSL");
  531. myTrust_tFTPConnection_1 = new MyTrust_tFTPConnection_1();
  532. trustManager_tFTPConnection_1 = myTrust_tFTPConnection_1
  533. .getTrustManagers();
  534. sslContext_tFTPConnection_1.init(null,
  535. trustManager_tFTPConnection_1,
  536. new java.security.SecureRandom());
  537. sslSocketFactory_tFTPConnection_1 = sslContext_tFTPConnection_1
  538. .getSocketFactory();
  539. ftp_tFTPConnection_1 = new SSLSessionReuseFTPSClient_tFTPConnection_1(
  540. false, sslContext_tFTPConnection_1);
  541. ftp_tFTPConnection_1.setControlEncoding("ISO-8859-15");
  542.  
  543. log.info("tFTPConnection_1 -FTPS security Mode is EXPLICIT.");
  544. log.info("tFTPConnection_1 - Attempt to connect to '"
  545. + "127.0.0.1" + "' with username '" + "test" + "'.");
  546.  
  547. ftp_tFTPConnection_1.connect("127.0.0.1", 21);
  548.  
  549. log.info("tFTPConnection_1 - Connect to '" + "127.0.0.1"
  550. + "' has succeeded.");
  551.  
  552. ftp_tFTPConnection_1.setRemoteVerificationEnabled(true);
  553.  
  554. final String decryptedPassword_tFTPConnection_1 = routines.system.PasswordEncryptUtil
  555. .decryptPassword("f3e656537b1a4d67");
  556.  
  557. boolean isLoginSuccessful_tFTPConnection_1 = ftp_tFTPConnection_1
  558. .login("test", decryptedPassword_tFTPConnection_1);
  559.  
  560. if (!isLoginSuccessful_tFTPConnection_1) {
  561. throw new RuntimeException("Login failed");
  562. }
  563.  
  564. ftp_tFTPConnection_1
  565. .setFileType(org.apache.commons.net.ftp.FTP.BINARY_FILE_TYPE);
  566. ftp_tFTPConnection_1.execPROT("P");
  567. ftp_tFTPConnection_1.execPBSZ(0);
  568. } catch (Exception e) {
  569.  
  570. log.error("tFTPConnection_1 - Can't create connection: "
  571. + e.getMessage());
  572.  
  573. throw e;
  574. }
  575.  
  576. ftp_tFTPConnection_1.enterLocalPassiveMode();
  577. log.debug("tFTPConnection_1 - Using the passive mode.");
  578.  
  579. globalMap.put("conn_tFTPConnection_1", ftp_tFTPConnection_1);
  580.  
  581. /**
  582. * [tFTPConnection_1 begin ] stop
  583. */
  584.  
  585. /**
  586. * [tFTPConnection_1 main ] start
  587. */
  588.  
  589. currentComponent = "tFTPConnection_1";
  590.  
  591. tos_count_tFTPConnection_1++;
  592.  
  593. /**
  594. * [tFTPConnection_1 main ] stop
  595. */
  596.  
  597. /**
  598. * [tFTPConnection_1 process_data_begin ] start
  599. */
  600.  
  601. currentComponent = "tFTPConnection_1";
  602.  
  603. /**
  604. * [tFTPConnection_1 process_data_begin ] stop
  605. */
  606.  
  607. /**
  608. * [tFTPConnection_1 process_data_end ] start
  609. */
  610.  
  611. currentComponent = "tFTPConnection_1";
  612.  
  613. /**
  614. * [tFTPConnection_1 process_data_end ] stop
  615. */
  616.  
  617. /**
  618. * [tFTPConnection_1 end ] start
  619. */
  620.  
  621. currentComponent = "tFTPConnection_1";
  622.  
  623. if (log.isDebugEnabled())
  624. log.debug("tFTPConnection_1 - " + ("Done."));
  625.  
  626. ok_Hash.put("tFTPConnection_1", true);
  627. end_Hash.put("tFTPConnection_1", System.currentTimeMillis());
  628.  
  629. if (execStat) {
  630. runStat.updateStatOnConnection("OnComponentOk1", 0, "ok");
  631. }
  632. tDBConnection_1Process(globalMap);
  633.  
  634. /**
  635. * [tFTPConnection_1 end ] stop
  636. */
  637. }// end the resume
  638.  
  639. } catch (java.lang.Exception e) {
  640.  
  641. if (!(e instanceof TalendException)) {
  642. log.fatal(currentComponent + " " + e.getMessage(), e);
  643. }
  644.  
  645. TalendException te = new TalendException(e, currentComponent,
  646. globalMap);
  647.  
  648. throw te;
  649. } catch (java.lang.Error error) {
  650.  
  651. runStat.stopThreadStat();
  652.  
  653. throw error;
  654. } finally {
  655.  
  656. try {
  657.  
  658. /**
  659. * [tFTPConnection_1 finally ] start
  660. */
  661.  
  662. currentComponent = "tFTPConnection_1";
  663.  
  664. /**
  665. * [tFTPConnection_1 finally ] stop
  666. */
  667. } catch (java.lang.Exception e) {
  668. // ignore
  669. } catch (java.lang.Error error) {
  670. // ignore
  671. }
  672. resourceMap = null;
  673. }
  674.  
  675. globalMap.put("tFTPConnection_1_SUBPROCESS_STATE", 1);
  676. }
  677.  
  678. public void tDBConnection_1Process(
  679. final java.util.Map<String, Object> globalMap)
  680. throws TalendException {
  681. globalMap.put("tDBConnection_1_SUBPROCESS_STATE", 0);
  682.  
  683. final boolean execStat = this.execStat;
  684.  
  685. String iterateId = "";
  686.  
  687. String currentComponent = "";
  688. java.util.Map<String, Object> resourceMap = new java.util.HashMap<String, Object>();
  689.  
  690. try {
  691. // TDI-39566 avoid throwing an useless Exception
  692. boolean resumeIt = true;
  693. if (globalResumeTicket == false && resumeEntryMethodName != null) {
  694. String currentMethodName = new java.lang.Exception()
  695. .getStackTrace()[0].getMethodName();
  696. resumeIt = resumeEntryMethodName.equals(currentMethodName);
  697. }
  698. if (resumeIt || globalResumeTicket) { // start the resume
  699. globalResumeTicket = true;
  700.  
  701. /**
  702. * [tDBConnection_1 begin ] start
  703. */
  704.  
  705. ok_Hash.put("tDBConnection_1", false);
  706. start_Hash.put("tDBConnection_1", System.currentTimeMillis());
  707.  
  708. currentComponent = "tDBConnection_1";
  709.  
  710. int tos_count_tDBConnection_1 = 0;
  711.  
  712. if (log.isDebugEnabled())
  713. log.debug("tDBConnection_1 - " + ("Start to work."));
  714. if (log.isDebugEnabled()) {
  715. class BytesLimit65535_tDBConnection_1 {
  716. public void limitLog4jByte() throws Exception {
  717. StringBuilder log4jParamters_tDBConnection_1 = new StringBuilder();
  718. log4jParamters_tDBConnection_1
  719. .append("Parameters:");
  720. log4jParamters_tDBConnection_1.append("DB_VERSION"
  721. + " = " + "MYSQL_5");
  722. log4jParamters_tDBConnection_1.append(" | ");
  723. log4jParamters_tDBConnection_1.append("HOST"
  724. + " = " + "\"192.168.99.100\"");
  725. log4jParamters_tDBConnection_1.append(" | ");
  726. log4jParamters_tDBConnection_1.append("PORT"
  727. + " = " + "\"3306\"");
  728. log4jParamters_tDBConnection_1.append(" | ");
  729. log4jParamters_tDBConnection_1.append("DBNAME"
  730. + " = " + "\"test\"");
  731. log4jParamters_tDBConnection_1.append(" | ");
  732. log4jParamters_tDBConnection_1.append("PROPERTIES"
  733. + " = " + "\"noDatetimeStringSync=true\"");
  734. log4jParamters_tDBConnection_1.append(" | ");
  735. log4jParamters_tDBConnection_1.append("USER"
  736. + " = " + "\"root\"");
  737. log4jParamters_tDBConnection_1.append(" | ");
  738. log4jParamters_tDBConnection_1.append("PASS"
  739. + " = "
  740. + String.valueOf("f3e656537b1a4d67")
  741. .substring(0, 4) + "...");
  742. log4jParamters_tDBConnection_1.append(" | ");
  743. log4jParamters_tDBConnection_1
  744. .append("USE_SHARED_CONNECTION" + " = "
  745. + "false");
  746. log4jParamters_tDBConnection_1.append(" | ");
  747. log4jParamters_tDBConnection_1
  748. .append("SPECIFY_DATASOURCE_ALIAS" + " = "
  749. + "false");
  750. log4jParamters_tDBConnection_1.append(" | ");
  751. log4jParamters_tDBConnection_1.append("AUTO_COMMIT"
  752. + " = " + "false");
  753. log4jParamters_tDBConnection_1.append(" | ");
  754. log4jParamters_tDBConnection_1
  755. .append("UNIFIED_COMPONENTS" + " = "
  756. + "tMysqlConnection");
  757. log4jParamters_tDBConnection_1.append(" | ");
  758. if (log.isDebugEnabled())
  759. log.debug("tDBConnection_1 - "
  760. + (log4jParamters_tDBConnection_1));
  761. }
  762. }
  763. new BytesLimit65535_tDBConnection_1().limitLog4jByte();
  764. }
  765.  
  766. String properties_tDBConnection_1 = "noDatetimeStringSync=true";
  767. if (properties_tDBConnection_1 == null
  768. || properties_tDBConnection_1.trim().length() == 0) {
  769. properties_tDBConnection_1 += "rewriteBatchedStatements=true";
  770. } else if (properties_tDBConnection_1 != null
  771. && !properties_tDBConnection_1
  772. .contains("rewriteBatchedStatements")) {
  773. properties_tDBConnection_1 += "&rewriteBatchedStatements=true";
  774. }
  775.  
  776. String url_tDBConnection_1 = "jdbc:mysql://" + "192.168.99.100"
  777. + ":" + "3306" + "/" + "test" + "?"
  778. + properties_tDBConnection_1;
  779.  
  780. String dbUser_tDBConnection_1 = "root";
  781.  
  782. final String decryptedPassword_tDBConnection_1 = routines.system.PasswordEncryptUtil
  783. .decryptPassword("f3e656537b1a4d67");
  784. String dbPwd_tDBConnection_1 = decryptedPassword_tDBConnection_1;
  785.  
  786. java.sql.Connection conn_tDBConnection_1 = null;
  787.  
  788. String driverClass_tDBConnection_1 = "com.mysql.jdbc.Driver";
  789. java.lang.Class.forName(driverClass_tDBConnection_1);
  790.  
  791. log.debug("tDBConnection_1 - Driver ClassName: "
  792. + driverClass_tDBConnection_1 + ".");
  793.  
  794. log.debug("tDBConnection_1 - Connection attempt to '"
  795. + url_tDBConnection_1 + "' with the username '"
  796. + dbUser_tDBConnection_1 + "'.");
  797.  
  798. conn_tDBConnection_1 = java.sql.DriverManager.getConnection(
  799. url_tDBConnection_1, dbUser_tDBConnection_1,
  800. dbPwd_tDBConnection_1);
  801. log.debug("tDBConnection_1 - Connection to '"
  802. + url_tDBConnection_1 + "' has succeeded.");
  803.  
  804. globalMap.put("conn_tDBConnection_1", conn_tDBConnection_1);
  805. if (null != conn_tDBConnection_1) {
  806.  
  807. log.debug("tDBConnection_1 - Connection is set auto commit to 'false'.");
  808. conn_tDBConnection_1.setAutoCommit(false);
  809. }
  810.  
  811. globalMap.put("conn_tDBConnection_1", conn_tDBConnection_1);
  812.  
  813. globalMap.put("db_tDBConnection_1", "test");
  814.  
  815. /**
  816. * [tDBConnection_1 begin ] stop
  817. */
  818.  
  819. /**
  820. * [tDBConnection_1 main ] start
  821. */
  822.  
  823. currentComponent = "tDBConnection_1";
  824.  
  825. tos_count_tDBConnection_1++;
  826.  
  827. /**
  828. * [tDBConnection_1 main ] stop
  829. */
  830.  
  831. /**
  832. * [tDBConnection_1 process_data_begin ] start
  833. */
  834.  
  835. currentComponent = "tDBConnection_1";
  836.  
  837. /**
  838. * [tDBConnection_1 process_data_begin ] stop
  839. */
  840.  
  841. /**
  842. * [tDBConnection_1 process_data_end ] start
  843. */
  844.  
  845. currentComponent = "tDBConnection_1";
  846.  
  847. /**
  848. * [tDBConnection_1 process_data_end ] stop
  849. */
  850.  
  851. /**
  852. * [tDBConnection_1 end ] start
  853. */
  854.  
  855. currentComponent = "tDBConnection_1";
  856.  
  857. if (log.isDebugEnabled())
  858. log.debug("tDBConnection_1 - " + ("Done."));
  859.  
  860. ok_Hash.put("tDBConnection_1", true);
  861. end_Hash.put("tDBConnection_1", System.currentTimeMillis());
  862.  
  863. /**
  864. * [tDBConnection_1 end ] stop
  865. */
  866. }// end the resume
  867.  
  868. } catch (java.lang.Exception e) {
  869.  
  870. if (!(e instanceof TalendException)) {
  871. log.fatal(currentComponent + " " + e.getMessage(), e);
  872. }
  873.  
  874. TalendException te = new TalendException(e, currentComponent,
  875. globalMap);
  876.  
  877. throw te;
  878. } catch (java.lang.Error error) {
  879.  
  880. runStat.stopThreadStat();
  881.  
  882. throw error;
  883. } finally {
  884.  
  885. try {
  886.  
  887. /**
  888. * [tDBConnection_1 finally ] start
  889. */
  890.  
  891. currentComponent = "tDBConnection_1";
  892.  
  893. /**
  894. * [tDBConnection_1 finally ] stop
  895. */
  896. } catch (java.lang.Exception e) {
  897. // ignore
  898. } catch (java.lang.Error error) {
  899. // ignore
  900. }
  901. resourceMap = null;
  902. }
  903.  
  904. globalMap.put("tDBConnection_1_SUBPROCESS_STATE", 1);
  905. }
  906.  
  907. public String resuming_logs_dir_path = null;
  908. public String resuming_checkpoint_path = null;
  909. public String parent_part_launcher = null;
  910. private String resumeEntryMethodName = null;
  911. private boolean globalResumeTicket = false;
  912.  
  913. public boolean watch = false;
  914. // portStats is null, it means don't execute the statistics
  915. public Integer portStats = null;
  916. public int portTraces = 4334;
  917. public String clientHost;
  918. public String defaultClientHost = "localhost";
  919. public String contextStr = "Default";
  920. public boolean isDefaultContext = true;
  921. public String pid = "0";
  922. public String rootPid = null;
  923. public String fatherPid = null;
  924. public String fatherNode = null;
  925. public long startTime = 0;
  926. public boolean isChildJob = false;
  927. public String log4jLevel = "";
  928.  
  929. private boolean execStat = true;
  930.  
  931. private ThreadLocal<java.util.Map<String, String>> threadLocal = new ThreadLocal<java.util.Map<String, String>>() {
  932. protected java.util.Map<String, String> initialValue() {
  933. java.util.Map<String, String> threadRunResultMap = new java.util.HashMap<String, String>();
  934. threadRunResultMap.put("errorCode", null);
  935. threadRunResultMap.put("status", "");
  936. return threadRunResultMap;
  937. };
  938. };
  939.  
  940. private PropertiesWithType context_param = new PropertiesWithType();
  941. public java.util.Map<String, Object> parentContextMap = new java.util.HashMap<String, Object>();
  942.  
  943. public String status = "";
  944.  
  945. public static void main(String[] args) {
  946. final ftpjob ftpjobClass = new ftpjob();
  947.  
  948. int exitCode = ftpjobClass.runJobInTOS(args);
  949. if (exitCode == 0) {
  950. log.info("TalendJob: 'ftpjob' - Done.");
  951. }
  952.  
  953. System.exit(exitCode);
  954. }
  955.  
  956. public String[][] runJob(String[] args) {
  957.  
  958. int exitCode = runJobInTOS(args);
  959. String[][] bufferValue = new String[][] { { Integer.toString(exitCode) } };
  960.  
  961. return bufferValue;
  962. }
  963.  
  964. public boolean hastBufferOutputComponent() {
  965. boolean hastBufferOutput = false;
  966.  
  967. return hastBufferOutput;
  968. }
  969.  
  970. public int runJobInTOS(String[] args) {
  971. // reset status
  972. status = "";
  973.  
  974. String lastStr = "";
  975. for (String arg : args) {
  976. if (arg.equalsIgnoreCase("--context_param")) {
  977. lastStr = arg;
  978. } else if (lastStr.equals("")) {
  979. evalParam(arg);
  980. } else {
  981. evalParam(lastStr + " " + arg);
  982. lastStr = "";
  983. }
  984. }
  985.  
  986. if (!"".equals(log4jLevel)) {
  987. if ("trace".equalsIgnoreCase(log4jLevel)) {
  988. log.setLevel(org.apache.log4j.Level.TRACE);
  989. } else if ("debug".equalsIgnoreCase(log4jLevel)) {
  990. log.setLevel(org.apache.log4j.Level.DEBUG);
  991. } else if ("info".equalsIgnoreCase(log4jLevel)) {
  992. log.setLevel(org.apache.log4j.Level.INFO);
  993. } else if ("warn".equalsIgnoreCase(log4jLevel)) {
  994. log.setLevel(org.apache.log4j.Level.WARN);
  995. } else if ("error".equalsIgnoreCase(log4jLevel)) {
  996. log.setLevel(org.apache.log4j.Level.ERROR);
  997. } else if ("fatal".equalsIgnoreCase(log4jLevel)) {
  998. log.setLevel(org.apache.log4j.Level.FATAL);
  999. } else if ("off".equalsIgnoreCase(log4jLevel)) {
  1000. log.setLevel(org.apache.log4j.Level.OFF);
  1001. }
  1002. org.apache.log4j.Logger.getRootLogger().setLevel(log.getLevel());
  1003. }
  1004. log.info("TalendJob: 'ftpjob' - Start.");
  1005.  
  1006. if (clientHost == null) {
  1007. clientHost = defaultClientHost;
  1008. }
  1009.  
  1010. if (pid == null || "0".equals(pid)) {
  1011. pid = TalendString.getAsciiRandomString(6);
  1012. }
  1013.  
  1014. if (rootPid == null) {
  1015. rootPid = pid;
  1016. }
  1017. if (fatherPid == null) {
  1018. fatherPid = pid;
  1019. } else {
  1020. isChildJob = true;
  1021. }
  1022.  
  1023. if (portStats != null) {
  1024. // portStats = -1; //for testing
  1025. if (portStats < 0 || portStats > 65535) {
  1026. // issue:10869, the portStats is invalid, so this client socket
  1027. // can't open
  1028. System.err.println("The statistics socket port " + portStats
  1029. + " is invalid.");
  1030. execStat = false;
  1031. }
  1032. } else {
  1033. execStat = false;
  1034. }
  1035.  
  1036. try {
  1037. // call job/subjob with an existing context, like:
  1038. // --context=production. if without this parameter, there will use
  1039. // the default context instead.
  1040. java.io.InputStream inContext = ftpjob.class.getClassLoader()
  1041. .getResourceAsStream(
  1042. "local_project/ftpjob_0_1/contexts/" + contextStr
  1043. + ".properties");
  1044. if (inContext == null) {
  1045. inContext = ftpjob.class.getClassLoader().getResourceAsStream(
  1046. "config/contexts/" + contextStr + ".properties");
  1047. }
  1048. if (inContext != null) {
  1049. // defaultProps is in order to keep the original context value
  1050. defaultProps.load(inContext);
  1051. inContext.close();
  1052. context = new ContextProperties(defaultProps);
  1053. } else if (!isDefaultContext) {
  1054. // print info and job continue to run, for case: context_param
  1055. // is not empty.
  1056. System.err.println("Could not find the context " + contextStr);
  1057. }
  1058.  
  1059. if (!context_param.isEmpty()) {
  1060. context.putAll(context_param);
  1061. // set types for params from parentJobs
  1062. for (Object key : context_param.keySet()) {
  1063. String context_key = key.toString();
  1064. String context_type = context_param
  1065. .getContextType(context_key);
  1066. context.setContextType(context_key, context_type);
  1067.  
  1068. }
  1069. }
  1070. } catch (java.io.IOException ie) {
  1071. System.err.println("Could not load context " + contextStr);
  1072. ie.printStackTrace();
  1073. }
  1074.  
  1075. // get context value from parent directly
  1076. if (parentContextMap != null && !parentContextMap.isEmpty()) {
  1077. }
  1078.  
  1079. // Resume: init the resumeUtil
  1080. resumeEntryMethodName = ResumeUtil
  1081. .getResumeEntryMethodName(resuming_checkpoint_path);
  1082. resumeUtil = new ResumeUtil(resuming_logs_dir_path, isChildJob, rootPid);
  1083. resumeUtil.initCommonInfo(pid, rootPid, fatherPid, projectName,
  1084. jobName, contextStr, jobVersion);
  1085.  
  1086. List<String> parametersToEncrypt = new java.util.ArrayList<String>();
  1087. // Resume: jobStart
  1088. resumeUtil.addLog("JOB_STARTED", "JOB:" + jobName,
  1089. parent_part_launcher, Thread.currentThread().getId() + "", "",
  1090. "", "", "",
  1091. resumeUtil.convertToJsonText(context, parametersToEncrypt));
  1092.  
  1093. if (execStat) {
  1094. try {
  1095. runStat.openSocket(!isChildJob);
  1096. runStat.setAllPID(rootPid, fatherPid, pid, jobName);
  1097. runStat.startThreadStat(clientHost, portStats);
  1098. runStat.updateStatOnJob(RunStat.JOBSTART, fatherNode);
  1099. } catch (java.io.IOException ioException) {
  1100. ioException.printStackTrace();
  1101. }
  1102. }
  1103.  
  1104. java.util.concurrent.ConcurrentHashMap<Object, Object> concurrentHashMap = new java.util.concurrent.ConcurrentHashMap<Object, Object>();
  1105. globalMap.put("concurrentHashMap", concurrentHashMap);
  1106.  
  1107. long startUsedMemory = Runtime.getRuntime().totalMemory()
  1108. - Runtime.getRuntime().freeMemory();
  1109. long endUsedMemory = 0;
  1110. long end = 0;
  1111.  
  1112. startTime = System.currentTimeMillis();
  1113.  
  1114. this.globalResumeTicket = true;// to run tPreJob
  1115.  
  1116. this.globalResumeTicket = false;// to run others jobs
  1117.  
  1118. try {
  1119. errorCode = null;
  1120. tFTPConnection_1Process(globalMap);
  1121. if (!"failure".equals(status)) {
  1122. status = "end";
  1123. }
  1124. } catch (TalendException e_tFTPConnection_1) {
  1125. globalMap.put("tFTPConnection_1_SUBPROCESS_STATE", -1);
  1126.  
  1127. e_tFTPConnection_1.printStackTrace();
  1128.  
  1129. }
  1130.  
  1131. this.globalResumeTicket = true;// to run tPostJob
  1132.  
  1133. end = System.currentTimeMillis();
  1134.  
  1135. if (watch) {
  1136. System.out.println((end - startTime) + " milliseconds");
  1137. }
  1138.  
  1139. endUsedMemory = Runtime.getRuntime().totalMemory()
  1140. - Runtime.getRuntime().freeMemory();
  1141. if (false) {
  1142. System.out.println((endUsedMemory - startUsedMemory)
  1143. + " bytes memory increase when running : ftpjob");
  1144. }
  1145.  
  1146. if (execStat) {
  1147. runStat.updateStatOnJob(RunStat.JOBEND, fatherNode);
  1148. runStat.stopThreadStat();
  1149. }
  1150. int returnCode = 0;
  1151. if (errorCode == null) {
  1152. returnCode = status != null && status.equals("failure") ? 1 : 0;
  1153. } else {
  1154. returnCode = errorCode.intValue();
  1155. }
  1156. resumeUtil.addLog("JOB_ENDED", "JOB:" + jobName, parent_part_launcher,
  1157. Thread.currentThread().getId() + "", "", "" + returnCode, "",
  1158. "", "");
  1159.  
  1160. return returnCode;
  1161.  
  1162. }
  1163.  
  1164. // only for OSGi env
  1165. public void destroy() {
  1166. closeSqlDbConnections();
  1167. closeFtpConnections();
  1168.  
  1169. }
  1170.  
  1171. private void closeSqlDbConnections() {
  1172. try {
  1173. Object obj_conn;
  1174. obj_conn = globalMap.remove("conn_tDBConnection_1");
  1175. if (null != obj_conn) {
  1176. ((java.sql.Connection) obj_conn).close();
  1177. }
  1178. } catch (java.lang.Exception e) {
  1179. }
  1180. }
  1181.  
  1182. private void closeFtpConnections() {
  1183. try {
  1184. Object obj_conn;
  1185. obj_conn = globalMap.remove("conn_tFTPConnection_1");
  1186. if (obj_conn != null) {
  1187. ((org.apache.commons.net.ftp.FTPSClient) obj_conn).disconnect();
  1188. }
  1189. } catch (java.lang.Exception e) {
  1190. }
  1191. }
  1192.  
  1193. private java.util.Map<String, Object> getSharedConnections4REST() {
  1194. java.util.Map<String, Object> connections = new java.util.HashMap<String, Object>();
  1195. connections.put("conn_tDBConnection_1",
  1196. globalMap.get("conn_tDBConnection_1"));
  1197.  
  1198. connections.put("conn_tFTPConnection_1",
  1199. globalMap.get("conn_tFTPConnection_1"));
  1200.  
  1201. return connections;
  1202. }
  1203.  
  1204. private void evalParam(String arg) {
  1205. if (arg.startsWith("--resuming_logs_dir_path")) {
  1206. resuming_logs_dir_path = arg.substring(25);
  1207. } else if (arg.startsWith("--resuming_checkpoint_path")) {
  1208. resuming_checkpoint_path = arg.substring(27);
  1209. } else if (arg.startsWith("--parent_part_launcher")) {
  1210. parent_part_launcher = arg.substring(23);
  1211. } else if (arg.startsWith("--watch")) {
  1212. watch = true;
  1213. } else if (arg.startsWith("--stat_port=")) {
  1214. String portStatsStr = arg.substring(12);
  1215. if (portStatsStr != null && !portStatsStr.equals("null")) {
  1216. portStats = Integer.parseInt(portStatsStr);
  1217. }
  1218. } else if (arg.startsWith("--trace_port=")) {
  1219. portTraces = Integer.parseInt(arg.substring(13));
  1220. } else if (arg.startsWith("--client_host=")) {
  1221. clientHost = arg.substring(14);
  1222. } else if (arg.startsWith("--context=")) {
  1223. contextStr = arg.substring(10);
  1224. isDefaultContext = false;
  1225. } else if (arg.startsWith("--father_pid=")) {
  1226. fatherPid = arg.substring(13);
  1227. } else if (arg.startsWith("--root_pid=")) {
  1228. rootPid = arg.substring(11);
  1229. } else if (arg.startsWith("--father_node=")) {
  1230. fatherNode = arg.substring(14);
  1231. } else if (arg.startsWith("--pid=")) {
  1232. pid = arg.substring(6);
  1233. } else if (arg.startsWith("--context_type")) {
  1234. String keyValue = arg.substring(15);
  1235. int index = -1;
  1236. if (keyValue != null && (index = keyValue.indexOf('=')) > -1) {
  1237. if (fatherPid == null) {
  1238. context_param.setContextType(keyValue.substring(0, index),
  1239. replaceEscapeChars(keyValue.substring(index + 1)));
  1240. } else { // the subjob won't escape the especial chars
  1241. context_param.setContextType(keyValue.substring(0, index),
  1242. keyValue.substring(index + 1));
  1243. }
  1244.  
  1245. }
  1246.  
  1247. } else if (arg.startsWith("--context_param")) {
  1248. String keyValue = arg.substring(16);
  1249. int index = -1;
  1250. if (keyValue != null && (index = keyValue.indexOf('=')) > -1) {
  1251. if (fatherPid == null) {
  1252. context_param.put(keyValue.substring(0, index),
  1253. replaceEscapeChars(keyValue.substring(index + 1)));
  1254. } else { // the subjob won't escape the especial chars
  1255. context_param.put(keyValue.substring(0, index),
  1256. keyValue.substring(index + 1));
  1257. }
  1258. }
  1259. } else if (arg.startsWith("--log4jLevel=")) {
  1260. log4jLevel = arg.substring(13);
  1261. }
  1262.  
  1263. }
  1264.  
  1265. private static final String NULL_VALUE_EXPRESSION_IN_COMMAND_STRING_FOR_CHILD_JOB_ONLY = "<TALEND_NULL>";
  1266.  
  1267. private final String[][] escapeChars = { { "\\\\", "\\" }, { "\\n", "\n" },
  1268. { "\\'", "\'" }, { "\\r", "\r" }, { "\\f", "\f" }, { "\\b", "\b" },
  1269. { "\\t", "\t" } };
  1270.  
  1271. private String replaceEscapeChars(String keyValue) {
  1272.  
  1273. if (keyValue == null || ("").equals(keyValue.trim())) {
  1274. return keyValue;
  1275. }
  1276.  
  1277. StringBuilder result = new StringBuilder();
  1278. int currIndex = 0;
  1279. while (currIndex < keyValue.length()) {
  1280. int index = -1;
  1281. // judege if the left string includes escape chars
  1282. for (String[] strArray : escapeChars) {
  1283. index = keyValue.indexOf(strArray[0], currIndex);
  1284. if (index >= 0) {
  1285.  
  1286. result.append(keyValue.substring(currIndex,
  1287. index + strArray[0].length()).replace(strArray[0],
  1288. strArray[1]));
  1289. currIndex = index + strArray[0].length();
  1290. break;
  1291. }
  1292. }
  1293. // if the left string doesn't include escape chars, append the left
  1294. // into the result
  1295. if (index < 0) {
  1296. result.append(keyValue.substring(currIndex));
  1297. currIndex = currIndex + keyValue.length();
  1298. }
  1299. }
  1300.  
  1301. return result.toString();
  1302. }
  1303.  
  1304. public Integer getErrorCode() {
  1305. return errorCode;
  1306. }
  1307.  
  1308. public String getStatus() {
  1309. return status;
  1310. }
  1311.  
  1312. ResumeUtil resumeUtil = null;
  1313. }
  1314. /************************************************************************************************
  1315. * 43314 characters generated by Talend Data Fabric on the October 8, 2018
  1316. * 12:59:32 PM EEST
  1317. ************************************************************************************************/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement