-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Refactors VM Schedule to make it more generic & add option to schedule min & max for autoscaling groups #13148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
vishesh92
wants to merge
7
commits into
apache:main
Choose a base branch
from
shapeblue:scheduled-asg-actions
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9f79df6
refactor vmschedule to make it more generic and add new commands for it
vishesh92 f0050ff
fixup
vishesh92 0d5949d
update marvin tests to use the new APIs
vishesh92 925c9ea
Update UI to use new APIs
vishesh92 20c3eaa
minor fixups
vishesh92 80f4b0d
Add support scheduling min & max for autoscaling groups
vishesh92 ad2c294
Add marvin test for ASG
vishesh92 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
132 changes: 132 additions & 0 deletions
132
.../main/java/org/apache/cloudstack/api/command/user/schedule/CreateResourceScheduleCmd.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,132 @@ | ||
| // 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.schedule; | ||
|
|
||
| import com.cloud.exception.InvalidParameterValueException; | ||
| import org.apache.cloudstack.acl.RoleType; | ||
| import org.apache.cloudstack.api.APICommand; | ||
| import org.apache.cloudstack.api.ApiCommandResourceType; | ||
| import org.apache.cloudstack.api.ApiConstants; | ||
| import org.apache.cloudstack.api.BaseCmd; | ||
| import org.apache.cloudstack.api.Parameter; | ||
| import org.apache.cloudstack.api.response.ResourceScheduleResponse; | ||
| import org.apache.cloudstack.context.CallContext; | ||
| import org.apache.cloudstack.schedule.ResourceScheduleManager; | ||
| import org.apache.commons.lang3.EnumUtils; | ||
|
|
||
| import javax.inject.Inject; | ||
| import java.util.Date; | ||
| import java.util.Map; | ||
|
|
||
| @APICommand(name = "createResourceSchedule", description = "Create Resource Schedule", responseObject = ResourceScheduleResponse.class, | ||
| requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, since = "4.23.0", | ||
| authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User}) | ||
| public class CreateResourceScheduleCmd extends BaseCmd { | ||
|
|
||
| @Inject | ||
| ResourceScheduleManager resourceScheduleManager; | ||
|
|
||
| @Parameter(name = ApiConstants.RESOURCE_TYPE, type = CommandType.STRING, required = true, description = "Type of the resource") | ||
| private String resourceType; | ||
|
|
||
| @Parameter(name = ApiConstants.RESOURCE_ID, type = CommandType.STRING, required = true, description = "ID of the resource for which schedule is to be defined") | ||
| private String resourceId; | ||
|
|
||
| @Parameter(name = ApiConstants.DESCRIPTION, type = CommandType.STRING, required = false, description = "Description of the schedule") | ||
| private String description; | ||
|
|
||
| @Parameter(name = ApiConstants.SCHEDULE, type = CommandType.STRING, required = true, description = "Schedule for action on resource in cron format. e.g. '0 15 10 * *' for 'at 15:00 on 10th day of every month'") | ||
| private String schedule; | ||
|
|
||
| @Parameter(name = ApiConstants.TIMEZONE, type = CommandType.STRING, required = true, description = "Specifies a timezone for this command. For more information on the timezone parameter, see TimeZone Format.") | ||
| private String timeZone; | ||
|
|
||
| @Parameter(name = ApiConstants.ACTION, type = CommandType.STRING, required = true, description = "Action to take on the resource.") | ||
| private String action; | ||
|
|
||
| @Parameter(name = ApiConstants.START_DATE, type = CommandType.DATE, required = false, description = "Start date from which the schedule becomes active. Defaults to current date plus 1 minute. (Format \"yyyy-MM-dd hh:mm:ss\")") | ||
| private Date startDate; | ||
|
|
||
| @Parameter(name = ApiConstants.END_DATE, type = CommandType.DATE, required = false, description = "End date after which the schedule becomes inactive. (Format \"yyyy-MM-dd hh:mm:ss\")") | ||
| private Date endDate; | ||
|
|
||
| @Parameter(name = ApiConstants.ENABLED, type = CommandType.BOOLEAN, required = false, description = "Enable schedule. Defaults to true") | ||
| private Boolean enabled; | ||
|
|
||
| @Parameter(name = ApiConstants.DETAILS, type = CommandType.MAP, required = false, description = "Map of (key/value pairs) details for the schedule.") | ||
| private Map details; | ||
|
|
||
| public ApiCommandResourceType getResourceType() { | ||
| ApiCommandResourceType type = EnumUtils.getEnumIgnoreCase(ApiCommandResourceType.class, resourceType); | ||
| if (type == null) { | ||
| throw new InvalidParameterValueException("Unknown resource type: " + resourceType); | ||
| } | ||
| return type; | ||
| } | ||
|
|
||
| public String getResourceId() { | ||
| return resourceId; | ||
| } | ||
|
|
||
| public String getDescription() { | ||
| return description; | ||
| } | ||
|
|
||
| public String getSchedule() { | ||
| return schedule; | ||
| } | ||
|
|
||
| public String getTimeZone() { | ||
| return timeZone; | ||
| } | ||
|
|
||
| public String getAction() { | ||
| return action; | ||
| } | ||
|
|
||
| public Date getStartDate() { | ||
| return startDate; | ||
| } | ||
|
|
||
| public Date getEndDate() { | ||
| return endDate; | ||
| } | ||
|
|
||
| public Boolean getEnabled() { | ||
| if (enabled == null) { | ||
| enabled = true; | ||
| } | ||
| return enabled; | ||
| } | ||
|
|
||
| public Map<String, String> getDetails() { | ||
| return convertDetailsToMap(details); | ||
| } | ||
|
|
||
| @Override | ||
| public void execute() { | ||
| ResourceScheduleResponse response = resourceScheduleManager.createSchedule(getResourceType(), getResourceId(), | ||
| getDescription(), getSchedule(), getTimeZone(), getAction(), getStartDate(), getEndDate(), getEnabled(), getDetails()); | ||
| response.setResponseName(getCommandName()); | ||
| setResponseObject(response); | ||
| } | ||
|
|
||
| @Override | ||
| public long getEntityOwnerId() { | ||
| return CallContext.current().getCallingAccount().getAccountId(); | ||
| } | ||
| } |
86 changes: 86 additions & 0 deletions
86
.../main/java/org/apache/cloudstack/api/command/user/schedule/DeleteResourceScheduleCmd.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| // 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.schedule; | ||
|
|
||
| import com.cloud.exception.InvalidParameterValueException; | ||
| import org.apache.cloudstack.acl.RoleType; | ||
| import org.apache.cloudstack.api.APICommand; | ||
| import org.apache.cloudstack.api.ApiCommandResourceType; | ||
| import org.apache.cloudstack.api.ApiConstants; | ||
| import org.apache.cloudstack.api.BaseCmd; | ||
| import org.apache.cloudstack.api.Parameter; | ||
| import org.apache.cloudstack.api.response.ResourceScheduleResponse; | ||
| import org.apache.cloudstack.api.response.SuccessResponse; | ||
| import org.apache.cloudstack.context.CallContext; | ||
| import org.apache.cloudstack.schedule.ResourceScheduleManager; | ||
| import org.apache.commons.lang3.EnumUtils; | ||
|
|
||
| import javax.inject.Inject; | ||
| import java.util.List; | ||
|
|
||
| @APICommand(name = "deleteResourceSchedule", description = "Delete Resource Schedule", responseObject = SuccessResponse.class, | ||
| requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, since = "4.23.0", | ||
| authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User}) | ||
| public class DeleteResourceScheduleCmd extends BaseCmd { | ||
|
|
||
| @Inject | ||
| ResourceScheduleManager resourceScheduleManager; | ||
|
|
||
| @Parameter(name = ApiConstants.RESOURCE_TYPE, type = CommandType.STRING, required = true, description = "Type of the resource") | ||
| private String resourceType; | ||
|
|
||
| @Parameter(name = ApiConstants.RESOURCE_ID, type = CommandType.STRING, required = true, description = "ID of the resource for which schedules are to be deleted") | ||
| private String resourceId; | ||
|
|
||
| @Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = ResourceScheduleResponse.class, required = false, description = "ID of the schedule to be deleted") | ||
| private Long id; | ||
|
|
||
| @Parameter(name = ApiConstants.IDS, type = CommandType.LIST, collectionType = CommandType.UUID, entityType = ResourceScheduleResponse.class, required = false, description = "comma separated list of schedule ids to be deleted") | ||
| private List<Long> ids; | ||
|
|
||
| public ApiCommandResourceType getResourceType() { | ||
| ApiCommandResourceType type = EnumUtils.getEnumIgnoreCase(ApiCommandResourceType.class, resourceType); | ||
| if (type == null) { | ||
| throw new InvalidParameterValueException("Unknown resource type: " + resourceType); | ||
| } | ||
| return type; | ||
| } | ||
|
|
||
| public String getResourceId() { | ||
| return resourceId; | ||
| } | ||
|
|
||
| public Long getId() { | ||
| return id; | ||
| } | ||
|
|
||
| public List<Long> getIds() { | ||
| return ids; | ||
| } | ||
|
|
||
| @Override | ||
| public void execute() { | ||
| resourceScheduleManager.removeSchedule(getResourceType(), getResourceId(), getId(), getIds()); | ||
| SuccessResponse response = new SuccessResponse(getCommandName()); | ||
| setResponseObject(response); | ||
| } | ||
|
|
||
| @Override | ||
| public long getEntityOwnerId() { | ||
| return CallContext.current().getCallingAccount().getAccountId(); | ||
| } | ||
| } | ||
97 changes: 97 additions & 0 deletions
97
...rc/main/java/org/apache/cloudstack/api/command/user/schedule/ListResourceScheduleCmd.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| // 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.schedule; | ||
|
|
||
| import com.cloud.exception.InvalidParameterValueException; | ||
| import org.apache.cloudstack.acl.RoleType; | ||
| import org.apache.cloudstack.api.APICommand; | ||
| import org.apache.cloudstack.api.ApiCommandResourceType; | ||
| 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.ResourceScheduleResponse; | ||
| import org.apache.cloudstack.schedule.ResourceScheduleManager; | ||
| import org.apache.commons.lang3.EnumUtils; | ||
|
|
||
| import javax.inject.Inject; | ||
| import java.util.List; | ||
|
|
||
| @APICommand(name = "listResourceSchedule", description = "List Resource Schedules", responseObject = ResourceScheduleResponse.class, | ||
| requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, since = "4.23.0", | ||
| authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User}) | ||
| public class ListResourceScheduleCmd extends BaseListCmd { | ||
|
|
||
| @Inject | ||
| ResourceScheduleManager resourceScheduleManager; | ||
|
|
||
| @Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = ResourceScheduleResponse.class, required = false, description = "ID of the schedule") | ||
| private Long id; | ||
|
|
||
| @Parameter(name = ApiConstants.IDS, type = CommandType.LIST, collectionType = CommandType.UUID, entityType = ResourceScheduleResponse.class, required = false, description = "comma separated list of schedule ids") | ||
| private List<Long> ids; | ||
|
|
||
| @Parameter(name = ApiConstants.RESOURCE_TYPE, type = CommandType.STRING, required = true, description = "Type of the resource.") | ||
| private String resourceType; | ||
|
|
||
| @Parameter(name = ApiConstants.RESOURCE_ID, type = CommandType.STRING, required = true, description = "ID of the resource for which schedules are to be listed.") | ||
| private String resourceId; | ||
|
|
||
| @Parameter(name = ApiConstants.ACTION, type = CommandType.STRING, required = false, description = "Action to take on the resource.") | ||
| private String action; | ||
|
|
||
| @Parameter(name = ApiConstants.ENABLED, type = CommandType.BOOLEAN, required = false, description = "Filter by enabled status.") | ||
| private Boolean enabled; | ||
|
|
||
| public Long getId() { | ||
| return id; | ||
| } | ||
|
|
||
| public List<Long> getIds() { | ||
| return ids; | ||
| } | ||
|
|
||
| public ApiCommandResourceType getResourceType() { | ||
| ApiCommandResourceType type = EnumUtils.getEnumIgnoreCase(ApiCommandResourceType.class, resourceType); | ||
| if (type == null) { | ||
| throw new InvalidParameterValueException("Unknown resource type: " + resourceType); | ||
| } | ||
| return type; | ||
| } | ||
|
|
||
| public String getResourceId() { | ||
| return resourceId; | ||
| } | ||
|
|
||
| public String getAction() { | ||
| return action; | ||
| } | ||
|
|
||
| public Boolean getEnabled() { | ||
| return enabled; | ||
| } | ||
|
|
||
| @Override | ||
| public void execute() { | ||
| ListResponse<ResourceScheduleResponse> response = resourceScheduleManager.listSchedule( | ||
| getId(), getIds(), getResourceType(), getResourceId(), getAction(), getEnabled(), | ||
| getStartIndex(), getPageSizeVal() | ||
| ); | ||
| response.setResponseName(getCommandName()); | ||
| setResponseObject(response); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.