You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by av...@apache.org on 2018/01/02 21:59:42 UTC
[4/7] ambari git commit: AMBARI-22717 : Remove Anomaly Detection code
from branch-3.0-ams. (avijayan)
http://git-wip-us.apache.org/repos/asf/ambari/blob/25c18121/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/metadata/ADMetadataProvider.scala
----------------------------------------------------------------------
diff --git a/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/metadata/ADMetadataProvider.scala b/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/metadata/ADMetadataProvider.scala
deleted file mode 100644
index c277221..0000000
--- a/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/metadata/ADMetadataProvider.scala
+++ /dev/null
@@ -1,147 +0,0 @@
-/*
- * 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.adservice.metadata
-
-import javax.ws.rs.core.Response
-
-import org.apache.ambari.metrics.adservice.configuration.MetricCollectorConfiguration
-import org.apache.commons.lang.StringUtils
-import org.slf4j.{Logger, LoggerFactory}
-
-import com.fasterxml.jackson.databind.ObjectMapper
-import com.fasterxml.jackson.module.scala.experimental.ScalaObjectMapper
-
-import scalaj.http.{Http, HttpRequest, HttpResponse}
-
-/**
- * Class to invoke Metrics Collector metadata API.
- * TODO : Instantiate a sync thread that regularly updates the internal maps by reading off AMS metadata.
- */
-class ADMetadataProvider extends MetricMetadataProvider {
-
- var metricCollectorHosts: Array[String] = Array.empty[String]
- var metricCollectorPort: String = _
- var metricCollectorProtocol: String = _
- var metricMetadataPath: String = "/v1/timeline/metrics/metadata/keys"
- val LOG : Logger = LoggerFactory.getLogger(classOf[ADMetadataProvider])
-
- val connectTimeout: Int = 10000
- val readTimeout: Int = 10000
- //TODO: Add retries for metrics collector GET call.
- //val retries: Long = 5
-
- def this(configuration: MetricCollectorConfiguration) {
- this
- if (StringUtils.isNotEmpty(configuration.getHosts)) {
- metricCollectorHosts = configuration.getHosts.split(",")
- }
- metricCollectorPort = configuration.getPort
- metricCollectorProtocol = configuration.getProtocol
- metricMetadataPath = configuration.getMetadataEndpoint
- }
-
- override def getMetricKeysForDefinitions(metricSourceDefinition: MetricSourceDefinition): Set[MetricKey] = {
-
- val numDefinitions: Int = metricSourceDefinition.metricDefinitions.size
- val metricKeySet: scala.collection.mutable.Set[MetricKey] = scala.collection.mutable.Set.empty[MetricKey]
-
- for (metricDef <- metricSourceDefinition.metricDefinitions) {
- if (metricDef.isValid) { //Skip requesting metric keys for invalid definitions.
- for (host <- metricCollectorHosts) {
- val metricKeys: Set[MetricKey] = getKeysFromMetricsCollector(metricCollectorProtocol, host, metricCollectorPort, metricMetadataPath, metricDef)
- if (metricKeys != null) {
- metricKeySet.++=(metricKeys)
- }
- }
- }
- }
- metricKeySet.toSet
- }
-
- /**
- *
- * @param protocol
- * @param host
- * @param port
- * @param path
- * @param metricDefinition
- * @return
- */
- def getKeysFromMetricsCollector(protocol: String, host: String, port: String, path: String, metricDefinition: MetricDefinition): Set[MetricKey] = {
-
- val url: String = protocol + "://" + host + ":" + port + path
- val mapper = new ObjectMapper() with ScalaObjectMapper
-
- if (metricDefinition.hosts == null || metricDefinition.hosts.isEmpty) {
- val request: HttpRequest = Http(url)
- .param("metricName", metricDefinition.metricName)
- .param("appId", metricDefinition.appId)
- makeHttpGetCall(request, mapper)
- } else {
- val metricKeySet: scala.collection.mutable.Set[MetricKey] = scala.collection.mutable.Set.empty[MetricKey]
-
- for (h <- metricDefinition.hosts) {
- val request: HttpRequest = Http(url)
- .param("metricName", metricDefinition.metricName)
- .param("appId", metricDefinition.appId)
- .param("hostname", h)
-
- val metricKeys = makeHttpGetCall(request, mapper)
- metricKeySet.++=(metricKeys)
- }
- metricKeySet.toSet
- }
- }
-
- private def makeHttpGetCall(request: HttpRequest, mapper: ObjectMapper): Set[MetricKey] = {
-
- try {
- val result: HttpResponse[String] = request.asString
- if (result.code == Response.Status.OK.getStatusCode) {
- LOG.info("Successfully fetched metric keys from metrics collector")
- val metricKeySet: java.util.Set[java.util.Map[String, String]] = mapper.readValue(result.body,
- classOf[java.util.Set[java.util.Map[String, String]]])
- getMetricKeys(metricKeySet)
- } else {
- LOG.error("Got an error when trying to fetch metric key from metrics collector. Code = " + result.code + ", Message = " + result.body)
- }
- } catch {
- case _: java.io.IOException | _: java.net.SocketTimeoutException => LOG.error("Unable to fetch metric keys from Metrics collector for : " + request.toString)
- }
- Set.empty[MetricKey]
- }
-
-
- def getMetricKeys(timelineMetricKeys: java.util.Set[java.util.Map[String, String]]): Set[MetricKey] = {
- val metricKeySet: scala.collection.mutable.Set[MetricKey] = scala.collection.mutable.Set.empty[MetricKey]
- val iter = timelineMetricKeys.iterator()
- while (iter.hasNext) {
- val timelineMetricKey: java.util.Map[String, String] = iter.next()
- val metricKey: MetricKey = MetricKey(
- timelineMetricKey.get("metricName"),
- timelineMetricKey.get("appId"),
- timelineMetricKey.get("instanceId"),
- timelineMetricKey.get("hostname"),
- timelineMetricKey.get("uuid").getBytes())
-
- metricKeySet.add(metricKey)
- }
- metricKeySet.toSet
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ambari/blob/25c18121/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/metadata/InputMetricDefinitionParser.scala
----------------------------------------------------------------------
diff --git a/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/metadata/InputMetricDefinitionParser.scala b/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/metadata/InputMetricDefinitionParser.scala
deleted file mode 100644
index 3c8ea84..0000000
--- a/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/metadata/InputMetricDefinitionParser.scala
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * 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.adservice.metadata
-
-import java.io.File
-
-import org.apache.ambari.metrics.adservice.app.ADServiceScalaModule
-
-import com.fasterxml.jackson.databind.ObjectMapper
-import com.fasterxml.jackson.module.scala.experimental.ScalaObjectMapper
-
-object InputMetricDefinitionParser {
-
- def parseInputDefinitionsFromDirectory(directory: String): List[MetricSourceDefinition] = {
-
- if (directory == null) {
- return List.empty[MetricSourceDefinition]
- }
- val mapper = new ObjectMapper() with ScalaObjectMapper
- mapper.registerModule(new ADServiceScalaModule)
- val metricSourceDefinitions: scala.collection.mutable.MutableList[MetricSourceDefinition] =
- scala.collection.mutable.MutableList.empty[MetricSourceDefinition]
-
- for (file <- getFilesInDirectory(directory)) {
- val source = scala.io.Source.fromFile(file)
- val lines = try source.mkString finally source.close()
- val definition: MetricSourceDefinition = mapper.readValue[MetricSourceDefinition](lines)
- if (definition != null) {
- metricSourceDefinitions.+=(definition)
- }
- }
- metricSourceDefinitions.toList
- }
-
- private def getFilesInDirectory(directory: String): List[File] = {
- val dir = new File(directory)
- if (dir.exists && dir.isDirectory) {
- dir.listFiles.filter(_.isFile).toList
- } else {
- List[File]()
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/25c18121/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/metadata/MetricDefinition.scala
----------------------------------------------------------------------
diff --git a/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/metadata/MetricDefinition.scala b/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/metadata/MetricDefinition.scala
deleted file mode 100644
index c668dfa..0000000
--- a/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/metadata/MetricDefinition.scala
+++ /dev/null
@@ -1,105 +0,0 @@
-/**
- * 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.adservice.metadata
-
-import org.apache.commons.lang3.StringUtils
-
-import com.fasterxml.jackson.annotation.JsonIgnore
-/*
- {
- "metric-name": "mem_free",
- "appId" : "HOST",
- "hosts" : ["h1","h2"],
- "metric-description" : "Free memory on a Host.",
- "troubleshooting-info" : "Sudden drop / hike in free memory on a host.",
- "static-threshold" : 10,
- “app-id” : “HOST”
-}
- */
-
-@SerialVersionUID(1002L)
-class MetricDefinition extends Serializable {
-
- var metricName: String = _
- var appId: String = _
- var hosts: List[String] = List.empty[String]
- var metricDescription: String = ""
- var troubleshootingInfo: String = ""
- var staticThreshold: Double = _
-
- //A Metric definition is valid if we can resolve a metricName and appId (defined or inherited) at runtime)
- private var valid : Boolean = true
-
- def this(metricName: String,
- appId: String,
- hosts: List[String],
- metricDescription: String,
- troubleshootingInfo: String,
- staticThreshold: Double) = {
- this
- this.metricName = metricName
- this.appId = appId
- this.hosts = hosts
- this.metricDescription = metricDescription
- this.troubleshootingInfo = troubleshootingInfo
- this.staticThreshold = staticThreshold
- }
-
- @Override
- override def equals(obj: scala.Any): Boolean = {
-
- if (obj == null || (getClass ne obj.getClass))
- return false
-
- val that = obj.asInstanceOf[MetricDefinition]
-
- if (!(metricName == that.metricName))
- return false
-
- if (StringUtils.isNotEmpty(appId)) {
- appId == that.appId
- }
- else {
- StringUtils.isEmpty(that.appId)
- }
- }
-
- def isValid: Boolean = {
- valid
- }
-
- def makeInvalid() : Unit = {
- valid = false
- }
-}
-
-object MetricDefinition {
-
- def apply(metricName: String,
- appId: String,
- hosts: List[String],
- metricDescription: String,
- troubleshootingInfo: String,
- staticThreshold: Double): MetricDefinition =
- new MetricDefinition(metricName, appId, hosts, metricDescription, troubleshootingInfo, staticThreshold)
-
- def apply(metricName: String, appId: String, hosts: List[String]): MetricDefinition =
- new MetricDefinition(metricName, appId, hosts, null, null, -1)
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ambari/blob/25c18121/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/metadata/MetricDefinitionService.scala
----------------------------------------------------------------------
diff --git a/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/metadata/MetricDefinitionService.scala b/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/metadata/MetricDefinitionService.scala
deleted file mode 100644
index 52ce39e..0000000
--- a/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/metadata/MetricDefinitionService.scala
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * 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.adservice.metadata
-
-import org.apache.ambari.metrics.adservice.service.AbstractADService
-
-trait MetricDefinitionService extends AbstractADService{
-
- /**
- * Given a 'UUID', return the metric key associated with it.
- * @param uuid UUID
- * @return
- */
- def getMetricKeyFromUuid(uuid: Array[Byte]) : MetricKey
-
- /**
- * Return all the definitions being tracked.
- * @return Map of Metric Source Definition name to Metric Source Definition.
- */
- def getDefinitions: List[MetricSourceDefinition]
-
- /**
- * Given a component definition name, return the definition associated with it.
- * @param name component definition name
- * @return
- */
- def getDefinitionByName(name: String) : MetricSourceDefinition
-
- /**
- * Add a new definition.
- * @param definition component definition JSON
- * @return
- */
- def addDefinition(definition: MetricSourceDefinition) : Boolean
-
- /**
- * Update a component definition by name. Only definitions which were added by API can be modified through API.
- * @param definition component definition name
- * @return
- */
- def updateDefinition(definition: MetricSourceDefinition) : Boolean
-
- /**
- * Delete a component definition by name. Only definitions which were added by API can be deleted through API.
- * @param name component definition name
- * @return
- */
- def deleteDefinitionByName(name: String) : Boolean
-
- /**
- * Given an appId, return set of definitions that are tracked for that appId.
- * @param appId component definition appId
- * @return
- */
- def getDefinitionByAppId(appId: String) : List[MetricSourceDefinition]
-
- /**
- * Return the mapping between definition name to set of metric keys.
- * @return Map of Metric Source Definition to set of metric keys associated with it.
- */
- def getMetricKeys: Map[String, Set[MetricKey]]
-
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/25c18121/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/metadata/MetricDefinitionServiceImpl.scala
----------------------------------------------------------------------
diff --git a/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/metadata/MetricDefinitionServiceImpl.scala b/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/metadata/MetricDefinitionServiceImpl.scala
deleted file mode 100644
index b9b4a7c..0000000
--- a/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/metadata/MetricDefinitionServiceImpl.scala
+++ /dev/null
@@ -1,242 +0,0 @@
-/*
- * 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.adservice.metadata
-
-import org.apache.ambari.metrics.adservice.app.AnomalyDetectionAppConfig
-import org.apache.ambari.metrics.adservice.db.AdMetadataStoreAccessor
-import org.slf4j.{Logger, LoggerFactory}
-
-import com.google.inject.{Inject, Singleton}
-
-@Singleton
-class MetricDefinitionServiceImpl extends MetricDefinitionService {
-
- val LOG : Logger = LoggerFactory.getLogger(classOf[MetricDefinitionServiceImpl])
-
- var adMetadataStoreAccessor: AdMetadataStoreAccessor = _
- var configuration: AnomalyDetectionAppConfig = _
- var metricMetadataProvider: MetricMetadataProvider = _
-
- val metricSourceDefinitionMap: scala.collection.mutable.Map[String, MetricSourceDefinition] = scala.collection.mutable.Map()
- val metricDefinitionMetricKeyMap: scala.collection.mutable.Map[MetricSourceDefinition, Set[MetricKey]] = scala.collection.mutable.Map()
- val metricKeys: scala.collection.mutable.Set[MetricKey] = scala.collection.mutable.Set.empty[MetricKey]
-
- @Inject
- def this (anomalyDetectionAppConfig: AnomalyDetectionAppConfig, metadataStoreAccessor: AdMetadataStoreAccessor) = {
- this ()
- adMetadataStoreAccessor = metadataStoreAccessor
- configuration = anomalyDetectionAppConfig
- }
-
- @Override
- def initialize() : Unit = {
- LOG.info("Initializing Metric Definition Service...")
-
- //Initialize Metric Metadata Provider
- metricMetadataProvider = new ADMetadataProvider(configuration.getMetricCollectorConfiguration)
-
- //Load definitions from metadata store
- val definitionsFromStore: List[MetricSourceDefinition] = adMetadataStoreAccessor.getSavedInputDefinitions
- for (definition <- definitionsFromStore) {
- sanitizeMetricSourceDefinition(definition)
- }
-
- //Load definitions from configs
- val definitionsFromConfig: List[MetricSourceDefinition] = getInputDefinitionsFromConfig
- for (definition <- definitionsFromConfig) {
- sanitizeMetricSourceDefinition(definition)
- }
-
- //Union the 2 sources, with DB taking precedence.
- //Save new definition list to DB.
- metricSourceDefinitionMap.++=(combineDefinitionSources(definitionsFromConfig, definitionsFromStore))
-
- //Reach out to AMS Metadata and get Metric Keys. Pass in MSD and get back Set<MK>
- for (definition <- metricSourceDefinitionMap.values) {
- val keys: Set[MetricKey] = metricMetadataProvider.getMetricKeysForDefinitions(definition)
- metricDefinitionMetricKeyMap(definition) = keys
- metricKeys.++=(keys)
- }
-
- LOG.info("Successfully initialized Metric Definition Service.")
- }
-
- def getMetricKeyFromUuid(uuid: Array[Byte]): MetricKey = {
- var key: MetricKey = null
- for (metricKey <- metricKeys) {
- if (metricKey.uuid.sameElements(uuid)) {
- key = metricKey
- }
- }
- key
- }
-
- @Override
- def getDefinitions: List[MetricSourceDefinition] = {
- metricSourceDefinitionMap.values.toList
- }
-
- @Override
- def getDefinitionByName(name: String): MetricSourceDefinition = {
- if (!metricSourceDefinitionMap.contains(name)) {
- LOG.warn("Metric Source Definition with name " + name + " not found")
- null
- } else {
- metricSourceDefinitionMap.apply(name)
- }
- }
-
- @Override
- def addDefinition(definition: MetricSourceDefinition): Boolean = {
- if (metricSourceDefinitionMap.contains(definition.definitionName)) {
- LOG.info("Definition with name " + definition.definitionName + " already present.")
- return false
- }
- definition.definitionSource = MetricSourceDefinitionType.API
-
- val success: Boolean = adMetadataStoreAccessor.saveInputDefinition(definition)
- if (success) {
- metricSourceDefinitionMap += definition.definitionName -> definition
- val keys: Set[MetricKey] = metricMetadataProvider.getMetricKeysForDefinitions(definition)
- metricDefinitionMetricKeyMap(definition) = keys
- metricKeys.++=(keys)
- LOG.info("Successfully created metric source definition : " + definition.definitionName)
- }
- success
- }
-
- @Override
- def updateDefinition(definition: MetricSourceDefinition): Boolean = {
- if (!metricSourceDefinitionMap.contains(definition.definitionName)) {
- LOG.warn("Metric Source Definition with name " + definition.definitionName + " not found")
- return false
- }
-
- if (metricSourceDefinitionMap.apply(definition.definitionName).definitionSource != MetricSourceDefinitionType.API) {
- return false
- }
- definition.definitionSource = MetricSourceDefinitionType.API
-
- val success: Boolean = adMetadataStoreAccessor.saveInputDefinition(definition)
- if (success) {
- metricSourceDefinitionMap += definition.definitionName -> definition
- val keys: Set[MetricKey] = metricMetadataProvider.getMetricKeysForDefinitions(definition)
- metricDefinitionMetricKeyMap(definition) = keys
- metricKeys.++=(keys)
- LOG.info("Successfully updated metric source definition : " + definition.definitionName)
- }
- success
- }
-
- @Override
- def deleteDefinitionByName(name: String): Boolean = {
- if (!metricSourceDefinitionMap.contains(name)) {
- LOG.warn("Metric Source Definition with name " + name + " not found")
- return false
- }
-
- val definition : MetricSourceDefinition = metricSourceDefinitionMap.apply(name)
- if (definition.definitionSource != MetricSourceDefinitionType.API) {
- LOG.warn("Cannot delete metric source definition which was not created through API.")
- return false
- }
-
- val success: Boolean = adMetadataStoreAccessor.removeInputDefinition(name)
- if (success) {
- metricSourceDefinitionMap -= definition.definitionName
- metricKeys.--=(metricDefinitionMetricKeyMap.apply(definition))
- metricDefinitionMetricKeyMap -= definition
- LOG.info("Successfully deleted metric source definition : " + name)
- }
- success
- }
-
- @Override
- def getDefinitionByAppId(appId: String): List[MetricSourceDefinition] = {
-
- val defList : List[MetricSourceDefinition] = metricSourceDefinitionMap.values.toList
- defList.filter(_.appId == appId)
- }
-
- def combineDefinitionSources(configDefinitions: List[MetricSourceDefinition], dbDefinitions: List[MetricSourceDefinition])
- : Map[String, MetricSourceDefinition] = {
-
- var combinedDefinitionMap: scala.collection.mutable.Map[String, MetricSourceDefinition] =
- scala.collection.mutable.Map.empty[String, MetricSourceDefinition]
-
- for (definitionFromDb <- dbDefinitions) {
- combinedDefinitionMap(definitionFromDb.definitionName) = definitionFromDb
- }
-
- for (definition <- configDefinitions) {
- if (!dbDefinitions.contains(definition)) {
- adMetadataStoreAccessor.saveInputDefinition(definition)
- combinedDefinitionMap(definition.definitionName) = definition
- }
- }
- combinedDefinitionMap.toMap
- }
-
- def getInputDefinitionsFromConfig: List[MetricSourceDefinition] = {
- val configDirectory = configuration.getMetricDefinitionServiceConfiguration.getInputDefinitionDirectory
- InputMetricDefinitionParser.parseInputDefinitionsFromDirectory(configDirectory)
- }
-
- def setAdMetadataStoreAccessor (adMetadataStoreAccessor: AdMetadataStoreAccessor) : Unit = {
- this.adMetadataStoreAccessor = adMetadataStoreAccessor
- }
-
- /**
- * Look into the Metric Definitions inside a Metric Source definition, and push down source level appId &
- * hosts to Metric definition if they do not have an override.
- * @param metricSourceDefinition Input Metric Source Definition
- */
- def sanitizeMetricSourceDefinition(metricSourceDefinition: MetricSourceDefinition): Unit = {
- val sourceLevelAppId: String = metricSourceDefinition.appId
- val sourceLevelHostList: List[String] = metricSourceDefinition.hosts
-
- for (metricDef <- metricSourceDefinition.metricDefinitions.toList) {
- if (metricDef.appId == null) {
- if (sourceLevelAppId == null || sourceLevelAppId.isEmpty) {
- metricDef.makeInvalid()
- } else {
- metricDef.appId = sourceLevelAppId
- }
- }
-
- if (metricDef.isValid && (metricDef.hosts == null || metricDef.hosts.isEmpty)) {
- if (sourceLevelHostList != null && sourceLevelHostList.nonEmpty) {
- metricDef.hosts = sourceLevelHostList
- }
- }
- }
- }
-
- /**
- * Return the mapping between definition name to set of metric keys.
- *
- * @return Map of Metric Source Definition to set of metric keys associated with it.
- */
- override def getMetricKeys: Map[String, Set[MetricKey]] = {
- val metricKeyMap: scala.collection.mutable.Map[String, Set[MetricKey]] = scala.collection.mutable.Map()
- for (definition <- metricSourceDefinitionMap.values) {
- metricKeyMap(definition.definitionName) = metricDefinitionMetricKeyMap.apply(definition)
- }
- metricKeyMap.toMap
- }
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/25c18121/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/metadata/MetricKey.scala
----------------------------------------------------------------------
diff --git a/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/metadata/MetricKey.scala b/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/metadata/MetricKey.scala
deleted file mode 100644
index 65c496e..0000000
--- a/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/metadata/MetricKey.scala
+++ /dev/null
@@ -1,53 +0,0 @@
-/**
- * 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.adservice.metadata
-
-import javax.xml.bind.annotation.XmlRootElement
-
-@XmlRootElement
-case class MetricKey (metricName: String, appId: String, instanceId: String, hostname: String, uuid: Array[Byte]) {
-
- @Override
- override def toString: String = {
- "MetricName=" + metricName + ",App=" + appId + ",InstanceId=" + instanceId + ",Host=" + hostname
- }
-
- @Override
- override def equals(obj: scala.Any): Boolean = {
-
- if (obj == null || (getClass ne obj.getClass))
- return false
-
- val that = obj.asInstanceOf[MetricKey]
-
- if (!(metricName == that.metricName))
- return false
-
- if (!(appId == that.appId))
- return false
-
- if (!(instanceId == that.instanceId))
- return false
-
- if (!(hostname == that.hostname))
- return false
-
- true
- }
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/25c18121/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/metadata/MetricMetadataProvider.scala
----------------------------------------------------------------------
diff --git a/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/metadata/MetricMetadataProvider.scala b/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/metadata/MetricMetadataProvider.scala
deleted file mode 100644
index b5ba15e..0000000
--- a/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/metadata/MetricMetadataProvider.scala
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * 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.adservice.metadata
-
-/**
- * Metadata provider for maintaining the metric information in the Metric Definition Service.
- */
-trait MetricMetadataProvider {
-
- /**
- * Return the set of Metric Keys for a given component definition.
- * @param metricSourceDefinition component definition
- * @return
- */
- def getMetricKeysForDefinitions(metricSourceDefinition: MetricSourceDefinition): Set[MetricKey]
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/25c18121/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/metadata/MetricSourceDefinition.scala
----------------------------------------------------------------------
diff --git a/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/metadata/MetricSourceDefinition.scala b/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/metadata/MetricSourceDefinition.scala
deleted file mode 100644
index 47b1499..0000000
--- a/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/metadata/MetricSourceDefinition.scala
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * 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.adservice.metadata
-
-import javax.xml.bind.annotation.XmlRootElement
-
-import org.apache.ambari.metrics.adservice.metadata.MetricSourceDefinitionType.MetricSourceDefinitionType
-import org.apache.ambari.metrics.adservice.model.AnomalyType.AnomalyType
-
-/*
-{
- "definition-name": "host-memory",
- "app-id" : "HOST",
- "hosts" : [“c6401.ambari.apache.org”],
- "metric-definitions" : [
- {
- "metric-name": "mem_free",
- "metric-description" : "Free memory on a Host.",
- "troubleshooting-info" : "Sudden drop / hike in free memory on a host.",
- "static-threshold" : 10,
- “app-id” : “HOST”
-} ],
-
- "related-definition-names" : ["host-cpu", “host-network”],
- “anomaly-detection-subsystems” : [“point-in-time”, “trend”]
-}
-*/
-
-
-@SerialVersionUID(10001L)
-@XmlRootElement
-class MetricSourceDefinition extends Serializable{
-
- var definitionName: String = _
- var appId: String = _
- var definitionSource: MetricSourceDefinitionType = MetricSourceDefinitionType.CONFIG
- var hosts: List[String] = List.empty[String]
- var relatedDefinitions: List[String] = List.empty[String]
- var associatedAnomalySubsystems: List[AnomalyType] = List.empty[AnomalyType]
-
- var metricDefinitions: scala.collection.mutable.MutableList[MetricDefinition] =
- scala.collection.mutable.MutableList.empty[MetricDefinition]
-
- def this(definitionName: String, appId: String, source: MetricSourceDefinitionType) = {
- this
- this.definitionName = definitionName
- this.appId = appId
- this.definitionSource = source
- }
-
- def addMetricDefinition(metricDefinition: MetricDefinition): Unit = {
- if (!metricDefinitions.contains(metricDefinition)) {
- metricDefinitions.+=(metricDefinition)
- }
- }
-
- def removeMetricDefinition(metricDefinition: MetricDefinition): Unit = {
- metricDefinitions = metricDefinitions.filter(_ != metricDefinition)
- }
-
- @Override
- override def equals(obj: scala.Any): Boolean = {
-
- if (obj == null) {
- return false
- }
- val that = obj.asInstanceOf[MetricSourceDefinition]
- definitionName.equals(that.definitionName)
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ambari/blob/25c18121/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/metadata/MetricSourceDefinitionType.scala
----------------------------------------------------------------------
diff --git a/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/metadata/MetricSourceDefinitionType.scala b/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/metadata/MetricSourceDefinitionType.scala
deleted file mode 100644
index 04ff95b..0000000
--- a/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/metadata/MetricSourceDefinitionType.scala
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * 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.adservice.metadata
-
-import javax.xml.bind.annotation.XmlRootElement
-
-@XmlRootElement
-object MetricSourceDefinitionType extends Enumeration{
- type MetricSourceDefinitionType = Value
- val CONFIG,API = Value
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ambari/blob/25c18121/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/model/AnomalyDetectionMethod.scala
----------------------------------------------------------------------
diff --git a/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/model/AnomalyDetectionMethod.scala b/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/model/AnomalyDetectionMethod.scala
deleted file mode 100644
index 81a7023..0000000
--- a/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/model/AnomalyDetectionMethod.scala
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * 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.adservice.model
-
-object AnomalyDetectionMethod extends Enumeration {
- type AnomalyDetectionMethod = Value
- val EMA, TUKEYS, KS, HSDEV, UNKOWN = Value
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/25c18121/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/model/AnomalyType.scala
----------------------------------------------------------------------
diff --git a/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/model/AnomalyType.scala b/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/model/AnomalyType.scala
deleted file mode 100644
index 817180e..0000000
--- a/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/model/AnomalyType.scala
+++ /dev/null
@@ -1,26 +0,0 @@
-/**
- * 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.adservice.model
-
-import javax.xml.bind.annotation.XmlRootElement
-
-@XmlRootElement
-object AnomalyType extends Enumeration {
- type AnomalyType = Value
- val POINT_IN_TIME, TREND, UNKNOWN = Value
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/25c18121/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/model/MetricAnomalyInstance.scala
----------------------------------------------------------------------
diff --git a/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/model/MetricAnomalyInstance.scala b/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/model/MetricAnomalyInstance.scala
deleted file mode 100644
index 248a380..0000000
--- a/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/model/MetricAnomalyInstance.scala
+++ /dev/null
@@ -1,32 +0,0 @@
-/**
- * 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.adservice.model
-
-import javax.xml.bind.annotation.XmlRootElement
-
-import org.apache.ambari.metrics.adservice.metadata.MetricKey
-import org.apache.ambari.metrics.adservice.model.AnomalyType.AnomalyType
-
-@XmlRootElement
-abstract class MetricAnomalyInstance {
-
- val metricKey: MetricKey
- val anomalyType: AnomalyType
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ambari/blob/25c18121/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/model/PointInTimeAnomalyInstance.scala
----------------------------------------------------------------------
diff --git a/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/model/PointInTimeAnomalyInstance.scala b/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/model/PointInTimeAnomalyInstance.scala
deleted file mode 100644
index 470cc2c..0000000
--- a/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/model/PointInTimeAnomalyInstance.scala
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * 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.adservice.model
-
-import java.util.Date
-
-import org.apache.ambari.metrics.adservice.metadata.MetricKey
-import org.apache.ambari.metrics.adservice.model.AnomalyDetectionMethod.AnomalyDetectionMethod
-import org.apache.ambari.metrics.adservice.model.AnomalyType.AnomalyType
-
-class PointInTimeAnomalyInstance(val metricKey: MetricKey,
- val timestamp: Long,
- val metricValue: Double,
- val methodType: AnomalyDetectionMethod,
- val anomalyScore: Double,
- val anomalousSeason: Season,
- val modelParameters: String) extends MetricAnomalyInstance {
-
- override val anomalyType: AnomalyType = AnomalyType.POINT_IN_TIME
-
- private def anomalyToString : String = {
- "Method=" + methodType + ", AnomalyScore=" + anomalyScore + ", Season=" + anomalousSeason.toString +
- ", Model Parameters=" + modelParameters
- }
-
- @Override
- override def toString: String = {
- "Metric : [" + metricKey.toString + ", Metric Value=" + metricValue + " @ Time = " + new Date(timestamp) + "], Anomaly : [" + anomalyToString + "]"
- }
-
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/25c18121/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/model/Range.scala
----------------------------------------------------------------------
diff --git a/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/model/Range.scala b/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/model/Range.scala
deleted file mode 100644
index 4ad35e7..0000000
--- a/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/model/Range.scala
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * 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.adservice.model
-
-/**
- * Class to capture a Range in a Season.
- * For example Monday - Wednesday is a 'Range' in a DAY Season.
- * @param lower lower end
- * @param higher higher end
- */
-case class Range (lower: Int, higher: Int) {
-
- def withinRange(value: Int) : Boolean = {
- if (lower <= higher) {
- (value >= lower) && (value <= higher)
- } else {
- !(value > higher) && (value < lower)
- }
- }
-
- @Override
- override def equals(obj: scala.Any): Boolean = {
- if (obj == null) {
- return false
- }
- val that : Range = obj.asInstanceOf[Range]
- (lower == that.lower) && (higher == that.higher)
- }
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/25c18121/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/model/Season.scala
----------------------------------------------------------------------
diff --git a/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/model/Season.scala b/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/model/Season.scala
deleted file mode 100644
index 84784bc..0000000
--- a/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/model/Season.scala
+++ /dev/null
@@ -1,122 +0,0 @@
-/*
- * 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.adservice.model
-
-import java.time.DayOfWeek
-import java.util.Calendar
-
-import javax.xml.bind.annotation.XmlRootElement
-
-import org.apache.ambari.metrics.adservice.model.SeasonType.SeasonType
-
-import com.fasterxml.jackson.databind.ObjectMapper
-import com.fasterxml.jackson.module.scala.DefaultScalaModule
-import com.fasterxml.jackson.module.scala.experimental.ScalaObjectMapper
-
-/**
- * Class to capture a 'Season' for a metric anomaly.
- * A Season is a combination of DAY Range and HOUR Range.
- * @param DAY Day Range
- * @param HOUR Hour Range
- */
-@XmlRootElement
-case class Season(var DAY: Range, var HOUR: Range) {
-
- def belongsTo(timestamp : Long) : Boolean = {
- val c = Calendar.getInstance
- c.setTimeInMillis(timestamp)
- val dayOfWeek = c.get(Calendar.DAY_OF_WEEK)
- val hourOfDay = c.get(Calendar.HOUR_OF_DAY)
-
- if (DAY.lower != -1 && !DAY.withinRange(dayOfWeek))
- return false
- if (HOUR.lower != -1 && !HOUR.withinRange(hourOfDay))
- return false
- true
- }
-
- @Override
- override def equals(obj: scala.Any): Boolean = {
-
- if (obj == null) {
- return false
- }
-
- val that : Season = obj.asInstanceOf[Season]
- DAY.equals(that.DAY) && HOUR.equals(that.HOUR)
- }
-
- @Override
- override def toString: String = {
-
- var prettyPrintString = ""
-
- var dLower: Int = DAY.lower - 1
- if (dLower == 0) {
- dLower = 7
- }
-
- var dHigher: Int = DAY.higher - 1
- if (dHigher == 0) {
- dHigher = 7
- }
-
- if (DAY != null) {
- prettyPrintString = prettyPrintString.concat("DAY : [" + DayOfWeek.of(dLower) + "," + DayOfWeek.of(dHigher)) + "]"
- }
-
- if (HOUR != null) {
- prettyPrintString = prettyPrintString.concat(" HOUR : [" + HOUR.lower + "," + HOUR.higher) + "]"
- }
- prettyPrintString
- }
-}
-
-object Season {
-
- def apply(DAY: Range, HOUR: Range): Season = new Season(DAY, HOUR)
-
- def apply(range: Range, seasonType: SeasonType): Season = {
- if (seasonType.equals(SeasonType.DAY)) {
- new Season(range, Range(-1,-1))
- } else {
- new Season(Range(-1,-1), range)
- }
- }
-
- val mapper = new ObjectMapper() with ScalaObjectMapper
- mapper.registerModule(DefaultScalaModule)
-
- def getSeasons(timestamp: Long, seasons : List[Season]) : List[Season] = {
- val validSeasons : scala.collection.mutable.MutableList[Season] = scala.collection.mutable.MutableList.empty[Season]
- for ( season <- seasons ) {
- if (season.belongsTo(timestamp)) {
- validSeasons += season
- }
- }
- validSeasons.toList
- }
-
- def toJson(season: Season) : String = {
- mapper.writeValueAsString(season)
- }
-
- def fromJson(seasonString: String) : Season = {
- mapper.readValue[Season](seasonString)
- }
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/25c18121/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/model/SeasonType.scala
----------------------------------------------------------------------
diff --git a/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/model/SeasonType.scala b/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/model/SeasonType.scala
deleted file mode 100644
index b510531..0000000
--- a/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/model/SeasonType.scala
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * 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.adservice.model
-
-object SeasonType extends Enumeration{
-
- type SeasonType = Value
- val DAY,HOUR = Value
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/25c18121/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/model/TimeRange.scala
----------------------------------------------------------------------
diff --git a/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/model/TimeRange.scala b/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/model/TimeRange.scala
deleted file mode 100644
index 0be2564..0000000
--- a/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/model/TimeRange.scala
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * 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.adservice.model
-
-import java.util.Date
-
-/**
- * A special form of a 'Range' class to denote Time range.
- */
-case class TimeRange (startTime: Long, endTime: Long) {
- @Override
- override def toString: String = {
- "StartTime=" + new Date(startTime) + ", EndTime=" + new Date(endTime)
- }
-
- @Override
- override def equals(obj: scala.Any): Boolean = {
- if (obj == null) {
- return false
- }
- val that : TimeRange = obj.asInstanceOf[TimeRange]
- (startTime == that.startTime) && (endTime == that.endTime)
- }
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/25c18121/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/model/TrendAnomalyInstance.scala
----------------------------------------------------------------------
diff --git a/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/model/TrendAnomalyInstance.scala b/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/model/TrendAnomalyInstance.scala
deleted file mode 100644
index d67747c..0000000
--- a/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/model/TrendAnomalyInstance.scala
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * 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.adservice.model
-
-import org.apache.ambari.metrics.adservice.metadata.MetricKey
-import org.apache.ambari.metrics.adservice.model.AnomalyDetectionMethod.AnomalyDetectionMethod
-import org.apache.ambari.metrics.adservice.model.AnomalyType.AnomalyType
-
-case class TrendAnomalyInstance (metricKey: MetricKey,
- anomalousPeriod: TimeRange,
- referencePeriod: TimeRange,
- methodType: AnomalyDetectionMethod,
- anomalyScore: Double,
- seasonInfo: Season,
- modelParameters: String) extends MetricAnomalyInstance {
-
- override val anomalyType: AnomalyType = AnomalyType.POINT_IN_TIME
-
- private def anomalyToString : String = {
- "Method=" + methodType + ", AnomalyScore=" + anomalyScore + ", Season=" + anomalousPeriod.toString +
- ", Model Parameters=" + modelParameters
- }
-
- @Override
- override def toString: String = {
- "Metric : [" + metricKey.toString + ", AnomalousPeriod=" + anomalousPeriod + ", ReferencePeriod=" + referencePeriod +
- "], Anomaly : [" + anomalyToString + "]"
- }
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/25c18121/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/resource/AnomalyResource.scala
----------------------------------------------------------------------
diff --git a/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/resource/AnomalyResource.scala b/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/resource/AnomalyResource.scala
deleted file mode 100644
index db12307..0000000
--- a/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/resource/AnomalyResource.scala
+++ /dev/null
@@ -1,80 +0,0 @@
-/**
- * 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.adservice.resource
-
-import javax.ws.rs.core.MediaType.APPLICATION_JSON
-import javax.ws.rs.core.Response
-import javax.ws.rs.{GET, Path, Produces, QueryParam}
-
-import org.apache.ambari.metrics.adservice.model.{AnomalyType, MetricAnomalyInstance}
-import org.apache.ambari.metrics.adservice.model.AnomalyType.AnomalyType
-import org.apache.ambari.metrics.adservice.service.ADQueryService
-import org.apache.commons.lang.StringUtils
-
-import com.google.inject.Inject
-
-@Path("/anomaly")
-class AnomalyResource {
-
- @Inject
- var aDQueryService: ADQueryService = _
-
- @GET
- @Produces(Array(APPLICATION_JSON))
- def getTopNAnomalies(@QueryParam("type") anType: String,
- @QueryParam("startTime") startTime: Long,
- @QueryParam("endTime") endTime: Long,
- @QueryParam("top") limit: Int): Response = {
-
- val anomalies: List[MetricAnomalyInstance] = aDQueryService.getTopNAnomaliesByType(
- parseAnomalyType(anType),
- parseStartTime(startTime),
- parseEndTime(endTime),
- parseTop(limit))
-
- Response.ok.entity(anomalies).build()
- }
-
- private def parseAnomalyType(anomalyType: String) : AnomalyType = {
- if (StringUtils.isEmpty(anomalyType)) {
- return AnomalyType.POINT_IN_TIME
- }
- AnomalyType.withName(anomalyType.toUpperCase)
- }
-
- private def parseStartTime(startTime: Long) : Long = {
- if (startTime > 0l) {
- return startTime
- }
- System.currentTimeMillis() - 60*60*1000
- }
-
- private def parseEndTime(endTime: Long) : Long = {
- if (endTime > 0l) {
- return endTime
- }
- System.currentTimeMillis()
- }
-
- private def parseTop(limit: Int) : Int = {
- if (limit > 0) {
- return limit
- }
- 5
- }
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/25c18121/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/resource/MetricDefinitionResource.scala
----------------------------------------------------------------------
diff --git a/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/resource/MetricDefinitionResource.scala b/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/resource/MetricDefinitionResource.scala
deleted file mode 100644
index 442bf46..0000000
--- a/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/resource/MetricDefinitionResource.scala
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * 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.adservice.resource
-
-import javax.ws.rs._
-import javax.ws.rs.core.MediaType.APPLICATION_JSON
-import javax.ws.rs.core.Response
-
-import org.apache.ambari.metrics.adservice.metadata.{MetricDefinitionService, MetricKey, MetricSourceDefinition}
-import org.apache.commons.lang.StringUtils
-
-import com.google.inject.Inject
-
-@Path("/metric-definition")
-class MetricDefinitionResource {
-
- @Inject
- var metricDefinitionService: MetricDefinitionService = _
-
- @GET
- @Produces(Array(APPLICATION_JSON))
- @Path("/{name}")
- def defaultGet(@PathParam("name") definitionName: String): Response = {
-
- if (StringUtils.isEmpty(definitionName)) {
- Response.ok.entity(Map("message" -> "Definition name cannot be empty. Use query parameter 'name'")).build()
- }
- val metricSourceDefinition = metricDefinitionService.getDefinitionByName(definitionName)
- if (metricSourceDefinition != null) {
- Response.ok.entity(metricSourceDefinition).build()
- } else {
- Response.ok.entity(Map("message" -> "Definition not found")).build()
- }
- }
-
- @GET
- @Produces(Array(APPLICATION_JSON))
- def getAllMetricDefinitions: Response = {
- val metricSourceDefinitionMap: List[MetricSourceDefinition] = metricDefinitionService.getDefinitions
- Response.ok.entity(metricSourceDefinitionMap).build()
- }
-
- @GET
- @Path("/keys")
- @Produces(Array(APPLICATION_JSON))
- def getMetricKeys: Response = {
- val metricKeyMap: Map[String, Set[MetricKey]] = metricDefinitionService.getMetricKeys
- Response.ok.entity(metricKeyMap).build()
- }
-
- @POST
- @Produces(Array(APPLICATION_JSON))
- def defaultPost(definition: MetricSourceDefinition) : Response = {
- if (definition == null) {
- Response.ok.entity(Map("message" -> "Definition content cannot be empty.")).build()
- }
- val success : Boolean = metricDefinitionService.addDefinition(definition)
- if (success) {
- Response.ok.entity(Map("message" -> "Definition saved")).build()
- } else {
- Response.ok.entity(Map("message" -> "Definition could not be saved")).build()
- }
- }
-
- @PUT
- @Produces(Array(APPLICATION_JSON))
- def defaultPut(definition: MetricSourceDefinition) : Response = {
- if (definition == null) {
- Response.ok.entity(Map("message" -> "Definition content cannot be empty.")).build()
- }
- val success : Boolean = metricDefinitionService.updateDefinition(definition)
- if (success) {
- Response.ok.entity(Map("message" -> "Definition updated")).build()
- } else {
- Response.ok.entity(Map("message" -> "Definition could not be updated")).build()
- }
- }
-
- @DELETE
- @Produces(Array(APPLICATION_JSON))
- @Path("/{name}")
- def defaultDelete(@PathParam("name") definitionName: String): Response = {
-
- if (StringUtils.isEmpty(definitionName)) {
- Response.ok.entity(Map("message" -> "Definition name cannot be empty. Use query parameter 'name'")).build()
- }
- val success: Boolean = metricDefinitionService.deleteDefinitionByName(definitionName)
- if (success) {
- Response.ok.entity(Map("message" -> "Definition deleted")).build()
- } else {
- Response.ok.entity(Map("message" -> "Definition could not be deleted")).build()
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/25c18121/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/resource/RootResource.scala
----------------------------------------------------------------------
diff --git a/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/resource/RootResource.scala b/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/resource/RootResource.scala
deleted file mode 100644
index fd55b64..0000000
--- a/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/resource/RootResource.scala
+++ /dev/null
@@ -1,38 +0,0 @@
-/**
- * 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.adservice.resource
-
-import java.time.LocalDateTime
-
-import javax.ws.rs.core.MediaType.APPLICATION_JSON
-import javax.ws.rs.core.Response
-import javax.ws.rs.{GET, Path, Produces}
-
-import org.joda.time.DateTime
-
-@Path("/")
-class RootResource {
-
- @Produces(Array(APPLICATION_JSON))
- @GET
- def default: Response = {
- val dtf = java.time.format.DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm")
- Response.ok.entity(Map("name" -> "anomaly-detection-service", "today" -> LocalDateTime.now)).build()
- }
-
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/25c18121/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/resource/SubsystemResource.scala
----------------------------------------------------------------------
diff --git a/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/resource/SubsystemResource.scala b/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/resource/SubsystemResource.scala
deleted file mode 100644
index e7d7c9a..0000000
--- a/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/resource/SubsystemResource.scala
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * 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.adservice.resource
-
-class SubsystemResource {
-
- /*
- GET / UPDATE - parameters (which subsystem, parameters)
- POST - Update sensitivity of a subsystem (which subsystem, increase or decrease, factor)
- */
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/25c18121/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/service/ADQueryService.scala
----------------------------------------------------------------------
diff --git a/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/service/ADQueryService.scala b/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/service/ADQueryService.scala
deleted file mode 100644
index 2cfa30f..0000000
--- a/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/service/ADQueryService.scala
+++ /dev/null
@@ -1,34 +0,0 @@
-/**
- * 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.adservice.service
-
-import org.apache.ambari.metrics.adservice.model.AnomalyType.AnomalyType
-import org.apache.ambari.metrics.adservice.model.MetricAnomalyInstance
-
-trait ADQueryService extends AbstractADService{
-
- /**
- * API to return list of single metric anomalies satisfying a set of conditions from the anomaly store.
- * @param anomalyType Type of the anomaly (Point In Time / Trend)
- * @param startTime Start of time range
- * @param endTime End of time range
- * @param limit Maximim number of anomaly metrics that need to be returned based on anomaly score.
- * @return
- */
- def getTopNAnomaliesByType(anomalyType: AnomalyType, startTime: Long, endTime: Long, limit: Int): List[MetricAnomalyInstance]
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/25c18121/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/service/ADQueryServiceImpl.scala
----------------------------------------------------------------------
diff --git a/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/service/ADQueryServiceImpl.scala b/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/service/ADQueryServiceImpl.scala
deleted file mode 100644
index 3b49208..0000000
--- a/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/service/ADQueryServiceImpl.scala
+++ /dev/null
@@ -1,56 +0,0 @@
-/**
- * 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.adservice.service
-import org.apache.ambari.metrics.adservice.db.AdAnomalyStoreAccessor
-import org.apache.ambari.metrics.adservice.model.AnomalyType.AnomalyType
-import org.apache.ambari.metrics.adservice.model.MetricAnomalyInstance
-import org.slf4j.{Logger, LoggerFactory}
-
-import com.google.inject.{Inject, Singleton}
-
-@Singleton
-class ADQueryServiceImpl extends ADQueryService {
-
- val LOG : Logger = LoggerFactory.getLogger(classOf[ADQueryServiceImpl])
-
- @Inject
- var adAnomalyStoreAccessor: AdAnomalyStoreAccessor = _
-
- /**
- * Initialize Service
- */
- override def initialize(): Unit = {
- LOG.info("Initializing AD Query Service...")
- adAnomalyStoreAccessor.initialize()
- LOG.info("Successfully initialized AD Query Service.")
- }
-
- /**
- * Implementation to return list of anomalies satisfying a set of conditions from the anomaly store.
- *
- * @param anomalyType Type of the anomaly (Point In Time / Trend)
- * @param startTime Start of time range
- * @param endTime End of time range
- * @param limit Maximim number of anomaly metrics that need to be returned based on anomaly score.
- * @return
- */
- override def getTopNAnomaliesByType(anomalyType: AnomalyType, startTime: Long, endTime: Long, limit: Int): List[MetricAnomalyInstance] = {
- val anomalies = adAnomalyStoreAccessor.getMetricAnomalies(anomalyType, startTime, endTime, limit)
- anomalies
- }
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/25c18121/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/service/AbstractADService.scala
----------------------------------------------------------------------
diff --git a/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/service/AbstractADService.scala b/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/service/AbstractADService.scala
deleted file mode 100644
index 56bb999..0000000
--- a/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/service/AbstractADService.scala
+++ /dev/null
@@ -1,44 +0,0 @@
-/**
- * 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.
- *//**
- * 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.adservice.service
-
-trait AbstractADService {
-
- /**
- * Initialize Service
- */
- def initialize(): Unit
-
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/25c18121/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/spark/prototype/MetricAnomalyDetector.scala
----------------------------------------------------------------------
diff --git a/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/spark/prototype/MetricAnomalyDetector.scala b/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/spark/prototype/MetricAnomalyDetector.scala
deleted file mode 100644
index 90c564e..0000000
--- a/ambari-metrics/ambari-metrics-anomaly-detection-service/src/main/scala/org/apache/ambari/metrics/adservice/spark/prototype/MetricAnomalyDetector.scala
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
- * 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.adservice.spark.prototype
-
-object MetricAnomalyDetector {
-
- /*
- Load current EMA model
- Filter step - Check if anomaly
- Collect / Write to AMS / Print.
- */
-
-// var brokers = "avijayan-ams-1.openstacklocal:2181,avijayan-ams-2.openstacklocal:2181,avijayan-ams-3.openstacklocal:2181"
-// var groupId = "ambari-metrics-group"
-// var topicName = "ambari-metrics-topic"
-// var numThreads = 1
-// val anomalyDetectionModels: Array[AnomalyDetectionTechnique] = Array[AnomalyDetectionTechnique]()
-//
-// def readProperties(propertiesFile: String): Properties = try {
-// val properties = new Properties
-// var inputStream = ClassLoader.getSystemResourceAsStream(propertiesFile)
-// if (inputStream == null) inputStream = new FileInputStream(propertiesFile)
-// properties.load(inputStream)
-// properties
-// } catch {
-// case ioEx: IOException =>
-// null
-// }
-//
-// def main(args: Array[String]): Unit = {
-//
-// @transient
-// lazy val log = org.apache.log4j.LogManager.getLogger("MetricAnomalyDetectorLogger")
-//
-// if (args.length < 1) {
-// System.err.println("Usage: MetricSparkConsumer <input-config-file>")
-// System.exit(1)
-// }
-//
-// //Read properties
-// val properties = readProperties(propertiesFile = args(0))
-//
-// //Load EMA parameters - w, n
-// val emaW = properties.getProperty("emaW").toDouble
-// val emaN = properties.getProperty("emaN").toDouble
-//
-// //collector info
-// val collectorHost: String = properties.getProperty("collectorHost")
-// val collectorPort: String = properties.getProperty("collectorPort")
-// val collectorProtocol: String = properties.getProperty("collectorProtocol")
-// val anomalyMetricPublisher = new MetricsCollectorInterface(collectorHost, collectorProtocol, collectorPort)
-//
-// //Instantiate Kafka stream reader
-// val sparkConf = new SparkConf().setAppName("AmbariMetricsAnomalyDetector")
-// val streamingContext = new StreamingContext(sparkConf, Duration(10000))
-//
-// val topicsSet = topicName.toSet
-// val kafkaParams = Map[String, String]("metadata.broker.list" -> brokers)
-//// val stream = KafkaUtils.createDirectStream()
-//
-// val kafkaStream = KafkaUtils.createStream(streamingContext, zkQuorum, groupId, Map(topicName -> numThreads), StorageLevel.MEMORY_AND_DISK_SER_2)
-// kafkaStream.print()
-//
-// var timelineMetricsStream = kafkaStream.map( message => {
-// val mapper = new ObjectMapper
-// val metrics = mapper.readValue(message._2, classOf[TimelineMetrics])
-// metrics
-// })
-// timelineMetricsStream.print()
-//
-// var appMetricStream = timelineMetricsStream.map( timelineMetrics => {
-// (timelineMetrics.getMetrics.get(0).getAppId, timelineMetrics)
-// })
-// appMetricStream.print()
-//
-// var filteredAppMetricStream = appMetricStream.filter( appMetricTuple => {
-// appIds.contains(appMetricTuple._1)
-// } )
-// filteredAppMetricStream.print()
-//
-// filteredAppMetricStream.foreachRDD( rdd => {
-// rdd.foreach( appMetricTuple => {
-// val timelineMetrics = appMetricTuple._2
-// logger.info("Received Metric (1): " + timelineMetrics.getMetrics.get(0).getMetricName)
-// log.info("Received Metric (2): " + timelineMetrics.getMetrics.get(0).getMetricName)
-// for (timelineMetric <- timelineMetrics.getMetrics) {
-// var anomalies = emaModel.test(timelineMetric)
-// anomalyMetricPublisher.publish(anomalies)
-// }
-// })
-// })
-//
-// streamingContext.start()
-// streamingContext.awaitTermination()
-// }
- }