Search in sources :

Example 66 with ArtifactVersion

use of io.cdap.cdap.api.artifact.ArtifactVersion in project cdap by caskdata.

the class ReportGenerationAppTest method populateMetaFiles.

/**
 * Adds mock program run meta files to the given location.
 * TODO: [CDAP-13216] this method should be marked as @VisibleForTesting. Temporarily calling this method
 * when initializing report generation Spark program to add mock data
 *
 * @param metaBaseLocation the location to add files
 * @param currentTime the current time in millis
 */
private static void populateMetaFiles(Location metaBaseLocation, Long currentTime) throws Exception {
    DatumWriter<GenericRecord> datumWriter = new GenericDatumWriter<>(ProgramRunInfoSerializer.SCHEMA);
    DataFileWriter<GenericRecord> dataFileWriter = new DataFileWriter<>(datumWriter);
    String appName = "Pipeline";
    String version = "-SNAPSHOT";
    String type = "WORKFLOW";
    String program1 = "SmartWorkflow_1";
    String program2 = "SmartWorkflow_2";
    // add a schedule info with program status trigger
    String scheduleInfo = "{\"name\": \"sched\",\"description\": \"desc\",\"triggerInfos\": [" + "{\"namespace\": \"default\",\"application\": \"app\",\"version\": \"-SNAPSHOT\",\"programType\": \"WORKFLOW\"," + "\"run\":\"randomRunId\",\"entity\": \"PROGRAM\",\"program\": \"wf\",\"programStatus\": \"KILLED\"," + "\"type\": \"PROGRAM_STATUS\"}]}";
    ProgramStartInfo startInfo = new ProgramStartInfo(ImmutableMap.of(), new ArtifactId(TEST_ARTIFACT_NAME, new ArtifactVersion("1.0.0"), ArtifactScope.USER), USER_ALICE, ImmutableMap.of(Constants.Notification.SCHEDULE_INFO_KEY, scheduleInfo));
    long delay = TimeUnit.MINUTES.toMillis(5);
    int mockMessageId = 0;
    for (String namespace : ImmutableList.of("default", "ns1", "ns2")) {
        Location nsLocation = metaBaseLocation.append(namespace);
        nsLocation.mkdirs();
        for (int i = 0; i < 5; i++) {
            long time = currentTime + TimeUnit.HOURS.toMillis(i);
            // file name is of the format <event-time-millis>-<creation-time-millis>.avro
            Location reportLocation = nsLocation.append(String.format("%d-%d.avro", time, System.currentTimeMillis()));
            reportLocation.createNew();
            dataFileWriter.create(ProgramRunInfoSerializer.SCHEMA, reportLocation.getOutputStream());
            String run1 = ReportIds.generate().toString();
            String run2 = ReportIds.generate().toString();
            dataFileWriter.append(createRecord(namespace, appName, version, type, program1, run1, "STARTING", time, startInfo, Integer.toString(++mockMessageId)));
            dataFileWriter.append(createRecord(namespace, appName, version, type, program1, run1, "FAILED", time + delay, null, Integer.toString(++mockMessageId)));
            dataFileWriter.append(createRecord(namespace, appName, version, type, program2, run2, "STARTING", time + delay, startInfo, Integer.toString(++mockMessageId)));
            dataFileWriter.append(createRecord(namespace, appName, version, type, program2, run2, "RUNNING", time + 2 * delay, null, Integer.toString(++mockMessageId)));
            dataFileWriter.append(createRecord(namespace, appName, version, type, program2, run2, "COMPLETED", time + 4 * delay, null, Integer.toString(++mockMessageId)));
            dataFileWriter.close();
        }
        LOG.debug("nsLocation.list() = {}", nsLocation.list());
    }
}
Also used : ArtifactVersion(io.cdap.cdap.api.artifact.ArtifactVersion) ArtifactId(io.cdap.cdap.api.artifact.ArtifactId) DataFileWriter(org.apache.avro.file.DataFileWriter) GenericDatumWriter(org.apache.avro.generic.GenericDatumWriter) ProgramStartInfo(io.cdap.cdap.report.main.ProgramStartInfo) GenericRecord(org.apache.avro.generic.GenericRecord) Location(org.apache.twill.filesystem.Location)

Example 67 with ArtifactVersion

use of io.cdap.cdap.api.artifact.ArtifactVersion in project cdap by caskdata.

the class AbstractTestManager method toRange.

private Set<ArtifactRange> toRange(ArtifactId parent) {
    Set<ArtifactRange> parents = new HashSet<>();
    parents.add(new ArtifactRange(parent.getParent().getNamespace(), parent.getArtifact(), new ArtifactVersion(parent.getVersion()), true, new ArtifactVersion(parent.getVersion()), true));
    return parents;
}
Also used : ArtifactVersion(io.cdap.cdap.api.artifact.ArtifactVersion) ArtifactRange(io.cdap.cdap.api.artifact.ArtifactRange) HashSet(java.util.HashSet)

Aggregations

ArtifactVersion (io.cdap.cdap.api.artifact.ArtifactVersion)67 Test (org.junit.Test)47 ArtifactRange (io.cdap.cdap.api.artifact.ArtifactRange)38 ArtifactId (io.cdap.cdap.api.artifact.ArtifactId)30 NamespaceId (io.cdap.cdap.proto.id.NamespaceId)28 Id (io.cdap.cdap.common.id.Id)22 PluginClass (io.cdap.cdap.api.plugin.PluginClass)19 ArtifactId (io.cdap.cdap.proto.id.ArtifactId)19 File (java.io.File)18 Manifest (java.util.jar.Manifest)13 Set (java.util.Set)11 Location (org.apache.twill.filesystem.Location)11 ApplicationClass (io.cdap.cdap.api.artifact.ApplicationClass)10 HashSet (java.util.HashSet)10 ArtifactNotFoundException (io.cdap.cdap.common.ArtifactNotFoundException)9 ImmutableSet (com.google.common.collect.ImmutableSet)8 ArtifactSummary (io.cdap.cdap.api.artifact.ArtifactSummary)8 PluginNotExistsException (io.cdap.cdap.internal.app.runtime.plugin.PluginNotExistsException)8 Gson (com.google.gson.Gson)7 ArtifactVersionRange (io.cdap.cdap.api.artifact.ArtifactVersionRange)7