Search in sources :

Example 6 with Application

use of co.cask.cdap.api.app.Application in project cdap by caskdata.

the class UnitTestManager method deployApplication.

@Override
public ApplicationManager deployApplication(NamespaceId namespace, Class<? extends Application> applicationClz, @Nullable Config configObject, File... bundleEmbeddedJars) {
    Preconditions.checkNotNull(applicationClz, "Application class cannot be null.");
    Type configType = Artifacts.getConfigType(applicationClz);
    try {
        ArtifactId artifactId = new ArtifactId(namespace.getNamespace(), applicationClz.getSimpleName(), "1.0-SNAPSHOT");
        addAppArtifact(artifactId, applicationClz);
        if (configObject == null) {
            configObject = (Config) TypeToken.of(configType).getRawType().newInstance();
        }
        Application app = applicationClz.newInstance();
        MockAppConfigurer configurer = new MockAppConfigurer(app);
        app.configure(configurer, new DefaultApplicationContext<>(configObject));
        ApplicationId applicationId = new ApplicationId(namespace.getNamespace(), configurer.getName());
        ArtifactSummary artifactSummary = new ArtifactSummary(artifactId.getArtifact(), artifactId.getVersion());
        appFabricClient.deployApplication(applicationId.toId(), new AppRequest(artifactSummary, configObject));
        return appManagerFactory.create(applicationId);
    } catch (Exception e) {
        throw Throwables.propagate(e);
    }
}
Also used : Type(java.lang.reflect.Type) MockAppConfigurer(co.cask.cdap.app.MockAppConfigurer) ArtifactSummary(co.cask.cdap.api.artifact.ArtifactSummary) ArtifactId(co.cask.cdap.proto.id.ArtifactId) ApplicationId(co.cask.cdap.proto.id.ApplicationId) Application(co.cask.cdap.api.app.Application) TransactionFailureException(org.apache.tephra.TransactionFailureException) IOException(java.io.IOException) AppRequest(co.cask.cdap.proto.artifact.AppRequest)

Aggregations

Application (co.cask.cdap.api.app.Application)6 IOException (java.io.IOException)3 Config (co.cask.cdap.api.Config)2 AbstractApplication (co.cask.cdap.api.app.AbstractApplication)2 MockAppConfigurer (co.cask.cdap.app.MockAppConfigurer)2 Type (java.lang.reflect.Type)2 Manifest (java.util.jar.Manifest)2 ApplicationContext (co.cask.cdap.api.app.ApplicationContext)1 ApplicationSpecification (co.cask.cdap.api.app.ApplicationSpecification)1 ApplicationClass (co.cask.cdap.api.artifact.ApplicationClass)1 ArtifactSummary (co.cask.cdap.api.artifact.ArtifactSummary)1 ArtifactVersion (co.cask.cdap.api.artifact.ArtifactVersion)1 Schema (co.cask.cdap.api.data.schema.Schema)1 UnsupportedTypeException (co.cask.cdap.api.data.schema.UnsupportedTypeException)1 PluginConfig (co.cask.cdap.api.plugin.PluginConfig)1 DefaultAppConfigurer (co.cask.cdap.app.DefaultAppConfigurer)1 ConfigResponse (co.cask.cdap.app.deploy.ConfigResponse)1 DistributedSparkProgramRunner (co.cask.cdap.app.runtime.spark.distributed.DistributedSparkProgramRunner)1 InvalidArtifactException (co.cask.cdap.common.InvalidArtifactException)1 ReflectionSchemaGenerator (co.cask.cdap.internal.io.ReflectionSchemaGenerator)1