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

io.fabric8.kubernetes.api.model.PersistentVolumeSpecBuilder Maven / Gradle / Ivy

The newest version!
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 io.fabric8.kubernetes.api.model.resource.Quantity;
import java.util.HashMap;
import java.util.Map;
import java.util.List;
import java.util.ArrayList;
import io.fabric8.common.VisitableBuilder;
import io.fabric8.common.Visitable;
import io.fabric8.common.Builder;

public class PersistentVolumeSpecBuilder extends PersistentVolumeSpecFluent implements VisitableBuilder{

     PersistentVolumeSpecFluent fluent;
public PersistentVolumeSpecBuilder(){
    this(new PersistentVolumeSpec());
}
public PersistentVolumeSpecBuilder( PersistentVolumeSpecFluent fluent ){
    this(fluent, new PersistentVolumeSpec());
}
public PersistentVolumeSpecBuilder( PersistentVolumeSpecFluent fluent , PersistentVolumeSpec instance ){
    this.fluent = fluent; fluent.withAccessModes(instance.getAccessModes()); fluent.withAwsElasticBlockStore(instance.getAwsElasticBlockStore()); fluent.withCapacity(instance.getCapacity()); fluent.withClaimRef(instance.getClaimRef()); fluent.withGcePersistentDisk(instance.getGcePersistentDisk()); fluent.withGlusterfs(instance.getGlusterfs()); fluent.withHostPath(instance.getHostPath()); fluent.withNfs(instance.getNfs()); fluent.withRbd(instance.getRbd()); 
}
public PersistentVolumeSpecBuilder( PersistentVolumeSpec instance ){
    this.fluent = this; this.withAccessModes(instance.getAccessModes()); this.withAwsElasticBlockStore(instance.getAwsElasticBlockStore()); this.withCapacity(instance.getCapacity()); this.withClaimRef(instance.getClaimRef()); this.withGcePersistentDisk(instance.getGcePersistentDisk()); this.withGlusterfs(instance.getGlusterfs()); this.withHostPath(instance.getHostPath()); this.withNfs(instance.getNfs()); this.withRbd(instance.getRbd()); 
}

public EditablePersistentVolumeSpec build(){
    EditablePersistentVolumeSpec buildable = new EditablePersistentVolumeSpec(fluent.getAccessModes(),fluent.getAwsElasticBlockStore(),fluent.getCapacity(),fluent.getClaimRef(),fluent.getGcePersistentDisk(),fluent.getGlusterfs(),fluent.getHostPath(),fluent.getNfs(),fluent.getRbd());
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