Search in sources :

Example 1 with GRPCServerConfig

use of io.pravega.controller.server.rpc.grpc.GRPCServerConfig in project pravega by pravega.

the class Main method main.

public static void main(String[] args) {
    try {
        // 0. Initialize metrics provider
        MetricsProvider.initialize(Config.getMetricsConfig());
        ZKClientConfig zkClientConfig = ZKClientConfigImpl.builder().connectionString(Config.ZK_URL).namespace("pravega/" + Config.CLUSTER_NAME).initialSleepInterval(Config.ZK_RETRY_SLEEP_MS).maxRetries(Config.ZK_MAX_RETRIES).sessionTimeoutMs(Config.ZK_SESSION_TIMEOUT_MS).build();
        StoreClientConfig storeClientConfig = StoreClientConfigImpl.withZKClient(zkClientConfig);
        HostMonitorConfig hostMonitorConfig = HostMonitorConfigImpl.builder().hostMonitorEnabled(Config.HOST_MONITOR_ENABLED).hostMonitorMinRebalanceInterval(Config.CLUSTER_MIN_REBALANCE_INTERVAL).containerCount(Config.HOST_STORE_CONTAINER_COUNT).hostContainerMap(HostMonitorConfigImpl.getHostContainerMap(Config.SERVICE_HOST, Config.SERVICE_PORT, Config.HOST_STORE_CONTAINER_COUNT)).build();
        TimeoutServiceConfig timeoutServiceConfig = TimeoutServiceConfig.builder().maxLeaseValue(Config.MAX_LEASE_VALUE).maxScaleGracePeriod(Config.MAX_SCALE_GRACE_PERIOD).build();
        ControllerEventProcessorConfig eventProcessorConfig = ControllerEventProcessorConfigImpl.withDefault();
        GRPCServerConfig grpcServerConfig = Config.getGRPCServerConfig();
        RESTServerConfig restServerConfig = RESTServerConfigImpl.builder().host(Config.REST_SERVER_IP).port(Config.REST_SERVER_PORT).build();
        ControllerServiceConfig serviceConfig = ControllerServiceConfigImpl.builder().threadPoolSize(Config.ASYNC_TASK_POOL_SIZE).storeClientConfig(storeClientConfig).hostMonitorConfig(hostMonitorConfig).controllerClusterListenerEnabled(true).timeoutServiceConfig(timeoutServiceConfig).eventProcessorConfig(Optional.of(eventProcessorConfig)).grpcServerConfig(Optional.of(grpcServerConfig)).restServerConfig(Optional.of(restServerConfig)).build();
        ControllerServiceMain controllerServiceMain = new ControllerServiceMain(serviceConfig);
        controllerServiceMain.startAsync();
        controllerServiceMain.awaitTerminated();
        log.info("Controller service exited");
        System.exit(0);
    } catch (Throwable e) {
        log.error("Controller service failed", e);
        System.exit(-1);
    }
}
Also used : ControllerEventProcessorConfig(io.pravega.controller.server.eventProcessor.ControllerEventProcessorConfig) TimeoutServiceConfig(io.pravega.controller.timeout.TimeoutServiceConfig) ZKClientConfig(io.pravega.controller.store.client.ZKClientConfig) GRPCServerConfig(io.pravega.controller.server.rpc.grpc.GRPCServerConfig) StoreClientConfig(io.pravega.controller.store.client.StoreClientConfig) HostMonitorConfig(io.pravega.controller.store.host.HostMonitorConfig) RESTServerConfig(io.pravega.controller.server.rest.RESTServerConfig)

Example 2 with GRPCServerConfig

use of io.pravega.controller.server.rpc.grpc.GRPCServerConfig in project pravega by pravega.

the class PravegaAuthManagerTest method registerInterceptors.

