All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.fabric8.kubernetes.api.model.VolumeSourceBuilder 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 io.fabric8.common.Builder;

public class VolumeSourceBuilder extends VolumeSourceFluent implements Builder{

private final VolumeSourceFluent fluent;

public VolumeSourceBuilder(){
    this(new VolumeSource());
}
public VolumeSourceBuilder( VolumeSourceFluent fluent ){
    this(fluent, new VolumeSource());
}
public VolumeSourceBuilder( VolumeSourceFluent fluent , VolumeSource instance ){
    this.fluent = fluent; fluent.withEmptyDir(instance.getEmptyDir()); fluent.withGitRepo(instance.getGitRepo()); fluent.withGlusterfs(instance.getGlusterfs()); fluent.withHostDir(instance.getHostDir()); fluent.withIscsi(instance.getIscsi()); fluent.withNfs(instance.getNfs()); fluent.withPersistentDisk(instance.getPersistentDisk()); fluent.withSecret(instance.getSecret()); 
}
public VolumeSourceBuilder( VolumeSource instance ){
    this.fluent = this; this.withEmptyDir(instance.getEmptyDir()); this.withGitRepo(instance.getGitRepo()); this.withGlusterfs(instance.getGlusterfs()); this.withHostDir(instance.getHostDir()); this.withIscsi(instance.getIscsi()); this.withNfs(instance.getNfs()); this.withPersistentDisk(instance.getPersistentDisk()); this.withSecret(instance.getSecret()); 
}

public VolumeSource build(){
    VolumeSource buildable = new VolumeSource(fluent.getEmptyDir(),fluent.getGitRepo(),fluent.getGlusterfs(),fluent.getHostDir(),fluent.getIscsi(),fluent.getNfs(),fluent.getPersistentDisk(),fluent.getSecret());
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