Search in sources :

Example 11 with HostGroup

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

the class BlueprintValidatorTest method testValidateBlueprintForStackShouldThrowBadRequestExceptionWhenJsonTreeCreationIsFailed.

@Test
public void testValidateBlueprintForStackShouldThrowBadRequestExceptionWhenJsonTreeCreationIsFailed() throws Exception {
    // GIVEN
    Blueprint blueprint = createBlueprint();
    Set<InstanceGroup> instanceGroups = createInstanceGroups();
    Set<HostGroup> hostGroups = createHostGroups(instanceGroups);
    IOException expectedException = new IOException("");
    BDDMockito.given(objectMapper.readTree(BDDMockito.anyString())).willThrow(expectedException);
    thrown.expect(BlueprintValidationException.class);
    thrown.expectMessage("Blueprint [null] can not be parsed from JSON.");
    thrown.expectCause(is(expectedException));
    // WHEN
    underTest.validateBlueprintForStack(blueprint, hostGroups, instanceGroups);
// THEN throw exception
}
Also used : Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) HostGroup(com.sequenceiq.cloudbreak.domain.HostGroup) IOException(java.io.IOException) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup) Test(org.junit.Test)

Example 12 with HostGroup

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

the class BlueprintValidatorTest method testValidateBlueprintForStackShouldThrowBadRequestExceptionWhenNoInstanceGroupForAHostGroup.

@Test
public void testValidateBlueprintForStackShouldThrowBadRequestExceptionWhenNoInstanceGroupForAHostGroup() throws IOException {
    // GIVEN
    Blueprint blueprint = createBlueprint();
    Set<InstanceGroup> instanceGroups = createInstanceGroups();
    Set<HostGroup> hostGroups = createHostGroups(instanceGroups.stream().sorted().limit(instanceGroups.size() - 1).collect(Collectors.toSet()));
    JsonNode blueprintJsonTree = createJsonTree();
    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 13 with HostGroup

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

the class BlueprintValidatorTest method testHostGroupScalingThrowsBadRequestExceptionWhenNodeCountIsLessThanMin.

@Test
public void testHostGroupScalingThrowsBadRequestExceptionWhenNodeCountIsLessThanMin() throws IOException {
    // GIVEN
    Blueprint blueprint = createBlueprint();
    JsonNode blueprintJsonTree = createJsonTree();
    InstanceGroup instanceGroup = createInstanceGroup(GROUP3, 1);
    HostGroup hostGroup = createHostGroup(instanceGroup.getGroupName(), instanceGroup);
    BDDMockito.given(objectMapper.readTree(BLUEPRINT_STRING)).willReturn(blueprintJsonTree);
    thrown.expect(BlueprintValidationException.class);
    thrown.expectMessage("The node count '0' 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 14 with HostGroup

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

the class BlueprintValidatorTest method testKnoxWithoutKerberos.

@Test
public void testKnoxWithoutKerberos() throws IOException {
    // GIVEN
    Blueprint blueprint = createBlueprint();
    Set<InstanceGroup> instanceGroups = createInstanceGroups();
    Set<HostGroup> hostGroups = createHostGroups(instanceGroups);
    instanceGroups.add(createInstanceGroup("gateway", 1));
    JsonNode blueprintJsonTree = createJsonTree();
    BDDMockito.given(objectMapper.readTree(BLUEPRINT_STRING)).willReturn(blueprintJsonTree);
    Cluster cluster = new Cluster();
    cluster.setSecure(false);
    // WHEN
    underTest.validateBlueprintForStack(cluster, blueprint, hostGroups, instanceGroups);
// THEN no exception thrown
}
Also used : Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) HostGroup(com.sequenceiq.cloudbreak.domain.HostGroup) Cluster(com.sequenceiq.cloudbreak.domain.Cluster) JsonNode(com.fasterxml.jackson.databind.JsonNode) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup) Test(org.junit.Test)

Example 15 with HostGroup

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

the class BlueprintValidator method validateHostGroups.

private void validateHostGroups(JsonNode hostGroupsNode, Collection<HostGroup> hostGroups, Collection<InstanceGroup> instanceGroups) {
    Set<String> hostGroupsInRequest = getHostGroupsFromRequest(hostGroups);
    Set<String> hostGroupsInBlueprint = getHostGroupsFromBlueprint(hostGroupsNode);
    if (!hostGroupsInRequest.containsAll(hostGroupsInBlueprint) || !hostGroupsInBlueprint.containsAll(hostGroupsInRequest)) {
        throw new BlueprintValidationException("The host groups in the validation [" + String.join(",", hostGroupsInBlueprint) + "] " + "must match the hostgroups in the request [" + String.join(",", hostGroupsInRequest) + "].");
    }
    if (!instanceGroups.isEmpty()) {
        Collection<String> instanceGroupNames = new HashSet<>();
        for (HostGroup hostGroup : hostGroups) {
            String instanceGroupName = hostGroup.getConstraint().getInstanceGroup().getGroupName();
            if (instanceGroupNames.contains(instanceGroupName)) {
                throw new BlueprintValidationException(String.format("Instance group '%s' is assigned to more than one hostgroup.", instanceGroupName));
            }
            instanceGroupNames.add(instanceGroupName);
        }
        if (instanceGroups.size() < hostGroupsInRequest.size()) {
            throw new BlueprintValidationException("Each host group must have an instance group");
        }
    }
}
Also used : HostGroup(com.sequenceiq.cloudbreak.domain.HostGroup) HashSet(java.util.HashSet)

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