Search in sources :

Example 1 with LocalLocationFactory

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

the class MapReduceTaskContextProvider method createProgram.

/**
   * Creates a {@link Program} instance based on the information from the {@link MapReduceContextConfig}, using
   * the given program ClassLoader.
   */
private Program createProgram(MapReduceContextConfig contextConfig, ClassLoader programClassLoader) {
    Location programLocation;
    LocationFactory locationFactory = new LocalLocationFactory();
    if (isLocal(contextConfig.getHConf())) {
        // Just create a local location factory. It's for temp usage only as the program location is always absolute.
        programLocation = locationFactory.create(contextConfig.getProgramJarURI());
    } else {
        // In distributed mode, the program jar is localized to the container
        programLocation = locationFactory.create(new File(contextConfig.getProgramJarName()).getAbsoluteFile().toURI());
    }
    return new DefaultProgram(new ProgramDescriptor(contextConfig.getProgramId(), contextConfig.getApplicationSpecification()), programLocation, programClassLoader);
}
Also used : DefaultProgram(co.cask.cdap.app.program.DefaultProgram) ProgramDescriptor(co.cask.cdap.app.program.ProgramDescriptor) LocalLocationFactory(org.apache.twill.filesystem.LocalLocationFactory) File(java.io.File) Location(org.apache.twill.filesystem.Location) LocalLocationFactory(org.apache.twill.filesystem.LocalLocationFactory) LocationFactory(org.apache.twill.filesystem.LocationFactory)

Example 2 with LocalLocationFactory

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

the class DefaultSecureStoreServiceTest method createCConf.

private static CConfiguration createCConf() throws Exception {
    CConfiguration cConf = CConfiguration.create();
    cConf.set(Constants.CFG_LOCAL_DATA_DIR, TEMPORARY_FOLDER.newFolder().getAbsolutePath());
    cConf.setBoolean(Constants.Security.ENABLED, true);
    cConf.setBoolean(Constants.Security.Authorization.ENABLED, true);
    // we only want to test authorization, but we don't specify principal/keytab, so disable kerberos
    cConf.setBoolean(Constants.Security.KERBEROS_ENABLED, false);
    cConf.setInt(Constants.Security.Authorization.CACHE_MAX_ENTRIES, 0);
    LocationFactory locationFactory = new LocalLocationFactory(TEMPORARY_FOLDER.newFolder());
    Location authorizerJar = AppJarHelper.createDeploymentJar(locationFactory, InMemoryAuthorizer.class);
    cConf.set(Constants.Security.Authorization.EXTENSION_JAR_PATH, authorizerJar.toURI().getPath());
    // set secure store provider
    cConf.set(Constants.Security.Store.PROVIDER, "file");
    return cConf;
}
Also used : CConfiguration(co.cask.cdap.common.conf.CConfiguration) LocalLocationFactory(org.apache.twill.filesystem.LocalLocationFactory) LocalLocationFactory(org.apache.twill.filesystem.LocalLocationFactory) LocationFactory(org.apache.twill.filesystem.LocationFactory) Location(org.apache.twill.filesystem.Location)

Example 3 with LocalLocationFactory

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

the class ProgramLifecycleServiceAuthorizationTest method createCConf.

private static CConfiguration createCConf() throws IOException {
    CConfiguration cConf = CConfiguration.create();
    cConf.setBoolean(Constants.Security.ENABLED, true);
    cConf.setBoolean(Constants.Security.Authorization.ENABLED, true);
    // we only want to test authorization, but we don't specify principal/keytab, so disable kerberos
    cConf.setBoolean(Constants.Security.KERBEROS_ENABLED, false);
    cConf.setInt(Constants.Security.Authorization.CACHE_MAX_ENTRIES, 0);
    LocationFactory locationFactory = new LocalLocationFactory(new File(TEMPORARY_FOLDER.newFolder().toURI()));
    Location authorizerJar = AppJarHelper.createDeploymentJar(locationFactory, InMemoryAuthorizer.class);
    cConf.set(Constants.Security.Authorization.EXTENSION_JAR_PATH, authorizerJar.toURI().getPath());
    return cConf;
}
Also used : CConfiguration(co.cask.cdap.common.conf.CConfiguration) LocalLocationFactory(org.apache.twill.filesystem.LocalLocationFactory) File(java.io.File) LocalLocationFactory(org.apache.twill.filesystem.LocalLocationFactory) LocationFactory(org.apache.twill.filesystem.LocationFactory) Location(org.apache.twill.filesystem.Location)

Example 4 with LocalLocationFactory

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

the class AuthorizationBootstrapperTest method setup.

