AMBARI-22740 : Fix integration test for HBase in branch-3.0-ams due to UUID 
changes. (avijayan)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/42112e28
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/42112e28
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/42112e28

Branch: refs/heads/branch-3.0-ams
Commit: 42112e28d12f7cd04e4a2d4e19204ea32d2d3ebf
Parents: a4293b7
Author: Aravindan Vijayan <[email protected]>
Authored: Mon Jan 8 10:19:15 2018 -0800
Committer: Aravindan Vijayan <[email protected]>
Committed: Mon Jan 8 10:19:15 2018 -0800

----------------------------------------------------------------------
 .../metrics2/sink/timeline/Precision.java       |    1 -
 .../conf/unix/ambari-metrics-collector          |    2 +-
 .../ambari-metrics-timelineservice/pom.xml      |    2 +-
 .../ambari/metrics/AMSApplicationServer.java    |  141 ++
 .../metrics/core/loadsimulator/LoadRunner.java  |  154 ++
 .../loadsimulator/MetricsLoadSimulator.java     |  138 ++
 .../core/loadsimulator/MetricsSenderWorker.java |   60 +
 .../metrics/core/loadsimulator/data/AppID.java  |   45 +
 .../core/loadsimulator/data/AppMetrics.java     |   47 +
 .../loadsimulator/data/ApplicationInstance.java |   58 +
 .../data/HostMetricsGenerator.java              |   61 +
 .../metrics/core/loadsimulator/data/Metric.java |   71 +
 .../data/MetricsGeneratorConfigurer.java        |   93 +
 .../core/loadsimulator/net/MetricsSender.java   |   31 +
 .../loadsimulator/net/RestMetricsSender.java    |   92 +
 .../loadsimulator/net/StdOutMetricsSender.java  |   56 +
 .../core/loadsimulator/net/UrlService.java      |  100 +
 .../metrics/core/loadsimulator/util/Json.java   |   62 +
 .../util/RandomMetricsProvider.java             |   39 +
 .../loadsimulator/util/TimeStampProvider.java   |   51 +
 .../timeline/HBaseTimelineMetricsService.java   |  592 ++++++
 .../timeline/MetricsCacheCommitterThread.java   |   38 +
 .../MetricsSystemInitializationException.java   |   41 +
 .../core/timeline/PhoenixHBaseAccessor.java     | 1844 +++++++++++++++++
 .../timeline/TimelineMetricConfiguration.java   |  712 +++++++
 .../TimelineMetricDistributedCache.java         |   32 +
 .../core/timeline/TimelineMetricStore.java      |  110 +
 .../timeline/TimelineMetricStoreWatcher.java    |  126 ++
 .../timeline/TimelineMetricsAggregatorSink.java |   60 +
 .../core/timeline/TimelineMetricsFilter.java    |  165 ++
 .../timeline/TimelineMetricsIgniteCache.java    |  288 +++
 .../aggregators/AbstractTimelineAggregator.java |  494 +++++
 .../timeline/aggregators/AggregatorUtils.java   |  254 +++
 .../timeline/aggregators/CustomDownSampler.java |   44 +
 .../timeline/aggregators/DownSamplerUtils.java  |  117 ++
 .../core/timeline/aggregators/Function.java     |  214 ++
 .../aggregators/TimelineClusterMetric.java      |   97 +
 .../aggregators/TimelineMetricAggregator.java   |   59 +
 .../TimelineMetricAggregatorFactory.java        |  528 +++++
 .../TimelineMetricAppAggregator.java            |  187 ++
 .../TimelineMetricClusterAggregator.java        |  150 ++
 .../TimelineMetricClusterAggregatorSecond.java  |  263 +++
 ...cClusterAggregatorSecondWithCacheSource.java |  104 +
 .../TimelineMetricFilteringHostAggregator.java  |   93 +
 .../TimelineMetricHostAggregator.java           |  120 ++
 .../aggregators/TimelineMetricReadHelper.java   |  170 ++
 .../timeline/aggregators/TopNDownSampler.java   |  112 ++
 .../v2/TimelineMetricClusterAggregator.java     |   93 +
 .../TimelineMetricFilteringHostAggregator.java  |  119 ++
 .../v2/TimelineMetricHostAggregator.java        |   75 +
 .../availability/AggregationTaskRunner.java     |  141 ++
 .../availability/CheckpointManager.java         |   95 +
 .../MetricCollectorHAController.java            |  307 +++
 .../OnlineOfflineStateModelFactory.java         |   69 +
 .../discovery/TimelineMetricHostMetadata.java   |   60 +
 .../discovery/TimelineMetricMetadataKey.java    |   80 +
 .../TimelineMetricMetadataManager.java          |  606 ++++++
 .../discovery/TimelineMetricMetadataSync.java   |  227 +++
 ...tTimelineMetricsSeriesAggregateFunction.java |   98 +
 .../function/SeriesAggregateFunction.java       |   42 +
 .../TimelineMetricsSeriesAggregateFunction.java |   25 +
 ...neMetricsSeriesAggregateFunctionFactory.java |   41 +
 ...melineMetricsSeriesAvgAggregateFunction.java |   39 +
 ...melineMetricsSeriesMaxAggregateFunction.java |   41 +
 ...melineMetricsSeriesMinAggregateFunction.java |   41 +
 ...melineMetricsSeriesSumAggregateFunction.java |   39 +
 .../metrics/core/timeline/query/Condition.java  |   51 +
 .../core/timeline/query/ConditionBuilder.java   |  143 ++
 .../core/timeline/query/ConnectionProvider.java |   29 +
 .../core/timeline/query/DefaultCondition.java   |  421 ++++
 .../query/DefaultPhoenixDataSource.java         |   90 +
 .../core/timeline/query/EmptyCondition.java     |  169 ++
 .../query/PhoenixConnectionProvider.java        |   31 +
 .../core/timeline/query/PhoenixTransactSQL.java |  803 ++++++++
 .../query/SplitByMetricNamesCondition.java      |  189 ++
 .../core/timeline/query/TopNCondition.java      |  162 ++
 .../timeline/sink/DefaultFSSinkProvider.java    |  151 ++
 .../core/timeline/sink/ExternalMetricsSink.java |   48 +
 .../timeline/sink/ExternalSinkProvider.java     |   35 +
 .../core/timeline/sink/HttpSinkProvider.java    |  231 +++
 .../core/timeline/sink/KafkaSinkProvider.java   |  109 +
 .../DefaultInternalMetricsSourceProvider.java   |   42 +
 .../timeline/source/InternalMetricsSource.java  |   30 +
 .../timeline/source/InternalSourceProvider.java |   39 +
 .../core/timeline/source/RawMetricsSource.java  |   85 +
 .../source/cache/InternalMetricCacheKey.java    |  109 +
 .../source/cache/InternalMetricCacheValue.java  |   37 +
 .../source/cache/InternalMetricsCache.java      |  229 +++
 .../cache/InternalMetricsCacheProvider.java     |   48 +
 .../cache/InternalMetricsCacheSizeOfEngine.java |   52 +
 .../timeline/uuid/HashBasedUuidGenStrategy.java |  209 ++
 .../timeline/uuid/MetricUuidGenStrategy.java    |   48 +
 .../timeline/uuid/RandomUuidGenStrategy.java    |   53 +
 .../records/ApplicationAttemptFinishData.java   |   95 +
 .../records/ApplicationAttemptHistoryData.java  |  171 ++
 .../records/ApplicationAttemptStartData.java    |   82 +
 .../metrics/records/ApplicationFinishData.java  |   94 +
 .../metrics/records/ApplicationHistoryData.java |  213 ++
 .../metrics/records/ApplicationStartData.java   |  106 +
 .../metrics/records/ContainerFinishData.java    |   90 +
 .../metrics/records/ContainerHistoryData.java   |  182 ++
 .../metrics/records/ContainerStartData.java     |   92 +
 .../pb/ApplicationAttemptFinishDataPBImpl.java  |  239 +++
 .../pb/ApplicationAttemptStartDataPBImpl.java   |  208 ++
 .../impl/pb/ApplicationFinishDataPBImpl.java    |  226 +++
 .../impl/pb/ApplicationStartDataPBImpl.java     |  229 +++
 .../impl/pb/ContainerFinishDataPBImpl.java      |  204 ++
 .../impl/pb/ContainerStartDataPBImpl.java       |  258 +++
 .../metrics/timeline/GenericObjectMapper.java   |  135 ++
 .../ambari/metrics/timeline/NameValuePair.java  |   59 +
 .../ambari/metrics/timeline/TimelineReader.java |  155 ++
 .../ambari/metrics/timeline/TimelineStore.java  |   29 +
 .../ambari/metrics/timeline/TimelineWriter.java |   46 +
 .../ambari/metrics/webapp/AMSController.java    |   37 +
 .../apache/ambari/metrics/webapp/AMSWebApp.java |   42 +
 .../metrics/webapp/JAXBContextResolver.java     |   64 +
 .../metrics/webapp/TimelineWebServices.java     |  513 +++++
 .../AMSApplicationServer.java                   |  141 --
 .../metrics/loadsimulator/LoadRunner.java       |  155 --
 .../loadsimulator/MetricsLoadSimulator.java     |  139 --
 .../loadsimulator/MetricsSenderWorker.java      |   60 -
 .../metrics/loadsimulator/data/AppID.java       |   46 -
 .../metrics/loadsimulator/data/AppMetrics.java  |   48 -
 .../loadsimulator/data/ApplicationInstance.java |   59 -
 .../data/HostMetricsGenerator.java              |   61 -
 .../metrics/loadsimulator/data/Metric.java      |   71 -
 .../data/MetricsGeneratorConfigurer.java        |   93 -
 .../loadsimulator/net/MetricsSender.java        |   31 -
 .../loadsimulator/net/RestMetricsSender.java    |   92 -
 .../loadsimulator/net/StdOutMetricsSender.java  |   56 -
 .../metrics/loadsimulator/net/UrlService.java   |  101 -
 .../metrics/loadsimulator/util/Json.java        |   63 -
 .../util/RandomMetricsProvider.java             |   40 -
 .../loadsimulator/util/TimeStampProvider.java   |   52 -
 .../timeline/HBaseTimelineMetricsService.java   |  594 ------
 .../timeline/MetricsCacheCommitterThread.java   |   38 -
 .../MetricsSystemInitializationException.java   |   42 -
 .../metrics/timeline/PhoenixHBaseAccessor.java  | 1904 ------------------
 .../timeline/TimelineMetricConfiguration.java   |  713 -------
 .../TimelineMetricDistributedCache.java         |   32 -
 .../metrics/timeline/TimelineMetricStore.java   |  110 -
 .../timeline/TimelineMetricStoreWatcher.java    |  126 --
 .../timeline/TimelineMetricsAggregatorSink.java |   60 -
 .../metrics/timeline/TimelineMetricsFilter.java |  170 --
 .../timeline/TimelineMetricsIgniteCache.java    |  296 ---
 .../aggregators/AbstractTimelineAggregator.java |  495 -----
 .../timeline/aggregators/AggregatorUtils.java   |  254 ---
 .../timeline/aggregators/CustomDownSampler.java |   44 -
 .../timeline/aggregators/DownSamplerUtils.java  |  117 --
 .../metrics/timeline/aggregators/Function.java  |  212 --
 .../aggregators/TimelineClusterMetric.java      |   97 -
 .../aggregators/TimelineMetricAggregator.java   |   59 -
 .../TimelineMetricAggregatorFactory.java        |  528 -----
 .../TimelineMetricAppAggregator.java            |  189 --
 .../TimelineMetricClusterAggregator.java        |  145 --
 .../TimelineMetricClusterAggregatorSecond.java  |  263 ---
 ...cClusterAggregatorSecondWithCacheSource.java |  104 -
 .../TimelineMetricFilteringHostAggregator.java  |   94 -
 .../TimelineMetricHostAggregator.java           |  121 --
 .../aggregators/TimelineMetricReadHelper.java   |  170 --
 .../timeline/aggregators/TopNDownSampler.java   |  112 --
 .../v2/TimelineMetricClusterAggregator.java     |   93 -
 .../TimelineMetricFilteringHostAggregator.java  |  119 --
 .../v2/TimelineMetricHostAggregator.java        |   76 -
 .../availability/AggregationTaskRunner.java     |  145 --
 .../availability/CheckpointManager.java         |   98 -
 .../MetricCollectorHAController.java            |  307 ---
 .../OnlineOfflineStateModelFactory.java         |   69 -
 .../discovery/TimelineMetricHostMetadata.java   |   60 -
 .../discovery/TimelineMetricMetadataKey.java    |   80 -
 .../TimelineMetricMetadataManager.java          |  612 ------
 .../discovery/TimelineMetricMetadataSync.java   |  227 ---
 ...tTimelineMetricsSeriesAggregateFunction.java |   98 -
 .../function/SeriesAggregateFunction.java       |   42 -
 .../TimelineMetricsSeriesAggregateFunction.java |   25 -
 ...neMetricsSeriesAggregateFunctionFactory.java |   41 -
 ...melineMetricsSeriesAvgAggregateFunction.java |   39 -
 ...melineMetricsSeriesMaxAggregateFunction.java |   41 -
 ...melineMetricsSeriesMinAggregateFunction.java |   41 -
 ...melineMetricsSeriesSumAggregateFunction.java |   39 -
 .../metrics/timeline/query/Condition.java       |   51 -
 .../timeline/query/ConditionBuilder.java        |  143 --
 .../timeline/query/ConnectionProvider.java      |   29 -
 .../timeline/query/DefaultCondition.java        |  421 ----
 .../query/DefaultPhoenixDataSource.java         |   90 -
 .../metrics/timeline/query/EmptyCondition.java  |  169 --
 .../query/PhoenixConnectionProvider.java        |   31 -
 .../timeline/query/PhoenixTransactSQL.java      |  804 --------
 .../query/SplitByMetricNamesCondition.java      |  189 --
 .../metrics/timeline/query/TopNCondition.java   |  162 --
 .../timeline/sink/DefaultFSSinkProvider.java    |  153 --
 .../timeline/sink/ExternalMetricsSink.java      |   48 -
 .../timeline/sink/ExternalSinkProvider.java     |   35 -
 .../metrics/timeline/sink/HttpSinkProvider.java |  231 ---
 .../timeline/sink/KafkaSinkProvider.java        |  118 --
 .../DefaultInternalMetricsSourceProvider.java   |   42 -
 .../timeline/source/InternalMetricsSource.java  |   30 -
 .../timeline/source/InternalSourceProvider.java |   39 -
 .../timeline/source/RawMetricsSource.java       |   85 -
 .../source/cache/InternalMetricCacheKey.java    |  109 -
 .../source/cache/InternalMetricCacheValue.java  |   37 -
 .../source/cache/InternalMetricsCache.java      |  229 ---
 .../cache/InternalMetricsCacheProvider.java     |   48 -
 .../cache/InternalMetricsCacheSizeOfEngine.java |   52 -
 .../timeline/uuid/HashBasedUuidGenStrategy.java |  206 --
 .../timeline/uuid/MetricUuidGenStrategy.java    |   48 -
 .../timeline/uuid/RandomUuidGenStrategy.java    |   53 -
 .../records/ApplicationAttemptFinishData.java   |   95 -
 .../records/ApplicationAttemptHistoryData.java  |  171 --
 .../records/ApplicationAttemptStartData.java    |   82 -
 .../records/ApplicationFinishData.java          |   94 -
 .../records/ApplicationHistoryData.java         |  213 --
 .../records/ApplicationStartData.java           |  106 -
 .../records/ContainerFinishData.java            |   90 -
 .../records/ContainerHistoryData.java           |  182 --
 .../records/ContainerStartData.java             |   92 -
 .../pb/ApplicationAttemptFinishDataPBImpl.java  |  239 ---
 .../pb/ApplicationAttemptStartDataPBImpl.java   |  208 --
 .../impl/pb/ApplicationFinishDataPBImpl.java    |  226 ---
 .../impl/pb/ApplicationStartDataPBImpl.java     |  229 ---
 .../impl/pb/ContainerFinishDataPBImpl.java      |  204 --
 .../impl/pb/ContainerStartDataPBImpl.java       |  258 ---
 .../timeline/GenericObjectMapper.java           |  135 --
 .../timeline/NameValuePair.java                 |   59 -
 .../timeline/TimelineReader.java                |  155 --
 .../timeline/TimelineStore.java                 |   29 -
 .../timeline/TimelineWriter.java                |   46 -
 .../webapp/AMSController.java                   |   37 -
 .../webapp/AMSWebApp.java                       |   42 -
 .../webapp/JAXBContextResolver.java             |   64 -
 .../webapp/TimelineWebServices.java             |  513 -----
 .../src/main/python/main.py                     |    4 +-
 .../core/loadsimulator/data/TestAppMetrics.java |  134 ++
 .../core/loadsimulator/data/TestMetric.java     |   80 +
 .../jmetertest/AMSJMeterLoadTest.java           |  198 ++
 .../jmetertest/jmetertest/AppGetMetric.java     |   57 +
 .../jmetertest/GetMetricRequestInfo.java        |   61 +
 .../jmetertest/JmeterTestPlanTask.java          |  276 +++
 .../net/TestRestMetricsSender.java              |   75 +
 .../net/TestStdOutMetricsSender.java            |   37 +
 .../util/TestRandomMetricsProvider.java         |   36 +
 .../util/TestTimeStampProvider.java             |   51 +
 .../timeline/AbstractMiniHBaseClusterTest.java  |  293 +++
 .../AbstractPhoenixConnectionlessTest.java      |  111 +
 .../metrics/core/timeline/FunctionTest.java     |   62 +
 .../HBaseTimelineMetricsServiceTest.java        |  136 ++
 .../core/timeline/ITPhoenixHBaseAccessor.java   |  472 +++++
 .../metrics/core/timeline/MetricTestHelper.java |  119 ++
 .../core/timeline/PhoenixHBaseAccessorTest.java |  291 +++
 .../metrics/core/timeline/TestClusterSuite.java |   34 +
 .../core/timeline/TestMetricHostAggregate.java  |   65 +
 .../core/timeline/TestPhoenixTransactSQL.java   |  608 ++++++
 .../core/timeline/TestTimelineMetricStore.java  |  123 ++
 .../TimelineMetricStoreWatcherTest.java         |  108 +
 .../TimelineMetricsAggregatorMemorySink.java    |  141 ++
 .../timeline/TimelineMetricsFilterTest.java     |  223 ++
 .../TimelineMetricsIgniteCacheTest.java         |  240 +++
 .../core/timeline/TopNConditionTest.java        |  105 +
 .../AbstractTimelineAggregatorTest.java         |  181 ++
 .../timeline/aggregators/DownSamplerTest.java   |   97 +
 .../aggregators/ITClusterAggregator.java        |  711 +++++++
 .../aggregators/ITMetricAggregator.java         |  355 ++++
 ...melineMetricClusterAggregatorSecondTest.java |  404 ++++
 ...sterAggregatorSecondWithCacheSourceTest.java |  114 ++
 .../MetricCollectorHAControllerTest.java        |  106 +
 .../timeline/discovery/TestMetadataManager.java |  234 +++
 .../timeline/discovery/TestMetadataSync.java    |  126 ++
 ...elineMetricsSeriesAggregateFunctionTest.java |  188 ++
 .../timeline/query/DefaultConditionTest.java    |  170 ++
 .../timeline/source/RawMetricsSourceTest.java   |  141 ++
 .../uuid/TimelineMetricUuidManagerTest.java     |  175 ++
 .../timeline/TestGenericObjectMapper.java       |  102 +
 .../metrics/webapp/TestTimelineWebServices.java |  118 ++
 .../loadsimulator/data/TestAppMetrics.java      |  134 --
 .../metrics/loadsimulator/data/TestMetric.java  |   80 -
 .../jmetertest/AMSJMeterLoadTest.java           |  198 --
 .../jmetertest/jmetertest/AppGetMetric.java     |   57 -
 .../jmetertest/GetMetricRequestInfo.java        |   61 -
 .../jmetertest/JmeterTestPlanTask.java          |  276 ---
 .../net/TestRestMetricsSender.java              |   76 -
 .../net/TestStdOutMetricsSender.java            |   37 -
 .../util/TestRandomMetricsProvider.java         |   36 -
 .../util/TestTimeStampProvider.java             |   51 -
 .../timeline/AbstractMiniHBaseClusterTest.java  |  295 ---
 .../AbstractPhoenixConnectionlessTest.java      |  111 -
 .../metrics/timeline/FunctionTest.java          |   62 -
 .../HBaseTimelineMetricsServiceTest.java        |  136 --
 .../timeline/ITPhoenixHBaseAccessor.java        |  439 ----
 .../metrics/timeline/MetricTestHelper.java      |  121 --
 .../timeline/PhoenixHBaseAccessorTest.java      |  292 ---
 .../metrics/timeline/TestClusterSuite.java      |   34 -
 .../timeline/TestMetricHostAggregate.java       |   66 -
 .../timeline/TestPhoenixTransactSQL.java        |  608 ------
 .../timeline/TestTimelineMetricStore.java       |  124 --
 .../TimelineMetricStoreWatcherTest.java         |  109 -
 .../TimelineMetricsAggregatorMemorySink.java    |  141 --
 .../timeline/TimelineMetricsFilterTest.java     |  223 --
 .../TimelineMetricsIgniteCacheTest.java         |  240 ---
 .../metrics/timeline/TopNConditionTest.java     |  105 -
 .../AbstractTimelineAggregatorTest.java         |  181 --
 .../timeline/aggregators/DownSamplerTest.java   |   97 -
 .../aggregators/ITClusterAggregator.java        |  669 ------
 .../aggregators/ITMetricAggregator.java         |  355 ----
 ...melineMetricClusterAggregatorSecondTest.java |  404 ----
 ...sterAggregatorSecondWithCacheSourceTest.java |  115 --
 .../MetricCollectorHAControllerTest.java        |  106 -
 .../timeline/discovery/TestMetadataManager.java |  234 ---
 .../timeline/discovery/TestMetadataSync.java    |  126 --
 ...elineMetricsSeriesAggregateFunctionTest.java |  188 --
 .../timeline/query/DefaultConditionTest.java    |  170 --
 .../timeline/source/RawMetricsSourceTest.java   |  141 --
 .../uuid/TimelineMetricUuidManagerTest.java     |  184 --
 .../timeline/TestGenericObjectMapper.java       |  102 -
 .../webapp/TestTimelineWebServices.java         |  124 --
 .../src/test/resources/loadsimulator/README     |    2 +-
 315 files changed, 25126 insertions(+), 25184 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/42112e28/ambari-metrics/ambari-metrics-common/src/main/java/org/apache/hadoop/metrics2/sink/timeline/Precision.java
