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();
}
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();
}
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();
}
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));
}
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);
}
Aggregations