@BeforeClass
public static void setup() throws Exception {
    CConfiguration cConf = CConfiguration.create();
    cConf.set(Constants.CFG_LOCAL_DATA_DIR, TMP_FOLDER.newFolder().getAbsolutePath());
    cConf.setBoolean(Constants.Security.ENABLED, true);
    cConf.setBoolean(Constants.Security.KERBEROS_ENABLED, false);
    cConf.setBoolean(Constants.Security.Authorization.ENABLED, true);
    Location deploymentJar = AppJarHelper.createDeploymentJar(new LocalLocationFactory(TMP_FOLDER.newFolder()), InMemoryAuthorizer.class);
    cConf.set(Constants.Security.Authorization.EXTENSION_JAR_PATH, deploymentJar.toURI().getPath());
    // make Alice an admin user, so she can create namespaces
    cConf.set(Constants.Security.Authorization.ADMIN_USERS, ADMIN_USER.getName());
    instanceId = new InstanceId(cConf.get(Constants.INSTANCE_NAME));
    // setup a system artifact
    File systemArtifactsDir = TMP_FOLDER.newFolder();
    cConf.set(Constants.AppFabric.SYSTEM_ARTIFACTS_DIR, systemArtifactsDir.getAbsolutePath());
    createSystemArtifact(systemArtifactsDir);
    Injector injector = Guice.createInjector(new AppFabricTestModule(cConf));
    namespaceQueryAdmin = injector.getInstance(NamespaceQueryAdmin.class);
    namespaceAdmin = injector.getInstance(NamespaceAdmin.class);
    defaultNamespaceEnsurer = new DefaultNamespaceEnsurer(namespaceAdmin);
    discoveryServiceClient = injector.getInstance(DiscoveryServiceClient.class);
    txManager = injector.getInstance(TransactionManager.class);
    datasetService = injector.getInstance(DatasetService.class);
    systemArtifactLoader = injector.getInstance(SystemArtifactLoader.class);
    authorizationBootstrapper = injector.getInstance(AuthorizationBootstrapper.class);
    artifactRepository = injector.getInstance(ArtifactRepository.class);
    dsFramework = injector.getInstance(DatasetFramework.class);
    authorizationEnforcer = injector.getInstance(AuthorizationEnforcer.class);
}
Also used : DiscoveryServiceClient(org.apache.twill.discovery.DiscoveryServiceClient) InstanceId(co.cask.cdap.proto.id.InstanceId) NamespaceAdmin(co.cask.cdap.common.namespace.NamespaceAdmin) DatasetService(co.cask.cdap.data2.datafabric.dataset.service.DatasetService) ArtifactRepository(co.cask.cdap.internal.app.runtime.artifact.ArtifactRepository) AuthorizationEnforcer(co.cask.cdap.security.spi.authorization.AuthorizationEnforcer) DefaultNamespaceEnsurer(co.cask.cdap.internal.app.namespace.DefaultNamespaceEnsurer) CConfiguration(co.cask.cdap.common.conf.CConfiguration) DatasetFramework(co.cask.cdap.data2.dataset2.DatasetFramework) AuthorizationBootstrapper(co.cask.cdap.security.authorization.AuthorizationBootstrapper) Injector(com.google.inject.Injector) TransactionManager(org.apache.tephra.TransactionManager) SystemArtifactLoader(co.cask.cdap.internal.app.runtime.artifact.SystemArtifactLoader) NamespaceQueryAdmin(co.cask.cdap.common.namespace.NamespaceQueryAdmin) AppFabricTestModule(co.cask.cdap.internal.guice.AppFabricTestModule) LocalLocationFactory(org.apache.twill.filesystem.LocalLocationFactory) File(java.io.File) Location(org.apache.twill.filesystem.Location) BeforeClass(org.junit.BeforeClass)

Example 5 with LocalLocationFactory

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

the class AuthorizationBootstrapperTest method createAppJar.

private static void createAppJar(Class<?> cls, File destFile, Manifest manifest) throws IOException {
    Location deploymentJar = AppJarHelper.createDeploymentJar(new LocalLocationFactory(TMP_FOLDER.newFolder()), cls, manifest);
    DirUtils.mkdirs(destFile.getParentFile());
    Files.copy(Locations.newInputSupplier(deploymentJar), destFile);
}
Also used : LocalLocationFactory(org.apache.twill.filesystem.LocalLocationFactory) Location(org.apache.twill.filesystem.Location)

Aggregations

LocalLocationFactory (org.apache.twill.filesystem.LocalLocationFactory)41 Location (org.apache.twill.filesystem.Location)29 LocationFactory (org.apache.twill.filesystem.LocationFactory)21 File (java.io.File)15 CConfiguration (co.cask.cdap.common.conf.CConfiguration)11 BeforeClass (org.junit.BeforeClass)11 Test (org.junit.Test)11 NamespacedLocationFactory (co.cask.cdap.common.namespace.NamespacedLocationFactory)5 ApplicationSpecification (co.cask.cdap.api.app.ApplicationSpecification)4 NamespaceAdmin (co.cask.cdap.common.namespace.NamespaceAdmin)4 ArtifactRepository (co.cask.cdap.internal.app.runtime.artifact.ArtifactRepository)4 ReflectionSchemaGenerator (co.cask.cdap.internal.io.ReflectionSchemaGenerator)4 Injector (com.google.inject.Injector)4 ApplicationSpecificationAdapter (co.cask.cdap.internal.app.ApplicationSpecificationAdapter)3 URL (java.net.URL)3 CloseableClassLoader (co.cask.cdap.api.artifact.CloseableClassLoader)2 ConfigResponse (co.cask.cdap.app.deploy.ConfigResponse)2 Configurator (co.cask.cdap.app.deploy.Configurator)2 DummyProgramRunnerFactory (co.cask.cdap.app.runtime.DummyProgramRunnerFactory)2 StreamAdmin (co.cask.cdap.data2.transaction.stream.StreamAdmin)2