use of io.cdap.cdap.api.artifact.ArtifactInfo in project cdap by cdapio.
the class GetArtifactPropertiesCommand method perform.
@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
String artifactName = arguments.get(ArgumentName.ARTIFACT_NAME.toString());
String artifactVersion = arguments.get(ArgumentName.ARTIFACT_VERSION.toString());
ArtifactId artifactId = cliConfig.getCurrentNamespace().artifact(artifactName, artifactVersion);
String scopeStr = arguments.getOptional(ArgumentName.SCOPE.toString());
ArtifactInfo info;
if (scopeStr == null) {
info = artifactClient.getArtifactInfo(artifactId);
} else {
ArtifactScope scope = ArtifactScope.valueOf(scopeStr.toUpperCase());
info = artifactClient.getArtifactInfo(artifactId, scope);
}
List<Map.Entry<String, String>> rows = new ArrayList<>(info.getProperties().size());
rows.addAll(info.getProperties().entrySet());
Table table = Table.builder().setHeader("key", "value").setRows(rows, new RowMaker<Map.Entry<String, String>>() {
@Override
public List<String> makeRow(Map.Entry<String, String> entry) {
List<String> columns = new ArrayList<>(2);
columns.add(entry.getKey());
columns.add(entry.getValue());
return columns;
}
}).build();
cliConfig.getTableRenderer().render(cliConfig, output, table);
}
use of io.cdap.cdap.api.artifact.ArtifactInfo in project cdap by cdapio.
the class ArtifactHttpHandler method getArtifactInfo.
@GET
@Path("/namespaces/{namespace-id}/artifacts/{artifact-name}/versions/{artifact-version}")
public void getArtifactInfo(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) throws Exception {
NamespaceId namespace = validateAndGetScopedNamespace(Ids.namespace(namespaceId), scope);
ArtifactId artifactId = validateAndGetArtifactId(namespace, artifactName, artifactVersion);
try {
ArtifactDetail detail = artifactRepository.getArtifact(Id.Artifact.fromEntityId(artifactId));
ArtifactDescriptor descriptor = detail.getDescriptor();
// info hides some fields that are available in detail, such as the location of the artifact
ArtifactInfo info = new ArtifactInfo(descriptor.getArtifactId(), detail.getMeta().getClasses(), detail.getMeta().getProperties(), detail.getMeta().getUsableBy());
responder.sendJson(HttpResponseStatus.OK, GSON.toJson(info, ArtifactInfo.class));
} 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 metadata from the store.");
}
}
use of io.cdap.cdap.api.artifact.ArtifactInfo in project cdap by cdapio.
the class ArtifactHttpHandlerInternal method listArtifacts.
@GET
@Path("/namespaces/{namespace-id}/artifacts")
public void listArtifacts(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespace) {
try {
NamespaceId namespaceId = new NamespaceId(namespace);
List<ArtifactInfo> result = new ArrayList<>(artifactRepository.getArtifactsInfo(namespaceId));
if (!NamespaceId.SYSTEM.equals(namespaceId)) {
result.addAll(artifactRepository.getArtifactsInfo(NamespaceId.SYSTEM));
}
responder.sendJson(HttpResponseStatus.OK, GSON.toJson(result, ARTIFACT_INFO_LIST_TYPE));
} catch (Exception e) {
LOG.warn("Exception reading artifact metadata for namespace {} from the store.", namespace, e);
responder.sendString(HttpResponseStatus.INTERNAL_SERVER_ERROR, "Error reading artifact metadata from the store.");
}
}
use of io.cdap.cdap.api.artifact.ArtifactInfo in project cdap by caskdata.
the class ArtifactHttpHandler method getArtifactInfo.
@GET
@Path("/namespaces/{namespace-id}/artifacts/{artifact-name}/versions/{artifact-version}")
public void getArtifactInfo(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) throws Exception {
NamespaceId namespace = validateAndGetScopedNamespace(Ids.namespace(namespaceId), scope);
ArtifactId artifactId = validateAndGetArtifactId(namespace, artifactName, artifactVersion);
try {
ArtifactDetail detail = artifactRepository.getArtifact(Id.Artifact.fromEntityId(artifactId));
ArtifactDescriptor descriptor = detail.getDescriptor();
// info hides some fields that are available in detail, such as the location of the artifact
ArtifactInfo info = new ArtifactInfo(descriptor.getArtifactId(), detail.getMeta().getClasses(), detail.getMeta().getProperties(), detail.getMeta().getUsableBy());
responder.sendJson(HttpResponseStatus.OK, GSON.toJson(info, ArtifactInfo.class));
} 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 metadata from the store.");
}
}
use of io.cdap.cdap.api.artifact.ArtifactInfo in project cdap by caskdata.
the class ArtifactHttpHandlerInternal method listArtifacts.
@GET
@Path("/namespaces/{namespace-id}/artifacts")
public void listArtifacts(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespace) {
try {
NamespaceId namespaceId = new NamespaceId(namespace);
List<ArtifactInfo> result = new ArrayList<>(artifactRepository.getArtifactsInfo(namespaceId));
if (!NamespaceId.SYSTEM.equals(namespaceId)) {
result.addAll(artifactRepository.getArtifactsInfo(NamespaceId.SYSTEM));
}
responder.sendJson(HttpResponseStatus.OK, GSON.toJson(result, ARTIFACT_INFO_LIST_TYPE));
} catch (Exception e) {
LOG.warn("Exception reading artifact metadata for namespace {} from the store.", namespace, e);
responder.sendString(HttpResponseStatus.INTERNAL_SERVER_ERROR, "Error reading artifact metadata from the store.");
}
}
Aggregations