List of usage examples for org.joda.time DateTimeZone UTC
DateTimeZone UTC
To view the source code for org.joda.time DateTimeZone UTC.
Click Source Link
From source file:com.nesscomputing.jdbi.JdbiMappers.java
License:Apache License
/** * Returns a DateTime object representing the date in UTC or null if the input is null. *///from w w w .j a v a 2 s . c o m public static DateTime getUTCDateTime(final ResultSet rs, final String columnName) throws SQLException { final Timestamp ts = rs.getTimestamp(columnName); return (ts == null) ? null : new DateTime(ts).withZone(DateTimeZone.UTC); }
From source file:com.nesscomputing.jdbi.JdbiMappers.java
License:Apache License
public static DateTime getUTCDateTime(final ResultSet rs, final int columnIndex) throws SQLException { final Timestamp ts = rs.getTimestamp(columnIndex); return (ts == null) ? null : new DateTime(ts).withZone(DateTimeZone.UTC); }
From source file:com.nesscomputing.jersey.types.DateParam.java
License:Apache License
DateParam(DateTime dateTime) {
this.dateTime = checkNotNull(dateTime, "null datetime").withZone(DateTimeZone.UTC);
}
From source file:com.nesscomputing.jersey.types.DateParam.java
License:Apache License
public static DateParam valueOf(String string) { if (string == null) { return null; }// w ww. j a v a 2 s . co m if (NUMBER_PATTERN.matcher(string).matches()) { return new DateParam(new DateTime(Long.parseLong(string), DateTimeZone.UTC)); } else { return new DateParam(new DateTime(string, DateTimeZone.UTC)); } }
From source file:com.netflix.atlas.client.interpreter.Time.java
License:Apache License
@Override public double apply(List<Metric> updates) { long alignedTime = System.currentTimeMillis() / STEP * STEP; DateTime now = new DateTime(alignedTime, DateTimeZone.UTC); return timeFunction.apply(now); }
From source file:com.netflix.ice.basic.BasicLineItemProcessor.java
License:Apache License
public Result process(long startMilli, boolean processDelayed, ProcessorConfig config, String[] items, Map<Product, ReadWriteData> usageDataByProduct, Map<Product, ReadWriteData> costDataByProduct, Map<String, Double> ondemandRate) { if (StringUtils.isEmpty(items[accountIdIndex]) || StringUtils.isEmpty(items[productIndex]) || StringUtils.isEmpty(items[usageTypeIndex]) || StringUtils.isEmpty(items[operationIndex]) || StringUtils.isEmpty(items[usageQuantityIndex]) || StringUtils.isEmpty(items[costIndex])) return Result.ignore; Account account = config.accountService.getAccountById(items[accountIdIndex]); if (account == null) return Result.ignore; double usageValue = Double.parseDouble(items[usageQuantityIndex]); double costValue = Double.parseDouble(items[costIndex]); long millisStart; long millisEnd; try {// ww w . j a va 2 s. c om millisStart = amazonBillingDateFormat.parseMillis(items[startTimeIndex]); millisEnd = amazonBillingDateFormat.parseMillis(items[endTimeIndex]); } catch (IllegalArgumentException e) { millisStart = amazonBillingDateFormat2.parseMillis(items[startTimeIndex]); millisEnd = amazonBillingDateFormat2.parseMillis(items[endTimeIndex]); } Product product = config.productService.getProductByAwsName(items[productIndex]); boolean reservationUsage = "Y".equals(items[reservedIndex]); ReformedMetaData reformedMetaData = reform(millisStart, config, product, reservationUsage, items[operationIndex], items[usageTypeIndex], items[descriptionIndex], costValue); product = reformedMetaData.product; Operation operation = reformedMetaData.operation; UsageType usageType = reformedMetaData.usageType; Zone zone = Zone.getZone(items[zoneIndex], reformedMetaData.region); int startIndex = (int) ((millisStart - startMilli) / AwsUtils.hourMillis); int endIndex = (int) ((millisEnd + 1000 - startMilli) / AwsUtils.hourMillis); Result result = Result.hourly; if (product == Product.ec2_instance) { result = processEc2Instance(processDelayed, reservationUsage, operation, zone); } else if (product == Product.redshift) { result = processRedshift(processDelayed, reservationUsage, operation, costValue); } else if (product == Product.data_transfer) { result = processDataTranfer(processDelayed, usageType); } else if (product == Product.cloudhsm) { result = processCloudhsm(processDelayed, usageType); } else if (product == Product.ebs) { result = processEbs(usageType); } else if (product == Product.rds) { result = processRds(usageType); } if (result == Result.ignore || result == Result.delay) return result; if (usageType.name.startsWith("TimedStorage-ByteHrs")) result = Result.daily; boolean monthlyCost = StringUtils.isEmpty(items[descriptionIndex]) ? false : items[descriptionIndex].toLowerCase().contains("-month"); ReadWriteData usageData = usageDataByProduct.get(null); ReadWriteData costData = costDataByProduct.get(null); ReadWriteData usageDataOfProduct = usageDataByProduct.get(product); ReadWriteData costDataOfProduct = costDataByProduct.get(product); if (result == Result.daily) { DateMidnight dm = new DateMidnight(millisStart, DateTimeZone.UTC); millisStart = dm.getMillis(); startIndex = (int) ((millisStart - startMilli) / AwsUtils.hourMillis); endIndex = startIndex + 24; } else if (result == Result.monthly) { startIndex = 0; endIndex = usageData.getNum(); int numHoursInMonth = new DateTime(startMilli, DateTimeZone.UTC).dayOfMonth().getMaximumValue() * 24; usageValue = usageValue * endIndex / numHoursInMonth; costValue = costValue * endIndex / numHoursInMonth; } if (monthlyCost) { int numHoursInMonth = new DateTime(startMilli, DateTimeZone.UTC).dayOfMonth().getMaximumValue() * 24; usageValue = usageValue * numHoursInMonth; } int[] indexes; if (endIndex - startIndex > 1) { usageValue = usageValue / (endIndex - startIndex); costValue = costValue / (endIndex - startIndex); indexes = new int[endIndex - startIndex]; for (int i = 0; i < indexes.length; i++) indexes[i] = startIndex + i; } else { indexes = new int[] { startIndex }; } TagGroup tagGroup = TagGroup.getTagGroup(account, reformedMetaData.region, zone, product, operation, usageType, null); TagGroup resourceTagGroup = null; if (costValue > 0 && !reservationUsage && product == Product.ec2_instance && tagGroup.operation == Operation.ondemandInstances) { String key = operation + "|" + tagGroup.region + "|" + usageType; ondemandRate.put(key, costValue / usageValue); } double resourceCostValue = costValue; if (items.length > resourceIndex && !StringUtils.isEmpty(items[resourceIndex]) && config.resourceService != null) { if (product == Product.ec2_instance && !reservationUsage && operation == Operation.ondemandInstances) operation = Operation .getReservedInstances(config.reservationService.getDefaultReservationUtilization(0L)); if (product == Product.ec2_instance && operation instanceof Operation.ReservationOperation) { UsageType usageTypeForPrice = usageType; if (usageType.name.endsWith(InstanceOs.others.name())) { usageTypeForPrice = UsageType.getUsageType( usageType.name.replace(InstanceOs.others.name(), InstanceOs.windows.name()), usageType.unit); } try { resourceCostValue = usageValue * config.reservationService.getLatestHourlyTotalPrice( millisStart, tagGroup.region, usageTypeForPrice, config.reservationService.getDefaultReservationUtilization(0L)); } catch (Exception e) { logger.error("failed to get RI price for " + tagGroup.region + " " + usageTypeForPrice); resourceCostValue = -1; } } String resourceGroupStr = config.resourceService.getResource(account, reformedMetaData.region, product, items[resourceIndex], items, millisStart); if (!StringUtils.isEmpty(resourceGroupStr)) { ResourceGroup resourceGroup = ResourceGroup.getResourceGroup(resourceGroupStr); resourceTagGroup = TagGroup.getTagGroup(account, reformedMetaData.region, zone, product, operation, usageType, resourceGroup); if (usageDataOfProduct == null) { usageDataOfProduct = new ReadWriteData(); costDataOfProduct = new ReadWriteData(); usageDataByProduct.put(product, usageDataOfProduct); costDataByProduct.put(product, costDataOfProduct); } } } if (config.randomizer != null && product == Product.monitor) return result; for (int i : indexes) { if (config.randomizer != null) { if (tagGroup.product != Product.rds && tagGroup.product != Product.s3 && usageData.getData(i).get(tagGroup) != null) break; long time = millisStart + i * AwsUtils.hourMillis; usageValue = config.randomizer.randomizeUsage(time, resourceTagGroup == null ? tagGroup : resourceTagGroup, usageValue); costValue = usageValue * config.randomizer.randomizeCost(tagGroup); } if (product != Product.monitor) { Map<TagGroup, Double> usages = usageData.getData(i); Map<TagGroup, Double> costs = costData.getData(i); addValue(usages, tagGroup, usageValue, config.randomizer == null || tagGroup.product == Product.rds || tagGroup.product == Product.s3); addValue(costs, tagGroup, costValue, config.randomizer == null || tagGroup.product == Product.rds || tagGroup.product == Product.s3); } else { resourceCostValue = usageValue * config.costPerMonitorMetricPerHour; } if (resourceTagGroup != null) { Map<TagGroup, Double> usagesOfResource = usageDataOfProduct.getData(i); Map<TagGroup, Double> costsOfResource = costDataOfProduct.getData(i); if (config.randomizer == null || tagGroup.product == Product.rds || tagGroup.product == Product.s3) { addValue(usagesOfResource, resourceTagGroup, usageValue, product != Product.monitor); if (!config.useCostForResourceGroup.equals("modeled") || resourceCostValue < 0) { addValue(costsOfResource, resourceTagGroup, costValue, product != Product.monitor); } else { addValue(costsOfResource, resourceTagGroup, resourceCostValue, product != Product.monitor); } } else { Map<String, Double> distribution = config.randomizer.getDistribution(tagGroup); for (Map.Entry<String, Double> entry : distribution.entrySet()) { String app = entry.getKey(); double dist = entry.getValue(); resourceTagGroup = TagGroup.getTagGroup(account, reformedMetaData.region, zone, product, operation, usageType, ResourceGroup.getResourceGroup(app)); double usage = usageValue * dist; if (product == Product.ec2_instance) usage = (int) usageValue * dist; addValue(usagesOfResource, resourceTagGroup, usage, false); addValue(costsOfResource, resourceTagGroup, usage * config.randomizer.randomizeCost(tagGroup), false); } } } } return result; }
From source file:com.netflix.ice.basic.BasicTagGroupManager.java
License:Apache License
@Override protected void poll() throws IOException { boolean downloaded = AwsUtils.downloadFileIfChanged(config.workS3BucketName, config.workS3BucketPrefix, file, 0);//from w w w.j av a2 s.com if (downloaded || tagGroups == null) { logger.info("trying to read from " + file); DataInputStream in = new DataInputStream(new FileInputStream(file)); try { TreeMap<Long, Collection<TagGroup>> tagGroupsWithResourceGroups = TagGroup.Serializer .deserializeTagGroups(config, in); TreeMap<Long, Collection<TagGroup>> tagGroups = removeResourceGroups(tagGroupsWithResourceGroups); Interval totalInterval = null; if (tagGroups.size() > 0) { totalInterval = new Interval(tagGroups.firstKey(), new DateTime(tagGroups.lastKey()).plusMonths(1).getMillis(), DateTimeZone.UTC); } this.totalInterval = totalInterval; this.tagGroups = tagGroups; this.tagGroupsWithResourceGroups = tagGroupsWithResourceGroups; logger.info("done reading " + file); } finally { in.close(); } } }
From source file:com.netflix.ice.basic.BasicTagGroupManager.java
License:Apache License
private Collection<Long> getMonthMillis(Interval interval) { Set<Long> result = Sets.newTreeSet(); for (Long milli : tagGroups.keySet()) { DateTime monthDate = new DateTime(milli, DateTimeZone.UTC); if (new Interval(monthDate, monthDate.plusMonths(1)).overlap(interval) != null) result.add(milli);/*w ww . j a v a 2 s.c om*/ } return result; }
From source file:com.netflix.ice.basic.BasicWeeklyCostEmailService.java
License:Apache License
private File createImage(ApplicationGroup appgroup) throws IOException { Map<String, Double> costs = Maps.newHashMap(); DateTime end = new DateTime(DateTimeZone.UTC).withDayOfWeek(1).withMillisOfDay(0); Interval interval = new Interval(end.minusWeeks(numWeeks), end); for (Product product : products) { List<ResourceGroup> resourceGroups = getResourceGroups(appgroup, product); if (resourceGroups.size() == 0) { continue; }// ww w. j a v a 2 s . co m DataManager dataManager = config.managers.getCostManager(product, ConsolidateType.weekly); if (dataManager == null) { continue; } TagLists tagLists = new TagLists(accounts, regions, null, Lists.newArrayList(product), null, null, resourceGroups); Map<Tag, double[]> data = dataManager.getData(interval, tagLists, TagType.Product, AggregateType.none, false); for (Tag tag : data.keySet()) { for (int week = 0; week < numWeeks; week++) { String key = tag + "|" + week; if (costs.containsKey(key)) costs.put(key, data.get(tag)[week] + costs.get(key)); else costs.put(key, data.get(tag)[week]); } } } boolean hasData = false; for (Map.Entry<String, Double> entry : costs.entrySet()) { if (!entry.getKey().contains("monitor") && entry.getValue() != null && entry.getValue() >= 0.1) { hasData = true; break; } } if (!hasData) return null; DefaultCategoryDataset dataset = new DefaultCategoryDataset(); for (Product product : products) { for (int week = 0; week < numWeeks; week++) { String weekStr = String.format("%s - %s week", formatter.print(end.minusWeeks(numWeeks - week)).substring(5), formatter.print(end.minusWeeks(numWeeks - week - 1)).substring(5)); dataset.addValue(costs.get(product + "|" + week), product.name, weekStr); } } JFreeChart chart = ChartFactory.createBarChart3D(appgroup.getDisplayName() + " Weekly AWS Costs", "", "Costs", dataset, PlotOrientation.VERTICAL, true, false, false); CategoryPlot categoryplot = (CategoryPlot) chart.getPlot(); BarRenderer3D renderer = (BarRenderer3D) categoryplot.getRenderer(); renderer.setItemLabelAnchorOffset(10.0); TextTitle title = chart.getTitle(); title.setFont(title.getFont().deriveFont((title.getFont().getSize() - 3))); renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator() { public java.lang.String generateLabel(org.jfree.data.category.CategoryDataset dataset, int row, int column) { return costFormatter.format(dataset.getValue(row, column)); } }); renderer.setBaseItemLabelsVisible(true); renderer.setBasePositiveItemLabelPosition( new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_CENTER)); NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis(); numberaxis.setNumberFormatOverride(costFormatter); BufferedImage image = chart.createBufferedImage(1200, 400); File outputfile = File.createTempFile("awscost", "png"); ImageIO.write(image, "png", outputfile); return outputfile; }
From source file:com.netflix.ice.basic.BasicWeeklyCostEmailService.java
License:Apache License
private MimeBodyPart constructEmail(int index, ApplicationGroup appGroup, StringBuilder body) throws IOException, MessagingException { if (index == 0 && !StringUtils.isEmpty(headerNote)) body.append(headerNote);/*from w w w . j a va2 s.com*/ numberFormatter.setMaximumFractionDigits(1); numberFormatter.setMinimumFractionDigits(1); File file = createImage(appGroup); if (file == null) return null; DateTime end = new DateTime(DateTimeZone.UTC).withDayOfWeek(1).withMillisOfDay(0); String link = getLink("area", ConsolidateType.hourly, appGroup, accounts, regions, end.minusWeeks(numWeeks), end); body.append(String.format("<b><h4><a href='%s'>%s</a> Weekly Costs:</h4></b>", link, appGroup.getDisplayName())); body.append("<table style=\"border: 1px solid #DDD; border-collapse: collapse\">"); body.append( "<tr style=\"background-color: whiteSmoke;text-align:center\" ><td style=\"border-left: 1px solid #DDD;\"></td>"); for (int i = 0; i <= accounts.size(); i++) { int cols = i == accounts.size() ? 1 : regions.size(); String accName = i == accounts.size() ? "total" : accounts.get(i).name; body.append(String.format( "<td style=\"border-left: 1px solid #DDD;font-weight: bold;padding: 4px\" colspan='%d'>", cols)) .append(accName).append("</td>"); } body.append("</tr>"); body.append("<tr style=\"background-color: whiteSmoke;text-align:center\" ><td></td>"); for (int i = 0; i < accounts.size(); i++) { boolean first = true; for (Region region : regions) { body.append("<td style=\"font-weight: bold;padding: 4px;" + (first ? "border-left: 1px solid #DDD;" : "") + "\">").append(region.name) .append("</td>"); first = false; } } body.append("<td style=\"border-left: 1px solid #DDD;\"></td></tr>"); Map<String, Double> costs = Maps.newHashMap(); Interval interval = new Interval(end.minusWeeks(numWeeks), end); double[] total = new double[numWeeks]; for (Product product : products) { List<ResourceGroup> resourceGroups = getResourceGroups(appGroup, product); if (resourceGroups.size() == 0) { continue; } DataManager dataManager = config.managers.getCostManager(product, ConsolidateType.weekly); if (dataManager == null) { continue; } for (int i = 0; i < accounts.size(); i++) { List<Account> accountList = Lists.newArrayList(accounts.get(i)); TagLists tagLists = new TagLists(accountList, regions, null, Lists.newArrayList(product), null, null, resourceGroups); Map<Tag, double[]> data = dataManager.getData(interval, tagLists, TagType.Region, AggregateType.none, false); for (Tag tag : data.keySet()) { for (int week = 0; week < numWeeks; week++) { String key = accounts.get(i) + "|" + tag + "|" + week; if (costs.containsKey(key)) costs.put(key, data.get(tag)[week] + costs.get(key)); else costs.put(key, data.get(tag)[week]); total[week] += data.get(tag)[week]; } } } } boolean firstLine = true; DateTime currentWeekEnd = end; for (int week = numWeeks - 1; week >= 0; week--) { String weekStr; if (week == numWeeks - 1) weekStr = "Last week"; else weekStr = (numWeeks - week - 1) + " weeks ago"; String background = week % 2 == 1 ? "background: whiteSmoke;" : ""; body.append(String.format( "<tr style=\"%s\"><td nowrap style=\"border-left: 1px solid #DDD;padding: 4px\">%s (%s - %s)</td>", background, weekStr, formatter.print(currentWeekEnd.minusWeeks(1)).substring(5), formatter.print(currentWeekEnd).substring(5))); for (int i = 0; i < accounts.size(); i++) { Account account = accounts.get(i); for (int j = 0; j < regions.size(); j++) { Region region = regions.get(j); String key = account + "|" + region + "|" + week; double cost = costs.get(key) == null ? 0 : costs.get(key); Double lastCost = week == 0 ? null : costs.get(account + "|" + region + "|" + (week - 1)); link = getLink("column", ConsolidateType.daily, appGroup, Lists.newArrayList(account), Lists.newArrayList(region), currentWeekEnd.minusWeeks(1), currentWeekEnd); body.append(getValueCell(cost, lastCost, link, firstLine)); } } link = getLink("column", ConsolidateType.daily, appGroup, accounts, regions, currentWeekEnd.minusWeeks(1), currentWeekEnd); body.append(getValueCell(total[week], week == 0 ? null : total[week - 1], link, firstLine)); body.append("</tr>"); firstLine = false; currentWeekEnd = currentWeekEnd.minusWeeks(1); } body.append("</table>"); numberFormatter.setMaximumFractionDigits(0); numberFormatter.setMinimumFractionDigits(0); if (!StringUtils.isEmpty(throughputMetrics)) body.append(throughputMetrics); body.append("<br><img src=\"cid:image_cid_" + index + "\"><br>"); for (Map.Entry<String, List<String>> entry : appGroup.data.entrySet()) { String product = entry.getKey(); List<String> selected = entry.getValue(); if (selected == null || selected.size() == 0) continue; link = getLink("area", ConsolidateType.hourly, appGroup, accounts, regions, end.minusWeeks(numWeeks), end); body.append(String.format("<b><h4>%s in <a href='%s'>%s</a>:</h4></b>", getResourceGroupsDisplayName(product), link, appGroup.getDisplayName())); for (String name : selected) body.append(" ").append(name).append("<br>"); } body.append("<hr><br>"); MimeBodyPart mimeBodyPart = new MimeBodyPart(); mimeBodyPart.setFileName(file.getName()); DataSource ds = new ByteArrayDataSource(new FileInputStream(file), "image/png"); mimeBodyPart.setDataHandler(new DataHandler(ds)); mimeBodyPart.setHeader("Content-ID", "<image_cid_" + index + ">"); mimeBodyPart.setHeader("Content-Disposition", "inline"); mimeBodyPart.setDisposition(MimeBodyPart.INLINE); file.delete(); return mimeBodyPart; }