Search in sources :

Example 61 with ArtifactSummary

use of io.cdap.cdap.api.artifact.ArtifactSummary in project cdap by cdapio.

the class ProgramLifecycleHttpHandlerTest method testSchedules.

@Test
public void testSchedules() throws Exception {
    // deploy an app with schedule
    Id.Artifact artifactId = Id.Artifact.from(Id.Namespace.fromEntityId(TEST_NAMESPACE_META1.getNamespaceId()), AppWithSchedule.NAME, VERSION1);
    addAppArtifact(artifactId, AppWithSchedule.class);
    AppRequest<? extends Config> request = new AppRequest<>(new ArtifactSummary(artifactId.getName(), artifactId.getVersion().getVersion()));
    ApplicationId defaultAppId = TEST_NAMESPACE_META1.getNamespaceId().app(AppWithSchedule.NAME);
    Assert.assertEquals(200, deploy(defaultAppId, request).getResponseCode());
    // deploy another version of the app
    ApplicationId appV2Id = TEST_NAMESPACE_META1.getNamespaceId().app(AppWithSchedule.NAME, VERSION2);
    Assert.assertEquals(200, deploy(appV2Id, request).getResponseCode());
    // list schedules for default version app, for the workflow and for the app, they should be same
    List<ScheduleDetail> schedules = getSchedules(TEST_NAMESPACE1, AppWithSchedule.NAME, AppWithSchedule.WORKFLOW_NAME);
    Assert.assertEquals(1, schedules.size());
    ScheduleDetail schedule = schedules.get(0);
    Assert.assertEquals(SchedulableProgramType.WORKFLOW, schedule.getProgram().getProgramType());
    Assert.assertEquals(AppWithSchedule.WORKFLOW_NAME, schedule.getProgram().getProgramName());
    Assert.assertEquals(new TimeTrigger("0/15 * * * * ?"), schedule.getTrigger());
    // there should be two schedules now
    List<ScheduleDetail> schedulesForApp = listSchedules(TEST_NAMESPACE1, AppWithSchedule.NAME, null);
    Assert.assertEquals(1, schedulesForApp.size());
    Assert.assertEquals(schedules, schedulesForApp);
    List<ScheduleDetail> schedules2 = getSchedules(TEST_NAMESPACE1, AppWithSchedule.NAME, VERSION2, AppWithSchedule.WORKFLOW_NAME);
    Assert.assertEquals(1, schedules2.size());
    ScheduleDetail schedule2 = schedules2.get(0);
    Assert.assertEquals(SchedulableProgramType.WORKFLOW, schedule2.getProgram().getProgramType());
    Assert.assertEquals(AppWithSchedule.WORKFLOW_NAME, schedule2.getProgram().getProgramName());
    Assert.assertEquals(new TimeTrigger("0/15 * * * * ?"), schedule2.getTrigger());
    String newSchedule = "newTimeSchedule";
    testAddSchedule(newSchedule);
    testDeleteSchedule(appV2Id, newSchedule);
    testUpdateSchedule(appV2Id);
    testReEnableSchedule("reEnabledSchedule");
}
Also used : ArtifactSummary(io.cdap.cdap.api.artifact.ArtifactSummary) TimeTrigger(io.cdap.cdap.internal.app.runtime.schedule.trigger.TimeTrigger) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) ServiceId(io.cdap.cdap.proto.id.ServiceId) Id(io.cdap.cdap.common.id.Id) ProfileId(io.cdap.cdap.proto.id.ProfileId) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) ProgramId(io.cdap.cdap.proto.id.ProgramId) ScheduleDetail(io.cdap.cdap.proto.ScheduleDetail) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) AppRequest(io.cdap.cdap.proto.artifact.AppRequest) Test(org.junit.Test)

Example 62 with ArtifactSummary

use of io.cdap.cdap.api.artifact.ArtifactSummary in project cdap by cdapio.

the class ProgramLifecycleHttpHandlerTest method testHistory.

