use of co.cask.cdap.proto.id.NamespaceId in project cdap by caskdata.
the class MetadataHandler method updateTopic.
@PUT
@Path("/topics/{topic}/properties")
public void updateTopic(HttpRequest request, HttpResponder responder, @PathParam("namespace") String namespace, @PathParam("topic") String topic) throws Exception {
TopicId topicId = new NamespaceId(namespace).topic(topic);
messagingService.updateTopic(new TopicMetadata(topicId, decodeTopicProperties(request.getContent())));
responder.sendStatus(HttpResponseStatus.OK);
}
use of co.cask.cdap.proto.id.NamespaceId in project cdap by caskdata.
the class MetadataHandler method createTopic.
@PUT
@Path("/topics/{topic}")
public void createTopic(HttpRequest request, HttpResponder responder, @PathParam("namespace") String namespace, @PathParam("topic") String topic) throws Exception {
TopicId topicId = new NamespaceId(namespace).topic(topic);
messagingService.createTopic(new TopicMetadata(topicId, decodeTopicProperties(request.getContent())));
responder.sendStatus(HttpResponseStatus.OK);
}
use of co.cask.cdap.proto.id.NamespaceId in project cdap by caskdata.
the class StoreHandler method store.
@POST
@Path("/store")
public void store(HttpRequest request, HttpResponder responder, @PathParam("namespace") String namespace, @PathParam("topic") String topic) throws Exception {
TopicId topicId = new NamespaceId(namespace).topic(topic);
StoreRequest storeRequest = createStoreRequest(topicId, request);
// It must be transactional with payload for store request
if (!storeRequest.isTransactional() || !storeRequest.hasNext()) {
throw new BadRequestException("Store request must be transactional with payload. Topic: " + topicId);
}
messagingService.storePayload(storeRequest);
responder.sendStatus(HttpResponseStatus.OK);
}
use of co.cask.cdap.proto.id.NamespaceId in project cdap by caskdata.
the class ArtifactHttpHandler method writeProperties.
@PUT
@Path("/namespaces/{namespace-id}/artifacts/{artifact-name}/versions/{artifact-version}/properties")
@AuditPolicy(AuditDetail.REQUEST_BODY)
public void writeProperties(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("artifact-name") String artifactName, @PathParam("artifact-version") String artifactVersion) throws Exception {
NamespaceId namespace = NamespaceId.SYSTEM.getNamespace().equalsIgnoreCase(namespaceId) ? NamespaceId.SYSTEM : validateAndGetNamespace(namespaceId);
Id.Artifact artifactId = validateAndGetArtifactId(namespace, artifactName, artifactVersion);
Map<String, String> properties;
try (Reader reader = new InputStreamReader(new ChannelBufferInputStream(request.getContent()), Charsets.UTF_8)) {
properties = GSON.fromJson(reader, MAP_STRING_STRING_TYPE);
} catch (JsonSyntaxException e) {
throw new BadRequestException("Json Syntax Error while parsing properties from request. " + "Please check that the properties are a json map from string to string.", e);
} catch (IOException e) {
throw new BadRequestException("Unable to read properties from the request.", e);
}
try {
artifactRepository.writeArtifactProperties(artifactId, properties);
responder.sendStatus(HttpResponseStatus.OK);
} catch (IOException e) {
LOG.error("Exception writing properties for artifact {}.", artifactId, e);
responder.sendString(HttpResponseStatus.INTERNAL_SERVER_ERROR, "Error adding properties to artifact.");
}
}
use of co.cask.cdap.proto.id.NamespaceId in project cdap by caskdata.
the class ProgramLifecycleService method retrieveProgramIdForRunRecord.
/**
* Helper method to get {@link ProgramId} for a RunRecord for type of program
*
* @param programType Type of program to search
* @param runId The target id of the {@link RunRecord} to find
* @return the program id of the run record or {@code null} if does not exist.
*/
@Nullable
private ProgramId retrieveProgramIdForRunRecord(ProgramType programType, String runId) {
// Get list of namespaces (borrow logic from AbstractAppFabricHttpHandler#listPrograms)
List<NamespaceMeta> namespaceMetas = nsStore.list();
// For each, get all programs under it
ProgramId targetProgramId = null;
for (NamespaceMeta nm : namespaceMetas) {
NamespaceId namespace = Ids.namespace(nm.getName());
Collection<ApplicationSpecification> appSpecs = store.getAllApplications(namespace);
// For each application get the programs checked against run records
for (ApplicationSpecification appSpec : appSpecs) {
switch(programType) {
case FLOW:
for (String programName : appSpec.getFlows().keySet()) {
ProgramId programId = validateProgramForRunRecord(nm.getName(), appSpec.getName(), appSpec.getAppVersion(), programType, programName, runId);
if (programId != null) {
targetProgramId = programId;
break;
}
}
break;
case MAPREDUCE:
for (String programName : appSpec.getMapReduce().keySet()) {
ProgramId programId = validateProgramForRunRecord(nm.getName(), appSpec.getName(), appSpec.getAppVersion(), programType, programName, runId);
if (programId != null) {
targetProgramId = programId;
break;
}
}
break;
case SPARK:
for (String programName : appSpec.getSpark().keySet()) {
ProgramId programId = validateProgramForRunRecord(nm.getName(), appSpec.getName(), appSpec.getAppVersion(), programType, programName, runId);
if (programId != null) {
targetProgramId = programId;
break;
}
}
break;
case SERVICE:
for (String programName : appSpec.getServices().keySet()) {
ProgramId programId = validateProgramForRunRecord(nm.getName(), appSpec.getName(), appSpec.getAppVersion(), programType, programName, runId);
if (programId != null) {
targetProgramId = programId;
break;
}
}
break;
case WORKER:
for (String programName : appSpec.getWorkers().keySet()) {
ProgramId programId = validateProgramForRunRecord(nm.getName(), appSpec.getName(), appSpec.getAppVersion(), programType, programName, runId);
if (programId != null) {
targetProgramId = programId;
break;
}
}
break;
case WORKFLOW:
for (String programName : appSpec.getWorkflows().keySet()) {
ProgramId programId = validateProgramForRunRecord(nm.getName(), appSpec.getName(), appSpec.getAppVersion(), programType, programName, runId);
if (programId != null) {
targetProgramId = programId;
break;
}
}
break;
case CUSTOM_ACTION:
case WEBAPP:
// no-op
break;
default:
LOG.debug("Unknown program type: " + programType.name());
break;
}
if (targetProgramId != null) {
break;
}
}
if (targetProgramId != null) {
break;
}
}
return targetProgramId;
}
Aggregations