Search in sources :

Example 36 with NamespaceId

use of io.cdap.cdap.proto.id.NamespaceId in project cdap by caskdata.

the class DatasetTypeHandlerTest method testNotFound.

@Test
public void testNotFound() throws Exception {
    NamespaceId nonExistent = new NamespaceId("nonExistent");
    HttpResponse response = makeModulesRequest(nonExistent);
    assertNamespaceNotFound(response, nonExistent);
    response = makeTypesRequest(nonExistent);
    assertNamespaceNotFound(response, nonExistent);
    DatasetModuleId datasetModule = nonExistent.datasetModule("module");
    response = makeModuleInfoRequest(datasetModule);
    assertNamespaceNotFound(response, nonExistent);
    DatasetTypeId datasetType = nonExistent.datasetType("type");
    response = makeTypeInfoRequest(datasetType);
    assertNamespaceNotFound(response, nonExistent);
    response = deployModule(datasetModule, TestModule1.class);
    assertNamespaceNotFound(response, nonExistent);
    response = deleteModule(datasetModule);
    assertNamespaceNotFound(response, nonExistent);
    response = deleteModules(nonExistent);
    assertNamespaceNotFound(response, nonExistent);
}
Also used : DatasetModuleId(io.cdap.cdap.proto.id.DatasetModuleId) DatasetTypeId(io.cdap.cdap.proto.id.DatasetTypeId) HttpResponse(io.cdap.common.http.HttpResponse) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) Test(org.junit.Test)

Example 37 with NamespaceId

use of io.cdap.cdap.proto.id.NamespaceId in project cdap by caskdata.

the class DatasetInstanceHandlerTest method testNotFound.

@Test
public void testNotFound() throws IOException {
    NamespaceId nonExistent = new NamespaceId("nonexistent");
    DatasetId datasetInstance = nonExistent.dataset("ds");
    HttpResponse response = makeInstancesRequest(nonExistent.getNamespace());
    assertNamespaceNotFound(response, nonExistent);
    // TODO: commented out for now until we add back namespace checks on get dataset CDAP-3901
    // response = getInstance(datasetInstance);
    // assertNamespaceNotFound(response, nonExistent);
    response = createInstance(datasetInstance, Table.class.getName(), null);
    assertNamespaceNotFound(response, nonExistent);
    response = updateInstance(datasetInstance, DatasetProperties.EMPTY);
    assertNamespaceNotFound(response, nonExistent);
    response = deleteInstance(datasetInstance);
    assertNamespaceNotFound(response, nonExistent);
    // it should be ok to use system
    response = getInstances(NamespaceId.SYSTEM.getNamespace());
    Assert.assertEquals(200, response.getResponseCode());
}
Also used : HttpResponse(io.cdap.common.http.HttpResponse) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) DatasetId(io.cdap.cdap.proto.id.DatasetId) Test(org.junit.Test)

Example 38 with NamespaceId

use of io.cdap.cdap.proto.id.NamespaceId in project cdap by caskdata.

the class AppLifecycleHttpHandler method getAllApps.

/**
 * Returns a list of applications associated with a namespace.
 */
