Search in sources :

Example 11 with FileContextLocationFactory

use of org.apache.twill.filesystem.FileContextLocationFactory in project cdap by caskdata.

the class SparkPackageUtils method resolveURI.

/**
   * Resolves a {@link URI} representation from the given {@link Location}. It resolves the URI in the same way
   * as Spark does.
   */
private static URI resolveURI(Location location) throws IOException {
    LocationFactory locationFactory = location.getLocationFactory();
    while (locationFactory instanceof ForwardingLocationFactory) {
        locationFactory = ((ForwardingLocationFactory) locationFactory).getDelegate();
    }
    if (!(locationFactory instanceof FileContextLocationFactory)) {
        return location.toURI();
    }
    // Resolves the URI the way as Spark does
    Configuration hConf = ((FileContextLocationFactory) locationFactory).getConfiguration();
    org.apache.hadoop.fs.Path path = new org.apache.hadoop.fs.Path(location.toURI().getPath());
    path = path.getFileSystem(hConf).makeQualified(path);
    return ((FileContextLocationFactory) locationFactory).getFileContext().resolvePath(path).toUri();
}
Also used : Path(java.nio.file.Path) Configuration(org.apache.hadoop.conf.Configuration) FileContextLocationFactory(org.apache.twill.filesystem.FileContextLocationFactory) ForwardingLocationFactory(org.apache.twill.filesystem.ForwardingLocationFactory) ForwardingLocationFactory(org.apache.twill.filesystem.ForwardingLocationFactory) LocationFactory(org.apache.twill.filesystem.LocationFactory) FileContextLocationFactory(org.apache.twill.filesystem.FileContextLocationFactory)

Example 12 with FileContextLocationFactory

use of org.apache.twill.filesystem.FileContextLocationFactory in project cdap by caskdata.

the class DFSMultiLiveStreamFileReaderTest method init.

@BeforeClass
public static void init() throws IOException {
    Configuration hConf = new Configuration();
    hConf.set(MiniDFSCluster.HDFS_MINIDFS_BASEDIR, TMP_FOLDER.newFolder().getAbsolutePath());
    dfsCluster = new MiniDFSCluster.Builder(hConf).numDataNodes(1).build();
    dfsCluster.waitClusterUp();
    locationFactory = new FileContextLocationFactory(dfsCluster.getFileSystem().getConf());
}
Also used : MiniDFSCluster(org.apache.hadoop.hdfs.MiniDFSCluster) Configuration(org.apache.hadoop.conf.Configuration) FileContextLocationFactory(org.apache.twill.filesystem.FileContextLocationFactory) BeforeClass(org.junit.BeforeClass)

Example 13 with FileContextLocationFactory

use of org.apache.twill.filesystem.FileContextLocationFactory in project cdap by caskdata.

the class DFSStreamFileJanitorTest method init.

