use of com.netflix.ice.processor.Ec2InstanceReservationPrice in project ice by Netflix.
the class BasicReservationService method getLatestHourlyTotalPrice.
public double getLatestHourlyTotalPrice(long time, Region region, UsageType usageType, ReservationUtilization utilization) {
Ec2InstanceReservationPrice ec2Price = ec2InstanceReservationPrices.get(utilization).get(new Ec2InstanceReservationPrice.Key(region, usageType));
double tier = getEc2Tier(time);
return ec2Price.hourlyPrice.getPrice(null).getPrice(tier) + ec2Price.upfrontPrice.getPrice(null).getUpfrontAmortized(time, term, tier);
}
use of com.netflix.ice.processor.Ec2InstanceReservationPrice in project ice by Netflix.
the class BasicReservationService method setPrice.
private boolean setPrice(ReservationUtilization utilization, long currentTime, Region region, UsageType usageType, double upfront, double hourly) {
Ec2InstanceReservationPrice.Key key = new Ec2InstanceReservationPrice.Key(region, usageType);
Ec2InstanceReservationPrice reservationPrice = ec2InstanceReservationPrices.get(utilization).get(key);
if (reservationPrice == null) {
reservationPrice = new Ec2InstanceReservationPrice();
ec2InstanceReservationPrices.get(utilization).put(key, reservationPrice);
}
Ec2InstanceReservationPrice.Price latestHourly = reservationPrice.hourlyPrice.getCreatePrice(futureMillis);
Ec2InstanceReservationPrice.Price latestUpfront = reservationPrice.upfrontPrice.getCreatePrice(futureMillis);
if (latestHourly.getListPrice() == null) {
latestHourly.setListPrice(hourly);
latestUpfront.setListPrice(upfront);
//logger.info("setting reservation price for " + usageType + " in " + region + ": " + upfront + " " + hourly);
return true;
} else if (latestHourly.getListPrice() != hourly || latestUpfront.getListPrice() != upfront) {
Ec2InstanceReservationPrice.Price oldHourly = reservationPrice.hourlyPrice.getCreatePrice(currentTime);
Ec2InstanceReservationPrice.Price oldUpfront = reservationPrice.upfrontPrice.getCreatePrice(currentTime);
oldHourly.setListPrice(latestHourly.getListPrice());
oldUpfront.setListPrice(latestUpfront.getListPrice());
latestHourly.setListPrice(hourly);
latestUpfront.setListPrice(upfront);
//logger.info("changing reservation price for " + usageType + " in " + region + ": " + upfront + " " + hourly);
return true;
} else {
//logger.info("exisitng reservation price for " + usageType + " in " + region + ": " + upfront + " " + hourly);
return false;
}
}
use of com.netflix.ice.processor.Ec2InstanceReservationPrice in project ice by Netflix.
the class BasicReservationService method getReservation.
public ReservationInfo getReservation(long time, TagGroup tagGroup, ReservationUtilization utilization) {
if (utilization == ReservationUtilization.FIXED)
return getFixedReservation(time, tagGroup);
double tier = getEc2Tier(time);
double upfrontAmortized = 0;
double houlyCost = 0;
int count = 0;
if (this.reservations.get(utilization).containsKey(tagGroup)) {
for (Reservation reservation : this.reservations.get(utilization).get(tagGroup)) {
if (time >= reservation.start && time < reservation.end) {
count += reservation.count;
Ec2InstanceReservationPrice.Key key = new Ec2InstanceReservationPrice.Key(tagGroup.region, tagGroup.usageType);
Ec2InstanceReservationPrice ec2Price = ec2InstanceReservationPrices.get(utilization).get(key);
if (ec2Price != null) {
// remove this...
upfrontAmortized += reservation.count * ec2Price.upfrontPrice.getPrice(reservation.start).getUpfrontAmortized(reservation.start, term, tier);
houlyCost += reservation.count * ec2Price.hourlyPrice.getPrice(reservation.start).getPrice(tier);
} else {
logger.error("Not able to find reservation price for " + key);
}
}
}
}
if (count == 0) {
Ec2InstanceReservationPrice.Key key = new Ec2InstanceReservationPrice.Key(tagGroup.region, tagGroup.usageType);
Ec2InstanceReservationPrice ec2Price = ec2InstanceReservationPrices.get(utilization).get(key);
if (ec2Price != null) {
// remove this...
upfrontAmortized = ec2Price.upfrontPrice.getPrice(null).getUpfrontAmortized(time, term, tier);
houlyCost = ec2Price.hourlyPrice.getPrice(null).getPrice(tier);
}
} else {
upfrontAmortized = upfrontAmortized / count;
houlyCost = houlyCost / count;
}
return new ReservationInfo(count, upfrontAmortized, houlyCost);
}
Aggregations