private void checkLevels(int levels) throws BadRequestException { if (levels < 1) { throw new BadRequestException(String.format("Invalid levels (%d), should be greater than 0.", levels)); } }
private void validateResponse(HttpURLConnection urlConn) throws Exception { int responseCode = urlConn.getResponseCode(); if (responseCode == HttpURLConnection.HTTP_OK) { return; } String errorMessage = new String(ByteStreams.toByteArray(urlConn.getErrorStream()), Charsets.UTF_8); if (responseCode == HttpURLConnection.HTTP_BAD_REQUEST) { throw new BadRequestException(errorMessage); } throw new Exception("Spark execution service request failed: " + errorMessage); } }
private void validateResponse(HttpURLConnection urlConn) throws Exception { int responseCode = urlConn.getResponseCode(); if (responseCode == HttpURLConnection.HTTP_OK) { return; } String errorMessage = new String(ByteStreams.toByteArray(urlConn.getErrorStream()), Charsets.UTF_8); if (responseCode == HttpURLConnection.HTTP_BAD_REQUEST) { throw new BadRequestException(errorMessage); } throw new Exception("Spark execution service request failed: " + errorMessage); } }
private ArtifactScope validateScope(String scope) throws BadRequestException { try { return ArtifactScope.valueOf(scope.toUpperCase()); } catch (IllegalArgumentException e) { throw new BadRequestException("Invalid scope " + scope); } }
private ArtifactId validateAndGetArtifactId(NamespaceId namespace, String name, String version) throws BadRequestException { try { return namespace.artifact(name, version); } catch (Exception e) { throw new BadRequestException(e.getMessage()); } }
private ProfileId getValidatedProfile(NamespaceId namespaceId, String profileName) throws BadRequestException { try { return namespaceId.profile(profileName); } catch (IllegalArgumentException e) { throw new BadRequestException(e.getMessage(), e); } }
static DatasetTypeId toDatasetTypeId(String namespace, String typeName) throws BadRequestException { try { return new DatasetTypeId(namespace, typeName); } catch (IllegalArgumentException | NullPointerException e) { throw new BadRequestException(e.getMessage()); } }
private NamespaceMeta getNamespaceMeta(FullHttpRequest request) throws BadRequestException { try { return parseBody(request, NamespaceMeta.class); } catch (JsonSyntaxException e) { throw new BadRequestException("Invalid json object provided in request body."); } } }
private ArtifactScope validateScope(String scope) throws BadRequestException { try { return ArtifactScope.valueOf(scope.toUpperCase()); } catch (IllegalArgumentException e) { throw new BadRequestException("Invalid scope " + scope); } }
private ArtifactId validateAndGetArtifactId(NamespaceId namespace, String name, String version) throws BadRequestException { try { return namespace.artifact(name, version); } catch (Exception e) { throw new BadRequestException(e.getMessage()); } }
/** * Helper method to get the {@link LogLevelUpdater} for the program. */ private LogLevelUpdater getLogLevelUpdater(RuntimeInfo runtimeInfo) throws Exception { ProgramController programController = runtimeInfo.getController(); if (!(programController instanceof LogLevelUpdater)) { throw new BadRequestException("Update log levels at runtime is only supported in distributed mode"); } return ((LogLevelUpdater) programController); }
private MetadataScope validateScope(String scope) throws BadRequestException { try { return MetadataScope.valueOf(scope.toUpperCase()); } catch (IllegalArgumentException e) { throw new BadRequestException(String.format("Invalid metadata scope '%s'. Expected '%s' or '%s'", scope, MetadataScope.USER, MetadataScope.SYSTEM)); } }
private Constants.FieldLineage.Direction parseDirection(String directionStr) throws BadRequestException { try { return Constants.FieldLineage.Direction.valueOf(directionStr.toUpperCase()); } catch (IllegalArgumentException e) { String directionValues = Joiner.on(", ").join(Constants.FieldLineage.Direction.values()); throw new BadRequestException(String.format("Direction must be specified to get the field lineage " + "summary and should be one of the following: [%s].", directionValues.toLowerCase())); } } }
protected int getInstances(FullHttpRequest request) throws BadRequestException { Instances instances; try { instances = parseBody(request, Instances.class); } catch (JsonSyntaxException e) { throw new BadRequestException("Invalid JSON in request: " + e.getMessage()); } if (instances == null) { throw new BadRequestException("Invalid instance value in request"); } return instances.getInstances(); }
static DatasetTypeId toDatasetTypeId(NamespaceId namespace, String typeName) throws BadRequestException { try { return new DatasetTypeId(namespace.getNamespace(), typeName); } catch (IllegalArgumentException | NullPointerException e) { throw new BadRequestException(e.getMessage()); } }
private static <T> T doReadExploreParameters(FullHttpRequest request, Class<T> clz) throws BadRequestException, IOException { try (Reader reader = new InputStreamReader(new ByteBufInputStream(request.content()), StandardCharsets.UTF_8)) { return GSON.fromJson(reader, clz); } catch (JsonSyntaxException | NullPointerException e) { throw new BadRequestException("Cannot read dataset specification from request: " + e.getMessage(), e); } }
static DatasetInstanceConfiguration getInstanceConfiguration(FullHttpRequest request) throws BadRequestException { Reader reader = new InputStreamReader(new ByteBufInputStream(request.content()), StandardCharsets.UTF_8); try { DatasetInstanceConfiguration config = GSON.fromJson(reader, DatasetInstanceConfiguration.class); Preconditions.checkNotNull(config.getTypeName(), "The typeName must be specified."); return config; } catch (JsonSyntaxException | NullPointerException e) { throw new BadRequestException(e.getMessage()); } }
static DatasetInstanceConfiguration getInstanceConfiguration(FullHttpRequest request) throws BadRequestException { Reader reader = new InputStreamReader(new ByteBufInputStream(request.content()), StandardCharsets.UTF_8); try { DatasetInstanceConfiguration config = GSON.fromJson(reader, DatasetInstanceConfiguration.class); Preconditions.checkNotNull(config.getTypeName(), "The typeName must be specified."); return config; } catch (JsonSyntaxException | NullPointerException e) { throw new BadRequestException(e.getMessage()); } }
static Map<String, String> getProperties(FullHttpRequest request) throws BadRequestException { Reader reader = new InputStreamReader(new ByteBufInputStream(request.content()), StandardCharsets.UTF_8); try { return GSON.fromJson(reader, new TypeToken<Map<String, String>>() { }.getType()); } catch (JsonSyntaxException e) { throw new BadRequestException(e.getMessage()); } }
static Map<String, String> getProperties(FullHttpRequest request) throws BadRequestException { Reader reader = new InputStreamReader(new ByteBufInputStream(request.content()), StandardCharsets.UTF_8); try { return GSON.fromJson(reader, new TypeToken<Map<String, String>>() { }.getType()); } catch (JsonSyntaxException e) { throw new BadRequestException(e.getMessage()); } }