Search in sources :

Example 16 with NotFoundException

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

the class ServiceClient method get.

/**
 * Gets a {@link ServiceSpecification} for a {@link Service}.
 *
 * @param service ID of the service
 * @return {@link ServiceSpecification} representing the service
 * @throws IOException if a network error occurred
 * @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
 * @throws NotFoundException if the app or service could not be found
 */
public ServiceSpecification get(ProgramId service) throws IOException, UnauthenticatedException, NotFoundException, UnauthorizedException {
    URL url = config.resolveNamespacedURLV3(service.getNamespaceId(), String.format("apps/%s/versions/%s/services/%s", service.getApplication(), service.getVersion(), service.getProgram()));
    HttpResponse response = restClient.execute(HttpMethod.GET, url, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND);
    if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
        throw new NotFoundException(service);
    }
    return ObjectResponse.fromJsonBody(response, ServiceSpecification.class).getResponseObject();
}
Also used : ServiceSpecification(io.cdap.cdap.api.service.ServiceSpecification) HttpResponse(io.cdap.common.http.HttpResponse) NotFoundException(io.cdap.cdap.common.NotFoundException) URL(java.net.URL)

Example 17 with NotFoundException

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

the class WorkflowClient method getWorkflowToken.

/**
 * Retrieve the {@link WorkflowToken} for the specified workflow run filtered by the specified
 * {@link WorkflowToken.Scope} and key.
 *
 * @param workflowRunId the run id of the workflow
 * @param scope the specified {@link WorkflowToken.Scope}. If null, it returns keys for
 * {@link WorkflowToken.Scope#USER}
 * @param key the specified key. If null, it returns all keys in the specified {@link WorkflowToken.Scope}
 * @return {@link WorkflowTokenDetail} with the specified filters
 */
public WorkflowTokenDetail getWorkflowToken(ProgramRunId workflowRunId, @Nullable WorkflowToken.Scope scope, @Nullable String key) throws IOException, UnauthenticatedException, NotFoundException, UnauthorizedException {
    String path = String.format("apps/%s/workflows/%s/runs/%s/token", workflowRunId.getApplication(), workflowRunId.getProgram(), workflowRunId.getRun());
    URL url = config.resolveNamespacedURLV3(workflowRunId.getNamespaceId(), appendScopeAndKeyToUrl(path, scope, key));
    HttpResponse response = restClient.execute(HttpMethod.GET, url, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND);
    if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
        String msg = "Either the workflow or its run id";
        if (key != null) {
            msg = String.format("%s or the specified key at the specified scope", msg);
        }
        throw new NotFoundException(workflowRunId, msg);
    }
    return ObjectResponse.fromJsonBody(response, WorkflowTokenDetail.class, GSON).getResponseObject();
}
Also used : HttpResponse(io.cdap.common.http.HttpResponse) NotFoundException(io.cdap.cdap.common.NotFoundException) WorkflowTokenDetail(io.cdap.cdap.proto.WorkflowTokenDetail) URL(java.net.URL)

Example 18 with NotFoundException

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

the class WorkflowClient method getWorkflowTokenAtNode.

/**
 * Retrieve the keys set by the specified node in the {@link WorkflowToken} for the specified workflow run
 * filtered by the specified {@link WorkflowToken.Scope} and key.
 *
 * @param workflowRunId the run id of the workflow
 * @param nodeName the name of the node
 * @param scope the specified {@link WorkflowToken.Scope}
 * @param key the specified key
 * @return {@link WorkflowTokenDetail} with the specified filters
 */
public WorkflowTokenNodeDetail getWorkflowTokenAtNode(ProgramRunId workflowRunId, String nodeName, @Nullable WorkflowToken.Scope scope, @Nullable String key) throws IOException, UnauthenticatedException, NotFoundException, UnauthorizedException {
    String path = String.format("apps/%s/workflows/%s/runs/%s/nodes/%s/token", workflowRunId.getApplication(), workflowRunId.getProgram(), workflowRunId.getRun(), nodeName);
    URL url = config.resolveNamespacedURLV3(workflowRunId.getNamespaceId(), appendScopeAndKeyToUrl(path, scope, key));
    HttpResponse response = restClient.execute(HttpMethod.GET, url, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND);
    if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
        String msg = "Either the workflow or its run id";
        if (key != null) {
            msg = String.format("%s or the specified key at the specified scope", msg);
        }
        throw new NotFoundException(workflowRunId, msg);
    }
    return ObjectResponse.fromJsonBody(response, WorkflowTokenNodeDetail.class, GSON).getResponseObject();
}
Also used : WorkflowTokenNodeDetail(io.cdap.cdap.proto.WorkflowTokenNodeDetail) HttpResponse(io.cdap.common.http.HttpResponse) NotFoundException(io.cdap.cdap.common.NotFoundException) URL(java.net.URL)

