Search in sources :

Example 11 with ArtifactDetail

use of io.cdap.cdap.internal.app.runtime.artifact.ArtifactDetail in project cdap by caskdata.

the class ArtifactHttpHandlerInternal method getArtifactDetailForVersions.

@GET
@Path("/namespaces/{namespace-id}/artifacts/{artifact-name}/versions")
public void getArtifactDetailForVersions(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespace, @PathParam("artifact-name") String artifactName, @QueryParam("lower") String lower, @QueryParam("upper") String upper, @QueryParam("limit") @DefaultValue("1") int limit, @QueryParam("order") String order, @QueryParam("scope") @DefaultValue("user") String scope) throws Exception {
    NamespaceId namespaceId = new NamespaceId(namespace);
    if (!namespaceId.equals(NamespaceId.SYSTEM)) {
        if (!namespaceQueryAdmin.exists(namespaceId)) {
            throw new NamespaceNotFoundException(namespaceId);
        }
    }
    ArtifactRange range = new ArtifactRange(namespaceId.getNamespace(), artifactName, new ArtifactVersionRange(new ArtifactVersion(lower), true, new ArtifactVersion(upper), true));
    ArtifactSortOrder sortOrder = ArtifactSortOrder.valueOf(order);
    List<ArtifactDetail> artifactDetailList = artifactRepository.getArtifactDetails(range, limit, sortOrder);
    responder.sendJson(HttpResponseStatus.OK, GSON.toJson(artifactDetailList, ARTIFACT_DETAIL_LIST_TYPE));
}
Also used : ArtifactVersion(io.cdap.cdap.api.artifact.ArtifactVersion) ArtifactVersionRange(io.cdap.cdap.api.artifact.ArtifactVersionRange) ArtifactRange(io.cdap.cdap.api.artifact.ArtifactRange) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) NamespaceNotFoundException(io.cdap.cdap.common.NamespaceNotFoundException) ArtifactSortOrder(io.cdap.cdap.proto.artifact.ArtifactSortOrder) ArtifactDetail(io.cdap.cdap.internal.app.runtime.artifact.ArtifactDetail) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 12 with ArtifactDetail

use of io.cdap.cdap.internal.app.runtime.artifact.ArtifactDetail in project cdap by caskdata.

the class ArtifactHttpHandlerInternal method getArtifactBytes.

@GET
@Path("/namespaces/{namespace-id}/artifacts/{artifact-name}/versions/{artifact-version}/download")
public void getArtifactBytes(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 = new ArtifactId(namespace.getNamespace(), artifactName, artifactVersion);
    ArtifactDetail artifactDetail = artifactRepository.getArtifact(Id.Artifact.fromEntityId(artifactId));
    Location location = artifactDetail.getDescriptor().getLocation();
    ZonedDateTime newModifiedDate = ZonedDateTime.ofInstant(Instant.ofEpochMilli(location.lastModified()), ZoneId.of("GMT"));
    HttpHeaders headers = new DefaultHttpHeaders().add(HttpHeaderNames.CONTENT_TYPE, HttpHeaderValues.APPLICATION_OCTET_STREAM).add(HttpHeaderNames.LAST_MODIFIED, newModifiedDate.format(DateTimeFormatter.RFC_1123_DATE_TIME));
    String lastModified = request.headers().get(HttpHeaderNames.IF_MODIFIED_SINCE);
    if (areDatesEqual(lastModified, newModifiedDate)) {
        responder.sendStatus(HttpResponseStatus.NOT_MODIFIED, headers);
        return;
    }
    responder.sendContent(HttpResponseStatus.OK, new LocationBodyProducer(location), headers);
}
Also used : HttpHeaders(io.netty.handler.codec.http.HttpHeaders) DefaultHttpHeaders(io.netty.handler.codec.http.DefaultHttpHeaders) ArtifactId(io.cdap.cdap.proto.id.ArtifactId) ZonedDateTime(java.time.ZonedDateTime) DefaultHttpHeaders(io.netty.handler.codec.http.DefaultHttpHeaders) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) ArtifactDetail(io.cdap.cdap.internal.app.runtime.artifact.ArtifactDetail) Location(org.apache.twill.filesystem.Location) LocationBodyProducer(io.cdap.cdap.common.http.LocationBodyProducer) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 13 with ArtifactDetail

