-
Notifications
You must be signed in to change notification settings - Fork 9
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
#P39046999 Persist last (5) successful local deployments as part of CLI application code #164
Open
leoSRM
wants to merge
9
commits into
aws-greengrass:main
Choose a base branch
from
leoSRM:main
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.
Open
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
aedb1bd
feat: persist last (5) successful local deployments as part of CLI ap…
15733d4
feat: persist last (5) successful local deployments as part of CLI ap…
4c219de
Merge branch 'main' into main
MikeDombo 8901982
feat: persist last (5) successful local deployments as part of CLI ap…
29bc119
Merge remote-tracking branch 'origin/main'
f89da2a
Merge branch 'aws-greengrass:main' into main
leoSRM cd5b76a
feat: persist last (5) successful local deployments as part of CLI ap…
43c8b1e
Merge remote-tracking branch 'origin/main'
ade3854
Merge branch 'aws-greengrass:main' into main
leoSRM 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 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 |
---|---|---|
|
@@ -9,6 +9,8 @@ | |
import com.aws.greengrass.authorization.Permission; | ||
import com.aws.greengrass.authorization.exceptions.AuthorizationException; | ||
import com.aws.greengrass.componentmanager.ComponentStore; | ||
import com.aws.greengrass.config.Node; | ||
import com.aws.greengrass.config.Topic; | ||
import com.aws.greengrass.config.Topics; | ||
import com.aws.greengrass.deployment.DeploymentQueue; | ||
import com.aws.greengrass.deployment.model.ConfigurationUpdateOperation; | ||
|
@@ -78,10 +80,12 @@ | |
import java.util.ArrayList; | ||
import java.util.Base64; | ||
import java.util.Collection; | ||
import java.util.Comparator; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.UUID; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
import java.util.stream.Collectors; | ||
import javax.inject.Inject; | ||
|
||
|
@@ -118,6 +122,7 @@ public class CLIEventStreamAgent { | |
private static final int DEBUG_PASSWORD_LENGTH_REQUIREMENT = 32; | ||
private static final String DEBUG_USERNAME = "debug"; | ||
private static final Duration DEBUG_PASSWORD_EXPIRATION = Duration.ofHours(8); | ||
private static final int PERSIST_LIMIT = 5; | ||
protected static final String CERT_FINGERPRINT_NAMESPACE = "_certificateFingerprint"; | ||
|
||
@Inject | ||
|
@@ -179,7 +184,27 @@ public void persistLocalDeployment(Topics serviceConfig, Map<String, Object> dep | |
String deploymentId = (String) deploymentDetails.get(DEPLOYMENT_ID_KEY_NAME); | ||
Topics localDeploymentDetails = localDeployments.lookupTopics(deploymentId); | ||
localDeploymentDetails.replaceAndWait(deploymentDetails); | ||
// TODO: [P41178971]: Implement a limit on no of local deployments to persist status for | ||
// #P39046999 Persist last (5) successful local deployments as part of CLI application code. | ||
if (localDeployments.size() > PERSIST_LIMIT) { | ||
List<Topics> childrenToRemove = new ArrayList<>(); | ||
AtomicInteger deploymentSucceeded = new AtomicInteger(); | ||
localDeployments.forEach(topics -> { | ||
Topics deploymentTopics = (Topics) topics; | ||
Topic existingChild = deploymentTopics.find(DEPLOYMENT_STATUS_KEY_NAME); | ||
String value = existingChild.getOnce().toString(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use |
||
if (DeploymentStatus.SUCCEEDED.toString().equals(value)) { | ||
deploymentSucceeded.getAndIncrement(); | ||
childrenToRemove.add(deploymentTopics); | ||
} | ||
}); | ||
// if more than PERSIST_LIMIT deployments are success, remove until PERSIST_LIMIT left | ||
if (deploymentSucceeded.get() > PERSIST_LIMIT) { | ||
childrenToRemove.stream() | ||
.sorted(Comparator.comparingLong(t -> t.find(DEPLOYMENT_STATUS_KEY_NAME).getModtime())) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. find may return null, you must handle this correctly. |
||
.limit(childrenToRemove.size() - PERSIST_LIMIT) | ||
.forEach(Node::remove); | ||
} | ||
} | ||
} | ||
|
||
@SuppressFBWarnings("SIC_INNER_SHOULD_BE_STATIC") | ||
|
This file contains 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
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.
check using
instanceof
before blindly casting toTopics
.