use of io.cdap.cdap.common.BadRequestException in project cdap by caskdata.
the class ArtifactClient method deleteProperty.
/**
* Delete a property for an artifact. If the property does not exist, this will be a no-op.
*
* @param artifactId the artifact to delete a property from
* @param key the property to delete
* @throws BadRequestException if the request is invalid. For example, if the artifact name or version is invalid
* @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
* @throws ArtifactNotFoundException if the artifact does not exist
* @throws IOException if a network error occurred
*/
public void deleteProperty(ArtifactId artifactId, String key) throws IOException, UnauthenticatedException, ArtifactNotFoundException, BadRequestException, UnauthorizedException {
String path = String.format("artifacts/%s/versions/%s/properties/%s", artifactId.getArtifact(), artifactId.getVersion(), key);
URL url = config.resolveNamespacedURLV3(artifactId.getParent(), path);
HttpRequest.Builder requestBuilder = HttpRequest.delete(url);
HttpRequest request = requestBuilder.build();
HttpResponse response = restClient.execute(request, config.getAccessToken(), HttpURLConnection.HTTP_BAD_REQUEST, HttpURLConnection.HTTP_NOT_FOUND);
int responseCode = response.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_NOT_FOUND) {
throw new ArtifactNotFoundException(artifactId);
} else if (responseCode == HttpURLConnection.HTTP_BAD_REQUEST) {
throw new BadRequestException(response.getResponseBodyAsString());
}
}
use of io.cdap.cdap.common.BadRequestException in project cdap by caskdata.
the class ArtifactClient method deleteProperties.
/**
* Delete all properties for an artifact. If no properties exist, this will be a no-op.
*
* @param artifactId the artifact to delete properties from
* @throws BadRequestException if the request is invalid. For example, if the artifact name or version is invalid
* @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
* @throws ArtifactNotFoundException if the artifact does not exist
* @throws IOException if a network error occurred
*/
public void deleteProperties(ArtifactId artifactId) throws IOException, UnauthenticatedException, ArtifactNotFoundException, BadRequestException, UnauthorizedException {
String path = String.format("artifacts/%s/versions/%s/properties", artifactId.getArtifact(), artifactId.getVersion());
URL url = config.resolveNamespacedURLV3(artifactId.getParent(), path);
HttpRequest.Builder requestBuilder = HttpRequest.delete(url);
HttpRequest request = requestBuilder.build();
HttpResponse response = restClient.execute(request, config.getAccessToken(), HttpURLConnection.HTTP_BAD_REQUEST, HttpURLConnection.HTTP_NOT_FOUND);
int responseCode = response.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_NOT_FOUND) {
throw new ArtifactNotFoundException(artifactId);
} else if (responseCode == HttpURLConnection.HTTP_BAD_REQUEST) {
throw new BadRequestException(response.getResponseBodyAsString());
}
}
use of io.cdap.cdap.common.BadRequestException in project cdap by caskdata.
the class ArtifactClient method writeProperties.
/**
* Write properties for an artifact. Any existing properties will be overwritten.
*
* @param artifactId the artifact to add properties to
* @param properties the properties to add
* @throws BadRequestException if the request is invalid. For example, if the artifact name or version is invalid
* @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
* @throws ArtifactNotFoundException if the artifact does not exist
* @throws IOException if a network error occurred
*/
public void writeProperties(ArtifactId artifactId, Map<String, String> properties) throws IOException, UnauthenticatedException, ArtifactNotFoundException, BadRequestException, UnauthorizedException {
String path = String.format("artifacts/%s/versions/%s/properties", artifactId.getArtifact(), artifactId.getVersion());
URL url = config.resolveNamespacedURLV3(artifactId.getParent(), path);
HttpRequest.Builder requestBuilder = HttpRequest.put(url);
HttpRequest request = requestBuilder.withBody(GSON.toJson(properties)).build();
HttpResponse response = restClient.execute(request, config.getAccessToken(), HttpURLConnection.HTTP_BAD_REQUEST, HttpURLConnection.HTTP_NOT_FOUND);
int responseCode = response.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_NOT_FOUND) {
throw new ArtifactNotFoundException(artifactId);
} else if (responseCode == HttpURLConnection.HTTP_BAD_REQUEST) {
throw new BadRequestException(response.getResponseBodyAsString());
}
}
use of io.cdap.cdap.common.BadRequestException in project cdap by caskdata.
the class ApplicationClient method addSchedule.
/**
* Add a schedule to an application.
*
* @param app the application
* @param scheduleDetail the schedule to be added
*/
public void addSchedule(ApplicationId app, ScheduleDetail scheduleDetail) throws ApplicationNotFoundException, IOException, UnauthenticatedException, UnauthorizedException, BadRequestException {
String path = String.format("apps/%s/versions/%s/schedules/%s", app.getApplication(), app.getVersion(), scheduleDetail.getName());
HttpResponse response = restClient.execute(HttpMethod.PUT, config.resolveNamespacedURLV3(app.getParent(), path), GSON.toJson(scheduleDetail), ImmutableMap.<String, String>of(), config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND, HttpURLConnection.HTTP_BAD_REQUEST);
int responseCode = response.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_NOT_FOUND) {
throw new ApplicationNotFoundException(app);
} else if (responseCode == HttpURLConnection.HTTP_BAD_REQUEST) {
throw new BadRequestException(String.format("Bad Request. Reason: %s", response.getResponseBodyAsString()));
}
}
use of io.cdap.cdap.common.BadRequestException in project cdap by caskdata.
the class DatasetModuleClient method add.
/**
* Adds a new dataset module.
*
* @param module the new dataset module
* @param className name of the dataset module class within the moduleJarFile
* @param moduleJarFile Jar file containing the dataset module class and dependencies
* @throws BadRequestException if the moduleJarFile does not exist
* @throws AlreadyExistsException if a dataset module with the same name already exists
* @throws IOException if a network error occurred
*/
public void add(DatasetModuleId module, String className, File moduleJarFile) throws BadRequestException, AlreadyExistsException, IOException, UnauthenticatedException {
URL url = config.resolveNamespacedURLV3(module.getParent(), String.format("data/modules/%s", module.getModule()));
Map<String, String> headers = ImmutableMap.of("X-Class-Name", className);
HttpRequest request = HttpRequest.put(url).addHeaders(headers).withBody(moduleJarFile).build();
HttpResponse response = restClient.upload(request, config.getAccessToken(), HttpURLConnection.HTTP_BAD_REQUEST, HttpURLConnection.HTTP_CONFLICT);
if (response.getResponseCode() == HttpURLConnection.HTTP_BAD_REQUEST) {
throw new BadRequestException(String.format("Module jar file does not exist: %s", moduleJarFile));
} else if (response.getResponseCode() == HttpURLConnection.HTTP_CONFLICT) {
throw new DatasetModuleAlreadyExistsException(module);
}
}
Aggregations