Search in sources :

Example 11 with JsonNodeFactory

use of com.fasterxml.jackson.databind.node.JsonNodeFactory in project cloudbreak by hortonworks.

the class BlueprintValidatorTest method testKnoxWithKerberosAndNonGwHasKnox.

@Test
public void testKnoxWithKerberosAndNonGwHasKnox() throws IOException {
    // GIVEN
    Blueprint blueprint = createBlueprint();
    Set<InstanceGroup> instanceGroups = new HashSet<>();
    instanceGroups.add(createInstanceGroup("gateway1", 1, InstanceGroupType.GATEWAY));
    instanceGroups.add(createInstanceGroup("gateway2", 1, InstanceGroupType.GATEWAY));
    instanceGroups.add(createInstanceGroup("master", 1, InstanceGroupType.CORE));
    Set<HostGroup> hostGroups = createHostGroups(instanceGroups);
    JsonNodeFactory jsonNodeFactory = JsonNodeFactory.instance;
    ObjectNode rootNode = jsonNodeFactory.objectNode();
    ArrayNode hostGroupsNode = rootNode.putArray("host_groups");
    addHostGroup(hostGroupsNode, "gateway1", SL_MIN0_MAX3, MA_MIN1_MAX3);
    addHostGroup(hostGroupsNode, "gateway2", SL_MIN0_MAX3, MA_MIN1_MAX3);
    addHostGroup(hostGroupsNode, "master", SL_MIN0_MAX3, KNOX);
    BDDMockito.given(objectMapper.readTree(BLUEPRINT_STRING)).willReturn(rootNode);
    Cluster cluster = new Cluster();
    cluster.setSecure(true);
    Gateway gateway = new Gateway();
    gateway.setEnableGateway(true);
    cluster.setGateway(gateway);
    thrown.expect(BlueprintValidationException.class);
    thrown.expectMessage("In case of Knox and Kerberos each 'Ambari Server' node must include the 'KNOX_GATEWAY' service. " + "The following host groups are missing the service: gateway1,gateway2");
    // WHEN
    underTest.validateBlueprintForStack(cluster, blueprint, hostGroups, instanceGroups);
// THEN exception thrown
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) Gateway(com.sequenceiq.cloudbreak.domain.Gateway) HostGroup(com.sequenceiq.cloudbreak.domain.HostGroup) Cluster(com.sequenceiq.cloudbreak.domain.Cluster) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup) HashSet(java.util.HashSet) JsonNodeFactory(com.fasterxml.jackson.databind.node.JsonNodeFactory) Test(org.junit.Test)

Example 12 with JsonNodeFactory

use of com.fasterxml.jackson.databind.node.JsonNodeFactory in project cloudbreak by hortonworks.

the class BlueprintValidatorTest method createJsonTree.

private JsonNode createJsonTree() {
    JsonNodeFactory jsonNodeFactory = JsonNodeFactory.instance;
    ObjectNode rootNode = jsonNodeFactory.objectNode();
    ArrayNode hostGroupsNode = rootNode.putArray("host_groups");
    addHostGroup(hostGroupsNode, GROUP1, SL_MIN0_MAX3, MA_MIN1_MAX1);
    addHostGroup(hostGroupsNode, GROUP2, MA_MIN1_MAX5);
    addHostGroup(hostGroupsNode, GROUP3, MA_MIN1_MAX3);
    return rootNode;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) JsonNodeFactory(com.fasterxml.jackson.databind.node.JsonNodeFactory)

Example 13 with JsonNodeFactory

use of com.fasterxml.jackson.databind.node.JsonNodeFactory in project cloudbreak by hortonworks.

the class BlueprintValidatorTest method testKnoxWithKerberosButOneNodeMissingKnox.

@Test
public void testKnoxWithKerberosButOneNodeMissingKnox() throws IOException {
    // GIVEN
    Blueprint blueprint = createBlueprint();
    Set<InstanceGroup> instanceGroups = new HashSet<>();
    instanceGroups.add(createInstanceGroup("gateway1", 1, InstanceGroupType.GATEWAY));
    instanceGroups.add(createInstanceGroup("gateway2", 1, InstanceGroupType.GATEWAY));
    instanceGroups.add(createInstanceGroup("master", 1, InstanceGroupType.CORE));
    Set<HostGroup> hostGroups = createHostGroups(instanceGroups);
    JsonNodeFactory jsonNodeFactory = JsonNodeFactory.instance;
    ObjectNode rootNode = jsonNodeFactory.objectNode();
    ArrayNode hostGroupsNode = rootNode.putArray("host_groups");
    addHostGroup(hostGroupsNode, "gateway1", SL_MIN0_MAX3, KNOX);
    addHostGroup(hostGroupsNode, "gateway2", SL_MIN0_MAX3, MA_MIN1_MAX3);
    addHostGroup(hostGroupsNode, "master", SL_MIN0_MAX3, MA_MIN1_MAX5);
    BDDMockito.given(objectMapper.readTree(BLUEPRINT_STRING)).willReturn(rootNode);
    Cluster cluster = new Cluster();
    cluster.setSecure(true);
    Gateway gateway = new Gateway();
    gateway.setEnableGateway(true);
    cluster.setGateway(gateway);
    thrown.expect(BlueprintValidationException.class);
    thrown.expectMessage("In case of Knox and Kerberos each 'Ambari Server' node must include the 'KNOX_GATEWAY' service. " + "The following host groups are missing the service: gateway2");
    // WHEN
    underTest.validateBlueprintForStack(cluster, blueprint, hostGroups, instanceGroups);
// THEN exception thrown
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) Gateway(com.sequenceiq.cloudbreak.domain.Gateway) HostGroup(com.sequenceiq.cloudbreak.domain.HostGroup) Cluster(com.sequenceiq.cloudbreak.domain.Cluster) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup) HashSet(java.util.HashSet) JsonNodeFactory(com.fasterxml.jackson.databind.node.JsonNodeFactory) Test(org.junit.Test)

