Skip to content

Commit 36efbfc

Browse files
committed
Merge remote-tracking branch 'origin/4.13'
2 parents 3575f5e + cd6f0cb commit 36efbfc

File tree

3 files changed

+15
-20
lines changed

3 files changed

+15
-20
lines changed

server/src/main/java/com/cloud/server/StatsCollector.java

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,10 @@ public String toString() {
192192
private static final String DISK_WRITE_IOPS_FIELD = "disk_write_iops";
193193
private static final String DISK_WRITE_KBS_FIELD = "disk_write_kbs";
194194

195+
private static final int HOURLY_TIME = 60;
196+
private static final int DAILY_TIME = HOURLY_TIME * 24;
197+
private static final Long ONE_MINUTE_IN_MILLISCONDS = 60000L;
198+
195199
private static final String DEFAULT_DATABASE_NAME = "cloudstack";
196200
private static final String INFLUXDB_HOST_MEASUREMENT = "host_stats";
197201
private static final String INFLUXDB_VM_MEASUREMENT = "vm_stats";
@@ -328,11 +332,11 @@ public boolean start() {
328332
protected void init(Map<String, String> configs) {
329333
_executor = Executors.newScheduledThreadPool(6, new NamedThreadFactory("StatsCollector"));
330334

331-
hostStatsInterval = NumbersUtil.parseLong(configs.get("host.stats.interval"), 60000L);
332-
hostAndVmStatsInterval = NumbersUtil.parseLong(configs.get("vm.stats.interval"), 60000L);
333-
storageStatsInterval = NumbersUtil.parseLong(configs.get("storage.stats.interval"), 60000L);
334-
volumeStatsInterval = NumbersUtil.parseLong(configs.get("volume.stats.interval"), 600000L);
335-
autoScaleStatsInterval = NumbersUtil.parseLong(configs.get("autoscale.stats.interval"), 60000L);
335+
hostStatsInterval = NumbersUtil.parseLong(configs.get("host.stats.interval"), ONE_MINUTE_IN_MILLISCONDS);
336+
hostAndVmStatsInterval = NumbersUtil.parseLong(configs.get("vm.stats.interval"), ONE_MINUTE_IN_MILLISCONDS);
337+
storageStatsInterval = NumbersUtil.parseLong(configs.get("storage.stats.interval"), ONE_MINUTE_IN_MILLISCONDS);
338+
volumeStatsInterval = NumbersUtil.parseLong(configs.get("volume.stats.interval"), ONE_MINUTE_IN_MILLISCONDS);
339+
autoScaleStatsInterval = NumbersUtil.parseLong(configs.get("autoscale.stats.interval"), ONE_MINUTE_IN_MILLISCONDS);
336340

337341
String statsUri = statsOutputUri.value();
338342
if (StringUtils.isNotBlank(statsUri)) {
@@ -427,8 +431,6 @@ protected void init(Map<String, String> configs) {
427431
Calendar cal = Calendar.getInstance(usageTimezone);
428432
cal.setTime(new Date());
429433
long endDate = 0;
430-
int HOURLY_TIME = 60;
431-
final int DAILY_TIME = 60 * 24;
432434
if (_usageAggregationRange == DAILY_TIME) {
433435
cal.set(Calendar.HOUR_OF_DAY, 0);
434436
cal.set(Calendar.MINUTE, 0);
@@ -454,9 +456,9 @@ protected void init(Map<String, String> configs) {
454456
s_logger.warn("Usage stats job aggregation range is to small, using the minimum value of " + UsageUtils.USAGE_AGGREGATION_RANGE_MIN);
455457
_usageAggregationRange = UsageUtils.USAGE_AGGREGATION_RANGE_MIN;
456458
}
457-
_diskStatsUpdateExecutor.scheduleAtFixedRate(new VmDiskStatsUpdaterTask(), (endDate - System.currentTimeMillis()), (_usageAggregationRange * 60 * 1000),
458-
TimeUnit.MILLISECONDS);
459459

460+
long period = _usageAggregationRange * ONE_MINUTE_IN_MILLISCONDS;
461+
_diskStatsUpdateExecutor.scheduleAtFixedRate(new VmDiskStatsUpdaterTask(), (endDate - System.currentTimeMillis()), period, TimeUnit.MILLISECONDS);
460462
}
461463

462464
/**
@@ -1209,7 +1211,7 @@ private String getAutoscaleAction(HashMap<Long, Double> avgCounter, long groupId
12091211
for (AutoScaleVmGroupPolicyMapVO asVmgPmap : listMap) {
12101212
AutoScalePolicyVO policyVO = _asPolicyDao.findById(asVmgPmap.getPolicyId());
12111213
if (policyVO != null) {
1212-
Integer quitetime = policyVO.getQuietTime();
1214+
int quitetime = policyVO.getQuietTime();
12131215
Date quitetimeDate = policyVO.getLastQuiteTime();
12141216
long last_quitetime = 0L;
12151217
if (quitetimeDate != null) {
@@ -1236,7 +1238,7 @@ private String getAutoscaleAction(HashMap<Long, Double> avgCounter, long groupId
12361238
if (counter_param.equals(counter_source.toString()))
12371239
break;
12381240
counter_count++;
1239-
} while (1 == 1);
1241+
} while (true);
12401242

12411243
Double sum = avgCounter.get(counter_count);
12421244
Double avg = sum / currentVM;
@@ -1540,9 +1542,6 @@ protected boolean isCurrentVmDiskStatsDifferentFromPrevious(VmDiskStatisticsVO p
15401542
boolean ioWriteDifferentFromPrevious = previousVmDiskStats.getCurrentIOWrite() != currentVmDiskStats.getCurrentIOWrite();
15411543
return bytesReadDifferentFromPrevious || bytesWriteDifferentFromPrevious || ioReadDifferentFromPrevious || ioWriteDifferentFromPrevious;
15421544
}
1543-
if (currentVmDiskStats == null) {
1544-
return false;
1545-
}
15461545
return true;
15471546
}
15481547

server/src/main/java/com/cloud/vm/UserVmManagerImpl.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -847,6 +847,7 @@ public UserVm resetVMSSHKey(ResetVMSSHKeyCmd cmd) throws ResourceUnavailableExce
847847
if (!result) {
848848
throw new CloudRuntimeException("Failed to reset SSH Key for the virtual machine ");
849849
}
850+
userVm.setPassword(password);
850851
return userVm;
851852
}
852853

@@ -6756,6 +6757,7 @@ public UserVm restoreVMInternal(Account caller, UserVmVO vm, Long newTemplateId)
67566757
if (!result) {
67576758
throw new CloudRuntimeException("VM reset is completed but failed to reset password for the virtual machine ");
67586759
}
6760+
vm.setPassword(password);
67596761
}
67606762

67616763
if (needRestart) {

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,6 @@ public void isCurrentVmDiskStatsDifferentFromPreviousTestNull() {
159159
Assert.assertTrue(result);
160160
}
161161

162-
@Test
163-
public void isCurrentVmDiskStatsDifferentFromPreviousTestBothNull() {
164-
boolean result = statsCollector.isCurrentVmDiskStatsDifferentFromPrevious(null, null);
165-
Assert.assertFalse(result);
166-
}
167-
168162
@Test
169163
public void isCurrentVmDiskStatsDifferentFromPreviousTestDifferentIoWrite() {
170164
configureAndTestisCurrentVmDiskStatsDifferentFromPrevious(123l, 123l, 123l, 12l, true);

0 commit comments

Comments
 (0)