Search in sources :

Example 1 with PipelineRunPrice

use of com.epam.pipeline.entity.cluster.PipelineRunPrice in project cloud-pipeline by epam.

the class InstanceOfferManager method getPipelineRunEstimatedPrice.

public PipelineRunPrice getPipelineRunEstimatedPrice(Long runId, Long regionId) {
    PipelineRun pipelineRun = pipelineRunManager.loadPipelineRun(runId);
    RunInstance runInstance = pipelineRun.getInstance();
    AwsRegion region = awsRegionManager.loadRegionOrGetDefault(regionId);
    double pricePerHourForInstance = getPricePerHourForInstance(runInstance.getNodeType(), isSpotRequest(runInstance.getSpot()), region.getAwsRegionName());
    double pricePerDisk = getPriceForDisk(runInstance.getNodeDisk(), region.getAwsRegionName());
    double pricePerHour = pricePerDisk + pricePerHourForInstance;
    PipelineRunPrice price = new PipelineRunPrice();
    price.setInstanceDisk(runInstance.getNodeDisk());
    price.setInstanceType(runInstance.getNodeType());
    price.setPricePerHour(pricePerHour);
    if (pipelineRun.getStatus().isFinal()) {
        long duration = pipelineRun.getEndDate().getTime() - pipelineRun.getStartDate().getTime();
        price.setTotalPrice(duration / ONE_HOUR * pricePerHour);
    } else {
        price.setTotalPrice(0);
    }
    return price;
}
Also used : PipelineRun(com.epam.pipeline.entity.pipeline.PipelineRun) AwsRegion(com.epam.pipeline.entity.region.AwsRegion) PipelineRunPrice(com.epam.pipeline.entity.cluster.PipelineRunPrice) RunInstance(com.epam.pipeline.entity.pipeline.RunInstance)

Aggregations

PipelineRunPrice (com.epam.pipeline.entity.cluster.PipelineRunPrice)1 PipelineRun (com.epam.pipeline.entity.pipeline.PipelineRun)1 RunInstance (com.epam.pipeline.entity.pipeline.RunInstance)1 AwsRegion (com.epam.pipeline.entity.region.AwsRegion)1