|
@@ -18,9 +18,18 @@
|
|
|
|
|
|
package org.apache.hadoop.yarn.server.federation.store.impl;
|
|
|
|
|
|
+import java.io.File;
|
|
|
+import java.io.IOException;
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
import java.sql.Connection;
|
|
|
import java.sql.SQLException;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.regex.Matcher;
|
|
|
+import java.util.regex.Pattern;
|
|
|
|
|
|
+import org.apache.commons.io.FileUtils;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.apache.hadoop.conf.Configuration;
|
|
|
import org.apache.hadoop.yarn.exceptions.YarnException;
|
|
|
import org.apache.hadoop.yarn.server.federation.store.FederationStateStore;
|
|
@@ -301,15 +310,12 @@ public class HSQLDBFederationStateStore extends SQLFederationStateStore {
|
|
|
+ " WHERE reservationId = reservationId_IN;"
|
|
|
+ " SET rowCount_OUT = 2; END";
|
|
|
|
|
|
+ private List<String> tables = new ArrayList<>();
|
|
|
|
|
|
@Override
|
|
|
public void init(Configuration conf) {
|
|
|
try {
|
|
|
super.init(conf);
|
|
|
- } catch (YarnException e1) {
|
|
|
- LOG.error("ERROR: failed to init HSQLDB " + e1.getMessage());
|
|
|
- }
|
|
|
- try {
|
|
|
conn = super.conn;
|
|
|
|
|
|
LOG.info("Database Init: Start");
|
|
@@ -342,8 +348,17 @@ public class HSQLDBFederationStateStore extends SQLFederationStateStore {
|
|
|
conn.prepareStatement(SP_UPDATERESERVATIONHOMESUBCLUSTER).execute();
|
|
|
|
|
|
LOG.info("Database Init: Complete");
|
|
|
- } catch (SQLException e) {
|
|
|
- LOG.error("ERROR: failed to inizialize HSQLDB " + e.getMessage());
|
|
|
+ } catch (Exception e) {
|
|
|
+ LOG.error("ERROR: failed to initialize HSQLDB {}.", e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void initConnection(Configuration conf) {
|
|
|
+ try {
|
|
|
+ super.init(conf);
|
|
|
+ conn = super.conn;
|
|
|
+ } catch (YarnException e1) {
|
|
|
+ LOG.error("ERROR: failed open connection to HSQLDB DB {}.", e1.getMessage());
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -351,9 +366,38 @@ public class HSQLDBFederationStateStore extends SQLFederationStateStore {
|
|
|
try {
|
|
|
conn.close();
|
|
|
} catch (SQLException e) {
|
|
|
- LOG.error(
|
|
|
- "ERROR: failed to close connection to HSQLDB DB " + e.getMessage());
|
|
|
+ LOG.error("ERROR: failed to close connection to HSQLDB DB {}.", e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Extract The Create Table Sql From The Script.
|
|
|
+ *
|
|
|
+ * @param dbIdentifier database identifier, Like Mysql / SqlServer
|
|
|
+ * @param regex the regex
|
|
|
+ * @throws IOException IO exception.
|
|
|
+ */
|
|
|
+ protected void extractCreateTableSQL(String dbIdentifier, String regex) throws IOException {
|
|
|
+
|
|
|
+ String[] createTableScriptPathItems = new String[] {
|
|
|
+ ".", "target", "test-classes", dbIdentifier, "FederationStateStoreTables.sql" };
|
|
|
+ String createTableScriptPath = StringUtils.join(createTableScriptPathItems, File.separator);
|
|
|
+
|
|
|
+ String createTableSQL =
|
|
|
+ FileUtils.readFileToString(new File(createTableScriptPath), StandardCharsets.UTF_8);
|
|
|
+ Pattern p = Pattern.compile(regex);
|
|
|
+ Matcher m = p.matcher(createTableSQL);
|
|
|
+ while (m != null && m.find()) {
|
|
|
+ String group = m.group();
|
|
|
+ tables.add(group);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public List<String> getTables() {
|
|
|
+ return tables;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setTables(List<String> tables) {
|
|
|
+ this.tables = tables;
|
|
|
+ }
|
|
|
}
|