com.liveperson.ephemerals.deploy.unit.DeploymentUnit Maven / Gradle / Ivy
package com.liveperson.ephemerals.deploy.unit;
import com.liveperson.ephemerals.deploy.DeploymentPort;
import com.liveperson.ephemerals.deploy.probe.Probe;
import com.liveperson.ephemerals.deploy.volume.Volume;
import com.liveperson.ephemerals.deploy.volume.VolumeMount;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Specification of deployment resources, runtime, network and health check.
*
* Created by waseemh on 9/4/16.
*/
public class DeploymentUnit {
/**
* Namespace of deployment unit
*/
private final String name;
/**
* Health Probe
*/
private final Probe healthProbe;
/**
* Readiness Probe
*/
private final Probe readinessProbe;
/**
* Deployment unit ports
*/
private final List ports;
/**
* CPU resource requirements
*/
private final double cpu;
/**
* Memory resource requirements
*/
private final int mem;
/**
* Commandline arguments
*/
private final Map cmdArgs;
/**
* Environment variables
*/
private final Map envVars;
/**
* Volumes
*/
private final Map volumes;
public DeploymentUnit(Builder builder) {
this.name = builder.name;
this.healthProbe = builder.healthProbe;
this.readinessProbe = builder.readinessProbe;
this.ports = builder.ports;
this.cpu = builder.cpu;
this.mem = builder.mem;
this.cmdArgs = builder.cmdArgs;
this.envVars = builder.envVars;
this.volumes = builder.volumes;
}
public double getCpu() {
return cpu;
}
public int getMem() {
return mem;
}
public Map getCmdArgs() {
return cmdArgs;
}
public Map getEnvVars() {
return envVars;
}
public String getName() {
return name;
}
public Probe getHealthProbe() {
return healthProbe;
}
public Probe getReadinessProbe() {return readinessProbe; }
public List getPorts() {
return ports;
}
public Map getVolumes() { return volumes; }
public static class Builder {
private String name;
private Probe healthProbe;
private Probe readinessProbe;
private List ports = new ArrayList<>();
private double cpu = 0.5;
private int mem = 1024;
private Map cmdArgs = new HashMap<>();
private Map envVars = new HashMap<>();
private Map volumes = new HashMap<>();
public Builder(String name) {
this.name = name;
}
public Builder withHealthProbe(Probe probe) {
this.healthProbe = probe;
return this;
}
public Builder withReadinessProbe(Probe probe) {
this.readinessProbe = probe;
return this;
}
public Builder withPorts(List ports) {
this.ports.addAll(ports);
return this;
}
public Builder withPort(DeploymentPort port) {
this.ports.add(port);
return this;
}
public Builder withCpu(double cpu) {
this.cpu = cpu;
return this;
}
public Builder withMem(int mem) {
this.mem = mem;
return this;
}
public Builder withCmdArgs(Map cmdArgs) {
this.cmdArgs.putAll(cmdArgs);
return this;
}
public Builder withCmdArg(String key, String value) {
this.cmdArgs.put(key,value);
return this;
}
public Builder withEnvVars(Map envVars) {
this.envVars.putAll(envVars);
return this;
}
public Builder withEnvVar(String key, String value) {
this.envVars.put(key,value);
return this;
}
public Builder withVolume(VolumeMount volumeMount, Volume volume) {
this.volumes.put(volumeMount,volume);
return this;
}
public DeploymentUnit build() {
return new DeploymentUnit(this);
}
}
}