Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add disk constraint #105

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,9 @@ public int getCollectdPort() {
public void setCollectdPort(int collectdPort) {
this.collectdPort = collectdPort;
}

// FIXME how much disk space does Logstash actually require?
public double getRequiredDiskMegabytes() {
return 10;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class OfferStrategy {
@Inject
private Features features;

private List<Rule> acceptanceRules = asList(this::hostRule, this::cpuRule, this::ramRule, this::portsRule);
private List<Rule> acceptanceRules = asList(this::hostRule, this::cpuRule, this::ramRule, this::portsRule, this::diskRule);

private List<Integer> neededPorts() {
final ArrayList<Integer> ports = new ArrayList<>();
Expand Down Expand Up @@ -119,6 +119,10 @@ private Stream<String> portsRule(ClusterState clusterState, Protos.Offer offer)
.map(port -> "required port " + port + " but was not in offer");
}

private Stream<String> diskRule(ClusterState clusterState, Protos.Offer offer) {
return complaintsForResourceType(offer.getResourcesList(), "disk", logstashConfig.getRequiredDiskMegabytes());
}

private boolean portIsInRanges(int port, Protos.Value.Ranges ranges) {
return ranges.getRangeList().stream().anyMatch(range -> new LongRange(range.getBegin(), range.getEnd()).containsLong(port));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,12 @@ public List<Protos.Resource> getResourcesList() {
.setType(Protos.Value.Type.SCALAR)
.setScalar(Protos.Value.Scalar.newBuilder().setValue(memNeeded).build())
.build(),
Protos.Resource.newBuilder()
.setName("disk")
.setType(Protos.Value.Type.SCALAR)
.setScalar(Protos.Value.Scalar.newBuilder()
.setValue(logstashConfig.getRequiredDiskMegabytes()).build())
.build(),
Protos.Resource.newBuilder()
.setName("ports")
.setRole(frameworkConfig.getMesosRole())
Expand Down