Fix parsing of AWS price list for bare metal instances
/*
- * Copyright 2017-2019 EPAM Systems, Inc. (https://www.epam.com/)
+ * Copyright 2017-2020 EPAM Systems, Inc. (https://www.epam.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,6 +18,7 @@ package com.epam.pipeline.manager.cloud.aws;
import com.epam.pipeline.entity.cluster.InstanceOffer;
import com.epam.pipeline.entity.region.CloudProvider;
+import com.epam.pipeline.manager.cloud.CloudInstancePriceService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.csv.CSVFormat;
@@ -30,7 +31,9 @@ import java.io.BufferedReader;
import java.io.IOException;
import java.util.Collections;
import java.util.Date;
+import java.util.HashSet;
import java.util.List;
+import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
@@ -38,6 +41,12 @@ import java.util.stream.StreamSupport;
@RequiredArgsConstructor
public class AWSPriceListReader {
+ private static final Set<String> COMPUTE_FAMILY = new HashSet<>();
+ static {
+ COMPUTE_FAMILY.add(CloudInstancePriceService.INSTANCE_PRODUCT_FAMILY);
+ COMPUTE_FAMILY.add("Compute Instance (bare metal)");
+ }
+
private final Long regionId;
public List<InstanceOffer> readPriceCsv(BufferedReader reader) {
@@ -68,7 +77,7 @@ public class AWSPriceListReader {
offer.setInstanceType(record.get("instance type"));
offer.setTenancy(record.get("tenancy"));
offer.setOperatingSystem(record.get("operating system"));
- offer.setProductFamily(record.get("product family"));
+ offer.setProductFamily(parseProductFamily(record.get("product family")));
offer.setVolumeType(record.get("volume type"));
offer.setVCPU(parseInteger(record.get("vcpu")));
offer.setGpu(parseInteger(record.get("gpu")));
@@ -78,6 +87,13 @@ public class AWSPriceListReader {
return offer;
}
+ private String parseProductFamily(final String productFamily) {
+ if (COMPUTE_FAMILY.contains(productFamily)) {
+ return CloudInstancePriceService.INSTANCE_PRODUCT_FAMILY;
+ }
+ return productFamily;
+ }
+
private void parseMemoryValue(InstanceOffer offer, String memoryValue) {
if (StringUtils.isBlank(memoryValue)) {
return;