private void testHistory(Class<?> app, Id.Program program) throws Exception {
    String namespace = program.getNamespaceId();
    deploy(app, 200, Constants.Gateway.API_VERSION_3_TOKEN, namespace);
    verifyProgramHistory(program.toEntityId());
    deleteApp(program.getApplication(), 200);
    ApplicationId appId = new ApplicationId(namespace, program.getApplicationId(), VERSION1);
    ProgramId programId = appId.program(program.getType(), program.getId());
    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).getResponseCode());
    verifyProgramHistory(programId);
    deleteApp(appId, 200);
}
Also used : ArtifactSummary(io.cdap.cdap.api.artifact.ArtifactSummary) Config(io.cdap.cdap.api.Config) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) ServiceId(io.cdap.cdap.proto.id.ServiceId) Id(io.cdap.cdap.common.id.Id) ProfileId(io.cdap.cdap.proto.id.ProfileId) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) ProgramId(io.cdap.cdap.proto.id.ProgramId) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) ProgramId(io.cdap.cdap.proto.id.ProgramId) AppRequest(io.cdap.cdap.proto.artifact.AppRequest)

Example 63 with ArtifactSummary

use of io.cdap.cdap.api.artifact.ArtifactSummary in project cdap by cdapio.

the class ProgramLifecycleHttpHandlerTest method testMultipleWorkflowSchedules.

