Search in sources :

Example 1 with BaseResource

use of com.linkedin.restli.server.resources.BaseResource in project incubator-gobblin by apache.

the class FlowStatusTest method setUp.

@BeforeClass
public void setUp() throws Exception {
    ConfigBuilder configBuilder = ConfigBuilder.create();
    JobStatusRetriever jobStatusRetriever = new TestJobStatusRetriever();
    final FlowStatusGenerator flowStatusGenerator = FlowStatusGenerator.builder().jobStatusRetriever(jobStatusRetriever).build();
    Injector injector = Guice.createInjector(new Module() {

        @Override
        public void configure(Binder binder) {
            binder.bind(FlowStatusGenerator.class).annotatedWith(Names.named(FlowStatusResource.FLOW_STATUS_GENERATOR_INJECT_NAME)).toInstance(flowStatusGenerator);
        }
    });
    _server = EmbeddedRestliServer.builder().resources(Lists.<Class<? extends BaseResource>>newArrayList(FlowStatusResource.class)).injector(injector).build();
    _server.startAsync();
    _server.awaitRunning();
    _client = new FlowStatusClient(String.format("http://localhost:%s/", _server.getPort()));
    messageJoiner = Joiner.on(FlowStatusResource.MESSAGE_SEPARATOR);
}
Also used : Binder(com.google.inject.Binder) Injector(com.google.inject.Injector) BaseResource(com.linkedin.restli.server.resources.BaseResource) ConfigBuilder(org.apache.gobblin.config.ConfigBuilder) AfterClass(org.testng.annotations.AfterClass) BeforeClass(org.testng.annotations.BeforeClass) Module(com.google.inject.Module) FlowStatusGenerator(org.apache.gobblin.service.monitoring.FlowStatusGenerator) JobStatusRetriever(org.apache.gobblin.service.monitoring.JobStatusRetriever) BeforeClass(org.testng.annotations.BeforeClass)

Example 2 with BaseResource

use of com.linkedin.restli.server.resources.BaseResource in project rest.li by linkedin.

the class TestRestLiMethodInvocation method getMockResource.

private <R> R getMockResource(Class<R> resourceClass) {
    R resource = _resourceFactory.getMock(resourceClass);
    EasyMock.reset(resource);
    EasyMock.makeThreadSafe(resource, true);
    if (BaseResource.class.isAssignableFrom(resourceClass)) {
        BaseResource baseResource = (BaseResource) resource;
        baseResource.setContext((ResourceContext) EasyMock.anyObject());
        EasyMock.expectLastCall().once();
    }
    return resource;
}
Also used : BaseResource(com.linkedin.restli.server.resources.BaseResource)

Example 3 with BaseResource

use of com.linkedin.restli.server.resources.BaseResource in project rest.li by linkedin.

the class RestLiMethodInvoker method invoke.

/**
   * Invokes the method with the specified callback and arguments built from the request.
   *
   * @param requestData
   *          {@link RestLiRequestData}
   * @param invocableMethod
   *          {@link RoutingResult}
   * @param restLiArgumentBuilder
   *          {@link RestLiArgumentBuilder}
   * @param callback
   *          {@link RequestExecutionCallback}
   * @param requestExecutionReportBuilder
   *          {@link RequestExecutionReportBuilder}
   */
public void invoke(final RestLiRequestData requestData, final RoutingResult invocableMethod, final RestLiArgumentBuilder restLiArgumentBuilder, final RequestExecutionCallback<Object> callback, final RequestExecutionReportBuilder requestExecutionReportBuilder) {
    try {
        ResourceMethodDescriptor resourceMethodDescriptor = invocableMethod.getResourceMethod();
        Object resource = _resourceFactory.create(resourceMethodDescriptor.getResourceModel().getResourceClass());
        //Acquire a handle on the ResourceContext when setting it in order to obtain any response attachments that need to
        //be streamed back.
        final ServerResourceContext resourceContext;
        resourceContext = (ServerResourceContext) invocableMethod.getContext();
        if (BaseResource.class.isAssignableFrom(resource.getClass())) {
            ((BaseResource) resource).setContext(resourceContext);
        }
        Object[] args = restLiArgumentBuilder.buildArguments(requestData, invocableMethod);
        // Now invoke the resource implementation.
        doInvoke(resourceMethodDescriptor, callback, requestExecutionReportBuilder, resource, resourceContext, args);
    } catch (Exception e) {
        callback.onError(e, requestExecutionReportBuilder == null ? null : requestExecutionReportBuilder.build(), ((ServerResourceContext) invocableMethod.getContext()).getRequestAttachmentReader(), //Technically response attachments
        invocableMethod.getContext().getResponseAttachments());
    //could exist here. One possible way is if there is a runtime exception during response
    //construction after the rest.li response filter chain has been completed.
    }
}
Also used : ResourceMethodDescriptor(com.linkedin.restli.internal.server.model.ResourceMethodDescriptor) BaseResource(com.linkedin.restli.server.resources.BaseResource) InvocationTargetException(java.lang.reflect.InvocationTargetException) RestLiServiceException(com.linkedin.restli.server.RestLiServiceException)

