Search in sources :

Example 11 with ArtifactInfo

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);
}
Also used : ArtifactScope(io.cdap.cdap.api.artifact.ArtifactScope) Table(io.cdap.cdap.cli.util.table.Table) ArtifactId(io.cdap.cdap.proto.id.ArtifactId) ArtifactInfo(io.cdap.cdap.api.artifact.ArtifactInfo) RowMaker(io.cdap.cdap.cli.util.RowMaker) ArrayList(java.util.ArrayList) Map(java.util.Map)

Example 12 with ArtifactInfo

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.");
    }
}
Also used : ArtifactId(io.cdap.cdap.proto.id.ArtifactId) ArtifactInfo(io.cdap.cdap.api.artifact.ArtifactInfo) ArtifactDescriptor(io.cdap.cdap.internal.app.runtime.artifact.ArtifactDescriptor) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) IOException(java.io.IOException) ArtifactDetail(io.cdap.cdap.internal.app.runtime.artifact.ArtifactDetail) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 13 with ArtifactInfo

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.");
    }
}
Also used : ArtifactInfo(io.cdap.cdap.api.artifact.ArtifactInfo) ArrayList(java.util.ArrayList) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) NamespaceNotFoundException(io.cdap.cdap.common.NamespaceNotFoundException) BadRequestException(io.cdap.cdap.common.BadRequestException) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 14 with ArtifactInfo

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.");
    }
}
Also used : ArtifactId(io.cdap.cdap.proto.id.ArtifactId) ArtifactInfo(io.cdap.cdap.api.artifact.ArtifactInfo) ArtifactDescriptor(io.cdap.cdap.internal.app.runtime.artifact.ArtifactDescriptor) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) IOException(java.io.IOException) ArtifactDetail(io.cdap.cdap.internal.app.runtime.artifact.ArtifactDetail) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 15 with ArtifactInfo

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.");
    }
}
Also used : ArtifactInfo(io.cdap.cdap.api.artifact.ArtifactInfo) ArrayList(java.util.ArrayList) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) NamespaceNotFoundException(io.cdap.cdap.common.NamespaceNotFoundException) BadRequestException(io.cdap.cdap.common.BadRequestException) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Aggregations

ArtifactInfo (io.cdap.cdap.api.artifact.ArtifactInfo)22 ArtifactId (io.cdap.cdap.proto.id.ArtifactId)12 ArrayList (java.util.ArrayList)10 NamespaceId (io.cdap.cdap.proto.id.NamespaceId)8 IOException (java.io.IOException)8 ArtifactScope (io.cdap.cdap.api.artifact.ArtifactScope)6 ArtifactNotFoundException (io.cdap.cdap.common.ArtifactNotFoundException)6 Test (org.junit.Test)6 ArtifactRange (io.cdap.cdap.api.artifact.ArtifactRange)4 ArtifactVersion (io.cdap.cdap.api.artifact.ArtifactVersion)4 Table (io.cdap.cdap.cli.util.table.Table)4 URL (java.net.URL)4 List (java.util.List)4 GET (javax.ws.rs.GET)4 Path (javax.ws.rs.Path)4 ArtifactManager (io.cdap.cdap.api.artifact.ArtifactManager)3 ArtifactDetail (io.cdap.cdap.internal.app.runtime.artifact.ArtifactDetail)3 ByteStreams (com.google.common.io.ByteStreams)2 CharStreams (com.google.common.io.CharStreams)2 Gson (com.google.gson.Gson)2