use of com.sequenceiq.cloudbreak.api.model.ConstraintJson in project cloudbreak by hortonworks.
the class ConstraintToConstraintJsonConverter method convert.
@Override
public ConstraintJson convert(Constraint source) {
ConstraintJson constraintJson = new ConstraintJson();
if (source.getConstraintTemplate() != null) {
constraintJson.setConstraintTemplateName(source.getConstraintTemplate().getName());
}
if (source.getInstanceGroup() != null) {
constraintJson.setInstanceGroupName(source.getInstanceGroup().getGroupName());
}
constraintJson.setHostCount(source.getHostCount());
return constraintJson;
}
use of com.sequenceiq.cloudbreak.api.model.ConstraintJson in project cloudbreak by hortonworks.
the class MockClusterCreationWithSaltFailTest method convertHostGroups.
private Set<HostGroupRequest> convertHostGroups(Iterable<HostGroup> hostGroups, String runRecipesOnHosts) {
Set<Long> recipeIds = Collections.emptySet();
List<String> hostGroupsWithRecipe = Collections.emptyList();
if (!runRecipesOnHosts.isEmpty()) {
recipeIds = getItContext().getContextParam(CloudbreakITContextConstants.RECIPE_ID, Set.class);
Assert.assertFalse(recipeIds == null || recipeIds.isEmpty());
hostGroupsWithRecipe = Arrays.asList(runRecipesOnHosts.split(","));
}
Set<HostGroupRequest> hgMaps = new HashSet<>();
for (HostGroup hostgroup : hostGroups) {
HostGroupRequest hostGroupBase = new HostGroupRequest();
hostGroupBase.setName(hostgroup.getName());
ConstraintJson constraintJson = new ConstraintJson();
constraintJson.setInstanceGroupName(hostgroup.getInstanceGroupName());
constraintJson.setHostCount(hostgroup.getHostCount());
hostGroupBase.setConstraint(constraintJson);
if (hostGroupsWithRecipe.contains(hostgroup.getName())) {
hostGroupBase.setRecipeIds(recipeIds);
}
hgMaps.add(hostGroupBase);
}
return hgMaps;
}
use of com.sequenceiq.cloudbreak.api.model.ConstraintJson in project cloudbreak by hortonworks.
the class ClusterCreationTest method convertHostGroups.
private Set<HostGroupRequest> convertHostGroups(Collection<HostGroup> hostGroups, String runRecipesOnHosts, Boolean autoRecoveryMode) {
Set<Long> recipeIds = Collections.emptySet();
List<String> hostGroupsWithRecipe = Collections.emptyList();
if (!runRecipesOnHosts.isEmpty()) {
recipeIds = getItContext().getContextParam(CloudbreakITContextConstants.RECIPE_ID, Set.class);
Assert.assertFalse(recipeIds == null || recipeIds.isEmpty());
hostGroupsWithRecipe = Arrays.asList(runRecipesOnHosts.split(","));
}
Set<HostGroupRequest> hgMaps = new HashSet<>(hostGroups.size());
for (HostGroup hostgroup : hostGroups) {
HostGroupRequest hostGroupBase = new HostGroupRequest();
hostGroupBase.setName(hostgroup.getName());
if (Boolean.TRUE.equals(autoRecoveryMode)) {
hostGroupBase.setRecoveryMode(RecoveryMode.AUTO);
}
ConstraintJson constraintJson = new ConstraintJson();
constraintJson.setInstanceGroupName(hostgroup.getInstanceGroupName());
constraintJson.setHostCount(hostgroup.getHostCount());
hostGroupBase.setConstraint(constraintJson);
if (hostGroupsWithRecipe.contains(hostgroup.getName())) {
hostGroupBase.setRecipeIds(recipeIds);
}
hgMaps.add(hostGroupBase);
}
return hgMaps;
}
use of com.sequenceiq.cloudbreak.api.model.ConstraintJson in project cloudbreak by hortonworks.
the class InstanceGroupV2RequestToHostGroupRequestConverter method convert.
@Override
public HostGroupRequest convert(InstanceGroupV2Request instanceGroupV2Request) {
HostGroupRequest hostGroupRequest = new HostGroupRequest();
hostGroupRequest.setName(instanceGroupV2Request.getGroup());
hostGroupRequest.setRecipeNames(instanceGroupV2Request.getRecipeNames());
hostGroupRequest.setRecipes(Collections.emptySet());
ConstraintJson constraintJson = new ConstraintJson();
constraintJson.setHostCount(instanceGroupV2Request.getNodeCount());
constraintJson.setInstanceGroupName(instanceGroupV2Request.getGroup());
hostGroupRequest.setConstraint(constraintJson);
hostGroupRequest.setRecipeIds(Collections.emptySet());
hostGroupRequest.setRecoveryMode(instanceGroupV2Request.getRecoveryMode());
return hostGroupRequest;
}
use of com.sequenceiq.cloudbreak.api.model.ConstraintJson in project cloudbreak by hortonworks.
the class HostGroupDecorator method decorate.
public HostGroup decorate(HostGroup subject, HostGroupRequest hostGroupRequest, IdentityUser user, Long stackId, boolean postRequest, Boolean publicInAccount) {
ConstraintJson constraintJson = hostGroupRequest.getConstraint();
Set<Long> recipeIds = hostGroupRequest.getRecipeIds();
Set<RecipeRequest> recipes = hostGroupRequest.getRecipes();
Set<String> recipeNames = hostGroupRequest.getRecipeNames();
LOGGER.debug("Decorating hostgroup on [{}] request.", postRequest ? "POST" : "PUT");
Constraint constraint = conversionService.convert(constraintJson, Constraint.class);
if (postRequest) {
constraint = decorateConstraint(stackId, user, constraint, constraintJson.getInstanceGroupName(), constraintJson.getConstraintTemplateName());
subject.setConstraint(constraint);
} else {
subject = getHostGroup(stackId, constraint, constraintJson, subject, user);
}
subject.getRecipes().clear();
if (recipeIds != null) {
prepareRecipesByIds(subject, recipeIds);
}
if (recipeNames != null && !recipeNames.isEmpty()) {
prepareRecipesByName(subject, user, recipeNames);
}
if (recipes != null && !recipes.isEmpty()) {
prepareRecipesByRequests(subject, user, recipes, publicInAccount);
}
return subject;
}
Aggregations