Cloud, Server and Webspace BillingItems and HostingAssets
This commit is contained in:
parent
62867a4cac
commit
afbb51c4d8
@ -17,8 +17,6 @@ import net.hostsharing.hsadminng.rbac.rbacdef.RbacView.SQL;
|
||||
import net.hostsharing.hsadminng.rbac.rbacobject.RbacObject;
|
||||
import net.hostsharing.hsadminng.stringify.Stringify;
|
||||
import net.hostsharing.hsadminng.stringify.Stringifyable;
|
||||
import org.hibernate.annotations.NotFound;
|
||||
import org.hibernate.annotations.NotFoundAction;
|
||||
import org.hibernate.annotations.Type;
|
||||
|
||||
import jakarta.persistence.CascadeType;
|
||||
|
@ -2,6 +2,7 @@ package net.hostsharing.hsadminng.hs.booking.item.validators;
|
||||
|
||||
|
||||
|
||||
import static net.hostsharing.hsadminng.hs.validation.BooleanProperty.booleanProperty;
|
||||
import static net.hostsharing.hsadminng.hs.validation.EnumerationProperty.enumerationProperty;
|
||||
import static net.hostsharing.hsadminng.hs.validation.IntegerProperty.integerProperty;
|
||||
|
||||
@ -9,6 +10,7 @@ class HsCloudServerBookingItemValidator extends HsBookingItemEntityValidator {
|
||||
|
||||
HsCloudServerBookingItemValidator() {
|
||||
super(
|
||||
booleanProperty("active").withDefault(true),
|
||||
integerProperty("CPUs").min(1).max(32).required(),
|
||||
integerProperty("RAM").unit("GB").min(1).max(128).required(),
|
||||
integerProperty("SSD").unit("GB").min(25).max(1000).step(25).required(),
|
||||
|
@ -7,11 +7,11 @@ class HsPrivateCloudBookingItemValidator extends HsBookingItemEntityValidator {
|
||||
|
||||
HsPrivateCloudBookingItemValidator() {
|
||||
super(
|
||||
integerProperty("CPUs").min(4).max(128).required().asTotalLimit(),
|
||||
integerProperty("RAM").unit("GB").min(4).max(512).required().asTotalLimit(),
|
||||
integerProperty("SSD").unit("GB").min(100).max(4000).step(25).required().asTotalLimit(),
|
||||
integerProperty("HDD").unit("GB").min(0).max(16000).step(25).withDefault(0).asTotalLimit(),
|
||||
integerProperty("Traffic").unit("GB").min(1000).max(40000).step(250).required().asTotalLimit(),
|
||||
integerProperty("CPUs").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).required().asTotalLimit(),
|
||||
integerProperty("HDD").unit("GB").min(0).max(16000).step(250).withDefault(0).asTotalLimit(),
|
||||
integerProperty("Traffic").unit("GB").min(250).max(40000).step(250).required().asTotalLimit(),
|
||||
enumerationProperty("SLA-Infrastructure").values("BASIC", "EXT8H", "EXT4H", "EXT2H").withDefault("BASIC")
|
||||
);
|
||||
}
|
||||
|
@ -142,7 +142,6 @@ public class HsHostingAssetEntity implements Stringifyable, RbacObject {
|
||||
dependsOnColumn("bookingItemUuid"),
|
||||
directlyFetchedByDependsOnColumn(),
|
||||
NULLABLE)
|
||||
.toRole("bookingItem", AGENT).grantPermission(INSERT)
|
||||
|
||||
.importEntityAlias("parentAsset", HsHostingAssetEntity.class, usingDefaultCase(),
|
||||
dependsOnColumn("parentAssetUuid"),
|
||||
|
@ -1,18 +1,48 @@
|
||||
package net.hostsharing.hsadminng.hs.hosting.asset.validators;
|
||||
|
||||
import static net.hostsharing.hsadminng.hs.validation.BooleanProperty.booleanProperty;
|
||||
import static net.hostsharing.hsadminng.hs.validation.EnumerationProperty.enumerationProperty;
|
||||
import static net.hostsharing.hsadminng.hs.validation.IntegerProperty.integerProperty;
|
||||
|
||||
class HsManagedServerHostingAssetValidator extends HsHostingAssetEntityValidator {
|
||||
|
||||
public HsManagedServerHostingAssetValidator() {
|
||||
super(
|
||||
integerProperty("monit_min_free_ssd").min(1).max(1000).optional(),
|
||||
integerProperty("monit_min_free_hdd").min(1).max(4000).optional(),
|
||||
integerProperty("monit_max_ssd_usage").unit("%").min(10).max(100).required(),
|
||||
integerProperty("monit_max_hdd_usage").unit("%").min(10).max(100).optional(),
|
||||
integerProperty("monit_max_cpu_usage").unit("%").min(10).max(100).required(),
|
||||
integerProperty("monit_max_ram_usage").unit("%").min(10).max(100).required()
|
||||
// TODO: stringProperty("monit_alarm_email").unit("GB").optional()
|
||||
// monitoring
|
||||
integerProperty("monit_max_cpu_usage").unit("%").min(10).max(100).withDefault(92),
|
||||
integerProperty("monit_max_ram_usage").unit("%").min(10).max(100).withDefault(92),
|
||||
integerProperty("monit_max_ssd_usage").unit("%").min(10).max(100).withDefault(98),
|
||||
integerProperty("monit_min_free_ssd").min(1).max(1000).withDefault(5),
|
||||
integerProperty("monit_max_hdd_usage").unit("%").min(10).max(100).withDefault(95),
|
||||
integerProperty("monit_min_free_hdd").min(1).max(4000).withDefault(10),
|
||||
// stringProperty("monit_alarm_email").unit("GB").optional() TODO.spec: via Contact?
|
||||
|
||||
// other settings
|
||||
integerProperty("fastcgi_small").min(0).max(16).withDefault(4), // TODO.spec: check limits
|
||||
|
||||
// database software
|
||||
booleanProperty("software-pgsql").withDefault(true),
|
||||
booleanProperty("software-mariadb").withDefault(true),
|
||||
|
||||
// PHP
|
||||
enumerationProperty("php-default").valuesFromProperties("software-php-").withDefault("8.2"),
|
||||
booleanProperty("software-php-5.6").withDefault(false),
|
||||
booleanProperty("software-php-7.0").withDefault(false),
|
||||
booleanProperty("software-php-7.1").withDefault(false),
|
||||
booleanProperty("software-php-7.2").withDefault(false),
|
||||
booleanProperty("software-php-7.3").withDefault(false),
|
||||
booleanProperty("software-php-7.4").withDefault(true),
|
||||
booleanProperty("software-php-8.0").withDefault(false),
|
||||
booleanProperty("software-php-8.1").withDefault(true),
|
||||
booleanProperty("software-php-8.2").withDefault(false),
|
||||
|
||||
// other software
|
||||
// TODO.spec: booleanProperty("software-postfix-tls-1.0").withDefault(false),
|
||||
// TODO.spec: booleanProperty("software-dovecot-tls-1.0").withDefault(false),
|
||||
booleanProperty("software-clamav").withDefault(true),
|
||||
booleanProperty("software-collabora").withDefault(false),
|
||||
booleanProperty("software-libreoffice").withDefault(false),
|
||||
booleanProperty("software-imagick-ghostscript").withDefault(true) // TODO.spec: default
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,8 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
|
||||
import static java.util.Arrays.stream;
|
||||
|
||||
@Setter
|
||||
public class EnumerationProperty extends ValidatableProperty<String> {
|
||||
|
||||
@ -30,9 +32,27 @@ public class EnumerationProperty extends ValidatableProperty<String> {
|
||||
return this;
|
||||
}
|
||||
|
||||
public void deferredInit(final ValidatableProperty<?>[] allProperties) {
|
||||
if (deferredInit != null) {
|
||||
if (this.values != null) {
|
||||
throw new IllegalStateException("property " + toString() + " already values");
|
||||
}
|
||||
this.values = deferredInit.apply(allProperties);
|
||||
}
|
||||
}
|
||||
|
||||
public ValidatableProperty<String> valuesFromProperties(final String propertyNamePrefix) {
|
||||
this.deferredInit = (ValidatableProperty<?>[] allProperties) -> stream(allProperties)
|
||||
.map(ValidatableProperty::propertyName)
|
||||
.filter(name -> name.startsWith(propertyNamePrefix))
|
||||
.map(name -> name.substring(propertyNamePrefix.length()))
|
||||
.toArray(String[]::new);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void validate(final ArrayList<String> result, final String propValue, final Map<String, Object> props) {
|
||||
if (Arrays.stream(values).noneMatch(v -> v.equals(propValue))) {
|
||||
if (stream(values).noneMatch(v -> v.equals(propValue))) {
|
||||
result.add(propertyName + "' is expected to be one of " + Arrays.toString(values) + " but is '" + propValue + "'");
|
||||
}
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ public abstract class HsEntityValidator<E> {
|
||||
|
||||
public HsEntityValidator(final ValidatableProperty<?>... validators) {
|
||||
propertyValidators = validators;
|
||||
stream(propertyValidators).forEach(p -> p.deferredInit(propertyValidators));
|
||||
}
|
||||
|
||||
protected static List<String> enrich(final String prefix, final List<String> messages) {
|
||||
|
@ -31,6 +31,7 @@ public abstract class ValidatableProperty<T> {
|
||||
private final String[] keyOrder;
|
||||
private Boolean required;
|
||||
private T defaultValue;
|
||||
protected Function<ValidatableProperty<?>[], T[]> deferredInit;
|
||||
private boolean isTotalsValidator = false;
|
||||
@JsonIgnore
|
||||
private List<Function<HsBookingItemEntity, List<String>>> asTotalLimitValidators; // TODO.impl: move to BookingItemIntegerProperty
|
||||
@ -57,6 +58,9 @@ public abstract class ValidatableProperty<T> {
|
||||
return this;
|
||||
}
|
||||
|
||||
public void deferredInit(final ValidatableProperty<?>[] allProperties) {
|
||||
}
|
||||
|
||||
public ValidatableProperty<T> asTotalLimit() {
|
||||
isTotalsValidator = true;
|
||||
return this;
|
||||
|
@ -55,6 +55,7 @@ class HsCloudServerBookingItemValidatorUnitTest {
|
||||
|
||||
// then
|
||||
assertThat(validator.properties()).map(Map::toString).containsExactlyInAnyOrder(
|
||||
"{type=boolean, propertyName=active, required=false, defaultValue=true, isTotalsValidator=false}",
|
||||
"{type=integer, propertyName=CPUs, min=1, max=32, required=true, isTotalsValidator=false}",
|
||||
"{type=integer, propertyName=RAM, unit=GB, min=1, max=128, required=true, isTotalsValidator=false}",
|
||||
"{type=integer, propertyName=SSD, unit=GB, min=25, max=1000, step=25, required=true, isTotalsValidator=false}",
|
||||
|
@ -280,9 +280,8 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup
|
||||
"statusPhrase": "Bad Request",
|
||||
"message": "[
|
||||
<<<'MANAGED_SERVER:vm1400.config.extra' is not expected but is set to '42',
|
||||
<<<'MANAGED_SERVER:vm1400.config.monit_max_ssd_usage' is expected to be >= 10 but is 0,
|
||||
<<<'MANAGED_SERVER:vm1400.config.monit_max_cpu_usage' is expected to be <= 100 but is 101,
|
||||
<<<'MANAGED_SERVER:vm1400.config.monit_max_ram_usage' is required but missing
|
||||
<<<'MANAGED_SERVER:vm1400.config.monit_max_ssd_usage' is expected to be >= 10 but is 0
|
||||
<<<]"
|
||||
}
|
||||
""".replaceAll(" +<<<", ""))); // @formatter:on
|
||||
|
@ -55,18 +55,22 @@ class HsHostingAssetPropsControllerAcceptanceTest {
|
||||
[
|
||||
{
|
||||
"type": "integer",
|
||||
"propertyName": "monit_min_free_ssd",
|
||||
"min": 1,
|
||||
"max": 1000,
|
||||
"propertyName": "monit_max_cpu_usage",
|
||||
"unit": "%",
|
||||
"min": 10,
|
||||
"max": 100,
|
||||
"required": false,
|
||||
"defaultValue": 92,
|
||||
"isTotalsValidator": false
|
||||
},
|
||||
{
|
||||
"type": "integer",
|
||||
"propertyName": "monit_min_free_hdd",
|
||||
"min": 1,
|
||||
"max": 4000,
|
||||
"propertyName": "monit_max_ram_usage",
|
||||
"unit": "%",
|
||||
"min": 10,
|
||||
"max": 100,
|
||||
"required": false,
|
||||
"defaultValue": 92,
|
||||
"isTotalsValidator": false
|
||||
},
|
||||
{
|
||||
@ -75,7 +79,17 @@ class HsHostingAssetPropsControllerAcceptanceTest {
|
||||
"unit": "%",
|
||||
"min": 10,
|
||||
"max": 100,
|
||||
"required": true,
|
||||
"required": false,
|
||||
"defaultValue": 98,
|
||||
"isTotalsValidator": false
|
||||
},
|
||||
{
|
||||
"type": "integer",
|
||||
"propertyName": "monit_min_free_ssd",
|
||||
"min": 1,
|
||||
"max": 1000,
|
||||
"required": false,
|
||||
"defaultValue": 5,
|
||||
"isTotalsValidator": false
|
||||
},
|
||||
{
|
||||
@ -85,29 +99,152 @@ class HsHostingAssetPropsControllerAcceptanceTest {
|
||||
"min": 10,
|
||||
"max": 100,
|
||||
"required": false,
|
||||
"defaultValue": 95,
|
||||
"isTotalsValidator": false
|
||||
},
|
||||
{
|
||||
"type": "integer",
|
||||
"propertyName": "monit_max_cpu_usage",
|
||||
"unit": "%",
|
||||
"min": 10,
|
||||
"max": 100,
|
||||
"required": true,
|
||||
"propertyName": "monit_min_free_hdd",
|
||||
"min": 1,
|
||||
"max": 4000,
|
||||
"required": false,
|
||||
"defaultValue": 10,
|
||||
"isTotalsValidator": false
|
||||
},
|
||||
{
|
||||
"type": "integer",
|
||||
"propertyName": "monit_max_ram_usage",
|
||||
"unit": "%",
|
||||
"min": 10,
|
||||
"max": 100,
|
||||
"required": true,
|
||||
"propertyName": "fastcgi_small",
|
||||
"min": 0,
|
||||
"max": 16,
|
||||
"required": false,
|
||||
"defaultValue": 4,
|
||||
"isTotalsValidator": false
|
||||
},
|
||||
{
|
||||
"type": "boolean",
|
||||
"propertyName": "software-pgsql",
|
||||
"required": false,
|
||||
"defaultValue": true,
|
||||
"isTotalsValidator": false
|
||||
},
|
||||
{
|
||||
"type": "boolean",
|
||||
"propertyName": "software-mariadb",
|
||||
"required": false,
|
||||
"defaultValue": true,
|
||||
"isTotalsValidator": false
|
||||
},
|
||||
{
|
||||
"type": "enumeration",
|
||||
"propertyName": "php-default",
|
||||
"values": [
|
||||
"5.6",
|
||||
"7.0",
|
||||
"7.1",
|
||||
"7.2",
|
||||
"7.3",
|
||||
"7.4",
|
||||
"8.0",
|
||||
"8.1",
|
||||
"8.2"
|
||||
],
|
||||
"required": false,
|
||||
"defaultValue": "8.2",
|
||||
"isTotalsValidator": false
|
||||
},
|
||||
{
|
||||
"type": "boolean",
|
||||
"propertyName": "software-php-5.6",
|
||||
"required": false,
|
||||
"defaultValue": false,
|
||||
"isTotalsValidator": false
|
||||
},
|
||||
{
|
||||
"type": "boolean",
|
||||
"propertyName": "software-php-7.0",
|
||||
"required": false,
|
||||
"defaultValue": false,
|
||||
"isTotalsValidator": false
|
||||
},
|
||||
{
|
||||
"type": "boolean",
|
||||
"propertyName": "software-php-7.1",
|
||||
"required": false,
|
||||
"defaultValue": false,
|
||||
"isTotalsValidator": false
|
||||
},
|
||||
{
|
||||
"type": "boolean",
|
||||
"propertyName": "software-php-7.2",
|
||||
"required": false,
|
||||
"defaultValue": false,
|
||||
"isTotalsValidator": false
|
||||
},
|
||||
{
|
||||
"type": "boolean",
|
||||
"propertyName": "software-php-7.3",
|
||||
"required": false,
|
||||
"defaultValue": false,
|
||||
"isTotalsValidator": false
|
||||
},
|
||||
{
|
||||
"type": "boolean",
|
||||
"propertyName": "software-php-7.4",
|
||||
"required": false,
|
||||
"defaultValue": true,
|
||||
"isTotalsValidator": false
|
||||
},
|
||||
{
|
||||
"type": "boolean",
|
||||
"propertyName": "software-php-8.0",
|
||||
"required": false,
|
||||
"defaultValue": false,
|
||||
"isTotalsValidator": false
|
||||
},
|
||||
{
|
||||
"type": "boolean",
|
||||
"propertyName": "software-php-8.1",
|
||||
"required": false,
|
||||
"defaultValue": true,
|
||||
"isTotalsValidator": false
|
||||
},
|
||||
{
|
||||
"type": "boolean",
|
||||
"propertyName": "software-php-8.2",
|
||||
"required": false,
|
||||
"defaultValue": false,
|
||||
"isTotalsValidator": false
|
||||
},
|
||||
{
|
||||
"type": "boolean",
|
||||
"propertyName": "software-clamav",
|
||||
"required": false,
|
||||
"defaultValue": true,
|
||||
"isTotalsValidator": false
|
||||
},
|
||||
{
|
||||
"type": "boolean",
|
||||
"propertyName": "software-collabora",
|
||||
"required": false,
|
||||
"defaultValue": false,
|
||||
"isTotalsValidator": false
|
||||
},
|
||||
{
|
||||
"type": "boolean",
|
||||
"propertyName": "software-libreoffice",
|
||||
"required": false,
|
||||
"defaultValue": false,
|
||||
"isTotalsValidator": false
|
||||
},
|
||||
{
|
||||
"type": "boolean",
|
||||
"propertyName": "software-imagick-ghostscript",
|
||||
"required": false,
|
||||
"defaultValue": true,
|
||||
"isTotalsValidator": false
|
||||
}
|
||||
]
|
||||
"""));
|
||||
// @formatter:on
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -24,8 +24,6 @@ import jakarta.servlet.http.HttpServletRequest;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import static java.util.Map.entry;
|
||||
import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.CLOUD_SERVER;
|
||||
|
@ -3,7 +3,6 @@ package net.hostsharing.hsadminng.hs.hosting.asset.validators;
|
||||
import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetEntity;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import jakarta.validation.ValidationException;
|
||||
|
||||
import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.MANAGED_SERVER;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@ -23,10 +22,6 @@ class HsHostingAssetEntityValidatorUnitTest {
|
||||
final var result = catchThrowable( ()-> HsHostingAssetEntityValidatorRegistry.validated(managedServerHostingAssetEntity));
|
||||
|
||||
// then
|
||||
assertThat(result).isInstanceOf(ValidationException.class)
|
||||
.hasMessageContaining(
|
||||
"'MANAGED_SERVER:vm1234.config.monit_max_ssd_usage' is required but missing",
|
||||
"'MANAGED_SERVER:vm1234.config.monit_max_cpu_usage' is required but missing",
|
||||
"'MANAGED_SERVER:vm1234.config.monit_max_ram_usage' is required but missing");
|
||||
assertThat(result).isNull(); // all required properties have defaults
|
||||
}
|
||||
}
|
||||
|
@ -32,7 +32,6 @@ class HsManagedServerHostingAssetValidatorUnitTest {
|
||||
assertThat(result).containsExactlyInAnyOrder(
|
||||
"'MANAGED_SERVER:vm1234.config.monit_max_cpu_usage' is expected to be >= 10 but is 2",
|
||||
"'MANAGED_SERVER:vm1234.config.monit_max_ram_usage' is expected to be <= 100 but is 101",
|
||||
"'MANAGED_SERVER:vm1234.config.monit_max_ssd_usage' is required but missing",
|
||||
"'MANAGED_SERVER:vm1234.config.monit_max_hdd_usage' is expected to be of type class java.lang.Integer, but is of type 'String'");
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user