Search in sources :

Example 91 with NamespaceId

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

the class ProfileHttpHandler method getProfiles.

/**
 * List the profiles in the given namespace. By default the results will not contain profiles in system scope.
 */
@GET
@Path("/namespaces/{namespace-id}/profiles")
public void getProfiles(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @QueryParam("includeSystem") @DefaultValue("false") String includeSystem) throws Exception {
    NamespaceId namespace = getValidatedNamespace(namespaceId);
    accessEnforcer.enforceOnParent(EntityType.PROFILE, namespace, authenticationContext.getPrincipal(), StandardPermission.LIST);
    boolean include = Boolean.valueOf(includeSystem);
    if (include) {
        accessEnforcer.enforceOnParent(EntityType.PROFILE, NamespaceId.SYSTEM, authenticationContext.getPrincipal(), StandardPermission.LIST);
    }
    List<Profile> profiles = verifyCpuLabelsProfiles(profileService.getProfiles(namespace, include), namespace);
    responder.sendJson(HttpResponseStatus.OK, GSON.toJson(profiles));
}
Also used : NamespaceId(io.cdap.cdap.proto.id.NamespaceId) Profile(io.cdap.cdap.proto.profile.Profile) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 92 with NamespaceId

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

the class ProfileHttpHandler method getSystemProfiles.

@GET
@Path("/profiles")
public void getSystemProfiles(HttpRequest request, HttpResponder responder) throws Exception {
    NamespaceId namespaceId = NamespaceId.SYSTEM;
    accessEnforcer.enforceOnParent(EntityType.PROFILE, namespaceId, authenticationContext.getPrincipal(), StandardPermission.LIST);
    List<Profile> profiles = verifyCpuLabelsProfiles(profileService.getProfiles(namespaceId, true), NamespaceId.SYSTEM);
    responder.sendJson(HttpResponseStatus.OK, GSON.toJson(profiles));
}
Also used : NamespaceId(io.cdap.cdap.proto.id.NamespaceId) Profile(io.cdap.cdap.proto.profile.Profile) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 93 with NamespaceId

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

the class AppLifecycleHttpHandlerInternal method getAppDetailForVersion.

/**
 * Get {@link ApplicationDetail} for a given application
 *
 * @param request     {@link HttpRequest}
 * @param responder   {@link HttpResponse}
 * @param namespace   the namespace to get all application details
 * @param application the id of the application to get its {@link ApplicationDetail}
 * @throws Exception if either namespace or application doesn't exist, or failed to get {@link ApplicationDetail}
 */
@GET
@Path("/app/{app-id}/versions/{version-id}")
public void getAppDetailForVersion(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") final String namespace, @PathParam("app-id") final String application, @PathParam("version-id") final String version) throws Exception {
    NamespaceId namespaceId = new NamespaceId(namespace);
    if (!namespaceQueryAdmin.exists(namespaceId)) {
        throw new NamespaceNotFoundException(namespaceId);
    }
    ApplicationId appId = new ApplicationId(namespace, application, version);
    responder.sendJson(HttpResponseStatus.OK, GSON.toJson(applicationLifecycleService.getAppDetail(appId)));
}
Also used : NamespaceId(io.cdap.cdap.proto.id.NamespaceId) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) NamespaceNotFoundException(io.cdap.cdap.common.NamespaceNotFoundException) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 94 with NamespaceId

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

the class AppLifecycleHttpHandlerInternal method getAppDetail.

/**
 * Get {@link ApplicationDetail} for a given application
 *
 * @param request     {@link HttpRequest}
 * @param responder   {@link HttpResponse}
 * @param namespace   the namespace to get all application details   *
 * @param application the id of the application to get its {@link ApplicationDetail}
 * @throws Exception if either namespace or application doesn't exist, or failed to get {@link ApplicationDetail}
 */
@GET
@Path("/app/{app-id}")
public void getAppDetail(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespace, @PathParam("app-id") String application) throws Exception {
    NamespaceId namespaceId = new NamespaceId(namespace);
    if (!namespaceQueryAdmin.exists(namespaceId)) {
        throw new NamespaceNotFoundException(namespaceId);
    }
    ApplicationId appId = new ApplicationId(namespace, application);
    responder.sendJson(HttpResponseStatus.OK, GSON.toJson(applicationLifecycleService.getAppDetail(appId)));
}
Also used : NamespaceId(io.cdap.cdap.proto.id.NamespaceId) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) NamespaceNotFoundException(io.cdap.cdap.common.NamespaceNotFoundException) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 95 with NamespaceId

use of io.cdap.cdap.proto.id.NamespaceId 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)

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