use of io.cdap.cdap.internal.app.runtime.artifact.ArtifactDetail in project cdap by caskdata.

the class ArtifactHttpHandlerInternal method getArtifactLocationPath.

@GET
@Path("/namespaces/{namespace-id}/artifacts/{artifact-name}/versions/{artifact-version}/location")
public void getArtifactLocationPath(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("artifact-name") String artifactName, @PathParam("artifact-version") String artifactVersion) {
    try {
        ArtifactDetail artifactDetail = artifactRepository.getArtifact(Id.Artifact.from(Id.Namespace.from(namespaceId), artifactName, artifactVersion));
        responder.sendString(HttpResponseStatus.OK, artifactDetail.getDescriptor().getLocation().toURI().getPath());
    } catch (Exception e) {
        LOG.warn("Exception reading artifact metadata for namespace {} from the store.", namespaceId, e);
        responder.sendString(HttpResponseStatus.INTERNAL_SERVER_ERROR, "Error reading artifact metadata from the store.");
    }
}
Also used : NamespaceNotFoundException(io.cdap.cdap.common.NamespaceNotFoundException) BadRequestException(io.cdap.cdap.common.BadRequestException) ArtifactDetail(io.cdap.cdap.internal.app.runtime.artifact.ArtifactDetail) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 14 with ArtifactDetail

use of io.cdap.cdap.internal.app.runtime.artifact.ArtifactDetail in project cdap by caskdata.

the class ArtifactHttpHandlerInternal method getArtifactDetail.

@GET
@Path("/namespaces/{namespace-id}/artifacts/{artifact-name}/versions/{artifact-version}")
public void getArtifactDetail(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespace, @PathParam("artifact-name") String artifactName, @PathParam("artifact-version") String artifactVersion, @QueryParam("scope") @DefaultValue("user") String scope) throws Exception {
    NamespaceId namespaceId = new NamespaceId(namespace);
    if (!namespaceId.equals(NamespaceId.SYSTEM)) {
        if (!namespaceQueryAdmin.exists(namespaceId)) {
            throw new NamespaceNotFoundException(namespaceId);
        }
    }
    ArtifactId artifactId = new ArtifactId(namespace, artifactName, artifactVersion);
    ArtifactDetail artifactDetail = artifactRepository.getArtifact(Id.Artifact.fromEntityId(artifactId));
    responder.sendJson(HttpResponseStatus.OK, GSON.toJson(artifactDetail));
}
Also used : ArtifactId(io.cdap.cdap.proto.id.ArtifactId) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) NamespaceNotFoundException(io.cdap.cdap.common.NamespaceNotFoundException) ArtifactDetail(io.cdap.cdap.internal.app.runtime.artifact.ArtifactDetail) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 15 with ArtifactDetail

use of io.cdap.cdap.internal.app.runtime.artifact.ArtifactDetail in project cdap by caskdata.

the class RemoteConfiguratorTest method testRemoteConfigurator.

