Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Admin Service #1922

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions repose-aggregator/commons/commons-utilities/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ dependencies {
testCompile "org.apache.logging.log4j:log4j-core"
testCompile group: 'org.apache.logging.log4j', name: 'log4j-core', classifier: 'tests'
testCompile "org.springframework:spring-test"
testCompile "org.springframework:spring-web"
testCompile "org.slf4j:jcl-over-slf4j"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class HttpServletRequestWrapperTest extends FunSpec with BeforeAndAfterEach with
val mockRequest = new MockHttpServletRequest
mockRequest.setRequestURI("/foo/bar")
queryParamMap foreach { case (parameterKey, parameterValues) =>
mockRequest.addParameter(parameterKey, parameterValues)
mockRequest.addParameter(parameterKey, parameterValues: _*)
mockRequest.setQueryString(Option(mockRequest.getQueryString).map(_ + "&").getOrElse("") + parameterValues.map(value => parameterKey + "=" + value).mkString("&"))
}
headerMap foreach { case (headerName, headerValues) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ dependencies {
testCompile "org.scalatest:scalatest_$scalaMajDotMin"
testCompile "org.mockito:mockito-all"
testCompile "org.springframework:spring-test"
testCompile "org.springframework:spring-web"
testCompile "org.slf4j:jcl-over-slf4j"
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ dependencies {
testCompile "org.scalatest:scalatest_$scalaMajDotMin"
testCompile "xerces:xerces-xsd11"
testCompile "org.springframework:spring-test"
testCompile "org.springframework:spring-web"
testCompile "org.slf4j:jcl-over-slf4j"
testCompile "org.hamcrest:hamcrest-all"
testCompile "org.mockito:mockito-all"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ dependencies {
testCompile "org.scalatest:scalatest_$scalaMajDotMin"
testCompile "org.mockito:mockito-all"
testCompile "org.springframework:spring-test"
testCompile "org.springframework:spring-web"
testCompile "commons-io:commons-io"
testCompile "org.slf4j:jcl-over-slf4j"
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ dependencies {
testCompile "org.scalatest:scalatest_$scalaMajDotMin"
testCompile "org.mockito:mockito-all"
testCompile "org.springframework:spring-test"
testCompile "org.springframework:spring-web"
testCompile "org.slf4j:jcl-over-slf4j"
testCompile "javax.ws.rs:javax.ws.rs-api"
testCompile "org.apache.logging.log4j:log4j-core"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ dependencies {
testCompile "org.scalatest:scalatest_$scalaMajDotMin"
testCompile "org.mockito:mockito-all"
testCompile "org.springframework:spring-test"
testCompile "org.springframework:spring-web"
testCompile "org.slf4j:jcl-over-slf4j"
testCompile "xerces:xerces-xsd11"
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ dependencies {
testCompile "org.scalatest:scalatest_$scalaMajDotMin"
testCompile "org.mockito:mockito-all"
testCompile "org.springframework:spring-test"
testCompile "org.springframework:spring-web"
testCompile "org.slf4j:jcl-over-slf4j"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ dependencies {
testCompile "org.mockito:mockito-all"
testCompile "org.scalatest:scalatest_$scalaMajDotMin"
testCompile "org.springframework:spring-test"
testCompile "org.springframework:spring-web"
testCompile "org.slf4j:jcl-over-slf4j"
testCompile "org.xmlunit:xmlunit-matchers"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* _=_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_=
* Repose
* _-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
* Copyright (C) 2010 - 2015 Rackspace US, Inc.
* _-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
* Licensed 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.openrepose.core.services.admin;

/**
* Created by adrian on 9/12/17.
*/
public interface AdminService {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.1" encoding="UTF-8"?>
<!--
_=_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_=
Repose
_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
Copyright (C) 2010 - 2015 Rackspace US, Inc.
_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
Licensed 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.
=_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_=_
-->

<xs:schema elementFormDefault="qualified"
targetNamespace="http://docs.openrepose.org/repose/admin-service/v1.0"
xmlns="http://docs.openrepose.org/repose/admin-service/v1.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:html="http://www.w3.org/1999/xhtml">

<xs:element name="admin-service" type="AdminServiceConfigType"/>

<xs:complexType name="AdminServiceConfigType">
<xs:attribute name="port" type="PositiveIntType"/>
</xs:complexType>

<xs:simpleType name="PositiveIntType">
<xs:restriction base="xs:int">
<xs:minInclusive value="1"/>
</xs:restriction>
</xs:simpleType>
</xs:schema>
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
_=_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_=
Repose
_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
Copyright (C) 2010 - 2015 Rackspace US, Inc.
_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
Licensed 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.
=_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_=_
-->


<bindings xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/jaxb"
version="2.0"
xsi:schemaLocation="http://java.sun.com/xml/ns/jaxb http://java.sun.com/xml/ns/jaxb/bindingschema_2_0.xsd"
schemaLocation="admin-service.xsd">

<schemaBindings>
<package name="org.openrepose.core.services.admin.config"/>
</schemaBindings>
</bindings>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.1" encoding="UTF-8"?>

<admin-service xmlns="http://docs.openrepose.org/repose/admin-service/v1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
port="8888"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
configurations {
compile.exclude module: "spring-boot-starter-tomcat"
}

dependencies {
compile project(":repose-aggregator:components:services:admin-service:admin-service-api")
compile project(":repose-aggregator:components:services:health-check-service:health-check-service-api")
compile project(":repose-aggregator:components:services:akka-http-client-service:akka-http-client-service-api")
compile project(":repose-aggregator:commons:commons-utilities")
compile project(":repose-aggregator:core:repose-core-api")
compile "org.scala-lang:scala-library"
compile "org.slf4j:slf4j-api"
compile "com.typesafe.scala-logging:scala-logging-slf4j_$scalaMajDotMin"
compile "org.springframework:spring-context"
compile "org.springframework.boot:spring-boot-starter-web"
compile "org.springframework.boot:spring-boot-starter-jetty"
compile "org.springframework.boot:spring-boot-starter-jersey"

compileOnly "javax.inject:javax.inject"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* _=_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_=
* Repose
* _-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
* Copyright (C) 2010 - 2015 Rackspace US, Inc.
* _-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
* Licensed 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.openrepose.adminservice;

import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jmx.JmxAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

/**
* Created by adrian on 9/12/17.
*/
@SpringBootApplication(exclude = JmxAutoConfiguration.class)
@Configuration
@ComponentScan
public class AdminServiceConfiguration {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* _=_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_=
* Repose
* _-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
* Copyright (C) 2010 - 2015 Rackspace US, Inc.
* _-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
* Licensed 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.openrepose.adminservice;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import java.util.Map;

public interface AdminWebInterface {
@Produces( {MediaType.APPLICATION_JSON} )
@GET
@Path("/health")
Map<String, Object> healthCheck();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* _=_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_=
* Repose
* _-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
* Copyright (C) 2010 - 2015 Rackspace US, Inc.
* _-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
* Licensed 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.openrepose.adminservice

import javax.inject.{Inject, Named}
import javax.ws.rs.Path
import org.openrepose.adminservice.AdminJaxRs.MyPath

import scala.annotation.meta.beanGetter
import scala.beans.BeanProperty

@Named
@Path("/")
class AdminJaxRs @Inject()(@MyPath("/node") @BeanProperty val nodeJaxRs: NodeJaxRs, @MyPath("/cluster") @BeanProperty val clusterJaxRs: ClusterJaxRs) {
}

object AdminJaxRs {
type MyPath = Path @beanGetter
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* _=_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_=
* Repose
* _-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
* Copyright (C) 2010 - 2015 Rackspace US, Inc.
* _-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
* Licensed 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.openrepose.adminservice

import java.util

import com.fasterxml.jackson.databind.ObjectMapper
import javax.annotation.{PostConstruct, PreDestroy}
import javax.inject.{Inject, Named}
import org.openrepose.commons.config.manager.UpdateListener
import org.openrepose.core.services.config.ConfigurationService
import org.openrepose.core.services.serviceclient.akka.{AkkaServiceClient, AkkaServiceClientFactory}
import org.openrepose.core.systemmodel.config.SystemModel
import org.springframework.beans.factory.annotation.Value

import scala.collection.JavaConverters._
import scala.io.Source

@Named
class ClusterJaxRs @Inject() (configurationService: ConfigurationService, akkaServiceClientFactory: AkkaServiceClientFactory, @Value("${server.port}") port: String) extends AdminWebInterface {
private var nodes: Map[String, String] = _
private var akkaServiceClient: AkkaServiceClient = _

@PostConstruct
def init(): Unit = {
akkaServiceClient = akkaServiceClientFactory.newAkkaServiceClient()

configurationService.subscribeTo(
"system-model.cfg.xml",
SystemModelConfigurationListener,
classOf[SystemModel]
)
}

@PreDestroy
def destroy(): Unit = {
configurationService.unsubscribeFrom("system-model.cfg.xml", SystemModelConfigurationListener)

akkaServiceClient.destroy()
}

override def healthCheck(): util.Map[String, Object] = {
val mapper = new ObjectMapper()

val responses = nodes.mapValues { host => akkaServiceClient.get(s"admin-$host", s"http://$host:$port/node/health", Map[String, String]().asJava) }

responses.mapValues({ response =>
response.getStatus match {
case 200 => mapper.readValue(Source.fromInputStream(response.getData).mkString, classOf[util.Map[String, String]])
case statusCode => Map("unknown_error" -> s"$statusCode").asJava
}
}).asJava.asInstanceOf[util.Map[String, Object]]
// Map("greeting" -> "Hello from the cluster").asJava
}

private object SystemModelConfigurationListener extends UpdateListener[SystemModel] {
private var initialized = false

override def configurationUpdated(configurationObject: SystemModel): Unit = {

initialized = true

nodes = configurationObject.getReposeCluster.asScala.flatMap({ cluster => cluster.getNodes.getNode.asScala}).map(node => (node.getId -> node.getHostname)).toMap
}

override def isInitialized: Boolean = initialized
}
}
Loading