use of io.cdap.cdap.api.artifact.ArtifactId in project cdap by caskdata.
the class ProgramNotificationSubscriberServiceTest method testAppSpecNotRequiredToWriteState.
@Test
public void testAppSpecNotRequiredToWriteState() throws Exception {
ProgramId programId = NamespaceId.DEFAULT.app("someapp").program(ProgramType.SERVICE, "s");
Map<String, String> systemArguments = new HashMap<>();
systemArguments.put(ProgramOptionConstants.SKIP_PROVISIONING, Boolean.TRUE.toString());
systemArguments.put(SystemArguments.PROFILE_NAME, ProfileId.NATIVE.getScopedName());
ProgramOptions programOptions = new SimpleProgramOptions(programId, new BasicArguments(systemArguments), new BasicArguments());
ProgramRunId runId = programId.run(RunIds.generate());
ArtifactId artifactId = NamespaceId.DEFAULT.artifact("testArtifact", "1.0").toApiArtifactId();
ApplicationSpecification appSpec = new DefaultApplicationSpecification("name", "1.0.0", ProjectInfo.getVersion().toString(), "desc", null, artifactId, Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap());
ProgramDescriptor programDescriptor = new ProgramDescriptor(programId, appSpec);
programStateWriter.start(runId, programOptions, null, programDescriptor);
Tasks.waitFor(ProgramRunStatus.STARTING, () -> TransactionRunners.run(transactionRunner, context -> {
AppMetadataStore metadataStoreDataset = AppMetadataStore.create(context);
RunRecordDetail meta = metadataStoreDataset.getRun(runId);
if (meta == null) {
return null;
}
Assert.assertEquals(artifactId, meta.getArtifactId());
return meta.getStatus();
}), 10, TimeUnit.SECONDS);
programStateWriter.completed(runId);
}
use of io.cdap.cdap.api.artifact.ArtifactId in project cdap by caskdata.
the class PluginInstantiatorTest method testResourceOrder.
/**
* If a plugin has some resources in main jar and in libraries, main jar should take precedence
*/
@Test
public void testResourceOrder() throws IOException {
File appDir = TMP_FOLDER.newFolder();
File pluginsDir = TMP_FOLDER.newFolder();
File pluginDir = TMP_FOLDER.newFolder();
File pluginArchive = TMP_FOLDER.newFile();
File jarDir = TMP_FOLDER.newFolder();
ArtifactId artifactId = new ArtifactId("dummy", new ArtifactVersion("1.0"), ArtifactScope.USER);
CConfiguration cConf = CConfiguration.create();
cConf.set(Constants.CFG_LOCAL_DATA_DIR, TMP_FOLDER.newFolder().getAbsolutePath());
ProgramClassLoader programClassLoader = new ProgramClassLoader(cConf, appDir, this.getClass().getClassLoader());
PluginInstantiator pluginInstantiator = new PluginInstantiator(cConf, programClassLoader, pluginsDir);
FileUtils.write(new File(jarDir, "test.class"), "jarData");
FileUtils.write(new File(pluginDir, "test.class"), "pluginData");
BundleJarUtil.createJar(jarDir, new File(pluginDir, "library.jar"));
BundleJarUtil.createJar(pluginDir, pluginArchive);
pluginInstantiator.addArtifact(Locations.toLocation(pluginArchive), artifactId);
PluginClassLoader loader = pluginInstantiator.getPluginClassLoader(artifactId, Collections.emptyList());
Assert.assertEquals("pluginData", IOUtils.toString(loader.getResource("test.class")));
pluginInstantiator.close();
}
use of io.cdap.cdap.api.artifact.ArtifactId 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.ArtifactId in project cdap by caskdata.
the class SupportBundleServiceTest method testSupportBundleService.
@Test
@Ignore
public void testSupportBundleService() throws Exception {
deploy(AppWithWorkflow.class, 200, Constants.Gateway.API_VERSION_3_TOKEN, namespaceId.getNamespace());
long startTime = System.currentTimeMillis();
ProgramId workflowProgram = new ProgramId(namespaceId.getNamespace(), AppWithWorkflow.NAME, ProgramType.WORKFLOW, AppWithWorkflow.SampleWorkflow.NAME);
RunId workflowRunId = RunIds.generate(startTime);
ArtifactId artifactId = namespaceId.artifact("testArtifact", "1.0").toApiArtifactId();
setStartAndRunning(workflowProgram, workflowRunId.getId(), artifactId);
List<RunRecord> runs = getProgramRuns(workflowProgram, ProgramRunStatus.RUNNING);
Assert.assertEquals(1, runs.size());
HttpResponse appsResponse = doGet(getVersionedAPIPath("apps/", Constants.Gateway.API_VERSION_3_TOKEN, namespaceId.getNamespace()));
Assert.assertEquals(200, appsResponse.getResponseCode());
// workflow ran for 1 minute
long workflowStopTime = TimeUnit.MILLISECONDS.toSeconds(startTime) + 60;
store.setStop(workflowProgram.run(workflowRunId.getId()), workflowStopTime, ProgramRunStatus.COMPLETED, SupportBundleTestHelper.createSourceId(++sourceId));
SupportBundleConfiguration supportBundleConfiguration = new SupportBundleConfiguration(namespaceId.getNamespace(), AppWithWorkflow.NAME, workflowRunId.getId(), ProgramType.valueOfCategoryName("workflows"), AppWithWorkflow.SampleWorkflow.NAME, 1);
String uuid = supportBundleService.generateSupportBundle(supportBundleConfiguration);
Assert.assertNotNull(uuid);
File tempFolder = new File(configuration.get(Constants.SupportBundle.LOCAL_DATA_DIR));
File uuidFile = new File(tempFolder, uuid);
Tasks.waitFor(CollectionState.FINISHED, () -> {
SupportBundleStatus supportBundleStatus = supportBundleService.getSingleBundleJson(uuidFile);
if (supportBundleStatus == null || supportBundleStatus.getStatus() == null) {
return CollectionState.INVALID;
}
return supportBundleStatus.getStatus();
}, 60, TimeUnit.SECONDS, 1, TimeUnit.SECONDS);
SupportBundleStatus supportBundleStatus = supportBundleService.getSingleBundleJson(uuidFile);
Set<SupportBundleTaskStatus> supportBundleTaskStatusList = supportBundleStatus.getTasks();
Assert.assertEquals(uuid, supportBundleStatus.getBundleId());
Assert.assertEquals(CollectionState.FINISHED, supportBundleStatus.getStatus());
for (SupportBundleTaskStatus supportBundleTaskStatus : supportBundleTaskStatusList) {
Assert.assertEquals(CollectionState.FINISHED, supportBundleTaskStatus.getStatus());
}
}
use of io.cdap.cdap.api.artifact.ArtifactId in project cdap by caskdata.
the class SupportBundleSystemLogTaskTest method generateWorkflowLog.
private String generateWorkflowLog() throws Exception {
deploy(AppWithWorkflow.class, 200, Constants.Gateway.API_VERSION_3_TOKEN, namespaceId.getNamespace());
long startTime = System.currentTimeMillis();
ProgramId workflowProgram = new ProgramId(namespaceId.getNamespace(), AppWithWorkflow.NAME, ProgramType.WORKFLOW, AppWithWorkflow.SampleWorkflow.NAME);
RunId workflowRunId = RunIds.generate(startTime);
ArtifactId artifactId = namespaceId.artifact("testArtifact", "1.0").toApiArtifactId();
setStartAndRunning(workflowProgram, workflowRunId.getId(), artifactId);
List<RunRecord> runs = getProgramRuns(workflowProgram, ProgramRunStatus.RUNNING);
Assert.assertEquals(1, runs.size());
HttpResponse appsResponse = doGet(getVersionedAPIPath("apps/", Constants.Gateway.API_VERSION_3_TOKEN, namespaceId.getNamespace()));
Assert.assertEquals(200, appsResponse.getResponseCode());
// workflow ran for 1 minute
long workflowStopTime = TimeUnit.MILLISECONDS.toSeconds(startTime) + 60;
store.setStop(workflowProgram.run(workflowRunId.getId()), workflowStopTime, ProgramRunStatus.COMPLETED, SupportBundleTestHelper.createSourceId(++sourceId));
return runs.get(0).getPid();
}
Aggregations