@Test
public void registerInterceptors() throws Exception {
    // Test the registration method.
    GRPCServerConfig config = GRPCServerConfigImpl.builder().authorizationEnabled(true).userPasswordFile(file.getAbsolutePath()).port(1000).build();
    PravegaAuthManager manager = new PravegaAuthManager(config);
    int port = TestUtils.getAvailableListenPort();
    ServerBuilder<?> server = ServerBuilder.forPort(port).useTransportSecurity(new File("../config/cert.pem"), new File("../config/key.pem"));
    server.addService(serviceImpl);
    manager.registerInterceptors(server);
    server.build().start();
    InlineExecutor executor = new InlineExecutor();
    Credentials creds = new DefaultCredentials("1111_aaaa", "admin");
    final ControllerImpl controllerClient = new ControllerImpl(ControllerImplConfig.builder().clientConfig(ClientConfig.builder().controllerURI(URI.create("tcp://localhost:" + port)).build()).retryAttempts(1).build(), executor);
    MultivaluedMap<String, String> map = new MultivaluedHashMap();
    // Without specifying a valid handler.
    assertThrows(AuthenticationException.class, () -> manager.authenticate("hi", map, AuthHandler.Permissions.READ));
    // Non existent interceptor method.
    map.add("method", "invalid");
    assertThrows(AuthenticationException.class, () -> manager.authenticate("hi", map, AuthHandler.Permissions.READ));
    // Specify a valid method but no parameters for default interceptor.
    map.putSingle("method", "Pravega-Default");
    assertThrows(AuthenticationException.class, () -> manager.authenticate("hi", map, AuthHandler.Permissions.READ));
    // Specify a valid method but no password for default interceptor.
    map.putSingle("username", "dummy3");
    assertThrows(AuthenticationException.class, () -> manager.authenticate("hi", map, AuthHandler.Permissions.READ));
    // Specify a valid method and parameters but invalid resource for default interceptor.
    map.putSingle("password", "password");
    assertFalse("Not existent resource should return false", manager.authenticate("invalid", map, AuthHandler.Permissions.READ));
    // Valid parameters for default interceptor
    map.putSingle("username", "dummy3");
    map.putSingle("password", "password");
    assertTrue("Read access for read resource should return true", manager.authenticate("readresource", map, AuthHandler.Permissions.READ));
    // Stream/scope access should be extended to segment.
    assertTrue("Read access for read resource should return true", manager.authenticate("readresource/segment", map, AuthHandler.Permissions.READ));
    // Levels of access
    assertFalse("Write access for read resource should return false", manager.authenticate("readresource", map, AuthHandler.Permissions.READ_UPDATE));
    assertTrue("Read access for write resource should return true", manager.authenticate("totalaccess", map, AuthHandler.Permissions.READ));
    assertTrue("Write access for write resource should return true", manager.authenticate("totalaccess", map, AuthHandler.Permissions.READ_UPDATE));
    // Check the wildcard access
    map.putSingle("username", "dummy4");
    assertTrue("Write access for write resource should return true", manager.authenticate("totalaccess", map, AuthHandler.Permissions.READ_UPDATE));
    map.putSingle("method", "testHandler");
    assertTrue("Test handler should be called", manager.authenticate("any", map, AuthHandler.Permissions.READ));
    assertThrows(RetriesExhaustedException.class, () -> controllerClient.createScope("hi").join());
}
Also used : DefaultCredentials(io.pravega.client.stream.impl.DefaultCredentials) MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) InlineExecutor(io.pravega.test.common.InlineExecutor) ControllerImpl(io.pravega.client.stream.impl.ControllerImpl) GRPCServerConfig(io.pravega.controller.server.rpc.grpc.GRPCServerConfig) File(java.io.File) Credentials(io.pravega.client.stream.impl.Credentials) DefaultCredentials(io.pravega.client.stream.impl.DefaultCredentials) Test(org.junit.Test)

Example 3 with GRPCServerConfig

use of io.pravega.controller.server.rpc.grpc.GRPCServerConfig in project pravega by pravega.

the class InProcPravegaCluster method startLocalController.

