use of co.cask.common.http.HttpResponse in project cdap by caskdata.
the class RemoteDatasetOpExecutor method update.
@Override
public DatasetSpecification update(DatasetId datasetInstanceId, DatasetTypeMeta typeMeta, DatasetProperties props, DatasetSpecification existing) throws Exception {
InternalDatasetCreationParams updateParams = new InternalDatasetUpdateParams(typeMeta, existing, props);
HttpResponse response = doRequest(datasetInstanceId, "update", GSON.toJson(updateParams));
return ObjectResponse.fromJsonBody(response, DatasetSpecification.class).getResponseObject();
}
use of co.cask.common.http.HttpResponse in project cdap by caskdata.
the class RemoteDatasetOpExecutor method doRequest.
private HttpResponse doRequest(DatasetId datasetInstanceId, String opName, @Nullable String body) throws IOException, ConflictException {
String path = String.format("namespaces/%s/data/datasets/%s/admin/%s", datasetInstanceId.getNamespace(), datasetInstanceId.getEntityName(), opName);
HttpRequest.Builder builder = remoteClient.requestBuilder(HttpMethod.POST, path);
if (body != null) {
builder.withBody(body);
}
String userId = authenticationContext.getPrincipal().getName();
if (userId != null) {
builder.addHeader(Constants.Security.Headers.USER_ID, userId);
}
HttpResponse httpResponse = remoteClient.execute(builder.build());
verifyResponse(httpResponse);
return httpResponse;
}
use of co.cask.common.http.HttpResponse in project cdap by caskdata.
the class RemoteDatasetOpExecutor method create.
@Override
public DatasetSpecification create(DatasetId datasetInstanceId, DatasetTypeMeta typeMeta, DatasetProperties props) throws Exception {
InternalDatasetCreationParams creationParams = new InternalDatasetCreationParams(typeMeta, props);
HttpResponse response = doRequest(datasetInstanceId, "create", GSON.toJson(creationParams));
return ObjectResponse.fromJsonBody(response, DatasetSpecification.class).getResponseObject();
}
use of co.cask.common.http.HttpResponse in project cdap by caskdata.
the class DatasetServiceClient method addInstance.
public void addInstance(String datasetInstanceName, String datasetType, DatasetProperties props, @Nullable KerberosPrincipalId owner) throws DatasetManagementException {
String ownerPrincipal = owner == null ? null : owner.getPrincipal();
DatasetInstanceConfiguration creationProperties = new DatasetInstanceConfiguration(datasetType, props.getProperties(), props.getDescription(), ownerPrincipal);
HttpResponse response = doPut("datasets/" + datasetInstanceName, GSON.toJson(creationProperties));
if (HttpResponseStatus.CONFLICT.code() == response.getResponseCode()) {
throw new InstanceConflictException(String.format("Failed to add instance %s due to conflict, details: %s", datasetInstanceName, response));
}
if (HttpResponseStatus.FORBIDDEN.code() == response.getResponseCode()) {
throw new DatasetManagementException(String.format("Failed to add instance %s, details: %s", datasetInstanceName, response), new UnauthorizedException(response.getResponseBodyAsString()));
}
if (HttpResponseStatus.OK.code() != response.getResponseCode()) {
throw new DatasetManagementException(String.format("Failed to add instance %s, details: %s", datasetInstanceName, response));
}
}
use of co.cask.common.http.HttpResponse in project cdap by caskdata.
the class ExploreHttpClient method doPartitionOperation.
private QueryHandle doPartitionOperation(DatasetId datasetId, DatasetSpecification spec, PartitionKey key, String endpoint, String operationName, Map<String, String> additionalArguments) throws ExploreException {
Map<String, String> args = new HashMap<>(additionalArguments);
PartitionedFileSetArguments.setOutputPartitionKey(args, key);
String tableName = ExploreProperties.getExploreTableName(spec.getProperties());
String databaseName = ExploreProperties.getExploreDatabaseName(spec.getProperties());
if (tableName != null) {
args.put(ExploreProperties.PROPERTY_EXPLORE_TABLE_NAME, tableName);
}
if (databaseName != null) {
args.put(ExploreProperties.PROPERTY_EXPLORE_DATABASE_NAME, databaseName);
}
HttpResponse response = doPost(String.format("namespaces/%s/data/explore/datasets/%s/%s", datasetId.getNamespace(), datasetId.getEntityName(), endpoint), GSON.toJson(args), null);
if (response.getResponseCode() == HttpURLConnection.HTTP_OK) {
return QueryHandle.fromId(parseResponseAsMap(response, "handle"));
}
throw new ExploreException(String.format("Cannot %s partition with key %s in dataset %s. Reason: %s", operationName, key, datasetId.toString(), response));
}
Aggregations