Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automated Generate from openapi release-1.28 #2862

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ public class EventLoggerTest {

@Test
public void buildEventPatch() {
String expectedStr = "2021-03-02T15:02:48.179000Z";
// String expectedStr = "2021-03-02T15:02:48.179000Z";
// TODO(yue99448822): Reset precision to 6 fractional decimal numbers
String expectedStr = "2021-03-02T15:02:48.179Z";
OffsetDateTime expected = OffsetDateTime.parse("2021-03-02T15:02:48.179000Z");
V1Patch patch = EventLogger.buildEventPatch(1, "foo", expected);
assertEquals(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void testDrainNodeNoPods() throws KubectlException, IOException {
wireMockRule.stubFor(
get(urlPathEqualTo("/api/v1/pods"))
.withQueryParam("fieldSelector", equalTo("spec.nodeName=node1"))
.willReturn(aResponse().withStatus(200).withBody("{}")));
.willReturn(aResponse().withStatus(200).withBody("{\"items\":[]}")));
V1Node node = new KubectlDrain().skipDiscovery().apiClient(apiClient).name("node1").execute();
wireMockRule.verify(1, patchRequestedFor(urlPathEqualTo("/api/v1/nodes/node1")));
wireMockRule.verify(1, getRequestedFor(urlPathEqualTo("/api/v1/pods")));
Expand Down
135 changes: 43 additions & 92 deletions fluent/src/main/java/io/kubernetes/client/fluent/BaseFluent.java
Original file line number Diff line number Diff line change
@@ -1,128 +1,79 @@
package io.kubernetes.client.fluent;

import java.util.LinkedHashSet;
import java.util.Map.Entry;
import java.util.stream.Collectors;
import java.util.Set;
import java.util.Optional;
import java.util.ArrayList;
import java.lang.String;
import java.util.AbstractMap;
import java.util.Objects;
import java.lang.Class;
import java.lang.Object;
import java.util.List;
import java.lang.String;
import java.util.Arrays;
import java.util.Collections;
public class BaseFluent<F extends Fluent<F>> implements Fluent<F>,Visitable<F>{
public class BaseFluent<F>{
public static final String VISIT = "visit";
public final VisitableMap _visitables = new VisitableMap();

public static <T>VisitableBuilder<T,?> builderOf(T item) {
if (item instanceof Editable) {
Object editor = ((Editable) item).edit();
if (editor instanceof VisitableBuilder) {
return (VisitableBuilder<T, ?>) editor;
}
}

try {
return (VisitableBuilder<T, ?>) Class.forName(item.getClass().getName() + "Builder", true, item.getClass().getClassLoader()).getConstructor(item.getClass())
.newInstance(item);
} catch (Exception e) {
try {
return (VisitableBuilder<T, ?>) Class.forName(item.getClass().getName() + "Builder").getConstructor(item.getClass())
.newInstance(item);
} catch (Exception e1) {
throw new IllegalStateException("Failed to create builder for: " + item.getClass(), e1);
}
}
Object editor = ((Editable) item).edit();
if (editor instanceof VisitableBuilder) {
return (VisitableBuilder<T, ?>) editor;
}
}

try {
return (VisitableBuilder<T, ?>) Class
.forName(item.getClass().getName() + "Builder", true, item.getClass().getClassLoader())
.getConstructor(item.getClass())
.newInstance(item);
} catch (Exception e) {
try {
return (VisitableBuilder<T, ?>) Class.forName(item.getClass().getName() + "Builder").getConstructor(item.getClass())
.newInstance(item);
} catch (Exception e1) {
throw new IllegalStateException("Failed to create builder for: " + item.getClass(), e1);
}
}
}

public static <T>List<T> build(List<? extends io.kubernetes.client.fluent.Builder<? extends T>> list) {
return list == null ? null : list.stream().map(Builder::build).collect(Collectors.toList());
}

public static <T>Set<T> build(Set<? extends io.kubernetes.client.fluent.Builder<? extends T>> set) {
return set == null ? null : new LinkedHashSet<T>(set.stream().map(Builder::build).collect(Collectors.toSet()));
}

public static <T>List<T> aggregate(List<? extends T>... lists) {
return new ArrayList(Arrays.stream(lists).filter(Objects::nonNull).collect(Collectors.toList()));
}

public static <T>Set<T> aggregate(Set<? extends T>... sets) {
return new LinkedHashSet(Arrays.stream(sets).filter(Objects::nonNull).collect(Collectors.toSet()));
}
public F accept(io.kubernetes.client.fluent.Visitor... visitors) {
return accept(Collections.emptyList(), visitors);
}
public <V>F accept(Class<V> type,Visitor<V> visitor) {
return accept(Collections.emptyList(), new Visitor<V>() {
@Override
public Class<V> getType() {
return type;
}

@Override
public void visit(List<Entry<String, Object>> path, V element) {
visitor.visit(path, element);
}

@Override
public void visit(V element) {
visitor.visit(element);
}
});
}
public F accept(List<Entry<String,Object>> path,io.kubernetes.client.fluent.Visitor... visitors) {
return accept(path, "", visitors);
}
public F accept(List<Entry<String,Object>> path,String currentKey,io.kubernetes.client.fluent.Visitor... visitors) {
List<Visitor> sortedVisitor = new ArrayList<>();
for (Visitor visitor : visitors) {
visitor = VisitorListener.wrap(visitor);
if (!visitor.canVisit(path, this)) {
continue;
}
sortedVisitor.add(visitor);
}
sortedVisitor.sort((l, r) -> ((Visitor) r).order() - ((Visitor) l).order());
for (Visitor visitor : sortedVisitor) {
visitor.visit(path, this);
}

List<Entry<String, Object>> copyOfPath = path != null ? new ArrayList(path) : new ArrayList<>();
copyOfPath.add(new AbstractMap.SimpleEntry<>(currentKey, this));

for (Entry<String, ?> entry : _visitables.entrySet()) {
List<Entry<String, Object>> newPath = Collections.unmodifiableList(copyOfPath);

// Copy visitables to avoid ConcurrentModificationException when Visitors add/remove Visitables
for (Visitable<F> visitable : new ArrayList<>((List<Visitable<F>>) entry.getValue())) {
for (Visitor visitor : visitors) {
if (visitor.getType() != null && visitor.getType().isAssignableFrom(visitable.getClass())) {
visitable.accept(newPath, entry.getKey(), visitor);
}
}

for (Visitor visitor : visitors) {
if (visitor.getType() == null || !visitor.getType().isAssignableFrom(visitable.getClass())) {
visitable.accept(newPath, entry.getKey(), visitor);
}
}
}
}
return (F) this;

public Optional<VisitableMap> getVisitableMap() {
return Optional.of(_visitables);
}

public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + 0;
return result;
int result = 1;
result = prime * result + 0;
return result;
}

public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
return true;
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
return true;
}


}
7 changes: 5 additions & 2 deletions fluent/src/main/java/io/kubernetes/client/fluent/Builder.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package io.kubernetes.client.fluent;

import java.lang.FunctionalInterface;
@FunctionalInterface
public interface Builder<T>{
@FunctionalInterface
public interface Builder<T>{


T build();


}
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,30 @@
public class DelegatingVisitor<T> implements Visitor<T>{
DelegatingVisitor(Class<T> type,Visitor<T> delegate) {
this.type = type;
this.delegate = delegate;
this.delegate = delegate;
}
private final Class<T> type;
private final Visitor<T> delegate;

public Class<T> getType() {
return type;
}

public void visit(T target) {
delegate.visit(target);
}

public int order() {
return delegate.order();
}

public void visit(List<Entry<String,Object>> path,T target) {
delegate.visit(path, target);
}

public <F>Predicate<List<Entry<String,Object>>> getRequirement() {
return delegate.getRequirement();
}


}
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package io.kubernetes.client.fluent;

public interface Editable<T>{


T edit();


}
5 changes: 0 additions & 5 deletions fluent/src/main/java/io/kubernetes/client/fluent/Fluent.java

This file was deleted.

3 changes: 3 additions & 0 deletions fluent/src/main/java/io/kubernetes/client/fluent/Nested.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package io.kubernetes.client.fluent;

public interface Nested<F>{


F and();


}
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,30 @@
public class PathAwareTypedVisitor<V,P> extends TypedVisitor<V>{
PathAwareTypedVisitor() {
List<Class> args = Visitors.getTypeArguments(PathAwareTypedVisitor.class, getClass());
if (args == null || args.isEmpty()) {
throw new IllegalStateException("Could not determine type arguments for path aware typed visitor.");
}
this.type = (Class<V>) args.get(0);
this.parentType = (Class<P>) args.get(1);
if (args == null || args.isEmpty()) {
throw new IllegalStateException("Could not determine type arguments for path aware typed visitor.");
}
this.type = (Class<V>) args.get(0);
this.parentType = (Class<P>) args.get(1);
}
private final Class<V> type;
private final Class<P> parentType;

public void visit(V element) {

}

public void visit(List<Entry<String,Object>> path,V element) {
visit(element);
}

public P getParent(List<Entry<String,Object>> path) {
return path.size() - 1 >= 0 ? (P) path.get(path.size() - 1) : null;
}

public Class<P> getParentType() {
return parentType;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@

import java.lang.Class;
public abstract class TypedVisitor<V> implements Visitor<V>{



public Class<V> getType() {
return (Class<V>) Visitors.getTypeArguments(TypedVisitor.class, getClass()).get(0);
}


}
Loading
Loading