Search in sources :

Example 6 with NamespaceNotFoundException

use of io.cdap.cdap.common.NamespaceNotFoundException in project cdap by caskdata.

the class SchedulerQueueResolver method getQueue.

/**
 * Get queue at namespace level if it is empty returns the default queue.
 *
 * @param namespaceId NamespaceId
 * @return schedule queue at namespace level or default queue.
 */
@Nullable
public String getQueue(NamespaceId namespaceId) throws IOException, NamespaceNotFoundException {
    if (namespaceId.equals(NamespaceId.SYSTEM)) {
        return systemQueue;
    }
    NamespaceMeta meta;
    try {
        meta = namespaceQueryAdmin.get(namespaceId);
    } catch (NamespaceNotFoundException e) {
        throw e;
    } catch (Exception e) {
        throw new IOException(e);
    }
    if (meta != null) {
        NamespaceConfig config = meta.getConfig();
        String namespaceQueue = config.getSchedulerQueueName();
        return Strings.isNullOrEmpty(namespaceQueue) ? getDefaultQueue() : namespaceQueue;
    } else {
        return getDefaultQueue();
    }
}
Also used : NamespaceConfig(io.cdap.cdap.proto.NamespaceConfig) NamespaceMeta(io.cdap.cdap.proto.NamespaceMeta) IOException(java.io.IOException) NamespaceNotFoundException(io.cdap.cdap.common.NamespaceNotFoundException) NamespaceNotFoundException(io.cdap.cdap.common.NamespaceNotFoundException) IOException(java.io.IOException) Nullable(javax.annotation.Nullable)

Example 7 with NamespaceNotFoundException

use of io.cdap.cdap.common.NamespaceNotFoundException in project cdap by caskdata.

the class AppLifecycleHttpHandlerTest method testDeployNonExistingNamespace.

/**
 * Tests deploying an application in a non-existing non-default namespace.
 */
@Test
public void testDeployNonExistingNamespace() throws Exception {
    HttpResponse response = deploy(AllProgramsApp.class, 404, Constants.Gateway.API_VERSION_3_TOKEN, "random");
    NotFoundException nfe = new NamespaceNotFoundException(new NamespaceId("random"));
    Assert.assertEquals(nfe.getMessage(), response.getResponseBodyAsString());
}
Also used : HttpResponse(io.cdap.common.http.HttpResponse) NotFoundException(io.cdap.cdap.common.NotFoundException) NamespaceNotFoundException(io.cdap.cdap.common.NamespaceNotFoundException) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) NamespaceNotFoundException(io.cdap.cdap.common.NamespaceNotFoundException) Test(org.junit.Test)

Example 8 with NamespaceNotFoundException

use of io.cdap.cdap.common.NamespaceNotFoundException 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 9 with NamespaceNotFoundException

use of io.cdap.cdap.common.NamespaceNotFoundException 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 10 with NamespaceNotFoundException

use of io.cdap.cdap.common.NamespaceNotFoundException 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

NamespaceNotFoundException (io.cdap.cdap.common.NamespaceNotFoundException)24 NamespaceId (io.cdap.cdap.proto.id.NamespaceId)12 IOException (java.io.IOException)10 NotFoundException (io.cdap.cdap.common.NotFoundException)8 HttpResponse (io.cdap.common.http.HttpResponse)6 NamespaceMeta (io.cdap.cdap.proto.NamespaceMeta)5 Path (javax.ws.rs.Path)5 BadRequestException (io.cdap.cdap.common.BadRequestException)4 NamespaceCannotBeDeletedException (io.cdap.cdap.common.NamespaceCannotBeDeletedException)4 UnauthorizedException (io.cdap.cdap.security.spi.authorization.UnauthorizedException)4 GET (javax.ws.rs.GET)4 Test (org.junit.Test)4 NamespaceAlreadyExistsException (io.cdap.cdap.common.NamespaceAlreadyExistsException)3 URL (java.net.URL)3 ArtifactRange (io.cdap.cdap.api.artifact.ArtifactRange)2 DatasetManagementException (io.cdap.cdap.api.dataset.DatasetManagementException)2 SecureStoreMetadata (io.cdap.cdap.api.security.store.SecureStoreMetadata)2 NamespaceCannotBeCreatedException (io.cdap.cdap.common.NamespaceCannotBeCreatedException)2 ArtifactDetail (io.cdap.cdap.internal.app.runtime.artifact.ArtifactDetail)2 ApplicationId (io.cdap.cdap.proto.id.ApplicationId)2