private Resource parseJsonElementToresource(String region, JsonNode jsonNode) {
Validate.notNull(jsonNode);
String imageId = jsonNode.get("imageId").getTextValue();
Resource resource = new AWSResource().withId(imageId).withRegion(region)
.withResourceType(AWSResourceType.IMAGE);
Long creationTime = imageIdToCreationTime.get(imageId);
if (creationTime != null) {
resource.setLaunchTime(new Date(creationTime));
}
JsonNode tags = jsonNode.get("tags");
if (tags == null || !tags.isArray() || tags.size() == 0) {
LOGGER.debug(String.format("No tags is found for %s", resource.getId()));
} else {
for (Iterator<JsonNode> it = tags.getElements(); it.hasNext();) {
JsonNode tag = it.next();
String key = tag.get("key").getTextValue();
String value = tag.get("value").getTextValue();
resource.setTag(key, value);
}
}
JsonNode descNode = jsonNode.get("description");
if (descNode != null && !descNode.isNull()) {
String description = descNode.getTextValue();
resource.setDescription(description);
String ancestorImageId = getBaseAmiIdFromDescription(description);
if (ancestorImageId != null && !ancestorImageIds.contains(ancestorImageId)) {
LOGGER.info(String.format("Found base AMI id %s from description '%s'", ancestorImageId, description));
ancestorImageIds.add(ancestorImageId);
}
}
((AWSResource) resource).setAWSResourceState(jsonNode.get("state").getTextValue());
String owner = getOwnerEmailForResource(resource);
if (owner != null) {
resource.setOwnerEmail(owner);
}
return resource;
}