Search in sources :

Example 1 with InstanceOffer

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;
}
Also used : InstanceOffer(com.epam.pipeline.entity.cluster.InstanceOffer) Date(java.util.Date)

Example 2 with InstanceOffer

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);
    }
}
Also used : InstanceOffer(com.epam.pipeline.entity.cluster.InstanceOffer) Map(java.util.Map) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with InstanceOffer

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;
}
Also used : InstanceOffer(com.epam.pipeline.entity.cluster.InstanceOffer) InstanceOfferRequestVO(com.epam.pipeline.controller.vo.InstanceOfferRequestVO)

Example 4 with InstanceOffer

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;
}
Also used : InstanceOffer(com.epam.pipeline.entity.cluster.InstanceOffer) Date(java.util.Date)

Example 5 with InstanceOffer

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();
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) InstanceOffer(com.epam.pipeline.entity.cluster.InstanceOffer) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) URL(java.net.URL) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

InstanceOffer (com.epam.pipeline.entity.cluster.InstanceOffer)5 Date (java.util.Date)2 Transactional (org.springframework.transaction.annotation.Transactional)2 InstanceOfferRequestVO (com.epam.pipeline.controller.vo.InstanceOfferRequestVO)1 BufferedReader (java.io.BufferedReader)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 URL (java.net.URL)1 Map (java.util.Map)1