
com.hubspot.mesos.json.MesosResourcesObject Maven / Gradle / Ivy
The newest version!
package com.hubspot.mesos.json;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Map;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.google.common.base.Optional;
import com.google.common.collect.ImmutableMap;
public class MesosResourcesObject {
private final ImmutableMap properties;
@JsonCreator
public MesosResourcesObject(Map properties) {
this.properties = ImmutableMap.copyOf(checkNotNull(properties, "properties is null"));
}
public Optional getNumCpus() {
return getResourceAsInteger("cpus");
}
public Optional getDiskSpace() {
return getResourceAsLong("disk");
}
public Optional getMemoryMegaBytes() {
return getResourceAsInteger("mem");
}
public Optional getPorts() {
return getResourceAsString("ports");
}
public Optional getResourceAsInteger(String resourceName) {
checkNotNull(resourceName, "resourceName is null");
return properties.containsKey(resourceName) ? Optional.of(((Number) properties.get(resourceName)).intValue()) : Optional. absent();
}
public Optional getResourceAsLong(String resourceName) {
checkNotNull(resourceName, "resourceName is null");
return properties.containsKey(resourceName) ? Optional.of(((Number) properties.get(resourceName)).longValue()) : Optional. absent();
}
public Optional getResourceAsString(String resourceName) {
checkNotNull(resourceName, "resourceName is null");
return properties.containsKey(resourceName) ? Optional.of(properties.get(resourceName).toString()) : Optional. absent();
}
public Optional
© 2015 - 2025 Weber Informatics LLC | Privacy Policy