-
Notifications
You must be signed in to change notification settings - Fork 1.3k
api,server: purge expunged resources #8999
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
Merged
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
9bd4f1e
upgrade: move 4.19.0->4.20.0 to 4.19.1->4.20.0
weizhouapache af9d68c
api,server: purge expunged resources
shwstppr 8ee1a15
fix
shwstppr 971991d
refactor
shwstppr 3103f85
fix
shwstppr f8fc404
another fix
shwstppr 420babb
defensive checks, test fix
shwstppr f0c04cb
fixes
shwstppr 73770a5
test fix
shwstppr 36d0cad
Merge branch 'main' into 4.20-fix-upgrade-path-from-4191
weizhouapache 7fd0c4e
Update api/src/main/java/org/apache/cloudstack/api/command/admin/offe…
shwstppr 00ca064
Update api/src/main/java/org/apache/cloudstack/api/command/admin/reso…
shwstppr 8bca921
Update api/src/main/java/org/apache/cloudstack/api/response/ServiceOf…
shwstppr dc593c5
Merge remote-tracking branch 'apache/main' into 4.20-fix-upgrade-path…
weizhouapache e61cc85
Merge remote-tracking branch 'apache/main' into feature-purgedb
shwstppr ff35da9
rephrase global config descriptions
shwstppr 6fbd01c
Merge remote-tracking branch 'wei/4.20-fix-upgrade-path-from-4191' in…
shwstppr d17678a
Merge remote-tracking branch 'apache/main' into feature-purgedb
shwstppr ced6e6d
code coverage
shwstppr 2a078c1
eof
shwstppr 90c584a
imports
shwstppr 195a904
Merge remote-tracking branch 'apache/main' into feature-purgedb
shwstppr 7ef4c4b
Merge branch 'main' into feature-purgedb
shwstppr 93edde5
Merge remote-tracking branch 'apache/main' into feature-purgedb
shwstppr 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
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
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
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
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
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
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
131 changes: 131 additions & 0 deletions
131
...main/java/org/apache/cloudstack/api/command/admin/resource/PurgeExpungedResourcesCmd.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,131 @@ | ||
| // 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.admin.resource; | ||
|
|
||
|
|
||
| import java.util.Date; | ||
|
|
||
| import javax.inject.Inject; | ||
|
|
||
| import org.apache.cloudstack.acl.RoleType; | ||
| import org.apache.cloudstack.api.APICommand; | ||
| import org.apache.cloudstack.api.ApiConstants; | ||
| import org.apache.cloudstack.api.ApiErrorCode; | ||
| import org.apache.cloudstack.api.BaseAsyncCmd; | ||
| import org.apache.cloudstack.api.BaseCmd; | ||
| import org.apache.cloudstack.api.Parameter; | ||
| import org.apache.cloudstack.api.ResponseObject; | ||
| import org.apache.cloudstack.api.ServerApiException; | ||
| import org.apache.cloudstack.api.response.PurgeExpungedResourcesResponse; | ||
| import org.apache.cloudstack.api.response.SuccessResponse; | ||
| import org.apache.cloudstack.context.CallContext; | ||
| import org.apache.cloudstack.resource.ResourceCleanupService; | ||
|
|
||
| import com.cloud.event.EventTypes; | ||
|
|
||
| @APICommand(name = "purgeExpungedResources", | ||
| description = "Purge expunged resources", | ||
| responseObject = SuccessResponse.class, | ||
| responseView = ResponseObject.ResponseView.Full, | ||
| requestHasSensitiveInfo = false, | ||
| responseHasSensitiveInfo = false, | ||
| authorized = {RoleType.Admin}, | ||
| since = "4.20") | ||
| public class PurgeExpungedResourcesCmd extends BaseAsyncCmd { | ||
|
|
||
| @Inject | ||
| ResourceCleanupService resourceCleanupService; | ||
|
|
||
| ///////////////////////////////////////////////////// | ||
| //////////////// API parameters ///////////////////// | ||
| ///////////////////////////////////////////////////// | ||
|
|
||
| @Parameter(name = ApiConstants.RESOURCE_TYPE, type = BaseCmd.CommandType.STRING, | ||
| description = "The type of the resource which need to be purged. Supported types: " + | ||
| "VirtualMachine") | ||
| private String resourceType; | ||
|
|
||
| @Parameter(name = ApiConstants.BATCH_SIZE, type = CommandType.LONG, | ||
| description = "The size of batch used during purging") | ||
| private Long batchSize; | ||
|
|
||
| @Parameter(name = ApiConstants.START_DATE, | ||
| type = CommandType.DATE, | ||
| description = "The start date range of the expunged resources used for purging " + | ||
| "(use format \"yyyy-MM-dd\" or \"yyyy-MM-dd HH:mm:ss\")") | ||
| private Date startDate; | ||
|
|
||
| @Parameter(name = ApiConstants.END_DATE, | ||
| type = CommandType.DATE, | ||
| description = "The end date range of the expunged resources used for purging " + | ||
| "(use format \"yyyy-MM-dd\" or \"yyyy-MM-dd HH:mm:ss\")") | ||
| private Date endDate; | ||
|
|
||
| ///////////////////////////////////////////////////// | ||
| /////////////////// Accessors /////////////////////// | ||
| ///////////////////////////////////////////////////// | ||
|
|
||
|
|
||
| public String getResourceType() { | ||
| return resourceType; | ||
| } | ||
|
|
||
| public Long getBatchSize() { | ||
| return batchSize; | ||
| } | ||
|
|
||
| public Date getStartDate() { | ||
| return startDate; | ||
| } | ||
|
|
||
| public Date getEndDate() { | ||
| return endDate; | ||
| } | ||
|
|
||
| @Override | ||
| public long getEntityOwnerId() { | ||
| return CallContext.current().getCallingAccount().getId(); | ||
| } | ||
|
|
||
| @Override | ||
| public String getEventType() { | ||
| return EventTypes.EVENT_PURGE_EXPUNGED_RESOURCES; | ||
| } | ||
|
|
||
| @Override | ||
| public String getEventDescription() { | ||
| return "Purging expunged resources"; | ||
| } | ||
|
|
||
| ///////////////////////////////////////////////////// | ||
| /////////////// API Implementation/////////////////// | ||
| ///////////////////////////////////////////////////// | ||
|
|
||
| @Override | ||
| public void execute() { | ||
| try { | ||
| long result = resourceCleanupService.purgeExpungedResources(this); | ||
| PurgeExpungedResourcesResponse response = new PurgeExpungedResourcesResponse(); | ||
| response.setResourceCount(result); | ||
| response.setObjectName(getCommandName().toLowerCase()); | ||
| setResponseObject(response); | ||
| } catch (Exception e) { | ||
| throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getLocalizedMessage()); | ||
| } | ||
| } | ||
| } |
39 changes: 39 additions & 0 deletions
39
api/src/main/java/org/apache/cloudstack/api/response/PurgeExpungedResourcesResponse.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,39 @@ | ||
| // 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.response; | ||
|
|
||
| import org.apache.cloudstack.api.ApiConstants; | ||
| import org.apache.cloudstack.api.BaseResponse; | ||
|
|
||
| import com.cloud.serializer.Param; | ||
| import com.google.gson.annotations.SerializedName; | ||
|
|
||
| public class PurgeExpungedResourcesResponse extends BaseResponse { | ||
|
|
||
| @SerializedName(ApiConstants.RESOURCE_COUNT) | ||
| @Param(description = "The count of the purged expunged resources") | ||
| private Long resourceCount; | ||
|
|
||
| public Long getResourceCount() { | ||
| return resourceCount; | ||
| } | ||
|
|
||
| public void setResourceCount(Long resourceCount) { | ||
| this.resourceCount = resourceCount; | ||
| } | ||
| } |
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
74 changes: 74 additions & 0 deletions
74
api/src/main/java/org/apache/cloudstack/resource/ResourceCleanupService.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,74 @@ | ||
| // 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.resource; | ||
|
|
||
| import org.apache.cloudstack.api.command.admin.resource.PurgeExpungedResourcesCmd; | ||
| import org.apache.cloudstack.framework.config.ConfigKey; | ||
|
|
||
| import com.cloud.vm.VirtualMachine; | ||
|
|
||
| public interface ResourceCleanupService { | ||
| int MINIMUM_EXPUNGED_RESOURCE_PURGE_JOB_DELAY_IN_SECONDS = 3 * 60; | ||
| ConfigKey<Boolean> ExpungedResourcePurgeEnabled = new ConfigKey<>("Advanced", Boolean.class, | ||
| "expunged.resources.purge.enabled", "false", | ||
| "Whether to run a background task to purge the DB records of the expunged resources", | ||
| false, ConfigKey.Scope.Global); | ||
| ConfigKey<String> ExpungedResourcePurgeResources = new ConfigKey<>("Advanced", String.class, | ||
| "expunged.resources.purge.resources", "", | ||
| "A comma-separated list of resource types that will be considered by the background task " + | ||
| "to purge the DB records of the expunged resources. Currently only VirtualMachine is supported. " + | ||
| "An empty value will result in considering all resource types for purging", | ||
| false, ConfigKey.Scope.Global); | ||
| ConfigKey<Integer> ExpungedResourcesPurgeInterval = new ConfigKey<>("Advanced", Integer.class, | ||
| "expunged.resources.purge.interval", "86400", | ||
| "Interval (in seconds) for the background task to purge the DB records of the expunged resources", | ||
| false); | ||
| ConfigKey<Integer> ExpungedResourcesPurgeDelay = new ConfigKey<>("Advanced", Integer.class, | ||
| "expunged.resources.purge.delay", "300", | ||
| "Initial delay (in seconds) to start the background task to purge the DB records of the " + | ||
| "expunged resources task", false); | ||
| ConfigKey<Integer> ExpungedResourcesPurgeBatchSize = new ConfigKey<>("Advanced", Integer.class, | ||
| "expunged.resources.purge.batch.size", "50", | ||
| "Batch size to be used during purging of the DB records of the expunged resources", | ||
| true); | ||
| ConfigKey<String> ExpungedResourcesPurgeStartTime = new ConfigKey<>("Advanced", String.class, | ||
| "expunged.resources.purge.start.time", "", | ||
| "Start time to be used by the background task to purge the DB records of the expunged " + | ||
| "resources. Use format \"yyyy-MM-dd\" or \"yyyy-MM-dd HH:mm:ss\"", true); | ||
| ConfigKey<Integer> ExpungedResourcesPurgeKeepPastDays = new ConfigKey<>("Advanced", Integer.class, | ||
| "expunged.resources.purge.keep.past.days", "30", | ||
| "The number of days in the past from the execution time of the background task to purge " + | ||
| "the DB records of the expunged resources for which the expunged resources must not be purged. " + | ||
| "To enable purging DB records of the expunged resource till the execution of the background " + | ||
| "task, set the value to zero.", true); | ||
| ConfigKey<Integer> ExpungedResourcePurgeJobDelay = new ConfigKey<>("Advanced", Integer.class, | ||
| "expunged.resource.purge.job.delay", | ||
| String.valueOf(MINIMUM_EXPUNGED_RESOURCE_PURGE_JOB_DELAY_IN_SECONDS), | ||
| String.format("Delay (in seconds) to execute the purging of the DB records of an expunged resource " + | ||
| "initiated by the configuration in the offering. Minimum value should be %d seconds " + | ||
| "and if a lower value is set then the minimum value will be used", | ||
| MINIMUM_EXPUNGED_RESOURCE_PURGE_JOB_DELAY_IN_SECONDS), | ||
| true); | ||
|
|
||
| enum ResourceType { | ||
| VirtualMachine | ||
| } | ||
|
|
||
| long purgeExpungedResources(PurgeExpungedResourcesCmd cmd); | ||
| void purgeExpungedVmResourcesLaterIfNeeded(VirtualMachine vm); | ||
| } | ||
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess the complete sentence makes sense as it is,
If needed, we can rephrase the whole statement