Compare commits

..

5 Commits

Author SHA1 Message Date
Michael Hoennig
2c24a2f593 WIP: importing office data as base for hosting assets 2024-07-17 16:48:30 +02:00
Michael Hoennig
a28d1b9a1e add entity validation 2024-07-17 14:17:46 +02:00
Michael Hoennig
2c34b577fb set parentAsset (ManagedServer) for ManagedWebspaces BookingItems 2024-07-17 11:22:03 +02:00
Michael Hoennig
eefde7443c set parentAsset (ManagedServer) for ManagedWebspaces and add Bandwidth dummy 2024-07-17 10:56:52 +02:00
Michael Hoennig
ce26f4665f set HA+BI caption and cleanup 2024-07-17 08:31:57 +02:00
21 changed files with 365 additions and 214 deletions

View File

@ -11,11 +11,12 @@ 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()
// @formatter:on

View File

@ -10,11 +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("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,15 +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,15 +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("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

@ -119,10 +119,14 @@ public class CsvDataImport extends ContextBasedTest {
protected void persist(final Integer id, final RbacObject entity) {
try {
final var asString = entity.toString();
if ( asString.contains("'null null, null'") || asString.equals("person()")) {
return;
}
//System.out.println("persisting #" + entity.hashCode() + ": " + entity);
em.persist(entity);
// uncomment for debugging purposes
// em.flush();
em.flush();
// System.out.println("persisted #" + entity.hashCode() + " as " + entity.getUuid());
} catch (Exception exc) {
System.err.println("failed to persist #" + entity.hashCode() + ": " + entity);
@ -143,6 +147,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,9 +3,13 @@ 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.hs.office.debitor.HsOfficeDebitorEntity;
import net.hostsharing.hsadminng.rbac.test.JpaAttempt;
import org.jetbrains.annotations.NotNull;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Tag;
@ -14,19 +18,25 @@ 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;
import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.MANAGED_SERVER;
import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.MANAGED_WEBSPACE;
import static net.hostsharing.hsadminng.mapper.PostgresDateRange.toPostgresDateRange;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assumptions.assumeThat;
/*
* This 'test' includes the complete legacy 'office' data import.
@ -75,22 +85,20 @@ import static org.assertj.core.api.Assertions.assertThat;
@Import({ Context.class, JpaAttempt.class })
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
@ExtendWith(OrderedDependedTestsExtension.class)
public class ImportHostingAssets extends CsvDataImport {
public class ImportHostingAssets extends ImportOfficeData {
private static final Integer IP_NUMBER_ID_OFFSET = 1000000;
private static final Integer HIVE_ID_OFFSET = 2000000;
private static final Integer PACKET_ID_OFFSET = 3000000;
record Hive(int hive_id, String hive_name, int inet_addr_id) {}
;
record Hive(int hive_id, String hive_name, int inet_addr_id, AtomicReference<HsHostingAssetEntity> serverRef) {}
private static Map<Integer, HsBookingItemEntity> bookingItems = new WriteOnceMap<>();
private static Map<Integer, Hive> hives = new WriteOnceMap<>();
private static Map<Integer, HsHostingAssetEntity> hostingAssets = new WriteOnceMap<>();
@Test
@Order(1010)
@Order(2010)
void importIpNumbers() {
try (Reader reader = resourceReader(MIGRATION_DATA_PATH + "inet_addr.csv")) {
final var lines = readAllLines(reader);
@ -101,7 +109,7 @@ public class ImportHostingAssets extends CsvDataImport {
}
@Test
@Order(1019)
@Order(2019)
void verifyIpNumbers() {
assumeThatWeAreImportingControlledTestData();
@ -118,7 +126,7 @@ public class ImportHostingAssets extends CsvDataImport {
}
@Test
@Order(1030)
@Order(2030)
void importHives() {
try (Reader reader = resourceReader(MIGRATION_DATA_PATH + "hive.csv")) {
final var lines = readAllLines(reader);
@ -129,24 +137,24 @@ public class ImportHostingAssets extends CsvDataImport {
}
@Test
@Order(1039)
@Order(2039)
void verifyHives() {
assumeThatWeAreImportingControlledTestData();
// no contacts yet => mostly null values
assertThat(toFormattedString(first(5, hives))).isEqualToIgnoringWhitespace("""
{
2000001=Hive[hive_id=1, hive_name=h01, inet_addr_id=358],
2000002=Hive[hive_id=2, hive_name=h02, inet_addr_id=359],
2000004=Hive[hive_id=4, hive_name=h03, inet_addr_id=360],
2000007=Hive[hive_id=7, hive_name=h04, inet_addr_id=361],
2000013=Hive[hive_id=13, hive_name=h05, inet_addr_id=430]
2000001=Hive[hive_id=1, hive_name=h01, inet_addr_id=358, serverRef=null],
2000002=Hive[hive_id=2, hive_name=h02, inet_addr_id=359, serverRef=null],
2000004=Hive[hive_id=4, hive_name=h03, inet_addr_id=360, serverRef=null],
2000007=Hive[hive_id=7, hive_name=h04, inet_addr_id=361, serverRef=null],
2000013=Hive[hive_id=13, hive_name=h05, inet_addr_id=430, serverRef=null]
}
""");
}
@Test
@Order(2000)
@Order(3000)
void importPackets() {
try (Reader reader = resourceReader(MIGRATION_DATA_PATH + "packet.csv")) {
final var lines = readAllLines(reader);
@ -157,21 +165,21 @@ public class ImportHostingAssets extends CsvDataImport {
}
@Test
@Order(2009)
@Order(3009)
void verifyPackets() {
assumeThatWeAreImportingControlledTestData();
assertThat(firstOfEachType(3, CLOUD_SERVER, MANAGED_SERVER, MANAGED_WEBSPACE)).isEqualToIgnoringWhitespace("""
{
3000003=HsHostingAssetEntity(MANAGED_WEBSPACE, agu00, D-???????-?:agu00),
3000007=HsHostingAssetEntity(MANAGED_WEBSPACE, ahr00, D-???????-?:ahr00),
3000008=HsHostingAssetEntity(MANAGED_WEBSPACE, ahr01, D-???????-?:ahr01),
3000964=HsHostingAssetEntity(MANAGED_SERVER, vm1064, D-???????-?:vm1064),
3000966=HsHostingAssetEntity(MANAGED_SERVER, vm1063, D-???????-?:vm1063),
3000967=HsHostingAssetEntity(MANAGED_SERVER, vm1062, D-???????-?:vm1062),
3023611=HsHostingAssetEntity(CLOUD_SERVER, vm2097, D-???????-?:vm2097),
3023612=HsHostingAssetEntity(CLOUD_SERVER, vm2062, D-???????-?:vm2062),
3023613=HsHostingAssetEntity(CLOUD_SERVER, vm2058, D-???????-?:vm2058)
3000003=HsHostingAssetEntity(MANAGED_WEBSPACE, agu00, HA agu00, MANAGED_SERVER:vm1001, D-???????-?:BI agu00),
3000007=HsHostingAssetEntity(MANAGED_WEBSPACE, ahr00, HA ahr00, MANAGED_SERVER:vm1005, D-???????-?:BI ahr00),
3000008=HsHostingAssetEntity(MANAGED_WEBSPACE, ahr01, HA ahr01, MANAGED_SERVER:vm1003, D-???????-?:BI ahr01),
3000964=HsHostingAssetEntity(MANAGED_SERVER, vm1064, HA vm1064, D-???????-?:BI vm1064),
3000966=HsHostingAssetEntity(MANAGED_SERVER, vm1063, HA vm1063, D-???????-?:BI vm1063),
3000967=HsHostingAssetEntity(MANAGED_SERVER, vm1062, HA vm1062, D-???????-?:BI vm1062),
3023611=HsHostingAssetEntity(CLOUD_SERVER, vm2097, HA vm2097, D-???????-?:BI vm2097),
3023612=HsHostingAssetEntity(CLOUD_SERVER, vm2062, HA vm2062, D-???????-?:BI vm2062),
3023613=HsHostingAssetEntity(CLOUD_SERVER, vm2058, HA vm2058, D-???????-?:BI vm2058)
}
""");
assertThat(firstOfEachType(
@ -180,21 +188,21 @@ public class ImportHostingAssets extends CsvDataImport {
HsBookingItemType.MANAGED_SERVER,
HsBookingItemType.MANAGED_WEBSPACE)).isEqualToIgnoringWhitespace("""
{
3000003=HsBookingItemEntity(MANAGED_WEBSPACE, [2024-07-17,), agu00),
3000007=HsBookingItemEntity(MANAGED_WEBSPACE, [2024-07-17,), ahr00),
3000008=HsBookingItemEntity(MANAGED_WEBSPACE, [2024-07-17,), ahr01),
3000964=HsBookingItemEntity(MANAGED_SERVER, [2024-07-17,), vm1064),
3000966=HsBookingItemEntity(MANAGED_SERVER, [2024-07-17,), vm1063),
3000967=HsBookingItemEntity(MANAGED_SERVER, [2024-07-17,), vm1062),
3023611=HsBookingItemEntity(CLOUD_SERVER, [2024-07-17,), vm2097),
3023612=HsBookingItemEntity(CLOUD_SERVER, [2024-07-17,), vm2062),
3023613=HsBookingItemEntity(CLOUD_SERVER, [2024-07-17,), vm2058)
3000003=HsBookingItemEntity(MANAGED_WEBSPACE, [2003-07-07,), BI agu00),
3000007=HsBookingItemEntity(MANAGED_WEBSPACE, [2001-12-17,), BI ahr00),
3000008=HsBookingItemEntity(MANAGED_WEBSPACE, [2003-03-12,), BI ahr01),
3000964=HsBookingItemEntity(MANAGED_SERVER, [2013-04-01,), BI vm1064),
3000966=HsBookingItemEntity(MANAGED_SERVER, [2013-04-01,), BI vm1063),
3000967=HsBookingItemEntity(MANAGED_SERVER, [2013-04-01,), BI vm1062),
3023611=HsBookingItemEntity(CLOUD_SERVER, [2022-08-10,), BI vm2097),
3023612=HsBookingItemEntity(CLOUD_SERVER, [2022-08-10,), BI vm2062),
3023613=HsBookingItemEntity(CLOUD_SERVER, [2022-08-10,), BI vm2058)
}
""");
}
@Test
@Order(2010)
@Order(3010)
void importPacketComponents() {
try (Reader reader = resourceReader(MIGRATION_DATA_PATH + "packet_component.csv")) {
final var lines = readAllLines(reader);
@ -205,7 +213,7 @@ public class ImportHostingAssets extends CsvDataImport {
}
@Test
@Order(2019)
@Order(3019)
void verifyPacketComponents() {
assumeThatWeAreImportingControlledTestData();
@ -213,21 +221,21 @@ public class ImportHostingAssets extends CsvDataImport {
assertThat(firstOfEachType(5, CLOUD_SERVER, MANAGED_SERVER, MANAGED_WEBSPACE))
.isEqualToIgnoringWhitespace("""
{
3000003=HsHostingAssetEntity(MANAGED_WEBSPACE, agu00, D-???????-?:agu00),
3000007=HsHostingAssetEntity(MANAGED_WEBSPACE, ahr00, D-???????-?:ahr00),
3000008=HsHostingAssetEntity(MANAGED_WEBSPACE, ahr01, D-???????-?:ahr01),
3000009=HsHostingAssetEntity(MANAGED_WEBSPACE, aih00, D-???????-?:aih00),
3000012=HsHostingAssetEntity(MANAGED_WEBSPACE, al000, D-???????-?:al000),
3000964=HsHostingAssetEntity(MANAGED_SERVER, vm1064, D-???????-?:vm1064),
3000966=HsHostingAssetEntity(MANAGED_SERVER, vm1063, D-???????-?:vm1063),
3000967=HsHostingAssetEntity(MANAGED_SERVER, vm1062, D-???????-?:vm1062),
3000968=HsHostingAssetEntity(MANAGED_SERVER, vm1061, D-???????-?:vm1061),
3000969=HsHostingAssetEntity(MANAGED_SERVER, vm1060, D-???????-?:vm1060),
3023611=HsHostingAssetEntity(CLOUD_SERVER, vm2097, D-???????-?:vm2097),
3023612=HsHostingAssetEntity(CLOUD_SERVER, vm2062, D-???????-?:vm2062),
3023613=HsHostingAssetEntity(CLOUD_SERVER, vm2058, D-???????-?:vm2058),
3023614=HsHostingAssetEntity(CLOUD_SERVER, vm2055, D-???????-?:vm2055),
3023615=HsHostingAssetEntity(CLOUD_SERVER, vm2010, D-???????-?:vm2010)
3000003=HsHostingAssetEntity(MANAGED_WEBSPACE, agu00, HA agu00, MANAGED_SERVER:vm1001, D-???????-?:BI agu00),
3000007=HsHostingAssetEntity(MANAGED_WEBSPACE, ahr00, HA ahr00, MANAGED_SERVER:vm1005, D-???????-?:BI ahr00),
3000008=HsHostingAssetEntity(MANAGED_WEBSPACE, ahr01, HA ahr01, MANAGED_SERVER:vm1003, D-???????-?:BI ahr01),
3000009=HsHostingAssetEntity(MANAGED_WEBSPACE, aih00, HA aih00, MANAGED_SERVER:vm1001, D-???????-?:BI aih00),
3000012=HsHostingAssetEntity(MANAGED_WEBSPACE, al000, HA al000, MANAGED_SERVER:vm1001, D-???????-?:BI al000),
3000964=HsHostingAssetEntity(MANAGED_SERVER, vm1064, HA vm1064, D-???????-?:BI vm1064),
3000966=HsHostingAssetEntity(MANAGED_SERVER, vm1063, HA vm1063, D-???????-?:BI vm1063),
3000967=HsHostingAssetEntity(MANAGED_SERVER, vm1062, HA vm1062, D-???????-?:BI vm1062),
3000968=HsHostingAssetEntity(MANAGED_SERVER, vm1061, HA vm1061, D-???????-?:BI vm1061),
3000969=HsHostingAssetEntity(MANAGED_SERVER, vm1060, HA vm1060, D-???????-?:BI vm1060),
3023611=HsHostingAssetEntity(CLOUD_SERVER, vm2097, HA vm2097, D-???????-?:BI vm2097),
3023612=HsHostingAssetEntity(CLOUD_SERVER, vm2062, HA vm2062, D-???????-?:BI vm2062),
3023613=HsHostingAssetEntity(CLOUD_SERVER, vm2058, HA vm2058, D-???????-?:BI vm2058),
3023614=HsHostingAssetEntity(CLOUD_SERVER, vm2055, HA vm2055, D-???????-?:BI vm2055),
3023615=HsHostingAssetEntity(CLOUD_SERVER, vm2010, HA vm2010, D-???????-?:BI vm2010)
}
""");
assertThat(firstOfEachType(
@ -237,25 +245,57 @@ public class ImportHostingAssets extends CsvDataImport {
HsBookingItemType.MANAGED_WEBSPACE))
.isEqualToIgnoringWhitespace("""
{
3000003=HsBookingItemEntity(MANAGED_WEBSPACE, [2024-07-17,), agu00, { "Multi": 3, "SLA-Platform": "EXT24H", "SSD": 8192, "Traffic": 20}),
3000007=HsBookingItemEntity(MANAGED_WEBSPACE, [2024-07-17,), ahr00, { "Multi": 6, "SLA-Platform": "EXT24H", "SSD": 25600, "Traffic": 10}),
3000008=HsBookingItemEntity(MANAGED_WEBSPACE, [2024-07-17,), ahr01, { "Multi": 3, "SLA-Platform": "EXT24H", "SSD": 5120, "Traffic": 10}),
3000009=HsBookingItemEntity(MANAGED_WEBSPACE, [2024-07-17,), aih00, { "HDD": 20480, "Multi": 2, "SLA-Platform": "BASIC", "SSD": 3072, "Traffic": 10}),
3000012=HsBookingItemEntity(MANAGED_WEBSPACE, [2024-07-17,), al000, { "HDD": 10240, "Multi": 3, "SLA-Platform": "BASIC", "SSD": 6144, "Traffic": 40}),
3000964=HsBookingItemEntity(MANAGED_SERVER, [2024-07-17,), 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, [2024-07-17,), 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, [2024-07-17,), 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, [2024-07-17,), 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, [2024-07-17,), 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, [2024-07-17,), vm2097, { "CPU": 8, "RAM": 12288, "SLA-Infrastructure": "EXT4H", "SLA-Platform": "BASIC", "SSD": 25600, "Traffic": 250}),
3023612=HsBookingItemEntity(CLOUD_SERVER, [2024-07-17,), vm2062, { "CPU": 10, "RAM": 65536, "SLA-Infrastructure": "EXT4H", "SLA-Platform": "BASIC", "SSD": 25600, "Traffic": 250}),
3023613=HsBookingItemEntity(CLOUD_SERVER, [2024-07-17,), vm2058, { "CPU": 1, "RAM": 8192, "SLA-Infrastructure": "EXT4H", "SLA-Platform": "BASIC", "SSD": 25600, "Traffic": 250}),
3023614=HsBookingItemEntity(CLOUD_SERVER, [2024-07-17,), vm2055, { "CPU": 8, "HDD": 256000, "RAM": 16384, "SLA-Infrastructure": "EXT4H", "SLA-Platform": "BASIC", "SSD": 25600, "Traffic": 250}),
3023615=HsBookingItemEntity(CLOUD_SERVER, [2024-07-17,), 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()
@ -281,7 +321,8 @@ public class ImportHostingAssets extends CsvDataImport {
final var hive = new Hive(
hive_id,
rec.getString("hive_name"),
rec.getInteger("inet_addr_id"));
rec.getInteger("inet_addr_id"),
new AtomicReference<>());
hives.put(HIVE_ID_OFFSET + hive_id, hive);
});
}
@ -292,7 +333,6 @@ public class ImportHostingAssets extends CsvDataImport {
.map(this::trimAll)
.map(row -> new Record(columns, row))
.forEach(rec -> {
final var packet_id = rec.getInteger("packet_id");
final var basepacket_code = rec.getString("basepacket_code");
final var packet_name = rec.getString("packet_name");
@ -304,31 +344,43 @@ public class ImportHostingAssets extends CsvDataImport {
final var old_inet_addr_id = rec.getInteger("old_inet_addr_id");
final var free = rec.getBoolean("free");
final var biType = determineBiType(basepacket_code);
final var bookingItem = HsBookingItemEntity.builder()
.type(switch (rec.getString("basepacket_code")) {
case "SRV/CLD" -> HsBookingItemType.CLOUD_SERVER;
case "SRV/MGD" -> HsBookingItemType.MANAGED_SERVER;
case "PAC/WEB" -> HsBookingItemType.MANAGED_WEBSPACE;
default -> throw new IllegalArgumentException(
"unknown basepacket_code: " + rec.getString("basepacket_code"));
})
.caption(packet_name)
.type(biType)
.caption("BI " + packet_name)
.validity(toPostgresDateRange(created, cancelled))
.build();
bookingItems.put(PACKET_ID_OFFSET + packet_id, bookingItem);
final var haType = determineHaType(basepacket_code);
final var asset = HsHostingAssetEntity.builder()
.type(switch (rec.getString("basepacket_code")) {
case "SRV/CLD" -> CLOUD_SERVER;
case "SRV/MGD" -> MANAGED_SERVER;
case "PAC/WEB" -> MANAGED_WEBSPACE;
default -> throw new IllegalArgumentException(
"unknown basepacket_code: " + rec.getString("basepacket_code"));
})
.identifier(rec.getString("packet_name"))
.type(haType)
.identifier(packet_name)
.bookingItem(bookingItem)
// .caption(rec.getString("description"))
.caption("HA " + packet_name)
.build();
hostingAssets.put(PACKET_ID_OFFSET + packet_id, asset);
if (haType == MANAGED_SERVER) {
hive(hive_id).serverRef.set(asset);
}
});
// once we know all hosting assets, we can set the parentAsset for managed webspaces
records.stream()
.map(this::trimAll)
.map(row -> new Record(columns, row))
.forEach(rec -> {
final var packet_id = rec.getInteger("packet_id");
final var basepacket_code = rec.getString("basepacket_code");
final var hive_id = rec.getInteger("hive_id");
final var haType = determineHaType(basepacket_code);
if (haType == MANAGED_WEBSPACE) {
final var managedWebspace = pac(packet_id);
final var parentAsset = hive(hive_id).serverRef.get();
managedWebspace.setParentAsset(parentAsset);
managedWebspace.getBookingItem().setParentItem(parentAsset.getBookingItem());
}
});
}
@ -338,57 +390,73 @@ public class ImportHostingAssets extends CsvDataImport {
.map(this::trimAll)
.map(row -> new Record(columns, row))
.forEach(rec -> {
final var packet_component_id = rec.getInteger("packet_component_id");
// final var packet_component_id = rec.getInteger("packet_component_id"); not needed
final var packet_id = rec.getInteger("packet_id");
final var quantity = rec.getInteger("quantity");
final var basecomponent_code = rec.getString("basecomponent_code");
final var created = rec.getLocalDate("created");
final var cancelled = rec.getLocalDate("cancelled");
// 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 = hostingAssets.get(PACKET_ID_OFFSET + packet_id);
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";
case "SLAWEB2H" -> "SLA-Web";
case "SLAWEB4H" -> "SLA-Web";
case "SLAWEB8H" -> "SLA-Web";
case "SLAMAIL2H" -> "SLA-EMail";
case "SLAMAIL4H" -> "SLA-EMail";
case "SLAMAIL8H" -> "SLA-EMail";
case "SLAMARIA2H" -> "SLA-Maria";
case "SLAMARIA4H" -> "SLA-Maria";
case "SLAMARIA8H" -> "SLA-Maria";
case "SLAPGSQL2H" -> "SLA-PgSQL";
case "SLAPGSQL4H" -> "SLA-PgSQL";
case "SLAPGSQL8H" -> "SLA-PgSQL";
case "SLAOFFIC2H" -> "SLA-Office";
case "SLAOFFIC4H" -> "SLA-Office";
case "SLAOFFIC8H" -> "SLA-Office";
case "BANDWIDTH" -> null; // TODO.spec: not implemented yet
case "BANDWIDTH" -> "Bandwidth";
default -> throw new IllegalArgumentException("unknown basecomponent_code: " + basecomponent_code);
};
if (name == null) {
} else if (name.equals("SLA-Infrastructure")) {
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);
@ -397,19 +465,57 @@ 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;
case "SRV/MGD" -> HsBookingItemType.MANAGED_SERVER;
case "PAC/WEB" -> HsBookingItemType.MANAGED_WEBSPACE;
default -> throw new IllegalArgumentException(
"unknown basepacket_code: " + basepacket_code);
};
}
private static @NotNull HsHostingAssetType determineHaType(final String basepacket_code) {
return switch (basepacket_code) {
case "SRV/CLD" -> CLOUD_SERVER;
case "SRV/MGD" -> MANAGED_SERVER;
case "PAC/WEB" -> MANAGED_WEBSPACE;
default -> throw new IllegalArgumentException(
"unknown basepacket_code: " + basepacket_code);
};
}
private static HsHostingAssetEntity ipNumber(final Integer inet_addr_id) {
return inet_addr_id != null ? hostingAssets.get(IP_NUMBER_ID_OFFSET + inet_addr_id) : null;
}
private static Hive hive(final Integer hive_id) {
return hive_id != null ? hives.get(HIVE_ID_OFFSET + hive_id) : null;
}
private static HsHostingAssetEntity pac(final Integer packet_id) {
return packet_id != null ? hostingAssets.get(PACKET_ID_OFFSET + packet_id) : null;
}
private String firstOfEachType(
final int maxCount,
final HsHostingAssetType... types) {
@ -442,6 +548,11 @@ public class ImportHostingAssets extends CsvDataImport {
.collect(toMap(Map.Entry::getKey, Map.Entry::getValue));
}
@Override
protected void assumeThatWeAreExplicitlyImportingOfficeData() {
assumeThat(false).isTrue();
}
protected static boolean isImportingControlledTestData() {
return MIGRATION_DATA_PATH.equals("migration");
}
@ -449,5 +560,4 @@ public class ImportHostingAssets extends CsvDataImport {
protected static void assumeThatWeAreImportingControlledTestData() {
// assumeThat(isImportingControlledTestData()).isTrue(); FIXME
}
}

View File

@ -111,6 +111,7 @@ public class ImportOfficeData extends CsvDataImport {
private static final List<Integer> IGNORE_BUSINESS_PARTNERS = Arrays.asList(
512167, // 11139, partner without contractual contact
512170, // 11142, partner without contractual contact
511725, // 10764, partner without contractual contact
-1
);
@ -313,6 +314,8 @@ public class ImportOfficeData extends CsvDataImport {
@Test
@Order(1040)
void importCoopShares() {
assumeThatWeAreExplicitlyImportingOfficeData();
try (Reader reader = resourceReader(MIGRATION_DATA_PATH + "share-transactions.csv")) {
final var lines = readAllLines(reader);
importCoopShares(justHeader(lines), withoutHeader(lines));
@ -324,6 +327,7 @@ public class ImportOfficeData extends CsvDataImport {
@Test
@Order(1041)
void verifyCoopShares() {
assumeThatWeAreExplicitlyImportingOfficeData();
assumeThatWeAreImportingControlledTestData();
assertThat(toFormattedString(coopShares)).isEqualToIgnoringWhitespace("""
@ -339,6 +343,7 @@ public class ImportOfficeData extends CsvDataImport {
@Test
@Order(1050)
void importCoopAssets() {
assumeThatWeAreExplicitlyImportingOfficeData();
try (Reader reader = resourceReader(MIGRATION_DATA_PATH + "asset-transactions.csv")) {
final var lines = readAllLines(reader);
@ -351,6 +356,7 @@ public class ImportOfficeData extends CsvDataImport {
@Test
@Order(1059)
void verifyCoopAssets() {
assumeThatWeAreExplicitlyImportingOfficeData();
assumeThatWeAreImportingControlledTestData();
assertThat(toFormattedString(coopAssets)).isEqualToIgnoringWhitespace("""
@ -372,7 +378,9 @@ public class ImportOfficeData extends CsvDataImport {
@Test
@Order(1099)
void verifyMemberships() {
assumeThatWeAreExplicitlyImportingOfficeData();
assumeThatWeAreImportingControlledTestData();
assertThat(toFormattedString(memberships)).isEqualToIgnoringWhitespace("""
{
17=Membership(M-1001700, P-10017, [2000-12-06,), ACTIVE),
@ -386,6 +394,8 @@ public class ImportOfficeData extends CsvDataImport {
@Test
@Order(2000)
void verifyAllPartnersHavePersons() {
assumeThatWeAreExplicitlyImportingOfficeData();
partners.forEach((id, p) -> {
final var partnerRel = p.getPartnerRel();
assertThat(partnerRel).describedAs("partner " + id + " without partnerRel").isNotNull();
@ -480,6 +490,23 @@ public class ImportOfficeData extends CsvDataImport {
assertThat(idsToRemove.size()).isEqualTo(1); // only from partner #99
}
@Test
@Order(3005)
void removeEmptyPersons() {
// avoid a error when persisting the deliberately invalid partner entry #99
final var idsToRemove = new HashSet<Integer>();
persons.forEach( (id, p) -> {
if ( p.getPersonType() == null ||
(p.getFamilyName() == null && p.getGivenName() == null && p.getTradeName() == null) ) {
idsToRemove.add(id);
}
});
idsToRemove.forEach(id -> persons.remove(id));
assumeThatWeAreImportingControlledTestData();
assertThat(idsToRemove.size()).isEqualTo(0);
}
@Test
@Order(9000)
@Commit
@ -487,7 +514,7 @@ public class ImportOfficeData extends CsvDataImport {
System.out.println("PERSISTING to database '" + jdbcUrl + "' as user '" + postgresAdminUser + "'");
deleteTestDataFromHsOfficeTables();
resetFromHsOfficeSequences();
resetHsOfficeSequences();
deleteFromTestTables();
deleteFromRbacTables();
@ -500,6 +527,8 @@ public class ImportOfficeData extends CsvDataImport {
jpaAttempt.transacted(() -> {
context(rbacSuperuser);
persons.forEach(this::persist);
relations.forEach( (id, rel) -> this.persist(id, rel.getAnchor()) );
relations.forEach( (id, rel) -> this.persist(id, rel.getHolder()) );
}).assertSuccessful();
jpaAttempt.transacted(() -> {
@ -560,6 +589,10 @@ public class ImportOfficeData extends CsvDataImport {
}
protected void assumeThatWeAreExplicitlyImportingOfficeData() {
assumeThat(true).isFalse();
}
private static boolean isImportingControlledTestData() {
return partners.size() <= MAX_NUMBER_OF_TEST_DATA_PARTNERS;
}
@ -568,62 +601,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,