use of com.sequenceiq.cloudbreak.domain.Constraint in project cloudbreak by hortonworks.
the class ContainerConstraintFactory method getAmbariAgentConstraint.
public ContainerConstraint getAmbariAgentConstraint(String ambariServerHost, String ambariAgentApp, String cloudPlatform, HostGroup hostGroup, Integer adjustment, List<String> hostBlackList, String identifier) {
String containerInstanceName;
containerInstanceName = YARN.equals(hostGroup.getCluster().getStack().getOrchestrator().getType()) ? createContainerInstanceNameForYarn(hostGroup, AMBARI_AGENT.getName(), identifier) : createContainerInstanceName(hostGroup, AMBARI_AGENT.getName(), identifier);
Constraint hgConstraint = hostGroup.getConstraint();
Builder builder = new Builder().withNamePrefix(containerInstanceName).withAppName(ambariAgentApp).networkMode(HOST_NETWORK_MODE);
if (hgConstraint.getInstanceGroup() != null) {
InstanceGroup instanceGroup = hgConstraint.getInstanceGroup();
Map<String, String> dataVolumeBinds = new HashMap<>();
dataVolumeBinds.put("/var/log/ambari-agent-container", CONTAINER_VOLUME_PATH);
dataVolumeBinds.put(HADOOP_MOUNT_DIR, HADOOP_MOUNT_DIR);
dataVolumeBinds.putAll(ImmutableMap.of("/data/jars", "/data/jars", HOST_VOLUME_PATH, CONTAINER_VOLUME_PATH));
builder.addVolumeBindings(dataVolumeBinds);
if (adjustment != null) {
List<String> candidates = collectUpscaleCandidates(hostGroup.getCluster().getId(), hostGroup.getName(), adjustment);
builder.addHosts(getHosts(candidates, instanceGroup));
} else {
builder.addHosts(getHosts(null, instanceGroup));
}
builder.cmd(new String[] { String.format("/usr/sbin/init systemd.setenv=AMBARI_SERVER_ADDR=%s systemd.setenv=CLOUD_PLATFORM=%s", ambariServerHost, cloudPlatform) });
}
if (hgConstraint.getConstraintTemplate() != null) {
builder.cpus(hgConstraint.getConstraintTemplate().getCpu());
builder.memory(hgConstraint.getConstraintTemplate().getMemory());
builder.constraints(getConstraints(hostBlackList));
if (adjustment != null) {
builder.instances(adjustment);
} else {
builder.instances(hgConstraint.getHostCount());
}
builder.withDiskSize(hgConstraint.getConstraintTemplate().getDisk());
Map<String, String> dataVolumeBinds = new HashMap<>();
dataVolumeBinds.put("/var/log/ambari-agent-container", CONTAINER_VOLUME_PATH);
builder.addVolumeBindings(dataVolumeBinds);
builder.cmd(new String[] { String.format("/usr/sbin/init systemd.setenv=AMBARI_SERVER_ADDR=%s systemd.setenv=USE_CONSUL_DNS=false", ambariServerHost) });
}
return builder.build();
}
use of com.sequenceiq.cloudbreak.domain.Constraint in project cloudbreak by hortonworks.
the class ClusterTerminationService method deleteClusterHostGroupsWithItsMetadata.
private void deleteClusterHostGroupsWithItsMetadata(Cluster cluster) {
Set<HostGroup> hostGroups = hostGroupRepository.findHostGroupsInCluster(cluster.getId());
Collection<Constraint> constraintsToDelete = new LinkedList<>();
for (HostGroup hg : hostGroups) {
hg.getRecipes().clear();
Constraint constraint = hg.getConstraint();
if (constraint != null) {
constraintsToDelete.add(constraint);
}
}
hostGroupRepository.delete(hostGroups);
constraintRepository.delete(constraintsToDelete);
cluster.getHostGroups().clear();
cluster.getContainers().clear();
clusterRepository.save(cluster);
}
use of com.sequenceiq.cloudbreak.domain.Constraint in project cloudbreak by hortonworks.
the class ConstraintRequestToConstraintConverter method convert.
@Override
public Constraint convert(ConstraintJson source) {
Constraint constraint = new Constraint();
constraint.setHostCount(source.getHostCount());
return constraint;
}
use of com.sequenceiq.cloudbreak.domain.Constraint in project cloudbreak by hortonworks.
the class StackValidationRequestToStackValidationConverter method convertHostGroupsFromJson.
private Set<HostGroup> convertHostGroupsFromJson(Collection<InstanceGroup> instanceGroups, Iterable<HostGroupRequest> hostGroupsJsons) {
Set<HostGroup> hostGroups = new HashSet<>();
for (HostGroupRequest json : hostGroupsJsons) {
HostGroup hostGroup = new HostGroup();
hostGroup.setName(json.getName());
Constraint constraint = getConversionService().convert(json.getConstraint(), Constraint.class);
String instanceGroupName = json.getConstraint().getInstanceGroupName();
if (instanceGroupName != null) {
InstanceGroup instanceGroup = instanceGroups.stream().filter(instanceGroup1 -> instanceGroup1.getGroupName().equals(instanceGroupName)).findFirst().get();
if (instanceGroup == null) {
throw new BadRequestException(String.format("Cannot find instance group named '%s' in instance group list", instanceGroupName));
}
constraint.setInstanceGroup(instanceGroup);
}
hostGroup.setConstraint(constraint);
hostGroups.add(hostGroup);
}
return hostGroups;
}
use of com.sequenceiq.cloudbreak.domain.Constraint in project cloudbreak by hortonworks.
the class HostGroupDecorator method getDetailsFromExistingHostGroup.
private HostGroup getDetailsFromExistingHostGroup(Constraint constraint, HostGroup subject, String instanceGroupName, Collection<HostGroup> hostGroups) {
Optional<HostGroup> hostGroupOptional = hostGroups.stream().filter(input -> input.getConstraint().getInstanceGroup().getGroupName().equals(instanceGroupName)).findFirst();
if (hostGroupOptional.isPresent()) {
HostGroup hostGroup = hostGroupOptional.get();
Integer instanceGroupNodeCount = hostGroup.getConstraint().getInstanceGroup().getNodeCount();
if (constraint.getHostCount() > instanceGroupNodeCount) {
throw new BadRequestException(String.format("The 'hostCount' of host group '%s' constraint could not be more than '%s'!", subject.getName(), instanceGroupNodeCount));
}
hostGroup.getConstraint().setHostCount(constraint.getHostCount());
hostGroup.setName(subject.getName());
return hostGroup;
} else {
throw new BadRequestException(String.format("Invalid 'instanceGroupName'! Could not find instance group with name: '%s'", instanceGroupName));
}
}
Aggregations