Search in sources :

Example 36 with ArtifactSummary

use of co.cask.cdap.api.artifact.ArtifactSummary in project cdap by caskdata.

the class ProgramLifecycleHttpHandlerTest method testHistory.

private void testHistory(Class<?> app, Id.Program program) throws Exception {
    String namespace = program.getNamespaceId();
    try {
        deploy(app, Constants.Gateway.API_VERSION_3_TOKEN, namespace);
        verifyProgramHistory(program.toEntityId());
    } catch (Exception e) {
        LOG.error("Got exception: ", e);
    } finally {
        deleteApp(program.getApplication(), 200);
    }
    ApplicationId appId = new ApplicationId(namespace, program.getApplicationId(), VERSION1);
    ProgramId programId = appId.program(program.getType(), program.getId());
    try {
        Id.Artifact artifactId = Id.Artifact.from(program.getNamespace(), app.getSimpleName(), "1.0.0");
        addAppArtifact(artifactId, app);
        AppRequest<Config> request = new AppRequest<>(new ArtifactSummary(artifactId.getName(), artifactId.getVersion().getVersion()), null);
        Assert.assertEquals(200, deploy(appId, request).getStatusLine().getStatusCode());
        verifyProgramHistory(programId);
    } catch (Exception e) {
        LOG.error("Got exception: ", e);
    } finally {
        deleteApp(appId, 200);
    }
}
Also used : ArtifactSummary(co.cask.cdap.api.artifact.ArtifactSummary) Config(co.cask.cdap.api.Config) ConsumerConfig(co.cask.cdap.data2.queue.ConsumerConfig) Id(co.cask.cdap.proto.Id) ProgramId(co.cask.cdap.proto.id.ProgramId) NamespaceId(co.cask.cdap.proto.id.NamespaceId) StreamId(co.cask.cdap.proto.id.StreamId) ApplicationId(co.cask.cdap.proto.id.ApplicationId) ApplicationId(co.cask.cdap.proto.id.ApplicationId) ProgramId(co.cask.cdap.proto.id.ProgramId) IOException(java.io.IOException) NotFoundException(co.cask.cdap.common.NotFoundException) AppRequest(co.cask.cdap.proto.artifact.AppRequest)

Example 37 with ArtifactSummary

use of co.cask.cdap.api.artifact.ArtifactSummary in project cdap by caskdata.

the class ApplicationDetail method fromSpec.

public static ApplicationDetail fromSpec(ApplicationSpecification spec, @Nullable String ownerPrincipal) {
    List<ProgramRecord> programs = new ArrayList<>();
    for (ProgramSpecification programSpec : spec.getFlows().values()) {
        programs.add(new ProgramRecord(ProgramType.FLOW, spec.getName(), programSpec.getName(), programSpec.getDescription()));
    }
    for (ProgramSpecification programSpec : spec.getMapReduce().values()) {
        programs.add(new ProgramRecord(ProgramType.MAPREDUCE, spec.getName(), programSpec.getName(), programSpec.getDescription()));
    }
    for (ProgramSpecification programSpec : spec.getServices().values()) {
        programs.add(new ProgramRecord(ProgramType.SERVICE, spec.getName(), programSpec.getName(), programSpec.getDescription()));
    }
    for (ProgramSpecification programSpec : spec.getSpark().values()) {
        programs.add(new ProgramRecord(ProgramType.SPARK, spec.getName(), programSpec.getName(), programSpec.getDescription()));
    }
    for (ProgramSpecification programSpec : spec.getWorkers().values()) {
        programs.add(new ProgramRecord(ProgramType.WORKER, spec.getName(), programSpec.getName(), programSpec.getDescription()));
    }
    for (ProgramSpecification programSpec : spec.getWorkflows().values()) {
        programs.add(new ProgramRecord(ProgramType.WORKFLOW, spec.getName(), programSpec.getName(), programSpec.getDescription()));
    }
    List<StreamDetail> streams = new ArrayList<>();
    for (StreamSpecification streamSpec : spec.getStreams().values()) {
        streams.add(new StreamDetail(streamSpec.getName()));
    }
    List<DatasetDetail> datasets = new ArrayList<>();
    for (DatasetCreationSpec datasetSpec : spec.getDatasets().values()) {
        datasets.add(new DatasetDetail(datasetSpec.getInstanceName(), datasetSpec.getTypeName()));
    }
    List<PluginDetail> plugins = new ArrayList<>();
    for (Map.Entry<String, Plugin> pluginEnty : spec.getPlugins().entrySet()) {
        plugins.add(new PluginDetail(pluginEnty.getKey(), pluginEnty.getValue().getPluginClass().getName(), pluginEnty.getValue().getPluginClass().getType()));
    }
    // this is only required if there are old apps lying around that failed to get upgrading during
    // the upgrade to v3.2 for some reason. In those cases artifact id will be null until they re-deploy the app.
    // in the meantime, we don't want this api call to null pointer exception.
    ArtifactSummary summary = spec.getArtifactId() == null ? new ArtifactSummary(spec.getName(), null) : ArtifactSummary.from(spec.getArtifactId());
    return new ApplicationDetail(spec.getName(), spec.getAppVersion(), spec.getDescription(), spec.getConfiguration(), streams, datasets, programs, plugins, summary, ownerPrincipal);
}
Also used : ProgramSpecification(co.cask.cdap.api.ProgramSpecification) StreamSpecification(co.cask.cdap.api.data.stream.StreamSpecification) ArrayList(java.util.ArrayList) ArtifactSummary(co.cask.cdap.api.artifact.ArtifactSummary) DatasetCreationSpec(co.cask.cdap.internal.dataset.DatasetCreationSpec) Map(java.util.Map) Plugin(co.cask.cdap.api.plugin.Plugin)

