use of io.cdap.cdap.proto.id.NamespaceId 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.proto.id.NamespaceId 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.proto.id.NamespaceId in project cdap by caskdata.
the class NamespaceHttpHandler method deleteDatasets.
@DELETE
@Path("/unrecoverable/namespaces/{namespace-id}/datasets")
public void deleteDatasets(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespace) throws Exception {
if (!cConf.getBoolean(Constants.Dangerous.UNRECOVERABLE_RESET, Constants.Dangerous.DEFAULT_UNRECOVERABLE_RESET)) {
responder.sendString(HttpResponseStatus.FORBIDDEN, String.format("All datasets in namespace %s cannot be deleted because '%s' is not enabled." + " Please enable it and restart CDAP Master.", namespace, Constants.Dangerous.UNRECOVERABLE_RESET));
return;
}
NamespaceId namespaceId = new NamespaceId(namespace);
namespaceAdmin.deleteDatasets(namespaceId);
responder.sendStatus(HttpResponseStatus.OK);
}
use of io.cdap.cdap.proto.id.NamespaceId in project cdap by caskdata.
the class NamespaceHttpHandler method getNamespace.
@GET
@Path("/namespaces/{namespace-id}")
public void getNamespace(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId) throws Exception {
// return keytab URI without version
NamespaceMeta ns = new NamespaceMeta.Builder(namespaceAdmin.get(new NamespaceId(namespaceId))).buildWithoutKeytabURIVersion();
responder.sendJson(HttpResponseStatus.OK, GSON.toJson(ns));
}
use of io.cdap.cdap.proto.id.NamespaceId in project cdap by caskdata.
the class RemoteConfiguratorTest method init.
@BeforeClass
public static void init() throws Exception {
cConf = CConfiguration.create();
cConf.set(Constants.CFG_LOCAL_DATA_DIR, TEMP_FOLDER.newFolder().getAbsolutePath());
cConf.setInt(Constants.TaskWorker.CONTAINER_KILL_AFTER_REQUEST_COUNT, 0);
InMemoryDiscoveryService discoveryService = new InMemoryDiscoveryService();
MasterEnvironments.setMasterEnvironment(new TestMasterEnvironment(discoveryService));
NamespaceAdmin namespaceAdmin = new InMemoryNamespaceAdmin();
namespaceAdmin.create(NamespaceMeta.SYSTEM);
namespaceAdmin.create(NamespaceMeta.DEFAULT);
remoteClientFactory = new RemoteClientFactory(discoveryService, new DefaultInternalAuthenticator(new AuthenticationTestContext()));
httpService = new CommonNettyHttpServiceBuilder(cConf, "test").setHttpHandlers(new TaskWorkerHttpHandlerInternal(cConf, className -> {
}, new NoOpMetricsCollectionService()), new ArtifactHttpHandlerInternal(new TestArtifactRepository(cConf), namespaceAdmin), new ArtifactLocalizerHttpHandlerInternal(new ArtifactLocalizer(cConf, remoteClientFactory, ((namespaceId, retryStrategy) -> {
return new NoOpArtifactManager();
})))).setPort(cConf.getInt(Constants.ArtifactLocalizer.PORT)).setChannelPipelineModifier(new ChannelPipelineModifier() {
@Override
public void modify(ChannelPipeline pipeline) {
pipeline.addAfter("compressor", "decompressor", new HttpContentDecompressor());
}
}).build();
httpService.start();
discoveryService.register(URIScheme.createDiscoverable(Constants.Service.TASK_WORKER, httpService));
discoveryService.register(URIScheme.createDiscoverable(Constants.Service.APP_FABRIC_HTTP, httpService));
metricsCollectionService = new NoOpMetricsCollectionService();
}
Aggregations