@BeforeClass
public static void init() throws IOException {
    Configuration hConf = new Configuration();
    hConf.set(MiniDFSCluster.HDFS_MINIDFS_BASEDIR, tmpFolder.newFolder().getAbsolutePath());
    dfsCluster = new MiniDFSCluster.Builder(hConf).numDataNodes(1).build();
    dfsCluster.waitClusterUp();
    namespaceAdmin = new InMemoryNamespaceClient();
    final LocationFactory lf = new FileContextLocationFactory(dfsCluster.getFileSystem().getConf());
    final NamespacedLocationFactory nlf = new DefaultNamespacedLocationFactory(cConf, lf, namespaceAdmin);
    Injector injector = Guice.createInjector(new ConfigModule(cConf, hConf), new ZKClientModule(), new AbstractModule() {

        @Override
        protected void configure() {
            bind(LocationFactory.class).toInstance(lf);
            bind(NamespacedLocationFactory.class).toInstance(nlf);
            bind(NamespaceAdmin.class).toInstance(namespaceAdmin);
            bind(NamespaceQueryAdmin.class).to(SimpleNamespaceQueryAdmin.class);
            bind(UGIProvider.class).to(RemoteUGIProvider.class);
            bind(OwnerAdmin.class).to(DefaultOwnerAdmin.class);
        }
    }, new TransactionMetricsModule(), new DiscoveryRuntimeModule().getInMemoryModules(), new DataFabricModules().getDistributedModules(), Modules.override(new DataSetsModules().getDistributedModules()).with(new AbstractModule() {

        @Override
        protected void configure() {
            bind(MetadataStore.class).to(NoOpMetadataStore.class);
            // bind to an in memory implementation for this test since the DefaultOwnerStore uses transaction and in this
            // test we are not starting a transaction service
            bind(OwnerStore.class).to(InMemoryOwnerStore.class).in(Scopes.SINGLETON);
        }
    }), new ExploreClientModule(), new ViewAdminModules().getInMemoryModules(), Modules.override(new StreamAdminModules().getDistributedModules()).with(new AbstractModule() {

        @Override
        protected void configure() {
            // Tests are running in same process, hence no need to have ZK to coordinate
            bind(StreamCoordinatorClient.class).to(InMemoryStreamCoordinatorClient.class).in(Scopes.SINGLETON);
            bind(StreamMetaStore.class).to(InMemoryStreamMetaStore.class);
        }
    }), new AbstractModule() {

        @Override
        protected void configure() {
            // We don't need notification in this test, hence inject an no-op one
            bind(NotificationFeedManager.class).to(NoOpNotificationFeedManager.class);
            bind(NamespaceStore.class).to(InMemoryNamespaceStore.class);
        }
    }, new AuthorizationTestModule(), new AuthorizationEnforcementModule().getInMemoryModules(), new AuthenticationContextModules().getMasterModule());
    locationFactory = injector.getInstance(LocationFactory.class);
    namespacedLocationFactory = injector.getInstance(NamespacedLocationFactory.class);
    namespaceStore = injector.getInstance(NamespaceStore.class);
    streamAdmin = injector.getInstance(StreamAdmin.class);
    fileWriterFactory = injector.getInstance(StreamFileWriterFactory.class);
    streamCoordinatorClient = injector.getInstance(StreamCoordinatorClient.class);
    streamCoordinatorClient.startAndWait();
}
Also used : CConfiguration(co.cask.cdap.common.conf.CConfiguration) Configuration(org.apache.hadoop.conf.Configuration) ConfigModule(co.cask.cdap.common.guice.ConfigModule) InMemoryNamespaceClient(co.cask.cdap.common.namespace.InMemoryNamespaceClient) FileContextLocationFactory(org.apache.twill.filesystem.FileContextLocationFactory) NamespacedLocationFactory(co.cask.cdap.common.namespace.NamespacedLocationFactory) DefaultNamespacedLocationFactory(co.cask.cdap.common.namespace.DefaultNamespacedLocationFactory) TransactionMetricsModule(co.cask.cdap.data.runtime.TransactionMetricsModule) ViewAdminModules(co.cask.cdap.data.view.ViewAdminModules) ZKClientModule(co.cask.cdap.common.guice.ZKClientModule) Injector(com.google.inject.Injector) StreamMetaStore(co.cask.cdap.data.stream.service.StreamMetaStore) InMemoryStreamMetaStore(co.cask.cdap.data.stream.service.InMemoryStreamMetaStore) SimpleNamespaceQueryAdmin(co.cask.cdap.common.namespace.SimpleNamespaceQueryAdmin) DiscoveryRuntimeModule(co.cask.cdap.common.guice.DiscoveryRuntimeModule) MiniDFSCluster(org.apache.hadoop.hdfs.MiniDFSCluster) AuthenticationContextModules(co.cask.cdap.security.auth.context.AuthenticationContextModules) DataSetsModules(co.cask.cdap.data.runtime.DataSetsModules) NamespaceStore(co.cask.cdap.store.NamespaceStore) InMemoryNamespaceStore(co.cask.cdap.store.InMemoryNamespaceStore) DefaultOwnerAdmin(co.cask.cdap.security.impersonation.DefaultOwnerAdmin) AuthorizationTestModule(co.cask.cdap.security.authorization.AuthorizationTestModule) InMemoryOwnerStore(co.cask.cdap.security.impersonation.InMemoryOwnerStore) NamespacedLocationFactory(co.cask.cdap.common.namespace.NamespacedLocationFactory) DefaultNamespacedLocationFactory(co.cask.cdap.common.namespace.DefaultNamespacedLocationFactory) LocationFactory(org.apache.twill.filesystem.LocationFactory) FileContextLocationFactory(org.apache.twill.filesystem.FileContextLocationFactory) AbstractModule(com.google.inject.AbstractModule) MetadataStore(co.cask.cdap.data2.metadata.store.MetadataStore) NoOpMetadataStore(co.cask.cdap.data2.metadata.store.NoOpMetadataStore) StreamAdmin(co.cask.cdap.data2.transaction.stream.StreamAdmin) RemoteUGIProvider(co.cask.cdap.security.impersonation.RemoteUGIProvider) ExploreClientModule(co.cask.cdap.explore.guice.ExploreClientModule) NoOpNotificationFeedManager(co.cask.cdap.notifications.feeds.service.NoOpNotificationFeedManager) DefaultNamespacedLocationFactory(co.cask.cdap.common.namespace.DefaultNamespacedLocationFactory) DataFabricModules(co.cask.cdap.data.runtime.DataFabricModules) InMemoryNamespaceStore(co.cask.cdap.store.InMemoryNamespaceStore) AuthorizationEnforcementModule(co.cask.cdap.security.authorization.AuthorizationEnforcementModule) BeforeClass(org.junit.BeforeClass)

Aggregations

Configuration (org.apache.hadoop.conf.Configuration)13 FileContextLocationFactory (org.apache.twill.filesystem.FileContextLocationFactory)13 MiniDFSCluster (org.apache.hadoop.hdfs.MiniDFSCluster)9 BeforeClass (org.junit.BeforeClass)9 LocationFactory (org.apache.twill.filesystem.LocationFactory)7 CConfiguration (co.cask.cdap.common.conf.CConfiguration)4 ConfigModule (co.cask.cdap.common.guice.ConfigModule)3 NamespacedLocationFactory (co.cask.cdap.common.namespace.NamespacedLocationFactory)3 Injector (com.google.inject.Injector)3 DiscoveryRuntimeModule (co.cask.cdap.common.guice.DiscoveryRuntimeModule)2 ZKClientModule (co.cask.cdap.common.guice.ZKClientModule)2 InMemoryNamespaceClient (co.cask.cdap.common.namespace.InMemoryNamespaceClient)2 NamespacedLocationFactoryTestClient (co.cask.cdap.common.namespace.NamespacedLocationFactoryTestClient)2 SimpleNamespaceQueryAdmin (co.cask.cdap.common.namespace.SimpleNamespaceQueryAdmin)2 DataFabricModules (co.cask.cdap.data.runtime.DataFabricModules)2 DataSetsModules (co.cask.cdap.data.runtime.DataSetsModules)2 TransactionMetricsModule (co.cask.cdap.data.runtime.TransactionMetricsModule)2 InMemoryStreamMetaStore (co.cask.cdap.data.stream.service.InMemoryStreamMetaStore)2 StreamMetaStore (co.cask.cdap.data.stream.service.StreamMetaStore)2 ViewAdminModules (co.cask.cdap.data.view.ViewAdminModules)2