Example 14 with JsonNodeFactory

use of com.fasterxml.jackson.databind.node.JsonNodeFactory in project cloudbreak by hortonworks.

the class BlueprintValidatorTest method createJsonTreeWithComponentInMoreGroups.

private JsonNode createJsonTreeWithComponentInMoreGroups() {
    JsonNodeFactory jsonNodeFactory = JsonNodeFactory.instance;
    ObjectNode rootNode = jsonNodeFactory.objectNode();
    ArrayNode hostGroupsNode = rootNode.putArray("host_groups");
    addHostGroup(hostGroupsNode, GROUP1, MA_MIN1_MAX1, MA_MIN1_MAX3);
    addHostGroup(hostGroupsNode, GROUP2, MA_MIN1_MAX5);
    addHostGroup(hostGroupsNode, GROUP3, MA_MIN1_MAX3);
    return rootNode;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) JsonNodeFactory(com.fasterxml.jackson.databind.node.JsonNodeFactory)

Example 15 with JsonNodeFactory

use of com.fasterxml.jackson.databind.node.JsonNodeFactory in project debezium by debezium.

the class VerifyRecord method printJson.

protected static void printJson(SourceRecord record) {
    JsonNode keyJson = null;
    JsonNode valueJson = null;
    try {
        // First serialize and deserialize the key ...
        byte[] keyBytes = keyJsonConverter.fromConnectData(record.topic(), record.keySchema(), record.key());
        keyJson = keyJsonDeserializer.deserialize(record.topic(), keyBytes);
        // then the value ...
        byte[] valueBytes = valueJsonConverter.fromConnectData(record.topic(), record.valueSchema(), record.value());
        valueJson = valueJsonDeserializer.deserialize(record.topic(), valueBytes);
        // And finally get ready to print it ...
        JsonNodeFactory nodeFactory = new JsonNodeFactory(false);
        ObjectNode message = nodeFactory.objectNode();
        message.set("key", keyJson);
        message.set("value", valueJson);
        Testing.print("Message on topic '" + record.topic() + "':");
        Testing.print(prettyJson(message));
    } catch (Throwable t) {
        Testing.printError(t);
        Testing.print("Problem with message on topic '" + record.topic() + "':");
        if (keyJson != null) {
            Testing.print("valid key = " + prettyJson(keyJson));
        } else {
            Testing.print("invalid key");
        }
        if (valueJson != null) {
            Testing.print("valid value = " + prettyJson(valueJson));
        } else {
            Testing.print("invalid value");
        }
        fail(t.getMessage());
    }
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JsonNode(com.fasterxml.jackson.databind.JsonNode) JsonNodeFactory(com.fasterxml.jackson.databind.node.JsonNodeFactory)

Aggregations

JsonNodeFactory (com.fasterxml.jackson.databind.node.JsonNodeFactory)35 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)28 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)17 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 IOException (java.io.IOException)5 Test (org.junit.Test)5 Blueprint (com.sequenceiq.cloudbreak.domain.Blueprint)4 Cluster (com.sequenceiq.cloudbreak.domain.Cluster)4 Gateway (com.sequenceiq.cloudbreak.domain.Gateway)4 HostGroup (com.sequenceiq.cloudbreak.domain.HostGroup)4 InstanceGroup (com.sequenceiq.cloudbreak.domain.InstanceGroup)4 HashSet (java.util.HashSet)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 File (java.io.File)3 ArrayList (java.util.ArrayList)3 ObjectWriter (com.fasterxml.jackson.databind.ObjectWriter)2 EventEntity (io.gravitee.management.model.EventEntity)2 BufferedWriter (java.io.BufferedWriter)2 FileWriter (java.io.FileWriter)2 PersistenceException (javax.persistence.PersistenceException)2