Skip to content

Commit 421f107

Browse files
marcaureleyadvr
authored andcommitted
CLOUDSTACK-10123: Entity should use GMT TZ for timestamp values (#2303)
Depending on the timezone you're running CS (before GMT timezones) you could experience that some jobs are marked as failed since the parent job got a null result despite its child job having successfully done the job. The child job got deleted by the CleanupTask ahead of time, due to a missing datetime conversion to GMT timezone. Jobs are failing with this message: Job failed with un-handled exception The fix intends to correct any datetime used in the code that should be using the GMT timezone instead of the local one since all DB datetime should be stored at GMT.
1 parent cd6288e commit 421f107

2 files changed

Lines changed: 4 additions & 5 deletions

File tree

engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2608,9 +2608,7 @@ protected void runInContext() {
26082608
s_logger.trace("VM Operation Thread Running");
26092609
try {
26102610
_workDao.cleanup(VmOpCleanupWait.value());
2611-
2612-
// TODO. hard-coded to one hour after job has been completed
2613-
final Date cutDate = new Date(new Date().getTime() - 3600000);
2611+
final Date cutDate = new Date(DateUtil.currentGMTTime().getTime() - VmOpCleanupInterval.value() * 1000);
26142612
_workJobDao.expungeCompletedWorkJobs(cutDate);
26152613
} catch (final Exception e) {
26162614
s_logger.error("VM Operations failed due to ", e);
@@ -2980,7 +2978,7 @@ protected void runInContext() {
29802978
try {
29812979
scanStalledVMInTransitionStateOnDisconnectedHosts();
29822980

2983-
final List<VMInstanceVO> instances = _vmDao.findVMInTransition(new Date(new Date().getTime() - AgentManager.Wait.value() * 1000), State.Starting, State.Stopping);
2981+
final List<VMInstanceVO> instances = _vmDao.findVMInTransition(new Date(DateUtil.currentGMTTime().getTime() - AgentManager.Wait.value() * 1000), State.Starting, State.Stopping);
29842982
for (final VMInstanceVO instance : instances) {
29852983
final State state = instance.getState();
29862984
if (state == State.Stopping) {

server/src/com/cloud/test/DatabaseConfig.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import com.cloud.storage.DiskOfferingVO;
4444
import com.cloud.storage.Storage.ProvisioningType;
4545
import com.cloud.storage.dao.DiskOfferingDaoImpl;
46+
import com.cloud.utils.DateUtil;
4647
import com.cloud.utils.PropertiesUtil;
4748
import com.cloud.utils.component.ComponentContext;
4849
import com.cloud.utils.db.DB;
@@ -639,7 +640,7 @@ public void saveStoragePool() {
639640
stmt.setLong(8, 0);
640641
stmt.setString(9, hostAddress);
641642
stmt.setString(10, hostPath);
642-
stmt.setDate(11, new Date(new java.util.Date().getTime()));
643+
stmt.setDate(11, new Date(DateUtil.currentGMTTime().getTime()));
643644
stmt.setLong(12, podId);
644645
stmt.setString(13, Status.Up.toString());
645646
stmt.setLong(14, clusterId);

0 commit comments

Comments
 (0)