Skip to content

Commit

Permalink
Add support of referenced RDS volume name
Browse files Browse the repository at this point in the history
  • Loading branch information
fdaugan committed Nov 20, 2021
1 parent b651b5f commit 2718e43
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 13 deletions.
Expand Up @@ -29,10 +29,13 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import lombok.extern.slf4j.Slf4j;

/**
* The provisioning price service for RDS AWS. Manage install or update of prices.
*/
@Component
@Slf4j
public class AwsPriceImportRds extends
AbstractAwsPriceImportVm<ProvDatabaseType, ProvDatabasePrice, AwsRdsPrice, ProvQuoteDatabase, LocalRdsContext, CsvForBeanRds> {

Expand Down Expand Up @@ -96,16 +99,23 @@ protected void installPrice(final LocalRdsContext context, final AwsRdsPrice csv
} else {
// Database storage
final var type = installStorageType(context, csv);
final var price = context.getPreviousStorage().computeIfAbsent(csv.getSku(), c -> {
if (type == null) {
// Ignore this type
return;
}

log.info("Add Database storage sku={}, type={}, location={}", csv.getSku(), type.getName(),
context.getRegion().getName());
syncAdd(context.getPreviousStorage(), csv.getSku(), c -> {
final var p = new ProvStoragePrice();
p.setCode(c);
p.setType(type);
p.setLocation(context.getRegion());
return p;
});
}, p ->

// Update the price as needed
saveAsNeeded(context, price, csv.getPricePerUnit(), spRepository);
saveAsNeeded(context, p, csv.getPricePerUnit(), spRepository));
}
}

Expand All @@ -120,19 +130,28 @@ private ProvStorageType installStorageType(final LocalRdsContext context, final
if ("Aurora PostgreSQL".equals(csv.getEngine())) {
name = "rds-gp-aurora-postgresql";
engine = "Aurora PostgreSQL";
} else {
} else { /* Any */
name = "rds-gp-aurora-mysql";
engine = "Aurora MySQL";
}
} else {
} else if ("Oracle".equals(csv.getEngine()) && StringUtils.startsWith(csv.getVolume(), "General Purpose")) {
name = "rds-gp-oracle";
engine = "Oracle";
} else if ("Any".equals(csv.getEngine())) {
engine = null;
if ("General Purpose".equals(csv.getVolume())) {
name = "rds-gp";
} else if ("Provisioned IOPS".equals(csv.getVolume())) {
name = "rds-io";
} else {
} else if ("Magnetic".equals(csv.getVolume())) {
name = "rds-magnetic";
} else {
log.error("Unknwown RDS storage type {}/{}/{}", csv.getVolume(), csv.getEngine(), csv.getSku());
return null;
}
} else {
log.error("Unknwown RDS storage type {}/{}/{}", csv.getVolume(), csv.getEngine(), csv.getSku());
return null;
}

// Create as needed
Expand All @@ -145,11 +164,12 @@ private ProvStorageType installStorageType(final LocalRdsContext context, final

// Merge the updated statistics
return copyAsNeeded(context, type, t -> {
final var ssd = "SSD".equals(csv.getStorage());
final var ssd = StringUtils.contains(csv.getStorage(), "SSD");
t.setName(type.getCode());
t.setDescription(csv.getVolume());
t.setMinimal(toInteger(csv.getSizeMin()));
t.setMaximal(toInteger(csv.getSizeMax()));
final var ref = context.getStorageTypes().get(csv.getVolumeName());
t.setMinimal(ref == null ? toInteger(csv.getSizeMin()) : ref.getMinimal());
t.setMaximal(ref == null ? toInteger(csv.getSizeMax()) : ref.getMaximal());
t.setEngine(engine == null ? null : engine.toUpperCase(Locale.ENGLISH));
t.setDatabaseType("%");
t.setOptimized(ssd ? ProvStorageOptimized.IOPS : null);
Expand Down
Expand Up @@ -9,7 +9,7 @@
import lombok.Setter;

/**
* AWS EC2 price configuration
* AWS RDS price configuration
*/
@Getter
@Setter
Expand All @@ -21,5 +21,10 @@ public class AwsRdsPrice extends AbstractAwsVmPrice {
private String sizeMin;
private String sizeMax;
private String volume;

/**
* Optional volume name reference.
*/
private String volumeName;

}
Expand Up @@ -17,7 +17,7 @@
public class CsvForBeanRds extends AbstractCsvForBeanEc2<AwsRdsPrice> {

/**
* EC2 CSV Mapping to Java bean property
* RDS CSV Mapping to Java bean property
*/
private static final Map<String, String> HEADERS_MAPPING = new HashMap<>();
static {
Expand All @@ -26,6 +26,7 @@ public class CsvForBeanRds extends AbstractCsvForBeanEc2<AwsRdsPrice> {
HEADERS_MAPPING.put("Min Volume Size", "sizeMin");
HEADERS_MAPPING.put("Max Volume Size", "sizeMax");
HEADERS_MAPPING.put("Volume Type", "volume");
HEADERS_MAPPING.put("Volume Name", "volumeName");
HEADERS_MAPPING.put("Storage Media", "storage");
}

Expand All @@ -45,8 +46,7 @@ public boolean isValidRaw(List<String> rawValues) {
// Only Single-AZ
// Only "Database Instance" and "Database Storage" products
// No outpost
return rawValues.size() > 37 && "Single-AZ".equals(rawValues.get(37))
&& "AWS Region".equals(rawValues.get(18))
return rawValues.size() > 37 && "Single-AZ".equals(rawValues.get(37)) && "AWS Region".equals(rawValues.get(18))
&& ("Database Instance".equals(rawValues.get(15)) || "Database Storage".equals(rawValues.get(15)));
}

Expand Down

0 comments on commit 2718e43

Please sign in to comment.