----------------------------------------------------------------------
diff --git 
a/ambari-metrics/ambari-metrics-common/src/main/java/org/apache/hadoop/metrics2/sink/timeline/Precision.java
 
b/ambari-metrics/ambari-metrics-common/src/main/java/org/apache/hadoop/metrics2/sink/timeline/Precision.java
index e87f06e..39bcce0 100644
--- 
a/ambari-metrics/ambari-metrics-common/src/main/java/org/apache/hadoop/metrics2/sink/timeline/Precision.java
+++ 
b/ambari-metrics/ambari-metrics-common/src/main/java/org/apache/hadoop/metrics2/sink/timeline/Precision.java
@@ -20,7 +20,6 @@ package org.apache.hadoop.metrics2.sink.timeline;
 /**
  * Is used to determine metrics aggregate table.
  *
- * @see 
org.apache.hadoop.yarn.server.applicationhistoryservice.webapp.TimelineWebServices#getTimelineMetric
  */
 public enum Precision {
   SECONDS,

http://git-wip-us.apache.org/repos/asf/ambari/blob/42112e28/ambari-metrics/ambari-metrics-timelineservice/conf/unix/ambari-metrics-collector
----------------------------------------------------------------------
diff --git 
a/ambari-metrics/ambari-metrics-timelineservice/conf/unix/ambari-metrics-collector
 
b/ambari-metrics/ambari-metrics-timelineservice/conf/unix/ambari-metrics-collector
index de764ec..58984a1 100644
--- 
a/ambari-metrics/ambari-metrics-timelineservice/conf/unix/ambari-metrics-collector
+++ 
b/ambari-metrics/ambari-metrics-timelineservice/conf/unix/ambari-metrics-collector
@@ -238,7 +238,7 @@ function start()
     echo "$(date) Launching in distributed mode. Assuming Hbase daemons up and 
running." | tee -a $STARTUPFILE
   fi
 
-       
CLASS='org.apache.hadoop.yarn.server.applicationhistoryservice.AMSApplicationServer'
+       CLASS='org.apache.ambari.metrics.AMSApplicationServer'
        # YARN_OPTS="${YARN_OPTS} ${YARN_TIMELINESERVER_OPTS}"
        # if [[ -n "${YARN_TIMELINESERVER_HEAPSIZE}" ]]; then
        #   JAVA_HEAP_MAX="-Xmx${YARN_TIMELINESERVER_HEAPSIZE}m"

http://git-wip-us.apache.org/repos/asf/ambari/blob/42112e28/ambari-metrics/ambari-metrics-timelineservice/pom.xml
----------------------------------------------------------------------
diff --git a/ambari-metrics/ambari-metrics-timelineservice/pom.xml 
b/ambari-metrics/ambari-metrics-timelineservice/pom.xml
index d3a976b..35aa79b 100644
--- a/ambari-metrics/ambari-metrics-timelineservice/pom.xml
+++ b/ambari-metrics/ambari-metrics-timelineservice/pom.xml
@@ -857,7 +857,7 @@
                   <classpathPrefix></classpathPrefix>
                   <!-- Specifies the main class of the application -->
                   <mainClass>
-                    
org.apache.hadoop.yarn.server.applicationhistoryservice.metrics.loadsimulator.MetricsLoadSimulator
+                    
org.apache.ambari.metrics.core.loadsimulator.MetricsLoadSimulator
                   </mainClass>
                 </manifest>
               </archive>

http://git-wip-us.apache.org/repos/asf/ambari/blob/42112e28/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/ambari/metrics/AMSApplicationServer.java
----------------------------------------------------------------------
diff --git 
a/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/ambari/metrics/AMSApplicationServer.java
 
b/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/ambari/metrics/AMSApplicationServer.java
new file mode 100644
index 0000000..b39135e
--- /dev/null
+++ 
b/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/ambari/metrics/AMSApplicationServer.java
@@ -0,0 +1,141 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.metrics;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.http.HttpConfig;
+import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem;
+import org.apache.hadoop.metrics2.source.JvmMetrics;
+import org.apache.hadoop.service.CompositeService;
+import org.apache.hadoop.util.ExitUtil;
+import org.apache.hadoop.util.ShutdownHookManager;
+import org.apache.hadoop.util.StringUtils;
+import org.apache.hadoop.yarn.YarnUncaughtExceptionHandler;
+import org.apache.hadoop.yarn.conf.YarnConfiguration;
+import org.apache.hadoop.yarn.exceptions.YarnRuntimeException;
+import org.apache.ambari.metrics.core.timeline.HBaseTimelineMetricsService;
+import org.apache.ambari.metrics.core.timeline.TimelineMetricConfiguration;
+import org.apache.ambari.metrics.core.timeline.TimelineMetricStore;
+import org.apache.ambari.metrics.webapp.AMSWebApp;
+import org.apache.hadoop.yarn.webapp.WebApp;
+import org.apache.hadoop.yarn.webapp.WebApps;
+
+/**
+ * Metrics collector web server
+ */
+public class AMSApplicationServer extends CompositeService {
+
+  public static final int SHUTDOWN_HOOK_PRIORITY = 30;
+  private static final Log LOG = LogFactory.getLog(AMSApplicationServer.class);
+
+  TimelineMetricStore timelineMetricStore;
+  private WebApp webApp;
+  private TimelineMetricConfiguration metricConfiguration;
+
+  public AMSApplicationServer() {
+    super(AMSApplicationServer.class.getName());
+  }
+
+  @Override
+  protected void serviceInit(Configuration conf) throws Exception {
+    metricConfiguration = TimelineMetricConfiguration.getInstance();
+    metricConfiguration.initialize();
+    timelineMetricStore = createTimelineMetricStore(conf);
+    addIfService(timelineMetricStore);
+    super.serviceInit(conf);
+  }
+
+  @Override
+  protected void serviceStart() throws Exception {
+    DefaultMetricsSystem.initialize("AmbariMetricsSystem");
+    JvmMetrics.initSingleton("AmbariMetricsSystem", null);
+
+    startWebApp();
+    super.serviceStart();
+  }
+
+  @Override
+  protected void serviceStop() throws Exception {
+    if (webApp != null) {
+      webApp.stop();
+    }
+
+    DefaultMetricsSystem.shutdown();
+    super.serviceStop();
+  }
+  
+  static AMSApplicationServer launchAMSApplicationServer(String[] args) {
+    Thread.setDefaultUncaughtExceptionHandler(new 
YarnUncaughtExceptionHandler());
+    StringUtils.startupShutdownMessage(AMSApplicationServer.class, args, LOG);
+    AMSApplicationServer amsApplicationServer = null;
+    try {
+      amsApplicationServer = new AMSApplicationServer();
+      ShutdownHookManager.get().addShutdownHook(
+        new CompositeServiceShutdownHook(amsApplicationServer),
+        SHUTDOWN_HOOK_PRIORITY);
+      YarnConfiguration conf = new YarnConfiguration();
+      amsApplicationServer.init(conf);
+      amsApplicationServer.start();
+    } catch (Throwable t) {
+      LOG.fatal("Error starting AMSApplicationServer", t);
+      ExitUtil.terminate(-1, "Error starting AMSApplicationServer");
+    }
+    return amsApplicationServer;
+  }
+
+  public static void main(String[] args) {
+    launchAMSApplicationServer(args);
+  }
+
+  protected TimelineMetricStore createTimelineMetricStore(Configuration conf) {
+    LOG.info("Creating metrics store.");
+    return new HBaseTimelineMetricsService(metricConfiguration);
+  }
+
+  protected void startWebApp() {
+    String bindAddress = null;
+    try {
+      bindAddress = metricConfiguration.getWebappAddress();
+    } catch (Exception e) {
+      throw new ExceptionInInitializerError("Cannot find bind address");
+    }
+    LOG.info("Instantiating metrics collector at " + bindAddress);
+    try {
+      Configuration conf = metricConfiguration.getMetricsConf();
+      conf.set("hadoop.http.max.threads", String.valueOf(metricConfiguration
+        .getTimelineMetricsServiceHandlerThreadCount()));
+      HttpConfig.Policy policy = HttpConfig.Policy.valueOf(
+        conf.get(TimelineMetricConfiguration.TIMELINE_SERVICE_HTTP_POLICY,
+          HttpConfig.Policy.HTTP_ONLY.name()));
+      webApp =
+          WebApps
+            .$for("timeline", null, null, "ws")
+            .withHttpPolicy(conf, policy)
+            .at(bindAddress)
+            .start(new AMSWebApp(timelineMetricStore));
+    } catch (Exception e) {
+      String msg = "AHSWebApp failed to start.";
+      LOG.error(msg, e);
+      throw new YarnRuntimeException(msg, e);
+    }
+  }
+  
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/42112e28/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/ambari/metrics/core/loadsimulator/LoadRunner.java
----------------------------------------------------------------------
diff --git 
a/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/ambari/metrics/core/loadsimulator/LoadRunner.java
 
b/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/ambari/metrics/core/loadsimulator/LoadRunner.java
new file mode 100644
index 0000000..679339b
--- /dev/null
+++ 
b/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/ambari/metrics/core/loadsimulator/LoadRunner.java
@@ -0,0 +1,154 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ambari.metrics.core.loadsimulator;
+
+import static 
org.apache.ambari.metrics.core.loadsimulator.data.AppID.MASTER_APPS;
+import static 
org.apache.ambari.metrics.core.loadsimulator.data.AppID.SLAVE_APPS;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Date;
+import java.util.List;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.ambari.metrics.core.loadsimulator.data.ApplicationInstance;
+import org.apache.ambari.metrics.core.loadsimulator.data.HostMetricsGenerator;
+import 
org.apache.ambari.metrics.core.loadsimulator.data.MetricsGeneratorConfigurer;
+import org.apache.ambari.metrics.core.loadsimulator.net.MetricsSender;
+import org.apache.ambari.metrics.core.loadsimulator.net.RestMetricsSender;
+import org.apache.ambari.metrics.core.loadsimulator.util.TimeStampProvider;
+import org.apache.ambari.metrics.core.loadsimulator.data.AppID;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ *
+ */
+public class LoadRunner {
+  private final static Logger LOG = LoggerFactory.getLogger(LoadRunner.class);
+
+  private final ScheduledExecutorService timer;
+  private final ExecutorService workersPool;
+  private final Collection<Callable<String>> workers;
+  private final long startTime = new Date().getTime();
+  private final int collectIntervalMillis;
+  private final int sendIntervalMillis;
+
+  public LoadRunner(String hostName,
+                    int threadCount,
+                    String metricsHostName,
+                    int minHostIndex,
+                    int collectIntervalMillis,
+                    int sendIntervalMillis,
+                    boolean createMaster) {
+    this.collectIntervalMillis = collectIntervalMillis;
+    this.workersPool = Executors.newFixedThreadPool(threadCount);
+    this.timer = Executors.newScheduledThreadPool(1);
+    this.sendIntervalMillis = sendIntervalMillis;
+
+    workers = prepareWorkers(hostName, threadCount, metricsHostName, 
createMaster, minHostIndex);
+  }
+
+  private Collection<Callable<String>> prepareWorkers(String hostName,
+                                                      int threadCount,
+                                                      String metricsHost,
+                                                      Boolean createMaster, 
int minHostIndex) {
+    Collection<Callable<String>> senderWorkers =
+      new ArrayList<Callable<String>>(threadCount);
+
+    int startIndex = minHostIndex;
+    if (createMaster) {
+      String simHost = hostName + startIndex;
+      addMetricsWorkers(senderWorkers, simHost, metricsHost, MASTER_APPS);
+      startIndex++;
+    }
+
+    for (int i = startIndex; i < threadCount + minHostIndex; i++) {
+      String simHost = hostName + i;
+      addMetricsWorkers(senderWorkers, simHost, metricsHost, SLAVE_APPS);
+    }
+
+    return senderWorkers;
+  }
+
+  private void addMetricsWorkers(Collection<Callable<String>> senderWorkers,
+                                 String specificHostName,
+                                 String metricsHostName,
+                                 AppID[] apps) {
+    for (AppID app : apps) {
+      HostMetricsGenerator metricsGenerator =
+        createApplicationMetrics(specificHostName, app);
+      MetricsSender sender = new RestMetricsSender(metricsHostName);
+      senderWorkers.add(new MetricsSenderWorker(sender, metricsGenerator));
+    }
+  }
+
+  private HostMetricsGenerator createApplicationMetrics(String simHost, AppID 
host) {
+    ApplicationInstance appInstance = new ApplicationInstance(simHost, host, 
"");
+    TimeStampProvider timeStampProvider = new TimeStampProvider(startTime,
+      collectIntervalMillis, sendIntervalMillis);
+
+    return MetricsGeneratorConfigurer
+      .createMetricsForHost(appInstance, timeStampProvider);
+  }
+
+  public void start() {
+    timer.scheduleAtFixedRate(new Runnable() {
+      @Override
+      public void run() {
+        try {
+          runOnce();
+        } catch (InterruptedException e) {
+          Thread.currentThread().interrupt();
+        }
+      }
+    }, 0, sendIntervalMillis, TimeUnit.MILLISECONDS);
+  }
+
+  public void runOnce() throws InterruptedException {
+    List<Future<String>> futures = workersPool.invokeAll(workers,
+      sendIntervalMillis / 2,
+      TimeUnit.MILLISECONDS);
+    int done = 0;
+
+    // TODO: correctly count the failed tasks
+    for (Future<String> future : futures) {
+      done += future.isDone() ? 1 : 0;
+    }
+
+    LOG.info("Finished successfully " + done + " tasks ");
+  }
+
+  public void shutdown() {
+    timer.shutdownNow();
+    workersPool.shutdownNow();
+  }
+
+  public static void main(String[] args) {
+    LoadRunner runner =
+      new LoadRunner("local", 0, "metrics", 0, 10000, 20000, false);
+
+    runner.start();
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/42112e28/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/ambari/metrics/core/loadsimulator/MetricsLoadSimulator.java
----------------------------------------------------------------------
diff --git 
a/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/ambari/metrics/core/loadsimulator/MetricsLoadSimulator.java
 
b/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/ambari/metrics/core/loadsimulator/MetricsLoadSimulator.java
new file mode 100644
index 0000000..93e03a5
--- /dev/null
+++ 
b/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/ambari/metrics/core/loadsimulator/MetricsLoadSimulator.java
@@ -0,0 +1,138 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ambari.metrics.core.loadsimulator;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Sample Usage:
+ * <pre>
+ * $ java -cp "dependency/*":LoadSimulator-1.0-SNAPSHOT.jar \
+ * org.apache.ambari.metrics.MetricsLoadSimulator \
+ * -h "bartosz.laptop" -n 2 -m "162.216.148.45" -c 10000 -s 30000</pre>
+ */
+public class MetricsLoadSimulator {
+  private final static Logger LOG = 
LoggerFactory.getLogger(MetricsLoadSimulator
+    .class);
+
+  public static void main(String[] args) throws IOException, 
InterruptedException {
+    Map<String, String> mapArgs = parseArgs(args);
+
+    LoadRunner loadRunner = new LoadRunner(
+      mapArgs.get("hostName"),
+      Integer.valueOf(mapArgs.get("numberOfHosts")),
+      mapArgs.get("metricsHostName"),
+      mapArgs.get("minHostIndex") == null ? 0 : 
Integer.valueOf(mapArgs.get("minHostIndex")),
+      Integer.valueOf(mapArgs.get("collectInterval")),
+      Integer.valueOf(mapArgs.get("sendInterval")),
+      Boolean.valueOf(mapArgs.get("master"))
+    );
+
+    loadRunner.start();
+  }
+
+  /*
+   Another entry point to the test to be called from 
./jmetertest/AMSJMeterLoadTest.java
+   */
+  public static void startTest(Map<String,String> mapArgs) {
+
+    LoadRunner loadRunner = new LoadRunner(
+            mapArgs.get("hostName"),
+            Integer.valueOf(mapArgs.get("numberOfHosts")),
+            mapArgs.get("metricsHostName"),
+            mapArgs.get("minHostIndex") == null ? 0 : 
Integer.valueOf(mapArgs.get("minHostIndex")),
+            Integer.valueOf(mapArgs.get("collectInterval")),
+            Integer.valueOf(mapArgs.get("sendInterval")),
+            Boolean.valueOf(mapArgs.get("master"))
+    );
+
+    loadRunner.start();
+  }
+
+  private static Map<String, String> parseArgs(String[] args) {
+    Map<String, String> mapProps = new HashMap<String, String>();
+    mapProps.put("hostName", "host");
+    mapProps.put("numberOfHosts", "20");
+    mapProps.put("trafficType", "burst");
+    mapProps.put("metricsHostName", "localhost");
+    mapProps.put("collectInterval", "10000");
+    mapProps.put("sendInterval", "60000");
+
+    if (args.length == 0) {
+      printUsage();
+      throw new RuntimeException("Unexpected argument, See usage message.");
+    } else {
+      for (int i = 0; i < args.length; i += 2) {
+        String arg = args[i];
+        if (arg.equals("-h")) {
+          mapProps.put("hostName", args[i + 1]);
+        } else if (arg.equals("-n")) {
+          mapProps.put("numberOfHosts", args[i + 1]);
+        } else if (arg.equals("-t")) {
+          mapProps.put("trafficType", args[i + 1]);
+        } else if (arg.equals("-m")) {
+          mapProps.put("metricsHostName", args[i + 1]);
+        } else if (arg.equals("-c")) {
+          mapProps.put("collectInterval", args[i + 1]);
+        } else if (arg.equals("-s")) {
+          mapProps.put("sendInterval", args[i + 1]);
+        } else if (arg.equals("-M")) {
+          mapProps.put("master", args[i + 1]);
+        } else if (arg.equals("-d")) {
+          // a dummy switch - it says that we agree with defaults
+        } else {
+          printUsage();
+          throw new RuntimeException("Unexpected argument, See usage 
message.");
+        }
+      }
+    }
+
+    LOG.info("Recognized options: baseHostName={} hosts#={} trafficMode={} " +
+        "metricsHostName={} collectIntervalMillis={} sendIntervalMillis={} " +
+        "simulateMaster={}",
+      mapProps.get("hostName"),
+      Integer.valueOf(mapProps.get("numberOfHosts")),
+      mapProps.get("trafficType"),
+      mapProps.get("metricsHostName"),
+      Integer.valueOf(mapProps.get("collectInterval")),
+      Integer.valueOf(mapProps.get("sendInterval")),
+      Boolean.valueOf(mapProps.get("master"))
+    );
+
+    return mapProps;
+  }
+
+  public static void printUsage() {
+    System.err.println("Usage: java MetricsLoadSimulator [OPTIONS]");
+    System.err.println("Options: ");
+    System.err.println("[-h hostName] [-n numberOfHosts] "
+      + "[-t trafficMode {burst, staggered}] [-m metricsHostName] "
+      + "[-c collectIntervalMillis {10 sec}] [-s sendIntervalMillis {60 sec}]"
+      + "[-M simulateMaster {true, false}] ");
+    System.err.println();
+    System.err.println("When you select a master, then one simulated host will 
play");
+    System.err.println("a role of a master, and the rest will be slaves. 
Otherwise");
+    System.err.println("all simulation threads (single thread is for single 
host)");
+    System.err.println("will be slave hosts");
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/42112e28/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/ambari/metrics/core/loadsimulator/MetricsSenderWorker.java
----------------------------------------------------------------------
diff --git 
a/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/ambari/metrics/core/loadsimulator/MetricsSenderWorker.java
 
b/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/ambari/metrics/core/loadsimulator/MetricsSenderWorker.java
new file mode 100644
index 0000000..6e5e6b7
--- /dev/null
+++ 
b/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/ambari/metrics/core/loadsimulator/MetricsSenderWorker.java
@@ -0,0 +1,60 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ambari.metrics.core.loadsimulator;
+
+
+import java.io.IOException;
+import java.util.concurrent.Callable;
+
+import org.apache.ambari.metrics.core.loadsimulator.util.Json;
+import org.apache.ambari.metrics.core.loadsimulator.data.AppMetrics;
+import org.apache.ambari.metrics.core.loadsimulator.data.HostMetricsGenerator;
+import org.apache.ambari.metrics.core.loadsimulator.net.MetricsSender;
+import org.apache.ambari.metrics.core.loadsimulator.net.RestMetricsSender;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ */
+public class MetricsSenderWorker implements Callable<String> {
+  private final static Logger LOG = 
LoggerFactory.getLogger(RestMetricsSender.class);
+
+  MetricsSender sender;
+  HostMetricsGenerator hmg;
+
+  public MetricsSenderWorker(MetricsSender sender, HostMetricsGenerator 
metricsGenerator) {
+    this.sender = sender;
+    hmg = metricsGenerator;
+  }
+
+  @Override
+  public String call() throws Exception {
+    AppMetrics hostMetrics = hmg.createMetrics();
+
+    try {
+      String request = new Json().serialize(hostMetrics); //inject?
+      String response = sender.pushMetrics(request);
+
+      return response;
+    } catch (IOException e) {
+      LOG.error("Error while pushing metrics: ", e);
+      throw e;
+    }
+
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/42112e28/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/ambari/metrics/core/loadsimulator/data/AppID.java
----------------------------------------------------------------------
diff --git 
a/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/ambari/metrics/core/loadsimulator/data/AppID.java
 
b/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/ambari/metrics/core/loadsimulator/data/AppID.java
new file mode 100644
index 0000000..7290516
--- /dev/null
+++ 
b/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/ambari/metrics/core/loadsimulator/data/AppID.java
@@ -0,0 +1,45 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ambari.metrics.core.loadsimulator.data;
+
+public enum AppID {
+  HOST("HOST"),
+  NAMENODE("namenode"),
+  RESOURCEMANAGER("resourcemanager"),
+  DATANODE("datanode"),
+  NODEMANAGER("nodemanager"),
+  MASTER_HBASE("hbase"),
+  SLAVE_HBASE("hbase"),
+  NIMBUS("nimbus"),
+  HIVEMETASTORE("hivemetastore"),
+  HIVESERVER2("hiveserver2"),
+  KAFKA_BROKER("kafka_broker");
+
+  public static final AppID[] MASTER_APPS = {HOST, NAMENODE, RESOURCEMANAGER, 
MASTER_HBASE, KAFKA_BROKER, NIMBUS, HIVEMETASTORE, HIVESERVER2};
+  public static final AppID[] SLAVE_APPS = {HOST, DATANODE, NODEMANAGER, 
SLAVE_HBASE};
+
+  private String id;
+
+  private AppID(String id) {
+    this.id = id;
+  }
+
+  public String getId() {
+    return id;
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/42112e28/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/ambari/metrics/core/loadsimulator/data/AppMetrics.java
----------------------------------------------------------------------
diff --git 
a/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/ambari/metrics/core/loadsimulator/data/AppMetrics.java
 
b/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/ambari/metrics/core/loadsimulator/data/AppMetrics.java
new file mode 100644
index 0000000..d49c81c
--- /dev/null
+++ 
b/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/ambari/metrics/core/loadsimulator/data/AppMetrics.java
@@ -0,0 +1,47 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ambari.metrics.core.loadsimulator.data;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+/**
+ * AppMetrics is a class that helps to create properly initialized metrics for
+ * current app. It also holds the
+ * metrics and can be serialized to json.
+ */
+public class AppMetrics {
+
+  private final Collection<Metric> metrics = new ArrayList<Metric>();
+  private final transient ApplicationInstance applicationId;
+  private final transient long startTime;
+
+  public AppMetrics(ApplicationInstance applicationId, long startTime) {
+    this.applicationId = applicationId;
+    this.startTime = startTime;
+  }
+
+  public Metric createMetric(String metricName) {
+    return new Metric(applicationId, metricName, startTime);
+  }
+
+  public void addMetric(Metric metric) {
+    metrics.add(metric);
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/42112e28/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/ambari/metrics/core/loadsimulator/data/ApplicationInstance.java
----------------------------------------------------------------------
diff --git 
a/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/ambari/metrics/core/loadsimulator/data/ApplicationInstance.java
 
b/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/ambari/metrics/core/loadsimulator/data/ApplicationInstance.java
new file mode 100644
index 0000000..ffe942b
--- /dev/null
+++ 
b/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/ambari/metrics/core/loadsimulator/data/ApplicationInstance.java
@@ -0,0 +1,58 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ambari.metrics.core.loadsimulator.data;
+
+/**
+ * AppId is a helper class that encapsulates the common part of metrics 
message.
+ * It contains hostName, appId and instanceId. It is immutable,
+ * and it can not hold null values.
+ */
+public final class ApplicationInstance {
+
+  private final transient String hostName;
+  private final transient AppID appId;
+  private final transient String instanceId;
+
+  /**
+   * @param hostname
+   * @param appId
+   * @param instanceId
+   */
+  public ApplicationInstance(String hostname, AppID appId, String instanceId) {
+    if (hostname == null || appId == null || instanceId == null)
+      throw new IllegalArgumentException("ApplicationInstance can not be " +
+        "instantiated with null values");
+
+    this.hostName = hostname;
+    this.appId = appId;
+    this.instanceId = instanceId;
+  }
+
+  public String getInstanceId() {
+    return instanceId;
+  }
+
+  public AppID getAppId() {
+    return appId;
+  }
+
+  public String getHostName() {
+    return hostName;
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/42112e28/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/ambari/metrics/core/loadsimulator/data/HostMetricsGenerator.java
----------------------------------------------------------------------
diff --git 
a/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/ambari/metrics/core/loadsimulator/data/HostMetricsGenerator.java
 
b/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/ambari/metrics/core/loadsimulator/data/HostMetricsGenerator.java
new file mode 100644
index 0000000..7e2fd1a
--- /dev/null
+++ 
b/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/ambari/metrics/core/loadsimulator/data/HostMetricsGenerator.java
@@ -0,0 +1,61 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ambari.metrics.core.loadsimulator.data;
+
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.ambari.metrics.core.loadsimulator.util.RandomMetricsProvider;
+import org.apache.ambari.metrics.core.loadsimulator.util.TimeStampProvider;
+
+/**
+ */
+public class HostMetricsGenerator {
+
+  private Map<String, RandomMetricsProvider> metricDataProviders = new 
HashMap<String, RandomMetricsProvider>();
+  private final TimeStampProvider tsp;
+  private final ApplicationInstance id;
+
+  public HostMetricsGenerator(ApplicationInstance id,
+                              TimeStampProvider timeStamps,
+                              Map<String, RandomMetricsProvider> 
metricDataProviders) {
+    this.id = id;
+    this.tsp = timeStamps;
+    this.metricDataProviders = metricDataProviders;
+  }
+
+  public AppMetrics createMetrics() {
+    long[] timestamps = tsp.timestampsForNextInterval();
+    AppMetrics appMetrics = new AppMetrics(id, timestamps[0]);
+
+    for (Map.Entry<String, RandomMetricsProvider> entry : 
metricDataProviders.entrySet()) {
+      String metricName = entry.getKey();
+      RandomMetricsProvider metricData = entry.getValue();
+
+      Metric metric = appMetrics.createMetric(metricName);
+      for (long timestamp : timestamps) {
+        metric.putMetric(timestamp, String.valueOf(metricData.next()));
+      }
+      appMetrics.addMetric(metric);
+    }
+
+    return appMetrics;
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/42112e28/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/ambari/metrics/core/loadsimulator/data/Metric.java
----------------------------------------------------------------------
diff --git 
a/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/ambari/metrics/core/loadsimulator/data/Metric.java
 
b/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/ambari/metrics/core/loadsimulator/data/Metric.java
new file mode 100644
index 0000000..7bcc852
--- /dev/null
+++ 
b/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/ambari/metrics/core/loadsimulator/data/Metric.java
@@ -0,0 +1,71 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ambari.metrics.core.loadsimulator.data;
+
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+public class Metric {
+
+  private String instanceid;
+  private String hostname;
+  private Map<String, String> metrics = new LinkedHashMap<String, String>();
+  private String starttime;
+  private String appid;
+  private String metricname;
+
+  // i don't like this ctor, but it has to be public for json deserialization
+  public Metric() {
+  }
+
+  public Metric(ApplicationInstance app, String metricName, long startTime) {
+    this.hostname = app.getHostName();
+    this.appid = app.getAppId().getId();
+    this.instanceid = app.getInstanceId();
+    this.metricname = metricName;
+    this.starttime = Long.toString(startTime);
+  }
+
+  public void putMetric(long timestamp, String value) {
+    metrics.put(Long.toString(timestamp), value);
+  }
+
+  public String getInstanceid() {
+    return instanceid;
+  }
+
+  public String getHostname() {
+    return hostname;
+  }
+
+  public Map<String, String> getMetrics() {
+    return metrics;
+  }
+
+  public String getStarttime() {
+    return starttime;
+  }
+
+  public String getAppid() {
+    return appid;
+  }
+
+  public String getMetricname() {
+    return metricname;
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/42112e28/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/ambari/metrics/core/loadsimulator/data/MetricsGeneratorConfigurer.java
----------------------------------------------------------------------
diff --git 
a/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/ambari/metrics/core/loadsimulator/data/MetricsGeneratorConfigurer.java
 
b/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/ambari/metrics/core/loadsimulator/data/MetricsGeneratorConfigurer.java
new file mode 100644
index 0000000..4f848a4
--- /dev/null
+++ 
b/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/ambari/metrics/core/loadsimulator/data/MetricsGeneratorConfigurer.java
@@ -0,0 +1,93 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ambari.metrics.core.loadsimulator.data;
+
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.ambari.metrics.core.loadsimulator.util.TimeStampProvider;
+import org.apache.ambari.metrics.core.loadsimulator.util.RandomMetricsProvider;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * MetricsGeneratorConfigurer is a factory that reads metrics definition from 
a file,
+ * and returns an Single HostMetricsGenerator. Check createMetricsForHost 
method
+ * for details.
+ */
+public class MetricsGeneratorConfigurer {
+
+  private final static Logger LOG = LoggerFactory.getLogger
+    (MetricsGeneratorConfigurer.class);
+
+  /**
+   * Creates HostMetricsGenerator configured with metric names loaded from 
file.
+   *
+   * @param id         ApplicationInstance descriptor, will be used to create
+   *                   HostMetricsGenerator, cannot be null
+   * @param timeStamps configured TimeStampProvider that can provide next
+   *                   timestamp, cannot be null
+   * @return HostMetricsGenerator with given ApplicationInstance id and 
configured
+   * mapping of
+   * metric names to data providers
+   */
+  public static HostMetricsGenerator createMetricsForHost(
+    ApplicationInstance id,
+    TimeStampProvider timeStamps) {
+    return new HostMetricsGenerator(id, timeStamps, 
readMetrics(id.getAppId()));
+  }
+
+  private static Map<String, RandomMetricsProvider> readMetrics(AppID type) {
+    InputStream input = null;
+    Map<String, RandomMetricsProvider> metrics =
+      new HashMap<String, RandomMetricsProvider>();
+    String fileName = "metrics_def/" + type.toString() + ".dat";
+
+    try {
+      LOG.info("Loading " + fileName);
+
+      input = MetricsGeneratorConfigurer.class.getClassLoader()
+        .getResourceAsStream(fileName);
+
+      BufferedReader reader = new BufferedReader(new InputStreamReader(input));
+
+      String line;
+      while ((line = reader.readLine()) != null) {
+        metrics.put(line.trim(), new RandomMetricsProvider(100, 200));
+      }
+
+    } catch (IOException e) {
+      LOG.error("Cannot read file " + fileName + " for appID " + 
type.toString(), e);
+    } finally {
+      if (input != null) {
+        try {
+          input.close();
+        } catch (IOException ex) {
+          // intentionally left blank, here we cannot do anything
+        }
+      }
+    }
+
+    return metrics;
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/42112e28/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/ambari/metrics/core/loadsimulator/net/MetricsSender.java
----------------------------------------------------------------------
diff --git 
a/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/ambari/metrics/core/loadsimulator/net/MetricsSender.java
 
b/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/ambari/metrics/core/loadsimulator/net/MetricsSender.java
new file mode 100644
index 0000000..e3876c7
--- /dev/null
+++ 
b/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/ambari/metrics/core/loadsimulator/net/MetricsSender.java
@@ -0,0 +1,31 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ambari.metrics.core.loadsimulator.net;
+
+/**
+ * MetricSender should provides a simple way of pushing metrics to some 
service.
+ */
+public interface MetricsSender {
+  /**
+   * Push metrics to the metric service (e.g. a metrics storage system).
+   *
+   * @param payload the payload to be sent to metrics service
+   * @return response message either acknowledgement or error
+   */
+  String pushMetrics(String payload);
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/42112e28/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/ambari/metrics/core/loadsimulator/net/RestMetricsSender.java
----------------------------------------------------------------------
diff --git 
a/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/ambari/metrics/core/loadsimulator/net/RestMetricsSender.java
 
b/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/ambari/metrics/core/loadsimulator/net/RestMetricsSender.java
new file mode 100644
index 0000000..455b381
--- /dev/null
+++ 
b/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/ambari/metrics/core/loadsimulator/net/RestMetricsSender.java
@@ -0,0 +1,92 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ambari.metrics.core.loadsimulator.net;
+
+import java.io.IOException;
+import java.util.concurrent.TimeUnit;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Stopwatch;
+
+/**
+ * Implements MetricsSender and provides a way of pushing metrics to 
application metrics history service using REST
+ * endpoint.
+ */
+public class RestMetricsSender implements MetricsSender {
+  private final static Logger LOG = 
LoggerFactory.getLogger(RestMetricsSender.class);
+
+  private final static String COLLECTOR_URL = 
"http://%s/ws/v1/timeline/metrics";;
+  private final String collectorServiceAddress;
+
+  /**
+   * Creates unconnected RestMetricsSender with endpoint configured as
+   * http://${metricsHost}:6188/ws/v1/timeline/metrics,
+   * where ${metricsHost} is specified by metricHost param.
+   *
+   * @param metricsHost the hostname that will be used to access application 
metrics history service.
+   */
+  public RestMetricsSender(String metricsHost) {
+    collectorServiceAddress = String.format(COLLECTOR_URL, metricsHost);
+  }
+
+  /**
+   * Push metrics to the REST endpoint. Connection is always open and closed 
on every call.
+   *
+   * @param payload the payload with metrics to be sent to metrics service
+   * @return response message either acknowledgement or error, empty on 
exception
+   */
+  @Override
+  public String pushMetrics(String payload) {
+    String responseString = "";
+    UrlService svc = null;
+    Stopwatch timer = new Stopwatch().start();
+
+    try {
+      LOG.info("server: {}", collectorServiceAddress);
+
+      svc = getConnectedUrlService();
+      responseString = svc.send(payload);
+
+      timer.stop();
+      LOG.info("http response time: " + timer.elapsed(TimeUnit.MILLISECONDS)
+        + " ms");
+
+      if (responseString.length() > 0) {
+        LOG.debug("POST response from server: " + responseString);
+      }
+    } catch (IOException e) {
+      LOG.error("", e);
+    } finally {
+      if (svc != null) {
+        svc.disconnect();
+      }
+    }
+
+    return responseString;
+  }
+
+  /**
+   * Relaxed to protected for testing.
+   */
+  protected UrlService getConnectedUrlService() throws IOException {
+    return UrlService.newConnection(collectorServiceAddress);
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/42112e28/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/ambari/metrics/core/loadsimulator/net/StdOutMetricsSender.java
----------------------------------------------------------------------
diff --git 
a/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/ambari/metrics/core/loadsimulator/net/StdOutMetricsSender.java
 
b/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/ambari/metrics/core/loadsimulator/net/StdOutMetricsSender.java
new file mode 100644
index 0000000..335b2c3
--- /dev/null
+++ 
b/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/ambari/metrics/core/loadsimulator/net/StdOutMetricsSender.java
@@ -0,0 +1,56 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ambari.metrics.core.loadsimulator.net;
+
+import java.io.PrintStream;
+
+/**
+ * StdOutMetricsSender dumps metrics to defined PrintStream out. It is useful 
for testing.
+ */
+public class StdOutMetricsSender implements MetricsSender {
+  public final PrintStream out;
+  private String metricsHostName;
+
+  /**
+   * Creates new StdOutMetricsSender with specified hostname (only used in 
messages) and sends output to System.out
+   *
+   * @param metricsHostName a name used in printed messages
+   */
+  public StdOutMetricsSender(String metricsHostName) {
+    this(metricsHostName, System.out);
+  }
+
+  /**
+   * Creates new StdOutMetricsSender with specified hostname (only used in 
messages) and PrintStream which is used as
+   * an output.
+   *
+   * @param metricsHostName a name used in printed messages
+   * @param out             PrintStream that the Sender will write to, can be 
System.out
+   */
+  public StdOutMetricsSender(String metricsHostName, PrintStream out) {
+    this.metricsHostName = metricsHostName;
+    this.out = out;
+  }
+
+  @Override
+  public String pushMetrics(String payload) {
+    out.println("Sending to " + metricsHostName + ": " + payload);
+
+    return "OK";
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/42112e28/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/ambari/metrics/core/loadsimulator/net/UrlService.java
----------------------------------------------------------------------
diff --git 
a/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/ambari/metrics/core/loadsimulator/net/UrlService.java
 
b/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/ambari/metrics/core/loadsimulator/net/UrlService.java
new file mode 100644
index 0000000..b30f854
--- /dev/null
+++ 
b/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/ambari/metrics/core/loadsimulator/net/UrlService.java
@@ -0,0 +1,100 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ambari.metrics.core.loadsimulator.net;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
+import java.net.HttpURLConnection;
+import java.net.URL;
+
+public class UrlService {
+
+  public static final int CONNECT_TIMEOUT = 20000;
+  public static final int READ_TIMEOUT = 20000;
+  private final String address;
+  private HttpURLConnection conn;
+
+  private UrlService(String address) {
+    this.address = address;
+  }
+
+  /**
+   * Returns a new UrlService connected to specified address.
+   *
+   * @param address
+   * @return
+   * @throws IOException
+   */
+  public static UrlService newConnection(String address) throws IOException {
+    UrlService svc = new UrlService(address);
+    svc.connect();
+
+    return svc;
+  }
+
+  public HttpURLConnection connect() throws IOException {
+    URL url = new URL(address);
+    conn = (HttpURLConnection) url.openConnection();
+
+    //TODO: make timeouts configurable
+    conn.setConnectTimeout(CONNECT_TIMEOUT);
+    conn.setReadTimeout(READ_TIMEOUT);
+    conn.setDoInput(true);
+    conn.setDoOutput(true);
+    conn.setRequestMethod("POST");
+    conn.setRequestProperty("Content-Type", "application/json");
+    conn.setRequestProperty("Accept", "*/*");
+
+    return conn;
+  }
+
+  public String send(String payload) throws IOException {
+    if (conn == null)
+      throw new IllegalStateException("Cannot use unconnected UrlService");
+    write(payload);
+
+    return read();
+  }
+
+  private String read() throws IOException {
+    StringBuilder response = new StringBuilder();
+
+    BufferedReader br = new BufferedReader(new InputStreamReader(
+      conn.getInputStream()));
+    String line = null;
+    while ((line = br.readLine()) != null) {
+      response.append(line);
+    }
+    br.close();
+
+    return response.toString();
+  }
+
+  private void write(String payload) throws IOException {
+    OutputStreamWriter writer = new OutputStreamWriter(conn.getOutputStream(),
+      "UTF-8");
+    writer.write(payload);
+    writer.close();
+  }
+
+  public void disconnect() {
+    conn.disconnect();
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/42112e28/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/ambari/metrics/core/loadsimulator/util/Json.java
----------------------------------------------------------------------
diff --git 
a/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/ambari/metrics/core/loadsimulator/util/Json.java
 
b/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/ambari/metrics/core/loadsimulator/util/Json.java
new file mode 100644
index 0000000..3e186a1
--- /dev/null
+++ 
b/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/ambari/metrics/core/loadsimulator/util/Json.java
@@ -0,0 +1,62 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ambari.metrics.core.loadsimulator.util;
+
+import java.io.IOException;
+
+import org.codehaus.jackson.annotate.JsonAutoDetect;
+import org.codehaus.jackson.annotate.JsonMethod;
+import org.codehaus.jackson.map.ObjectMapper;
+import org.codehaus.jackson.map.SerializationConfig;
+
+/**
+ * Small wrapper that configures the ObjectMapper with some defaults.
+ */
+public class Json {
+  private ObjectMapper myObjectMapper;
+
+  /**
+   * Creates default Json ObjectMapper that maps fields.
+   */
+  public Json() {
+    this(false);
+  }
+
+  /**
+   * Creates a Json ObjectMapper that maps fields and optionally pretty prints 
the
+   * serialized objects.
+   *
+   * @param pretty a flag - if true the output will be pretty printed.
+   */
+  public Json(boolean pretty) {
+    myObjectMapper = new ObjectMapper();
+    myObjectMapper.setVisibility(JsonMethod.FIELD, 
JsonAutoDetect.Visibility.ANY);
+    if (pretty) {
+      myObjectMapper.configure(SerializationConfig.Feature.INDENT_OUTPUT, 
true);
+    }
+  }
+
+  public String serialize(Object o) throws IOException {
+    return myObjectMapper.writeValueAsString(o);
+  }
+
+  public <T> T deserialize(String content, Class<T> paramClass) throws 
IOException {
+    return myObjectMapper.readValue(content, paramClass);
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/42112e28/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/ambari/metrics/core/loadsimulator/util/RandomMetricsProvider.java
----------------------------------------------------------------------
diff --git 
a/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/ambari/metrics/core/loadsimulator/util/RandomMetricsProvider.java
 
b/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/ambari/metrics/core/loadsimulator/util/RandomMetricsProvider.java
new file mode 100644
index 0000000..a0cf9f6
--- /dev/null
+++ 
b/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/ambari/metrics/core/loadsimulator/util/RandomMetricsProvider.java
@@ -0,0 +1,39 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ambari.metrics.core.loadsimulator.util;
+
+import java.util.Random;
+
+/**
+ */
+public class RandomMetricsProvider {
+
+  private double min;
+  private double max;
+  private Random rnd;
+
+  public RandomMetricsProvider(double min, double max) {
+    this.min = min;
+    this.max = max;
+    this.rnd = new Random();
+  }
+
+  public double next() {
+    return rnd.nextDouble() * (max - min) + min;
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/42112e28/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/ambari/metrics/core/loadsimulator/util/TimeStampProvider.java
----------------------------------------------------------------------
diff --git 
a/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/ambari/metrics/core/loadsimulator/util/TimeStampProvider.java
 
b/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/ambari/metrics/core/loadsimulator/util/TimeStampProvider.java
new file mode 100644
index 0000000..015a297
--- /dev/null
+++ 
b/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/ambari/metrics/core/loadsimulator/util/TimeStampProvider.java
@@ -0,0 +1,51 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ambari.metrics.core.loadsimulator.util;
+
+/**
+ */
+public class TimeStampProvider {
+  private int timeStep;
+  private long currentTime;
+  private int sendInterval;
+
+  public TimeStampProvider(long startTime, int timeStep, int sendInterval) {
+    this.timeStep = timeStep;
+    this.currentTime = startTime - timeStep;
+    this.sendInterval = sendInterval;
+  }
+
+  public long next() {
+    return currentTime += timeStep;
+  }
+
+  public long[] timestampsForNextInterval() {
+    return timestampsForInterval(sendInterval);
+  }
+
+  private long[] timestampsForInterval(int sendInterval) {
+    int steps = sendInterval / timeStep;
+    long[] timestamps = new long[steps];
+
+    for (int i = 0; i < timestamps.length; i++) {
+      timestamps[i] = next();
+    }
+
+    return timestamps;
+  }
+}

Reply via email to