Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 30 additions & 30 deletions src/main/java/io/cloudsoft/terraform/parser/StateParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ public final class StateParser {
*/
public static final ImmutableList PROBLEMATIC_RESOURCES = ImmutableList.of("aws_emr_cluster.spark_cluster");

private static Predicate<? super PlanLogEntry> providerPredicate = (Predicate<PlanLogEntry>) ple -> ple.getProvider() != PlanLogEntry.Provider.NOT_SUPPORTED;
private static Predicate<? super PlanLogEntry> changeSummaryPredicate = (Predicate<PlanLogEntry>) ple -> ple.type == PlanLogEntry.LType.CHANGE_SUMMARY;
private static Predicate<? super PlanLogEntry> outputsPredicate = (Predicate<PlanLogEntry>) ple -> ple.type == PlanLogEntry.LType.OUTPUTS;
private static Predicate<? super PlanLogEntry> plannedChangedPredicate = (Predicate<PlanLogEntry>) ple -> ple.type == PlanLogEntry.LType.PLANNED_CHANGE;
private static Predicate<? super PlanLogEntry> driftPredicate = (Predicate<PlanLogEntry>) ple -> ple.type == PlanLogEntry.LType.RESOURCE_DRIFT;
private static Predicate<? super PlanLogEntry> errorPredicate = (Predicate<PlanLogEntry>) ple -> ple.type == PlanLogEntry.LType.DIAGNOSTIC;
private static Predicate<? super PlanLogEntry> providerPredicate = (Predicate<PlanLogEntry>) planLogEntry -> planLogEntry.getProvider() != PlanLogEntry.Provider.NOT_SUPPORTED;
private static Predicate<? super PlanLogEntry> changeSummaryPredicate = (Predicate<PlanLogEntry>) planLogEntry -> planLogEntry.type == PlanLogEntry.LType.CHANGE_SUMMARY;
private static Predicate<? super PlanLogEntry> outputsPredicate = (Predicate<PlanLogEntry>) planLogEntry -> planLogEntry.type == PlanLogEntry.LType.OUTPUTS;
private static Predicate<? super PlanLogEntry> plannedChangedPredicate = (Predicate<PlanLogEntry>) planLogEntry -> planLogEntry.type == PlanLogEntry.LType.PLANNED_CHANGE;
private static Predicate<? super PlanLogEntry> driftPredicate = (Predicate<PlanLogEntry>) planLogEntry -> planLogEntry.type == PlanLogEntry.LType.RESOURCE_DRIFT;
private static Predicate<? super PlanLogEntry> errorPredicate = (Predicate<PlanLogEntry>) planLogEntry -> planLogEntry.type == PlanLogEntry.LType.DIAGNOSTIC;
private static Predicate<? super JsonNode> isNotBlankPredicate = node -> node != null && !BLANK_ITEMS.contains((node instanceof TextNode) ? node.asText() : node.toString());


Expand Down Expand Up @@ -72,36 +72,36 @@ public static Map<String, Object> parseResources(final String state){
Map<String, Object> resourceBody = new LinkedHashMap<>();

//if (resource.has("mode") && "managed".equals(resource.get("mode").asText())) {
result.put(resource.get("address").asText(), resourceBody);
result.put(resource.get("address").asText(), resourceBody);

resourceBody.put("resource.address", resource.get("address").asText());
resourceBody.put("resource.mode", resource.get("mode").asText());
resourceBody.put("resource.type", resource.get("type").asText());
resourceBody.put("resource.name", resource.get("name").asText());
resourceBody.put("resource.provider", resource.get("provider_name").asText());
if(resource.has("values")) {
Iterator<Map.Entry<String, JsonNode>> it = resource.get("values").fields();
while(it.hasNext()) {
Map.Entry<String,JsonNode> value = it.next();
if(isNotBlankPredicate.test(value.getValue())) {
if((resourceBody.get("resource.address").toString().startsWith(GOOGLE.getPrefix()) && value.getKey().equals("cluster_config"))){
parseClusterData(value.getValue(), "value.cluster_config", resourceBody);
} else {
resourceBody.put("value." + value.getKey(), value.getValue() instanceof TextNode? value.getValue().asText() : value.getValue().toString());
}
resourceBody.put("resource.address", resource.get("address").asText());
resourceBody.put("resource.mode", resource.get("mode").asText());
resourceBody.put("resource.type", resource.get("type").asText());
resourceBody.put("resource.name", resource.get("name").asText());
resourceBody.put("resource.provider", resource.get("provider_name").asText());
if(resource.has("values")) {
Iterator<Map.Entry<String, JsonNode>> it = resource.get("values").fields();
while(it.hasNext()) {
Map.Entry<String,JsonNode> value = it.next();
if(isNotBlankPredicate.test(value.getValue())) {
if((resourceBody.get("resource.address").toString().startsWith(GOOGLE.getPrefix()) && value.getKey().equals("cluster_config"))){
parseClusterData(value.getValue(), "value.cluster_config", resourceBody);
} else {
resourceBody.put("value." + value.getKey(), value.getValue() instanceof TextNode? value.getValue().asText() : value.getValue().toString());
}
}
}
}

if(resource.has("sensitive_values")) {
Iterator<Map.Entry<String, JsonNode>> it = resource.get("sensitive_values").fields();
while(it.hasNext()) {
Map.Entry<String,JsonNode> value = it.next();
if(isNotBlankPredicate.test(value.getValue())) {
resourceBody.put("sensitive.value." + value.getKey(), value.getValue() instanceof TextNode? value.getValue().asText() : value.getValue().toString());
}
if(resource.has("sensitive_values")) {
Iterator<Map.Entry<String, JsonNode>> it = resource.get("sensitive_values").fields();
while(it.hasNext()) {
Map.Entry<String,JsonNode> value = it.next();
if(isNotBlankPredicate.test(value.getValue())) {
resourceBody.put("sensitive.value." + value.getKey(), value.getValue() instanceof TextNode? value.getValue().asText() : value.getValue().toString());
}
}
}
//}

});
Expand Down Expand Up @@ -160,7 +160,7 @@ public static Map<String, Object> parsePlanLogEntries(final String planLogEntrie
try {
return objectMapper.readValue(log, PlanLogEntry.class);
} catch (JsonProcessingException e) {
LOG.warn("Unable to parse plan log entry: "+log, e);
e.printStackTrace();
}
return null;
}).filter(Objects::nonNull).collect(Collectors.toList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ public void testDeployFromAWSAndFromCfgInBundle() throws Exception {
Assert.assertTrue(entity instanceof TerraformConfiguration);
EntityAsserts.assertAttributeEventually(entity, Sensors.newStringSensor("tf.configuration.applied"), Objects::nonNull);

Assert.assertTrue(((Integer) entity.getChildren().size()).equals(1));
Entity resource = Iterables.getOnlyElement(entity.getChildren());
EntityAsserts.assertAttributeEventually(resource, Sensors.newStringSensor("tf.resource.address"), v -> v.equals("aws_instance.web"));
EntityAsserts.assertAttributeEventually(resource, Sensors.newStringSensor("tf.resource.mode"), v -> v.equals("managed"));
Expand All @@ -80,9 +79,9 @@ public void testDeployFromLocalhostAndFromCfgInBlueprint() throws Exception {
Application app = deploy("localhost_location", "classpath://blueprints/tf-cfg-in-blueprint.bom");

Entity entity = Iterables.getOnlyElement(app.getChildren());

Assert.assertTrue(entity instanceof TerraformConfiguration);
EntityAsserts.assertAttributeEventually(entity, Sensors.newStringSensor("tf.configuration.applied"), Objects::nonNull);

EntityAsserts.assertPredicateEventuallyTrue(entity, entity1 -> ((Integer) entity1.getChildren().size()).equals(1));

Entity resource = Iterables.getOnlyElement(entity.getChildren());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import org.apache.brooklyn.util.text.Identifiers;
import org.apache.brooklyn.util.text.Strings;
import org.apache.commons.lang3.tuple.Pair;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.annotations.Test;

public class TerraformContainerDriverTest extends AbstractYamlTest {
Expand All @@ -25,6 +27,7 @@ public void simpleEmptyApp() throws Exception {
Dumper.dumpInfo(app);
EntityAsserts.assertAttributeEqualsEventually(app, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.RUNNING);
EntityAsserts.assertAttributeEqualsEventually(app, Attributes.SERVICE_UP, true);

}

protected Pair<String,String> getAwsKey() {
Expand Down