Example 38 with ArtifactSummary

use of co.cask.cdap.api.artifact.ArtifactSummary in project cdap by caskdata.

the class AuthorizationTest method testMRStreamAuth.

@Test
@Category(SlowTests.class)
public void testMRStreamAuth() throws Exception {
    createAuthNamespace();
    Authorizer authorizer = getAuthorizer();
    ApplicationManager appManager = deployApplication(AUTH_NAMESPACE, StreamAuthApp.class);
    // After deploy, change Alice from ALL to ADMIN on the namespace
    authorizer.revoke(AUTH_NAMESPACE, ALICE, EnumSet.allOf(Action.class));
    authorizer.grant(AUTH_NAMESPACE, ALICE, EnumSet.of(Action.ADMIN));
    StreamManager streamManager = getStreamManager(AUTH_NAMESPACE.stream(StreamAuthApp.STREAM));
    streamManager.send("Hello");
    final MapReduceManager mrManager = appManager.getMapReduceManager(StreamAuthApp.MAPREDUCE);
    mrManager.start();
    // Since Alice had full permissions, she should be able to execute the MR job successfully
    mrManager.waitForRun(ProgramRunStatus.COMPLETED, 1, TimeUnit.MINUTES);
    DataSetManager<KeyValueTable> kvManager = getDataset(AUTH_NAMESPACE.dataset(StreamAuthApp.KVTABLE));
    try (KeyValueTable kvTable = kvManager.get()) {
        byte[] value = kvTable.read("Hello");
        Assert.assertArrayEquals(Bytes.toBytes("Hello"), value);
    }
    ProgramId mrId = AUTH_NAMESPACE.app(StreamAuthApp.APP).mr(StreamAuthApp.MAPREDUCE);
    authorizer.grant(mrId.getNamespaceId(), BOB, ImmutableSet.of(Action.ADMIN));
    ArtifactSummary artifactSummary = appManager.getInfo().getArtifact();
    ArtifactId artifactId = AUTH_NAMESPACE.artifact(artifactSummary.getName(), artifactSummary.getVersion());
    authorizer.grant(artifactId, BOB, EnumSet.allOf(Action.class));
    authorizer.grant(mrId.getParent(), BOB, EnumSet.allOf(Action.class));
    authorizer.grant(mrId, BOB, EnumSet.allOf(Action.class));
    authorizer.grant(AUTH_NAMESPACE.stream(StreamAuthApp.STREAM), BOB, EnumSet.of(Action.ADMIN));
    authorizer.grant(AUTH_NAMESPACE.dataset(StreamAuthApp.KVTABLE), BOB, EnumSet.allOf(Action.class));
    streamManager.send("World");
    // Switch user to Bob. Note that he doesn't have READ access on the stream.
    SecurityRequestContext.setUserId(BOB.getName());
    mrManager.start();
    mrManager.waitForRun(ProgramRunStatus.FAILED, 1, TimeUnit.MINUTES);
    kvManager = getDataset(AUTH_NAMESPACE.dataset(StreamAuthApp.KVTABLE));
    try (KeyValueTable kvTable = kvManager.get()) {
        byte[] value = kvTable.read("World");
        Assert.assertNull(value);
    }
    // Now grant Bob, READ access on the stream. MR job should execute successfully now.
    authorizer.grant(AUTH_NAMESPACE.stream(StreamAuthApp.STREAM), BOB, ImmutableSet.of(Action.READ));
    mrManager.start();
    mrManager.waitForRuns(ProgramRunStatus.COMPLETED, 2, 1, TimeUnit.MINUTES);
    kvManager = getDataset(AUTH_NAMESPACE.dataset(StreamAuthApp.KVTABLE));
    try (KeyValueTable kvTable = kvManager.get()) {
        byte[] value = kvTable.read("World");
        Assert.assertEquals("World", Bytes.toString(value));
    }
    SecurityRequestContext.setUserId(ALICE.getName());
    appManager.delete();
    assertNoAccess(AUTH_NAMESPACE.app(StreamAuthApp.APP));
}
Also used : ApplicationManager(co.cask.cdap.test.ApplicationManager) Action(co.cask.cdap.proto.security.Action) ArtifactSummary(co.cask.cdap.api.artifact.ArtifactSummary) MapReduceManager(co.cask.cdap.test.MapReduceManager) ArtifactId(co.cask.cdap.proto.id.ArtifactId) StreamManager(co.cask.cdap.test.StreamManager) KeyValueTable(co.cask.cdap.api.dataset.lib.KeyValueTable) InMemoryAuthorizer(co.cask.cdap.security.authorization.InMemoryAuthorizer) Authorizer(co.cask.cdap.security.spi.authorization.Authorizer) ProgramId(co.cask.cdap.proto.id.ProgramId) Category(org.junit.experimental.categories.Category) Test(org.junit.Test)