@Test
public void testMultipleWorkflowSchedules() throws Exception {
    // Deploy the app
    NamespaceId testNamespace2 = new NamespaceId(TEST_NAMESPACE2);
    Id.Namespace idTestNamespace2 = Id.Namespace.fromEntityId(testNamespace2);
    Id.Artifact artifactId = Id.Artifact.from(idTestNamespace2, "appwithmultiplescheduledworkflows", VERSION1);
    addAppArtifact(artifactId, AppWithMultipleSchedules.class);
    AppRequest<? extends Config> appRequest = new AppRequest<>(new ArtifactSummary(artifactId.getName(), artifactId.getVersion().getVersion()));
    Id.Application appDefault = new Id.Application(idTestNamespace2, AppWithMultipleSchedules.NAME);
    ApplicationId app1 = testNamespace2.app(AppWithMultipleSchedules.NAME, VERSION1);
    ApplicationId app2 = testNamespace2.app(AppWithMultipleSchedules.NAME, VERSION2);
    Assert.assertEquals(200, deploy(appDefault, appRequest).getResponseCode());
    Assert.assertEquals(200, deploy(app1, appRequest).getResponseCode());
    Assert.assertEquals(200, deploy(app2, appRequest).getResponseCode());
    // Schedule details from non-versioned API
    List<ScheduleDetail> someSchedules = getSchedules(TEST_NAMESPACE2, AppWithMultipleSchedules.NAME, AppWithMultipleSchedules.SOME_WORKFLOW);
    Assert.assertEquals(2, someSchedules.size());
    Assert.assertEquals(AppWithMultipleSchedules.SOME_WORKFLOW, someSchedules.get(0).getProgram().getProgramName());
    Assert.assertEquals(AppWithMultipleSchedules.SOME_WORKFLOW, someSchedules.get(1).getProgram().getProgramName());
    // Schedule details from non-versioned API
    List<ScheduleDetail> anotherSchedules = getSchedules(TEST_NAMESPACE2, AppWithMultipleSchedules.NAME, AppWithMultipleSchedules.ANOTHER_WORKFLOW);
    Assert.assertEquals(3, anotherSchedules.size());
    Assert.assertEquals(AppWithMultipleSchedules.ANOTHER_WORKFLOW, anotherSchedules.get(0).getProgram().getProgramName());
    Assert.assertEquals(AppWithMultipleSchedules.ANOTHER_WORKFLOW, anotherSchedules.get(1).getProgram().getProgramName());
    Assert.assertEquals(AppWithMultipleSchedules.ANOTHER_WORKFLOW, anotherSchedules.get(2).getProgram().getProgramName());
    // Schedule details from non-versioned API filtered by Trigger type
    List<ScheduleDetail> filteredTimeSchedules = getSchedules(TEST_NAMESPACE2, AppWithMultipleSchedules.NAME, AppWithMultipleSchedules.TRIGGERED_WORKFLOW, ProtoTrigger.Type.TIME);
    Assert.assertEquals(1, filteredTimeSchedules.size());
    assertProgramInSchedules(AppWithMultipleSchedules.TRIGGERED_WORKFLOW, filteredTimeSchedules);
    // Schedule details from non-versioned API filtered by Trigger type
    List<ScheduleDetail> programStatusSchedules = getSchedules(TEST_NAMESPACE2, AppWithMultipleSchedules.NAME, AppWithMultipleSchedules.TRIGGERED_WORKFLOW, ProtoTrigger.Type.PROGRAM_STATUS);
    Assert.assertEquals(4, programStatusSchedules.size());
    assertProgramInSchedules(AppWithMultipleSchedules.TRIGGERED_WORKFLOW, programStatusSchedules);
    deleteApp(appDefault, 200);
    // Schedule of app1 from versioned API
    List<ScheduleDetail> someSchedules1 = getSchedules(TEST_NAMESPACE2, AppWithMultipleSchedules.NAME, VERSION1, AppWithMultipleSchedules.SOME_WORKFLOW);
    Assert.assertEquals(2, someSchedules1.size());
    assertProgramInSchedules(AppWithMultipleSchedules.SOME_WORKFLOW, someSchedules1);
    // Schedule details from versioned API filtered by Trigger type
    filteredTimeSchedules = getSchedules(TEST_NAMESPACE2, AppWithMultipleSchedules.NAME, VERSION1, AppWithMultipleSchedules.TRIGGERED_WORKFLOW, ProtoTrigger.Type.TIME);
    Assert.assertEquals(1, filteredTimeSchedules.size());
    assertProgramInSchedules(AppWithMultipleSchedules.TRIGGERED_WORKFLOW, filteredTimeSchedules);
    // Schedule details from versioned API filtered by Trigger type
    programStatusSchedules = getSchedules(TEST_NAMESPACE2, AppWithMultipleSchedules.NAME, VERSION1, AppWithMultipleSchedules.TRIGGERED_WORKFLOW, ProtoTrigger.Type.PROGRAM_STATUS);
    Assert.assertEquals(4, programStatusSchedules.size());
    assertProgramInSchedules(AppWithMultipleSchedules.TRIGGERED_WORKFLOW, programStatusSchedules);
    // Schedules triggered by SOME_WORKFLOW's completed or failed or killed status
    ProgramId someWorkflow = app1.workflow(AppWithMultipleSchedules.SOME_WORKFLOW);
    List<ScheduleDetail> triggeredSchedules1 = listSchedulesByTriggerProgram(TEST_NAMESPACE2, someWorkflow, ProgramStatus.COMPLETED, ProgramStatus.FAILED, ProgramStatus.KILLED);
    Assert.assertEquals(3, triggeredSchedules1.size());
    assertProgramInSchedules(AppWithMultipleSchedules.TRIGGERED_WORKFLOW, triggeredSchedules1);
    List<ScheduleDetail> filteredSchedules = listSchedulesByTriggerProgram(TEST_NAMESPACE2, someWorkflow, ProgramScheduleStatus.SCHEDULED, ProgramStatus.COMPLETED, ProgramStatus.FAILED, ProgramStatus.KILLED);
    // No schedule is enabled yet
    Assert.assertEquals(0, filteredSchedules.size());
    filteredSchedules = listSchedulesByTriggerProgram(TEST_NAMESPACE2, someWorkflow, ProgramScheduleStatus.SUSPENDED, ProgramStatus.COMPLETED, ProgramStatus.FAILED, ProgramStatus.KILLED);
    // All schedules are suspended
    Assert.assertEquals(3, filteredSchedules.size());
    // Schedules triggered by SOME_WORKFLOW's completed status
    List<ScheduleDetail> triggeredByCompletedSchedules = listSchedulesByTriggerProgram(TEST_NAMESPACE2, someWorkflow, ProgramStatus.COMPLETED);
    Assert.assertEquals(2, triggeredByCompletedSchedules.size());
    assertProgramInSchedules(AppWithMultipleSchedules.TRIGGERED_WORKFLOW, triggeredByCompletedSchedules);
    // Schedules triggered by ANOTHER_WORKFLOW regardless of program status
    ProgramId anotherWorkflow = app1.workflow(AppWithMultipleSchedules.ANOTHER_WORKFLOW);
    List<ScheduleDetail> triggeredSchedules2 = listSchedulesByTriggerProgram(TEST_NAMESPACE2, anotherWorkflow);
    Assert.assertEquals(1, triggeredSchedules2.size());
    assertProgramInSchedules(AppWithMultipleSchedules.TRIGGERED_WORKFLOW, triggeredSchedules2);
    deleteApp(app1, 200);
    // Schedule detail of app2 from versioned API
    List<ScheduleDetail> anotherSchedules2 = getSchedules(TEST_NAMESPACE2, AppWithMultipleSchedules.NAME, VERSION2, AppWithMultipleSchedules.ANOTHER_WORKFLOW);
    Assert.assertEquals(3, anotherSchedules2.size());
    assertProgramInSchedules(AppWithMultipleSchedules.ANOTHER_WORKFLOW, anotherSchedules2);
    deleteApp(app2, 200);
}
Also used : ProgramId(io.cdap.cdap.proto.id.ProgramId) AppRequest(io.cdap.cdap.proto.artifact.AppRequest) ArtifactSummary(io.cdap.cdap.api.artifact.ArtifactSummary) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) ServiceId(io.cdap.cdap.proto.id.ServiceId) Id(io.cdap.cdap.common.id.Id) ProfileId(io.cdap.cdap.proto.id.ProfileId) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) ProgramId(io.cdap.cdap.proto.id.ProgramId) ScheduleDetail(io.cdap.cdap.proto.ScheduleDetail) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) Test(org.junit.Test)

