Search in sources :

Example 96 with NamespaceId

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);
}
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 97 with NamespaceId

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));
}
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 98 with NamespaceId

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);
}
Also used : NamespaceId(io.cdap.cdap.proto.id.NamespaceId) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

Example 99 with NamespaceId

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));
}
Also used : NamespaceMeta(io.cdap.cdap.proto.NamespaceMeta) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 100 with NamespaceId

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();
}
Also used : ConfigResponse(io.cdap.cdap.app.deploy.ConfigResponse) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) AccessException(io.cdap.cdap.api.security.AccessException) LocalLocationFactory(org.apache.twill.filesystem.LocalLocationFactory) ArtifactClasses(io.cdap.cdap.api.artifact.ArtifactClasses) ArtifactLocalizerHttpHandlerInternal(io.cdap.cdap.internal.app.worker.sidecar.ArtifactLocalizerHttpHandlerInternal) GsonBuilder(com.google.gson.GsonBuilder) ArtifactMeta(io.cdap.cdap.internal.app.runtime.artifact.ArtifactMeta) MasterEnvironments(io.cdap.cdap.master.environment.MasterEnvironments) AppJarHelper(io.cdap.cdap.common.test.AppJarHelper) Gson(com.google.gson.Gson) TaskWorkerHttpHandlerInternal(io.cdap.cdap.internal.app.worker.TaskWorkerHttpHandlerInternal) MasterEnvironmentRunnableContext(io.cdap.cdap.master.spi.environment.MasterEnvironmentRunnableContext) NettyHttpService(io.cdap.http.NettyHttpService) After(org.junit.After) Map(java.util.Map) ConfigTestApp(io.cdap.cdap.ConfigTestApp) ArtifactInfo(io.cdap.cdap.api.artifact.ArtifactInfo) CloseableClassLoader(io.cdap.cdap.api.artifact.CloseableClassLoader) ClassRule(org.junit.ClassRule) NoOpMetricsCollectionService(io.cdap.cdap.common.metrics.NoOpMetricsCollectionService) ArtifactManager(io.cdap.cdap.api.artifact.ArtifactManager) AuthenticationTestContext(io.cdap.cdap.security.auth.context.AuthenticationTestContext) AfterClass(org.junit.AfterClass) ArtifactDescriptor(io.cdap.cdap.internal.app.runtime.artifact.ArtifactDescriptor) ArtifactRepositoryReader(io.cdap.cdap.internal.app.runtime.artifact.ArtifactRepositoryReader) ApplicationSpecification(io.cdap.cdap.api.app.ApplicationSpecification) ProgramType(io.cdap.cdap.api.app.ProgramType) MasterEnvironment(io.cdap.cdap.master.spi.environment.MasterEnvironment) ChannelPipeline(io.netty.channel.ChannelPipeline) ApplicationClass(io.cdap.cdap.api.artifact.ApplicationClass) AppDeploymentInfo(io.cdap.cdap.internal.app.deploy.pipeline.AppDeploymentInfo) Id(io.cdap.cdap.common.id.Id) ApplicationSpecificationAdapter(io.cdap.cdap.internal.app.ApplicationSpecificationAdapter) CommonNettyHttpServiceBuilder(io.cdap.cdap.common.http.CommonNettyHttpServiceBuilder) ArtifactLocalizer(io.cdap.cdap.internal.app.worker.sidecar.ArtifactLocalizer) NamespaceMeta(io.cdap.cdap.proto.NamespaceMeta) List(java.util.List) Constants(io.cdap.cdap.common.conf.Constants) Configurator(io.cdap.cdap.app.deploy.Configurator) AppSpecInfo(io.cdap.cdap.internal.app.deploy.pipeline.AppSpecInfo) NotFoundException(io.cdap.cdap.common.NotFoundException) RemoteClientFactory(io.cdap.cdap.common.internal.remote.RemoteClientFactory) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) InMemoryDiscoveryService(org.apache.twill.discovery.InMemoryDiscoveryService) BeforeClass(org.junit.BeforeClass) InMemoryNamespaceAdmin(io.cdap.cdap.common.namespace.InMemoryNamespaceAdmin) Location(org.apache.twill.filesystem.Location) ChannelPipelineModifier(io.cdap.http.ChannelPipelineModifier) HashMap(java.util.HashMap) Supplier(java.util.function.Supplier) DiscoveryServiceClient(org.apache.twill.discovery.DiscoveryServiceClient) ArtifactHttpHandlerInternal(io.cdap.cdap.gateway.handlers.ArtifactHttpHandlerInternal) ConfiguratorTask(io.cdap.cdap.internal.app.worker.ConfiguratorTask) TwillRunnerService(org.apache.twill.api.TwillRunnerService) ArtifactId(io.cdap.cdap.proto.id.ArtifactId) ArtifactDetail(io.cdap.cdap.internal.app.runtime.artifact.ArtifactDetail) Nullable(javax.annotation.Nullable) DiscoveryService(org.apache.twill.discovery.DiscoveryService) URIScheme(io.cdap.cdap.common.discovery.URIScheme) DefaultArtifactRepository(io.cdap.cdap.internal.app.runtime.artifact.DefaultArtifactRepository) Test(org.junit.Test) IOException(java.io.IOException) LocationFactory(org.apache.twill.filesystem.LocationFactory) MetricsCollectionService(io.cdap.cdap.api.metrics.MetricsCollectionService) DefaultInternalAuthenticator(io.cdap.cdap.common.internal.remote.DefaultInternalAuthenticator) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) NamespaceAdmin(io.cdap.cdap.common.namespace.NamespaceAdmin) ArtifactRepository(io.cdap.cdap.internal.app.runtime.artifact.ArtifactRepository) HttpContentDecompressor(io.netty.handler.codec.http.HttpContentDecompressor) MasterEnvironmentRunnable(io.cdap.cdap.master.spi.environment.MasterEnvironmentRunnable) AllProgramsApp(io.cdap.cdap.AllProgramsApp) Assert(org.junit.Assert) Collections(java.util.Collections) TemporaryFolder(org.junit.rules.TemporaryFolder) RemoteClientFactory(io.cdap.cdap.common.internal.remote.RemoteClientFactory) CommonNettyHttpServiceBuilder(io.cdap.cdap.common.http.CommonNettyHttpServiceBuilder) InMemoryNamespaceAdmin(io.cdap.cdap.common.namespace.InMemoryNamespaceAdmin) NamespaceAdmin(io.cdap.cdap.common.namespace.NamespaceAdmin) AuthenticationTestContext(io.cdap.cdap.security.auth.context.AuthenticationTestContext) ArtifactLocalizer(io.cdap.cdap.internal.app.worker.sidecar.ArtifactLocalizer) TaskWorkerHttpHandlerInternal(io.cdap.cdap.internal.app.worker.TaskWorkerHttpHandlerInternal) NoOpMetricsCollectionService(io.cdap.cdap.common.metrics.NoOpMetricsCollectionService) ChannelPipeline(io.netty.channel.ChannelPipeline) HttpContentDecompressor(io.netty.handler.codec.http.HttpContentDecompressor) DefaultInternalAuthenticator(io.cdap.cdap.common.internal.remote.DefaultInternalAuthenticator) InMemoryNamespaceAdmin(io.cdap.cdap.common.namespace.InMemoryNamespaceAdmin) ArtifactHttpHandlerInternal(io.cdap.cdap.gateway.handlers.ArtifactHttpHandlerInternal) InMemoryDiscoveryService(org.apache.twill.discovery.InMemoryDiscoveryService) ChannelPipelineModifier(io.cdap.http.ChannelPipelineModifier) ArtifactLocalizerHttpHandlerInternal(io.cdap.cdap.internal.app.worker.sidecar.ArtifactLocalizerHttpHandlerInternal) BeforeClass(org.junit.BeforeClass)

Aggregations

NamespaceId (io.cdap.cdap.proto.id.NamespaceId)648 Test (org.junit.Test)292 Path (javax.ws.rs.Path)136 ApplicationId (io.cdap.cdap.proto.id.ApplicationId)124 NamespaceMeta (io.cdap.cdap.proto.NamespaceMeta)108 IOException (java.io.IOException)102 ProgramId (io.cdap.cdap.proto.id.ProgramId)86 GET (javax.ws.rs.GET)74 DatasetId (io.cdap.cdap.proto.id.DatasetId)68 ArrayList (java.util.ArrayList)64 BadRequestException (io.cdap.cdap.common.BadRequestException)60 ArtifactId (io.cdap.cdap.proto.id.ArtifactId)58 Principal (io.cdap.cdap.proto.security.Principal)56 Set (java.util.Set)52 Id (io.cdap.cdap.common.id.Id)50 File (java.io.File)50 HashSet (java.util.HashSet)50 NotFoundException (io.cdap.cdap.common.NotFoundException)48 NamespaceNotFoundException (io.cdap.cdap.common.NamespaceNotFoundException)46 HashMap (java.util.HashMap)46