diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice/src/main/java/org/apache/hadoop/yarn/server/timelineservice/storage/TimelineSchemaCreator.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice/src/main/java/org/apache/hadoop/yarn/server/timelineservice/storage/TimelineSchemaCreator.java index 5120856..5c3eacd 100644 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice/src/main/java/org/apache/hadoop/yarn/server/timelineservice/storage/TimelineSchemaCreator.java +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice/src/main/java/org/apache/hadoop/yarn/server/timelineservice/storage/TimelineSchemaCreator.java @@ -54,6 +54,11 @@ final static String NAME = TimelineSchemaCreator.class.getSimpleName(); private static final Log LOG = LogFactory.getLog(TimelineSchemaCreator.class); private static final String PHOENIX_OPTION_SHORT = "p"; + private static final String FORCED_OPTION_SHORT = "f"; + private static final String APP_TABLE_NAME_SHORT = "a"; + private static final String APP_TO_FLOW_TABLE_NAME_SHORT = "a2f"; + private static final String TTL_OPTION_SHORT = "m"; + private static final String ENTITY_TABLE_NAME_SHORT = "e"; public static void main(String[] args) throws Exception { @@ -66,22 +71,24 @@ public static void main(String[] args) throws Exception { CommandLine commandLine = parseArgs(otherArgs); // Grab the entityTableName argument - String entityTableName = commandLine.getOptionValue("e"); + String entityTableName = commandLine.getOptionValue(ENTITY_TABLE_NAME_SHORT); if (StringUtils.isNotBlank(entityTableName)) { hbaseConf.set(EntityTable.TABLE_NAME_CONF_NAME, entityTableName); } - String entityTableTTLMetrics = commandLine.getOptionValue("m"); + String entityTableTTLMetrics = commandLine.getOptionValue(TTL_OPTION_SHORT); if (StringUtils.isNotBlank(entityTableTTLMetrics)) { int metricsTTL = Integer.parseInt(entityTableTTLMetrics); new EntityTable().setMetricsTTL(metricsTTL, hbaseConf); } // Grab the appToflowTableName argument - String appToflowTableName = commandLine.getOptionValue("a2f"); + String appToflowTableName = commandLine.getOptionValue( + APP_TO_FLOW_TABLE_NAME_SHORT); if (StringUtils.isNotBlank(appToflowTableName)) { hbaseConf.set(AppToFlowTable.TABLE_NAME_CONF_NAME, appToflowTableName); } // Grab the applicationTableName argument - String applicationTableName = commandLine.getOptionValue("a"); + String applicationTableName = commandLine.getOptionValue( + APP_TABLE_NAME_SHORT); if (StringUtils.isNotBlank(applicationTableName)) { hbaseConf.set(ApplicationTable.TABLE_NAME_CONF_NAME, applicationTableName); @@ -89,7 +96,12 @@ public static void main(String[] args) throws Exception { List exceptions = new ArrayList<>(); try { - createAllTables(hbaseConf); + boolean forced = commandLine.hasOption(FORCED_OPTION_SHORT); + if (forced) { + LOG.info("Force mode is on. " + + "Will continue on htable creation exceptions!"); + } + createAllTables(hbaseConf, forced); LOG.info("Successfully created HBase schema. "); } catch (IOException e) { LOG.error("Error in creating hbase tables: " + e.getMessage()); @@ -135,26 +147,39 @@ private static CommandLine parseArgs(String[] args) throws ParseException { Options options = new Options(); // Input - Option o = new Option("e", "entityTableName", true, "entity table name"); + Option o = new Option(ENTITY_TABLE_NAME_SHORT, "entityTableName", true, + "entity table name"); o.setArgName("entityTableName"); o.setRequired(false); options.addOption(o); - o = new Option("m", "metricsTTL", true, "TTL for metrics column family"); + o = new Option(TTL_OPTION_SHORT, "metricsTTL", true, + "TTL for metrics column family"); o.setArgName("metricsTTL"); o.setRequired(false); options.addOption(o); - o = new Option("a2f", "appToflowTableName", true, "app to flow table name"); + o = new Option(APP_TO_FLOW_TABLE_NAME_SHORT, "appToflowTableName", true, + "app to flow table name"); o.setArgName("appToflowTableName"); - o = new Option("a", "applicationTableName", true, "application table name"); + o.setRequired(false); + options.addOption(o); + + o = new Option(APP_TABLE_NAME_SHORT, "applicationTableName", true, + "application table name"); o.setArgName("applicationTableName"); o.setRequired(false); options.addOption(o); + // Options without an argument + // No need to set arg name since we do not need an argument here o = new Option(PHOENIX_OPTION_SHORT, "usePhoenix", false, "create Phoenix offline aggregation tables"); - // No need to set arg name since we do not need an argument here + o.setRequired(false); + options.addOption(o); + + o = new Option(FORCED_OPTION_SHORT, "force", false, "force to create all " + + "hbase tables even if exceptions happened during the process. "); o.setRequired(false); options.addOption(o); @@ -172,8 +197,8 @@ private static CommandLine parseArgs(String[] args) throws ParseException { return commandLine; } - private static void createAllTables(Configuration hbaseConf) - throws IOException { + private static void createAllTables(Configuration hbaseConf, + boolean forced) throws IOException { Connection conn = null; try { @@ -182,9 +207,33 @@ private static void createAllTables(Configuration hbaseConf) if (admin == null) { throw new IOException("Cannot create table since admin is null"); } - new EntityTable().createTable(admin, hbaseConf); - new AppToFlowTable().createTable(admin, hbaseConf); - new ApplicationTable().createTable(admin, hbaseConf); + try { + new EntityTable().createTable(admin, hbaseConf); + } catch (Exception e) { + if (forced) { + LOG.warn("Forced to continue on: " + e.getMessage()); + } else { + throw e; + } + } + try { + new AppToFlowTable().createTable(admin, hbaseConf); + } catch (Exception e) { + if (forced) { + LOG.warn("Forced to continue on: " + e.getMessage()); + } else { + throw e; + } + } + try { + new ApplicationTable().createTable(admin, hbaseConf); + } catch (Exception e) { + if (forced) { + LOG.warn("Forced to continue on: " + e.getMessage()); + } else { + throw e; + } + } } finally { if (conn != null) { conn.close();