use of co.cask.common.http.HttpResponse in project cdap by caskdata.
the class ProgramClient method getWorkflowCurrent.
/**
* Get the current run information for the Workflow based on the runid
*
* @param workflowId ID of the workflow
* @param runId ID of the run for which the details are to be returned
* @return list of {@link WorkflowActionNode} currently running for the given runid
* @throws IOException if a network error occurred
* @throws NotFoundException if the application, workflow, or runid could not be found
* @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
*/
public List<WorkflowActionNode> getWorkflowCurrent(WorkflowId workflowId, String runId) throws IOException, NotFoundException, UnauthenticatedException, UnauthorizedException {
String path = String.format("/apps/%s/workflows/%s/runs/%s/current", workflowId.getApplication(), workflowId.getProgram(), runId);
URL url = config.resolveNamespacedURLV3(workflowId.getNamespaceId(), path);
HttpResponse response = restClient.execute(HttpMethod.GET, url, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND);
if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
throw new NotFoundException(workflowId.run(runId));
}
ObjectResponse<List<WorkflowActionNode>> objectResponse = ObjectResponse.fromJsonBody(response, new TypeToken<List<WorkflowActionNode>>() {
}.getType(), GSON);
return objectResponse.getResponseObject();
}
use of co.cask.common.http.HttpResponse in project cdap by caskdata.
the class AbstractMetadataClient method searchMetadata.
/**
* Searches entities in the specified namespace whose metadata matches the specified query.
*
* @param namespace the namespace to search in
* @param query the query string with which to search
* @param targets {@link EntityTypeSimpleName}s to search. If empty, all possible types will be searched
* @param sort specifies sort field and sort order. If {@code null}, the sort order is by relevance
* @param offset the index to start with in the search results. To return results from the beginning, pass {@code 0}
* @param limit the number of results to return, starting from #offset. To return all, pass {@link Integer#MAX_VALUE}
* @param numCursors the number of cursors to return in the response. A cursor identifies the first index of the
* next page for pagination purposes
* @param cursor the cursor that acts as the starting index for the requested page. This is only applicable when
* #sortInfo is not default. If offset is also specified, it is applied starting at
* the cursor. If {@code null}, the first row is used as the cursor
* @param showHidden boolean which specifies whether to display hidden entities (entity whose name start with "_")
* or not.
* @return A set of {@link MetadataSearchResultRecord} for the given query.
*/
public MetadataSearchResponse searchMetadata(Id.Namespace namespace, String query, Set<EntityTypeSimpleName> targets, @Nullable String sort, int offset, int limit, int numCursors, @Nullable String cursor, boolean showHidden) throws IOException, UnauthenticatedException, UnauthorizedException, BadRequestException {
String path = String.format("metadata/search?query=%s", query);
for (EntityTypeSimpleName t : targets) {
path += "&target=" + t;
}
if (sort != null) {
path += "&sort=" + URLEncoder.encode(sort, "UTF-8");
}
path += "&offset=" + offset;
path += "&limit=" + limit;
path += "&numCursors=" + numCursors;
if (cursor != null) {
path += "&cursor=" + cursor;
}
if (showHidden) {
path += "&showHidden=" + true;
}
URL searchURL = resolve(namespace, path);
HttpResponse response = execute(HttpRequest.get(searchURL).build(), HttpResponseStatus.BAD_REQUEST.getCode());
if (HttpResponseStatus.BAD_REQUEST.getCode() == response.getResponseCode()) {
throw new BadRequestException(response.getResponseBodyAsString());
}
return GSON.fromJson(response.getResponseBodyAsString(), MetadataSearchResponse.class);
}
use of co.cask.common.http.HttpResponse in project cdap by caskdata.
the class AbstractMetadataClient method searchMetadata.
/**
* Searches entities in the specified namespace whose metadata matches the specified query.
*
* @param namespace the namespace to search in
* @param query the query string with which to search
* @param targets {@link EntityTypeSimpleName}s to search. If empty, all possible types will be searched
* @param sort specifies sort field and sort order. If {@code null}, the sort order is by relevance
* @param offset the index to start with in the search results. To return results from the beginning, pass {@code 0}
* @param limit the number of results to return, starting from #offset. To return all, pass {@link Integer#MAX_VALUE}
* @param numCursors the number of cursors to return in the response. A cursor identifies the first index of the
* next page for pagination purposes
* @param cursor the cursor that acts as the starting index for the requested page. This is only applicable when
* #sortInfo is not default. If offset is also specified, it is applied starting at
* the cursor. If {@code null}, the first row is used as the cursor
* @param showHidden boolean which specifies whether to display hidden entities (entity whose name start with "_")
* or not.
* @return A set of {@link MetadataSearchResultRecord} for the given query.
*/
public MetadataSearchResponse searchMetadata(NamespaceId namespace, String query, Set<EntityTypeSimpleName> targets, @Nullable String sort, int offset, int limit, int numCursors, @Nullable String cursor, boolean showHidden) throws IOException, UnauthenticatedException, UnauthorizedException, BadRequestException {
String path = String.format("metadata/search?query=%s", query);
for (EntityTypeSimpleName t : targets) {
path += "&target=" + t;
}
if (sort != null) {
path += "&sort=" + URLEncoder.encode(sort, "UTF-8");
}
path += "&offset=" + offset;
path += "&limit=" + limit;
path += "&numCursors=" + numCursors;
if (cursor != null) {
path += "&cursor=" + cursor;
}
if (showHidden) {
path += "&showHidden=" + true;
}
URL searchURL = resolve(namespace, path);
HttpResponse response = execute(HttpRequest.get(searchURL).build(), HttpResponseStatus.BAD_REQUEST.code());
if (HttpResponseStatus.BAD_REQUEST.code() == response.getResponseCode()) {
throw new BadRequestException(response.getResponseBodyAsString());
}
return GSON.fromJson(response.getResponseBodyAsString(), MetadataSearchResponse.class);
}
use of co.cask.common.http.HttpResponse in project cdap by caskdata.
the class AbstractMetadataClient method doGetMetadata.
private Set<MetadataRecord> doGetMetadata(Id.NamespacedId namespacedId, String entityPath, @Nullable MetadataScope scope) throws IOException, UnauthenticatedException, NotFoundException, BadRequestException, UnauthorizedException {
String path = String.format("%s/metadata", entityPath);
path = scope == null ? path : String.format("%s?scope=%s", path, scope);
HttpResponse response = makeRequest(namespacedId, path, HttpMethod.GET);
return GSON.fromJson(response.getResponseBodyAsString(), SET_METADATA_RECORD_TYPE);
}
use of co.cask.common.http.HttpResponse in project cdap by caskdata.
the class AbstractMetadataClient method getProperties.
private Map<String, String> getProperties(Id.NamespacedId namespacedId, String entityPath, @Nullable MetadataScope scope) throws IOException, UnauthenticatedException, NotFoundException, BadRequestException, UnauthorizedException {
String path = String.format("%s/metadata/properties", entityPath);
path = scope == null ? path : String.format("%s?scope=%s", path, scope);
HttpResponse response = makeRequest(namespacedId, path, HttpMethod.GET);
return GSON.fromJson(response.getResponseBodyAsString(), MAP_STRING_STRING_TYPE);
}
Aggregations