Search in sources :

Example 26 with SConfiguration

use of io.cdap.cdap.common.conf.SConfiguration in project cdap by cdapio.

the class TaskWorkerServiceTest method testPeriodicRestartWithInflightRequest.

@Test
public void testPeriodicRestartWithInflightRequest() throws IOException {
    CConfiguration cConf = createCConf();
    SConfiguration sConf = createSConf();
    cConf.setInt(Constants.TaskWorker.CONTAINER_KILL_AFTER_REQUEST_COUNT, 10);
    cConf.setInt(Constants.TaskWorker.CONTAINER_KILL_AFTER_DURATION_SECOND, 2);
    TaskWorkerService taskWorkerService = new TaskWorkerService(cConf, sConf, new InMemoryDiscoveryService(), (namespaceId, retryStrategy) -> null, metricsCollectionService, new CommonNettyHttpServiceFactory(cConf, metricsCollectionService));
    serviceCompletionFuture = TaskWorkerTestUtil.getServiceCompletionFuture(taskWorkerService);
    // start the service
    taskWorkerService.startAndWait();
    InetSocketAddress addr = taskWorkerService.getBindAddress();
    URI uri = URI.create(String.format("http://%s:%s", addr.getHostName(), addr.getPort()));
    // Post valid request
    String want = "5000";
    RunnableTaskRequest req = RunnableTaskRequest.getBuilder(TestRunnableClass.class.getName()).withParam(want).build();
    String reqBody = GSON.toJson(req);
    HttpResponse response = HttpRequests.execute(HttpRequest.post(uri.resolve("/v3Internal/worker/run").toURL()).withBody(reqBody).build(), new DefaultHttpRequestConfig(false));
    Assert.assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
    Assert.assertEquals(want, response.getResponseBodyAsString());
    TaskWorkerTestUtil.waitForServiceCompletion(serviceCompletionFuture);
    Assert.assertEquals(Service.State.TERMINATED, taskWorkerService.state());
}
Also used : InetSocketAddress(java.net.InetSocketAddress) DefaultHttpRequestConfig(io.cdap.cdap.common.http.DefaultHttpRequestConfig) SConfiguration(io.cdap.cdap.common.conf.SConfiguration) HttpResponse(io.cdap.common.http.HttpResponse) CommonNettyHttpServiceFactory(io.cdap.cdap.common.http.CommonNettyHttpServiceFactory) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) InMemoryDiscoveryService(org.apache.twill.discovery.InMemoryDiscoveryService) URI(java.net.URI) RunnableTaskRequest(io.cdap.cdap.api.service.worker.RunnableTaskRequest) Test(org.junit.Test)

Example 27 with SConfiguration

use of io.cdap.cdap.common.conf.SConfiguration in project cdap by cdapio.

the class TaskWorkerServiceTest method testPeriodicRestart.

@Test
public void testPeriodicRestart() {
    CConfiguration cConf = createCConf();
    SConfiguration sConf = createSConf();
    cConf.setInt(Constants.TaskWorker.CONTAINER_KILL_AFTER_REQUEST_COUNT, 1);
    cConf.setInt(Constants.TaskWorker.CONTAINER_KILL_AFTER_DURATION_SECOND, 5);
    TaskWorkerService taskWorkerService = new TaskWorkerService(cConf, sConf, new InMemoryDiscoveryService(), (namespaceId, retryStrategy) -> null, metricsCollectionService, new CommonNettyHttpServiceFactory(cConf, metricsCollectionService));
    serviceCompletionFuture = TaskWorkerTestUtil.getServiceCompletionFuture(taskWorkerService);
    // start the service
    taskWorkerService.startAndWait();
    TaskWorkerTestUtil.waitForServiceCompletion(serviceCompletionFuture);
    Assert.assertEquals(Service.State.TERMINATED, taskWorkerService.state());
}
Also used : SConfiguration(io.cdap.cdap.common.conf.SConfiguration) CommonNettyHttpServiceFactory(io.cdap.cdap.common.http.CommonNettyHttpServiceFactory) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) InMemoryDiscoveryService(org.apache.twill.discovery.InMemoryDiscoveryService) Test(org.junit.Test)

Example 28 with SConfiguration

use of io.cdap.cdap.common.conf.SConfiguration in project cdap by cdapio.

the class AppFabricServerTest method testSSL.

@Test
public void testSSL() throws IOException {
    CConfiguration cConf = CConfiguration.create();
    cConf.setBoolean(Constants.Security.SSL.INTERNAL_ENABLED, true);
    SConfiguration sConf = SConfiguration.create();
    final Injector injector = AppFabricTestHelper.getInjector(cConf, sConf);
    try {
        final DiscoveryServiceClient discoveryServiceClient = injector.getInstance(DiscoveryServiceClient.class);
        AppFabricServer appFabricServer = injector.getInstance(AppFabricServer.class);
        appFabricServer.startAndWait();
        Assert.assertTrue(appFabricServer.isRunning());
        Supplier<EndpointStrategy> endpointStrategySupplier = Suppliers.memoize(() -> new RandomEndpointStrategy(() -> discoveryServiceClient.discover(Constants.Service.APP_FABRIC_HTTP)))::get;
        Discoverable discoverable = endpointStrategySupplier.get().pick(3, TimeUnit.SECONDS);
        Assert.assertNotNull(discoverable);
        Assert.assertTrue(URIScheme.HTTPS.isMatch(discoverable));
        InetSocketAddress addr = discoverable.getSocketAddress();
        // Since the server uses a self signed certificate we need a client that trusts all certificates
        SSLSocket socket = (SSLSocket) LDAPLoginModule.TrustAllSSLSocketFactory.getDefault().createSocket(addr.getHostName(), addr.getPort());
        // in millis
        socket.setSoTimeout(5000);
        // Would throw exception if the server does not support ssl.
        // "javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?"
        socket.startHandshake();
        appFabricServer.stopAndWait();
    } finally {
        AppFabricTestHelper.shutdown();
    }
}
Also used : Discoverable(org.apache.twill.discovery.Discoverable) DiscoveryServiceClient(org.apache.twill.discovery.DiscoveryServiceClient) RandomEndpointStrategy(io.cdap.cdap.common.discovery.RandomEndpointStrategy) EndpointStrategy(io.cdap.cdap.common.discovery.EndpointStrategy) Injector(com.google.inject.Injector) InetSocketAddress(java.net.InetSocketAddress) SSLSocket(javax.net.ssl.SSLSocket) SConfiguration(io.cdap.cdap.common.conf.SConfiguration) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) RandomEndpointStrategy(io.cdap.cdap.common.discovery.RandomEndpointStrategy) Test(org.junit.Test)

Example 29 with SConfiguration

use of io.cdap.cdap.common.conf.SConfiguration in project cdap by cdapio.

the class DefaultSecureStoreServiceTest method setup.

@BeforeClass
public static void setup() throws Exception {
    SConfiguration sConf = SConfiguration.create();
    sConf.set(Constants.Security.Store.FILE_PASSWORD, "secret");
    CConfiguration cConf = createCConf();
    final Injector injector = AppFabricTestHelper.getInjector(cConf, sConf);
    discoveryServiceClient = injector.getInstance(DiscoveryServiceClient.class);
    appFabricServer = injector.getInstance(AppFabricServer.class);
    appFabricServer.startAndWait();
    waitForService(Constants.Service.DATASET_MANAGER);
    secureStore = injector.getInstance(SecureStore.class);
    secureStoreManager = injector.getInstance(SecureStoreManager.class);
    accessController = injector.getInstance(AccessControllerInstantiator.class).get();
    // Wait for the default namespace creation
    String user = AuthorizationUtil.getEffectiveMasterUser(cConf);
    accessController.grant(Authorizable.fromEntityId(NamespaceId.DEFAULT), new Principal(user, Principal.PrincipalType.USER), EnumSet.allOf(StandardPermission.class));
    // Starting the Appfabric server will create the default namespace
    Tasks.waitFor(true, new Callable<Boolean>() {

        @Override
        public Boolean call() throws Exception {
            return injector.getInstance(NamespaceAdmin.class).exists(NamespaceId.DEFAULT);
        }
    }, 5, TimeUnit.SECONDS);
    accessController.revoke(Authorizable.fromEntityId(NamespaceId.DEFAULT), new Principal(user, Principal.PrincipalType.USER), Collections.singleton(StandardPermission.UPDATE));
}
Also used : DiscoveryServiceClient(org.apache.twill.discovery.DiscoveryServiceClient) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) SecureStore(io.cdap.cdap.api.security.store.SecureStore) StandardPermission(io.cdap.cdap.proto.security.StandardPermission) UnauthorizedException(io.cdap.cdap.security.spi.authorization.UnauthorizedException) Injector(com.google.inject.Injector) SConfiguration(io.cdap.cdap.common.conf.SConfiguration) SecureStoreManager(io.cdap.cdap.api.security.store.SecureStoreManager) Principal(io.cdap.cdap.proto.security.Principal) BeforeClass(org.junit.BeforeClass)

Example 30 with SConfiguration

use of io.cdap.cdap.common.conf.SConfiguration in project cdap by cdapio.

the class TinkCipherTest method testEncryptionAndDecryption.

@Test
public void testEncryptionAndDecryption() throws CipherException, IOException, GeneralSecurityException {
    SConfiguration sConf = SConfiguration.create();
    sConf.set(Constants.Security.Authentication.USER_CREDENTIAL_ENCRYPTION_KEYSET, generateKeySet());
    TinkCipher cipher = new TinkCipher(sConf);
    byte[] plainData = generateRandomBytes(2 * 1024);
    byte[] associatedData = generateRandomBytes(64);
    byte[] cipherData = cipher.encrypt(plainData, associatedData);
    byte[] decryptedData = cipher.decrypt(cipherData, associatedData);
    Assert.assertArrayEquals(plainData, decryptedData);
    String cipherDataBase64Encoded = cipher.encryptToBase64(plainData, associatedData);
    decryptedData = cipher.decryptFromBase64(cipherDataBase64Encoded, associatedData);
    Assert.assertArrayEquals(plainData, decryptedData);
}
Also used : SConfiguration(io.cdap.cdap.common.conf.SConfiguration) Test(org.junit.Test)

Aggregations

SConfiguration (io.cdap.cdap.common.conf.SConfiguration)70 CConfiguration (io.cdap.cdap.common.conf.CConfiguration)52 Test (org.junit.Test)32 BeforeClass (org.junit.BeforeClass)20 InMemoryDiscoveryService (org.apache.twill.discovery.InMemoryDiscoveryService)16 Injector (com.google.inject.Injector)14 CommonNettyHttpServiceFactory (io.cdap.cdap.common.http.CommonNettyHttpServiceFactory)12 File (java.io.File)12 InetSocketAddress (java.net.InetSocketAddress)10 ConfigModule (io.cdap.cdap.common.guice.ConfigModule)8 Principal (io.cdap.cdap.proto.security.Principal)8 NoOpAccessController (io.cdap.cdap.security.spi.authorization.NoOpAccessController)8 Configuration (org.apache.hadoop.conf.Configuration)8 Before (org.junit.Before)8 RunnableTaskRequest (io.cdap.cdap.api.service.worker.RunnableTaskRequest)6 IOModule (io.cdap.cdap.common.guice.IOModule)6 InMemoryDiscoveryModule (io.cdap.cdap.common.guice.InMemoryDiscoveryModule)6 DefaultHttpRequestConfig (io.cdap.cdap.common.http.DefaultHttpRequestConfig)6 InMemoryNamespaceAdmin (io.cdap.cdap.common.namespace.InMemoryNamespaceAdmin)6 HttpResponse (io.cdap.common.http.HttpResponse)6