use of io.cdap.cdap.proto.id.NamespaceId in project cdap by caskdata.
the class ArtifactHttpHandler method getProperties.
@GET
@Path("/namespaces/{namespace-id}/artifacts/{artifact-name}/versions/{artifact-version}/properties")
public void getProperties(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("artifact-name") String artifactName, @PathParam("artifact-version") String artifactVersion, @QueryParam("scope") @DefaultValue("user") String scope, @QueryParam("keys") @Nullable String keys) throws Exception {
NamespaceId namespace = validateAndGetScopedNamespace(Ids.namespace(namespaceId), scope);
ArtifactId artifactId = validateAndGetArtifactId(namespace, artifactName, artifactVersion);
try {
ArtifactDetail artifactDetail = artifactRepository.getArtifact(Id.Artifact.fromEntityId(artifactId));
Map<String, String> properties = artifactDetail.getMeta().getProperties();
Map<String, String> result;
if (keys != null && !keys.isEmpty()) {
result = new HashMap<>();
for (String key : Splitter.on(',').trimResults().split(keys)) {
result.put(key, properties.get(key));
}
} else {
result = properties;
}
responder.sendJson(HttpResponseStatus.OK, GSON.toJson(result));
} catch (IOException e) {
LOG.error("Exception reading artifacts named {} for namespace {} from the store.", artifactName, namespaceId, e);
responder.sendString(HttpResponseStatus.INTERNAL_SERVER_ERROR, "Error reading artifact properties from the store.");
}
}
use of io.cdap.cdap.proto.id.NamespaceId in project cdap by caskdata.
the class ArtifactHttpHandler method deleteArtifact.
@DELETE
@Path("/namespaces/{namespace-id}/artifacts/{artifact-name}/versions/{artifact-version}")
public void deleteArtifact(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);
ArtifactId artifactId = validateAndGetArtifactId(namespace, artifactName, artifactVersion);
try {
artifactRepository.deleteArtifact(Id.Artifact.fromEntityId(artifactId));
responder.sendStatus(HttpResponseStatus.OK);
} catch (IOException e) {
LOG.error("Exception deleting artifact named {} for namespace {} from the store.", artifactName, namespaceId, e);
responder.sendString(HttpResponseStatus.INTERNAL_SERVER_ERROR, "Error deleting artifact metadata from the store: " + e.getMessage());
}
}
use of io.cdap.cdap.proto.id.NamespaceId in project cdap by caskdata.
the class ArtifactHttpHandler method getArtifactProperties.
@POST
@Path("/namespaces/{namespace-id}/artifactproperties")
public void getArtifactProperties(FullHttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @QueryParam("order") @DefaultValue("DESC") String order) throws Exception {
NamespaceId namespace = validateAndGetNamespace(namespaceId);
ArtifactSortOrder sortOrder = ArtifactSortOrder.valueOf(order);
List<ArtifactPropertiesRequest> propertyRequests;
try (Reader reader = new InputStreamReader(new ByteBufInputStream(request.content()), StandardCharsets.UTF_8)) {
propertyRequests = GSON.fromJson(reader, BATCH_ARTIFACT_PROPERTIES_REQUEST);
} catch (JsonSyntaxException e) {
throw new BadRequestException("Unable to parse request: " + e.getMessage(), e);
}
List<ArtifactSummaryProperties> result = new ArrayList<>(propertyRequests.size());
for (ArtifactPropertiesRequest propertiesRequest : propertyRequests) {
NamespaceId requestNamespace = propertiesRequest.getScope() == ArtifactScope.SYSTEM ? NamespaceId.SYSTEM : namespace;
ArtifactRange range = new ArtifactRange(requestNamespace.getNamespace(), propertiesRequest.getName(), ArtifactVersionRange.parse(propertiesRequest.getVersion()));
List<ArtifactDetail> artifactDetails = artifactRepository.getArtifactDetails(range, 1, sortOrder);
for (ArtifactDetail artifactDetail : artifactDetails) {
Map<String, String> properties = artifactDetail.getMeta().getProperties();
Map<String, String> filteredProperties = new HashMap<>(propertiesRequest.getProperties().size());
for (String propertyKey : propertiesRequest.getProperties()) {
if (properties.containsKey(propertyKey)) {
filteredProperties.put(propertyKey, properties.get(propertyKey));
}
}
String artifactVersion = artifactDetail.getDescriptor().getArtifactId().getVersion().getVersion();
result.add(new ArtifactSummaryProperties(propertiesRequest.getName(), artifactVersion, propertiesRequest.getScope(), filteredProperties));
}
}
responder.sendJson(HttpResponseStatus.OK, GSON.toJson(result, BATCH_ARTIFACT_PROPERTIES_RESPONSE));
}
use of io.cdap.cdap.proto.id.NamespaceId in project cdap by caskdata.
the class ArtifactHttpHandler method writeProperty.
@PUT
@Path("/namespaces/{namespace-id}/artifacts/{artifact-name}/versions/{artifact-version}/properties/{property}")
@AuditPolicy(AuditDetail.REQUEST_BODY)
public void writeProperty(FullHttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("artifact-name") String artifactName, @PathParam("artifact-version") String artifactVersion, @PathParam("property") String key) throws Exception {
NamespaceId namespace = NamespaceId.SYSTEM.getNamespace().equalsIgnoreCase(namespaceId) ? NamespaceId.SYSTEM : validateAndGetNamespace(namespaceId);
ArtifactId artifactId = validateAndGetArtifactId(namespace, artifactName, artifactVersion);
String value = request.content().toString(StandardCharsets.UTF_8);
if (value == null) {
responder.sendStatus(HttpResponseStatus.OK);
return;
}
try {
artifactRepository.writeArtifactProperty(Id.Artifact.fromEntityId(artifactId), key, value);
responder.sendStatus(HttpResponseStatus.OK);
} catch (IOException e) {
LOG.error("Exception writing properties for artifact {}.", artifactId, e);
responder.sendString(HttpResponseStatus.INTERNAL_SERVER_ERROR, "Error writing property to artifact.");
}
}
use of io.cdap.cdap.proto.id.NamespaceId in project cdap by caskdata.
the class ArtifactHttpHandler method deleteProperty.
@DELETE
@Path("/namespaces/{namespace-id}/artifacts/{artifact-name}/versions/{artifact-version}/properties/{property}")
public void deleteProperty(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("artifact-name") String artifactName, @PathParam("artifact-version") String artifactVersion, @PathParam("property") String key) throws Exception {
NamespaceId namespace = NamespaceId.SYSTEM.getNamespace().equalsIgnoreCase(namespaceId) ? NamespaceId.SYSTEM : validateAndGetNamespace(namespaceId);
ArtifactId artifactId = validateAndGetArtifactId(namespace, artifactName, artifactVersion);
try {
artifactRepository.deleteArtifactProperty(Id.Artifact.fromEntityId(artifactId), key);
responder.sendStatus(HttpResponseStatus.OK);
} catch (IOException e) {
LOG.error("Exception updating properties for artifact {}.", artifactId, e);
responder.sendString(HttpResponseStatus.INTERNAL_SERVER_ERROR, "Error deleting property for artifact.");
}
}
Aggregations