@GET
@Path("/apps")
public void getAllApps(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @QueryParam("artifactName") String artifactName, @QueryParam("artifactVersion") String artifactVersion, @QueryParam("pageToken") String pageToken, @QueryParam("pageSize") Integer pageSize, @QueryParam("orderBy") SortOrder orderBy, @QueryParam("nameFilter") String nameFilter) throws Exception {
    NamespaceId namespace = validateNamespace(namespaceId);
    Set<String> names = new HashSet<>();
    if (!Strings.isNullOrEmpty(artifactName)) {
        for (String name : Splitter.on(',').split(artifactName)) {
            names.add(name);
        }
    }
    if (Optional.ofNullable(pageSize).orElse(0) != 0) {
        JsonPaginatedListResponder.respond(GSON, responder, APP_LIST_PAGINATED_KEY, jsonListResponder -> {
            AtomicReference<ApplicationRecord> lastRecord = new AtomicReference<>(null);
            ScanApplicationsRequest scanRequest = getScanRequest(namespaceId, artifactVersion, pageToken, pageSize, orderBy, nameFilter, names);
            boolean pageLimitReached = applicationLifecycleService.scanApplications(scanRequest, appDetail -> {
                ApplicationRecord record = new ApplicationRecord(appDetail);
                jsonListResponder.send(record);
                lastRecord.set(record);
            });
            ApplicationRecord record = lastRecord.get();
            return !pageLimitReached || record == null ? null : record.getName() + EntityId.IDSTRING_PART_SEPARATOR + record.getAppVersion();
        });
    } else {
        ScanApplicationsRequest scanRequest = getScanRequest(namespaceId, artifactVersion, pageToken, null, orderBy, nameFilter, names);
        JsonWholeListResponder.respond(GSON, responder, jsonListResponder -> applicationLifecycleService.scanApplications(scanRequest, d -> jsonListResponder.send(new ApplicationRecord(d))));
    }
}
Also used : ScanApplicationsRequest(io.cdap.cdap.app.store.ScanApplicationsRequest) AuditDetail(io.cdap.cdap.common.security.AuditDetail) ApplicationDetail(io.cdap.cdap.proto.ApplicationDetail) Arrays(java.util.Arrays) GsonBuilder(com.google.gson.GsonBuilder) ScanApplicationsRequest(io.cdap.cdap.app.store.ScanApplicationsRequest) ArtifactSummary(io.cdap.cdap.api.artifact.ArtifactSummary) Map(java.util.Map) HeaderParam(javax.ws.rs.HeaderParam) ApplicationNotFoundException(io.cdap.cdap.common.ApplicationNotFoundException) ProgramTerminator(io.cdap.cdap.internal.app.deploy.ProgramTerminator) EnumSet(java.util.EnumSet) HttpRequest(io.netty.handler.codec.http.HttpRequest) BodyConsumer(io.cdap.http.BodyConsumer) Set(java.util.Set) Reader(java.io.Reader) FullHttpRequest(io.netty.handler.codec.http.FullHttpRequest) StandardCharsets(java.nio.charset.StandardCharsets) Id(io.cdap.cdap.common.id.Id) JsonArray(com.google.gson.JsonArray) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) Singleton(com.google.inject.Singleton) Iterables(com.google.common.collect.Iterables) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Location(org.apache.twill.filesystem.Location) GET(javax.ws.rs.GET) AccessEnforcer(io.cdap.cdap.security.spi.authorization.AccessEnforcer) UnauthorizedException(io.cdap.cdap.security.spi.authorization.UnauthorizedException) ArrayList(java.util.ArrayList) Strings(com.google.common.base.Strings) NamespaceNotFoundException(io.cdap.cdap.common.NamespaceNotFoundException) WriteConflictException(io.cdap.cdap.internal.app.runtime.artifact.WriteConflictException) JsonWriter(com.google.gson.stream.JsonWriter) Nullable(javax.annotation.Nullable) AuditPolicy(io.cdap.cdap.common.security.AuditPolicy) AbstractBodyConsumer(io.cdap.cdap.common.http.AbstractBodyConsumer) Throwables(com.google.common.base.Throwables) DatasetManagementException(io.cdap.cdap.api.dataset.DatasetManagementException) IOException(java.io.IOException) ConflictException(io.cdap.cdap.common.ConflictException) NotImplementedException(io.cdap.cdap.common.NotImplementedException) InputStreamReader(java.io.InputStreamReader) ProgramRuntimeService(io.cdap.cdap.app.runtime.ProgramRuntimeService) File(java.io.File) ExecutionException(java.util.concurrent.ExecutionException) HttpHeaderNames(io.netty.handler.codec.http.HttpHeaderNames) JsonObject(com.google.gson.JsonObject) NamespaceQueryAdmin(io.cdap.cdap.common.namespace.NamespaceQueryAdmin) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) AccessException(io.cdap.cdap.api.security.AccessException) Inject(com.google.inject.Inject) LoggerFactory(org.slf4j.LoggerFactory) Path(javax.ws.rs.Path) Unpooled(io.netty.buffer.Unpooled) QueryParam(javax.ws.rs.QueryParam) Gson(com.google.gson.Gson) AuthenticationContext(io.cdap.cdap.security.spi.authentication.AuthenticationContext) DefaultValue(javax.ws.rs.DefaultValue) Splitter(com.google.common.base.Splitter) DELETE(javax.ws.rs.DELETE) SortOrder(io.cdap.cdap.spi.data.SortOrder) ApplicationUpdateDetail(io.cdap.cdap.proto.ApplicationUpdateDetail) BatchApplicationDetail(io.cdap.cdap.proto.BatchApplicationDetail) Collection(java.util.Collection) ApplicationLifecycleService(io.cdap.cdap.internal.app.services.ApplicationLifecycleService) HttpResponseStatus(io.netty.handler.codec.http.HttpResponseStatus) List(java.util.List) DefaultHttpHeaders(io.netty.handler.codec.http.DefaultHttpHeaders) CaseInsensitiveEnumTypeAdapterFactory(io.cdap.cdap.common.io.CaseInsensitiveEnumTypeAdapterFactory) Optional(java.util.Optional) Constants(io.cdap.cdap.common.conf.Constants) InvalidArtifactException(io.cdap.cdap.common.InvalidArtifactException) DirUtils(io.cdap.cdap.common.utils.DirUtils) ArtifactScope(io.cdap.cdap.api.artifact.ArtifactScope) ArtifactAlreadyExistsException(io.cdap.cdap.common.ArtifactAlreadyExistsException) NotFoundException(io.cdap.cdap.common.NotFoundException) StandardPermission(io.cdap.cdap.proto.security.StandardPermission) PathParam(javax.ws.rs.PathParam) TypeToken(com.google.common.reflect.TypeToken) ApplicationWithPrograms(io.cdap.cdap.internal.app.deploy.pipeline.ApplicationWithPrograms) EntityId(io.cdap.cdap.proto.id.EntityId) ServiceException(io.cdap.cdap.common.ServiceException) AtomicReference(java.util.concurrent.atomic.AtomicReference) JsonElement(com.google.gson.JsonElement) HashSet(java.util.HashSet) OutputStreamWriter(java.io.OutputStreamWriter) ByteBufInputStream(io.netty.buffer.ByteBufInputStream) AbstractAppFabricHttpHandler(io.cdap.cdap.gateway.handlers.util.AbstractAppFabricHttpHandler) ProgramController(io.cdap.cdap.app.runtime.ProgramController) Logger(org.slf4j.Logger) POST(javax.ws.rs.POST) HttpResponder(io.cdap.http.HttpResponder) HttpHeaderValues(io.netty.handler.codec.http.HttpHeaderValues) JsonSyntaxException(com.google.gson.JsonSyntaxException) ChunkResponder(io.cdap.http.ChunkResponder) ApplicationFilter(io.cdap.cdap.app.store.ApplicationFilter) ProgramId(io.cdap.cdap.proto.id.ProgramId) BadRequestException(io.cdap.cdap.common.BadRequestException) KerberosPrincipalId(io.cdap.cdap.proto.id.KerberosPrincipalId) ArtifactNotFoundException(io.cdap.cdap.common.ArtifactNotFoundException) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) NamespacePathLocator(io.cdap.cdap.common.namespace.NamespacePathLocator) PUT(javax.ws.rs.PUT) FileReader(java.io.FileReader) AppRequest(io.cdap.cdap.proto.artifact.AppRequest) ApplicationRecord(io.cdap.cdap.proto.ApplicationRecord) Collections(java.util.Collections) AtomicReference(java.util.concurrent.atomic.AtomicReference) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) HashSet(java.util.HashSet) ApplicationRecord(io.cdap.cdap.proto.ApplicationRecord) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 39 with NamespaceId

