List of usage examples for org.joda.time DateTime DateTime
public DateTime(Object instant)
From source file:ch.icclab.cyclops.schedule.runner.CloudStackClient.java
License:Open Source License
/** * This method gets called from outside in order to get data from CloudStack and store it into database *///from w ww. j a va 2s. com private void updateRecords() { logger.debug("Started with updating Usage Records from CloudStack"); // get data from CloudStack Boolean status = cloudStackPuller.pullUsageRecords(); if (status) { // get now Long time = new DateTime(DateTimeZone.UTC).getMillis(); // update time stamp LatestPullORM pull = (LatestPullORM) hibernateClient.getObject(LatestPullORM.class, 1l); if (pull == null) { pull = new LatestPullORM(time); } else { pull.setTimeStamp(time); } hibernateClient.persistObject(pull); } else { logger.error("Couldn't update CloudStack Usage records"); } }
From source file:ch.icclab.cyclops.services.iaas.cloudstack.client.CloudStackClient.java
License:Open Source License
/** * This method gets called from outside in order to get data from CloudStack and store it into database * * @return//from ww w . j a v a 2 s. c om */ private void updateRecords() { logger.debug("Started with updating Usage Records from CloudStack"); // mark the date (we have to do it here, not in DB client, as request can be before midnight and saving to DB on the next day) DateTime mark = new DateTime(DateTimeZone.UTC); // get data from CloudStack Boolean status = cloudStackPuller.pullUsageRecords(); if (status) { try { // check for the first time whether we are using extended CloudStack if (settings.extendedCloudStack() || settings.isExtendedCloudStackFlagUnset()) { // try to pull data status = cloudStackPuller.pullCustomUsageRecords(); // update settings to reflect whether we are using extended CloudStack or vanilla one if (settings.isExtendedCloudStackFlagUnset()) { if (status) { settings.setExtendedCloudStack(); // also update meter list selection with extended list CloudStackMeter meter = new CloudStackMeter(); meter.initializeWithList(CloudStackUsageTypes.getExtendedList()); } else { settings.setVanillaCloudStack(); } } } } catch (Exception e) { // if it failed we know that we have to work only with vanilla cloudstack settings.setVanillaCloudStack(); } // everything went fine, save timestamp to database dbClient.saveLog(mark, "pull"); } else { logger.error("Couldn't update CloudStack Usage records"); } }
From source file:ch.icclab.cyclops.services.iaas.cloudstack.client.CloudStackScheduler.java
License:Open Source License
/** * Compute difference between now and closest full hour * * @return time in milliseconds/* w w w . j ava 2s .c om*/ */ private long getSecondsToFullHour() { DateTime now = new DateTime(DateTimeZone.UTC); DateTime hour = now.hourOfDay().roundCeilingCopy(); // return difference in milliseconds return new Duration(now, hour).getMillis(); }
From source file:ch.icclab.cyclops.services.iaas.cloudstack.client.CloudStackScheduler.java
License:Open Source License
/** * Log what have just happened//from w w w. j ava 2 s . c o m * * @param command as typeEvent */ private void logEvent(String command) { DateTime mark = new DateTime(DateTimeZone.UTC); new InfluxDBClient().saveLog(mark, command); logger.trace("CloudStackScheduler logging event: " + command); }
From source file:ch.icclab.cyclops.timeseries.InfluxDBResponse.java
License:Open Source License
/** * Parse and transform InfluxDB's underlying structure * @return list of maps//from ww w .j a va 2 s .c om */ public List<Map> getListOfObjects() throws Exception { List<Map> list = new ArrayList<>(); if (object != null && !object.hasError()) { // iterate over available results for (QueryResult.Result result : object.getResults()) { // multiple query responses can have empty results if (result != null) { List<QueryResult.Series> bulk = result.getSeries(); if (bulk != null && !bulk.isEmpty()) { // iterate over available series for (QueryResult.Series series : result.getSeries()) { // iterate over individual value sets Map<String, String> tags = series.getTags(); List<String> columns = series.getColumns(); int time = columns.indexOf(TIME_FIELD); List<List<Object>> values = series.getValues(); // iterate over individual values if (values != null && !values.isEmpty()) { for (List<Object> value : values) { // we will store one row here Map<String, Object> row = new HashMap<>(); // add tag values if there are any if (tags != null && !tags.isEmpty()) { row.putAll(tags); } // individual entries of the value int i = 0; for (Object entry : value) { // timestamp needs to be in Long and not String if (time == i) { entry = new DateTime(entry).getMillis() / 1000; } row.put(columns.get(i), entry); i++; } // remove property that is used for counting and should never be visible row.remove(InfluxDBCredentials.COUNTER_FIELD_NAME); // return de-flattened map list.add(new Gson().fromJson(JsonUnflattener.unflatten(new Gson().toJson(row)), Map.class)); } } } } } } return list; } throw new Exception("Couldn't parse InfluxDB response"); }
From source file:ch.icclab.cyclops.util.DateInterval.java
License:Open Source License
public DateInterval() { DateTime from = whenWasLastPull();/*from w ww .ja v a 2s . c om*/ fromDate = from.toString("yyyy-MM-dd'T'HH:mm:ssZ"); toDate = new DateTime(DateTimeZone.UTC).toString("yyyy-MM-dd'T'HH:mm:ssZ"); if (fromDate.contains("+")) fromDate = fromDate.substring(0, fromDate.indexOf("+")); if (toDate.contains("+")) toDate = toDate.substring(0, toDate.indexOf("+")); }
From source file:ch.icclab.cyclops.util.DateInterval.java
License:Open Source License
/** * Will determine when was the last entry point (pull from Ceilometer), or even if there was any * * @return date object of the last commit, or epoch if there was none *//*from ww w . j av a 2 s. co m*/ private DateTime whenWasLastPull() { DateTime last; LatestPullORM pull = (LatestPullORM) HibernateClient.getInstance().getObject(LatestPullORM.class, 1l); if (pull == null) { last = new DateTime(0); } else { last = new DateTime(pull.getTimeStamp()); } logger.trace("Getting the last pull date " + last.toString()); // get date specified by admin String date = Loader.getSettings().getOpenStackSettings().getFirstImport(); if (date != null && !date.isEmpty()) { try { logger.trace("Admin provided us with import date preference " + date); DateTime selection = Time.getDateForTime(date); // if we are first time starting and having Epoch, change it to admin's selection // otherwise skip admin's selection and continue from the last DB entry time if (last.getMillis() == 0) { logger.debug("Setting first import date as configuration file dictates."); last = selection; } } catch (Exception ignored) { // ignoring configuration preference, as admin didn't provide correct format logger.debug("Import date selection for Ceilometer ignored - use yyyy-MM-dd'T'HH:mm:ssZ format"); } } DateTime dateTime = last.toDateTime(DateTimeZone.UTC); return dateTime; }
From source file:ch.opentrainingcenter.charts.bar.internal.ChartDataSupport.java
License:Open Source License
private void adjust(final List<ChartDataWrapper> past, final List<ChartDataWrapper> now, final int yearOffset) { final Set<String> allCategories = new HashSet<>(); for (final ChartDataWrapper vm : past) { allCategories.add(vm.getCategory()); }// w w w . ja v a2 s.c o m final List<ChartDataWrapper> list = new ArrayList<>(); for (final ChartDataWrapper vm : now) { final boolean added = allCategories.add(vm.getCategory()); if (added) { // existierte noch nicht DateTime dt = new DateTime(vm.getDate().getTime()); dt = dt.minusYears(yearOffset); list.add(new ChartDataWrapper(0d, 0, vm.getCategory(), dt.toDate())); } } past.addAll(list); }
From source file:ch.opentrainingcenter.client.views.ngchart.DynamicChartViewPart.java
License:Open Source License
private void update() { Display.getDefault().asyncExec(new Runnable() { @Override/* ww w. java 2 s. c o m*/ public void run() { final XAxisChart xAxis = XAxisChart.getByIndex(tagMonatJahrCombo.getSelectionIndex()); compareWithLastYear.setEnabled(!XAxisChart.DAY.equals(xAxis)); final SimplePair<Date> startEnd = getStartEnd(); final String start = TimeHelper.convertDateToString(startEnd.getFirst()); final String end = TimeHelper.convertDateToString(startEnd.getSecond()); LOGGER.info(String.format("Chart now %s von %s bis %s", xAxis, start, end)); //$NON-NLS-1$ final int sportIndex = comboSport.getSelectionIndex(); final Sport sport = Sport.getByIndex(sportIndex); final List<ITraining> dataNow = getFilteredData(xAxis, startEnd.getFirst(), startEnd.getSecond(), sport); final DateTime dtStartCurrent = new DateTime(startEnd.getFirst().getTime()); final DateTime dtEndCurrent = new DateTime(startEnd.getSecond().getTime()); final Date startPastOne = dtStartCurrent.minusYears(1).toDate(); final Date endPastOne = dtEndCurrent.minusYears(1).toDate(); final String readablePastStartOne = TimeHelper.convertDateToString(startPastOne); final String readablePastEndOne = TimeHelper.convertDateToString(endPastOne); LOGGER.info(String.format("Chart past One %s von %s bis %s", xAxis, readablePastStartOne, //$NON-NLS-1$ readablePastEndOne)); final List<ITraining> dataPastOne = getFilteredData(xAxis, startPastOne, endPastOne, sport); final Date startPastTwo = dtStartCurrent.minusYears(2).toDate(); final Date endPastTwo = dtEndCurrent.minusYears(2).toDate(); final String readablePastStart2 = TimeHelper.convertDateToString(startPastTwo); final String readablePastEnd2 = TimeHelper.convertDateToString(endPastTwo); LOGGER.info(String.format("Chart past Two %s von %s bis %s", xAxis, readablePastStart2, //$NON-NLS-1$ readablePastEnd2)); final List<ITraining> dataPastTwo = getFilteredData(xAxis, startPastTwo, endPastTwo, sport); final List<PastTraining> past = new ArrayList<>(); past.add(new PastTraining(2, dataPastTwo)); past.add(new PastTraining(1, dataPastOne)); final TrainingChart chartType = TrainingChart.getByIndex(yAchseCombo.getSelectionIndex()); final boolean compareLast = compareWithLastYear.getSelection(); chartViewer.updateData(dataNow, past, xAxis, chartType, compareLast); chartViewer.updateRenderer(xAxis, chartType, compareLast); chartViewer.forceRedraw(); sectionChart.setExpanded(true); final java.awt.Color color; if (TrainingChart.DISTANZ.equals(chartType)) { color = ColorFromPreferenceHelper.getColor(store, PreferenceConstants.CHART_DISTANCE_COLOR, 255); } else { color = ColorFromPreferenceHelper.getColor(store, PreferenceConstants.CHART_HEART_COLOR, 255); } labelIconNow.setImage(createImage(ColorFromPreferenceHelper.awtColor2swtColot(color))); labelIconPast.setImage(createImage(ColorFromPreferenceHelper.awtColor2swtColot(color.brighter()))); labelIconPastPast.setImage( createImage(ColorFromPreferenceHelper.awtColor2swtColot(color.brighter().brighter()))); labelTextNow.setText(DATE_FORMAT.format(dtStartCurrent.toDate()) + PFEIL + DATE_FORMAT.format(dtEndCurrent.toDate())); labelTextPast.setText(DATE_FORMAT.format(startPastOne) + PFEIL + DATE_FORMAT.format(endPastOne)); labelTextPastPast .setText(DATE_FORMAT.format(startPastTwo) + PFEIL + DATE_FORMAT.format(endPastTwo)); labelIconPast.setVisible(compareLast); labelTextPast.setVisible(compareLast); labelIconPastPast.setVisible(compareLast); labelTextPastPast.setVisible(compareLast); sectionLegende.setExpanded(true); } }); }
From source file:ch.opentrainingcenter.client.views.ngchart.DynamicChartViewPart.java
License:Open Source License
private SimplePair<Date> getStartEnd() { final XAxisChart xAxis = XAxisChart.getByIndex(tagMonatJahrCombo.getSelectionIndex()); final boolean year = XAxisChart.YEAR.equals(xAxis); final boolean yearTillNow = XAxisChart.YEAR_START_TILL_NOW.equals(xAxis); Date start = dateVon.getDate().toDate();// von.toDate(); Date end = dateBis.getDate().toDate();// DateTime.now().toDate(); dateVon.setEnabled(!(yearTillNow || year)); dateBis.setEnabled(!year);/*w w w. jav a2s . c om*/ if (yearTillNow || year) { final int yStart = new DateTime(end.getTime()).get(DateTimeFieldType.year()); start = TimeHelper.getDate(yStart, 0, 1); dateVon.setEnabled(false); } if (year) { final int yEnd = new DateTime(end.getTime()).get(DateTimeFieldType.year()); end = TimeHelper.getDate(yEnd, 11, 31); dateBis.setEnabled(false); } return new SimplePair<Date>(start, end); }