18
18
*/
19
19
package org .apache .cloudstack .vm .schedule ;
20
20
21
- import com .cloud .api .query .MutualExclusiveIdsManagerBase ;
22
- import com .cloud .event .ActionEvent ;
23
- import com .cloud .event .EventTypes ;
24
- import com .cloud .exception .InvalidParameterValueException ;
25
- import com .cloud .user .AccountManager ;
26
- import com .cloud .utils .DateUtil ;
27
- import com .cloud .utils .Pair ;
28
- import com .cloud .utils .component .PluggableService ;
29
- import com .cloud .utils .db .SearchCriteria ;
30
- import com .cloud .utils .db .Transaction ;
31
- import com .cloud .utils .db .TransactionCallback ;
32
- import com .cloud .utils .exception .CloudRuntimeException ;
33
- import com .cloud .vm .UserVmManager ;
34
- import com .cloud .vm .VirtualMachine ;
21
+ import java .time .ZonedDateTime ;
22
+ import java .util .ArrayList ;
23
+ import java .util .Date ;
24
+ import java .util .List ;
25
+ import java .util .Objects ;
26
+ import java .util .TimeZone ;
27
+
28
+ import javax .inject .Inject ;
29
+
35
30
import org .apache .cloudstack .api .ApiCommandResourceType ;
36
31
import org .apache .cloudstack .api .command .user .vm .CreateVMScheduleCmd ;
37
32
import org .apache .cloudstack .api .command .user .vm .DeleteVMScheduleCmd ;
42
37
import org .apache .cloudstack .context .CallContext ;
43
38
import org .apache .cloudstack .vm .schedule .dao .VMScheduleDao ;
44
39
import org .apache .commons .lang .time .DateUtils ;
40
+ import org .apache .commons .lang3 .ObjectUtils ;
45
41
import org .apache .commons .lang3 .StringUtils ;
46
42
import org .apache .log4j .Logger ;
47
43
import org .springframework .scheduling .support .CronExpression ;
48
44
49
- import javax .inject .Inject ;
50
- import java .time .ZonedDateTime ;
51
- import java .util .ArrayList ;
52
- import java .util .Date ;
53
- import java .util .List ;
54
- import java .util .Objects ;
55
- import java .util .TimeZone ;
45
+ import com .cloud .api .query .MutualExclusiveIdsManagerBase ;
46
+ import com .cloud .event .ActionEvent ;
47
+ import com .cloud .event .EventTypes ;
48
+ import com .cloud .exception .InvalidParameterValueException ;
49
+ import com .cloud .user .AccountManager ;
50
+ import com .cloud .utils .DateUtil ;
51
+ import com .cloud .utils .Pair ;
52
+ import com .cloud .utils .component .PluggableService ;
53
+ import com .cloud .utils .db .SearchCriteria ;
54
+ import com .cloud .utils .db .Transaction ;
55
+ import com .cloud .utils .db .TransactionCallback ;
56
+ import com .cloud .utils .exception .CloudRuntimeException ;
57
+ import com .cloud .vm .UserVmManager ;
58
+ import com .cloud .vm .VirtualMachine ;
56
59
57
60
public class VMScheduleManagerImpl extends MutualExclusiveIdsManagerBase implements VMScheduleManager , PluggableService {
58
61
@@ -208,6 +211,9 @@ public VMScheduleResponse updateSchedule(UpdateVMScheduleCmd cmd) {
208
211
Date cmdStartDate = cmd .getStartDate ();
209
212
Date cmdEndDate = cmd .getEndDate ();
210
213
Boolean enabled = cmd .getEnabled ();
214
+ final String originalTimeZone = vmSchedule .getTimeZone ();
215
+ final Date originalStartDate = vmSchedule .getStartDate ();
216
+ final Date originalEndDate = vmSchedule .getEndDate ();
211
217
212
218
TimeZone timeZone ;
213
219
String timeZoneId ;
@@ -234,7 +240,13 @@ public VMScheduleResponse updateSchedule(UpdateVMScheduleCmd cmd) {
234
240
startDate = Date .from (DateUtil .getZoneDateTime (cmdStartDate , timeZone .toZoneId ()).toInstant ());
235
241
}
236
242
237
- validateStartDateEndDate (Objects .requireNonNullElse (startDate , DateUtils .addMinutes (new Date (), 1 )), endDate , timeZone );
243
+ if (ObjectUtils .anyNotNull (cmdStartDate , cmdEndDate , cmdTimeZone ) &&
244
+ (!Objects .equals (originalTimeZone , timeZoneId ) ||
245
+ !Objects .equals (originalStartDate , startDate ) ||
246
+ !Objects .equals (originalEndDate , endDate ))) {
247
+ validateStartDateEndDate (Objects .requireNonNullElse (startDate , DateUtils .addMinutes (new Date (), 1 )),
248
+ endDate , timeZone );
249
+ }
238
250
239
251
if (enabled != null ) {
240
252
vmSchedule .setEnabled (enabled );
0 commit comments