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

(cherry picked from commit f2df6b8983)
This commit is contained in:
Subru Krishnan 2017-11-08 18:07:12 -08:00
parent 5486542074
commit 46a740a82e
2 changed files with 4 additions and 26 deletions

View File

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

View File

@ -37,18 +37,12 @@ import org.apache.hadoop.yarn.util.resource.DefaultResourceCalculator;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
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.guice.spi.container.servlet.GuiceContainer;
import com.sun.jersey.test.framework.JerseyTest;
import com.sun.jersey.test.framework.WebAppDescriptor;
/**
* Test ResourceEstimatorService.
@ -70,29 +64,12 @@ public class TestResourceEstimatorService extends JerseyTest {
private long containerMemAlloc;
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() {
super(new WebAppDescriptor.Builder(
"org.apache.hadoop.resourceestimator.service")
.contextListenerClass(GuiceServletConfig.class)
.filterClass(com.google.inject.servlet.GuiceFilter.class).build());
super("org.apache.hadoop.resourceestimator.service");
}
@Before @Override public void setUp() throws Exception {
super.setUp();
GuiceServletConfig
.setInjector(Guice.createInjector(new WebServletModule()));
containerMemAlloc = 1024;
containerCPUAlloc = 1;
containerSpec = Resource.newInstance(containerMemAlloc, containerCPUAlloc);