Repository: knox Updated Branches: refs/heads/master 3ef4a08d5 -> d3d269f93
KNOX-398 - initial contribution for the Knox management API Project: http://git-wip-us.apache.org/repos/asf/knox/repo Commit: http://git-wip-us.apache.org/repos/asf/knox/commit/d3d269f9 Tree: http://git-wip-us.apache.org/repos/asf/knox/tree/d3d269f9 Diff: http://git-wip-us.apache.org/repos/asf/knox/diff/d3d269f9 Branch: refs/heads/master Commit: d3d269f939f068dfd4228ab54cbd3b66986a0841 Parents: 3ef4a08 Author: Larry McCay <[email protected]> Authored: Fri Jun 20 18:34:40 2014 -0400 Committer: Larry McCay <[email protected]> Committed: Fri Jun 20 18:34:40 2014 -0400 ---------------------------------------------------------------------- .../JerseyServiceDeploymentContributorBase.java | 2 +- gateway-release/pom.xml | 4 + .../apache/hadoop/gateway/GatewayServer.java | 14 +++- .../services/DefaultGatewayServices.java | 10 +++ .../services/DefaultServerInfoService.java | 69 ++++++++++++++++ gateway-service-admin/pom.xml | 59 +++++++++++++ .../gateway/service/admin/VersionResource.java | 87 ++++++++++++++++++++ .../AdminServiceDeploymentContributor.java | 59 +++++++++++++ ....gateway.deploy.ServiceDeploymentContributor | 19 +++++ .../gateway/services/GatewayServices.java | 1 + .../gateway/services/ServerInfoService.java | 34 ++++++++ pom.xml | 6 ++ 12 files changed, 360 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/knox/blob/d3d269f9/gateway-provider-jersey/src/main/java/org/apache/hadoop/gateway/jersey/JerseyServiceDeploymentContributorBase.java ---------------------------------------------------------------------- diff --git a/gateway-provider-jersey/src/main/java/org/apache/hadoop/gateway/jersey/JerseyServiceDeploymentContributorBase.java b/gateway-provider-jersey/src/main/java/org/apache/hadoop/gateway/jersey/JerseyServiceDeploymentContributorBase.java index dc8a340..85bd17a 100644 --- a/gateway-provider-jersey/src/main/java/org/apache/hadoop/gateway/jersey/JerseyServiceDeploymentContributorBase.java +++ b/gateway-provider-jersey/src/main/java/org/apache/hadoop/gateway/jersey/JerseyServiceDeploymentContributorBase.java @@ -30,7 +30,7 @@ import java.util.List; public abstract class JerseyServiceDeploymentContributorBase extends ServiceDeploymentContributorBase { private static final String PACKAGES_PARAM = "jersey.config.server.provider.packages"; - private static final String TRACE_LOGGING_PARAM = "jersey.config.server.tracing"; +// private static final String TRACE_LOGGING_PARAM = "jersey.config.server.tracing"; protected abstract String[] getPackages(); http://git-wip-us.apache.org/repos/asf/knox/blob/d3d269f9/gateway-release/pom.xml ---------------------------------------------------------------------- diff --git a/gateway-release/pom.xml b/gateway-release/pom.xml index 80f00bd..84834ef 100644 --- a/gateway-release/pom.xml +++ b/gateway-release/pom.xml @@ -115,6 +115,10 @@ </dependency> <dependency> <groupId>${gateway-group}</groupId> + <artifactId>gateway-service-admin</artifactId> + </dependency> + <dependency> + <groupId>${gateway-group}</groupId> <artifactId>gateway-service-as</artifactId> </dependency> <dependency> http://git-wip-us.apache.org/repos/asf/knox/blob/d3d269f9/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayServer.java ---------------------------------------------------------------------- diff --git a/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayServer.java b/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayServer.java index c9c5717..b444faa 100644 --- a/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayServer.java +++ b/gateway-server/src/main/java/org/apache/hadoop/gateway/GatewayServer.java @@ -97,6 +97,7 @@ public class GatewayServer { GatewayConfig config = new GatewayConfigImpl(); redeployTopologies( config, cmd.getOptionValue( GatewayCommandLine.REDEPLOY_LONG ) ); } else { + buildProperties = loadBuildProperties(); services = instantiateGatewayServices(); if (services == null) { log.failedToInstantiateGatewayServices(); @@ -121,10 +122,17 @@ public class GatewayServer { } private static void printVersion() { - buildProperties = loadBuildProperties(); System.out.println( res.gatewayVersionMessage( // I18N not required. - buildProperties.getProperty( "build.version", "unknown" ), - buildProperties.getProperty( "build.hash", "unknown" ) ) ); + getBuildVersion(), + getBuildHash() ) ); + } + + public static String getBuildHash() { + return buildProperties.getProperty( "build.hash", "unknown" ); + } + + public static String getBuildVersion() { + return buildProperties.getProperty( "build.version", "unknown" ); } private static GatewayServices instantiateGatewayServices() { http://git-wip-us.apache.org/repos/asf/knox/blob/d3d269f9/gateway-server/src/main/java/org/apache/hadoop/gateway/services/DefaultGatewayServices.java ---------------------------------------------------------------------- diff --git a/gateway-server/src/main/java/org/apache/hadoop/gateway/services/DefaultGatewayServices.java b/gateway-server/src/main/java/org/apache/hadoop/gateway/services/DefaultGatewayServices.java index b9055f2..eacd124 100644 --- a/gateway-server/src/main/java/org/apache/hadoop/gateway/services/DefaultGatewayServices.java +++ b/gateway-server/src/main/java/org/apache/hadoop/gateway/services/DefaultGatewayServices.java @@ -92,6 +92,10 @@ public class DefaultGatewayServices implements GatewayServices { DefaultHostMapperService hm = new DefaultHostMapperService(); hm.init( config, options ); services.put( HOST_MAPPING_SERVICE, hm ); + + DefaultServerInfoService sis = new DefaultServerInfoService(); + sis.init( config, options ); + services.put( SERVER_INFO_SERVICE, sis ); } public void start() throws ServiceLifecycleException { @@ -104,6 +108,9 @@ public class DefaultGatewayServices implements GatewayServices { SSLService ssl = (SSLService) services.get(SSL_SERVICE); ssl.start(); + + ServerInfoService sis = (ServerInfoService) services.get(SERVER_INFO_SERVICE); + sis.start(); } public void stop() throws ServiceLifecycleException { @@ -116,6 +123,9 @@ public class DefaultGatewayServices implements GatewayServices { SSLService ssl = (SSLService) services.get(SSL_SERVICE); ssl.stop(); + + ServerInfoService sis = (ServerInfoService) services.get(SERVER_INFO_SERVICE); + sis.stop(); } /* (non-Javadoc) http://git-wip-us.apache.org/repos/asf/knox/blob/d3d269f9/gateway-server/src/main/java/org/apache/hadoop/gateway/services/DefaultServerInfoService.java ---------------------------------------------------------------------- diff --git a/gateway-server/src/main/java/org/apache/hadoop/gateway/services/DefaultServerInfoService.java b/gateway-server/src/main/java/org/apache/hadoop/gateway/services/DefaultServerInfoService.java new file mode 100644 index 0000000..21a16d7 --- /dev/null +++ b/gateway-server/src/main/java/org/apache/hadoop/gateway/services/DefaultServerInfoService.java @@ -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.hadoop.gateway.services; + +import java.util.Map; + +import org.apache.hadoop.gateway.GatewayServer; +import org.apache.hadoop.gateway.config.GatewayConfig; + +/** + * Simple server info service implementation that delegates to the + * static methods of the GatewayServer itself for the info. + */ +public class DefaultServerInfoService implements ServerInfoService { + + /* (non-Javadoc) + * @see org.apache.hadoop.gateway.services.Service#init(org.apache.hadoop.gateway.config.GatewayConfig, java.util.Map) + */ + @Override + public void init(GatewayConfig config, Map<String, String> options) + throws ServiceLifecycleException { + } + + /* (non-Javadoc) + * @see org.apache.hadoop.gateway.services.Service#start() + */ + @Override + public void start() throws ServiceLifecycleException { + } + + /* (non-Javadoc) + * @see org.apache.hadoop.gateway.services.Service#stop() + */ + @Override + public void stop() throws ServiceLifecycleException { + } + + /* (non-Javadoc) + * @see org.apache.hadoop.gateway.services.ServerInfoService#getBuildVersion() + */ + @Override + public String getBuildVersion() { + return GatewayServer.getBuildVersion(); + } + + /* (non-Javadoc) + * @see org.apache.hadoop.gateway.services.ServerInfoService#getBuildHash() + */ + @Override + public String getBuildHash() { + return GatewayServer.getBuildHash(); + } + +} http://git-wip-us.apache.org/repos/asf/knox/blob/d3d269f9/gateway-service-admin/pom.xml ---------------------------------------------------------------------- diff --git a/gateway-service-admin/pom.xml b/gateway-service-admin/pom.xml new file mode 100644 index 0000000..bd8c764 --- /dev/null +++ b/gateway-service-admin/pom.xml @@ -0,0 +1,59 @@ +<?xml version="1.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. +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.apache.hadoop</groupId> + <artifactId>gateway</artifactId> + <version>0.5.0-SNAPSHOT</version> + </parent> + <groupId>org.apache.hadoop</groupId> + <artifactId>gateway-service-admin</artifactId> + <version>0.5.0-SNAPSHOT</version> + <name>gateway-service-admin</name> + <url>http://maven.apache.org</url> + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + </properties> + <dependencies> + <dependency> + <groupId>${gateway-group}</groupId> + <artifactId>gateway-spi</artifactId> + </dependency> + <dependency> + <groupId>${gateway-group}</groupId> + <artifactId>gateway-provider-rewrite</artifactId> + </dependency> + <dependency> + <groupId>${gateway-group}</groupId> + <artifactId>gateway-provider-jersey</artifactId> + </dependency> + <dependency> + <groupId>com.owlike</groupId> + <artifactId>genson</artifactId> + <version>0.99</version> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <scope>test</scope> + </dependency> + </dependencies> +</project> http://git-wip-us.apache.org/repos/asf/knox/blob/d3d269f9/gateway-service-admin/src/main/java/org/apache/hadoop/gateway/service/admin/VersionResource.java ---------------------------------------------------------------------- diff --git a/gateway-service-admin/src/main/java/org/apache/hadoop/gateway/service/admin/VersionResource.java b/gateway-service-admin/src/main/java/org/apache/hadoop/gateway/service/admin/VersionResource.java new file mode 100644 index 0000000..100f2b3 --- /dev/null +++ b/gateway-service-admin/src/main/java/org/apache/hadoop/gateway/service/admin/VersionResource.java @@ -0,0 +1,87 @@ +/** + * 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.hadoop.gateway.service.admin; + +import javax.servlet.http.HttpServletRequest; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.Response; + +import org.apache.hadoop.gateway.services.GatewayServices; +import org.apache.hadoop.gateway.services.ServerInfoService; + +import static javax.ws.rs.core.MediaType.APPLICATION_JSON; +import static javax.ws.rs.core.Response.ok; +import static javax.ws.rs.core.Response.status; +import static javax.ws.rs.core.Response.Status.NOT_FOUND; + +@Path( "/admin/api/v1" ) +public class VersionResource { + @Context + private HttpServletRequest request; + + @GET + @Produces({APPLICATION_JSON}) + @Path( "version" ) + public Response getVersion() { + ServerVersion version = getServerVersion(); + if (version != null) { + return ok(version).build(); + } else { + return status(NOT_FOUND).build(); + } + } + + /** + * @return + */ + private ServerVersion getServerVersion() { + GatewayServices services = (GatewayServices)request.getServletContext(). + getAttribute(GatewayServices.GATEWAY_SERVICES_ATTRIBUTE); + + ServerInfoService sis = services.getService(GatewayServices.SERVER_INFO_SERVICE); + + return new ServerVersion(sis.getBuildVersion(), sis.getBuildHash()); + } + + public static class ServerVersion { + private String version; + private String hash; + + public ServerVersion(String version, String hash) { + super(); + this.version = version; + this.hash = hash; + } + + public String getVersion() { + return version; + } + public void setVersion(String version) { + this.version = version; + } + public String getHash() { + return hash; + } + public void setHash(String hash) { + this.hash = hash; + } + } +} http://git-wip-us.apache.org/repos/asf/knox/blob/d3d269f9/gateway-service-admin/src/main/java/org/apache/hadoop/gateway/service/admin/deploy/AdminServiceDeploymentContributor.java ---------------------------------------------------------------------- diff --git a/gateway-service-admin/src/main/java/org/apache/hadoop/gateway/service/admin/deploy/AdminServiceDeploymentContributor.java b/gateway-service-admin/src/main/java/org/apache/hadoop/gateway/service/admin/deploy/AdminServiceDeploymentContributor.java new file mode 100644 index 0000000..2cf398d --- /dev/null +++ b/gateway-service-admin/src/main/java/org/apache/hadoop/gateway/service/admin/deploy/AdminServiceDeploymentContributor.java @@ -0,0 +1,59 @@ +/** + * 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.hadoop.gateway.service.admin.deploy; + +import org.apache.hadoop.gateway.jersey.JerseyServiceDeploymentContributorBase; + +/** + * + */ +public class AdminServiceDeploymentContributor extends JerseyServiceDeploymentContributorBase { + + /* (non-Javadoc) + * @see org.apache.hadoop.gateway.deploy.ServiceDeploymentContributor#getRole() + */ + @Override + public String getRole() { + return "ADMIN"; + } + + /* (non-Javadoc) + * @see org.apache.hadoop.gateway.deploy.ServiceDeploymentContributor#getName() + */ + @Override + public String getName() { + return "admin"; + } + + /* (non-Javadoc) + * @see org.apache.hadoop.gateway.jersey.JerseyServiceDeploymentContributorBase#getPackages() + */ + @Override + protected String[] getPackages() { + return new String[]{ "org.apache.hadoop.gateway.service.admin" }; + } + + /* (non-Javadoc) + * @see org.apache.hadoop.gateway.jersey.JerseyServiceDeploymentContributorBase#getPatterns() + */ + @Override + protected String[] getPatterns() { + return new String[]{ "admin/**?**" }; + } + +} http://git-wip-us.apache.org/repos/asf/knox/blob/d3d269f9/gateway-service-admin/src/main/resources/META-INF/services/org.apache.hadoop.gateway.deploy.ServiceDeploymentContributor ---------------------------------------------------------------------- diff --git a/gateway-service-admin/src/main/resources/META-INF/services/org.apache.hadoop.gateway.deploy.ServiceDeploymentContributor b/gateway-service-admin/src/main/resources/META-INF/services/org.apache.hadoop.gateway.deploy.ServiceDeploymentContributor new file mode 100644 index 0000000..a29e97f --- /dev/null +++ b/gateway-service-admin/src/main/resources/META-INF/services/org.apache.hadoop.gateway.deploy.ServiceDeploymentContributor @@ -0,0 +1,19 @@ +########################################################################## +# 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. +########################################################################## + +org.apache.hadoop.gateway.service.admin.deploy.AdminServiceDeploymentContributor \ No newline at end of file http://git-wip-us.apache.org/repos/asf/knox/blob/d3d269f9/gateway-spi/src/main/java/org/apache/hadoop/gateway/services/GatewayServices.java ---------------------------------------------------------------------- diff --git a/gateway-spi/src/main/java/org/apache/hadoop/gateway/services/GatewayServices.java b/gateway-spi/src/main/java/org/apache/hadoop/gateway/services/GatewayServices.java index 2de2d66..9af6b96 100644 --- a/gateway-spi/src/main/java/org/apache/hadoop/gateway/services/GatewayServices.java +++ b/gateway-spi/src/main/java/org/apache/hadoop/gateway/services/GatewayServices.java @@ -34,6 +34,7 @@ public interface GatewayServices extends Service, ProviderDeploymentContributor public static final String TOKEN_SERVICE = "TokenService"; public static final String SERVICE_REGISTRY_SERVICE = "ServiceRegistryService"; public static final String HOST_MAPPING_SERVICE = "HostMappingService"; + public static final String SERVER_INFO_SERVICE = "ServerInfoService"; public abstract Collection<String> getServiceNames(); http://git-wip-us.apache.org/repos/asf/knox/blob/d3d269f9/gateway-spi/src/main/java/org/apache/hadoop/gateway/services/ServerInfoService.java ---------------------------------------------------------------------- diff --git a/gateway-spi/src/main/java/org/apache/hadoop/gateway/services/ServerInfoService.java b/gateway-spi/src/main/java/org/apache/hadoop/gateway/services/ServerInfoService.java new file mode 100644 index 0000000..137a74e --- /dev/null +++ b/gateway-spi/src/main/java/org/apache/hadoop/gateway/services/ServerInfoService.java @@ -0,0 +1,34 @@ +/** + * 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.hadoop.gateway.services; + +/** + * This service provides a central place to acquire information + * about the running server instance. + */ +public interface ServerInfoService extends Service { + /** + * Get the build version for the server instance + */ + String getBuildVersion(); + + /** + * Get the build hash for the server instance + */ + String getBuildHash(); +} http://git-wip-us.apache.org/repos/asf/knox/blob/d3d269f9/pom.xml ---------------------------------------------------------------------- diff --git a/pom.xml b/pom.xml index d7281ff..6cfd104 100644 --- a/pom.xml +++ b/pom.xml @@ -52,6 +52,7 @@ <module>gateway-provider-security-authz-acls</module> <module>gateway-provider-identity-assertion-pseudo</module> <module>gateway-provider-jersey</module> + <module>gateway-service-admin</module> <module>gateway-service-as</module> <module>gateway-service-hbase</module> <module>gateway-service-hive</module> @@ -431,6 +432,11 @@ </dependency> <dependency> <groupId>${gateway-group}</groupId> + <artifactId>gateway-service-admin</artifactId> + <version>${gateway-version}</version> + </dependency> + <dependency> + <groupId>${gateway-group}</groupId> <artifactId>gateway-service-as</artifactId> <version>${gateway-version}</version> </dependency>