Example 19 with NotFoundException

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

the class ProfileStore method deleteProfile.

/**
 * Deletes the profile from the profile store
 *
 * @param profileId the id of the profile to delete
 * @throws NotFoundException if the profile is not found
 * @throws ProfileConflictException if the profile is enabled
 */
public void deleteProfile(ProfileId profileId) throws NotFoundException, ProfileConflictException, IOException {
    Collection<Field<?>> fields = getProfileKeys(profileId);
    Profile value = getProfileInternal(fields);
    if (value == null) {
        throw new NotFoundException(profileId);
    }
    if (value.getStatus() == ProfileStatus.ENABLED) {
        throw new ProfileConflictException(String.format("Profile %s in namespace %s is currently enabled. A profile can " + "only be deleted if it is disabled", profileId.getProfile(), profileId.getNamespace()), profileId);
    }
    profileTable.delete(getProfileKeys(profileId));
}
Also used : Field(io.cdap.cdap.spi.data.table.field.Field) TableNotFoundException(io.cdap.cdap.spi.data.TableNotFoundException) NotFoundException(io.cdap.cdap.common.NotFoundException) ProfileConflictException(io.cdap.cdap.common.ProfileConflictException) Profile(io.cdap.cdap.proto.profile.Profile)

Example 20 with NotFoundException

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

the class ProfileStore method removeProfileAssignment.

/**
 * Remove an assignment from the profile.
 *
 * @param profileId the profile id
 * @param entityId the entity to remove from the assignment
 * @throws NotFoundException if the profile is not found
 */
public void removeProfileAssignment(ProfileId profileId, EntityId entityId) throws NotFoundException, IOException {
    Collection<Field<?>> keys = getProfileKeys(profileId);
    Profile profile = getProfileInternal(keys);
    if (profile == null) {
        throw new NotFoundException(profileId);
    }
    addEntityIdKey(keys, entityId);
    profileEntityTable.delete(keys);
}
Also used : Field(io.cdap.cdap.spi.data.table.field.Field) TableNotFoundException(io.cdap.cdap.spi.data.TableNotFoundException) NotFoundException(io.cdap.cdap.common.NotFoundException) Profile(io.cdap.cdap.proto.profile.Profile)

Aggregations

NotFoundException (io.cdap.cdap.common.NotFoundException)266 HttpResponse (io.cdap.common.http.HttpResponse)86 URL (java.net.URL)76 ApplicationNotFoundException (io.cdap.cdap.common.ApplicationNotFoundException)54 ProgramId (io.cdap.cdap.proto.id.ProgramId)52 NamespaceNotFoundException (io.cdap.cdap.common.NamespaceNotFoundException)50 ApplicationId (io.cdap.cdap.proto.id.ApplicationId)50 Path (javax.ws.rs.Path)50 BadRequestException (io.cdap.cdap.common.BadRequestException)42 ProgramNotFoundException (io.cdap.cdap.common.ProgramNotFoundException)42 ApplicationSpecification (io.cdap.cdap.api.app.ApplicationSpecification)36 NamespaceId (io.cdap.cdap.proto.id.NamespaceId)36 IOException (java.io.IOException)36 GET (javax.ws.rs.GET)36 Test (org.junit.Test)30 ProgramRunId (io.cdap.cdap.proto.id.ProgramRunId)28 HashMap (java.util.HashMap)28 ProgramSpecification (io.cdap.cdap.api.ProgramSpecification)26 ConflictException (io.cdap.cdap.common.ConflictException)26 ArrayList (java.util.ArrayList)26