|
|
|
@ -6,6 +6,7 @@ import net.hostsharing.hsadminng.hs.booking.item.HsBookingItemType;
|
|
|
|
|
import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetEntity;
|
|
|
|
|
import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType;
|
|
|
|
|
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;
|
|
|
|
@ -19,6 +20,7 @@ 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 static java.util.Arrays.stream;
|
|
|
|
|
import static java.util.stream.Collectors.toMap;
|
|
|
|
@ -82,9 +84,7 @@ public class ImportHostingAssets extends CsvDataImport {
|
|
|
|
|
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<>();
|
|
|
|
@ -137,11 +137,11 @@ public class ImportHostingAssets extends CsvDataImport {
|
|
|
|
|
// 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]
|
|
|
|
|
}
|
|
|
|
|
""");
|
|
|
|
|
}
|
|
|
|
@ -164,9 +164,9 @@ public class ImportHostingAssets extends CsvDataImport {
|
|
|
|
|
|
|
|
|
|
assertThat(firstOfEachType(3, CLOUD_SERVER, MANAGED_SERVER, MANAGED_WEBSPACE)).isEqualToIgnoringWhitespace("""
|
|
|
|
|
{
|
|
|
|
|
3000003=HsHostingAssetEntity(MANAGED_WEBSPACE, agu00, HA agu00, D-???????-?:BI agu00),
|
|
|
|
|
3000007=HsHostingAssetEntity(MANAGED_WEBSPACE, ahr00, HA ahr00, D-???????-?:BI ahr00),
|
|
|
|
|
3000008=HsHostingAssetEntity(MANAGED_WEBSPACE, ahr01, HA ahr01, D-???????-?:BI ahr01),
|
|
|
|
|
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),
|
|
|
|
@ -214,11 +214,11 @@ public class ImportHostingAssets extends CsvDataImport {
|
|
|
|
|
assertThat(firstOfEachType(5, CLOUD_SERVER, MANAGED_SERVER, MANAGED_WEBSPACE))
|
|
|
|
|
.isEqualToIgnoringWhitespace("""
|
|
|
|
|
{
|
|
|
|
|
3000003=HsHostingAssetEntity(MANAGED_WEBSPACE, agu00, HA agu00, D-???????-?:BI agu00),
|
|
|
|
|
3000007=HsHostingAssetEntity(MANAGED_WEBSPACE, ahr00, HA ahr00, D-???????-?:BI ahr00),
|
|
|
|
|
3000008=HsHostingAssetEntity(MANAGED_WEBSPACE, ahr01, HA ahr01, D-???????-?:BI ahr01),
|
|
|
|
|
3000009=HsHostingAssetEntity(MANAGED_WEBSPACE, aih00, HA aih00, D-???????-?:BI aih00),
|
|
|
|
|
3000012=HsHostingAssetEntity(MANAGED_WEBSPACE, al000, HA al000, D-???????-?:BI al000),
|
|
|
|
|
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),
|
|
|
|
@ -282,7 +282,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);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
@ -293,7 +294,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");
|
|
|
|
@ -305,13 +305,7 @@ 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 = 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);
|
|
|
|
|
};
|
|
|
|
|
final var biType = determineBiType(basepacket_code);
|
|
|
|
|
final var bookingItem = HsBookingItemEntity.builder()
|
|
|
|
|
.type(biType)
|
|
|
|
|
.caption("BI " + packet_name)
|
|
|
|
@ -319,13 +313,7 @@ public class ImportHostingAssets extends CsvDataImport {
|
|
|
|
|
.build();
|
|
|
|
|
bookingItems.put(PACKET_ID_OFFSET + packet_id, bookingItem);
|
|
|
|
|
|
|
|
|
|
final var haType = 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);
|
|
|
|
|
};
|
|
|
|
|
final var haType = determineHaType(basepacket_code);
|
|
|
|
|
final var asset = HsHostingAssetEntity.builder()
|
|
|
|
|
.type(haType)
|
|
|
|
|
.identifier(packet_name)
|
|
|
|
@ -333,6 +321,25 @@ public class ImportHostingAssets extends CsvDataImport {
|
|
|
|
|
.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);
|
|
|
|
|
managedWebspace.setParentAsset(hive(hive_id).serverRef.get());
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -342,14 +349,14 @@ 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?
|
|
|
|
|
|
|
|
|
|
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";
|
|
|
|
@ -369,26 +376,32 @@ public class ImportHostingAssets extends CsvDataImport {
|
|
|
|
|
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 "SLAINFR2H" -> "EXT2H";
|
|
|
|
|
case "SLAINFR4H" -> "EXT4H";
|
|
|
|
@ -414,6 +427,26 @@ public class ImportHostingAssets extends CsvDataImport {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
@ -422,6 +455,10 @@ public class ImportHostingAssets extends CsvDataImport {
|
|
|
|
|
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) {
|
|
|
|
|