-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AMBARI-22192. Setup an application server for hosting the AD System M…
…anager.
- Loading branch information
Showing
18 changed files
with
855 additions
and
210 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
12 changes: 12 additions & 0 deletions
12
ambari-metrics-anomaly-detection-service/src/main/resources/config.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
server: | ||
applicationConnectors: | ||
- type: http | ||
port: 9999 | ||
adminConnectors: | ||
- type: http | ||
port: 9990 | ||
requestLog: | ||
type: external | ||
|
||
logging: | ||
type: external |
69 changes: 69 additions & 0 deletions
69
...-service/src/main/scala/org/apache/ambari/metrics/adservice/app/AnomalyDetectionApp.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/** | ||
* 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.app | ||
|
||
import javax.ws.rs.Path | ||
import javax.ws.rs.container.{ContainerRequestFilter, ContainerResponseFilter} | ||
|
||
import org.apache.ambari.metrics.adservice.app.GuiceInjector.{withInjector, wrap} | ||
import org.glassfish.jersey.filter.LoggingFilter | ||
|
||
import com.codahale.metrics.health.HealthCheck | ||
import com.fasterxml.jackson.databind.{ObjectMapper, SerializationFeature} | ||
import com.fasterxml.jackson.datatype.joda.JodaModule | ||
import com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider | ||
import com.fasterxml.jackson.module.scala.DefaultScalaModule | ||
import io.dropwizard.Application | ||
import io.dropwizard.setup.Environment | ||
|
||
class AnomalyDetectionApp extends Application[AnomalyDetectionAppConfig] { | ||
override def getName = "anomaly-detection-service" | ||
|
||
override def run(t: AnomalyDetectionAppConfig, env: Environment): Unit = { | ||
configure(t, env) | ||
} | ||
|
||
def configure(config: AnomalyDetectionAppConfig, env: Environment) { | ||
withInjector(new AnomalyDetectionAppModule(config, env)) { injector => | ||
injector.instancesWithAnnotation(classOf[Path]).foreach { r => env.jersey().register(r) } | ||
injector.instancesOfType(classOf[HealthCheck]).foreach { h => env.healthChecks.register(h.getClass.getName, h) } | ||
injector.instancesOfType(classOf[ContainerRequestFilter]).foreach { f => env.jersey().register(f) } | ||
injector.instancesOfType(classOf[ContainerResponseFilter]).foreach { f => env.jersey().register(f) } | ||
} | ||
env.jersey.register(jacksonJaxbJsonProvider) | ||
env.jersey.register(new LoggingFilter) | ||
} | ||
|
||
private def jacksonJaxbJsonProvider: JacksonJaxbJsonProvider = { | ||
val provider = new JacksonJaxbJsonProvider() | ||
val objectMapper = new ObjectMapper() | ||
objectMapper.registerModule(DefaultScalaModule) | ||
objectMapper.registerModule(new JodaModule) | ||
objectMapper.configure(SerializationFeature.WRAP_ROOT_VALUE, false) | ||
objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false) | ||
objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false) | ||
objectMapper.configure(SerializationFeature.WRITE_EMPTY_JSON_ARRAYS, true) | ||
provider.setMapper(objectMapper) | ||
provider | ||
} | ||
} | ||
|
||
|
||
object AnomalyDetectionApp { | ||
def main(args: Array[String]): Unit = new AnomalyDetectionApp().run(args: _*) | ||
} |
24 changes: 24 additions & 0 deletions
24
...ce/src/main/scala/org/apache/ambari/metrics/adservice/app/AnomalyDetectionAppConfig.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package org.apache.ambari.metrics.adservice.app | ||
|
||
import io.dropwizard.Configuration | ||
|
||
/** | ||
* 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. | ||
*/ | ||
class AnomalyDetectionAppConfig extends Configuration { | ||
|
||
} |
38 changes: 38 additions & 0 deletions
38
...ce/src/main/scala/org/apache/ambari/metrics/adservice/app/AnomalyDetectionAppModule.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/** | ||
* 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.app | ||
|
||
import org.apache.ambari.metrics.adservice.resource.{AnomalyResource, RootResource} | ||
import org.apache.ambari.metrics.adservice.service.{ADQueryService, ADQueryServiceImpl} | ||
|
||
import com.codahale.metrics.health.HealthCheck | ||
import com.google.inject.AbstractModule | ||
import com.google.inject.multibindings.Multibinder | ||
import io.dropwizard.setup.Environment | ||
|
||
class AnomalyDetectionAppModule(config: AnomalyDetectionAppConfig, env: Environment) extends AbstractModule { | ||
override def configure() { | ||
bind(classOf[AnomalyDetectionAppConfig]).toInstance(config) | ||
bind(classOf[Environment]).toInstance(env) | ||
val healthCheckBinder = Multibinder.newSetBinder(binder(), classOf[HealthCheck]) | ||
healthCheckBinder.addBinding().to(classOf[DefaultHealthCheck]) | ||
bind(classOf[AnomalyResource]) | ||
bind(classOf[RootResource]) | ||
bind(classOf[ADQueryService]).to(classOf[ADQueryServiceImpl]) | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...n-service/src/main/scala/org/apache/ambari/metrics/adservice/app/DefaultHealthCheck.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/** | ||
* 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.app | ||
|
||
import com.codahale.metrics.health.HealthCheck | ||
import com.codahale.metrics.health.HealthCheck.Result | ||
|
||
class DefaultHealthCheck extends HealthCheck { | ||
override def check(): Result = Result.healthy() | ||
} |
56 changes: 56 additions & 0 deletions
56
...ection-service/src/main/scala/org/apache/ambari/metrics/adservice/app/GuiceInjector.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.adservice.app | ||
|
||
import java.lang.annotation.Annotation | ||
|
||
import com.google.inject.{Guice, Injector, Module, TypeLiteral} | ||
|
||
import scala.collection.JavaConversions._ | ||
import scala.language.implicitConversions | ||
import scala.reflect._ | ||
|
||
object GuiceInjector { | ||
|
||
def withInjector(modules: Module*)(fn: (Injector) => Unit) = { | ||
val injector = Guice.createInjector(modules.toList: _*) | ||
fn(injector) | ||
} | ||
|
||
implicit def wrap(injector: Injector): InjectorWrapper = new InjectorWrapper(injector) | ||
} | ||
|
||
class InjectorWrapper(injector: Injector) { | ||
def instancesWithAnnotation[T <: Annotation](annotationClass: Class[T]): List[AnyRef] = { | ||
injector.getAllBindings.filter { case (k, v) => | ||
!k.getTypeLiteral.getRawType.getAnnotationsByType[T](annotationClass).isEmpty | ||
}.map { case (k, v) => injector.getInstance(k).asInstanceOf[AnyRef] }.toList | ||
} | ||
|
||
def instancesOfType[T: ClassTag](typeClass: Class[T]): List[T] = { | ||
injector.findBindingsByType(TypeLiteral.get(classTag[T].runtimeClass)).map { b => | ||
injector.getInstance(b.getKey).asInstanceOf[T] | ||
}.toList | ||
} | ||
|
||
def dumpBindings(): Unit = { | ||
injector.getBindings.keySet() foreach { k => | ||
println(s"bind key = ${k.toString}") | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
...service/src/main/scala/org/apache/ambari/metrics/adservice/resource/AnomalyResource.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/** | ||
* 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.{GET, Path, Produces} | ||
import javax.ws.rs.core.Response | ||
import javax.ws.rs.core.MediaType.APPLICATION_JSON | ||
|
||
import org.joda.time.DateTime | ||
|
||
@Path("/topNAnomalies") | ||
class AnomalyResource { | ||
|
||
@GET | ||
@Produces(Array(APPLICATION_JSON)) | ||
def default: Response = { | ||
Response.ok.entity(Map("message" -> "Anomaly Detection Service!", | ||
"today" -> DateTime.now.toString("MM-dd-yyyy hh:mm"))).build() | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
...on-service/src/main/scala/org/apache/ambari/metrics/adservice/resource/RootResource.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/** | ||
* 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.{GET, Path, Produces} | ||
import javax.ws.rs.core.Response | ||
import javax.ws.rs.core.MediaType.APPLICATION_JSON | ||
|
||
import org.joda.time.DateTime | ||
|
||
@Path("/") | ||
class RootResource { | ||
|
||
@Produces(Array(APPLICATION_JSON)) | ||
@GET | ||
def default: Response = { | ||
Response.ok.entity(Map("name" -> "anomaly-detection-service", "today" -> DateTime.now.toString("MM-dd-yyyy hh:mm"))).build() | ||
} | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
...n-service/src/main/scala/org/apache/ambari/metrics/adservice/service/ADQueryService.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/** | ||
* 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 ADQueryService { | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
...rvice/src/main/scala/org/apache/ambari/metrics/adservice/service/ADQueryServiceImpl.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/** | ||
* 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 | ||
|
||
class ADQueryServiceImpl extends ADQueryService { | ||
|
||
} |
Oops, something went wrong.