use of io.cdap.cdap.proto.id.NamespaceId in project cdap by caskdata.

the class ArtifactHttpHandler method deleteProperties.

@DELETE
@Path("/namespaces/{namespace-id}/artifacts/{artifact-name}/versions/{artifact-version}/properties")
public void deleteProperties(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("artifact-name") String artifactName, @PathParam("artifact-version") String artifactVersion) throws Exception {
    NamespaceId namespace = NamespaceId.SYSTEM.getNamespace().equalsIgnoreCase(namespaceId) ? NamespaceId.SYSTEM : validateAndGetNamespace(namespaceId);
    ArtifactId artifactId = validateAndGetArtifactId(namespace, artifactName, artifactVersion);
    try {
        artifactRepository.deleteArtifactProperties(Id.Artifact.fromEntityId(artifactId));
        responder.sendStatus(HttpResponseStatus.OK);
    } catch (IOException e) {
        LOG.error("Exception deleting properties for artifact {}.", artifactId, e);
        responder.sendString(HttpResponseStatus.INTERNAL_SERVER_ERROR, "Error deleting properties for artifact.");
    }
}
Also used : ArtifactId(io.cdap.cdap.proto.id.ArtifactId) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) IOException(java.io.IOException) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

Example 40 with NamespaceId

use of io.cdap.cdap.proto.id.NamespaceId in project cdap by caskdata.

the class ArtifactHttpHandler method getArtifacts.

@GET
@Path("/namespaces/{namespace-id}/artifacts")
public void getArtifacts(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @Nullable @QueryParam("scope") String scope) throws Exception {
    try {
        if (scope == null) {
            NamespaceId namespace = validateAndGetNamespace(namespaceId);
            responder.sendJson(HttpResponseStatus.OK, GSON.toJson(artifactRepository.getArtifactSummaries(namespace, true)));
        } else {
            NamespaceId namespace = validateAndGetScopedNamespace(Ids.namespace(namespaceId), scope);
            responder.sendJson(HttpResponseStatus.OK, GSON.toJson(artifactRepository.getArtifactSummaries(namespace, false)));
        }
    } catch (IOException e) {
        LOG.error("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 : NamespaceId(io.cdap.cdap.proto.id.NamespaceId) IOException(java.io.IOException) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

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