rohityadavcloud commented on code in PR #7289:
URL: https://github.com/apache/cloudstack/pull/7289#discussion_r1133514743
##########
api/src/main/java/com/cloud/event/EventTypes.java:
##########
@@ -87,6 +87,12 @@
public class EventTypes {
+ public static final String EVENT_VMSCHEDULE_CREATE = "VM.SCHEDULE";
Review Comment:
Should this be called `VM.SCHEDULE.CREATE` ?
##########
api/src/main/java/com/cloud/vm/schedule/VMSchedule.java:
##########
@@ -0,0 +1,49 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package com.cloud.vm.schedule;
+
+import org.apache.cloudstack.api.Identity;
+import org.apache.cloudstack.api.InternalIdentity;
+
+public interface VMSchedule extends Identity, InternalIdentity {
+ public enum State {
+ Disabled, Enabled
+ }
+
+ public enum Action {
+ start, stop, forcestop, reboot
+ }
+
+ public String getUuid();
Review Comment:
Is this necesasry if VMSchedule extends Identity and InternalIdentity?
##########
api/src/main/java/org/apache/cloudstack/api/ApiConstants.java:
##########
@@ -1020,6 +1020,16 @@ public class ApiConstants {
public static final String PRIVATE_MTU = "privatemtu";
public static final String MTU = "mtu";
public static final String LIST_APIS = "listApis";
+ public static final String VM_SCHEDULE_DESCRIPTION = "description";
Review Comment:
VM_ prefix isn't necessary unless the parameter is specifically for VM
Schedule feature, this for example can simply be description (it's possible the
DESCRIPTION param already exists that you can simply reuse).
##########
api/src/main/java/org/apache/cloudstack/api/command/user/vmschedule/CreateVMScheduleCmd.java:
##########
@@ -0,0 +1,142 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package org.apache.cloudstack.api.command.user.vmschedule;
+
+import com.cloud.event.EventTypes;
+import com.cloud.exception.ResourceAllocationException;
+import com.cloud.user.Account;
+import com.cloud.utils.exception.CloudRuntimeException;
+import com.cloud.vm.VirtualMachine;
+import com.cloud.vm.schedule.VMSchedule;
+import org.apache.cloudstack.acl.RoleType;
+
+import org.apache.cloudstack.api.APICommand;
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.BaseAsyncCreateCmd;
+import org.apache.cloudstack.api.BaseCmd;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.ApiErrorCode;
+import org.apache.cloudstack.api.response.UserVmResponse;
+import org.apache.cloudstack.api.response.VMScheduleResponse;
+import org.apache.cloudstack.context.CallContext;
+import org.apache.log4j.Logger;
+
+@APICommand(name = CreateVMScheduleCmd.APINAME,
+ description = "Creates Schedule for a VM",
+ responseObject = VMScheduleResponse.class,
+ since = "4.19.0",
+ entityType = {VMSchedule.class},
+ requestHasSensitiveInfo = false, responseHasSensitiveInfo = false,
+ authorized = {RoleType.Admin, RoleType.ResourceAdmin,
RoleType.DomainAdmin, RoleType.User})
+public class CreateVMScheduleCmd extends BaseAsyncCreateCmd {
+ public static final String APINAME = "createVMSchedule";
+ public static final Logger s_logger =
Logger.getLogger(CreateVMScheduleCmd.class);
Review Comment:
nit - we generally these day declare it as LOG or LOGGER, s_logger naming is
considered old/archaic.
##########
api/src/main/java/org/apache/cloudstack/api/command/user/vmschedule/CreateVMScheduleCmd.java:
##########
@@ -0,0 +1,142 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package org.apache.cloudstack.api.command.user.vmschedule;
+
+import com.cloud.event.EventTypes;
+import com.cloud.exception.ResourceAllocationException;
+import com.cloud.user.Account;
+import com.cloud.utils.exception.CloudRuntimeException;
+import com.cloud.vm.VirtualMachine;
+import com.cloud.vm.schedule.VMSchedule;
+import org.apache.cloudstack.acl.RoleType;
+
+import org.apache.cloudstack.api.APICommand;
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.BaseAsyncCreateCmd;
+import org.apache.cloudstack.api.BaseCmd;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.ApiErrorCode;
+import org.apache.cloudstack.api.response.UserVmResponse;
+import org.apache.cloudstack.api.response.VMScheduleResponse;
+import org.apache.cloudstack.context.CallContext;
+import org.apache.log4j.Logger;
+
+@APICommand(name = CreateVMScheduleCmd.APINAME,
+ description = "Creates Schedule for a VM",
+ responseObject = VMScheduleResponse.class,
+ since = "4.19.0",
+ entityType = {VMSchedule.class},
+ requestHasSensitiveInfo = false, responseHasSensitiveInfo = false,
+ authorized = {RoleType.Admin, RoleType.ResourceAdmin,
RoleType.DomainAdmin, RoleType.User})
+public class CreateVMScheduleCmd extends BaseAsyncCreateCmd {
+ public static final String APINAME = "createVMSchedule";
+ public static final Logger s_logger =
Logger.getLogger(CreateVMScheduleCmd.class);
+
+ @Parameter(name = ApiConstants.VIRTUAL_MACHINE_ID, type =
CommandType.UUID, required = true, entityType = UserVmResponse.class,
description = "The ID of the vm")
+ private Long vmId;
+
+ @Parameter(name = ApiConstants.VM_SCHEDULE_DESCRIPTION, type =
CommandType.STRING, required = false, description = "The description of the VM
schedule")
+ private String description;
+
+ @Parameter(name = ApiConstants.VM_SCHEDULE_ACTION, type =
CommandType.STRING, required = true, description = "The action of VM Schedule")
Review Comment:
you may even list such events in the API docs if they are limited (such as
declared in the enum)
##########
api/src/main/java/org/apache/cloudstack/api/ResponseGenerator.java:
##########
@@ -60,76 +72,70 @@
import org.apache.cloudstack.api.response.GuestVlanRangeResponse;
import org.apache.cloudstack.api.response.GuestVlanResponse;
import org.apache.cloudstack.api.response.HostForMigrationResponse;
+
import org.apache.cloudstack.api.response.HostResponse;
import org.apache.cloudstack.api.response.HypervisorCapabilitiesResponse;
+import org.apache.cloudstack.api.response.VlanIpRangeResponse;
import org.apache.cloudstack.api.response.IPAddressResponse;
import org.apache.cloudstack.api.response.ImageStoreResponse;
+import org.apache.cloudstack.api.response.LoadBalancerResponse;
+import org.apache.cloudstack.api.response.LBStickinessResponse;
+import org.apache.cloudstack.api.response.LBHealthCheckResponse;
+import org.apache.cloudstack.api.response.PodResponse;
+import org.apache.cloudstack.api.response.ZoneResponse;
+import org.apache.cloudstack.api.response.VolumeResponse;
import org.apache.cloudstack.api.response.InstanceGroupResponse;
import org.apache.cloudstack.api.response.InternalLoadBalancerElementResponse;
+import org.apache.cloudstack.api.response.StoragePoolResponse;
import org.apache.cloudstack.api.response.IpForwardingRuleResponse;
import org.apache.cloudstack.api.response.IsolationMethodResponse;
-import org.apache.cloudstack.api.response.LBHealthCheckResponse;
-import org.apache.cloudstack.api.response.LBStickinessResponse;
import org.apache.cloudstack.api.response.ListResponse;
-import org.apache.cloudstack.api.response.LoadBalancerResponse;
import org.apache.cloudstack.api.response.ManagementServerResponse;
import org.apache.cloudstack.api.response.NetworkACLItemResponse;
import org.apache.cloudstack.api.response.NetworkACLResponse;
+
+import org.apache.cloudstack.api.response.VpnUsersResponse;
+import org.apache.cloudstack.api.response.RemoteAccessVpnResponse;
+import org.apache.cloudstack.api.response.TemplateResponse;
+import org.apache.cloudstack.api.response.SecurityGroupResponse;
+import org.apache.cloudstack.api.response.TemplatePermissionsResponse;
import org.apache.cloudstack.api.response.NetworkOfferingResponse;
import org.apache.cloudstack.api.response.NetworkPermissionsResponse;
import org.apache.cloudstack.api.response.NetworkResponse;
import org.apache.cloudstack.api.response.NicResponse;
import org.apache.cloudstack.api.response.NicSecondaryIpResponse;
import org.apache.cloudstack.api.response.OvsProviderResponse;
import org.apache.cloudstack.api.response.PhysicalNetworkResponse;
-import org.apache.cloudstack.api.response.PodResponse;
import org.apache.cloudstack.api.response.PortableIpRangeResponse;
import org.apache.cloudstack.api.response.PortableIpResponse;
import org.apache.cloudstack.api.response.PrivateGatewayResponse;
+import org.apache.cloudstack.api.response.ProjectResponse;
+import org.apache.cloudstack.api.response.VpcOfferingResponse;
import org.apache.cloudstack.api.response.ProjectAccountResponse;
import org.apache.cloudstack.api.response.ProjectInvitationResponse;
-import org.apache.cloudstack.api.response.ProjectResponse;
+import org.apache.cloudstack.api.response.SystemVmInstanceResponse;
+import org.apache.cloudstack.api.response.VpcResponse;
+import org.apache.cloudstack.api.response.ServiceResponse;
import org.apache.cloudstack.api.response.ProviderResponse;
import org.apache.cloudstack.api.response.RegionResponse;
-import org.apache.cloudstack.api.response.RemoteAccessVpnResponse;
-import org.apache.cloudstack.api.response.ResourceCountResponse;
import org.apache.cloudstack.api.response.ResourceIconResponse;
-import org.apache.cloudstack.api.response.ResourceLimitResponse;
import org.apache.cloudstack.api.response.ResourceTagResponse;
import org.apache.cloudstack.api.response.RollingMaintenanceResponse;
import org.apache.cloudstack.api.response.RouterHealthCheckResultResponse;
import org.apache.cloudstack.api.response.SSHKeyPairResponse;
-import org.apache.cloudstack.api.response.SecurityGroupResponse;
-import org.apache.cloudstack.api.response.ServiceOfferingResponse;
-import org.apache.cloudstack.api.response.ServiceResponse;
+import org.apache.cloudstack.api.response.StaticRouteResponse;
+import org.apache.cloudstack.api.response.StorageNetworkIpRangeResponse;
+import org.apache.cloudstack.api.response.TrafficTypeResponse;
+import org.apache.cloudstack.api.response.VirtualRouterProviderResponse;
+import org.apache.cloudstack.api.response.Site2SiteVpnGatewayResponse;
import org.apache.cloudstack.api.response.Site2SiteCustomerGatewayResponse;
import org.apache.cloudstack.api.response.Site2SiteVpnConnectionResponse;
-import org.apache.cloudstack.api.response.Site2SiteVpnGatewayResponse;
-import org.apache.cloudstack.api.response.SnapshotPolicyResponse;
-import org.apache.cloudstack.api.response.SnapshotResponse;
import org.apache.cloudstack.api.response.SnapshotScheduleResponse;
-import org.apache.cloudstack.api.response.StaticRouteResponse;
-import org.apache.cloudstack.api.response.StorageNetworkIpRangeResponse;
-import org.apache.cloudstack.api.response.StoragePoolResponse;
-import org.apache.cloudstack.api.response.SystemVmInstanceResponse;
-import org.apache.cloudstack.api.response.SystemVmResponse;
-import org.apache.cloudstack.api.response.TemplatePermissionsResponse;
-import org.apache.cloudstack.api.response.TemplateResponse;
+import org.apache.cloudstack.api.response.UsageRecordResponse;
import org.apache.cloudstack.api.response.TrafficMonitorResponse;
-import org.apache.cloudstack.api.response.TrafficTypeResponse;
+import org.apache.cloudstack.api.response.VMSnapshotResponse;
import org.apache.cloudstack.api.response.UpgradeRouterTemplateResponse;
-import org.apache.cloudstack.api.response.UsageRecordResponse;
import org.apache.cloudstack.api.response.UserDataResponse;
-import org.apache.cloudstack.api.response.UserResponse;
-import org.apache.cloudstack.api.response.UserVmResponse;
-import org.apache.cloudstack.api.response.VMSnapshotResponse;
-import org.apache.cloudstack.api.response.VirtualRouterProviderResponse;
-import org.apache.cloudstack.api.response.VlanIpRangeResponse;
-import org.apache.cloudstack.api.response.VolumeResponse;
-import org.apache.cloudstack.api.response.VpcOfferingResponse;
-import org.apache.cloudstack.api.response.VpcResponse;
-import org.apache.cloudstack.api.response.VpnUsersResponse;
Review Comment:
nit - imports are not sorted or grouped logically, pl check/fix your IDE
settings.
##########
api/src/main/java/org/apache/cloudstack/api/command/user/vmschedule/CreateVMScheduleCmd.java:
##########
@@ -0,0 +1,142 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package org.apache.cloudstack.api.command.user.vmschedule;
+
+import com.cloud.event.EventTypes;
+import com.cloud.exception.ResourceAllocationException;
+import com.cloud.user.Account;
+import com.cloud.utils.exception.CloudRuntimeException;
+import com.cloud.vm.VirtualMachine;
+import com.cloud.vm.schedule.VMSchedule;
+import org.apache.cloudstack.acl.RoleType;
+
+import org.apache.cloudstack.api.APICommand;
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.BaseAsyncCreateCmd;
+import org.apache.cloudstack.api.BaseCmd;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.ApiErrorCode;
+import org.apache.cloudstack.api.response.UserVmResponse;
+import org.apache.cloudstack.api.response.VMScheduleResponse;
+import org.apache.cloudstack.context.CallContext;
+import org.apache.log4j.Logger;
+
+@APICommand(name = CreateVMScheduleCmd.APINAME,
+ description = "Creates Schedule for a VM",
+ responseObject = VMScheduleResponse.class,
+ since = "4.19.0",
+ entityType = {VMSchedule.class},
+ requestHasSensitiveInfo = false, responseHasSensitiveInfo = false,
+ authorized = {RoleType.Admin, RoleType.ResourceAdmin,
RoleType.DomainAdmin, RoleType.User})
+public class CreateVMScheduleCmd extends BaseAsyncCreateCmd {
+ public static final String APINAME = "createVMSchedule";
+ public static final Logger s_logger =
Logger.getLogger(CreateVMScheduleCmd.class);
+
+ @Parameter(name = ApiConstants.VIRTUAL_MACHINE_ID, type =
CommandType.UUID, required = true, entityType = UserVmResponse.class,
description = "The ID of the vm")
+ private Long vmId;
+
+ @Parameter(name = ApiConstants.VM_SCHEDULE_DESCRIPTION, type =
CommandType.STRING, required = false, description = "The description of the VM
schedule")
+ private String description;
+
+ @Parameter(name = ApiConstants.VM_SCHEDULE_ACTION, type =
CommandType.STRING, required = true, description = "The action of VM Schedule")
+ private String action;
+
+ @Parameter(name = ApiConstants.VM_SCHEDULE_PERIOD, type =
CommandType.STRING, required = true, description = "The period of VM Schedule")
Review Comment:
Needs better explanation, if this is cron like string.
##########
api/src/main/java/org/apache/cloudstack/api/command/user/vmschedule/DisableVMScheduleCmd.java:
##########
@@ -0,0 +1,83 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package org.apache.cloudstack.api.command.user.vmschedule;
+
+import com.cloud.event.EventTypes;
+import com.cloud.user.Account;
+import com.cloud.vm.schedule.VMSchedule;
+import org.apache.cloudstack.acl.RoleType;
+import org.apache.cloudstack.acl.SecurityChecker;
+import org.apache.cloudstack.api.ACL;
+import org.apache.cloudstack.api.APICommand;
+import org.apache.cloudstack.api.BaseAsyncCmd;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.context.CallContext;
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.ApiErrorCode;
+import org.apache.cloudstack.api.response.SuccessResponse;
+import org.apache.cloudstack.api.response.VMScheduleResponse;
+import org.apache.log4j.Logger;
+
+@APICommand(name = DisableVMScheduleCmd.APINAME, description = "Updates a VM
Schedule", responseObject = SuccessResponse.class,
+ requestHasSensitiveInfo = false, responseHasSensitiveInfo =
false,since = "4.19.0",
Review Comment:
nit - space between params and comma
##########
api/src/main/java/org/apache/cloudstack/api/command/user/vmschedule/ListVMScheduleCmd.java:
##########
@@ -0,0 +1,85 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package org.apache.cloudstack.api.command.user.vmschedule;
+
+import com.cloud.vm.schedule.VMSchedule;
+import org.apache.cloudstack.acl.RoleType;
+import org.apache.cloudstack.api.APICommand;
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.BaseListCmd;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.response.ListResponse;
+import org.apache.cloudstack.api.response.UserVmResponse;
+import org.apache.cloudstack.api.response.VMScheduleResponse;
+import org.apache.log4j.Logger;
+
+import java.util.ArrayList;
+import java.util.List;
+
+@APICommand(name = ListVMScheduleCmd.APINAME,
+ description = "Lists Schedules for a VM",
+ responseObject = VMScheduleResponse.class,
+ since = "4.19.0",
+ requestHasSensitiveInfo = false, responseHasSensitiveInfo = false,
+ authorized = {RoleType.Admin, RoleType.ResourceAdmin,
RoleType.DomainAdmin, RoleType.User})
+public class ListVMScheduleCmd extends BaseListCmd {
+ public static final String APINAME = "listVMSchedules";
+ public static final Logger s_logger =
Logger.getLogger(ListVMScheduleCmd.class);
+
+ @Parameter(name = ApiConstants.VM_SCHEDULE_ID, type = CommandType.UUID,
entityType = VMScheduleResponse.class, description = "The ID of the VM
schedule")
+ private Long id;
+
+ @Parameter(name=ApiConstants.VM_SCHEDULE_IDS, type=CommandType.LIST,
collectionType=CommandType.UUID, entityType=VMScheduleResponse.class,
description="the IDs of the vm schedule, mutually exclusive with vmscheduleid",
since = "4.9")
+ private List<Long> ids;
+
Review Comment:
suggestion: simply `ids` as param name would do.
##########
api/src/main/java/org/apache/cloudstack/api/command/user/vmschedule/UpdateVMScheduleCmd.java:
##########
@@ -0,0 +1,121 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package org.apache.cloudstack.api.command.user.vmschedule;
+
+import com.cloud.event.EventTypes;
+import com.cloud.user.Account;
+import com.cloud.vm.schedule.VMSchedule;
+import org.apache.cloudstack.acl.RoleType;
+import org.apache.cloudstack.api.APICommand;
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.BaseAsyncCmd;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.response.VMScheduleResponse;
+import org.apache.cloudstack.context.CallContext;
+import org.apache.cloudstack.api.ApiErrorCode;
+import org.apache.log4j.Logger;
+
+
+@APICommand(name = UpdateVMScheduleCmd.APINAME,
+ description = "Update Schedule for a VM",
+ responseObject = VMScheduleResponse.class,
+ entityType = {VMSchedule.class},
+ since = "4.19.0",
+ requestHasSensitiveInfo = false, responseHasSensitiveInfo = false,
+ authorized = {RoleType.Admin, RoleType.ResourceAdmin,
RoleType.DomainAdmin, RoleType.User})
+public class UpdateVMScheduleCmd extends BaseAsyncCmd {
+ public static final String APINAME = "updateVMSchedule";
+ public static final Logger s_logger =
Logger.getLogger(UpdateVMScheduleCmd.class);
Review Comment:
nit - same as before on s_logger
##########
api/src/main/java/org/apache/cloudstack/api/ApiConstants.java:
##########
@@ -1020,6 +1020,16 @@ public class ApiConstants {
public static final String PRIVATE_MTU = "privatemtu";
public static final String MTU = "mtu";
public static final String LIST_APIS = "listApis";
+ public static final String VM_SCHEDULE_DESCRIPTION = "description";
+ public static final String VM_SCHEDULE_ACTION = "action";
+ public static final String VM_SCHEDULE_PERIOD = "period";
+ public static final String VM_SCHEDULE_TAG = "tag";
+ public static final String VM_SCHEDULE_TIMEZONE = "timezone";
+ public static final String VM_SCHEDULE_ID = "vmscheduleid";
+
+ public static final String VM_SCHEDULE_IDS = "vmscheduleids";
Review Comment:
suggestion - such a param name isn't necessary when called for an API that's
related to VM Schedule, however, this can be useful if the params are not used
with VM Scheduler APIs.
##########
api/src/main/java/org/apache/cloudstack/api/BaseCmd.java:
##########
@@ -185,6 +186,8 @@ public static enum CommandType {
@Inject
public VMSnapshotService _vmSnapshotService;
@Inject
+ public VMScheduleManager vmScheduleManager;
Review Comment:
Avoid injecting it here and making BaseCmd even more bulkier to instatiate.
Unless there is a general-purpose requirement, pl declare on VM Scheduler
feature related API command classes instead.
##########
server/src/main/java/com/cloud/vm/schedule/VMScheduleManagerImpl.java:
##########
@@ -0,0 +1,295 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package com.cloud.vm.schedule;
+
+
Review Comment:
nit - extra new line
##########
api/src/main/java/org/apache/cloudstack/api/command/user/vmschedule/CreateVMScheduleCmd.java:
##########
@@ -0,0 +1,142 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package org.apache.cloudstack.api.command.user.vmschedule;
+
+import com.cloud.event.EventTypes;
+import com.cloud.exception.ResourceAllocationException;
+import com.cloud.user.Account;
+import com.cloud.utils.exception.CloudRuntimeException;
+import com.cloud.vm.VirtualMachine;
+import com.cloud.vm.schedule.VMSchedule;
+import org.apache.cloudstack.acl.RoleType;
+
+import org.apache.cloudstack.api.APICommand;
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.BaseAsyncCreateCmd;
+import org.apache.cloudstack.api.BaseCmd;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.ApiErrorCode;
+import org.apache.cloudstack.api.response.UserVmResponse;
+import org.apache.cloudstack.api.response.VMScheduleResponse;
+import org.apache.cloudstack.context.CallContext;
+import org.apache.log4j.Logger;
+
+@APICommand(name = CreateVMScheduleCmd.APINAME,
+ description = "Creates Schedule for a VM",
+ responseObject = VMScheduleResponse.class,
+ since = "4.19.0",
+ entityType = {VMSchedule.class},
+ requestHasSensitiveInfo = false, responseHasSensitiveInfo = false,
+ authorized = {RoleType.Admin, RoleType.ResourceAdmin,
RoleType.DomainAdmin, RoleType.User})
+public class CreateVMScheduleCmd extends BaseAsyncCreateCmd {
+ public static final String APINAME = "createVMSchedule";
+ public static final Logger s_logger =
Logger.getLogger(CreateVMScheduleCmd.class);
+
+ @Parameter(name = ApiConstants.VIRTUAL_MACHINE_ID, type =
CommandType.UUID, required = true, entityType = UserVmResponse.class,
description = "The ID of the vm")
+ private Long vmId;
+
+ @Parameter(name = ApiConstants.VM_SCHEDULE_DESCRIPTION, type =
CommandType.STRING, required = false, description = "The description of the VM
schedule")
+ private String description;
+
+ @Parameter(name = ApiConstants.VM_SCHEDULE_ACTION, type =
CommandType.STRING, required = true, description = "The action of VM Schedule")
+ private String action;
+
+ @Parameter(name = ApiConstants.VM_SCHEDULE_PERIOD, type =
CommandType.STRING, required = true, description = "The period of VM Schedule")
+ private String period;
+
+ @Parameter(name = ApiConstants.VM_SCHEDULE_TAG, type = CommandType.STRING,
required = false, description = "The tag of VM Schedule")
Review Comment:
Needs better description for users, how they should use it? Is this
following a macro rule; what happens when the tag string is provided.
##########
server/src/main/java/com/cloud/vm/schedule/VMScheduleManagerImpl.java:
##########
@@ -0,0 +1,295 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package com.cloud.vm.schedule;
+
+
+import com.cloud.event.ActionEvent;
+import com.cloud.event.EventTypes;
+import com.cloud.exception.InvalidParameterValueException;
+import com.cloud.utils.ListUtils;
+import com.cloud.utils.component.ManagerBase;
+import com.cloud.utils.component.PluggableService;
+import com.cloud.utils.exception.CloudRuntimeException;
+import com.cloud.vm.VMInstanceVO;
+import com.cloud.vm.VirtualMachineManager;
+import com.cloud.vm.dao.VMInstanceDao;
+import com.cloud.vm.schedule.dao.VMScheduleDao;
+import org.apache.cloudstack.api.command.user.vmschedule.CreateVMScheduleCmd;
+import org.apache.cloudstack.api.command.user.vmschedule.ListVMScheduleCmd;
+import org.apache.cloudstack.api.command.user.vmschedule.UpdateVMScheduleCmd;
+import org.apache.cloudstack.api.command.user.vmschedule.DeleteVMScheduleCmd;
+import org.apache.cloudstack.api.command.user.vmschedule.EnableVMScheduleCmd;
+import org.apache.cloudstack.api.command.user.vmschedule.DisableVMScheduleCmd;
+import org.apache.cloudstack.framework.config.ConfigKey;
+import org.apache.cloudstack.framework.config.Configurable;
+import org.apache.cloudstack.framework.jobs.AsyncJobManager;
+import org.apache.cloudstack.managed.context.ManagedContextRunnable;
+import org.apache.cloudstack.poll.BackgroundPollManager;
+import org.apache.cloudstack.poll.BackgroundPollTask;
+import org.apache.log4j.Logger;
+import org.springframework.stereotype.Component;
+
+import javax.inject.Inject;
+import javax.naming.ConfigurationException;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+
+@Component
+public class VMScheduleManagerImpl extends ManagerBase implements
VMScheduleManager, Configurable, PluggableService {
+ public static final Logger s_logger =
Logger.getLogger(VMScheduleManagerImpl.class);
+
+ @Inject
+ private VMScheduleDao vmScheduleDao;
+
+ @Inject
+ private VirtualMachineManager vmManager;
+
+ @Inject
+ private BackgroundPollManager backgroundPollManager;
+
+ @Inject
+ private AsyncJobManager asyncJobManager;
+
+ @Inject
+ private VMInstanceDao vmInstanceDao;
+
+ private static final ConfigKey<Integer> VMSchedulerInterval = new
ConfigKey<>("Advanced", Integer.class,
+ "gc.interval", "120",
Review Comment:
nit - should this be renamed as vm.scheduler.interval? gc.interval might be
not correct to name the global setting s and conflict with any other existing
settings
##########
server/src/main/java/com/cloud/vm/schedule/VMScheduleManagerImpl.java:
##########
@@ -0,0 +1,295 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package com.cloud.vm.schedule;
+
+
+import com.cloud.event.ActionEvent;
+import com.cloud.event.EventTypes;
+import com.cloud.exception.InvalidParameterValueException;
+import com.cloud.utils.ListUtils;
+import com.cloud.utils.component.ManagerBase;
+import com.cloud.utils.component.PluggableService;
+import com.cloud.utils.exception.CloudRuntimeException;
+import com.cloud.vm.VMInstanceVO;
+import com.cloud.vm.VirtualMachineManager;
+import com.cloud.vm.dao.VMInstanceDao;
+import com.cloud.vm.schedule.dao.VMScheduleDao;
+import org.apache.cloudstack.api.command.user.vmschedule.CreateVMScheduleCmd;
+import org.apache.cloudstack.api.command.user.vmschedule.ListVMScheduleCmd;
+import org.apache.cloudstack.api.command.user.vmschedule.UpdateVMScheduleCmd;
+import org.apache.cloudstack.api.command.user.vmschedule.DeleteVMScheduleCmd;
+import org.apache.cloudstack.api.command.user.vmschedule.EnableVMScheduleCmd;
+import org.apache.cloudstack.api.command.user.vmschedule.DisableVMScheduleCmd;
+import org.apache.cloudstack.framework.config.ConfigKey;
+import org.apache.cloudstack.framework.config.Configurable;
+import org.apache.cloudstack.framework.jobs.AsyncJobManager;
+import org.apache.cloudstack.managed.context.ManagedContextRunnable;
+import org.apache.cloudstack.poll.BackgroundPollManager;
+import org.apache.cloudstack.poll.BackgroundPollTask;
+import org.apache.log4j.Logger;
+import org.springframework.stereotype.Component;
+
+import javax.inject.Inject;
+import javax.naming.ConfigurationException;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+
+@Component
+public class VMScheduleManagerImpl extends ManagerBase implements
VMScheduleManager, Configurable, PluggableService {
+ public static final Logger s_logger =
Logger.getLogger(VMScheduleManagerImpl.class);
+
+ @Inject
+ private VMScheduleDao vmScheduleDao;
+
+ @Inject
+ private VirtualMachineManager vmManager;
+
+ @Inject
+ private BackgroundPollManager backgroundPollManager;
+
+ @Inject
+ private AsyncJobManager asyncJobManager;
+
+ @Inject
+ private VMInstanceDao vmInstanceDao;
+
+ private static final ConfigKey<Integer> VMSchedulerInterval = new
ConfigKey<>("Advanced", Integer.class,
+ "gc.interval", "120",
+ "The interval at which background tasks runs in milliseconds",
false);
+
+ @Override
+ public boolean start() {
+
+ return true;
+ }
+
+ @Override
+ public boolean stop() {
+ return true;
+ }
+
+ @Override
+ public String getConfigComponentName() {
+ return VMScheduleManager.class.getSimpleName();
+ }
+
+ @Override
+ public ConfigKey<?>[] getConfigKeys() {
+ return new ConfigKey<?>[] {
+ VMSchedulerInterval
+ };
+ }
+
+ @Override
+ public boolean configure(final String name, final Map<String, Object>
params) throws ConfigurationException {
+ backgroundPollManager.submitTask(new
VMScheduleManagerImpl.VMScheduleBackgroundTask(this));
+ return true;
+ }
+
+ @Override
+ public List<Class<?>> getCommands() {
+ final List<Class<?>> cmdList = new ArrayList<>();
+ cmdList.add(CreateVMScheduleCmd.class);
+ cmdList.add(ListVMScheduleCmd.class);
+ cmdList.add(UpdateVMScheduleCmd.class);
+ cmdList.add(DeleteVMScheduleCmd.class);
+ cmdList.add(EnableVMScheduleCmd.class);
+ cmdList.add(DisableVMScheduleCmd.class);
+ cmdList.add(UpdateVMScheduleCmd.class);
+ return cmdList;
+ }
+
+ @Override
+ public VMSchedule findVMSchedule(Long id) {
+ if (id == null || id < 1L) {
+ if (s_logger.isTraceEnabled()) {
+ s_logger.trace(String.format("VMSchedule ID is invalid [%s]",
id));
+ return null;
+ }
+ }
+
+ VMSchedule vmSchedule = vmScheduleDao.findById(id);
+ if (vmSchedule == null) {
+ if(s_logger.isTraceEnabled()) {
+ s_logger.trace(String.format("VmSchedule ID not found
[id=%s]", id));
+ return null;
+ }
+ }
+
+ return vmSchedule;
+ }
+
+ @Override
+ @ActionEvent(eventType = EventTypes.EVENT_VMSCHEDULE_CREATE,
eventDescription = "creating vm schedule", async = true)
+ public VMSchedule createVMSchedule(Long vmId, String description, String
action, String period, String tag, String timezone) {
+ VMScheduleVO vmScheduleVo = new VMScheduleVO(vmId, description,
action, period, tag, timezone);
+ VMSchedule vmSchedule = vmScheduleDao.persist(vmScheduleVo);
+ if (vmSchedule == null) {
+ throw new CloudRuntimeException("Failed to create schedule for vm:
" + vmId);
+ }
+
+ return vmSchedule;
+ }
+
+ @Override
+ public List<VMSchedule> listVMSchedules(ListVMScheduleCmd cmd) {
+ if(cmd.getId() != null) {
+ VMSchedule vmSchedule = findVMSchedule(cmd.getId());
+ List<VMSchedule> arr = new ArrayList<>();
+ arr.add(vmSchedule);
+ return arr;
+ }
+
+ List<? extends VMSchedule> vmSchedules= vmScheduleDao.listAll();
+ return ListUtils.toListOfInterface(vmSchedules);
+ }
+
+ @Override
+ @ActionEvent(eventType = EventTypes.EVENT_VMSCHEDULE_DELETE,
eventDescription = "deleting VM Schedule")
+ public boolean deleteVMSchedule(Long vmScheduleId) {
+ VMSchedule vmSchedule = vmScheduleDao.findById(vmScheduleId);
+ if (vmSchedule == null) {
+ throw new InvalidParameterValueException("unable to find the vm
schedule with id " + vmScheduleId);
+ }
+
+ return vmScheduleDao.remove(vmSchedule.getId());
+ }
+
+ @Override
+ @ActionEvent(eventType = EventTypes.EVENT_VMSCHEDULE_ENABLE,
eventDescription = "enable VM Schedule")
+ public boolean enableVMSchedule(Long vmScheduleId) {
+ VMScheduleVO vmSchedule = vmScheduleDao.findById(vmScheduleId);
+ if (vmSchedule == null) {
+ throw new InvalidParameterValueException("unable to find the vm
schedule with id " + vmScheduleId);
+ }
+
+ vmSchedule.setState(VMSchedule.State.Enabled);
+ boolean updateResult = vmScheduleDao.update(vmSchedule.getId(),
vmSchedule);
+
+ return updateResult;
+ }
+
+ @Override
+ @ActionEvent(eventType = EventTypes.EVENT_VMSCHEDULE_DISABLE,
eventDescription = "disable VM Schedule")
+ public boolean disableVMSchedule(Long vmScheduleId) {
+ VMScheduleVO vmSchedule = vmScheduleDao.findById(vmScheduleId);
+ if (vmSchedule == null) {
+ throw new InvalidParameterValueException("unable to find the vm
schedule with id " + vmScheduleId);
+ }
+
+ vmSchedule.setState(VMSchedule.State.Disabled);
+ boolean updateResult = vmScheduleDao.update(vmSchedule.getId(),
vmSchedule);
+
+ return updateResult;
+ }
+
+ @Override
+ @ActionEvent(eventType = EventTypes.EVENT_VMSCHEDULE_UPDATE,
eventDescription = "update VM Schedule")
+ public VMSchedule updateVMSchedule(UpdateVMScheduleCmd cmd) {
+ VMScheduleVO vmSchedule = vmScheduleDao.findById(cmd.getId());
+ if (vmSchedule == null) {
+ throw new InvalidParameterValueException("unable to find the vm
schedule with id " + cmd.getId());
+ }
+ String description = cmd.getDescription();
+ String period = cmd.getPeriod();
+ String action = cmd.getAction();
+ String tag = cmd.getTag();
+ String timezone = cmd.getTimezone();
+
+ if (vmSchedule.getState() == VMSchedule.State.Disabled) {
+ if (description != null)
+ vmSchedule.setDescription(description);
+ if (period != null)
+ vmSchedule.setPeriod(period);
+ if (action != null)
+ vmSchedule.setAction(action);
+ if (tag != null)
+ vmSchedule.setTag(tag);
+ if (timezone != null)
+ vmSchedule.setTimezone(timezone);
+
+ vmScheduleDao.update(vmSchedule.getId(), vmSchedule);
+ } else {
+ throw new InvalidParameterValueException("Enable the state of VM
Schedule before updating it");
+ }
+ return vmSchedule;
+ }
+
+ public static final class VMScheduleBackgroundTask extends
ManagedContextRunnable implements BackgroundPollTask {
+ private VMScheduleManagerImpl serviceImpl;
+
+ public VMScheduleBackgroundTask(VMScheduleManagerImpl serviceImpl) {
+ this.serviceImpl = serviceImpl;
+ }
+
+ private void scheduleActionOnVM(String action, VMSchedule.State state,
String uuid, String period) {
+
+ serviceImpl.vmManager.start(uuid, null);
+ }
+
+ private Boolean matchPeriodWithCurrentTimestamp(String period){
+ Date currentTimestamp = new Date();
+ String[] periodParts = period.split(" ");
+
+
+ return true;
+ }
+
+ private void getVmSchedulesToBeExecuted() {
+
+ }
+
+ @Override
+ protected void runInContext() {
+ try {
+ if (s_logger.isTraceEnabled()) {
+ s_logger.trace("VM Scheduler GC task is running...");
+ }
+ // Date currentTimestamp = new Date();
+ for (final VMScheduleVO vmSchedule
:serviceImpl.vmScheduleDao.listAll()) {
+ VMInstanceVO vmInstance =
serviceImpl.vmInstanceDao.findById(vmSchedule.getVmId());
+ scheduleActionOnVM(vmSchedule.getAction(),
vmSchedule.getState(), vmInstance.getUuid(), vmSchedule.getPeriod());
+ }
+
+ /*
+ Long accountId= CallContext.current().getCallingAccountId();
+ List<VMInstanceVO> vmInstanceVOList =
serviceImpl.vmInstanceDao.listByAccountId(accountId);
+ for (final VMInstanceVO vmInstance : vmInstanceVOList) {
+ List<VMScheduleVO> vmScheduleVOList =
serviceImpl.vmScheduleDao.findByVm(vmInstance.getId());
+ if (vmScheduleVOList != null) {
+ for (final VMScheduleVO vmSchedule : vmScheduleVOList)
{
+ scheduleActionOnVM(vmSchedule.getAction(),
vmSchedule.getState(), vmInstance.getUuid(), vmSchedule.getPeriod());
+ }
+ }
+ }
+ */
+ } catch (final Throwable t) {
+ s_logger.error("Error trying to run VM Scheduler GC task", t);
+ }
+ }
+
+ @Override
+ public Long getDelay() {
+ // In Milliseconds
+ return VMSchedulerInterval.value() * 1000L;
Review Comment:
suggestion - need to check if you must multiply by 1000L (or if background
poll manager does it already?)
##########
api/src/main/java/org/apache/cloudstack/api/command/user/vmschedule/CreateVMScheduleCmd.java:
##########
@@ -0,0 +1,142 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package org.apache.cloudstack.api.command.user.vmschedule;
+
+import com.cloud.event.EventTypes;
+import com.cloud.exception.ResourceAllocationException;
+import com.cloud.user.Account;
+import com.cloud.utils.exception.CloudRuntimeException;
+import com.cloud.vm.VirtualMachine;
+import com.cloud.vm.schedule.VMSchedule;
+import org.apache.cloudstack.acl.RoleType;
+
+import org.apache.cloudstack.api.APICommand;
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.BaseAsyncCreateCmd;
+import org.apache.cloudstack.api.BaseCmd;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.ApiErrorCode;
+import org.apache.cloudstack.api.response.UserVmResponse;
+import org.apache.cloudstack.api.response.VMScheduleResponse;
+import org.apache.cloudstack.context.CallContext;
+import org.apache.log4j.Logger;
+
+@APICommand(name = CreateVMScheduleCmd.APINAME,
+ description = "Creates Schedule for a VM",
+ responseObject = VMScheduleResponse.class,
+ since = "4.19.0",
+ entityType = {VMSchedule.class},
+ requestHasSensitiveInfo = false, responseHasSensitiveInfo = false,
+ authorized = {RoleType.Admin, RoleType.ResourceAdmin,
RoleType.DomainAdmin, RoleType.User})
+public class CreateVMScheduleCmd extends BaseAsyncCreateCmd {
+ public static final String APINAME = "createVMSchedule";
+ public static final Logger s_logger =
Logger.getLogger(CreateVMScheduleCmd.class);
+
+ @Parameter(name = ApiConstants.VIRTUAL_MACHINE_ID, type =
CommandType.UUID, required = true, entityType = UserVmResponse.class,
description = "The ID of the vm")
Review Comment:
nit - vm -> VM (abbreviations generally capitalised)
##########
api/src/main/java/org/apache/cloudstack/api/command/user/vmschedule/DisableVMScheduleCmd.java:
##########
@@ -0,0 +1,83 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package org.apache.cloudstack.api.command.user.vmschedule;
+
+import com.cloud.event.EventTypes;
+import com.cloud.user.Account;
+import com.cloud.vm.schedule.VMSchedule;
+import org.apache.cloudstack.acl.RoleType;
+import org.apache.cloudstack.acl.SecurityChecker;
+import org.apache.cloudstack.api.ACL;
+import org.apache.cloudstack.api.APICommand;
+import org.apache.cloudstack.api.BaseAsyncCmd;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.context.CallContext;
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.ApiErrorCode;
+import org.apache.cloudstack.api.response.SuccessResponse;
+import org.apache.cloudstack.api.response.VMScheduleResponse;
+import org.apache.log4j.Logger;
+
+@APICommand(name = DisableVMScheduleCmd.APINAME, description = "Updates a VM
Schedule", responseObject = SuccessResponse.class,
Review Comment:
nit - indent fix needed
##########
api/src/main/java/org/apache/cloudstack/api/command/user/vmschedule/DisableVMScheduleCmd.java:
##########
@@ -0,0 +1,83 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package org.apache.cloudstack.api.command.user.vmschedule;
+
+import com.cloud.event.EventTypes;
+import com.cloud.user.Account;
+import com.cloud.vm.schedule.VMSchedule;
+import org.apache.cloudstack.acl.RoleType;
+import org.apache.cloudstack.acl.SecurityChecker;
+import org.apache.cloudstack.api.ACL;
+import org.apache.cloudstack.api.APICommand;
+import org.apache.cloudstack.api.BaseAsyncCmd;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.context.CallContext;
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.ApiErrorCode;
+import org.apache.cloudstack.api.response.SuccessResponse;
+import org.apache.cloudstack.api.response.VMScheduleResponse;
+import org.apache.log4j.Logger;
+
+@APICommand(name = DisableVMScheduleCmd.APINAME, description = "Updates a VM
Schedule", responseObject = SuccessResponse.class,
+ requestHasSensitiveInfo = false, responseHasSensitiveInfo =
false,since = "4.19.0",
+ entityType = {VMSchedule.class},
Review Comment:
question - why do we need entityType in APICommand annotation, where/how is
it used?
##########
api/src/main/java/org/apache/cloudstack/api/command/user/vmschedule/ListVMScheduleCmd.java:
##########
@@ -0,0 +1,85 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package org.apache.cloudstack.api.command.user.vmschedule;
+
+import com.cloud.vm.schedule.VMSchedule;
+import org.apache.cloudstack.acl.RoleType;
+import org.apache.cloudstack.api.APICommand;
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.BaseListCmd;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.response.ListResponse;
+import org.apache.cloudstack.api.response.UserVmResponse;
+import org.apache.cloudstack.api.response.VMScheduleResponse;
+import org.apache.log4j.Logger;
+
+import java.util.ArrayList;
+import java.util.List;
+
+@APICommand(name = ListVMScheduleCmd.APINAME,
+ description = "Lists Schedules for a VM",
+ responseObject = VMScheduleResponse.class,
+ since = "4.19.0",
+ requestHasSensitiveInfo = false, responseHasSensitiveInfo = false,
+ authorized = {RoleType.Admin, RoleType.ResourceAdmin,
RoleType.DomainAdmin, RoleType.User})
+public class ListVMScheduleCmd extends BaseListCmd {
+ public static final String APINAME = "listVMSchedules";
+ public static final Logger s_logger =
Logger.getLogger(ListVMScheduleCmd.class);
+
+ @Parameter(name = ApiConstants.VM_SCHEDULE_ID, type = CommandType.UUID,
entityType = VMScheduleResponse.class, description = "The ID of the VM
schedule")
Review Comment:
suggestion: simply `id` as param name would do.
##########
api/src/main/java/org/apache/cloudstack/api/command/user/vmschedule/UpdateVMScheduleCmd.java:
##########
@@ -0,0 +1,121 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package org.apache.cloudstack.api.command.user.vmschedule;
+
+import com.cloud.event.EventTypes;
+import com.cloud.user.Account;
+import com.cloud.vm.schedule.VMSchedule;
+import org.apache.cloudstack.acl.RoleType;
+import org.apache.cloudstack.api.APICommand;
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.BaseAsyncCmd;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.response.VMScheduleResponse;
+import org.apache.cloudstack.context.CallContext;
+import org.apache.cloudstack.api.ApiErrorCode;
+import org.apache.log4j.Logger;
+
+
Review Comment:
nit - extra new line
##########
engine/schema/src/main/java/com/cloud/vm/schedule/dao/VMScheduleDao.java:
##########
@@ -0,0 +1,27 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package com.cloud.vm.schedule.dao;
+
+import com.cloud.utils.db.GenericDao;
+import com.cloud.vm.schedule.VMScheduleVO;
+import java.util.List;
+
+public interface VMScheduleDao extends GenericDao<VMScheduleVO, Long> {
+
+ List<VMScheduleVO> findByVm(Long vmId);
Review Comment:
suggestion - a helper method to find the next schedule action based on
current time could be useful
##########
api/src/main/java/org/apache/cloudstack/api/APICommand.java:
##########
@@ -50,4 +49,5 @@
RoleType[] authorized() default {};
Class<?>[] entityType() default {};
+
Review Comment:
nit - still see newline changes in `APICommand`
##########
server/src/main/java/com/cloud/vm/schedule/VMScheduleManagerImpl.java:
##########
@@ -0,0 +1,295 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package com.cloud.vm.schedule;
+
+
+import com.cloud.event.ActionEvent;
+import com.cloud.event.EventTypes;
+import com.cloud.exception.InvalidParameterValueException;
+import com.cloud.utils.ListUtils;
+import com.cloud.utils.component.ManagerBase;
+import com.cloud.utils.component.PluggableService;
+import com.cloud.utils.exception.CloudRuntimeException;
+import com.cloud.vm.VMInstanceVO;
+import com.cloud.vm.VirtualMachineManager;
+import com.cloud.vm.dao.VMInstanceDao;
+import com.cloud.vm.schedule.dao.VMScheduleDao;
+import org.apache.cloudstack.api.command.user.vmschedule.CreateVMScheduleCmd;
+import org.apache.cloudstack.api.command.user.vmschedule.ListVMScheduleCmd;
+import org.apache.cloudstack.api.command.user.vmschedule.UpdateVMScheduleCmd;
+import org.apache.cloudstack.api.command.user.vmschedule.DeleteVMScheduleCmd;
+import org.apache.cloudstack.api.command.user.vmschedule.EnableVMScheduleCmd;
+import org.apache.cloudstack.api.command.user.vmschedule.DisableVMScheduleCmd;
+import org.apache.cloudstack.framework.config.ConfigKey;
+import org.apache.cloudstack.framework.config.Configurable;
+import org.apache.cloudstack.framework.jobs.AsyncJobManager;
+import org.apache.cloudstack.managed.context.ManagedContextRunnable;
+import org.apache.cloudstack.poll.BackgroundPollManager;
+import org.apache.cloudstack.poll.BackgroundPollTask;
+import org.apache.log4j.Logger;
+import org.springframework.stereotype.Component;
+
+import javax.inject.Inject;
+import javax.naming.ConfigurationException;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+
+@Component
Review Comment:
nit - `@Component` isn't needed, if you've declared this explicitly as a
bean in one of the spring context xmls
##########
api/src/main/java/org/apache/cloudstack/api/command/user/vmschedule/CreateVMScheduleCmd.java:
##########
@@ -0,0 +1,73 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package org.apache.cloudstack.api.command.user.vmschedule;
+
+import com.cloud.event.EventTypes;
+import com.cloud.exception.ResourceAllocationException;
+import com.cloud.user.Account;
+import org.apache.cloudstack.acl.RoleType;
+import org.apache.cloudstack.api.APICommand;
+import org.apache.cloudstack.api.BaseAsyncCreateCmd;
+import org.apache.cloudstack.api.BaseCmd;
+import org.apache.cloudstack.api.response.VMScheduleResponse;
+import org.apache.log4j.Logger;
+
+@APICommand(name = CreateVMScheduleCmd.APINAME,
+ description = "Creates Schedule for a VM",
+ responseObject = VMScheduleResponse.class,
+ since = "4.18.0",
+ requestHasSensitiveInfo = false, responseHasSensitiveInfo = false,
+ authorized = {RoleType.Admin, RoleType.ResourceAdmin,
RoleType.DomainAdmin, RoleType.User})
+public class CreateVMScheduleCmd extends BaseAsyncCreateCmd {
+ public static final String APINAME = "createVMSchedule";
Review Comment:
I haven't been following generic changes wrt API implementation if there's a
new pattern we should use that. @GutoVeronezi if there's a new agreed policy
feel free to raise a PR to
https://github.com/shapeblue/hackerbook/blob/main/hack/api.md and discuss on
dev@ML (if not already discussed). Thanks.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]