Example 39 with ArtifactSummary

use of co.cask.cdap.api.artifact.ArtifactSummary 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)

Example 40 with ArtifactSummary

use of co.cask.cdap.api.artifact.ArtifactSummary in project cdap by caskdata.

the class ServiceClientTestRun method deployApp.

/**
   * Deploy app of given version
   */
private void deployApp(ApplicationId app) throws Exception {
    AppRequest createRequest = new AppRequest<>(new ArtifactSummary(artifactId.getArtifact(), artifactId.getVersion()));
    appClient.deploy(app, createRequest);
}
Also used : ArtifactSummary(co.cask.cdap.api.artifact.ArtifactSummary) AppRequest(co.cask.cdap.proto.artifact.AppRequest)

Aggregations

ArtifactSummary (co.cask.cdap.api.artifact.ArtifactSummary)59 Test (org.junit.Test)34 ApplicationId (co.cask.cdap.proto.id.ApplicationId)31 AppRequest (co.cask.cdap.proto.artifact.AppRequest)28 Id (co.cask.cdap.proto.Id)21 NamespaceId (co.cask.cdap.proto.id.NamespaceId)21 ArtifactId (co.cask.cdap.proto.id.ArtifactId)18 ProgramId (co.cask.cdap.proto.id.ProgramId)13 IOException (java.io.IOException)10 ApplicationManager (co.cask.cdap.test.ApplicationManager)9 HashMap (java.util.HashMap)8 StreamId (co.cask.cdap.proto.id.StreamId)7 HashSet (java.util.HashSet)7 ArtifactRange (co.cask.cdap.api.artifact.ArtifactRange)6 ArtifactVersion (co.cask.cdap.api.artifact.ArtifactVersion)6 PluginInfo (co.cask.cdap.proto.artifact.PluginInfo)6 JsonObject (com.google.gson.JsonObject)6 File (java.io.File)6 URL (java.net.URL)6 NotFoundException (co.cask.cdap.common.NotFoundException)5