Search in sources :

Example 11 with ArtifactId

use of co.cask.cdap.proto.id.ArtifactId in project cdap by caskdata.

the class TestFrameworkTestRun method testAppFromArtifact.

@Test
public void testAppFromArtifact() throws Exception {
    ArtifactId artifactId = NamespaceId.DEFAULT.artifact("cfg-app", "1.0.0-SNAPSHOT");
    addAppArtifact(artifactId, ConfigTestApp.class);
    ApplicationId appId = NamespaceId.DEFAULT.app("AppFromArtifact");
    AppRequest<ConfigTestApp.ConfigClass> createRequest = new AppRequest<>(new ArtifactSummary(artifactId.getArtifact(), artifactId.getVersion()), new ConfigTestApp.ConfigClass("testStream", "testDataset"));
    ApplicationManager appManager = deployApplication(appId, createRequest);
    testAppConfig(appId.getApplication(), appManager, createRequest.getConfig());
}
Also used : ApplicationManager(co.cask.cdap.test.ApplicationManager) ArtifactSummary(co.cask.cdap.api.artifact.ArtifactSummary) ArtifactId(co.cask.cdap.proto.id.ArtifactId) ApplicationId(co.cask.cdap.proto.id.ApplicationId) ConfigTestApp(co.cask.cdap.ConfigTestApp) AppRequest(co.cask.cdap.proto.artifact.AppRequest) Test(org.junit.Test)

Example 12 with ArtifactId

use of co.cask.cdap.proto.id.ArtifactId in project cdap by caskdata.

the class TestFrameworkTestBase method deployWithArtifact.

/**
 * Deploys an {@link Application} using the given artifact jar with an optional config object.
 */
protected static <T> ApplicationManager deployWithArtifact(NamespaceId namespaceId, Class<? extends Application> appClass, File artifactJar, @Nullable T config) throws Exception {
    ArtifactId artifactId = new ArtifactId(namespaceId.getNamespace(), appClass.getSimpleName(), "1.0-SNAPSHOT");
    addArtifact(artifactId, artifactJar);
    AppRequest<T> appRequest = new AppRequest<>(new ArtifactSummary(artifactId.getArtifact(), artifactId.getVersion()), config);
    return deployApplication(namespaceId.app(appClass.getSimpleName()), appRequest);
}
Also used : ArtifactSummary(co.cask.cdap.api.artifact.ArtifactSummary) ArtifactId(co.cask.cdap.proto.id.ArtifactId) AppRequest(co.cask.cdap.proto.artifact.AppRequest)

Example 13 with ArtifactId

use of co.cask.cdap.proto.id.ArtifactId in project cdap by caskdata.

the class LocalArtifactLoaderStage method process.

/**
 * Instantiates the Application class and calls configure() on it to generate the {@link ApplicationSpecification}.
 *
 * @param deploymentInfo information needed to deploy the application, such as the artifact to create it from
 *                       and the application config to use.
 */
@Override
public void process(AppDeploymentInfo deploymentInfo) throws Exception {
    ArtifactId artifactId = deploymentInfo.getArtifactId();
    Location artifactLocation = deploymentInfo.getArtifactLocation();
    String appClassName = deploymentInfo.getAppClassName();
    String appVersion = deploymentInfo.getApplicationVersion();
    String configString = deploymentInfo.getConfigString();
    EntityImpersonator classLoaderImpersonator = new EntityImpersonator(artifactId, impersonator);
    ClassLoader artifactClassLoader = artifactRepository.createArtifactClassLoader(artifactLocation, classLoaderImpersonator);
    getContext().setProperty(LocalApplicationManager.ARTIFACT_CLASSLOADER_KEY, artifactClassLoader);
    InMemoryConfigurator inMemoryConfigurator = new InMemoryConfigurator(cConf, Id.Namespace.fromEntityId(deploymentInfo.getNamespaceId()), Id.Artifact.fromEntityId(artifactId), appClassName, artifactRepository, artifactClassLoader, deploymentInfo.getApplicationName(), deploymentInfo.getApplicationVersion(), configString);
    ListenableFuture<ConfigResponse> result = inMemoryConfigurator.config();
    ConfigResponse response = result.get(120, TimeUnit.SECONDS);
    if (response.getExitCode() != 0) {
        throw new IllegalArgumentException("Failed to configure application: " + deploymentInfo);
    }
    ApplicationSpecification specification = adapter.fromJson(response.get());
    ApplicationId applicationId;
    if (appVersion == null) {
        applicationId = deploymentInfo.getNamespaceId().app(specification.getName());
    } else {
        applicationId = deploymentInfo.getNamespaceId().app(specification.getName(), appVersion);
    }
    authorizationEnforcer.enforce(applicationId, authenticationContext.getPrincipal(), Action.ADMIN);
    emit(new ApplicationDeployable(deploymentInfo.getArtifactId(), deploymentInfo.getArtifactLocation(), applicationId, specification, store.getApplication(applicationId), ApplicationDeployScope.USER, deploymentInfo.getOwnerPrincipal(), deploymentInfo.canUpdateSchedules()));
}
Also used : ApplicationSpecification(co.cask.cdap.api.app.ApplicationSpecification) ArtifactId(co.cask.cdap.proto.id.ArtifactId) EntityImpersonator(co.cask.cdap.security.impersonation.EntityImpersonator) ConfigResponse(co.cask.cdap.app.deploy.ConfigResponse) ApplicationId(co.cask.cdap.proto.id.ApplicationId) InMemoryConfigurator(co.cask.cdap.internal.app.deploy.InMemoryConfigurator) Location(org.apache.twill.filesystem.Location)

