Search in sources :

Example 51 with Location

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

the class CoprocessorManager method getCoprocessorDescriptor.

/**
   * Get the descriptor for a single coprocessor that uses the pre-built coprocessor jar.
   */
public CoprocessorDescriptor getCoprocessorDescriptor(Class<? extends Coprocessor> coprocessor, @Nullable Integer priority) throws IOException {
    if (priority == null) {
        priority = Coprocessor.PRIORITY_USER;
    }
    Location jarFile = ensureCoprocessorExists();
    String jarPath = manageCoprocessors ? jarFile.toURI().getPath() : null;
    return new CoprocessorDescriptor(coprocessor.getName(), jarPath, priority, null);
}
Also used : CoprocessorDescriptor(co.cask.cdap.spi.hbase.CoprocessorDescriptor) Location(org.apache.twill.filesystem.Location)

Example 52 with Location

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

the class IntegrationTestManager method createModuleJarFile.

private File createModuleJarFile(Class<?> cls) throws IOException {
    String version = String.format("1.0.%d-SNAPSHOT", System.currentTimeMillis());
    File moduleJarFile = new File(tmpFolder, String.format("%s-%s.jar", cls.getSimpleName(), version));
    Location deploymentJar = AppJarHelper.createDeploymentJar(locationFactory, cls, new Manifest(), CLASS_ACCEPTOR);
    Files.copy(Locations.newInputSupplier(deploymentJar), moduleJarFile);
    return moduleJarFile;
}
Also used : Manifest(java.util.jar.Manifest) File(java.io.File) Location(org.apache.twill.filesystem.Location)

Example 53 with Location

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

the class IntegrationTestManager method addPluginArtifact.

@Override
public ArtifactManager addPluginArtifact(ArtifactId artifactId, Set<ArtifactRange> parents, Class<?> pluginClass, Class<?>... pluginClasses) throws Exception {
    Manifest manifest = createManifest(pluginClass, pluginClasses);
    final Location appJar = PluginJarHelper.createPluginJar(locationFactory, manifest, pluginClass, pluginClasses);
    artifactClient.add(artifactId, parents, new InputSupplier<InputStream>() {

        @Override
        public InputStream getInput() throws IOException {
            return appJar.getInputStream();
        }
    });
    appJar.delete();
    return new RemoteArtifactManager(clientConfig, restClient, artifactId);
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) RemoteArtifactManager(co.cask.cdap.test.remote.RemoteArtifactManager) IOException(java.io.IOException) Manifest(java.util.jar.Manifest) Location(org.apache.twill.filesystem.Location)

Example 54 with Location

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

the class IntegrationTestManager method deployApplication.

@Override
@SuppressWarnings("unchecked")
public ApplicationManager deployApplication(NamespaceId namespace, Class<? extends Application> applicationClz, @Nullable Config configObject, File... bundleEmbeddedJars) {
    // See if the application class comes from file or jar.
    // If it's from JAR, no need to trace dependency since it should already be in an application jar.
    URL appClassURL = applicationClz.getClassLoader().getResource(applicationClz.getName().replace('.', '/') + ".class");
    // Should never happen, otherwise the ClassLoader is broken
    Preconditions.checkNotNull(appClassURL, "Cannot find class %s from the classloader", applicationClz);
    String appConfig = "";
    Type configType = Artifacts.getConfigType(applicationClz);
    try {
        if (configObject != null) {
            appConfig = GSON.toJson(configObject);
        } else {
            configObject = (Config) TypeToken.of(configType).getRawType().newInstance();
        }
        // Create and deploy application jar
        File appJarFile = new File(tmpFolder, String.format("%s-1.0.0-SNAPSHOT.jar", applicationClz.getSimpleName()));
        try {
            if ("jar".equals(appClassURL.getProtocol())) {
                copyJarFile(appClassURL, appJarFile);
            } else {
                Location appJar = AppJarHelper.createDeploymentJar(locationFactory, applicationClz, new Manifest(), CLASS_ACCEPTOR, bundleEmbeddedJars);
                Files.copy(Locations.newInputSupplier(appJar), appJarFile);
            }
            applicationClient.deploy(namespace, appJarFile, appConfig);
        } finally {
            if (!appJarFile.delete()) {
                LOG.warn("Failed to delete temporary app jar {}", appJarFile.getAbsolutePath());
            }
        }
        // Extracts application id from the application class
        Application application = applicationClz.newInstance();
        MockAppConfigurer configurer = new MockAppConfigurer(application);
        application.configure(configurer, new DefaultApplicationContext<>(configObject));
        String applicationId = configurer.getName();
        return new RemoteApplicationManager(namespace.app(applicationId), clientConfig, restClient);
    } catch (Exception e) {
        throw Throwables.propagate(e);
    }
}
Also used : Type(java.lang.reflect.Type) RemoteApplicationManager(co.cask.cdap.test.remote.RemoteApplicationManager) MockAppConfigurer(co.cask.cdap.app.MockAppConfigurer) Manifest(java.util.jar.Manifest) File(java.io.File) Application(co.cask.cdap.api.app.Application) URL(java.net.URL) IOException(java.io.IOException) Location(org.apache.twill.filesystem.Location)

Example 55 with Location

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

the class IntegrationTestManager method addAppArtifact.

@Override
public ArtifactManager addAppArtifact(ArtifactId artifactId, Class<?> appClass, Manifest manifest) throws Exception {
    final Location appJar = AppJarHelper.createDeploymentJar(locationFactory, appClass, manifest, CLASS_ACCEPTOR);
    artifactClient.add(artifactId, null, new InputSupplier<InputStream>() {

        @Override
        public InputStream getInput() throws IOException {
            return appJar.getInputStream();
        }
    });
    appJar.delete();
    return new RemoteArtifactManager(clientConfig, restClient, artifactId);
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) RemoteArtifactManager(co.cask.cdap.test.remote.RemoteArtifactManager) IOException(java.io.IOException) Location(org.apache.twill.filesystem.Location)

Aggregations

Location (org.apache.twill.filesystem.Location)246 Test (org.junit.Test)104 IOException (java.io.IOException)57 File (java.io.File)39 LocalLocationFactory (org.apache.twill.filesystem.LocalLocationFactory)29 LocationFactory (org.apache.twill.filesystem.LocationFactory)29 FileSet (co.cask.cdap.api.dataset.lib.FileSet)28 StreamEvent (co.cask.cdap.api.flow.flowlet.StreamEvent)27 PartitionedFileSet (co.cask.cdap.api.dataset.lib.PartitionedFileSet)23 CConfiguration (co.cask.cdap.common.conf.CConfiguration)19 NamespaceId (co.cask.cdap.proto.id.NamespaceId)19 Manifest (java.util.jar.Manifest)18 HashMap (java.util.HashMap)17 StreamId (co.cask.cdap.proto.id.StreamId)16 OutputStream (java.io.OutputStream)15 DatasetFramework (co.cask.cdap.data2.dataset2.DatasetFramework)13 TimePartitionedFileSet (co.cask.cdap.api.dataset.lib.TimePartitionedFileSet)11 StreamConfig (co.cask.cdap.data2.transaction.stream.StreamConfig)10 ArrayList (java.util.ArrayList)9 StreamAdmin (co.cask.cdap.data2.transaction.stream.StreamAdmin)8