@Test
public void testRemoteConfigurator() throws Exception {
    LocationFactory locationFactory = new LocalLocationFactory(TEMP_FOLDER.newFolder());
    Location appJar = AppJarHelper.createDeploymentJar(locationFactory, AllProgramsApp.class);
    ArtifactId artifactId = NamespaceId.DEFAULT.artifact(AllProgramsApp.class.getSimpleName(), "1.0.0");
    artifacts.put(artifactId, new ArtifactDetail(new ArtifactDescriptor(artifactId.getNamespace(), artifactId.toApiArtifactId(), appJar), new ArtifactMeta(ArtifactClasses.builder().build())));
    AppDeploymentInfo info = new AppDeploymentInfo(artifactId, appJar, NamespaceId.DEFAULT, new ApplicationClass(AllProgramsApp.class.getName(), "", null), null, null, null);
    Configurator configurator = new RemoteConfigurator(cConf, metricsCollectionService, info, remoteClientFactory);
    // Extract response from the configurator.
    ListenableFuture<ConfigResponse> result = configurator.config();
    ConfigResponse response = result.get(10, TimeUnit.SECONDS);
    Assert.assertNotNull(response);
    AppSpecInfo appSpecInfo = response.getAppSpecInfo();
    if (appSpecInfo == null) {
        throw new IllegalStateException("Failed to deploy application");
    }
    ApplicationSpecification specification = appSpecInfo.getAppSpec();
    Assert.assertNotNull(specification);
    // Simple checks.
    Assert.assertEquals(AllProgramsApp.NAME, specification.getName());
    ApplicationSpecification expectedSpec = Specifications.from(new AllProgramsApp());
    for (ProgramType programType : ProgramType.values()) {
        Assert.assertEquals(expectedSpec.getProgramsByType(programType), specification.getProgramsByType(programType));
    }
    Assert.assertEquals(expectedSpec.getDatasets(), specification.getDatasets());
}
Also used : ArtifactMeta(io.cdap.cdap.internal.app.runtime.artifact.ArtifactMeta) ApplicationSpecification(io.cdap.cdap.api.app.ApplicationSpecification) ArtifactId(io.cdap.cdap.proto.id.ArtifactId) AppSpecInfo(io.cdap.cdap.internal.app.deploy.pipeline.AppSpecInfo) Configurator(io.cdap.cdap.app.deploy.Configurator) ApplicationClass(io.cdap.cdap.api.artifact.ApplicationClass) AllProgramsApp(io.cdap.cdap.AllProgramsApp) ConfigResponse(io.cdap.cdap.app.deploy.ConfigResponse) LocalLocationFactory(org.apache.twill.filesystem.LocalLocationFactory) LocationFactory(org.apache.twill.filesystem.LocationFactory) AppDeploymentInfo(io.cdap.cdap.internal.app.deploy.pipeline.AppDeploymentInfo) ArtifactDescriptor(io.cdap.cdap.internal.app.runtime.artifact.ArtifactDescriptor) ProgramType(io.cdap.cdap.api.app.ProgramType) LocalLocationFactory(org.apache.twill.filesystem.LocalLocationFactory) Location(org.apache.twill.filesystem.Location) ArtifactDetail(io.cdap.cdap.internal.app.runtime.artifact.ArtifactDetail) Test(org.junit.Test)

Aggregations

ArtifactDetail (io.cdap.cdap.internal.app.runtime.artifact.ArtifactDetail)38 ArtifactId (io.cdap.cdap.proto.id.ArtifactId)24 NamespaceId (io.cdap.cdap.proto.id.NamespaceId)20 Path (javax.ws.rs.Path)16 GET (javax.ws.rs.GET)14 Test (org.junit.Test)12 ArtifactRange (io.cdap.cdap.api.artifact.ArtifactRange)10 ArtifactNotFoundException (io.cdap.cdap.common.ArtifactNotFoundException)10 IOException (java.io.IOException)10 ArtifactVersion (io.cdap.cdap.api.artifact.ArtifactVersion)8 ArtifactDescriptor (io.cdap.cdap.internal.app.runtime.artifact.ArtifactDescriptor)8 ApplicationSpecification (io.cdap.cdap.api.app.ApplicationSpecification)6 NamespaceNotFoundException (io.cdap.cdap.common.NamespaceNotFoundException)6 ProgramId (io.cdap.cdap.proto.id.ProgramId)6 Location (org.apache.twill.filesystem.Location)6 ApplicationNotFoundException (io.cdap.cdap.common.ApplicationNotFoundException)5 ApplicationClass (io.cdap.cdap.api.artifact.ApplicationClass)4 ArtifactId (io.cdap.cdap.api.artifact.ArtifactId)4 ArtifactSummary (io.cdap.cdap.api.artifact.ArtifactSummary)4 Configurator (io.cdap.cdap.app.deploy.Configurator)4