Example 4 with BaseResource

use of com.linkedin.restli.server.resources.BaseResource in project incubator-gobblin by apache.

the class FlowConfigTest method setUp.

@BeforeClass
public void setUp() throws Exception {
    ConfigBuilder configBuilder = ConfigBuilder.create();
    _testDirectory = Files.createTempDir();
    configBuilder.addPrimitive(ConfigurationKeys.JOB_CONFIG_FILE_DIR_KEY, _testDirectory.getAbsolutePath()).addPrimitive(ConfigurationKeys.SPECSTORE_FS_DIR_KEY, TEST_SPEC_STORE_DIR);
    cleanUpDir(TEST_SPEC_STORE_DIR);
    Config config = configBuilder.build();
    final FlowCatalog flowCatalog = new FlowCatalog(config);
    flowCatalog.startAsync();
    flowCatalog.awaitRunning();
    Injector injector = Guice.createInjector(new Module() {

        @Override
        public void configure(Binder binder) {
            binder.bind(FlowCatalog.class).annotatedWith(Names.named("flowCatalog")).toInstance(flowCatalog);
            // indicate that we are in unit testing since the resource is being blocked until flow catalog changes have
            // been made
            binder.bindConstant().annotatedWith(Names.named("readyToUse")).to(Boolean.TRUE);
        }
    });
    _server = EmbeddedRestliServer.builder().resources(Lists.<Class<? extends BaseResource>>newArrayList(FlowConfigsResource.class)).injector(injector).build();
    _server.startAsync();
    _server.awaitRunning();
    _client = new FlowConfigClient(String.format("http://localhost:%s/", _server.getPort()));
}
Also used : Binder(com.google.inject.Binder) Config(com.typesafe.config.Config) Injector(com.google.inject.Injector) BaseResource(com.linkedin.restli.server.resources.BaseResource) ConfigBuilder(org.apache.gobblin.config.ConfigBuilder) AfterClass(org.testng.annotations.AfterClass) BeforeClass(org.testng.annotations.BeforeClass) Module(com.google.inject.Module) FlowCatalog(org.apache.gobblin.runtime.spec_catalog.FlowCatalog) BeforeClass(org.testng.annotations.BeforeClass)

Example 5 with BaseResource

use of com.linkedin.restli.server.resources.BaseResource in project incubator-gobblin by apache.

the class RestliServiceBasedLimiterTest method createAndStartServer.

private RestliServer createAndStartServer(Config baseConfig, int port) {
    ThrottlingGuiceServletConfig guiceServletConfig = new ThrottlingGuiceServletConfig();
    guiceServletConfig.initialize(baseConfig.withFallback(ConfigFactory.parseMap(ImmutableMap.of(ThrottlingGuiceServletConfig.LISTENING_PORT, Integer.toString(port)))));
    Injector injector = guiceServletConfig.getInjector();
    EmbeddedRestliServer server = EmbeddedRestliServer.builder().resources(Lists.<Class<? extends BaseResource>>newArrayList(LimiterServerResource.class)).injector(injector).port(port).build();
    server.startAsync();
    server.awaitRunning();
    return new RestliServer(server, guiceServletConfig);
}
Also used : ThrottlingGuiceServletConfig(org.apache.gobblin.restli.throttling.ThrottlingGuiceServletConfig) EmbeddedRestliServer(org.apache.gobblin.restli.EmbeddedRestliServer) EmbeddedRestliServer(org.apache.gobblin.restli.EmbeddedRestliServer) Injector(com.google.inject.Injector) BaseResource(com.linkedin.restli.server.resources.BaseResource)

Aggregations

BaseResource (com.linkedin.restli.server.resources.BaseResource)5 Injector (com.google.inject.Injector)3 Binder (com.google.inject.Binder)2 Module (com.google.inject.Module)2 ConfigBuilder (org.apache.gobblin.config.ConfigBuilder)2 AfterClass (org.testng.annotations.AfterClass)2 BeforeClass (org.testng.annotations.BeforeClass)2 ResourceMethodDescriptor (com.linkedin.restli.internal.server.model.ResourceMethodDescriptor)1 RestLiServiceException (com.linkedin.restli.server.RestLiServiceException)1 Config (com.typesafe.config.Config)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 EmbeddedRestliServer (org.apache.gobblin.restli.EmbeddedRestliServer)1 ThrottlingGuiceServletConfig (org.apache.gobblin.restli.throttling.ThrottlingGuiceServletConfig)1 FlowCatalog (org.apache.gobblin.runtime.spec_catalog.FlowCatalog)1 FlowStatusGenerator (org.apache.gobblin.service.monitoring.FlowStatusGenerator)1 JobStatusRetriever (org.apache.gobblin.service.monitoring.JobStatusRetriever)1