Example 14 with ArtifactId

use of co.cask.cdap.proto.id.ArtifactId in project cdap by caskdata.

the class AuditPublishTest method testPublish.

@Test
public void testPublish() throws Exception {
    String defaultNs = NamespaceId.DEFAULT.getNamespace();
    String appName = WordCountApp.class.getSimpleName();
    // Define expected values
    Set<? extends EntityId> expectedMetadataChangeEntities = ImmutableSet.of(Ids.namespace(defaultNs).artifact(WordCountApp.class.getSimpleName(), "1"), Ids.namespace(defaultNs).app(appName), Ids.namespace(defaultNs).app(appName).flow(WordCountApp.WordCountFlow.class.getSimpleName()), Ids.namespace(defaultNs).app(appName).mr(WordCountApp.VoidMapReduceJob.class.getSimpleName()), Ids.namespace(defaultNs).app(appName).service(WordCountApp.WordFrequencyService.class.getSimpleName()), Ids.namespace(defaultNs).dataset("mydataset"), Ids.namespace(defaultNs).stream("text"));
    Multimap<AuditType, EntityId> expectedAuditEntities = HashMultimap.create();
    expectedAuditEntities.putAll(AuditType.METADATA_CHANGE, expectedMetadataChangeEntities);
    expectedAuditEntities.putAll(AuditType.CREATE, ImmutableSet.of(Ids.namespace(defaultNs).dataset("mydataset"), Ids.namespace(defaultNs).stream("text")));
    // Deploy application
    AppFabricTestHelper.deployApplication(Id.Namespace.DEFAULT, WordCountApp.class, null, cConf);
    // Verify audit messages
    List<AuditMessage> publishedMessages = fetchAuditMessages();
    Multimap<AuditType, EntityId> actualAuditEntities = HashMultimap.create();
    for (AuditMessage message : publishedMessages) {
        EntityId entityId = message.getEntityId();
        if (entityId instanceof NamespacedEntityId) {
            if (((NamespacedEntityId) entityId).getNamespace().equals(NamespaceId.SYSTEM.getNamespace())) {
                // Ignore system audit messages
                continue;
            }
        }
        if (entityId.getEntityType() == EntityType.ARTIFACT && entityId instanceof ArtifactId) {
            ArtifactId artifactId = (ArtifactId) entityId;
            // Version is dynamic for deploys in test cases
            entityId = Ids.namespace(artifactId.getNamespace()).artifact(artifactId.getArtifact(), "1");
        }
        actualAuditEntities.put(message.getType(), entityId);
    }
    Assert.assertEquals(expectedAuditEntities, actualAuditEntities);
}
Also used : NamespacedEntityId(co.cask.cdap.proto.id.NamespacedEntityId) EntityId(co.cask.cdap.proto.id.EntityId) AuditMessage(co.cask.cdap.proto.audit.AuditMessage) NamespacedEntityId(co.cask.cdap.proto.id.NamespacedEntityId) ArtifactId(co.cask.cdap.proto.id.ArtifactId) AuditType(co.cask.cdap.proto.audit.AuditType) WordCountApp(co.cask.cdap.WordCountApp) Test(org.junit.Test)

Example 15 with ArtifactId

use of co.cask.cdap.proto.id.ArtifactId in project cdap by caskdata.

the class DataQualityAppTest method setup.

@BeforeClass
public static void setup() throws Exception {
    appArtifact = NamespaceId.DEFAULT.artifact("dqArtifact", "1.0");
    addAppArtifact(appArtifact, DataQualityApp.class, BatchSource.class.getPackage().getName(), PipelineConfigurer.class.getPackage().getName());
    ArtifactId pluginArtifactId = NamespaceId.DEFAULT.artifact("source-plugin", "1.0.0-SNAPSHOT");
    addPluginArtifact(pluginArtifactId, appArtifact, StreamBatchSource.class, AvroKey.class, GenericRecord.class);
}
Also used : ArtifactId(co.cask.cdap.proto.id.ArtifactId) BeforeClass(org.junit.BeforeClass)

Aggregations

ArtifactId (co.cask.cdap.proto.id.ArtifactId)105 Test (org.junit.Test)45 NamespaceId (co.cask.cdap.proto.id.NamespaceId)40 IOException (java.io.IOException)29 Path (javax.ws.rs.Path)29 ArtifactSummary (co.cask.cdap.api.artifact.ArtifactSummary)24 ApplicationId (co.cask.cdap.proto.id.ApplicationId)22 ArtifactVersion (co.cask.cdap.api.artifact.ArtifactVersion)15 PluginClass (co.cask.cdap.api.plugin.PluginClass)15 ArtifactRange (co.cask.cdap.api.artifact.ArtifactRange)14 AppRequest (co.cask.cdap.proto.artifact.AppRequest)14 ProgramId (co.cask.cdap.proto.id.ProgramId)14 ArtifactNotFoundException (co.cask.cdap.common.ArtifactNotFoundException)13 File (java.io.File)13 Id (co.cask.cdap.common.id.Id)11 AuditPolicy (co.cask.cdap.common.security.AuditPolicy)11 Map (java.util.Map)10 BadRequestException (co.cask.cdap.common.BadRequestException)9 ArtifactInfo (co.cask.cdap.api.artifact.ArtifactInfo)8 ArtifactDetail (co.cask.cdap.internal.app.runtime.artifact.ArtifactDetail)8