YARN-11631. [GPG] Add GPGWebServices. (#6354) Contributed by Shilun Fan.
Reviewed-by: Inigo Goiri <inigoiri@apache.org> Signed-off-by: Shilun Fan <slfan1989@apache.org>
This commit is contained in:
parent
60033fd581
commit
64beecb7cb
@ -118,6 +118,17 @@
|
||||
<type>test-jar</type>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.sun.jersey.jersey-test-framework</groupId>
|
||||
<artifactId>jersey-test-framework-core</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sun.jersey.jersey-test-framework</groupId>
|
||||
<artifactId>jersey-test-framework-grizzly2</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
@ -299,7 +299,8 @@ public void startWepApp() {
|
||||
}
|
||||
LOG.info("Instantiating GPGWebApp at {}.", webAppAddress);
|
||||
GPGWebApp gpgWebApp = new GPGWebApp(this);
|
||||
webApp = WebApps.$for("gpg").at(webAppAddress).start(gpgWebApp);
|
||||
webApp = WebApps.$for("gpg", GPGContext.class, this.gpgContext,
|
||||
"ws").at(webAppAddress).start(gpgWebApp);
|
||||
}
|
||||
|
||||
@SuppressWarnings("resource")
|
||||
|
@ -34,6 +34,7 @@ public GPGWebApp(GlobalPolicyGenerator gpg) {
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
bind(GPGWebServices.class);
|
||||
bind(JAXBContextResolver.class);
|
||||
bind(GPGWebApp.class).toInstance(this);
|
||||
bind(GenericExceptionHandler.class);
|
||||
|
@ -0,0 +1,62 @@
|
||||
/** * Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.hadoop.yarn.server.globalpolicygenerator.webapp;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
import org.apache.hadoop.http.JettyUtils;
|
||||
import org.apache.hadoop.yarn.server.globalpolicygenerator.GlobalPolicyGenerator;
|
||||
import org.apache.hadoop.yarn.server.globalpolicygenerator.webapp.dao.GpgInfo;
|
||||
import org.apache.hadoop.yarn.webapp.WebApp;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
@Singleton
|
||||
@Path("/ws/v1/gpg")
|
||||
public class GPGWebServices {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(GPGWebServices.class);
|
||||
|
||||
private GlobalPolicyGenerator gpgGenerator;
|
||||
private WebApp webapp;
|
||||
|
||||
@Inject
|
||||
public GPGWebServices(final GlobalPolicyGenerator gpg, final WebApp webapp) {
|
||||
this.gpgGenerator = gpg;
|
||||
this.webapp = webapp;
|
||||
}
|
||||
|
||||
@GET
|
||||
@Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8,
|
||||
MediaType.APPLICATION_XML + "; " + JettyUtils.UTF_8 })
|
||||
public GpgInfo get() {
|
||||
return new GpgInfo(this.gpgGenerator.getGPGContext());
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/info")
|
||||
@Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8,
|
||||
MediaType.APPLICATION_XML + "; " + JettyUtils.UTF_8 })
|
||||
public GpgInfo getGPGInfo() {
|
||||
return new GpgInfo(this.gpgGenerator.getGPGContext());
|
||||
}
|
||||
}
|
@ -0,0 +1,81 @@
|
||||
/**
|
||||
* 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.yarn.server.globalpolicygenerator.webapp.dao;
|
||||
|
||||
import org.apache.hadoop.util.VersionInfo;
|
||||
import org.apache.hadoop.yarn.server.globalpolicygenerator.GPGContext;
|
||||
import org.apache.hadoop.yarn.server.globalpolicygenerator.GlobalPolicyGenerator;
|
||||
import org.apache.hadoop.yarn.util.YarnVersionInfo;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
@XmlRootElement
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
public class GpgInfo {
|
||||
private String gpgVersion;
|
||||
private String gpgBuildVersion;
|
||||
private String gpgVersionBuiltOn;
|
||||
private String hadoopVersion;
|
||||
private String hadoopBuildVersion;
|
||||
private String hadoopVersionBuiltOn;
|
||||
private long gpgStartupTime;
|
||||
|
||||
public GpgInfo() {
|
||||
} // JAXB needs this
|
||||
|
||||
public GpgInfo(final GPGContext context) {
|
||||
this.gpgVersion = YarnVersionInfo.getVersion();
|
||||
this.gpgBuildVersion = YarnVersionInfo.getBuildVersion();
|
||||
this.gpgVersionBuiltOn = YarnVersionInfo.getDate();
|
||||
this.hadoopVersion = VersionInfo.getVersion();
|
||||
this.hadoopBuildVersion = VersionInfo.getBuildVersion();
|
||||
this.hadoopVersionBuiltOn = VersionInfo.getDate();
|
||||
this.gpgStartupTime = GlobalPolicyGenerator.getGPGStartupTime();
|
||||
}
|
||||
|
||||
public String getGpgVersion() {
|
||||
return gpgVersion;
|
||||
}
|
||||
|
||||
public String getGpgBuildVersion() {
|
||||
return gpgBuildVersion;
|
||||
}
|
||||
|
||||
public String getGpgVersionBuiltOn() {
|
||||
return gpgVersionBuiltOn;
|
||||
}
|
||||
|
||||
public String getHadoopVersion() {
|
||||
return hadoopVersion;
|
||||
}
|
||||
|
||||
public String getHadoopBuildVersion() {
|
||||
return hadoopBuildVersion;
|
||||
}
|
||||
|
||||
public String getHadoopVersionBuiltOn() {
|
||||
return hadoopVersionBuiltOn;
|
||||
}
|
||||
|
||||
public long getGpgStartupTime() {
|
||||
return gpgStartupTime;
|
||||
}
|
||||
}
|
@ -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.
|
||||
*/
|
||||
|
||||
package org.apache.hadoop.yarn.server.globalpolicygenerator.webapp.dao;
|
@ -0,0 +1,96 @@
|
||||
/** * 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.yarn.server.globalpolicygenerator.webapp;
|
||||
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.servlet.GuiceFilter;
|
||||
import com.google.inject.servlet.ServletModule;
|
||||
import com.sun.jersey.api.client.WebResource;
|
||||
import com.sun.jersey.guice.spi.container.servlet.GuiceContainer;
|
||||
import com.sun.jersey.test.framework.WebAppDescriptor;
|
||||
import org.apache.hadoop.yarn.server.globalpolicygenerator.GPGContext;
|
||||
import org.apache.hadoop.yarn.server.globalpolicygenerator.GlobalPolicyGenerator;
|
||||
import org.apache.hadoop.yarn.server.resourcemanager.webapp.JAXBContextResolver;
|
||||
import org.apache.hadoop.yarn.webapp.GenericExceptionHandler;
|
||||
import org.apache.hadoop.yarn.webapp.GuiceServletConfig;
|
||||
import org.apache.hadoop.yarn.webapp.JerseyTestBase;
|
||||
import org.apache.hadoop.yarn.webapp.WebApp;
|
||||
import org.codehaus.jettison.json.JSONException;
|
||||
import org.codehaus.jettison.json.JSONObject;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
public class TestGPGWebServices extends JerseyTestBase {
|
||||
private static GlobalPolicyGenerator gpg;
|
||||
private static GPGWebApp webApp;
|
||||
|
||||
private static class XWebServletModule extends ServletModule {
|
||||
@Override
|
||||
protected void configureServlets() {
|
||||
bind(JAXBContextResolver.class);
|
||||
bind(GPGWebServices.class);
|
||||
bind(GenericExceptionHandler.class);
|
||||
gpg = new GlobalPolicyGenerator();
|
||||
webApp = new GPGWebApp(gpg);
|
||||
bind(WebApp.class).toInstance(webApp);
|
||||
bind(GlobalPolicyGenerator.class).toInstance(gpg);
|
||||
bind(GPGContext.class).toInstance(gpg.getGPGContext());
|
||||
serve("/*").with(GuiceContainer.class);
|
||||
}
|
||||
}
|
||||
|
||||
static {
|
||||
GuiceServletConfig.setInjector(
|
||||
Guice.createInjector(new XWebServletModule()));
|
||||
}
|
||||
|
||||
@Before
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
GuiceServletConfig.setInjector(
|
||||
Guice.createInjector(new XWebServletModule()));
|
||||
}
|
||||
|
||||
public TestGPGWebServices() {
|
||||
super(new WebAppDescriptor.Builder(
|
||||
"org.apache.hadoop.yarn.server.globalpolicygenerator.webapp")
|
||||
.contextListenerClass(GuiceServletConfig.class)
|
||||
.filterClass(GuiceFilter.class)
|
||||
.contextPath("jersey-guice-filter").servletPath("/").build());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetGPG() throws JSONException, Exception {
|
||||
WebResource r = resource();
|
||||
JSONObject json = r.path("ws").path("v1").path("gpg")
|
||||
.accept(MediaType.APPLICATION_JSON).get(JSONObject.class);
|
||||
assertNotNull(json);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetGPGInfo() throws JSONException, Exception {
|
||||
WebResource r = resource();
|
||||
JSONObject json = r.path("ws").path("v1").path("gpg").path("info")
|
||||
.accept(MediaType.APPLICATION_JSON).get(JSONObject.class);
|
||||
assertNotNull(json);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user