![JAR search and dependency download from the Maven repository](/logo.png)
io.fabric8.kubernetes.api.model.extensions.DeploymentSpecBuilder Maven / Gradle / Ivy
package io.fabric8.kubernetes.api.model.extensions;
import io.fabric8.kubernetes.api.builder.VisitableBuilder;
import java.lang.Boolean;
import javax.validation.Validation;
import javax.validation.Validator;
import javax.validation.ValidatorFactory;
import javax.validation.ValidationException;
import javax.validation.ConstraintViolation;
import javax.validation.ConstraintViolationException;
import java.util.Set;
import java.lang.Object;
public class DeploymentSpecBuilder extends DeploymentSpecFluentImpl implements VisitableBuilder{
DeploymentSpecFluent> fluent;
Boolean validationEnabled;
public DeploymentSpecBuilder(){
this(true);
}
public DeploymentSpecBuilder(Boolean validationEnabled){
this(new DeploymentSpec(), validationEnabled);
}
public DeploymentSpecBuilder(DeploymentSpecFluent> fluent){
this(fluent, true);
}
public DeploymentSpecBuilder(DeploymentSpecFluent> fluent,Boolean validationEnabled){
this(fluent, new DeploymentSpec(), validationEnabled);
}
public DeploymentSpecBuilder(DeploymentSpecFluent> fluent,DeploymentSpec instance){
this(fluent, instance, true);
}
public DeploymentSpecBuilder(DeploymentSpecFluent> fluent,DeploymentSpec instance,Boolean validationEnabled){
this.fluent = fluent;
fluent.withMinReadySeconds(instance.getMinReadySeconds());
fluent.withPaused(instance.getPaused());
fluent.withReplicas(instance.getReplicas());
fluent.withRevisionHistoryLimit(instance.getRevisionHistoryLimit());
fluent.withRollbackTo(instance.getRollbackTo());
fluent.withSelector(instance.getSelector());
fluent.withStrategy(instance.getStrategy());
fluent.withTemplate(instance.getTemplate());
this.validationEnabled = validationEnabled;
}
public DeploymentSpecBuilder(DeploymentSpec instance){
this(instance,true);
}
public DeploymentSpecBuilder(DeploymentSpec instance,Boolean validationEnabled){
this.fluent = this;
this.withMinReadySeconds(instance.getMinReadySeconds());
this.withPaused(instance.getPaused());
this.withReplicas(instance.getReplicas());
this.withRevisionHistoryLimit(instance.getRevisionHistoryLimit());
this.withRollbackTo(instance.getRollbackTo());
this.withSelector(instance.getSelector());
this.withStrategy(instance.getStrategy());
this.withTemplate(instance.getTemplate());
this.validationEnabled = validationEnabled;
}
public DeploymentSpec build(){
DeploymentSpec buildable = new DeploymentSpec(fluent.getMinReadySeconds(),fluent.isPaused(),fluent.getReplicas(),fluent.getRevisionHistoryLimit(),fluent.getRollbackTo(),fluent.getSelector(),fluent.getStrategy(),fluent.getTemplate());
validate(buildable);
return buildable;
}
private void validate(T item){
if (!validationEnabled) { return; }
Validator validator = null;
try {
ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
validator = factory.getValidator();
} catch(ValidationException e) {return;}
Set> violations = validator.validate(item);
if (!violations.isEmpty()) {
throw new ConstraintViolationException(violations);
}
}
public boolean equals(Object o){
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (!super.equals(o)) return false;
DeploymentSpecBuilder that = (DeploymentSpecBuilder) o;
if (fluent != null &&fluent != this ? !fluent.equals(that.fluent) :that.fluent != null &&fluent != this ) return false;
if (validationEnabled != null ? !validationEnabled.equals(that.validationEnabled) :that.validationEnabled != null) return false;
return true;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy