Search in sources :

Example 1 with InMemoryNamespaceAdmin

use of io.cdap.cdap.common.namespace.InMemoryNamespaceAdmin in project cdap by caskdata.

the class RemoteConfiguratorTest method init.

@BeforeClass
public static void init() throws Exception {
    cConf = CConfiguration.create();
    cConf.set(Constants.CFG_LOCAL_DATA_DIR, TEMP_FOLDER.newFolder().getAbsolutePath());
    cConf.setInt(Constants.TaskWorker.CONTAINER_KILL_AFTER_REQUEST_COUNT, 0);
    InMemoryDiscoveryService discoveryService = new InMemoryDiscoveryService();
    MasterEnvironments.setMasterEnvironment(new TestMasterEnvironment(discoveryService));
    NamespaceAdmin namespaceAdmin = new InMemoryNamespaceAdmin();
    namespaceAdmin.create(NamespaceMeta.SYSTEM);
    namespaceAdmin.create(NamespaceMeta.DEFAULT);
    remoteClientFactory = new RemoteClientFactory(discoveryService, new DefaultInternalAuthenticator(new AuthenticationTestContext()));
    httpService = new CommonNettyHttpServiceBuilder(cConf, "test").setHttpHandlers(new TaskWorkerHttpHandlerInternal(cConf, className -> {
    }, new NoOpMetricsCollectionService()), new ArtifactHttpHandlerInternal(new TestArtifactRepository(cConf), namespaceAdmin), new ArtifactLocalizerHttpHandlerInternal(new ArtifactLocalizer(cConf, remoteClientFactory, ((namespaceId, retryStrategy) -> {
        return new NoOpArtifactManager();
    })))).setPort(cConf.getInt(Constants.ArtifactLocalizer.PORT)).setChannelPipelineModifier(new ChannelPipelineModifier() {

        @Override
        public void modify(ChannelPipeline pipeline) {
            pipeline.addAfter("compressor", "decompressor", new HttpContentDecompressor());
        }
    }).build();
    httpService.start();
    discoveryService.register(URIScheme.createDiscoverable(Constants.Service.TASK_WORKER, httpService));
    discoveryService.register(URIScheme.createDiscoverable(Constants.Service.APP_FABRIC_HTTP, httpService));
    metricsCollectionService = new NoOpMetricsCollectionService();
}
Also used : ConfigResponse(io.cdap.cdap.app.deploy.ConfigResponse) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) AccessException(io.cdap.cdap.api.security.AccessException) LocalLocationFactory(org.apache.twill.filesystem.LocalLocationFactory) ArtifactClasses(io.cdap.cdap.api.artifact.ArtifactClasses) ArtifactLocalizerHttpHandlerInternal(io.cdap.cdap.internal.app.worker.sidecar.ArtifactLocalizerHttpHandlerInternal) GsonBuilder(com.google.gson.GsonBuilder) ArtifactMeta(io.cdap.cdap.internal.app.runtime.artifact.ArtifactMeta) MasterEnvironments(io.cdap.cdap.master.environment.MasterEnvironments) AppJarHelper(io.cdap.cdap.common.test.AppJarHelper) Gson(com.google.gson.Gson) TaskWorkerHttpHandlerInternal(io.cdap.cdap.internal.app.worker.TaskWorkerHttpHandlerInternal) MasterEnvironmentRunnableContext(io.cdap.cdap.master.spi.environment.MasterEnvironmentRunnableContext) NettyHttpService(io.cdap.http.NettyHttpService) After(org.junit.After) Map(java.util.Map) ConfigTestApp(io.cdap.cdap.ConfigTestApp) ArtifactInfo(io.cdap.cdap.api.artifact.ArtifactInfo) CloseableClassLoader(io.cdap.cdap.api.artifact.CloseableClassLoader) ClassRule(org.junit.ClassRule) NoOpMetricsCollectionService(io.cdap.cdap.common.metrics.NoOpMetricsCollectionService) ArtifactManager(io.cdap.cdap.api.artifact.ArtifactManager) AuthenticationTestContext(io.cdap.cdap.security.auth.context.AuthenticationTestContext) AfterClass(org.junit.AfterClass) ArtifactDescriptor(io.cdap.cdap.internal.app.runtime.artifact.ArtifactDescriptor) ArtifactRepositoryReader(io.cdap.cdap.internal.app.runtime.artifact.ArtifactRepositoryReader) ApplicationSpecification(io.cdap.cdap.api.app.ApplicationSpecification) ProgramType(io.cdap.cdap.api.app.ProgramType) MasterEnvironment(io.cdap.cdap.master.spi.environment.MasterEnvironment) ChannelPipeline(io.netty.channel.ChannelPipeline) ApplicationClass(io.cdap.cdap.api.artifact.ApplicationClass) AppDeploymentInfo(io.cdap.cdap.internal.app.deploy.pipeline.AppDeploymentInfo) Id(io.cdap.cdap.common.id.Id) ApplicationSpecificationAdapter(io.cdap.cdap.internal.app.ApplicationSpecificationAdapter) CommonNettyHttpServiceBuilder(io.cdap.cdap.common.http.CommonNettyHttpServiceBuilder) ArtifactLocalizer(io.cdap.cdap.internal.app.worker.sidecar.ArtifactLocalizer) NamespaceMeta(io.cdap.cdap.proto.NamespaceMeta) List(java.util.List) Constants(io.cdap.cdap.common.conf.Constants) Configurator(io.cdap.cdap.app.deploy.Configurator) AppSpecInfo(io.cdap.cdap.internal.app.deploy.pipeline.AppSpecInfo) NotFoundException(io.cdap.cdap.common.NotFoundException) RemoteClientFactory(io.cdap.cdap.common.internal.remote.RemoteClientFactory) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) InMemoryDiscoveryService(org.apache.twill.discovery.InMemoryDiscoveryService) BeforeClass(org.junit.BeforeClass) InMemoryNamespaceAdmin(io.cdap.cdap.common.namespace.InMemoryNamespaceAdmin) Location(org.apache.twill.filesystem.Location) ChannelPipelineModifier(io.cdap.http.ChannelPipelineModifier) HashMap(java.util.HashMap) Supplier(java.util.function.Supplier) DiscoveryServiceClient(org.apache.twill.discovery.DiscoveryServiceClient) ArtifactHttpHandlerInternal(io.cdap.cdap.gateway.handlers.ArtifactHttpHandlerInternal) ConfiguratorTask(io.cdap.cdap.internal.app.worker.ConfiguratorTask) TwillRunnerService(org.apache.twill.api.TwillRunnerService) ArtifactId(io.cdap.cdap.proto.id.ArtifactId) ArtifactDetail(io.cdap.cdap.internal.app.runtime.artifact.ArtifactDetail) Nullable(javax.annotation.Nullable) DiscoveryService(org.apache.twill.discovery.DiscoveryService) URIScheme(io.cdap.cdap.common.discovery.URIScheme) DefaultArtifactRepository(io.cdap.cdap.internal.app.runtime.artifact.DefaultArtifactRepository) Test(org.junit.Test) IOException(java.io.IOException) LocationFactory(org.apache.twill.filesystem.LocationFactory) MetricsCollectionService(io.cdap.cdap.api.metrics.MetricsCollectionService) DefaultInternalAuthenticator(io.cdap.cdap.common.internal.remote.DefaultInternalAuthenticator) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) NamespaceAdmin(io.cdap.cdap.common.namespace.NamespaceAdmin) ArtifactRepository(io.cdap.cdap.internal.app.runtime.artifact.ArtifactRepository) HttpContentDecompressor(io.netty.handler.codec.http.HttpContentDecompressor) MasterEnvironmentRunnable(io.cdap.cdap.master.spi.environment.MasterEnvironmentRunnable) AllProgramsApp(io.cdap.cdap.AllProgramsApp) Assert(org.junit.Assert) Collections(java.util.Collections) TemporaryFolder(org.junit.rules.TemporaryFolder) RemoteClientFactory(io.cdap.cdap.common.internal.remote.RemoteClientFactory) CommonNettyHttpServiceBuilder(io.cdap.cdap.common.http.CommonNettyHttpServiceBuilder) InMemoryNamespaceAdmin(io.cdap.cdap.common.namespace.InMemoryNamespaceAdmin) NamespaceAdmin(io.cdap.cdap.common.namespace.NamespaceAdmin) AuthenticationTestContext(io.cdap.cdap.security.auth.context.AuthenticationTestContext) ArtifactLocalizer(io.cdap.cdap.internal.app.worker.sidecar.ArtifactLocalizer) TaskWorkerHttpHandlerInternal(io.cdap.cdap.internal.app.worker.TaskWorkerHttpHandlerInternal) NoOpMetricsCollectionService(io.cdap.cdap.common.metrics.NoOpMetricsCollectionService) ChannelPipeline(io.netty.channel.ChannelPipeline) HttpContentDecompressor(io.netty.handler.codec.http.HttpContentDecompressor) DefaultInternalAuthenticator(io.cdap.cdap.common.internal.remote.DefaultInternalAuthenticator) InMemoryNamespaceAdmin(io.cdap.cdap.common.namespace.InMemoryNamespaceAdmin) ArtifactHttpHandlerInternal(io.cdap.cdap.gateway.handlers.ArtifactHttpHandlerInternal) InMemoryDiscoveryService(org.apache.twill.discovery.InMemoryDiscoveryService) ChannelPipelineModifier(io.cdap.http.ChannelPipelineModifier) ArtifactLocalizerHttpHandlerInternal(io.cdap.cdap.internal.app.worker.sidecar.ArtifactLocalizerHttpHandlerInternal) BeforeClass(org.junit.BeforeClass)

Example 2 with InMemoryNamespaceAdmin

use of io.cdap.cdap.common.namespace.InMemoryNamespaceAdmin in project cdap by caskdata.

the class LeaderElectionMessagingServiceTest method init.

@BeforeClass
public static void init() throws IOException {
    zkServer = InMemoryZKServer.builder().setDataDir(TEMP_FOLDER.newFolder()).build();
    zkServer.startAndWait();
    cConf = CConfiguration.create();
    cConf.set(Constants.Zookeeper.QUORUM, zkServer.getConnectionStr());
    cConf.setInt(Constants.Zookeeper.CFG_SESSION_TIMEOUT_MILLIS, 2000);
    cConf.set(Constants.CFG_LOCAL_DATA_DIR, TEMP_FOLDER.newFolder().getAbsolutePath());
    cConf.set(Constants.MessagingSystem.HTTP_SERVER_BIND_ADDRESS, InetAddress.getLocalHost().getHostName());
    cConf.set(Constants.MessagingSystem.SYSTEM_TOPICS, "topic");
    cConf.setLong(Constants.MessagingSystem.HA_FENCING_DELAY_SECONDS, 0L);
    namespaceQueryAdmin = new InMemoryNamespaceAdmin();
    levelDBTableFactory = new LevelDBTableFactory(cConf);
}
Also used : InMemoryNamespaceAdmin(io.cdap.cdap.common.namespace.InMemoryNamespaceAdmin) LevelDBTableFactory(io.cdap.cdap.messaging.store.leveldb.LevelDBTableFactory) BeforeClass(org.junit.BeforeClass)

Example 3 with InMemoryNamespaceAdmin

use of io.cdap.cdap.common.namespace.InMemoryNamespaceAdmin in project cdap by caskdata.

the class UGIProviderTest method init.

@BeforeClass
public static void init() throws Exception {
    cConf = CConfiguration.create();
    cConf.set(Constants.CFG_LOCAL_DATA_DIR, TEMP_FOLDER.newFolder().getAbsolutePath());
    namespaceClient = new InMemoryNamespaceAdmin();
    // Start KDC
    miniKdc = new MiniKdc(MiniKdc.createConf(), TEMP_FOLDER.newFolder());
    miniKdc.start();
    System.setProperty("java.security.krb5.conf", miniKdc.getKrb5conf().getAbsolutePath());
    localKeytabDirPath = TEMP_FOLDER.newFolder();
    // Generate keytab
    aliceKeytabFile = createPrincipal(localKeytabDirPath, "alice");
    bobKeytabFile = createPrincipal(localKeytabDirPath, "bob");
    eveKeytabFile = createPrincipal(localKeytabDirPath, "eve");
    // construct Kerberos PrincipalIds
    aliceKerberosPrincipalId = new KerberosPrincipalId(getPrincipal("alice"));
    bobKerberosPrincipalId = new KerberosPrincipalId(getPrincipal("bob"));
    eveKerberosPrincipalId = new KerberosPrincipalId(getPrincipal("eve"));
    // Start mini DFS cluster
    Configuration hConf = new Configuration();
    hConf.set(MiniDFSCluster.HDFS_MINIDFS_BASEDIR, TEMP_FOLDER.newFolder().getAbsolutePath());
    hConf.setBoolean("ipc.client.fallback-to-simple-auth-allowed", true);
    hConf.setBoolean("ignore.secure.ports.for.testing", true);
    miniDFSCluster = new MiniDFSCluster.Builder(hConf).numDataNodes(1).build();
    miniDFSCluster.waitClusterUp();
    locationFactory = new FileContextLocationFactory(miniDFSCluster.getFileSystem().getConf());
    hConf = new Configuration();
    hConf.set("hadoop.security.authentication", "kerberos");
    UserGroupInformation.setConfiguration(hConf);
}
Also used : MiniDFSCluster(org.apache.hadoop.hdfs.MiniDFSCluster) Configuration(org.apache.hadoop.conf.Configuration) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) InMemoryNamespaceAdmin(io.cdap.cdap.common.namespace.InMemoryNamespaceAdmin) MiniKdc(org.apache.hadoop.minikdc.MiniKdc) FileContextLocationFactory(org.apache.twill.filesystem.FileContextLocationFactory) KerberosPrincipalId(io.cdap.cdap.proto.id.KerberosPrincipalId) BeforeClass(org.junit.BeforeClass)

Example 4 with InMemoryNamespaceAdmin

use of io.cdap.cdap.common.namespace.InMemoryNamespaceAdmin in project cdap by caskdata.

the class FileSecureStoreServiceTest method setUp.

@Before
public void setUp() throws Exception {
    CConfiguration conf = CConfiguration.create();
    conf.set(Constants.Security.Store.FILE_PATH, TEMP_FOLDER.newFolder().getAbsolutePath());
    SConfiguration sConf = SConfiguration.create();
    sConf.set(Constants.Security.Store.FILE_PASSWORD, "secret");
    InMemoryNamespaceAdmin namespaceClient = new InMemoryNamespaceAdmin();
    NamespaceMeta namespaceMeta = new NamespaceMeta.Builder().setName(NAMESPACE1).build();
    namespaceClient.create(namespaceMeta);
    namespaceMeta = new NamespaceMeta.Builder().setName(NAMESPACE2).build();
    namespaceClient.create(namespaceMeta);
    FileSecureStoreService fileSecureStoreService = new FileSecureStoreService(conf, sConf, namespaceClient);
    secureStoreManager = fileSecureStoreService;
    secureStore = fileSecureStoreService;
}
Also used : InMemoryNamespaceAdmin(io.cdap.cdap.common.namespace.InMemoryNamespaceAdmin) NamespaceMeta(io.cdap.cdap.proto.NamespaceMeta) SConfiguration(io.cdap.cdap.common.conf.SConfiguration) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) Before(org.junit.Before)

Example 5 with InMemoryNamespaceAdmin

use of io.cdap.cdap.common.namespace.InMemoryNamespaceAdmin in project cdap by caskdata.

the class RemoteSecureStoreTest method setUp.

@BeforeClass
public static void setUp() throws Exception {
    CConfiguration conf = CConfiguration.create();
    conf.setBoolean(Constants.Security.SSL.INTERNAL_ENABLED, true);
    conf.set(Constants.Security.Store.FILE_PATH, TEMP_FOLDER.newFolder().getAbsolutePath());
    SConfiguration sConf = SConfiguration.create();
    sConf.set(Constants.Security.Store.FILE_PASSWORD, "secret");
    InMemoryNamespaceAdmin namespaceClient = new InMemoryNamespaceAdmin();
    NamespaceMeta namespaceMeta = new NamespaceMeta.Builder().setName(NAMESPACE1).build();
    namespaceClient.create(namespaceMeta);
    FileSecureStoreService fileSecureStoreService = new FileSecureStoreService(conf, sConf, namespaceClient);
    // Starts a mock server to handle remote secure store requests
    httpService = new HttpsEnabler().configureKeyStore(conf, sConf).enable(NettyHttpService.builder("remoteSecureStoreTest").setHttpHandlers(new SecureStoreHandler(fileSecureStoreService, fileSecureStoreService)).setExceptionHandler(new HttpExceptionHandler())).build();
    httpService.start();
    InMemoryDiscoveryService discoveryService = new InMemoryDiscoveryService();
    discoveryService.register(URIScheme.HTTPS.createDiscoverable(Constants.Service.SECURE_STORE_SERVICE, httpService.getBindAddress()));
    RemoteClientFactory remoteClientFactory = new RemoteClientFactory(discoveryService, new DefaultInternalAuthenticator(new AuthenticationTestContext()));
    remoteSecureStore = new RemoteSecureStore(remoteClientFactory);
}
Also used : RemoteClientFactory(io.cdap.cdap.common.internal.remote.RemoteClientFactory) FileSecureStoreService(io.cdap.cdap.security.store.FileSecureStoreService) AuthenticationTestContext(io.cdap.cdap.security.auth.context.AuthenticationTestContext) HttpExceptionHandler(io.cdap.cdap.common.HttpExceptionHandler) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) DefaultInternalAuthenticator(io.cdap.cdap.common.internal.remote.DefaultInternalAuthenticator) InMemoryNamespaceAdmin(io.cdap.cdap.common.namespace.InMemoryNamespaceAdmin) NamespaceMeta(io.cdap.cdap.proto.NamespaceMeta) SConfiguration(io.cdap.cdap.common.conf.SConfiguration) HttpsEnabler(io.cdap.cdap.common.security.HttpsEnabler) SecureStoreHandler(io.cdap.cdap.security.store.SecureStoreHandler) InMemoryDiscoveryService(org.apache.twill.discovery.InMemoryDiscoveryService) BeforeClass(org.junit.BeforeClass)

Aggregations

InMemoryNamespaceAdmin (io.cdap.cdap.common.namespace.InMemoryNamespaceAdmin)8 BeforeClass (org.junit.BeforeClass)7 CConfiguration (io.cdap.cdap.common.conf.CConfiguration)5 NamespaceMeta (io.cdap.cdap.proto.NamespaceMeta)4 SConfiguration (io.cdap.cdap.common.conf.SConfiguration)2 DefaultInternalAuthenticator (io.cdap.cdap.common.internal.remote.DefaultInternalAuthenticator)2 RemoteClientFactory (io.cdap.cdap.common.internal.remote.RemoteClientFactory)2 AuthenticationTestContext (io.cdap.cdap.security.auth.context.AuthenticationTestContext)2 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 AllProgramsApp (io.cdap.cdap.AllProgramsApp)1 ConfigTestApp (io.cdap.cdap.ConfigTestApp)1 ApplicationSpecification (io.cdap.cdap.api.app.ApplicationSpecification)1 ProgramType (io.cdap.cdap.api.app.ProgramType)1 ApplicationClass (io.cdap.cdap.api.artifact.ApplicationClass)1 ArtifactClasses (io.cdap.cdap.api.artifact.ArtifactClasses)1 ArtifactInfo (io.cdap.cdap.api.artifact.ArtifactInfo)1 ArtifactManager (io.cdap.cdap.api.artifact.ArtifactManager)1 CloseableClassLoader (io.cdap.cdap.api.artifact.CloseableClassLoader)1