forked from jenkinsci/spotinst-plugin
-
Notifications
You must be signed in to change notification settings - Fork 1
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
Jenkins plugin instance type search #27
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
e923e94
InstanceType_by_user_input
sitay93 639cb4f
InstanceType_by_user_input
sitay93 434fe5b
InstanceType_by_user_input backward compatibility
sitay93 9ab88b4
InstanceType_by_user_input Liron's rejects
sitay93 25bc627
InstanceType_by_user_input Ziv's rejects
sitay93 cd7ca68
InstanceType_by_user_input invalidType alerts and backward compatibility
sitay93 5deda43
InstanceType_by_user_input remove redundant note
sitay93 645c97b
InstanceType_by_user_input remove redundant note
sitay93 9b1854e
InstanceType_by_user_input Ziv's Rejects
sitay93 e66653a
InstanceType_by_user_input Logger
sitay93 a335317
InstanceType_by_user_input Logger readable format
sitay93 bbf0a1c
InstanceType_by_user_input fix hpi
sitay93 e14c552
InstanceType_by_user_input JenkinsWiki.adoc version 2.2.9
sitay93 cbccac5
InstanceType_by_user_input method name by code convention
sitay93 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
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
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
83 changes: 83 additions & 0 deletions
83
src/main/java/hudson/plugins/spotinst/cloud/monitor/AwsSpotinstCloudInstanceTypeMonitor.java
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 |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package hudson.plugins.spotinst.cloud.monitor; | ||
|
||
import hudson.Extension; | ||
import hudson.model.AdministrativeMonitor; | ||
import hudson.plugins.spotinst.cloud.AwsSpotinstCloud; | ||
import hudson.slaves.Cloud; | ||
import jenkins.model.Jenkins; | ||
import org.apache.commons.collections.CollectionUtils; | ||
|
||
import java.util.*; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
@Extension | ||
public class AwsSpotinstCloudInstanceTypeMonitor extends AdministrativeMonitor { | ||
//region members | ||
Map<String, List<String>> invalidInstancesByGroupId; | ||
//endregion | ||
|
||
//region Overrides | ||
@Override | ||
public boolean isActivated() { | ||
boolean retVal; | ||
initInvalidInstances(); | ||
retVal = hasInvalidInstanceType(); | ||
return retVal; | ||
} | ||
|
||
@Override | ||
public String getDisplayName() { | ||
return "Aws Spotinst Cloud Instance Type Monitor"; | ||
} | ||
//endregion | ||
|
||
//region Methods | ||
public boolean hasInvalidInstanceType() { | ||
return invalidInstancesByGroupId.isEmpty() == false; | ||
} | ||
//endregion | ||
|
||
//region getters & setters | ||
public String getInvalidInstancesByGroupId() { | ||
Stream<String> invalidInstancesForOutput = | ||
invalidInstancesByGroupId.keySet().stream().map(this::generateAlertMessage); | ||
String retVal = invalidInstancesForOutput.collect(Collectors.joining(", ")); | ||
|
||
return retVal; | ||
} | ||
//endregion | ||
|
||
//region private Methods | ||
private void initInvalidInstances() { | ||
invalidInstancesByGroupId = new HashMap<>(); | ||
Jenkins jenkinsInstance = Jenkins.getInstance(); | ||
List<Cloud> clouds = jenkinsInstance != null ? jenkinsInstance.clouds : new LinkedList<>(); | ||
List<AwsSpotinstCloud> awsClouds = clouds.stream().filter(cloud -> cloud instanceof AwsSpotinstCloud) | ||
.map(awsCloud -> (AwsSpotinstCloud) awsCloud) | ||
.collect(Collectors.toList()); | ||
|
||
awsClouds.forEach(awsCloud -> { | ||
String elastigroupId = awsCloud.getGroupId(); | ||
List<String> invalidTypes = awsCloud.getInvalidInstanceTypes(); | ||
|
||
if (CollectionUtils.isEmpty(invalidTypes) == false) { | ||
invalidInstancesByGroupId.put(elastigroupId, invalidTypes); | ||
} | ||
}); | ||
} | ||
|
||
private String generateAlertMessage(String group) { | ||
StringBuilder retVal = new StringBuilder(); | ||
retVal.append('\'').append(group).append('\'').append(": ["); | ||
|
||
List<String> InvalidInstancesByGroup = invalidInstancesByGroupId.get(group); | ||
Stream<String> InvalidInstancesForAlert = | ||
InvalidInstancesByGroup.stream().map(invalidInstance -> '\'' + invalidInstance + '\''); | ||
|
||
String instances = InvalidInstancesForAlert.collect(Collectors.joining(", ")); | ||
retVal.append(instances).append(']'); | ||
return retVal.toString(); | ||
} | ||
//region | ||
} |
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.
if retVal == true (has invalid) generate the alert message and print it to log