/** * Checks that object reference is not null, throws {@link ValidationException} in the case of * null {@code object} with given {@code message}. */ private static void checkNotNull(Object object, String message) throws ValidationException { if (object == null) { throw new ValidationException(message); } }
/** * Checks that expression is true, throws {@link ValidationException} otherwise. * * <p>Exception uses error message built from error message template and error message parameters. */ private static void check(boolean expression, String message) throws ValidationException { if (!expression) { throw new ValidationException(message); } } }
private void checkNotNull(Object object, String errorMessage) throws ValidationException { if (object == null) { throw new ValidationException(errorMessage); } }
private static void checkArgument(boolean expression, String error) throws ValidationException { if (!expression) { throw new ValidationException(error); } }
private static void checkArgument(boolean expression, String error) throws ValidationException { if (!expression) { throw new ValidationException(error); } }
private static void checkArgument( boolean expression, String errorMessageTemplate, Object... errorMessageParams) throws ValidationException { if (!expression) { throw new ValidationException(format(errorMessageTemplate, errorMessageParams)); } } }
private static void checkNotNull( Object object, String errorMessageTemplate, Object... errorMessageParams) throws ValidationException { if (object == null) { throw new ValidationException(format(errorMessageTemplate, errorMessageParams)); } } }
private static void checkNotNull( Object object, String errorMessageTemplate, Object... errorMessageParams) throws ValidationException { if (object == null) { throw new ValidationException(format(errorMessageTemplate, errorMessageParams)); } } }
private static void checkArgument( boolean expression, String errorMessageTemplate, Object... errorMessageParams) throws ValidationException { if (!expression) { throw new ValidationException(format(errorMessageTemplate, errorMessageParams)); } } }
private static void checkNotNull( Object object, String errorMessageTemplate, Object... errorMessageParams) throws ValidationException { if (object == null) { throw new ValidationException(format(errorMessageTemplate, errorMessageParams)); } } }
/** * Checks that expression is true, throws {@link ValidationException} otherwise. * * <p>Exception uses error message built from error message template and error message parameters. */ private static void check(boolean expression, String fmt, Object... args) throws ValidationException { if (!expression) { throw new ValidationException(format(fmt, args)); } }
private void checkNotNull(Object object, String messageFmt, Object... messageArguments) throws ValidationException { if (object == null) { throw new ValidationException(format(messageFmt, messageArguments)); } } }
/** Parses link content into depends_on field representation - removes column and further chars */ private String getContainerFromLink(String link) throws ValidationException { String container = link; if (link != null) { String[] split = container.split(":"); if (split.length > 2) { throw new ValidationException(format("Service link '%s' is invalid", link)); } container = split[0]; } return container; }
private void validateLongAttribute( String attributeName, String attributeValue, String machineName) throws ValidationException { if (attributeValue != null) { try { Long.parseLong(attributeValue); } catch (NumberFormatException e) { throw new ValidationException( format( "Value '%s' of attribute '%s' in machine '%s' is illegal", attributeValue, attributeName, machineName)); } } }
@VisibleForTesting ComposeRecipe doParse(String recipeContent) throws ValidationException { ComposeRecipe composeRecipe; try { composeRecipe = YAML_PARSER.readValue(recipeContent, ComposeRecipe.class); } catch (IOException e) { throw new ValidationException( "Parsing of environment configuration failed. " + e.getLocalizedMessage()); } return composeRecipe; }
private void checkDependency( String dependency, String containerName, Map<String, ComposeService> containers, String errorMessage) throws ValidationException { if (containerName.equals(dependency)) { throw new ValidationException(errorMessage + ": " + containerName); } if (!containers.containsKey(dependency)) { throw new ValidationException( format( "Dependency '%s' in service '%s' points to unknown service.", dependency, containerName)); } } }
/** * Parses volumesFrom content into depends_on field representation - removes column and further * chars */ private String getContainerFromVolumesFrom(String volumesFrom) throws ValidationException { String container = volumesFrom; if (volumesFrom != null) { String[] split = container.split(":"); if (split.length > 2) { throw new ValidationException(format("Service volumes_from '%s' is invalid", volumesFrom)); } container = split[0]; } return container; }
@Override protected DockerfileEnvironment doCreate( @Nullable InternalRecipe recipe, Map<String, InternalMachineConfig> machines, List<Warning> warnings) throws InfrastructureException, ValidationException { checkNotNull(recipe, "Null recipe is not supported by docker file environment factory"); if (!DockerfileEnvironment.TYPE.equals(recipe.getType())) { throw new ValidationException( format( "Dockerfile environment parser doesn't support recipe type '%s'", recipe.getType())); } String dockerfile = recipe.getContent(); checkArgument(dockerfile != null, "Dockerfile content should not be null."); addRamAttributes(machines); return new DockerfileEnvironment(dockerfile, recipe, machines, warnings); }
@Override protected DockerImageEnvironment doCreate( @Nullable InternalRecipe recipe, Map<String, InternalMachineConfig> machines, List<Warning> warnings) throws InfrastructureException, ValidationException { checkNotNull(recipe, "Null recipe is not supported by docker image environment factory"); if (!DockerImageEnvironment.TYPE.equals(recipe.getType())) { throw new ValidationException( format( "Docker image environment parser doesn't support recipe type '%s'", recipe.getType())); } String dockerImage = recipe.getContent(); checkArgument(dockerImage != null, "Docker image should not be null."); addRamAttributes(machines); return new DockerImageEnvironment(dockerImage, recipe, machines, warnings); }
private void validateRoutesMatchServices(OpenShiftEnvironment env) throws ValidationException { Set<String> recipeServices = env.getServices() .values() .stream() .map(s -> s.getMetadata().getName()) .collect(Collectors.toSet()); for (Route route : env.getRoutes().values()) { if (route.getSpec() == null || route.getSpec().getTo() == null || !route.getSpec().getTo().getKind().equals(SERVICE_KIND)) { continue; } String serviceName = route.getSpec().getTo().getName(); if (!recipeServices.contains(serviceName)) { throw new ValidationException( String.format( "Route '%s' refers to Service '%s'. Routes must refer to Services included in recipe", route.getMetadata().getName(), serviceName)); } } } }