HADOOP-15025. Ensure singleton for ResourceEstimatorService. (Rui Li via Subru).

This commit is contained in:
Subru Krishnan 2017-11-08 18:07:12 -08:00
parent 49b4c0b334
commit f2df6b8983
2 changed files with 4 additions and 26 deletions

View File

@ -34,6 +34,7 @@
import javax.ws.rs.Produces; import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import com.sun.jersey.spi.resource.Singleton;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.resourceestimator.common.api.RecurrenceId; import org.apache.hadoop.resourceestimator.common.api.RecurrenceId;
import org.apache.hadoop.resourceestimator.common.api.ResourceSkyline; import org.apache.hadoop.resourceestimator.common.api.ResourceSkyline;
@ -56,13 +57,13 @@
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.GsonBuilder; import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
import com.google.inject.Singleton;
/** /**
* Resource Estimator Service which provides a set of REST APIs for users to * Resource Estimator Service which provides a set of REST APIs for users to
* use the estimation service. * use the estimation service.
*/ */
@Singleton @Path("/resourceestimator") public class ResourceEstimatorService { @Singleton
@Path("/resourceestimator") public class ResourceEstimatorService {
private static final Logger LOGGER = private static final Logger LOGGER =
LoggerFactory.getLogger(ResourceEstimatorService.class); LoggerFactory.getLogger(ResourceEstimatorService.class);
private final SkylineStore skylineStore; private final SkylineStore skylineStore;

View File

@ -37,18 +37,12 @@
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.GsonBuilder; import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
import com.google.inject.Guice;
import com.google.inject.servlet.ServletModule;
import com.sun.jersey.api.client.WebResource; import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.guice.spi.container.servlet.GuiceContainer;
import com.sun.jersey.test.framework.JerseyTest; import com.sun.jersey.test.framework.JerseyTest;
import com.sun.jersey.test.framework.WebAppDescriptor;
/** /**
* Test ResourceEstimatorService. * Test ResourceEstimatorService.
@ -70,29 +64,12 @@ public class TestResourceEstimatorService extends JerseyTest {
private long containerMemAlloc; private long containerMemAlloc;
private int containerCPUAlloc; private int containerCPUAlloc;
private static class WebServletModule extends ServletModule {
@Override protected void configureServlets() {
bind(ResourceEstimatorService.class);
serve("/*").with(GuiceContainer.class);
}
}
static {
GuiceServletConfig
.setInjector(Guice.createInjector(new WebServletModule()));
}
public TestResourceEstimatorService() { public TestResourceEstimatorService() {
super(new WebAppDescriptor.Builder( super("org.apache.hadoop.resourceestimator.service");
"org.apache.hadoop.resourceestimator.service")
.contextListenerClass(GuiceServletConfig.class)
.filterClass(com.google.inject.servlet.GuiceFilter.class).build());
} }
@Before @Override public void setUp() throws Exception { @Before @Override public void setUp() throws Exception {
super.setUp(); super.setUp();
GuiceServletConfig
.setInjector(Guice.createInjector(new WebServletModule()));
containerMemAlloc = 1024; containerMemAlloc = 1024;
containerCPUAlloc = 1; containerCPUAlloc = 1;
containerSpec = Resource.newInstance(containerMemAlloc, containerCPUAlloc); containerSpec = Resource.newInstance(containerMemAlloc, containerCPUAlloc);