use of com.epam.pipeline.entity.cluster.InstanceOffer in project cloud-pipeline by epam.
the class InstanceOfferManagerTest method makeInstanceOffer.
private InstanceOffer makeInstanceOffer(String type) {
InstanceOffer offer = new InstanceOffer();
offer.setInstanceType(type);
offer.setVCPU(1);
offer.setGpu(1);
offer.setPricePerUnit(1);
offer.setMemory(1);
offer.setSku("sku");
offer.setPriceListPublishDate(new Date());
offer.setRegion("eu-central-1");
return offer;
}
use of com.epam.pipeline.entity.cluster.InstanceOffer in project cloud-pipeline by epam.
the class InstanceOfferDao method insertInstanceOffers.
@Transactional(propagation = Propagation.MANDATORY)
@SuppressWarnings("unchecked")
public void insertInstanceOffers(List<InstanceOffer> offerList) {
for (int i = 0; i < offerList.size(); i += INSERT_BATCH_SIZE) {
final List<InstanceOffer> batchList = offerList.subList(i, i + INSERT_BATCH_SIZE > offerList.size() ? offerList.size() : i + INSERT_BATCH_SIZE);
Map<String, Object>[] batchValues = new Map[batchList.size()];
for (int j = 0; j < batchList.size(); j++) {
InstanceOffer offer = batchList.get(j);
batchValues[j] = InstanceOfferParameters.getParameters(offer).getValues();
}
getNamedParameterJdbcTemplate().batchUpdate(createInstanceOfferQuery, batchValues);
}
}
use of com.epam.pipeline.entity.cluster.InstanceOffer in project cloud-pipeline by epam.
the class InstanceOfferManager method getPriceForDisk.
private double getPriceForDisk(int instanceDisk, String regionId) {
InstanceOfferRequestVO requestVO = new InstanceOfferRequestVO();
requestVO.setProductFamily(STORAGE_PRODUCT_FAMILY);
requestVO.setVolumeType(GENERAL_PURPOSE_VOLUME_TYPE);
requestVO.setRegion(regionId);
List<InstanceOffer> offers = instanceOfferDao.loadInstanceOffers(requestVO);
if (offers.size() == 1) {
return offers.get(0).getPricePerUnit() / (DAYS_IN_MONTH * HOURS_IN_DAY) * instanceDisk;
}
return 0;
}
use of com.epam.pipeline.entity.cluster.InstanceOffer in project cloud-pipeline by epam.
the class AwsPriceListReader method parseRecord.
private InstanceOffer parseRecord(CSVRecord record) {
InstanceOffer offer = new InstanceOffer();
offer.setPriceListPublishDate(new Date());
offer.setSku(record.get("sku"));
offer.setTermType(record.get("termtype"));
offer.setUnit(record.get("unit"));
offer.setPricePerUnit(parseFloat(record.get("priceperunit")));
offer.setCurrency(record.get("currency"));
offer.setInstanceType(record.get("instance type"));
offer.setTenancy(record.get("tenancy"));
offer.setOperatingSystem(record.get("operating system"));
offer.setProductFamily(record.get("product family"));
offer.setVolumeType(record.get("volume type"));
offer.setVCPU(parseInteger(record.get("vcpu")));
offer.setGpu(parseInteger(record.get("gpu")));
offer.setInstanceFamily(record.get("instance family"));
offer.setRegion(awsRegion);
parseMemoryValue(offer, record.get("memory"));
return offer;
}
use of com.epam.pipeline.entity.cluster.InstanceOffer in project cloud-pipeline by epam.
the class InstanceOfferManager method updatePriceListForRegion.
@Transactional(propagation = Propagation.REQUIRED)
public List<InstanceOffer> updatePriceListForRegion(String awsRegion) {
String url = String.format(AWS_EC2_PRICING_URL_TEMPLATE, awsRegion);
try (InputStream input = new URL(url).openStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(input))) {
// skip first lines
int skipLines = COLUMNS_LINE_INDEX;
while (skipLines > 0) {
String line = reader.readLine();
if (line == null) {
LOGGER.debug("AWS Price list for region {} is empty", awsRegion);
return Collections.emptyList();
}
skipLines--;
}
instanceOfferDao.removeInstanceOffersForRegion(awsRegion);
List<InstanceOffer> instanceOffers = new AwsPriceListReader(awsRegion).readPriceCsv(reader);
instanceOfferDao.insertInstanceOffers(instanceOffers);
return instanceOffers;
} catch (IOException e) {
LOGGER.error(e.getMessage(), e);
return Collections.emptyList();
}
}
Aggregations