hosting-asset-data-migration #79

Merged
hsh-michaelhoennig merged 22 commits from hosting-asset-data-migration into master 2024-07-22 11:30:34 +02:00
9 changed files with 23 additions and 25 deletions
Showing only changes of commit ab28d2cc3b - Show all commits

View File

@ -13,8 +13,8 @@ class HsCloudServerBookingItemValidator extends HsBookingItemEntityValidator {
integerProperty("CPU") .min( 1) .max( 32) .required(),
integerProperty("RAM").unit("GB") .min( 1) .max( 8192) .required(),
integerProperty("SSD").unit("GB") .min( 0) .max( 1000) .step(25).requiresExactlyOneOf("SDD", "HDD").withDefault(0),
integerProperty("HDD").unit("GB") .min( 0) .max( 4000) .step(250).requiresExactlyOneOf("SSD", "HDD").withDefault(0),
integerProperty("SSD").unit("GB") .min( 25) .max( 1000) .step(25).requiresAtLeastOneOf("SDD", "HDD"),
integerProperty("HDD").unit("GB") .min(250) .max( 4000) .step(250).requiresAtLeastOneOf("SSD", "HDD"),
integerProperty("Traffic").unit("GB") .min(250) .max(10000) .step(250).requiresAtMaxOneOf("Bandwidth", "Traffic"),
integerProperty("Bandwidth").unit("GB") .min(250) .max(10000) .step(250).requiresAtMaxOneOf("Bandwidth", "Traffic"), // TODO.spec

View File

@ -12,8 +12,8 @@ class HsManagedServerBookingItemValidator extends HsBookingItemEntityValidator {
super(
integerProperty("CPU").min(1).max(32).required(),
integerProperty("RAM").unit("GB").min(1).max(128).required(),
integerProperty("SSD").unit("GB").min(25).max(2000).step(25).requiresExactlyOneOf("SSD", "HDD").withDefault(0).asTotalLimit().withThreshold(200),
integerProperty("HDD").unit("GB").min(0).max(10000).step(250).requiresExactlyOneOf("SSD", "HDD").withDefault(0).asTotalLimit().withThreshold(200),
integerProperty("SSD").unit("GB").min(25).max(2000).step(25).requiresAtLeastOneOf("SSD", "HDD").asTotalLimit().withThreshold(200),
integerProperty("HDD").unit("GB").min(250).max(10000).step(250).requiresAtLeastOneOf("SSD", "HDD").asTotalLimit().withThreshold(200),
integerProperty("Traffic").unit("GB").min(250).max(64000).step(250).requiresAtMaxOneOf("Bandwidth", "Traffic").asTotalLimit().withThreshold(200),
integerProperty("Bandwidth").unit("GB").min(250).max(64000).step(250).requiresAtMaxOneOf("Bandwidth", "Traffic").asTotalLimit().withThreshold(200), // TODO.spec
enumerationProperty("SLA-Platform").values("BASIC", "EXT8H", "EXT4H", "EXT2H").withDefault("BASIC"),

View File

@ -9,8 +9,8 @@ class HsPrivateCloudBookingItemValidator extends HsBookingItemEntityValidator {
// @formatter:off
integerProperty("CPU") .min( 1).max( 128).required().asTotalLimit(),
integerProperty("RAM").unit("GB") .min( 1).max( 512).required().asTotalLimit(),
integerProperty("SSD").unit("GB") .min( 25).max( 4000).step(25).requiresExactlyOneOf("SSD", "HDD").withDefault(0).asTotalLimit(),
integerProperty("HDD").unit("GB") .min( 0).max(16000).step(250).requiresExactlyOneOf("SSD", "HDD").withDefault(0).asTotalLimit(),
integerProperty("SSD").unit("GB") .min( 25).max( 4000).step(25).requiresAtLeastOneOf("SSD", "HDD").asTotalLimit(),
integerProperty("HDD").unit("GB") .min(250).max(16000).step(250).requiresAtLeastOneOf("SSD", "HDD").asTotalLimit(),
integerProperty("Traffic").unit("GB") .min(250).max(64000).step(250).requiresAtMaxOneOf("Bandwidth", "Traffic").asTotalLimit(),
integerProperty("Bandwidth").unit("GB") .min(250).max(64000).step(250).requiresAtMaxOneOf("Bandwidth", "Traffic").asTotalLimit(), // TODO.spec

View File

@ -32,7 +32,7 @@ import static org.apache.commons.lang3.ObjectUtils.isArray;
public abstract class ValidatableProperty<P extends ValidatableProperty<?, ?>, T> {
protected static final String[] KEY_ORDER_HEAD = Array.of("propertyName");
protected static final String[] KEY_ORDER_TAIL = Array.of("required", "requiresExactlyOneOf", "requiresAtMaxOneOf", "defaultValue", "readOnly", "writeOnly", "computed", "isTotalsValidator", "thresholdPercentage");
protected static final String[] KEY_ORDER_TAIL = Array.of("required", "requiresAtLeastOneOf", "requiresAtMaxOneOf", "defaultValue", "readOnly", "writeOnly", "computed", "isTotalsValidator", "thresholdPercentage");
protected static final String[] KEY_ORDER = Array.join(KEY_ORDER_HEAD, KEY_ORDER_TAIL);
final Class<T> type;
@ -42,7 +42,7 @@ public abstract class ValidatableProperty<P extends ValidatableProperty<?, ?>, T
private final String[] keyOrder;
private Boolean required;
private Set<String> requiresExactlyOneOf;
private Set<String> requiresAtLeastOneOf;
private Set<String> requiresAtMaxOneOf;
private T defaultValue;
@ -109,8 +109,8 @@ protected void setDeferredInit(final Function<ValidatableProperty<?, ?>[], T[]>
return self();
}
public P requiresExactlyOneOf(final String... propNames) {
requiresExactlyOneOf = new LinkedHashSet<>(List.of(propNames));
public P requiresAtLeastOneOf(final String... propNames) {
requiresAtLeastOneOf = new LinkedHashSet<>(List.of(propNames));
return self();
}
@ -191,7 +191,7 @@ protected void setDeferredInit(final Function<ValidatableProperty<?, ?>[], T[]>
if (required == TRUE) {
result.add(propertyName + "' is required but missing");
}
validateRequiresExactlyOneOf(result, propsProvider);
validateRequiresAtLeastOneOf(result, propsProvider);
}
if (propValue != null){
validateRequiresAtMaxOneOf(result, propsProvider);
@ -207,16 +207,14 @@ protected void setDeferredInit(final Function<ValidatableProperty<?, ?>[], T[]>
return result;
}
private void validateRequiresExactlyOneOf(final ArrayList<String> result, final PropertiesProvider propsProvider) {
if (requiresExactlyOneOf != null ) {
private void validateRequiresAtLeastOneOf(final ArrayList<String> result, final PropertiesProvider propsProvider) {
if (requiresAtLeastOneOf != null ) {
final var allPropNames = propsProvider.directProps().keySet();
final var entriesWithValue = allPropNames.stream()
.filter(name -> requiresExactlyOneOf.contains(name))
.filter(name -> requiresAtLeastOneOf.contains(name))
.count();
if (entriesWithValue == 0) {
result.add(propertyName + "' is required once in group " + requiresExactlyOneOf + " but missing");
} else if (entriesWithValue > 1) {
result.add(propertyName + "' is required once in group " + requiresExactlyOneOf + " but multiple properties are set");
result.add(propertyName + "' is required once in group " + requiresAtLeastOneOf + " but missing");
}
}
}
@ -237,8 +235,8 @@ protected void setDeferredInit(final Function<ValidatableProperty<?, ?>[], T[]>
protected abstract void validate(final List<String> result, final T propValue, final PropertiesProvider propProvider);
public void verifyConsistency(final Map.Entry<? extends Enum<?>, ?> typeDef) {
if (required == null && requiresExactlyOneOf == null && requiresAtMaxOneOf == null) {
throw new IllegalStateException(typeDef.getKey() + "[" + propertyName + "] not fully initialized, please call either .required(), .optional(), .withDefault(...), .requiresExactlyOneOf(...) or .requiresAtMaxOneOf(...)" );
if (required == null && requiresAtLeastOneOf == null && requiresAtMaxOneOf == null) {
throw new IllegalStateException(typeDef.getKey() + "[" + propertyName + "] not fully initialized, please call either .required(), .optional(), .withDefault(...), .requiresAtLeastOneOf(...) or .requiresAtMaxOneOf(...)" );
}
}

View File

@ -58,8 +58,8 @@ class HsCloudServerBookingItemValidatorUnitTest {
"{type=boolean, propertyName=active, defaultValue=true}",
"{type=integer, propertyName=CPU, min=1, max=32, required=true}",
"{type=integer, propertyName=RAM, unit=GB, min=1, max=8192, required=true}",
"{type=integer, propertyName=SSD, unit=GB, min=0, max=1000, step=25, requiresExactlyOneOf=[SDD, HDD], defaultValue=0}",
"{type=integer, propertyName=HDD, unit=GB, min=0, max=4000, step=250, requiresExactlyOneOf=[SSD, HDD], defaultValue=0}",
"{type=integer, propertyName=SSD, unit=GB, min=25, max=1000, step=25, requiresAtLeastOneOf=[SDD, HDD]}",
"{type=integer, propertyName=HDD, unit=GB, min=250, max=4000, step=250, requiresAtLeastOneOf=[SSD, HDD]}",
"{type=integer, propertyName=Traffic, unit=GB, min=250, max=10000, step=250, requiresAtMaxOneOf=[Bandwidth, Traffic]}",
"{type=integer, propertyName=Bandwidth, unit=GB, min=250, max=10000, step=250, requiresAtMaxOneOf=[Bandwidth, Traffic]}",
"{type=enumeration, propertyName=SLA-Infrastructure, values=[BASIC, EXT8H, EXT4H, EXT2H]}");

View File

@ -65,8 +65,8 @@ class HsManagedServerBookingItemValidatorUnitTest {
assertThat(validator.properties()).map(Map::toString).containsExactlyInAnyOrder(
"{type=integer, propertyName=CPU, min=1, max=32, required=true}",
"{type=integer, propertyName=RAM, unit=GB, min=1, max=128, required=true}",
"{type=integer, propertyName=SSD, unit=GB, min=25, max=2000, step=25, requiresExactlyOneOf=[SSD, HDD], defaultValue=0, isTotalsValidator=true, thresholdPercentage=200}",
"{type=integer, propertyName=HDD, unit=GB, min=0, max=10000, step=250, requiresExactlyOneOf=[SSD, HDD], defaultValue=0, isTotalsValidator=true, thresholdPercentage=200}",
"{type=integer, propertyName=SSD, unit=GB, min=25, max=2000, step=25, requiresAtLeastOneOf=[SSD, HDD], isTotalsValidator=true, thresholdPercentage=200}",
"{type=integer, propertyName=HDD, unit=GB, min=250, max=10000, step=250, requiresAtLeastOneOf=[SSD, HDD], isTotalsValidator=true, thresholdPercentage=200}",
"{type=integer, propertyName=Traffic, unit=GB, min=250, max=64000, step=250, requiresAtMaxOneOf=[Bandwidth, Traffic], isTotalsValidator=true, thresholdPercentage=200}",
"{type=integer, propertyName=Bandwidth, unit=GB, min=250, max=64000, step=250, requiresAtMaxOneOf=[Bandwidth, Traffic], isTotalsValidator=true, thresholdPercentage=200}",
"{type=enumeration, propertyName=SLA-Platform, values=[BASIC, EXT8H, EXT4H, EXT2H], defaultValue=BASIC}",

View File

@ -11,6 +11,7 @@ import static java.util.Map.ofEntries;
import static net.hostsharing.hsadminng.hs.booking.item.HsBookingItemType.CLOUD_SERVER;
import static net.hostsharing.hsadminng.hs.booking.item.HsBookingItemType.MANAGED_SERVER;
import static net.hostsharing.hsadminng.hs.booking.item.HsBookingItemType.PRIVATE_CLOUD;
import static net.hostsharing.hsadminng.hs.booking.project.TestHsBookingProject.TEST_PROJECT;
import static org.assertj.core.api.Assertions.assertThat;
class HsPrivateCloudBookingItemValidatorUnitTest {
@ -28,6 +29,7 @@ class HsPrivateCloudBookingItemValidatorUnitTest {
// given
final var privateCloudBookingItemEntity = HsBookingItemEntity.builder()
.type(PRIVATE_CLOUD)
.project(TEST_PROJECT)
.caption("myPC")
.resources(ofEntries(
entry("CPU", 4),

View File

@ -212,7 +212,6 @@ public class CsvDataImport extends ContextBasedTest {
}
void logError(final Runnable assertion) {
assertion.run();
try {
hsh-michaelhoennig marked this conversation as resolved Outdated

muss raus

muss raus
assertion.run();
} catch (final AssertionError exc) {

View File

@ -37,7 +37,6 @@ import static java.util.Optional.ofNullable;
import static net.hostsharing.hsadminng.mapper.PostgresDateRange.toPostgresDateRange;
import static org.apache.commons.lang3.StringUtils.isBlank;
import static org.apache.commons.lang3.StringUtils.isNotBlank;
import static org.assertj.core.api.Assertions.as;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assumptions.assumeThat;
import static org.assertj.core.api.Fail.fail;