Skip to content

Commit

Permalink
Merge pull request #120 from rundeck-plugins/fix_endpoint_bug
Browse files Browse the repository at this point in the history
Add check to confirm endpoint is set
  • Loading branch information
qualman authored May 10, 2022
2 parents 12f5022 + 14788b6 commit f9fffb5
Showing 1 changed file with 35 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,42 +104,52 @@ public NodeSetImpl performQuery() {
}
}

if (getEndpoint().equals("ALL_REGIONS")) {
if(getEndpoint() != null) {
if (getEndpoint().equals("ALL_REGIONS")) {

//Retrieve dynamic list of EC2 regions from AWS
DescribeRegionsResult regionsResult = ec2.describeRegions();
for (Region region : regionsResult.getRegions()) {
regions.add(region.getEndpoint());
}
//Retrieve dynamic list of EC2 regions from AWS
DescribeRegionsResult regionsResult = ec2.describeRegions();
for (Region region : regionsResult.getRegions()) {
regions.add(region.getEndpoint());
}

} else {
try {
//Use comma-separated list of region supplied by user
regions.addAll(Arrays.asList(getEndpoint().replaceAll("\\s+", "").split(",")));
} catch (NullPointerException e) {
throw new IllegalArgumentException("Failed to parse endpoint: Region cannot be empty");
} else {
try {
//Use comma-separated list of region supplied by user
regions.addAll(Arrays.asList(getEndpoint().replaceAll("\\s+", "").split(",")));
} catch (NullPointerException e) {
throw new IllegalArgumentException("Failed to parse endpoint: Region cannot be empty");
}
}
}

for (String region : regions) {
for (String region : regions) {

ec2.setEndpoint(region);
zones = ec2.describeAvailabilityZones();
final ArrayList<Filter> filters = buildFilters();
ec2.setEndpoint(region);
zones = ec2.describeAvailabilityZones();
final ArrayList<Filter> filters = buildFilters();

final Set<Instance> newInstances = addExtraMappingAttribute(query(ec2, new DescribeInstancesRequest().withFilters(filters).withMaxResults(maxResults)));
final Set<Instance> newInstances = addExtraMappingAttribute(query(ec2, new DescribeInstancesRequest().withFilters(filters).withMaxResults(maxResults)));

if (!newInstances.isEmpty() && newInstances !=null) {
instances.addAll(newInstances);
}
if (!newInstances.isEmpty() && newInstances != null) {
instances.addAll(newInstances);
}

try {
Thread.sleep(100);
} catch(InterruptedException ex) {
Thread.currentThread().interrupt();
try {
Thread.sleep(100);
} catch (InterruptedException ex) {
Thread.currentThread().interrupt();
}
}
}
else{
zones = ec2.describeAvailabilityZones();

final ArrayList<Filter> filters = buildFilters();

//use ec2 object without defining endpoint and sdk will assign default

instances = addExtraMappingAttribute(query(ec2, new DescribeInstancesRequest().withFilters(filters).withMaxResults(maxResults)));
}
mapInstances(nodeSet, instances);
return nodeSet;
}
Expand Down

0 comments on commit f9fffb5

Please sign in to comment.