public static String getDateDisplayString(TimeZone tz, Date time) { return getDateDisplayString(tz, time, "yyyy-MM-dd HH:mm:ss"); }
public static String displayDateInTimezone(TimeZone tz, Date time) { return getDateDisplayString(tz, time, "yyyy-MM-dd HH:mm:ss z"); }
@Override public String getLastUpdateTime() { Date date = _mshostVo.getLastUpdateTime(); return DateUtil.getDateDisplayString(TimeZone.getDefault(), date); }
@Override public String getLastPollTime() { Date time = _job.getLastPolled(); if (time != null) return DateUtil.getDateDisplayString(TimeZone.getDefault(), time); return "N/A"; }
@Override public String getCreateTime() { Date time = _job.getCreated(); if (time != null) return DateUtil.getDateDisplayString(TimeZone.getDefault(), time); return "N/A"; }
@Override public String getLastUpdateTime() { Date time = _job.getLastUpdated(); if (time != null) return DateUtil.getDateDisplayString(TimeZone.getDefault(), time); return "N/A"; }
@Override public void ensureQueue(String syncObjType, long syncObjId) { Date dt = DateUtil.currentGMTTime(); String sql = "INSERT IGNORE INTO sync_queue(sync_objtype, sync_objid, created, last_updated)" + " values(?, ?, ?, ?)"; TransactionLegacy txn = TransactionLegacy.currentTxn(); PreparedStatement pstmt = null; try { pstmt = txn.prepareAutoCloseStatement(sql); pstmt.setString(1, syncObjType); pstmt.setLong(2, syncObjId); pstmt.setString(3, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), dt)); pstmt.setString(4, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), dt)); pstmt.execute(); } catch (SQLException e) { s_logger.warn("Unable to create sync queue " + syncObjType + "-" + syncObjId + ":" + e.getMessage(), e); } catch (Throwable e) { s_logger.warn("Unable to create sync queue " + syncObjType + "-" + syncObjId + ":" + e.getMessage(), e); } }
@Override public List<VmDiskStatisticsVO> listActiveAndRecentlyDeleted(Date minRemovedDate, int startIndex, int limit) { List<VmDiskStatisticsVO> vmDiskStats = new ArrayList<VmDiskStatisticsVO>(); if (minRemovedDate == null) return vmDiskStats; TransactionLegacy txn = TransactionLegacy.currentTxn(); try { String sql = ACTIVE_AND_RECENTLY_DELETED_SEARCH + " LIMIT " + startIndex + "," + limit; PreparedStatement pstmt = null; pstmt = txn.prepareAutoCloseStatement(sql); pstmt.setString(1, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), minRemovedDate)); ResultSet rs = pstmt.executeQuery(); while (rs.next()) { vmDiskStats.add(toEntityBean(rs, false)); } } catch (Exception ex) { s_logger.error("error saving vm disk stats to cloud_usage db", ex); } return vmDiskStats; }
@Override public List<UserStatisticsVO> listActiveAndRecentlyDeleted(Date minRemovedDate, int startIndex, int limit) { List<UserStatisticsVO> userStats = new ArrayList<UserStatisticsVO>(); if (minRemovedDate == null) return userStats; TransactionLegacy txn = TransactionLegacy.currentTxn(); try { String sql = ACTIVE_AND_RECENTLY_DELETED_SEARCH + " LIMIT " + startIndex + "," + limit; PreparedStatement pstmt = null; pstmt = txn.prepareAutoCloseStatement(sql); pstmt.setString(1, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), minRemovedDate)); ResultSet rs = pstmt.executeQuery(); while (rs.next()) { userStats.add(toEntityBean(rs, false)); } } catch (Exception ex) { s_logger.error("error saving user stats to cloud_usage db", ex); } return userStats; }
private long getMaxEventId(Date endDate) { TransactionLegacy txn = TransactionLegacy.currentTxn(); PreparedStatement pstmt = null; try { String sql = MAX_EVENT; pstmt = txn.prepareAutoCloseStatement(sql); pstmt.setString(1, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), endDate)); ResultSet rs = pstmt.executeQuery(); if (rs.next()) { return Long.valueOf(rs.getLong(1)); } return 0; } catch (Exception ex) { s_logger.error("error getting max event id", ex); throw new CloudRuntimeException(ex.getMessage()); } finally { txn.close(); } }
@Override @DB public void update(long id, long runid, String name, String version, String serviceIP, int servicePort, Date lastUpdate) { TransactionLegacy txn = TransactionLegacy.currentTxn(); PreparedStatement pstmt = null; try { txn.start(); pstmt = txn.prepareAutoCloseStatement("update mshost set name=?, version=?, service_ip=?, service_port=?, last_update=?, removed=null, alert_count=0, runid=?, state=? where id=?"); pstmt.setString(1, name); pstmt.setString(2, version); pstmt.setString(3, serviceIP); pstmt.setInt(4, servicePort); pstmt.setString(5, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), lastUpdate)); pstmt.setLong(6, runid); pstmt.setString(7, ManagementServerHost.State.Up.toString()); pstmt.setLong(8, id); pstmt.executeUpdate(); txn.commit(); } catch (Exception e) { s_logger.warn("Unexpected exception, ", e); throw new RuntimeException(e.getMessage(), e); } }
public static void main(String[] args) { TimeZone localTimezone = Calendar.getInstance().getTimeZone(); TimeZone gmtTimezone = TimeZone.getTimeZone("GMT"); TimeZone estTimezone = TimeZone.getTimeZone("EST"); Date time = new Date(); System.out.println("local time :" + DateUtil.getDateDisplayString(localTimezone, time)); System.out.println("GMT time :" + DateUtil.getDateDisplayString(gmtTimezone, time)); System.out.println("EST time :" + DateUtil.getDateDisplayString(estTimezone, time)); //Test next run time. Expects interval and schedule as arguments if (args.length == 2) { System.out.println("Next run time: " + DateUtil.getNextRunTime(IntervalType.getIntervalType(args[0]), args[1], "GMT", time).toString()); } }
@Override public void update(VMTemplateHostVO instance) { TransactionLegacy txn = TransactionLegacy.currentTxn(); PreparedStatement pstmt = null; try { Date now = new Date(); String sql = UPDATE_TEMPLATE_HOST_REF; pstmt = txn.prepareAutoCloseStatement(sql); pstmt.setString(1, instance.getDownloadState().toString()); pstmt.setInt(2, instance.getDownloadPercent()); pstmt.setString(3, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), now)); pstmt.setString(4, instance.getErrorString()); pstmt.setString(5, instance.getLocalDownloadPath()); pstmt.setString(6, instance.getJobId()); pstmt.setLong(7, instance.getHostId()); pstmt.setLong(8, instance.getTemplateId()); pstmt.executeUpdate(); } catch (Exception e) { s_logger.warn("Exception: ", e); } }
@Override public void update(long id, long runId, State state, Date lastUpdate) { TransactionLegacy txn = TransactionLegacy.currentTxn(); PreparedStatement pstmt = null; try { pstmt = txn.prepareAutoCloseStatement("update mshost set state=?, last_update=? where id=? and runid=?"); pstmt.setString(1, state.toString()); pstmt.setString(2, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), lastUpdate)); pstmt.setLong(3, id); pstmt.setLong(4, runId); int count = pstmt.executeUpdate(); if (count < 1) { s_logger.info("Invalid cluster session detected, runId " + runId + " is no longer valid"); throw new CloudRuntimeException("Invalid cluster session detected, runId " + runId + " is no longer valid", new ClusterInvalidSessionException("runId " + runId + " is no longer valid")); } } catch (SQLException e) { throw new CloudRuntimeException("DB exception: ", e); } }
@Override @DB public void update(long id, long runid, Date lastUpdate) { TransactionLegacy txn = TransactionLegacy.currentTxn(); PreparedStatement pstmt = null; try { txn.start(); pstmt = txn.prepareAutoCloseStatement("update mshost set last_update=?, removed=null, alert_count=0 where id=? and runid=?"); pstmt.setString(1, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), lastUpdate)); pstmt.setLong(2, id); pstmt.setLong(3, runid); int count = pstmt.executeUpdate(); txn.commit(); if (count < 1) { s_logger.info("Invalid cluster session detected, runId " + runid + " is no longer valid"); throw new CloudRuntimeException("Invalid cluster session detected, runId " + runid + " is no longer valid", new ClusterInvalidSessionException("runId " + runid + " is no longer valid")); } } catch (Exception e) { s_logger.warn("Unexpected exception, ", e); throw new RuntimeException(e.getMessage(), e); } }
@Override public void update(UsageVMSnapshotVO usage) { TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.USAGE_DB); PreparedStatement pstmt = null; try { txn.start(); pstmt = txn.prepareAutoCloseStatement(UPDATE_DELETED); pstmt.setString(1, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), usage.getProcessed())); pstmt.setLong(2, usage.getAccountId()); pstmt.setLong(3, usage.getId()); pstmt.setLong(4, usage.getVmId()); pstmt.setString(5, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), usage.getCreated())); pstmt.executeUpdate(); txn.commit(); } catch (Exception e) { txn.rollback(); s_logger.warn("Error updating UsageVMSnapshotVO", e); } finally { txn.close(); } }
@Override public void updateDeleted(UsageSnapshotOnPrimaryVO usage) { TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.USAGE_DB); PreparedStatement pstmt = null; try { txn.start(); pstmt = txn.prepareAutoCloseStatement(UPDATE_DELETED); pstmt.setString(1, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), usage.getDeleted())); pstmt.setLong(2, usage.getAccountId()); pstmt.setLong(3, usage.getId()); pstmt.setLong(4, usage.getVmId()); pstmt.setString(5, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), usage.getCreated())); pstmt.executeUpdate(); txn.commit(); } catch (Exception e) { txn.rollback(); s_logger.warn("Error updating UsageSnapshotOnPrimaryVO", e); } finally { txn.close(); } }
@Override public void update(UsageVMInstanceVO instance) { TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.USAGE_DB); PreparedStatement pstmt = null; try { txn.start(); String sql = UPDATE_USAGE_INSTANCE_SQL; pstmt = txn.prepareAutoCloseStatement(sql); pstmt.setString(1, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), instance.getEndDate())); pstmt.setLong(2, instance.getAccountId()); pstmt.setLong(3, instance.getVmInstanceId()); pstmt.setInt(4, instance.getUsageType()); pstmt.executeUpdate(); txn.commit(); } catch (Exception e) { s_logger.warn(e); } finally { txn.close(); } }
@Override public void update(UsageNetworkOfferingVO usage) { TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.USAGE_DB); try { txn.start(); if (usage.getDeleted() != null) { try(PreparedStatement pstmt = txn.prepareStatement(UPDATE_DELETED);) { if (pstmt != null) { pstmt.setString(1, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), usage.getDeleted())); pstmt.setLong(2, usage.getAccountId()); pstmt.setLong(3, usage.getVmInstanceId()); pstmt.setLong(4, usage.getNetworkOfferingId()); pstmt.executeUpdate(); } }catch (SQLException e) { throw new CloudException("Error updating UsageNetworkOfferingVO:"+e.getMessage(), e); } } txn.commit(); } catch (Exception e) { txn.rollback(); s_logger.warn("Error updating UsageNetworkOfferingVO:"+e.getMessage(), e); } finally { txn.close(); } }
@Override public void update(UsageVolumeVO usage) { TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.USAGE_DB); PreparedStatement pstmt = null; try { txn.start(); if (usage.getDeleted() != null) { pstmt = txn.prepareAutoCloseStatement(UPDATE_DELETED); pstmt.setString(1, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), usage.getDeleted())); pstmt.setLong(2, usage.getAccountId()); pstmt.setLong(3, usage.getId()); pstmt.executeUpdate(); } txn.commit(); } catch (Exception e) { txn.rollback(); s_logger.warn("Error updating UsageVolumeVO", e); } finally { txn.close(); } }