io.fabric8.kubernetes.api.model.KubeSchemaBuilder 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 io.fabric8.openshift.api.model.ImageList;
import io.fabric8.kubernetes.api.model.resource.Quantity;
import io.fabric8.openshift.api.model.ImageRepositoryList;
import java.util.Map;
import io.fabric8.openshift.api.model.template.Template;
import io.fabric8.openshift.api.model.BuildList;
import io.fabric8.openshift.api.model.RouteList;
import io.fabric8.openshift.api.model.DeploymentList;
import io.fabric8.openshift.api.model.TagEvent;
import java.util.HashMap;
import io.fabric8.openshift.api.model.config.Config;
import io.fabric8.openshift.api.model.TagEventList;
import io.fabric8.kubernetes.api.model.errors.StatusError;
import io.fabric8.openshift.api.model.BuildConfigList;
import io.fabric8.openshift.api.model.DeploymentConfigList;
import io.fabric8.common.Builder;
public class KubeSchemaBuilder extends KubeSchemaFluent implements Builder{
private final KubeSchemaFluent> fluent;
public KubeSchemaBuilder(){
this(new KubeSchema());
}
public KubeSchemaBuilder( KubeSchemaFluent> fluent ){
this(fluent, new KubeSchema());
}
public KubeSchemaBuilder( KubeSchemaFluent> fluent , KubeSchema instance ){
this.fluent = fluent; fluent.withBuildConfigList(instance.getBuildConfigList()); fluent.withBuildList(instance.getBuildList()); fluent.withConfig(instance.getConfig()); fluent.withContainerStatus(instance.getContainerStatus()); fluent.withDeploymentConfigList(instance.getDeploymentConfigList()); fluent.withDeploymentList(instance.getDeploymentList()); fluent.withEndpoints(instance.getEndpoints()); fluent.withEndpointsList(instance.getEndpointsList()); fluent.withEnvVar(instance.getEnvVar()); fluent.withImageList(instance.getImageList()); fluent.withImageRepositoryList(instance.getImageRepositoryList()); fluent.withKubernetesList(instance.getKubernetesList()); fluent.withMinion(instance.getMinion()); fluent.withMinionList(instance.getMinionList()); fluent.withPodList(instance.getPodList()); fluent.withQuantity(instance.getQuantity()); fluent.withReplicationControllerList(instance.getReplicationControllerList()); fluent.withRouteList(instance.getRouteList()); fluent.withServiceList(instance.getServiceList()); fluent.withStatusError(instance.getStatusError()); fluent.withTagEvent(instance.getTagEvent()); fluent.withTagEventList(instance.getTagEventList()); fluent.withTemplate(instance.getTemplate());
}
public KubeSchemaBuilder( KubeSchema instance ){
this.fluent = this; this.withBuildConfigList(instance.getBuildConfigList()); this.withBuildList(instance.getBuildList()); this.withConfig(instance.getConfig()); this.withContainerStatus(instance.getContainerStatus()); this.withDeploymentConfigList(instance.getDeploymentConfigList()); this.withDeploymentList(instance.getDeploymentList()); this.withEndpoints(instance.getEndpoints()); this.withEndpointsList(instance.getEndpointsList()); this.withEnvVar(instance.getEnvVar()); this.withImageList(instance.getImageList()); this.withImageRepositoryList(instance.getImageRepositoryList()); this.withKubernetesList(instance.getKubernetesList()); this.withMinion(instance.getMinion()); this.withMinionList(instance.getMinionList()); this.withPodList(instance.getPodList()); this.withQuantity(instance.getQuantity()); this.withReplicationControllerList(instance.getReplicationControllerList()); this.withRouteList(instance.getRouteList()); this.withServiceList(instance.getServiceList()); this.withStatusError(instance.getStatusError()); this.withTagEvent(instance.getTagEvent()); this.withTagEventList(instance.getTagEventList()); this.withTemplate(instance.getTemplate());
}
public KubeSchema build(){
KubeSchema buildable = new KubeSchema(fluent.getBuildConfigList(),fluent.getBuildList(),fluent.getConfig(),fluent.getContainerStatus(),fluent.getDeploymentConfigList(),fluent.getDeploymentList(),fluent.getEndpoints(),fluent.getEndpointsList(),fluent.getEnvVar(),fluent.getImageList(),fluent.getImageRepositoryList(),fluent.getKubernetesList(),fluent.getMinion(),fluent.getMinionList(),fluent.getPodList(),fluent.getQuantity(),fluent.getReplicationControllerList(),fluent.getRouteList(),fluent.getServiceList(),fluent.getStatusError(),fluent.getTagEvent(),fluent.getTagEventList(),fluent.getTemplate());
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