in ambari-metrics-timelineservice/src/main/java/org/apache/ambari/metrics/core/timeline/discovery/TimelineMetricMetadataManager.java [139:214]
public void initializeMetadata(boolean scheduleMetadateSync) {
//Create metadata schema
Connection conn = null;
Statement stmt = null;
String encoding = metricsConf.get(HBASE_ENCODING_SCHEME, DEFAULT_ENCODING);
String compression = metricsConf.get(HBASE_COMPRESSION_SCHEME, DEFAULT_TABLE_COMPRESSION);
try {
LOG.info("Initializing metrics metadata schema...");
conn = hBaseAccessor.getConnectionRetryingOnException();
stmt = conn.createStatement();
// Metadata
String metadataSql = String.format(CREATE_METRICS_METADATA_TABLE_SQL,
encoding, compression);
stmt.executeUpdate(metadataSql);
String hostedAppSql = String.format(CREATE_HOSTED_APPS_METADATA_TABLE_SQL,
encoding, compression);
stmt.executeUpdate(hostedAppSql);
//Host Instances table
String hostedInstancesSql = String.format(CREATE_INSTANCE_HOST_TABLE_SQL,
encoding, compression);
stmt.executeUpdate(hostedInstancesSql);
} catch (SQLException | InterruptedException sql) {
LOG.error("Error creating Metrics Schema in HBase using Phoenix.", sql);
throw new MetricsSystemInitializationException(
"Error creating Metrics Metadata Schema in HBase using Phoenix.", sql);
} finally {
if (stmt != null) {
try {
stmt.close();
} catch (SQLException e) {
// Ignore
}
}
if (conn != null) {
try {
conn.close();
} catch (SQLException e) {
// Ignore
}
}
}
metricMetadataSync = new TimelineMetricMetadataSync(this);
// Schedule the executor to sync to store
if (scheduleMetadateSync) {
executorService.scheduleWithFixedDelay(metricMetadataSync,
metricsConf.getInt(METRICS_METADATA_SYNC_INIT_DELAY, 120), // 2 minutes
metricsConf.getInt(METRICS_METADATA_SYNC_SCHEDULE_DELAY, 300), // 5 minutes
TimeUnit.SECONDS);
}
// Read from store and initialize map
try {
Map<TimelineMetricMetadataKey, TimelineMetricMetadata> metadata = getMetadataFromStore();
LOG.info("Retrieved " + metadata.size() + ", metadata objects from store.");
// Store in the cache
METADATA_CACHE.putAll(metadata);
Map<String, TimelineMetricHostMetadata> hostedAppData = getHostedAppsFromStore();
LOG.info("Retrieved " + hostedAppData.size() + " host objects from store.");
HOSTED_APPS_MAP.putAll(hostedAppData);
loadUuidMapsOnInit();
hBaseAccessor.setMetadataInstance(this);
} catch (SQLException e) {
LOG.warn("Exception loading metric metadata", e);
}
}