Example 64 with ArtifactSummary

use of io.cdap.cdap.api.artifact.ArtifactSummary in project cdap by cdapio.

the class ApplicationDetail method fromSpec.

public static ApplicationDetail fromSpec(ApplicationSpecification spec, @Nullable String ownerPrincipal) {
    List<ProgramRecord> programs = new ArrayList<>();
    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<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(), datasets, programs, plugins, summary, ownerPrincipal);
}
Also used : ProgramSpecification(io.cdap.cdap.api.ProgramSpecification) ArrayList(java.util.ArrayList) ArtifactSummary(io.cdap.cdap.api.artifact.ArtifactSummary) DatasetCreationSpec(io.cdap.cdap.internal.dataset.DatasetCreationSpec) Map(java.util.Map) Plugin(io.cdap.cdap.api.plugin.Plugin)

Example 65 with ArtifactSummary

use of io.cdap.cdap.api.artifact.ArtifactSummary in project cdap by cdapio.

the class DraftStore method fromRow.

@SuppressWarnings("ConstantConditions")
private Draft fromRow(StructuredRow row, boolean includeConfig) {
    String id = row.getString(ID_COL);
    String name = row.getString(NAME_COL);
    String description = row.getString(DESCRIPTION_COL);
    long createTime = row.getLong(CREATED_COL);
    long updateTime = row.getLong(UPDATED_COL);
    String artifactStr = row.getString(ARTIFACT_COL);
    ArtifactSummary artifact = GSON.fromJson(artifactStr, ArtifactSummary.class);
    String configStr = row.getString(PIPELINE_COL);
    ETLConfig config = null;
    if (includeConfig) {
        if (StudioUtil.isBatchPipeline(artifact)) {
            config = GSON.fromJson(configStr, ETLBatchConfig.class);
        } else if (StudioUtil.isStreamingPipeline(artifact)) {
            config = GSON.fromJson(configStr, DataStreamsConfig.class);
        } else {
            throw new IllegalArgumentException(String.format("Failed to parse pipeline config string: %s is not a supported pipeline type", artifact.getName()));
        }
    }
    return new Draft(config, name, description, artifact, id, createTime, updateTime);
}
Also used : ETLBatchConfig(io.cdap.cdap.etl.proto.v2.ETLBatchConfig) ArtifactSummary(io.cdap.cdap.api.artifact.ArtifactSummary) ETLConfig(io.cdap.cdap.etl.proto.v2.ETLConfig)

Aggregations

ArtifactSummary (io.cdap.cdap.api.artifact.ArtifactSummary)152 ApplicationId (io.cdap.cdap.proto.id.ApplicationId)86 AppRequest (io.cdap.cdap.proto.artifact.AppRequest)80 Test (org.junit.Test)70 NamespaceId (io.cdap.cdap.proto.id.NamespaceId)48 ArtifactId (io.cdap.cdap.proto.id.ArtifactId)44 ProgramId (io.cdap.cdap.proto.id.ProgramId)44 Id (io.cdap.cdap.common.id.Id)36 ProfileId (io.cdap.cdap.proto.id.ProfileId)26 HttpResponse (io.cdap.common.http.HttpResponse)26 IOException (java.io.IOException)22 URL (java.net.URL)22 JsonObject (com.google.gson.JsonObject)18 NotFoundException (io.cdap.cdap.common.NotFoundException)18 ArtifactVersion (io.cdap.cdap.api.artifact.ArtifactVersion)16 ArtifactNotFoundException (io.cdap.cdap.common.ArtifactNotFoundException)16 File (java.io.File)16 Map (java.util.Map)16 ArtifactId (io.cdap.cdap.api.artifact.ArtifactId)14 KerberosPrincipalId (io.cdap.cdap.proto.id.KerberosPrincipalId)14