Search in sources :

Example 1 with GatekeeperAWSInstance

use of org.finra.gatekeeper.services.aws.model.GatekeeperAWSInstance in project Gatekeeper by FINRAOS.

the class Ec2LookupServiceTests method testDefaultStatus.

@Test
public void testDefaultStatus() {
    Map<String, String> statusMap = new HashMap<>();
    statusMap.put("i-12345", null);
    statusMap.put("i-abcde", "Active");
    statusMap.put("i-456cd", "Online");
    statusMap.put("i-123ab", "Inactive");
    when(ssmService.checkInstancesWithSsm(any(), any())).thenReturn(statusMap);
    List<GatekeeperAWSInstance> instances = Ec2LookupService.getInstances(awsEnvironment, "Linux", "APPLICATION", "T");
    Assert.assertEquals("Test search result", 5, instances.size());
    for (GatekeeperAWSInstance instance : instances) {
        if (statusMap.get(instance.getInstanceId()) == null) {
            Assert.assertEquals("Unknown should be default when the resulting lookup is null", "Unknown", instance.getSsmStatus());
        } else {
            Assert.assertEquals("Statuses should match", statusMap.get(instance.getInstanceId()), instance.getSsmStatus());
        }
    }
}
Also used : GatekeeperAWSInstance(org.finra.gatekeeper.services.aws.model.GatekeeperAWSInstance) Test(org.junit.Test)

Example 2 with GatekeeperAWSInstance

use of org.finra.gatekeeper.services.aws.model.GatekeeperAWSInstance in project Gatekeeper by FINRAOS.

the class Ec2LookupService method loadInstances.

private List<GatekeeperAWSInstance> loadInstances(AWSEnvironment environment) {
    logger.info("Refreshing Instance Data");
    List<GatekeeperAWSInstance> instanceList = new ArrayList<>();
    DescribeInstancesRequest describeInstancesRequest = new DescribeInstancesRequest();
    ArrayList<Filter> describeInstanceRequestFilters = new ArrayList<>();
    describeInstanceRequestFilters.add(createAwsFilter("instance-state-code", Arrays.asList(INSTANCE_RUNNING)));
    describeInstancesRequest.setFilters(describeInstanceRequestFilters);
    DescribeInstancesResult result = awsSessionService.getEC2Session(environment).describeInstances(describeInstancesRequest);
    result.getReservations().forEach(reservation -> {
        reservation.getInstances().forEach(instance -> {
            String ipAddress = instance.getPrivateIpAddress() != null ? instance.getPrivateIpAddress() : instance.getPublicIpAddress() != null ? instance.getPublicIpAddress() : "";
            instanceList.add(new GatekeeperAWSInstance(instance.getInstanceId(), getTagValue(instance, gatekeeperEc2Properties.getAppIdentityTag()), getTagValue(instance, "Name"), ipAddress, instance.getPlatform() == null ? "Linux" : StringUtils.capitalize(instance.getPlatform())));
        });
    });
    return instanceList;
}
Also used : GatekeeperAWSInstance(org.finra.gatekeeper.services.aws.model.GatekeeperAWSInstance)

Aggregations

GatekeeperAWSInstance (org.finra.gatekeeper.services.aws.model.GatekeeperAWSInstance)2 Test (org.junit.Test)1