@Override protected void validateStateOnStart(PlacementHostSelectionTaskState state) { if (state.resourceCount < 1) { throw new LocalizableValidationException("'resourceCount' must be greater than 0.", "request.resource-count.zero"); } }
@Override protected void validateStateOnStart(ClusteringTaskState state) throws IllegalArgumentException { if (state.resourceCount < 1) { throw new LocalizableValidationException("'resourceCount' must be greater than 0.", "request.resource-count.zero"); } }
public static void assertNotNull(Object value, String propertyName) { if (value == null) { throw new LocalizableValidationException(String.format(PROPERTY_CANNOT_BE_NULL_MESSAGE_FORMAT, propertyName), "common.assertion.property.required", propertyName); } }
public static void assertNotEmpty(Object[] value, String propertyName) { if (value == null || value.length == 0) { throw new LocalizableValidationException(String.format(PROPERTY_CANNOT_BE_EMPTY_MESSAGE_FORMAT, propertyName), "common.assertion.property.not.empty", propertyName); } }
public static void assertNotEmpty(Collection<?> value, String propertyName) { if (value == null || value.isEmpty()) { throw new LocalizableValidationException(String.format(PROPERTY_CANNOT_BE_EMPTY_MESSAGE_FORMAT, propertyName), "common.assertion.property.not.empty", propertyName); } }
public static void assertNotEmpty(Map<?, ?> value, String propertyName) { if (value == null || value.isEmpty()) { throw new LocalizableValidationException(String.format(PROPERTY_CANNOT_BE_EMPTY_MESSAGE_FORMAT, propertyName), "common.assertion.property.not.empty", propertyName); } }
public static void assertEmpty(Collection<?> value, String propertyName) { if (value != null && !value.isEmpty()) { throw new LocalizableValidationException( String.format(PROPERTY_MUST_BE_EMPTY_MESSAGE_FORMAT, propertyName), "common.assertion.property.empty", propertyName); } }
public static void validateLocalVolumeName(String name) { if (name == null || name.trim().isEmpty()) { throw new LocalizableValidationException(ERROR_VOLUME_NAME_IS_REQUIRED, "compute.volumes.name.required"); } Matcher matcher = RX_VOLUME_NAME.matcher(name); if (!matcher.matches()) { String errMsg = String.format(ERROR_VOLUME_NAME_INVALID, name); throw new LocalizableValidationException(errMsg, "compute.volumes.name.invalid"); } }
public static void validateContainerName(String name) { if ((name != null) && !NAME_PATTERN.matcher(name).matches()) { throw new LocalizableValidationException("Invalid container name '" + name + "', only " + NAME_PATTERN.pattern() + " are allowed.", "common.validate.container.name", name, NAME_PATTERN.pattern()); } }
private void validateUri(URI uri) { if (!UriUtils.HTTPS_SCHEME.equalsIgnoreCase(uri.getScheme()) && !UriUtils.HTTP_SCHEME.equalsIgnoreCase(uri.getScheme())) { throw new LocalizableValidationException("Unsupported scheme: " + uri.getScheme(), "common.unsupported.scheme", uri.getScheme()); } }
private void validateUri(URI uri) { if (!UriUtils.HTTPS_SCHEME.equalsIgnoreCase(uri.getScheme()) && !UriUtils.HTTP_SCHEME.equalsIgnoreCase(uri.getScheme())) { throw new LocalizableValidationException("Unsupported scheme: " + uri.getScheme(), "common.unsupported.scheme", uri.getScheme()); } }
private void throwExceptionIfIpOverlap(String ipBegin, String ipEnd, IPVersion ipVersion, String ipUnderTest) { if (SubnetValidator.isIpInBetween(ipBegin, ipEnd, ipVersion, ipUnderTest )) { throw new LocalizableValidationException( String.format("The submitted IP address range overlaps with a " + "previously defined IP address range: %s-%s ", ipBegin, ipEnd), "subnet.range.ip.overlap", ipBegin, ipEnd); } }
private static String getLinkFromUrl(Operation op, boolean failIfMissing) { String resourcePoolLink = null; if (op.getUri().getPath().startsWith(SELF_LINK)) { resourcePoolLink = op.getUri().getPath().substring(SELF_LINK.length()); } if (failIfMissing && (resourcePoolLink == null || resourcePoolLink.isEmpty())) { throw new LocalizableValidationException("Resource pool link is required in the URL", "compute.elastic.placement.resource-pool.in.url"); } return resourcePoolLink; }
private void completeTask(ContainerRedeploymentTaskState state) { String redeployedContainers = StringUtils.join(state.containerStateLinks, ", "); String description = String.format("Containers [%s] redeployed", redeployedContainers); sendEventLog(state.tenantLinks, description, (op, ex) -> { if (ex != null) { op.fail(new LocalizableValidationException("Failed to publish an event log", "request.container.redeployment.event-log.create-fail")); } complete(); }); }
public static URI getShellUri(ComputeState host, ContainerState shellContainer) { PortBinding portBinding = getShellPortBinding(shellContainer); if (portBinding == null) { throw new LocalizableValidationException("Could not locate shell port", "compute.shell.port"); } String uriHost = UriUtilsExtended.extractHost(host.address); return UriUtils.buildUri(UriUtils.HTTPS_SCHEME, uriHost, Integer.parseInt(portBinding.hostPort), null, null); }
private DeferredResult<Void> handleUserGroupRoleAssignment(AuthRole role) { if (role == AuthRole.CLOUD_ADMIN) { return handleCloudAdminGroupAssignment(principalId); } return DeferredResult.failed(new LocalizableValidationException( ROLE_NOT_SUPPORTED_MESSAGE, ROLE_NOT_SUPPORTED_MESSAGE_CODE, role.name())); }
private void processSearchRequest(RequestContext context) { String apiVersion = getApiVersion(context.registryState); if (ApiVersion.V1.toString().equals(apiVersion)) { processV1SearchRequest(context); } else if (ApiVersion.V2.toString().equals(apiVersion)) { processV2SearchRequest(context); } else { String errorMsg = String.format("Unsupported registry version '%s'.", apiVersion); context.operation.fail(new LocalizableValidationException(errorMsg, "adapter.unsupported.registry.version", apiVersion)); } }
private ElasticPlacementZoneState processInput(Operation op) { if (!op.hasBody()) { throw (new LocalizableValidationException("body is required", "compute.elastic.placement.body.required")); } ElasticPlacementZoneState state = op.getBody(ElasticPlacementZoneState.class); Utils.validateState(getStateDescription(), state); return state; }
private DeferredResult<Void> handleUserRoleUnassignment(AuthRole role) { if (role == AuthRole.CLOUD_ADMIN) { return UserGroupsUpdater.create() .setService(service) .setGroupLink(CLOUD_ADMINS_USER_GROUP_LINK) .setUsersToRemove(Collections.singletonList(principalId)) .update(); } return DeferredResult.failed(new LocalizableValidationException( ROLE_NOT_SUPPORTED_MESSAGE, ROLE_NOT_SUPPORTED_MESSAGE_CODE, role.name())); }
private DeferredResult<Void> handleUserRoleAssignment(AuthRole role) { if (role != AuthRole.CLOUD_ADMIN) { return DeferredResult.failed(new LocalizableValidationException( ROLE_NOT_SUPPORTED_MESSAGE, ROLE_NOT_SUPPORTED_MESSAGE_CODE, role.name())); } return PrincipalUtil.getOrCreateUser(service, principalId) .thenCompose(user -> UserGroupsUpdater.create() .setService(service) .setGroupLink(AuthUtil.CLOUD_ADMINS_USER_GROUP_LINK) .setUsersToAdd(Collections.singletonList(principalId)) .update()); }