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

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

There is a newer version: 0.0.54
Show 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.openshift.api.model.BuildConfig;
import io.fabric8.openshift.api.model.OAuthClient;
import io.fabric8.openshift.api.model.DeploymentConfig;
import java.util.Map;
import io.fabric8.openshift.api.model.ImageStream;
import java.util.List;
import io.fabric8.openshift.api.model.template.Template;
import java.util.HashMap;
import io.fabric8.openshift.api.model.OAuthAccessToken;
import io.fabric8.openshift.api.model.OAuthClientAuthorization;
import io.fabric8.openshift.api.model.Route;
import java.util.ArrayList;
import io.fabric8.common.Builder;

public class KubernetesListBuilder extends KubernetesListFluent implements Builder{

     KubernetesListFluent fluent;
public KubernetesListBuilder(){
    this(new KubernetesList());
}
public KubernetesListBuilder( KubernetesListFluent fluent ){
    this(fluent, new KubernetesList());
}
public KubernetesListBuilder( KubernetesListFluent fluent , KubernetesList instance ){
    this.fluent = fluent; fluent.withApiVersion(instance.getApiVersion()); fluent.withItems(instance.getItems()); fluent.withKind(instance.getKind()); fluent.withMetadata(instance.getMetadata()); fluent.withServices(instance.getServices()); fluent.withReplicationControllers(instance.getReplicationControllers()); fluent.withPods(instance.getPods()); fluent.withBuildConfigs(instance.getBuildConfigs()); fluent.withDeploymentConfigs(instance.getDeploymentConfigs()); fluent.withImageStreams(instance.getImageStreams()); fluent.withRoutes(instance.getRoutes()); fluent.withTemplates(instance.getTemplates()); fluent.withOAuthClients(instance.getOAuthClients()); fluent.withOAuthClientAuthorizations(instance.getOAuthClientAuthorizations()); fluent.withOAuthAccessTokens(instance.getOAuthAccessTokens()); fluent.withNamespaces(instance.getNamespaces()); fluent.withSecrets(instance.getSecrets()); 
}
public KubernetesListBuilder( KubernetesList instance ){
    this.fluent = this; this.withApiVersion(instance.getApiVersion()); this.withItems(instance.getItems()); this.withKind(instance.getKind()); this.withMetadata(instance.getMetadata()); this.withServices(instance.getServices()); this.withReplicationControllers(instance.getReplicationControllers()); this.withPods(instance.getPods()); this.withBuildConfigs(instance.getBuildConfigs()); this.withDeploymentConfigs(instance.getDeploymentConfigs()); this.withImageStreams(instance.getImageStreams()); this.withRoutes(instance.getRoutes()); this.withTemplates(instance.getTemplates()); this.withOAuthClients(instance.getOAuthClients()); this.withOAuthClientAuthorizations(instance.getOAuthClientAuthorizations()); this.withOAuthAccessTokens(instance.getOAuthAccessTokens()); this.withNamespaces(instance.getNamespaces()); this.withSecrets(instance.getSecrets()); 
}

public KubernetesList build(){
    KubernetesList buildable = new KubernetesList(fluent.getApiVersion(),fluent.getItems(),fluent.getKind(),fluent.getMetadata(),fluent.getServices(),fluent.getReplicationControllers(),fluent.getPods(),fluent.getBuildConfigs(),fluent.getDeploymentConfigs(),fluent.getImageStreams(),fluent.getRoutes(),fluent.getTemplates(),fluent.getOAuthClients(),fluent.getOAuthClientAuthorizations(),fluent.getOAuthAccessTokens(),fluent.getNamespaces(),fluent.getSecrets());
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 - 2024 Weber Informatics LLC | Privacy Policy