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
}
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
}
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
}
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
}
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");
}
}
}
Aggregations