use of io.cdap.cdap.proto.id.ProgramId in project cdap by caskdata.
the class MetadataHttpHandlerTestRun method testSearchMetadataDelete.
@Test
public void testSearchMetadataDelete() throws Exception {
NamespaceId namespace = new NamespaceId("ns1");
namespaceClient.create(new NamespaceMeta.Builder().setName(namespace).build());
// Deploy app
appClient.deploy(namespace, createAppJarFile(AllProgramsApp.class, AllProgramsApp.class.getSimpleName(), "1.0"));
ArtifactId artifact = namespace.artifact(AllProgramsApp.class.getSimpleName(), "1.0");
ApplicationId app = namespace.app(AllProgramsApp.NAME);
ProgramId service = app.service(AllProgramsApp.NoOpService.NAME);
DatasetId datasetInstance = namespace.dataset(AllProgramsApp.DATASET_NAME);
// wait for metadata to be processed
Tasks.waitFor(false, () -> getProperties(app, MetadataScope.SYSTEM).isEmpty(), 10, TimeUnit.SECONDS);
Tasks.waitFor(false, () -> getProperties(service, MetadataScope.SYSTEM).isEmpty(), 10, TimeUnit.SECONDS);
Tasks.waitFor(false, () -> getProperties(datasetInstance, MetadataScope.SYSTEM).isEmpty(), 10, TimeUnit.SECONDS);
Set<String> tags = ImmutableSet.of("tag1", "tag2");
// Add metadata
addTags(app, tags);
addTags(datasetInstance, tags);
// Assert metadata
assertSearch(searchMetadata(namespace, AllProgramsApp.DATASET_NAME), datasetInstance);
assertSearch(searchMetadata(namespace, "all*"), app, artifact);
assertSearch(searchMetadata(namespace, "tag1"), app, datasetInstance);
// Delete entities
appClient.delete(app);
datasetClient.delete(datasetInstance);
artifactClient.delete(artifact);
// Assert no metadata
waitForSearch(() -> searchMetadata(namespace, AllProgramsApp.DATASET_NAME));
waitForSearch(() -> searchMetadata(namespace, "all*"));
waitForSearch(() -> searchMetadata(namespace, "tag1"));
}
use of io.cdap.cdap.proto.id.ProgramId in project cdap by caskdata.
the class UsageHandlerTestRun method testWorkerUsage.
@Test
public void testWorkerUsage() throws Exception {
final ApplicationId app = NamespaceId.DEFAULT.app(AllProgramsApp.NAME);
final ProgramId program = app.worker(AllProgramsApp.NoOpWorker.NAME);
final DatasetId dataset = NamespaceId.DEFAULT.dataset(AllProgramsApp.DATASET_NAME);
Assert.assertEquals(0, getAppDatasetUsage(app).size());
Assert.assertEquals(0, getDatasetProgramUsage(dataset).size());
deployApp(AllProgramsApp.class);
try {
startProgram(program);
// Wait for the worker to complete
assertProgramRuns(getProgramClient(), program, ProgramRunStatus.COMPLETED, 1, 20);
Assert.assertTrue(getProgramDatasetUsage(program).contains(dataset));
Assert.assertTrue(getAppDatasetUsage(app).contains(dataset));
Assert.assertTrue(getDatasetProgramUsage(dataset).contains(program));
} finally {
deleteApp(app);
Assert.assertEquals(0, getAppDatasetUsage(app).size());
Assert.assertEquals(0, getDatasetProgramUsage(dataset).size());
}
}
use of io.cdap.cdap.proto.id.ProgramId in project cdap by caskdata.
the class PreferencesHttpHandlerInternal method getProgramPreferences.
/**
* Get program level preferences
*
* Note that if the given program doesn't exist, the return {@link PreferencesDetail} will be empty
* (i.e. {@link PreferencesDetail#properties} will be an empty map). In the case of requesting resolved preferences,
* the returned {@link PreferencesDetail} will include preferences from ancestor (i.e. preferences at application,
* namespace and instance level)
*
* @param request {@link HttpRequest}
* @param responder the responder used for sending response back to client
* @param namespace the namespace of the application
* @param appId the application to get preferences for
* @param programType the type of the program
* @param programId id of the program to get preferences for
* @param resolved whether to return resolved preferences or not
* @throws Exception
*/
@Path("/namespaces/{namespace-id}/apps/{application-id}/{program-type}/{program-id}/preferences")
@GET
public void getProgramPreferences(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespace, @PathParam("application-id") String appId, @PathParam("program-type") String programType, @PathParam("program-id") String programId, @QueryParam("resolved") boolean resolved) throws Exception {
ProgramId program = new ProgramId(namespace, appId, getProgramType(programType), programId);
// No need to check if program exists. PreferencesService returns an empty PreferencesDetail when that happens.
PreferencesDetail detail;
if (resolved) {
detail = preferencesService.getResolvedPreferences(program);
} else {
detail = preferencesService.getPreferences(program);
}
responder.sendJson(HttpResponseStatus.OK, GSON.toJson(detail, PreferencesDetail.class));
}
use of io.cdap.cdap.proto.id.ProgramId in project cdap by caskdata.
the class ProgramLifecycleHttpHandler method startPrograms.
/**
* Starts all programs that are passed into the data. The data is an array of JSON objects
* where each object must contain the following three elements: appId, programType, and programId
* (flow name, service name, etc.). In additional, each object can contain an optional runtimeargs element,
* which is a map of arguments to start the program with.
* <p>
* Example input:
* <pre><code>
* [{"appId": "App1", "programType": "Service", "programId": "Service1"},
* {"appId": "App1", "programType": "Mapreduce", "programId": "MapReduce2", "runtimeargs":{"arg1":"val1"}}]
* </code></pre>
* </p><p>
* The response will be an array of JsonObjects each of which will contain the three input parameters
* as well as a "statusCode" field which maps to the status code for the data in that JsonObjects.
* </p><p>
* If an error occurs in the input (for the example above, App2 does not exist), then all JsonObjects for which the
* parameters have a valid status will have the status field but all JsonObjects for which the parameters do not have
* a valid status will have an error message and statusCode.
* </p><p>
* For example, if there is no App2 in the data above, then the response would be 200 OK with following possible data:
* </p>
* <pre><code>
* [{"appId": "App1", "programType": "Service", "programId": "Service1", "statusCode": 200},
* {"appId": "App2", "programType": "Mapreduce", "programId": "Mapreduce2",
* "statusCode":404, "error": "App: App2 not found"}]
* </code></pre>
*/
@POST
@Path("/start")
@AuditPolicy({ AuditDetail.REQUEST_BODY, AuditDetail.RESPONSE_BODY })
public void startPrograms(FullHttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId) throws Exception {
List<BatchProgramStart> programs = validateAndGetBatchInput(request, BATCH_STARTS_TYPE);
List<BatchProgramResult> output = new ArrayList<>(programs.size());
for (BatchProgramStart program : programs) {
ProgramId programId = new ProgramId(namespaceId, program.getAppId(), program.getProgramType(), program.getProgramId());
try {
String runId = lifecycleService.run(programId, program.getRuntimeargs(), false).getId();
output.add(new BatchProgramResult(program, HttpResponseStatus.OK.code(), null, runId));
} catch (NotFoundException e) {
output.add(new BatchProgramResult(program, HttpResponseStatus.NOT_FOUND.code(), e.getMessage()));
} catch (BadRequestException e) {
output.add(new BatchProgramResult(program, HttpResponseStatus.BAD_REQUEST.code(), e.getMessage()));
} catch (ConflictException e) {
output.add(new BatchProgramResult(program, HttpResponseStatus.CONFLICT.code(), e.getMessage()));
}
}
responder.sendJson(HttpResponseStatus.OK, GSON.toJson(output));
}
use of io.cdap.cdap.proto.id.ProgramId in project cdap by caskdata.
the class ProgramLifecycleHttpHandler method doAddSchedule.
private void doAddSchedule(FullHttpRequest request, HttpResponder responder, String namespace, String appName, String appVersion, String scheduleName) throws Exception {
final ApplicationId applicationId = new ApplicationId(namespace, appName, appVersion);
ScheduleDetail scheduleFromRequest = readScheduleDetailBody(request, scheduleName);
if (scheduleFromRequest.getProgram() == null) {
throw new BadRequestException("No program was specified for the schedule");
}
if (scheduleFromRequest.getProgram().getProgramType() == null) {
throw new BadRequestException("No program type was specified for the schedule");
}
if (scheduleFromRequest.getProgram().getProgramName() == null) {
throw new BadRequestException("No program name was specified for the schedule");
}
if (scheduleFromRequest.getTrigger() == null) {
throw new BadRequestException("No trigger was specified for the schedule");
}
ProgramType programType = ProgramType.valueOfSchedulableType(scheduleFromRequest.getProgram().getProgramType());
String programName = scheduleFromRequest.getProgram().getProgramName();
ProgramId programId = applicationId.program(programType, programName);
lifecycleService.ensureProgramExists(programId);
String description = Objects.firstNonNull(scheduleFromRequest.getDescription(), "");
Map<String, String> properties = Objects.firstNonNull(scheduleFromRequest.getProperties(), Collections.emptyMap());
List<? extends Constraint> constraints = Objects.firstNonNull(scheduleFromRequest.getConstraints(), NO_CONSTRAINTS);
long timeoutMillis = Objects.firstNonNull(scheduleFromRequest.getTimeoutMillis(), Schedulers.JOB_QUEUE_TIMEOUT_MILLIS);
ProgramSchedule schedule = new ProgramSchedule(scheduleName, description, programId, properties, scheduleFromRequest.getTrigger(), constraints, timeoutMillis);
programScheduleService.add(schedule);
responder.sendStatus(HttpResponseStatus.OK);
}
Aggregations