private ControllerServiceMain startLocalController(int controllerId) {
    ZKClientConfig zkClientConfig = ZKClientConfigImpl.builder().connectionString(zkUrl).namespace("pravega/" + clusterName).initialSleepInterval(2000).maxRetries(1).sessionTimeoutMs(10 * 1000).build();
    StoreClientConfig storeClientConfig = StoreClientConfigImpl.withZKClient(zkClientConfig);
    HostMonitorConfig hostMonitorConfig = HostMonitorConfigImpl.builder().hostMonitorEnabled(true).hostMonitorMinRebalanceInterval(Config.CLUSTER_MIN_REBALANCE_INTERVAL).containerCount(Config.HOST_STORE_CONTAINER_COUNT).build();
    TimeoutServiceConfig timeoutServiceConfig = TimeoutServiceConfig.builder().maxLeaseValue(Config.MAX_LEASE_VALUE).maxScaleGracePeriod(Config.MAX_SCALE_GRACE_PERIOD).build();
    ControllerEventProcessorConfig eventProcessorConfig = ControllerEventProcessorConfigImpl.withDefault();
    GRPCServerConfig grpcServerConfig = GRPCServerConfigImpl.builder().port(this.controllerPorts[controllerId]).publishedRPCHost("localhost").publishedRPCPort(this.controllerPorts[controllerId]).authorizationEnabled(this.enableAuth).tlsEnabled(this.enableTls).tlsTrustStore("../config/cert.pem").tlsCertFile("../config/cert.pem").tlsKeyFile("../config/key.pem").userPasswordFile("../config/passwd").tokenSigningKey("secret").build();
    RESTServerConfig restServerConfig = RESTServerConfigImpl.builder().host("0.0.0.0").port(this.restServerPort).build();
    ControllerServiceConfig serviceConfig = ControllerServiceConfigImpl.builder().threadPoolSize(Config.ASYNC_TASK_POOL_SIZE).storeClientConfig(storeClientConfig).hostMonitorConfig(hostMonitorConfig).controllerClusterListenerEnabled(false).timeoutServiceConfig(timeoutServiceConfig).eventProcessorConfig(Optional.of(eventProcessorConfig)).grpcServerConfig(Optional.of(grpcServerConfig)).restServerConfig(Optional.of(restServerConfig)).build();
    ControllerServiceMain controllerService = new ControllerServiceMain(serviceConfig);
    controllerService.startAsync();
    return controllerService;
}
Also used : ControllerEventProcessorConfig(io.pravega.controller.server.eventProcessor.ControllerEventProcessorConfig) TimeoutServiceConfig(io.pravega.controller.timeout.TimeoutServiceConfig) ZKClientConfig(io.pravega.controller.store.client.ZKClientConfig) GRPCServerConfig(io.pravega.controller.server.rpc.grpc.GRPCServerConfig) StoreClientConfig(io.pravega.controller.store.client.StoreClientConfig) ControllerServiceConfig(io.pravega.controller.server.ControllerServiceConfig) HostMonitorConfig(io.pravega.controller.store.host.HostMonitorConfig) RESTServerConfig(io.pravega.controller.server.rest.RESTServerConfig) ControllerServiceMain(io.pravega.controller.server.ControllerServiceMain)

Example 4 with GRPCServerConfig

use of io.pravega.controller.server.rpc.grpc.GRPCServerConfig in project pravega by pravega.

the class ConfigTest method testGRPCConfig.

@Test
public void testGRPCConfig() {
    GRPCServerConfig grpcServerConfig = Config.getGRPCServerConfig();
    Assert.assertEquals(9090, grpcServerConfig.getPort());
    Assert.assertEquals(9090, (int) grpcServerConfig.getPublishedRPCPort().orElse(12345));
    Assert.assertFalse(grpcServerConfig.getPublishedRPCHost().isPresent());
}
Also used : GRPCServerConfig(io.pravega.controller.server.rpc.grpc.GRPCServerConfig) Test(org.junit.Test)

Aggregations

GRPCServerConfig (io.pravega.controller.server.rpc.grpc.GRPCServerConfig)4 ControllerEventProcessorConfig (io.pravega.controller.server.eventProcessor.ControllerEventProcessorConfig)2 RESTServerConfig (io.pravega.controller.server.rest.RESTServerConfig)2 StoreClientConfig (io.pravega.controller.store.client.StoreClientConfig)2 ZKClientConfig (io.pravega.controller.store.client.ZKClientConfig)2 HostMonitorConfig (io.pravega.controller.store.host.HostMonitorConfig)2 TimeoutServiceConfig (io.pravega.controller.timeout.TimeoutServiceConfig)2 Test (org.junit.Test)2 ControllerImpl (io.pravega.client.stream.impl.ControllerImpl)1 Credentials (io.pravega.client.stream.impl.Credentials)1 DefaultCredentials (io.pravega.client.stream.impl.DefaultCredentials)1 ControllerServiceConfig (io.pravega.controller.server.ControllerServiceConfig)1 ControllerServiceMain (io.pravega.controller.server.ControllerServiceMain)1 InlineExecutor (io.pravega.test.common.InlineExecutor)1 File (java.io.File)1 MultivaluedHashMap (javax.ws.rs.core.MultivaluedHashMap)1