annotations.io.fabric8.kubernetes.api.model.PodStateBuilder Maven / Gradle / Ivy
package io.fabric8.kubernetes.api.model;
import javax.validation.ConstraintViolation;
import javax.validation.Validation;
import javax.validation.Validator;
import javax.validation.ValidatorFactory;
import javax.validation.ValidationException;
import java.util.Set;
import java.util.HashMap;
import java.util.Map;
import java.util.List;
import java.util.ArrayList;
import io.fabric8.common.Builder;
public class PodStateBuilder extends PodStateFluent implements Builder{
private final PodStateFluent> fluent;
public PodStateBuilder(){
this(new PodState());
}
public PodStateBuilder( PodStateFluent> fluent ){
this(fluent, new PodState());
}
public PodStateBuilder( PodStateFluent> fluent , PodState instance ){
this.fluent = fluent; fluent.withCondition(instance.getCondition()); fluent.withHost(instance.getHost()); fluent.withHostIP(instance.getHostIP()); fluent.withInfo(instance.getInfo()); fluent.withManifest(instance.getManifest()); fluent.withMessage(instance.getMessage()); fluent.withPodIP(instance.getPodIP()); fluent.withStatus(instance.getStatus());
}
public PodStateBuilder( PodState instance ){
this.fluent = this; this.withCondition(instance.getCondition()); this.withHost(instance.getHost()); this.withHostIP(instance.getHostIP()); this.withInfo(instance.getInfo()); this.withManifest(instance.getManifest()); this.withMessage(instance.getMessage()); this.withPodIP(instance.getPodIP()); this.withStatus(instance.getStatus());
}
public PodState build(){
PodState buildable = new PodState(fluent.getCondition(),fluent.getHost(),fluent.getHostIP(),fluent.getInfo(),fluent.getManifest(),fluent.getMessage(),fluent.getPodIP(),fluent.getStatus());
validate(buildable);
return buildable;
}
private void validate(T item) {
try {
ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
Validator validator = factory.getValidator();
Set> violations = validator.validate(item);
if (!violations.isEmpty()) {
StringBuilder sb = new StringBuilder();
sb.append("Constraint Violations:\n");
for (ConstraintViolation violation : violations) {
sb.append("\t").append(violation.getRootBeanClass().getSimpleName()).append(" ").append(violation.getPropertyPath()).append(":").append(violation.getMessage()).append("\n");
}
throw new IllegalStateException(sb.toString());
}
} catch(ValidationException e) {
//ignore
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy