Search in sources :

Example 1 with HostGroup

use of com.sequenceiq.cloudbreak.domain.HostGroup in project cloudbreak by hortonworks.

the class HdfConfigProviderTest method testNifiNodeIdentitiesWhenMasterIsAvailable.

@Test
public void testNifiNodeIdentitiesWhenMasterIsAvailable() throws IOException {
    // GIVEN
    String blueprintText = FileReaderUtils.readFileFromClasspath("blueprints-jackson/bp-kerberized-test.bp");
    Set<HostGroup> hostGroups = new HashSet<>();
    hostGroups.add(TestUtil.hostGroup("master", 2));
    hostGroups.add(TestUtil.hostGroup("worker", 2));
    hostGroups.add(TestUtil.hostGroup("compute", 2));
    Map<String, List<InstanceMetaData>> groupInstanes = new HashMap<>();
    for (HostGroup hg : hostGroups) {
        groupInstanes.put(hg.getName(), new ArrayList<>(hg.getConstraint().getInstanceGroup().getInstanceMetaData()));
    }
    when(blueprintProcessor.getHostGroupsWithComponent("NIFI_MASTER")).thenReturn(Sets.newHashSet("master"));
    when(blueprintProcessor.pathValue("configurations", "nifi-ambari-config", "nifi.node.ssl.port")).thenReturn(Optional.of("9091"));
    when(blueprintProcessorFactory.get(anyString())).thenReturn(blueprintProcessor);
    // WHEN
    HdfConfigs hdfConfigs = underTest.createHdfConfig(hostGroups, groupInstanes, blueprintText);
    // THEN
    StringBuilder expectedNodeEntities = new StringBuilder();
    int i = 0;
    for (InstanceMetaData instance : groupInstanes.get("master")) {
        expectedNodeEntities.append("<property name=\"Node Identity " + ++i + "\">CN=" + instance.getDiscoveryFQDN() + ", OU=NIFI</property>");
    }
    Assert.assertEquals(expectedNodeEntities.toString(), hdfConfigs.getNodeEntities());
    Assert.assertEquals(Optional.of(groupInstanes.get("master").stream().map(im -> im.getPublicIp() + ":9091").collect(Collectors.joining(","))), hdfConfigs.getProxyHosts());
    verify(blueprintProcessor, times(1)).getHostGroupsWithComponent("NIFI_MASTER");
}
Also used : Mock(org.mockito.Mock) RunWith(org.junit.runner.RunWith) TestUtil(com.sequenceiq.cloudbreak.TestUtil) HashMap(java.util.HashMap) Matchers.anyString(org.mockito.Matchers.anyString) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Map(java.util.Map) FileReaderUtils(com.sequenceiq.cloudbreak.util.FileReaderUtils) InjectMocks(org.mockito.InjectMocks) HostGroup(com.sequenceiq.cloudbreak.domain.HostGroup) BlueprintTextProcessor(com.sequenceiq.cloudbreak.blueprint.BlueprintTextProcessor) InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) Set(java.util.Set) Mockito.times(org.mockito.Mockito.times) IOException(java.io.IOException) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) Mockito.verify(org.mockito.Mockito.verify) List(java.util.List) MockitoJUnitRunner(org.mockito.runners.MockitoJUnitRunner) BlueprintProcessorFactory(com.sequenceiq.cloudbreak.blueprint.BlueprintProcessorFactory) Optional(java.util.Optional) Assert(org.junit.Assert) HashMap(java.util.HashMap) HostGroup(com.sequenceiq.cloudbreak.domain.HostGroup) Matchers.anyString(org.mockito.Matchers.anyString) InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) ArrayList(java.util.ArrayList) List(java.util.List) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 2 with HostGroup

use of com.sequenceiq.cloudbreak.domain.HostGroup in project cloudbreak by hortonworks.

the class BlueprintValidatorTest method testHostGroupScalingThrowsBadRequestExceptionWhenNodeCountIsMoreThanMax.

@Test
public void testHostGroupScalingThrowsBadRequestExceptionWhenNodeCountIsMoreThanMax() throws IOException {
    // GIVEN
    Blueprint blueprint = createBlueprint();
    JsonNode blueprintJsonTree = createJsonTree();
    InstanceGroup instanceGroup = createInstanceGroup(GROUP3, 3);
    HostGroup hostGroup = createHostGroup(instanceGroup.getGroupName(), instanceGroup);
    BDDMockito.given(objectMapper.readTree(BLUEPRINT_STRING)).willReturn(blueprintJsonTree);
    thrown.expect(BlueprintValidationException.class);
    thrown.expectMessage("The node count '4' for hostgroup 'group3' cannot be less than '1' or more than '3' because of 'mastercomp3' component");
    // WHEN
    underTest.validateHostGroupScalingRequest(blueprint, hostGroup, 1);
// THEN throw exception
}
Also used : Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) HostGroup(com.sequenceiq.cloudbreak.domain.HostGroup) JsonNode(com.fasterxml.jackson.databind.JsonNode) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup) Test(org.junit.Test)

Example 3 with HostGroup

use of com.sequenceiq.cloudbreak.domain.HostGroup in project cloudbreak by hortonworks.

the class BlueprintValidatorTest method testValidateBlueprintForStackShouldThrowBadRequestExceptionWhenNotEnoughGroupDefinedInBlueprint.

@Test
public void testValidateBlueprintForStackShouldThrowBadRequestExceptionWhenNotEnoughGroupDefinedInBlueprint() throws IOException {
    // GIVEN
    Blueprint blueprint = createBlueprint();
    Set<InstanceGroup> instanceGroups = createInstanceGroups();
    Set<HostGroup> hostGroups = createHostGroups(instanceGroups);
    JsonNode blueprintJsonTree = createJsonTreeWithNotEnoughGroup();
    BDDMockito.given(objectMapper.readTree(BLUEPRINT_STRING)).willReturn(blueprintJsonTree);
    thrown.expect(BlueprintValidationException.class);
    thrown.expectMessage(Matchers.startsWith("The host groups in the validation"));
    // WHEN
    underTest.validateBlueprintForStack(blueprint, hostGroups, instanceGroups);
// THEN throw exception
}
Also used : Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) HostGroup(com.sequenceiq.cloudbreak.domain.HostGroup) JsonNode(com.fasterxml.jackson.databind.JsonNode) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup) Test(org.junit.Test)

Example 4 with HostGroup

use of com.sequenceiq.cloudbreak.domain.HostGroup in project cloudbreak by hortonworks.

the class BlueprintValidatorTest method testValidateBlueprintForStackShouldThrowBadRequestExceptionWhenComponentIsLessThanMin.

@Test
public void testValidateBlueprintForStackShouldThrowBadRequestExceptionWhenComponentIsLessThanMin() throws IOException {
    // GIVEN
    Blueprint blueprint = createBlueprint();
    Set<InstanceGroup> instanceGroups = createInstanceGroups();
    Set<HostGroup> hostGroups = createHostGroups(instanceGroups);
    instanceGroups.add(createInstanceGroup("gateway", 1));
    JsonNode blueprintJsonTree = createJsonTreeWithComponentIsLess();
    BDDMockito.given(objectMapper.readTree(BLUEPRINT_STRING)).willReturn(blueprintJsonTree);
    thrown.expect(BlueprintValidationException.class);
    thrown.expectMessage("Incorrect number of 'slavecomp2' components are in '[group3]' hostgroups: count: 3, min: 5 max: 6");
    // WHEN
    underTest.validateBlueprintForStack(blueprint, hostGroups, instanceGroups);
// THEN throw exception
}
Also used : Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) HostGroup(com.sequenceiq.cloudbreak.domain.HostGroup) JsonNode(com.fasterxml.jackson.databind.JsonNode) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup) Test(org.junit.Test)

Example 5 with HostGroup

use of com.sequenceiq.cloudbreak.domain.HostGroup 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)

Aggregations

HostGroup (com.sequenceiq.cloudbreak.domain.HostGroup)94 Cluster (com.sequenceiq.cloudbreak.domain.Cluster)33 Test (org.junit.Test)33 InstanceGroup (com.sequenceiq.cloudbreak.domain.InstanceGroup)31 Blueprint (com.sequenceiq.cloudbreak.domain.Blueprint)29 HashSet (java.util.HashSet)22 JsonNode (com.fasterxml.jackson.databind.JsonNode)20 HostMetadata (com.sequenceiq.cloudbreak.domain.HostMetadata)20 List (java.util.List)20 HashMap (java.util.HashMap)19 Stack (com.sequenceiq.cloudbreak.domain.Stack)18 InstanceMetaData (com.sequenceiq.cloudbreak.domain.InstanceMetaData)16 AmbariClient (com.sequenceiq.ambari.client.AmbariClient)15 Map (java.util.Map)14 HttpClientConfig (com.sequenceiq.cloudbreak.client.HttpClientConfig)13 BadRequestException (com.sequenceiq.cloudbreak.controller.BadRequestException)12 Constraint (com.sequenceiq.cloudbreak.domain.Constraint)11 ArrayList (java.util.ArrayList)11 Set (java.util.Set)11 Inject (javax.inject.Inject)11