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));
}
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);
}
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.");
}
}
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));
}
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());
}
Aggregations