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());
}
}
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;
}
Aggregations