hosting-asset-data-migration #79
@ -2,6 +2,7 @@ package net.hostsharing.hsadminng.hs.office.migration;
|
|||||||
|
|
||||||
import net.hostsharing.hsadminng.context.Context;
|
import net.hostsharing.hsadminng.context.Context;
|
||||||
import net.hostsharing.hsadminng.hs.booking.item.HsBookingItemEntity;
|
import net.hostsharing.hsadminng.hs.booking.item.HsBookingItemEntity;
|
||||||
|
import net.hostsharing.hsadminng.hs.booking.item.HsBookingItemType;
|
||||||
import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetEntity;
|
import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetEntity;
|
||||||
import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType;
|
import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType;
|
||||||
import net.hostsharing.hsadminng.rbac.test.JpaAttempt;
|
import net.hostsharing.hsadminng.rbac.test.JpaAttempt;
|
||||||
@ -143,10 +144,10 @@ public class ImportHostingAssets extends CsvDataImport {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Order(2000)
|
@Order(2000)
|
||||||
void importServersAndWebspaces() {
|
void importPackets() {
|
||||||
try (Reader reader = resourceReader(MIGRATION_DATA_PATH + "packet.csv")) {
|
try (Reader reader = resourceReader(MIGRATION_DATA_PATH + "packet.csv")) {
|
||||||
final var lines = readAllLines(reader);
|
final var lines = readAllLines(reader);
|
||||||
importServersAndWebspaces(justHeader(lines), withoutHeader(lines));
|
importPackets(justHeader(lines), withoutHeader(lines));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
@ -154,17 +155,45 @@ public class ImportHostingAssets extends CsvDataImport {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Order(2009)
|
@Order(2009)
|
||||||
void verifyServersAndWebspaces() {
|
void verifyPackets() {
|
||||||
assumeThatWeAreImportingControlledTestData();
|
assumeThatWeAreImportingControlledTestData();
|
||||||
|
|
||||||
// no contacts yet => mostly null values
|
// no contacts yet => mostly null values
|
||||||
assertThat(toFormattedString(firstOfType(5, hostingAssets, CLOUD_SERVER, MANAGED_SERVER, MANAGED_WEBSPACE))).isEqualToIgnoringWhitespace("""
|
assertThat(toFormattedString(firstOfType(5, hostingAssets, CLOUD_SERVER, MANAGED_SERVER, MANAGED_WEBSPACE))).isEqualToIgnoringWhitespace("""
|
||||||
{
|
{
|
||||||
2000012=HsHostingAssetEntity(MANAGED_WEBSPACE, al000),
|
2000012=HsHostingAssetEntity(MANAGED_WEBSPACE, al000, D-???????-?:al000),
|
||||||
2000008=HsHostingAssetEntity(MANAGED_WEBSPACE, ahr01),
|
2000008=HsHostingAssetEntity(MANAGED_WEBSPACE, ahr01, D-???????-?:ahr01),
|
||||||
2000009=HsHostingAssetEntity(MANAGED_WEBSPACE, aih00),
|
2000009=HsHostingAssetEntity(MANAGED_WEBSPACE, aih00, D-???????-?:aih00),
|
||||||
2000007=HsHostingAssetEntity(MANAGED_WEBSPACE, ahr00),
|
2000007=HsHostingAssetEntity(MANAGED_WEBSPACE, ahr00, D-???????-?:ahr00),
|
||||||
2000003=HsHostingAssetEntity(MANAGED_WEBSPACE, agu00)
|
2000003=HsHostingAssetEntity(MANAGED_WEBSPACE, agu00, D-???????-?:agu00)
|
||||||
|
}
|
||||||
|
""");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Order(2010)
|
||||||
|
void importPacketComponents() {
|
||||||
|
try (Reader reader = resourceReader(MIGRATION_DATA_PATH + "packet_component.csv")) {
|
||||||
|
final var lines = readAllLines(reader);
|
||||||
|
importPacketComponents(justHeader(lines), withoutHeader(lines));
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Order(2019)
|
||||||
|
void verifyPacketComponents() {
|
||||||
|
assumeThatWeAreImportingControlledTestData();
|
||||||
|
|
||||||
|
// no contacts yet => mostly null values
|
||||||
|
assertThat(toFormattedString(firstOfType(5, hostingAssets, CLOUD_SERVER, MANAGED_SERVER, MANAGED_WEBSPACE))).isEqualToIgnoringWhitespace("""
|
||||||
|
{
|
||||||
|
2000012=HsHostingAssetEntity(MANAGED_WEBSPACE, al000, D-???????-?:al000),
|
||||||
|
2000008=HsHostingAssetEntity(MANAGED_WEBSPACE, ahr01, D-???????-?:ahr01),
|
||||||
|
2000009=HsHostingAssetEntity(MANAGED_WEBSPACE, aih00, D-???????-?:aih00),
|
||||||
|
2000007=HsHostingAssetEntity(MANAGED_WEBSPACE, ahr00, D-???????-?:ahr00),
|
||||||
|
2000003=HsHostingAssetEntity(MANAGED_WEBSPACE, agu00, D-???????-?:agu00)
|
||||||
}
|
}
|
||||||
""");
|
""");
|
||||||
}
|
}
|
||||||
@ -198,7 +227,7 @@ public class ImportHostingAssets extends CsvDataImport {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void importServersAndWebspaces(final String[] header, final List<String[]> records) {
|
private void importPackets(final String[] header, final List<String[]> records) {
|
||||||
final var columns = new Columns(header);
|
final var columns = new Columns(header);
|
||||||
records.stream()
|
records.stream()
|
||||||
.map(this::trimAll)
|
.map(this::trimAll)
|
||||||
@ -216,6 +245,16 @@ public class ImportHostingAssets extends CsvDataImport {
|
|||||||
final var old_inet_addr_id = rec.getInteger("old_inet_addr_id");
|
final var old_inet_addr_id = rec.getInteger("old_inet_addr_id");
|
||||||
final var free = rec.getBoolean("free");
|
final var free = rec.getBoolean("free");
|
||||||
|
|
||||||
|
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)
|
||||||
|
.build();
|
||||||
|
|
||||||
final var asset = HsHostingAssetEntity.builder()
|
final var asset = HsHostingAssetEntity.builder()
|
||||||
.type(switch (rec.getString("basepacket_code")) {
|
.type(switch (rec.getString("basepacket_code")) {
|
||||||
case "SRV/CLD" -> CLOUD_SERVER;
|
case "SRV/CLD" -> CLOUD_SERVER;
|
||||||
@ -224,12 +263,91 @@ public class ImportHostingAssets extends CsvDataImport {
|
|||||||
default -> throw new IllegalArgumentException("unknown basepacket_code: " + rec.getString("basepacket_code"));
|
default -> throw new IllegalArgumentException("unknown basepacket_code: " + rec.getString("basepacket_code"));
|
||||||
})
|
})
|
||||||
.identifier(rec.getString("packet_name"))
|
.identifier(rec.getString("packet_name"))
|
||||||
|
.bookingItem(bookingItem)
|
||||||
// .caption(rec.getString("description"))
|
// .caption(rec.getString("description"))
|
||||||
.build();
|
.build();
|
||||||
hostingAssets.put(PACKET_ID_OFFSET + packet_id, asset);
|
hostingAssets.put(PACKET_ID_OFFSET + packet_id, asset);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void importPacketComponents(final String[] header, final List<String[]> records) {
|
||||||
|
final var columns = new Columns(header);
|
||||||
|
records.stream()
|
||||||
|
.map(this::trimAll)
|
||||||
|
.map(row -> new Record(columns, row))
|
||||||
|
.forEach(rec -> {
|
||||||
|
final var packet_component_id = rec.getInteger("packet_component_id");
|
||||||
|
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 asset = hostingAssets.get(PACKET_ID_OFFSET + 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 "TRAFFIC" -> "Traffic";
|
||||||
|
case "OFFICE" -> "Online Office Server";
|
||||||
|
case "SLABASIC" -> "SLA-Platform";
|
||||||
|
|
||||||
|
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
|
||||||
|
default -> throw new IllegalArgumentException("unknown basecomponent_code: " + basecomponent_code);
|
||||||
|
};
|
||||||
|
if ( name == null ) {
|
||||||
|
} else if ( name.equals("SLA-Infrastructure")) {
|
||||||
|
final var slaValue = switch (basecomponent_code) {
|
||||||
|
case "SLAINFR2H" -> "EXT2H";
|
||||||
|
case "SLAINFR4H" -> "EXT4H";
|
||||||
|
case "SLAINFR8H" -> "EXT4H";
|
||||||
|
default -> throw new IllegalArgumentException("unknown basecomponent_code: " + basecomponent_code);
|
||||||
|
};
|
||||||
|
asset.getBookingItem().getResources().put(name, slaValue);
|
||||||
|
} else if ( name.equals("SLA-Platform")) {
|
||||||
|
final var slaValue = switch (basecomponent_code) {
|
||||||
|
case "SLABASIC" -> "BASIC";
|
||||||
|
case "SLAPLAT2H" -> "EXT2H";
|
||||||
|
case "SLAPLAT4H" -> "EXT4H";
|
||||||
|
case "SLAEXT24H" -> "EXT24H";
|
||||||
|
case "SLAPLAT8H" -> "EXT8H";
|
||||||
|
default -> throw new IllegalArgumentException("unknown basecomponent_code: " + basecomponent_code);
|
||||||
|
};
|
||||||
|
asset.getBookingItem().getResources().put(name, slaValue);
|
||||||
|
} else if ( name.startsWith("SLA")) {
|
||||||
|
asset.getBookingItem().getResources().put(name, true);
|
||||||
|
} else {
|
||||||
|
asset.getBookingItem().getResources().put(name, quantity);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private Map<Integer, Object> firstOfType(
|
private Map<Integer, Object> firstOfType(
|
||||||
final int maxCount,
|
final int maxCount,
|
||||||
final Map<Integer, HsHostingAssetEntity> hostingAssets,
|
final Map<Integer, HsHostingAssetEntity> hostingAssets,
|
||||||
|
Loading…
Reference in New Issue
Block a user