add entity validation

This commit is contained in:
Michael Hoennig 2024-07-17 14:17:46 +02:00
parent 2c34b577fb
commit a28d1b9a1e
21 changed files with 192 additions and 138 deletions

View File

@ -11,11 +11,11 @@ class HsCloudServerBookingItemValidator extends HsBookingItemEntityValidator {
// @formatter:off
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( 0) .max( 1000) .step(25).required(), // (1)
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).optional(), // (1) // FIXME: required()vvv
integerProperty("HDD").unit("GB") .min( 0) .max( 4000) .step(250).withDefault(0),
integerProperty("Traffic").unit("GB") .min(250) .max(10000) .step(250).required(),
integerProperty("Traffic").unit("GB") .min(250) .max(10000) .step(250).optional(), // FIXME: required()
integerProperty("Bandwidth").unit("GB") .min(250) .max(10000) .step(250).optional(), // TODO.spec
enumerationProperty("SLA-Infrastructure").values("BASIC", "EXT8H", "EXT4H", "EXT2H").optional()

View File

@ -10,12 +10,12 @@ class HsManagedServerBookingItemValidator extends HsBookingItemEntityValidator {
HsManagedServerBookingItemValidator() {
super(
integerProperty("CPUs").min(1).max(32).required(),
integerProperty("CPU").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().asTotalLimit().withThreshold(200),
integerProperty("HDD").unit("GB").min(0).max(4000).step(250).withDefault(0).asTotalLimit().withThreshold(200),
integerProperty("Traffic").unit("GB").min(250).max(10000).step(250).required().asTotalLimit().withThreshold(200),
integerProperty("Bandwidth").unit("GB").min(250).max(10000).step(250).optional().asTotalLimit().withThreshold(200), // TODO.spec
integerProperty("SSD").unit("GB").min(25).max(2000).step(25).optional().asTotalLimit().withThreshold(200), // FIXME: required()
integerProperty("HDD").unit("GB").min(0).max(10000).step(250).withDefault(0).asTotalLimit().withThreshold(200),
integerProperty("Traffic").unit("GB").min(250).max(64000).step(250).required().asTotalLimit().withThreshold(200),
integerProperty("Bandwidth").unit("GB").min(250).max(64000).step(250).optional().asTotalLimit().withThreshold(200), // TODO.spec
enumerationProperty("SLA-Platform").values("BASIC", "EXT8H", "EXT4H", "EXT2H").withDefault("BASIC"),
booleanProperty("SLA-EMail").falseIf("SLA-Platform", "BASIC").withDefault(false),
booleanProperty("SLA-Maria").falseIf("SLA-Platform", "BASIC").optional(),

View File

@ -23,16 +23,16 @@ class HsManagedWebspaceBookingItemValidator extends HsBookingItemEntityValidator
public HsManagedWebspaceBookingItemValidator() {
super(
integerProperty("SSD").unit("GB").min(1).max(100).step(1).required(),
integerProperty("HDD").unit("GB").min(0).max(250).step(10).optional(),
integerProperty("Traffic").unit("GB").min(10).max(1000).step(10).required(),
integerProperty("SSD").unit("GB").min(1).max(2000).step(1).required(),
integerProperty("HDD").unit("GB").min(0).max(10000).step(10).optional(),
integerProperty("Traffic").unit("GB").min(10).max(64000).step(10).required(),
integerProperty("Bandwidth").unit("GB").min(10).max(1000).step(10).optional(), // TODO.spec
integerProperty("Multi").min(1).max(100).step(1).withDefault(1)
.eachComprising( 25, unixUsers())
.eachComprising( 5, databaseUsers())
.eachComprising( 5, databases())
.eachComprising(250, eMailAddresses()),
integerProperty("Daemons").min(0).max(10).withDefault(0),
integerProperty("Daemons").min(0).max(16).withDefault(0),
booleanProperty("Online Office Server").optional(),
enumerationProperty("SLA-Platform").values("BASIC", "EXT24H").withDefault("BASIC")
);

View File

@ -7,16 +7,16 @@ class HsPrivateCloudBookingItemValidator extends HsBookingItemEntityValidator {
HsPrivateCloudBookingItemValidator() {
super(
// @formatter:off
integerProperty("CPUs") .min( 1).max( 128).required().asTotalLimit(),
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).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(),
integerProperty("Bandwidth").unit("GB") .min(250).max(40000).step(250).optional().asTotalLimit(), // TODO.spec
integerProperty("Traffic").unit("GB") .min(250).max(64000).step(250).required().asTotalLimit(),
integerProperty("Bandwidth").unit("GB") .min(250).max(64000).step(250).optional().asTotalLimit(), // TODO.spec
// Alternatively we could specify it similarly to "Multi" option but exclusively counting:
// integerProperty("Resource-Points") .min(4).max(100).required()
// .each("CPUs").countsAs(64)
// .each("CPU").countsAs(64)
// .each("RAM").countsAs(64)
// .each("SSD").countsAs(18)
// .each("HDD").countsAs(2)

View File

@ -33,11 +33,11 @@ begin
managedServerUuid := uuid_generate_v4();
insert
into hs_booking_item (uuid, projectuuid, type, parentitemuuid, caption, validity, resources)
values (privateCloudUuid, relatedProject.uuid, 'PRIVATE_CLOUD', null, 'some PrivateCloud', daterange('20240401', null, '[]'), '{ "CPUs": 10, "RAM": 32, "SSD": 4000, "HDD": 10000, "Traffic": 2000 }'::jsonb),
(uuid_generate_v4(), null, 'MANAGED_SERVER', privateCloudUuid, 'some ManagedServer', daterange('20230115', '20240415', '[)'), '{ "CPUs": 2, "RAM": 4, "SSD": 500, "Traffic": 500 }'::jsonb),
(uuid_generate_v4(), null, 'CLOUD_SERVER', privateCloudUuid, 'test CloudServer', daterange('20230115', '20240415', '[)'), '{ "CPUs": 2, "RAM": 4, "SSD": 750, "Traffic": 500 }'::jsonb),
(uuid_generate_v4(), null, 'CLOUD_SERVER', privateCloudUuid, 'prod CloudServer', daterange('20230115', '20240415', '[)'), '{ "CPUs": 4, "RAM": 16, "SSD": 1000, "Traffic": 500 }'::jsonb),
(managedServerUuid, relatedProject.uuid, 'MANAGED_SERVER', null, 'separate ManagedServer', daterange('20221001', null, '[]'), '{ "CPUs": 2, "RAM": 8, "SSD": 500, "Traffic": 500 }'::jsonb),
values (privateCloudUuid, relatedProject.uuid, 'PRIVATE_CLOUD', null, 'some PrivateCloud', daterange('20240401', null, '[]'), '{ "CPU": 10, "RAM": 32, "SSD": 4000, "HDD": 10000, "Traffic": 2000 }'::jsonb),
(uuid_generate_v4(), null, 'MANAGED_SERVER', privateCloudUuid, 'some ManagedServer', daterange('20230115', '20240415', '[)'), '{ "CPU": 2, "RAM": 4, "SSD": 500, "Traffic": 500 }'::jsonb),
(uuid_generate_v4(), null, 'CLOUD_SERVER', privateCloudUuid, 'test CloudServer', daterange('20230115', '20240415', '[)'), '{ "CPU": 2, "RAM": 4, "SSD": 750, "Traffic": 500 }'::jsonb),
(uuid_generate_v4(), null, 'CLOUD_SERVER', privateCloudUuid, 'prod CloudServer', daterange('20230115', '20240415', '[)'), '{ "CPU": 4, "RAM": 16, "SSD": 1000, "Traffic": 500 }'::jsonb),
(managedServerUuid, relatedProject.uuid, 'MANAGED_SERVER', null, 'separate ManagedServer', daterange('20221001', null, '[]'), '{ "CPU": 2, "RAM": 8, "SSD": 500, "Traffic": 500 }'::jsonb),
(uuid_generate_v4(), null, 'MANAGED_WEBSPACE', managedServerUuid, 'some ManagedWebspace', daterange('20221001', null, '[]'), '{ "SSD": 50, "Traffic": 20, "Daemons": 2, "Multi": 4 }'::jsonb),
(uuid_generate_v4(), relatedProject.uuid, 'MANAGED_WEBSPACE', null, 'separate ManagedWebspace', daterange('20221001', null, '[]'), '{ "SSD": 100, "Traffic": 50, "Daemons": 0, "Multi": 1 }'::jsonb);
end; $$;

View File

@ -101,7 +101,7 @@ class HsBookingItemControllerAcceptanceTest extends ContextBasedTestWithCleanup
"resources": {
"RAM": 8,
"SSD": 500,
"CPUs": 2,
"CPU": 2,
"Traffic": 500
}
},
@ -114,7 +114,7 @@ class HsBookingItemControllerAcceptanceTest extends ContextBasedTestWithCleanup
"HDD": 10000,
"RAM": 32,
"SSD": 4000,
"CPUs": 10,
"CPU": 10,
"Traffic": 2000
}
}
@ -148,7 +148,7 @@ class HsBookingItemControllerAcceptanceTest extends ContextBasedTestWithCleanup
"type": "MANAGED_SERVER",
"caption": "some new booking",
"validTo": "{validTo}",
"resources": { "CPUs": 12, "RAM": 4, "SSD": 100, "Traffic": 250 }
"resources": { "CPU": 12, "RAM": 4, "SSD": 100, "Traffic": 250 }
}
"""
.replace("{projectUuid}", givenProject.getUuid().toString())
@ -166,7 +166,7 @@ class HsBookingItemControllerAcceptanceTest extends ContextBasedTestWithCleanup
"caption": "some new booking",
"validFrom": "{today}",
"validTo": "{todayPlus1Month}",
"resources": { "CPUs": 12, "SSD": 100, "Traffic": 250 }
"resources": { "CPU": 12, "SSD": 100, "Traffic": 250 }
}
"""
.replace("{today}", LocalDate.now().toString())
@ -267,7 +267,7 @@ class HsBookingItemControllerAcceptanceTest extends ContextBasedTestWithCleanup
"resources": {
"RAM": 8,
"SSD": 500,
"CPUs": 2,
"CPU": 2,
"Traffic": 500
}
}

View File

@ -92,7 +92,7 @@ class HsBookingItemControllerRestTest {
"caption": "some new booking",
"validTo": "{validTo}",
"garbage": "should not be accepted",
"resources": { "CPUs": 12, "RAM": 4, "SSD": 100, "Traffic": 250 }
"resources": { "CPU": 12, "RAM": 4, "SSD": 100, "Traffic": 250 }
}
"""
.replace("{projectUuid}", givenProjectUuid.toString())
@ -108,7 +108,7 @@ class HsBookingItemControllerRestTest {
"caption": "some new booking",
"validFrom": "{today}",
"validTo": "{todayPlus1Month}",
"resources": { "CPUs": 12, "SSD": 100, "Traffic": 250 }
"resources": { "CPU": 12, "SSD": 100, "Traffic": 250 }
}
"""
.replace("{today}", LocalDate.now().toString())
@ -141,7 +141,7 @@ class HsBookingItemControllerRestTest {
"type": "MANAGED_SERVER",
"caption": "some new booking",
"validFrom": "{validFrom}",
"resources": { "CPUs": 12, "RAM": 4, "SSD": 100, "Traffic": 250 }
"resources": { "CPU": 12, "RAM": 4, "SSD": 100, "Traffic": 250 }
}
"""
.replace("{projectUuid}", givenProjectUuid.toString())
@ -159,7 +159,7 @@ class HsBookingItemControllerRestTest {
"caption": "some new booking",
"validFrom": "{today}",
"validTo": null,
"resources": { "CPUs": 12, "SSD": 100, "Traffic": 250 }
"resources": { "CPU": 12, "SSD": 100, "Traffic": 250 }
}
"""
.replace("{today}", LocalDate.now().toString())

View File

@ -25,7 +25,7 @@ class HsBookingItemEntityUnitTest {
.type(HsBookingItemType.CLOUD_SERVER)
.caption("some caption")
.resources(Map.ofEntries(
entry("CPUs", 2),
entry("CPU", 2),
entry("SSD-storage", 512),
entry("HDD-storage", 2048)))
.validity(toPostgresDateRange(GIVEN_VALID_FROM, GIVEN_VALID_TO))

View File

@ -211,7 +211,7 @@ class HsBookingItemRepositoryIntegrationTest extends ContextBasedTestWithCleanup
final var result = jpaAttempt.transacted(() -> {
context("superuser-alex@hostsharing.net");
final var foundBookingItem = em.find(HsBookingItemEntity.class, givenBookingItemUuid);
foundBookingItem.getResources().put("CPUs", 2);
foundBookingItem.getResources().put("CPU", 2);
foundBookingItem.getResources().remove("SSD-storage");
foundBookingItem.getResources().put("HSD-storage", 2048);
foundBookingItem.setValidity(Range.closedOpen(
@ -336,7 +336,7 @@ class HsBookingItemRepositoryIntegrationTest extends ContextBasedTestWithCleanup
.validity(Range.closedOpen(
LocalDate.parse("2020-01-01"), LocalDate.parse("2023-01-01")))
.resources(Map.ofEntries(
entry("CPUs", 1),
entry("CPU", 1),
entry("SSD-storage", 256)))
.build();

View File

@ -17,7 +17,7 @@ public class TestHsBookingItem {
.type(HsBookingItemType.CLOUD_SERVER)
.caption("test cloud server booking item")
.resources(Map.ofEntries(
entry("CPUs", 2),
entry("CPU", 2),
entry("RAM", 4),
entry("SSD", 50),
entry("Traffic", 250)
@ -30,7 +30,7 @@ public class TestHsBookingItem {
.type(HsBookingItemType.MANAGED_SERVER)
.caption("test project booking item")
.resources(Map.ofEntries(
entry("CPUs", 2),
entry("CPU", 2),
entry("RAM", 4),
entry("SSD", 50),
entry("Traffic", 250)

View File

@ -33,7 +33,7 @@ class HsCloudServerBookingItemValidatorUnitTest {
.project(project)
.caption("Test-Server")
.resources(Map.ofEntries(
entry("CPUs", 2),
entry("CPU", 2),
entry("RAM", 25),
entry("SSD", 25),
entry("Traffic", 250),
@ -71,7 +71,7 @@ class HsCloudServerBookingItemValidatorUnitTest {
.type(CLOUD_SERVER)
.caption("Test Cloud-Server")
.resources(ofEntries(
entry("CPUs", 2),
entry("CPU", 2),
entry("RAM", 10),
entry("SSD", 50),
entry("Traffic", 2500)
@ -81,7 +81,7 @@ class HsCloudServerBookingItemValidatorUnitTest {
.type(MANAGED_SERVER)
.caption("Test Managed-Server")
.resources(ofEntries(
entry("CPUs", 3),
entry("CPU", 3),
entry("RAM", 20),
entry("SSD", 100),
entry("Traffic", 3000)
@ -92,7 +92,7 @@ class HsCloudServerBookingItemValidatorUnitTest {
.project(project)
.caption("Test Cloud")
.resources(ofEntries(
entry("CPUs", 4),
entry("CPU", 4),
entry("RAM", 20),
entry("SSD", 100),
entry("Traffic", 5000)

View File

@ -40,7 +40,7 @@ class HsManagedServerBookingItemValidatorUnitTest {
.type(MANAGED_SERVER)
.project(project)
.resources(Map.ofEntries(
entry("CPUs", 2),
entry("CPU", 2),
entry("RAM", 25),
entry("SSD", 25),
entry("Traffic", 250),
@ -82,7 +82,7 @@ class HsManagedServerBookingItemValidatorUnitTest {
final var subCloudServerBookingItemEntity = HsBookingItemEntity.builder()
.type(CLOUD_SERVER)
.resources(ofEntries(
entry("CPUs", 2),
entry("CPU", 2),
entry("RAM", 10),
entry("SSD", 50),
entry("Traffic", 2500)
@ -91,7 +91,7 @@ class HsManagedServerBookingItemValidatorUnitTest {
final HsBookingItemEntity subManagedServerBookingItemEntity = HsBookingItemEntity.builder()
.type(MANAGED_SERVER)
.resources(ofEntries(
entry("CPUs", 3),
entry("CPU", 3),
entry("RAM", 20),
entry("SSD", 100),
entry("Traffic", 3000)
@ -101,7 +101,7 @@ class HsManagedServerBookingItemValidatorUnitTest {
.type(PRIVATE_CLOUD)
.project(project)
.resources(ofEntries(
entry("CPUs", 4),
entry("CPU", 4),
entry("RAM", 20),
entry("SSD", 100),
entry("Traffic", 5000)

View File

@ -29,7 +29,7 @@ class HsManagedWebspaceBookingItemValidatorUnitTest {
.project(project)
.caption("Test Managed-Webspace")
.resources(Map.ofEntries(
entry("CPUs", 2),
entry("CPU", 2),
entry("RAM", 25),
entry("Traffic", 250),
entry("SLA-EMail", true)

View File

@ -30,7 +30,7 @@ class HsPrivateCloudBookingItemValidatorUnitTest {
.type(PRIVATE_CLOUD)
.caption("myPC")
.resources(ofEntries(
entry("CPUs", 4),
entry("CPU", 4),
entry("RAM", 20),
entry("SSD", 100),
entry("Traffic", 5000),
@ -42,7 +42,7 @@ class HsPrivateCloudBookingItemValidatorUnitTest {
.type(MANAGED_SERVER)
.caption("myMS-1")
.resources(ofEntries(
entry("CPUs", 2),
entry("CPU", 2),
entry("RAM", 10),
entry("SSD", 50),
entry("Traffic", 2500),
@ -54,7 +54,7 @@ class HsPrivateCloudBookingItemValidatorUnitTest {
.type(CLOUD_SERVER)
.caption("myMS-2")
.resources(ofEntries(
entry("CPUs", 2),
entry("CPU", 2),
entry("RAM", 10),
entry("SSD", 50),
entry("Traffic", 2500),
@ -80,7 +80,7 @@ class HsPrivateCloudBookingItemValidatorUnitTest {
.type(PRIVATE_CLOUD)
.caption("myPC")
.resources(ofEntries(
entry("CPUs", 4),
entry("CPU", 4),
entry("RAM", 20),
entry("SSD", 100),
entry("Traffic", 5000),
@ -92,7 +92,7 @@ class HsPrivateCloudBookingItemValidatorUnitTest {
.type(MANAGED_SERVER)
.caption("myMS-1")
.resources(ofEntries(
entry("CPUs", 3),
entry("CPU", 3),
entry("RAM", 20),
entry("SSD", 100),
entry("Traffic", 3000),
@ -104,7 +104,7 @@ class HsPrivateCloudBookingItemValidatorUnitTest {
.type(CLOUD_SERVER)
.caption("myMS-2")
.resources(ofEntries(
entry("CPUs", 2),
entry("CPU", 2),
entry("RAM", 10),
entry("SSD", 50),
entry("Traffic", 2500),

View File

@ -702,7 +702,7 @@ class HsHostingAssetControllerAcceptanceTest extends ContextBasedTestWithCleanup
context.define("superuser-alex@hostsharing.net");
final var project = projectRepo.findByCaption(projectCaption).getFirst();
final var resources = switch (bookingItemType) {
case MANAGED_SERVER -> Map.<String, Object>ofEntries(entry("CPUs", 1),
case MANAGED_SERVER -> Map.<String, Object>ofEntries(entry("CPU", 1),
entry("RAM", 20),
entry("SSD", 25),
entry("Traffic", 250));

View File

@ -16,7 +16,7 @@ class HsHostingAssetEntityUnitTest {
.identifier("vm1234")
.caption("some managed asset")
.config(Map.ofEntries(
entry("CPUs", 2),
entry("CPU", 2),
entry("SSD-storage", 512),
entry("HDD-storage", 2048)))
.build();
@ -27,7 +27,7 @@ class HsHostingAssetEntityUnitTest {
.identifier("xyz00")
.caption("some managed webspace")
.config(Map.ofEntries(
entry("CPUs", 2),
entry("CPU", 2),
entry("SSD-storage", 512),
entry("HDD-storage", 2048)))
.build();

View File

@ -263,7 +263,7 @@ class HsHostingAssetRepositoryIntegrationTest extends ContextBasedTestWithCleanu
final var result = jpaAttempt.transacted(() -> {
context("superuser-alex@hostsharing.net");
final var foundAsset = em.find(HsHostingAssetEntity.class, givenAssetUuid);
foundAsset.getConfig().put("CPUs", 2);
foundAsset.getConfig().put("CPU", 2);
foundAsset.getConfig().remove("SSD-storage");
foundAsset.getConfig().put("HSD-storage", 2048);
return toCleanup(assetRepo.save(foundAsset));
@ -404,7 +404,7 @@ class HsHostingAssetRepositoryIntegrationTest extends ContextBasedTestWithCleanu
.identifier(identifier)
.caption("some temp cloud asset")
.config(Map.ofEntries(
entry("CPUs", 1),
entry("CPU", 1),
entry("SSD-storage", 256)))
.build();

View File

@ -22,7 +22,7 @@ class HsManagedWebspaceHostingAssetValidatorUnitTest {
.type(HsBookingItemType.MANAGED_SERVER)
.caption("Test Managed-Server")
.resources(Map.ofEntries(
entry("CPUs", 2),
entry("CPU", 2),
entry("RAM", 25),
entry("SSD", 25),
entry("Traffic", 250),

View File

@ -143,6 +143,62 @@ public class CsvDataImport extends ContextBasedTest {
.collect(Collectors.joining(",\n")) +
"\n}\n";
}
protected void deleteTestDataFromHsOfficeTables() {
jpaAttempt.transacted(() -> {
context(rbacSuperuser);
em.createNativeQuery("delete from hs_hosting_asset where true").executeUpdate();
em.createNativeQuery("delete from hs_booking_item where true").executeUpdate();
em.createNativeQuery("delete from hs_booking_project where true").executeUpdate();
em.createNativeQuery("delete from hs_office_coopassetstransaction where true").executeUpdate();
em.createNativeQuery("delete from hs_office_coopassetstransaction_legacy_id where true").executeUpdate();
em.createNativeQuery("delete from hs_office_coopsharestransaction where true").executeUpdate();
em.createNativeQuery("delete from hs_office_coopsharestransaction_legacy_id where true").executeUpdate();
em.createNativeQuery("delete from hs_office_membership where true").executeUpdate();
em.createNativeQuery("delete from hs_office_sepamandate where true").executeUpdate();
em.createNativeQuery("delete from hs_office_sepamandate_legacy_id where true").executeUpdate();
em.createNativeQuery("delete from hs_office_debitor where true").executeUpdate();
em.createNativeQuery("delete from hs_office_bankaccount where true").executeUpdate();
em.createNativeQuery("delete from hs_office_partner where true").executeUpdate();
em.createNativeQuery("delete from hs_office_partner_details where true").executeUpdate();
em.createNativeQuery("delete from hs_office_relation where true").executeUpdate();
em.createNativeQuery("delete from hs_office_contact where true").executeUpdate();
em.createNativeQuery("delete from hs_office_person where true").executeUpdate();
}).assertSuccessful();
}
protected void resetHsOfficeSequences() {
jpaAttempt.transacted(() -> {
context(rbacSuperuser);
em.createNativeQuery("alter sequence hs_office_contact_legacy_id_seq restart with 1000000000;").executeUpdate();
em.createNativeQuery("alter sequence hs_office_coopassetstransaction_legacy_id_seq restart with 1000000000;")
.executeUpdate();
em.createNativeQuery("alter sequence public.hs_office_coopsharestransaction_legacy_id_seq restart with 1000000000;")
.executeUpdate();
em.createNativeQuery("alter sequence public.hs_office_partner_legacy_id_seq restart with 1000000000;")
.executeUpdate();
em.createNativeQuery("alter sequence public.hs_office_sepamandate_legacy_id_seq restart with 1000000000;")
.executeUpdate();
});
}
protected void deleteFromTestTables() {
jpaAttempt.transacted(() -> {
context(rbacSuperuser);
em.createNativeQuery("delete from test_domain where true").executeUpdate();
em.createNativeQuery("delete from test_package where true").executeUpdate();
em.createNativeQuery("delete from test_customer where true").executeUpdate();
}).assertSuccessful();
}
protected void deleteFromRbacTables() {
jpaAttempt.transacted(() -> {
context(rbacSuperuser);
em.createNativeQuery("delete from rbacuser_rv where name not like 'superuser-%'").executeUpdate();
em.createNativeQuery("delete from tx_journal where true").executeUpdate();
em.createNativeQuery("delete from tx_context where true").executeUpdate();
}).assertSuccessful();
}
}
class Columns {

View File

@ -3,8 +3,10 @@ package net.hostsharing.hsadminng.hs.office.migration;
import net.hostsharing.hsadminng.context.Context;
import net.hostsharing.hsadminng.hs.booking.item.HsBookingItemEntity;
import net.hostsharing.hsadminng.hs.booking.item.HsBookingItemType;
import net.hostsharing.hsadminng.hs.booking.item.validators.HsBookingItemEntityValidatorRegistry;
import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetEntity;
import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType;
import net.hostsharing.hsadminng.hs.hosting.asset.validators.HostingAssetEntitySaveProcessor;
import net.hostsharing.hsadminng.rbac.test.JpaAttempt;
import org.jetbrains.annotations.NotNull;
import org.junit.jupiter.api.MethodOrderer;
@ -15,14 +17,17 @@ import org.junit.jupiter.api.TestMethodOrder;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
import org.springframework.context.annotation.Import;
import org.springframework.test.annotation.Commit;
import org.springframework.test.annotation.DirtiesContext;
import java.io.Reader;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Function;
import static java.util.Arrays.stream;
import static java.util.Optional.ofNullable;
import static java.util.stream.Collectors.toMap;
import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.CLOUD_SERVER;
import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.IPV4_NUMBER;
@ -238,25 +243,58 @@ public class ImportHostingAssets extends CsvDataImport {
HsBookingItemType.MANAGED_WEBSPACE))
.isEqualToIgnoringWhitespace("""
{
3000003=HsBookingItemEntity(MANAGED_WEBSPACE, [2003-07-07,), BI agu00, { "Multi": 3, "SLA-Platform": "EXT24H", "SSD": 8192, "Traffic": 20}),
3000007=HsBookingItemEntity(MANAGED_WEBSPACE, [2001-12-17,), BI ahr00, { "Multi": 6, "SLA-Platform": "EXT24H", "SSD": 25600, "Traffic": 10}),
3000008=HsBookingItemEntity(MANAGED_WEBSPACE, [2003-03-12,), BI ahr01, { "Multi": 3, "SLA-Platform": "EXT24H", "SSD": 5120, "Traffic": 10}),
3000009=HsBookingItemEntity(MANAGED_WEBSPACE, [2002-07-03,), BI aih00, { "HDD": 20480, "Multi": 2, "SLA-Platform": "BASIC", "SSD": 3072, "Traffic": 10}),
3000012=HsBookingItemEntity(MANAGED_WEBSPACE, [2003-10-17,), BI al000, { "HDD": 10240, "Multi": 3, "SLA-Platform": "BASIC", "SSD": 6144, "Traffic": 40}),
3000964=HsBookingItemEntity(MANAGED_SERVER, [2013-04-01,), BI vm1064, { "CPU": 2, "RAM": 4096, "SLA-EMail": true, "SLA-Maria": true, "SLA-Office": true, "SLA-PgSQL": true, "SLA-Platform": "EXT4H", "SLA-Web": true, "SSD": 76800, "Traffic": 500}),
3000966=HsBookingItemEntity(MANAGED_SERVER, [2013-04-01,), BI vm1063, { "CPU": 2, "HDD": 256000, "RAM": 8192, "SLA-EMail": true, "SLA-Maria": true, "SLA-Office": true, "SLA-PgSQL": true, "SLA-Platform": "EXT4H", "SLA-Web": true, "SSD": 51200, "Traffic": 250}),
3000967=HsBookingItemEntity(MANAGED_SERVER, [2013-04-01,), BI vm1062, { "CPU": 2, "HDD": 256000, "RAM": 12288, "SLA-EMail": true, "SLA-Maria": true, "SLA-Office": true, "SLA-PgSQL": true, "SLA-Platform": "EXT2H", "SLA-Web": true, "SSD": 102400, "Traffic": 250}),
3000968=HsBookingItemEntity(MANAGED_SERVER, [2013-04-01,), BI vm1061, { "CPU": 6, "HDD": 256000, "RAM": 14336, "SLA-EMail": true, "SLA-Maria": true, "SLA-Office": true, "SLA-PgSQL": true, "SLA-Platform": "BASIC", "SLA-Web": true, "SSD": 384000, "Traffic": 250}),
3000969=HsBookingItemEntity(MANAGED_SERVER, [2013-04-01,), BI vm1060, { "CPU": 2, "RAM": 4096, "SLA-EMail": true, "SLA-Maria": true, "SLA-Office": true, "SLA-PgSQL": true, "SLA-Platform": "EXT2H", "SLA-Web": true, "SSD": 76800, "Traffic": 250}),
3023611=HsBookingItemEntity(CLOUD_SERVER, [2022-08-10,), BI vm2097, { "CPU": 8, "RAM": 12288, "SLA-Infrastructure": "EXT4H", "SLA-Platform": "BASIC", "SSD": 25600, "Traffic": 250}),
3023612=HsBookingItemEntity(CLOUD_SERVER, [2022-08-10,), BI vm2062, { "CPU": 10, "RAM": 65536, "SLA-Infrastructure": "EXT4H", "SLA-Platform": "BASIC", "SSD": 25600, "Traffic": 250}),
3023613=HsBookingItemEntity(CLOUD_SERVER, [2022-08-10,), BI vm2058, { "CPU": 1, "RAM": 8192, "SLA-Infrastructure": "EXT4H", "SLA-Platform": "BASIC", "SSD": 25600, "Traffic": 250}),
3023614=HsBookingItemEntity(CLOUD_SERVER, [2022-08-10,), BI vm2055, { "CPU": 8, "HDD": 256000, "RAM": 16384, "SLA-Infrastructure": "EXT4H", "SLA-Platform": "BASIC", "SSD": 25600, "Traffic": 250}),
3023615=HsBookingItemEntity(CLOUD_SERVER, [2022-08-10,), BI vm2010, { "CPU": 2, "RAM": 2048, "SLA-Infrastructure": "EXT4H", "SLA-Platform": "BASIC", "SSD": 51200, "Traffic": 250})
3000003=HsBookingItemEntity(MANAGED_WEBSPACE, [2003-07-07,), BI agu00, { "Multi": 3, "SLA-Platform": "EXT24H", "SSD": 8, "Traffic": 20}),
3000007=HsBookingItemEntity(MANAGED_WEBSPACE, [2001-12-17,), BI ahr00, { "Multi": 6, "SLA-Platform": "EXT24H", "SSD": 25, "Traffic": 10}),
3000008=HsBookingItemEntity(MANAGED_WEBSPACE, [2003-03-12,), BI ahr01, { "Multi": 3, "SLA-Platform": "EXT24H", "SSD": 5, "Traffic": 10}),
3000009=HsBookingItemEntity(MANAGED_WEBSPACE, [2002-07-03,), BI aih00, { "HDD": 20, "Multi": 2, "SLA-Platform": "EXT24H", "SSD": 3, "Traffic": 10}),
3000012=HsBookingItemEntity(MANAGED_WEBSPACE, [2003-10-17,), BI al000, { "HDD": 10, "Multi": 3, "SLA-Platform": "EXT24H", "SSD": 6, "Traffic": 40}),
3000964=HsBookingItemEntity(MANAGED_SERVER, [2013-04-01,), BI vm1064, { "CPU": 2, "RAM": 4, "SLA-EMail": true, "SLA-Maria": true, "SLA-Office": true, "SLA-PgSQL": true, "SLA-Platform": "EXT2H", "SLA-Web": true, "SSD": 75, "Traffic": 500}),
3000966=HsBookingItemEntity(MANAGED_SERVER, [2013-04-01,), BI vm1063, { "CPU": 2, "HDD": 250, "RAM": 8, "SLA-EMail": true, "SLA-Maria": true, "SLA-Office": true, "SLA-PgSQL": true, "SLA-Platform": "EXT8H", "SLA-Web": true, "SSD": 50, "Traffic": 250}),
3000967=HsBookingItemEntity(MANAGED_SERVER, [2013-04-01,), BI vm1062, { "CPU": 2, "HDD": 250, "RAM": 12, "SLA-EMail": true, "SLA-Maria": true, "SLA-Office": true, "SLA-PgSQL": true, "SLA-Platform": "EXT4H", "SLA-Web": true, "SSD": 100, "Traffic": 250}),
3000968=HsBookingItemEntity(MANAGED_SERVER, [2013-04-01,), BI vm1061, { "CPU": 6, "HDD": 250, "RAM": 14, "SLA-EMail": true, "SLA-Maria": true, "SLA-Office": true, "SLA-PgSQL": true, "SLA-Platform": "EXT4H", "SLA-Web": true, "SSD": 375, "Traffic": 250}),
3000969=HsBookingItemEntity(MANAGED_SERVER, [2013-04-01,), BI vm1060, { "CPU": 2, "RAM": 4, "SLA-EMail": true, "SLA-Maria": true, "SLA-Office": true, "SLA-PgSQL": true, "SLA-Platform": "EXT8H", "SLA-Web": true, "SSD": 75, "Traffic": 250}),
3023611=HsBookingItemEntity(CLOUD_SERVER, [2022-08-10,), BI vm2097, { "CPU": 8, "RAM": 12, "SLA-Infrastructure": "EXT4H", "SSD": 25, "Traffic": 250}),
3023612=HsBookingItemEntity(CLOUD_SERVER, [2022-08-10,), BI vm2062, { "CPU": 10, "RAM": 64, "SLA-Infrastructure": "EXT8H", "SSD": 25, "Traffic": 250}),
3023613=HsBookingItemEntity(CLOUD_SERVER, [2022-08-10,), BI vm2058, { "CPU": 1, "RAM": 8, "SLA-Infrastructure": "EXT4H", "SSD": 25, "Traffic": 250}),
3023614=HsBookingItemEntity(CLOUD_SERVER, [2022-08-10,), BI vm2055, { "CPU": 8, "HDD": 250, "RAM": 16, "SLA-Infrastructure": "EXT4H", "SSD": 25, "Traffic": 250}),
3023615=HsBookingItemEntity(CLOUD_SERVER, [2022-08-10,), BI vm2010, { "CPU": 2, "RAM": 2, "SLA-Infrastructure": "EXT4H", "SSD": 50, "Traffic": 250})
}
""");
}
@Test
@Order(9000)
@Commit
void persistEntities() {
System.out.println("PERSISTING to database '" + jdbcUrl + "' as user '" + postgresAdminUser + "'");
deleteTestDataFromHsOfficeTables();
resetHsOfficeSequences();
deleteFromTestTables();
deleteFromRbacTables();
jpaAttempt.transacted(() -> {
context(rbacSuperuser);
bookingItems.forEach(
(key, bi) -> HsBookingItemEntityValidatorRegistry.validated(bi)
);
}).assertSuccessful();
jpaAttempt.transacted(() -> {
context(rbacSuperuser);
hostingAssets.forEach((key, ha) ->
new HostingAssetEntitySaveProcessor(ha)
.preprocessEntity()
.validateEntity()
.prepareForSave()
// .saveUsing(assetRepo::save)
// .validateContext()
);
}).assertSuccessful();
}
private void importIpNumbers(final String[] header, final List<String[]> records) {
final var columns = new Columns(header);
records.stream()
@ -357,24 +395,32 @@ public class ImportHostingAssets extends CsvDataImport {
final var basecomponent_code = rec.getString("basecomponent_code");
// final var created = rec.getLocalDate("created"); TODO.spec: can we do without?
// final var cancelled = rec.getLocalDate("cancelled"); TODO.spec: can we do without?
Function<Integer, Object> convert = (v -> v);
final var asset = pac(packet_id);
final var name = switch (basecomponent_code) {
case "DAEMON" -> "Daemons";
case "MULTI" -> "Multi";
case "CPU" -> "CPU";
case "RAM" -> "RAM";
case "QUOTA" -> "SSD";
case "STORAGE" -> "HDD";
case "RAM" -> returning("RAM", convert = v -> v/1024);
case "QUOTA" -> returning("SSD", convert = v -> v/1024);
case "STORAGE" -> returning("HDD", convert = v -> v/1024);
case "TRAFFIC" -> "Traffic";
case "OFFICE" -> "Online Office Server";
case "SLABASIC" -> "SLA-Platform";
case "OFFICE" -> returning("Online Office Server", convert = v -> v == 1);
case "SLABASIC" -> switch (asset.getType()) {
case CLOUD_SERVER -> "SLA-Infrastructure";
case MANAGED_SERVER -> "SLA-Platform";
case MANAGED_WEBSPACE -> "SLA-Platform";
default -> throw new IllegalArgumentException("SLABASIC not defined for " + asset.getType());
};
case "SLAINFR2H" -> "SLA-Infrastructure";
case "SLAINFR4H" -> "SLA-Infrastructure";
case "SLAINFR8H" -> "SLA-Infrastructure";
case "SLAEXT24H" -> "SLA-Platform";
case "SLAPLAT2H" -> "SLA-Platform";
case "SLAPLAT4H" -> "SLA-Platform";
case "SLAPLAT8H" -> "SLA-Platform";
@ -405,9 +451,11 @@ public class ImportHostingAssets extends CsvDataImport {
if (name.equals("SLA-Infrastructure")) {
final var slaValue = switch (basecomponent_code) {
case "SLABASIC" -> "BASIC";
case "SLAINFR2H" -> "EXT2H";
case "SLAINFR4H" -> "EXT4H";
case "SLAINFR8H" -> "EXT4H";
case "SLAINFR8H" -> "EXT8H";
case "SLAINFR24H" -> "EXT24H";
default -> throw new IllegalArgumentException("unknown basecomponent_code: " + basecomponent_code);
};
asset.getBookingItem().getResources().put(name, slaValue);
@ -416,19 +464,25 @@ public class ImportHostingAssets extends CsvDataImport {
case "SLABASIC" -> "BASIC";
case "SLAPLAT2H" -> "EXT2H";
case "SLAPLAT4H" -> "EXT4H";
case "SLAEXT24H" -> "EXT24H";
case "SLAPLAT8H" -> "EXT8H";
case "SLAEXT24H" -> "EXT24H";
default -> throw new IllegalArgumentException("unknown basecomponent_code: " + basecomponent_code);
};
if ( ofNullable(asset.getBookingItem().getResources().get(name)).map("BASIC"::equals).orElse(true) ) {
asset.getBookingItem().getResources().put(name, slaValue);
}
} else if (name.startsWith("SLA")) {
asset.getBookingItem().getResources().put(name, true);
} else if (quantity > 0) {
asset.getBookingItem().getResources().put(name, quantity);
asset.getBookingItem().getResources().put(name, convert.apply(quantity));
}
});
}
<V> V returning(final V value, final Object... assignments) {
return value;
}
private static @NotNull HsBookingItemType determineBiType(final String basepacket_code) {
return switch (basepacket_code) {
case "SRV/CLD" -> HsBookingItemType.CLOUD_SERVER;

View File

@ -487,7 +487,7 @@ public class ImportOfficeData extends CsvDataImport {
System.out.println("PERSISTING to database '" + jdbcUrl + "' as user '" + postgresAdminUser + "'");
deleteTestDataFromHsOfficeTables();
resetFromHsOfficeSequences();
resetHsOfficeSequences();
deleteFromTestTables();
deleteFromRbacTables();
@ -568,62 +568,6 @@ public class ImportOfficeData extends CsvDataImport {
assumeThat(partners.size()).isLessThanOrEqualTo(MAX_NUMBER_OF_TEST_DATA_PARTNERS);
}
private void deleteTestDataFromHsOfficeTables() {
jpaAttempt.transacted(() -> {
context(rbacSuperuser);
em.createNativeQuery("delete from hs_hosting_asset where true").executeUpdate();
em.createNativeQuery("delete from hs_booking_item where true").executeUpdate();
em.createNativeQuery("delete from hs_booking_project where true").executeUpdate();
em.createNativeQuery("delete from hs_office_coopassetstransaction where true").executeUpdate();
em.createNativeQuery("delete from hs_office_coopassetstransaction_legacy_id where true").executeUpdate();
em.createNativeQuery("delete from hs_office_coopsharestransaction where true").executeUpdate();
em.createNativeQuery("delete from hs_office_coopsharestransaction_legacy_id where true").executeUpdate();
em.createNativeQuery("delete from hs_office_membership where true").executeUpdate();
em.createNativeQuery("delete from hs_office_sepamandate where true").executeUpdate();
em.createNativeQuery("delete from hs_office_sepamandate_legacy_id where true").executeUpdate();
em.createNativeQuery("delete from hs_office_debitor where true").executeUpdate();
em.createNativeQuery("delete from hs_office_bankaccount where true").executeUpdate();
em.createNativeQuery("delete from hs_office_partner where true").executeUpdate();
em.createNativeQuery("delete from hs_office_partner_details where true").executeUpdate();
em.createNativeQuery("delete from hs_office_relation where true").executeUpdate();
em.createNativeQuery("delete from hs_office_contact where true").executeUpdate();
em.createNativeQuery("delete from hs_office_person where true").executeUpdate();
}).assertSuccessful();
}
private void resetFromHsOfficeSequences() {
jpaAttempt.transacted(() -> {
context(rbacSuperuser);
em.createNativeQuery("alter sequence hs_office_contact_legacy_id_seq restart with 1000000000;").executeUpdate();
em.createNativeQuery("alter sequence hs_office_coopassetstransaction_legacy_id_seq restart with 1000000000;")
.executeUpdate();
em.createNativeQuery("alter sequence public.hs_office_coopsharestransaction_legacy_id_seq restart with 1000000000;")
.executeUpdate();
em.createNativeQuery("alter sequence public.hs_office_partner_legacy_id_seq restart with 1000000000;")
.executeUpdate();
em.createNativeQuery("alter sequence public.hs_office_sepamandate_legacy_id_seq restart with 1000000000;")
.executeUpdate();
});
}
private void deleteFromTestTables() {
jpaAttempt.transacted(() -> {
context(rbacSuperuser);
em.createNativeQuery("delete from test_domain where true").executeUpdate();
em.createNativeQuery("delete from test_package where true").executeUpdate();
em.createNativeQuery("delete from test_customer where true").executeUpdate();
}).assertSuccessful();
}
private void deleteFromRbacTables() {
jpaAttempt.transacted(() -> {
context(rbacSuperuser);
em.createNativeQuery("delete from rbacuser_rv where name not like 'superuser-%'").executeUpdate();
em.createNativeQuery("delete from tx_journal where true").executeUpdate();
em.createNativeQuery("delete from tx_context where true").executeUpdate();
}).assertSuccessful();
}
private <E extends RbacObject> void updateLegacyIds(
Map<Integer, E> entities,
final String legacyIdTable,