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

chore: minimizing methods in handler templates #3301

Merged
merged 1 commit into from
Jul 14, 2021
Merged
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 3 additions & 52 deletions extensions/camel-k/client/src/main/resources/resource-handler.vm
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,15 @@

package io.fabric8.camelk.client.handlers.$apiVersion;

import java.util.function.Predicate;

import io.fabric8.kubernetes.client.Config;
import io.fabric8.kubernetes.client.ResourceHandler;
import io.fabric8.kubernetes.client.Watch;
import io.fabric8.kubernetes.client.Watcher;
import io.fabric8.camelk.client.internal.$apiVersion.${model.name}OperationsImpl;

import io.fabric8.kubernetes.client.dsl.base.OperationContext;
import io.fabric8.kubernetes.client.dsl.Resource;
import okhttp3.OkHttpClient;

import io.fabric8.kubernetes.api.model.DeletionPropagation;
import io.fabric8.kubernetes.api.model.ListOptions;
import ${model.fullyQualifiedName};
import ${model.fullyQualifiedName}Builder;

import java.util.TreeMap;
import java.util.concurrent.TimeUnit;

public class ${model.name}Handler implements ResourceHandler<${model.name}, ${model.name}Builder> {

@Override
Expand All @@ -64,53 +54,14 @@ public class ${model.name}Handler implements ResourceHandler<${model.name}, ${mo
#end
}

@Override
public ${model.name} create(OkHttpClient client, Config config, String namespace, ${model.name} item, boolean dryRun) {
return new ${model.name}OperationsImpl(client, config).withItem(item).inNamespace(namespace).dryRun(dryRun).create();
}

@Override
public ${model.name} replace(OkHttpClient client, Config config, String namespace, ${model.name} item, boolean dryRun) {
return new ${model.name}OperationsImpl(client, config).withItem(item).inNamespace(namespace).withName(item.getMetadata().getName()).dryRun(dryRun).replace(item);
}

@Override
public ${model.name} reload(OkHttpClient client, Config config, String namespace, ${model.name} item) {
return new ${model.name}OperationsImpl(client, config).withItem(item).inNamespace(namespace).withName(item.getMetadata().getName()).fromServer().get();
}

@Override
public ${model.name}Builder edit(${model.name} item) {
return new ${model.name}Builder(item);
}

@Override
public Boolean delete(OkHttpClient client, Config config, String namespace, DeletionPropagation propagationPolicy, long gracePeriodSeconds, ${model.name} item, boolean dryRun) {
return new ${model.name}OperationsImpl(client, config).withItem(item).inNamespace(namespace).withName(item.getMetadata().getName()).dryRun(dryRun).withPropagationPolicy(propagationPolicy).withGracePeriod(gracePeriodSeconds).delete();
}

@Override
public Watch watch(OkHttpClient client, Config config, String namespace, ${model.name} item, Watcher<${model.name}> watcher) {
return new ${model.name}OperationsImpl(client, config).withItem(item).inNamespace(namespace).withName(item.getMetadata().getName()).watch(watcher);
public Resource<${model.name}> resource(OkHttpClient client, Config config, String namespace, ${model.name} item) {
return new ${model.name}OperationsImpl(client, config).withItem(item).inNamespace(namespace).withName(item.getMetadata().getName());
}

@Override
public Watch watch(OkHttpClient client, Config config, String namespace, ${model.name} item, String resourceVersion, Watcher<${model.name}> watcher) {
return new ${model.name}OperationsImpl(client, config).withItem(item).inNamespace(namespace).withName(item.getMetadata().getName()).watch(resourceVersion, watcher);
}

@Override
public Watch watch(OkHttpClient client, Config config, String namespace, ${model.name} item, ListOptions listOptions, Watcher<${model.name}> watcher) {
return new ${model.name}OperationsImpl(client, config).withItem(item).inNamespace(namespace).withName(item.getMetadata().getName()).watch(listOptions, watcher);
}

@Override
public ${model.name} waitUntilReady(OkHttpClient client, Config config, String namespace, ${model.name} item, long amount, TimeUnit timeUnit) throws InterruptedException {
return new ${model.name}OperationsImpl(client, config).withItem(item).inNamespace(namespace).withName(item.getMetadata().getName()).waitUntilReady(amount, timeUnit);
}

@Override
public ${model.name} waitUntilCondition(OkHttpClient client, Config config, String namespace, ${model.name} item, Predicate<${model.name}> condition, long amount, TimeUnit timeUnit) throws InterruptedException {
return new ${model.name}OperationsImpl(client, config).withItem(item).inNamespace(namespace).withName(item.getMetadata().getName()).waitUntilCondition(condition, amount, timeUnit);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,15 @@

package io.fabric8.certmanager.${group}.${apiVersion}.handlers;

import java.util.function.Predicate;

import io.fabric8.kubernetes.client.Config;
import io.fabric8.kubernetes.client.ResourceHandler;
import io.fabric8.kubernetes.client.Watch;
import io.fabric8.kubernetes.client.Watcher;
import io.fabric8.certmanager.client.${group}.${apiVersion}.internal.${model.name}OperationsImpl;

import io.fabric8.kubernetes.client.dsl.base.OperationContext;
import io.fabric8.kubernetes.client.dsl.Resource;
import okhttp3.OkHttpClient;

import io.fabric8.kubernetes.api.model.DeletionPropagation;
import io.fabric8.kubernetes.api.model.ListOptions;
import ${model.fullyQualifiedName};
import ${model.fullyQualifiedName}Builder;

import java.util.TreeMap;
import java.util.concurrent.TimeUnit;

public class ${model.name}Handler implements ResourceHandler<${model.name}, ${model.name}Builder> {

@Override
Expand All @@ -65,53 +55,14 @@ public class ${model.name}Handler implements ResourceHandler<${model.name}, ${mo
#end
}

@Override
public ${model.name} create(OkHttpClient client, Config config, String namespace, ${model.name} item, boolean dryRun) {
return new ${model.name}OperationsImpl(client, config).withItem(item).inNamespace(namespace).dryRun(dryRun).create();
}

@Override
public ${model.name} replace(OkHttpClient client, Config config, String namespace, ${model.name} item, boolean dryRun) {
return new ${model.name}OperationsImpl(client, config).withItem(item).inNamespace(namespace).withName(item.getMetadata().getName()).dryRun(dryRun).replace(item);
}

@Override
public ${model.name} reload(OkHttpClient client, Config config, String namespace, ${model.name} item) {
return new ${model.name}OperationsImpl(client, config).withItem(item).inNamespace(namespace).withName(item.getMetadata().getName()).fromServer().get();
}

@Override
public ${model.name}Builder edit(${model.name} item) {
return new ${model.name}Builder(item);
}

@Override
public Boolean delete(OkHttpClient client, Config config, String namespace, DeletionPropagation propagationPolicy, long gracePeriodSeconds, ${model.name} item, boolean dryRun) {
return new ${model.name}OperationsImpl(client, config).withItem(item).inNamespace(namespace).withName(item.getMetadata().getName()).dryRun(dryRun).withPropagationPolicy(propagationPolicy).withGracePeriod(gracePeriodSeconds).delete();
}

@Override
public Watch watch(OkHttpClient client, Config config, String namespace, ${model.name} item, Watcher<${model.name}> watcher) {
return new ${model.name}OperationsImpl(client, config).withItem(item).inNamespace(namespace).withName(item.getMetadata().getName()).watch(watcher);
public Resource<${model.name}> resource(OkHttpClient client, Config config, String namespace, ${model.name} item) {
return new ${model.name}OperationsImpl(client, config).withItem(item).inNamespace(namespace).withName(item.getMetadata().getName());
}

@Override
public Watch watch(OkHttpClient client, Config config, String namespace, ${model.name} item, String resourceVersion, Watcher<${model.name}> watcher) {
return new ${model.name}OperationsImpl(client, config).withItem(item).inNamespace(namespace).withName(item.getMetadata().getName()).watch(resourceVersion, watcher);
}

@Override
public Watch watch(OkHttpClient client, Config config, String namespace, ${model.name} item, ListOptions listOptions, Watcher<${model.name}> watcher) {
return new ${model.name}OperationsImpl(client, config).withItem(item).inNamespace(namespace).withName(item.getMetadata().getName()).watch(listOptions, watcher);
}

@Override
public ${model.name} waitUntilReady(OkHttpClient client, Config config, String namespace, ${model.name} item, long amount, TimeUnit timeUnit) throws InterruptedException {
return new ${model.name}OperationsImpl(client, config).withItem(item).inNamespace(namespace).withName(item.getMetadata().getName()).waitUntilReady(amount, timeUnit);
}

@Override
public ${model.name} waitUntilCondition(OkHttpClient client, Config config, String namespace, ${model.name} item, Predicate<${model.name}> condition, long amount, TimeUnit timeUnit) throws InterruptedException {
return new ${model.name}OperationsImpl(client, config).withItem(item).inNamespace(namespace).withName(item.getMetadata().getName()).waitUntilCondition(condition, amount, timeUnit);
}
}
55 changes: 3 additions & 52 deletions extensions/chaosmesh/client/src/main/resources/resource-handler.vm
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,15 @@

package io.fabric8.chaosmesh.client.handlers;

import java.util.function.Predicate;

import io.fabric8.kubernetes.client.Config;
import io.fabric8.kubernetes.client.ResourceHandler;
import io.fabric8.kubernetes.client.Watch;
import io.fabric8.kubernetes.client.Watcher;
import io.fabric8.chaosmesh.client.internal.${model.name}OperationsImpl;

import io.fabric8.kubernetes.client.dsl.base.OperationContext;
import io.fabric8.kubernetes.client.dsl.Resource;
import okhttp3.OkHttpClient;

import io.fabric8.kubernetes.api.model.DeletionPropagation;
import io.fabric8.kubernetes.api.model.ListOptions;
import ${model.fullyQualifiedName};
import ${model.fullyQualifiedName}Builder;

import java.util.TreeMap;
import java.util.concurrent.TimeUnit;

public class ${model.name}Handler implements ResourceHandler<${model.name}, ${model.name}Builder> {

@Override
Expand All @@ -64,53 +54,14 @@ public class ${model.name}Handler implements ResourceHandler<${model.name}, ${mo
#end
}

@Override
public ${model.name} create(OkHttpClient client, Config config, String namespace, ${model.name} item, boolean dryRun) {
return new ${model.name}OperationsImpl(client, config).withItem(item).inNamespace(namespace).dryRun(dryRun).create();
}

@Override
public ${model.name} replace(OkHttpClient client, Config config, String namespace, ${model.name} item, boolean dryRun) {
return new ${model.name}OperationsImpl(client, config).withItem(item).inNamespace(namespace).withName(item.getMetadata().getName()).dryRun(dryRun).replace(item);
}

@Override
public ${model.name} reload(OkHttpClient client, Config config, String namespace, ${model.name} item) {
return new ${model.name}OperationsImpl(client, config).withItem(item).inNamespace(namespace).withName(item.getMetadata().getName()).fromServer().get();
}

@Override
public ${model.name}Builder edit(${model.name} item) {
return new ${model.name}Builder(item);
}

@Override
public Boolean delete(OkHttpClient client, Config config, String namespace, DeletionPropagation propagationPolicy, long gracePeriodSeconds, ${model.name} item, boolean dryRun) {
return new ${model.name}OperationsImpl(client, config).withItem(item).inNamespace(namespace).withName(item.getMetadata().getName()).dryRun(dryRun).withPropagationPolicy(propagationPolicy).withGracePeriod(gracePeriodSeconds).delete();
}

@Override
public Watch watch(OkHttpClient client, Config config, String namespace, ${model.name} item, Watcher<${model.name}> watcher) {
return new ${model.name}OperationsImpl(client, config).withItem(item).inNamespace(namespace).withName(item.getMetadata().getName()).watch(watcher);
public Resource<${model.name}> resource(OkHttpClient client, Config config, String namespace, ${model.name} item) {
return new ${model.name}OperationsImpl(client, config).withItem(item).inNamespace(namespace).withName(item.getMetadata().getName());
}

@Override
public Watch watch(OkHttpClient client, Config config, String namespace, ${model.name} item, String resourceVersion, Watcher<${model.name}> watcher) {
return new ${model.name}OperationsImpl(client, config).withItem(item).inNamespace(namespace).withName(item.getMetadata().getName()).watch(resourceVersion, watcher);
}

@Override
public Watch watch(OkHttpClient client, Config config, String namespace, ${model.name} item, ListOptions listOptions, Watcher<${model.name}> watcher) {
return new ${model.name}OperationsImpl(client, config).withItem(item).inNamespace(namespace).withName(item.getMetadata().getName()).watch(listOptions, watcher);
}

@Override
public ${model.name} waitUntilReady(OkHttpClient client, Config config, String namespace, ${model.name} item, long amount, TimeUnit timeUnit) throws InterruptedException {
return new ${model.name}OperationsImpl(client, config).withItem(item).inNamespace(namespace).withName(item.getMetadata().getName()).waitUntilReady(amount, timeUnit);
}

@Override
public ${model.name} waitUntilCondition(OkHttpClient client, Config config, String namespace, ${model.name} item, Predicate<${model.name}> condition, long amount, TimeUnit timeUnit) throws InterruptedException {
return new ${model.name}OperationsImpl(client, config).withItem(item).inNamespace(namespace).withName(item.getMetadata().getName()).waitUntilCondition(condition, amount, timeUnit);
}
}
56 changes: 4 additions & 52 deletions extensions/knative/client/src/main/resources/resource-handler.vm
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,16 @@

package io.fabric8.knative.client.${group}.${apiVersion}.handlers;

import java.util.function.Predicate;

import io.fabric8.kubernetes.client.Config;
import io.fabric8.kubernetes.client.ResourceHandler;
import io.fabric8.kubernetes.client.Watch;
import io.fabric8.kubernetes.client.Watcher;
import io.fabric8.kubernetes.client.dsl.Resource;
import io.fabric8.knative.client.${group}.${apiVersion}.internal.${model.name}OperationsImpl;

import io.fabric8.kubernetes.client.dsl.base.OperationContext;
import okhttp3.OkHttpClient;

import io.fabric8.kubernetes.api.model.DeletionPropagation;
import io.fabric8.kubernetes.api.model.ListOptions;
import ${model.fullyQualifiedName};
import ${model.fullyQualifiedName}Builder;

import java.util.TreeMap;
import java.util.concurrent.TimeUnit;

public class ${model.name}Handler implements ResourceHandler<${model.name}, ${model.name}Builder> {

@Override
Expand All @@ -65,53 +56,14 @@ public class ${model.name}Handler implements ResourceHandler<${model.name}, ${mo
#end
}

@Override
public ${model.name} create(OkHttpClient client, Config config, String namespace, ${model.name} item, boolean dryRun) {
return new ${model.name}OperationsImpl(client, config).withItem(item).inNamespace(namespace).dryRun(dryRun).create();
}

@Override
public ${model.name} replace(OkHttpClient client, Config config, String namespace, ${model.name} item, boolean dryRun) {
return new ${model.name}OperationsImpl(client, config).withItem(item).inNamespace(namespace).withName(item.getMetadata().getName()).dryRun(dryRun).replace(item);
}

@Override
public ${model.name} reload(OkHttpClient client, Config config, String namespace, ${model.name} item) {
return new ${model.name}OperationsImpl(client, config).withItem(item).inNamespace(namespace).withName(item.getMetadata().getName()).fromServer().get();
}

@Override
public ${model.name}Builder edit(${model.name} item) {
return new ${model.name}Builder(item);
}

@Override
public Boolean delete(OkHttpClient client, Config config, String namespace, DeletionPropagation propagationPolicy, long gracePeriodSeconds, ${model.name} item, boolean dryRun) {
return new ${model.name}OperationsImpl(client, config).withItem(item).inNamespace(namespace).withName(item.getMetadata().getName()).dryRun(dryRun).withPropagationPolicy(propagationPolicy).withGracePeriod(gracePeriodSeconds).delete();
}


@Override
public Watch watch(OkHttpClient client, Config config, String namespace, ${model.name} item, Watcher<${model.name}> watcher) {
return new ${model.name}OperationsImpl(client, config).withItem(item).inNamespace(namespace).withName(item.getMetadata().getName()).watch(watcher);
public Resource<${model.name}> resource(OkHttpClient client, Config config, String namespace, ${model.name} item) {
return new ${model.name}OperationsImpl(client, config).withItem(item).inNamespace(namespace).withName(item.getMetadata().getName());
}

@Override
public Watch watch(OkHttpClient client, Config config, String namespace, ${model.name} item, String resourceVersion, Watcher<${model.name}> watcher) {
return new ${model.name}OperationsImpl(client, config).withItem(item).inNamespace(namespace).withName(item.getMetadata().getName()).watch(resourceVersion, watcher);
}

@Override
public Watch watch(OkHttpClient client, Config config, String namespace, ${model.name} item, ListOptions listOptions, Watcher<${model.name}> watcher) {
return new ${model.name}OperationsImpl(client, config).withItem(item).inNamespace(namespace).withName(item.getMetadata().getName()).watch(listOptions, watcher);
}

@Override
public ${model.name} waitUntilReady(OkHttpClient client, Config config, String namespace, ${model.name} item, long amount, TimeUnit timeUnit) throws InterruptedException {
return new ${model.name}OperationsImpl(client, config).withItem(item).inNamespace(namespace).withName(item.getMetadata().getName()).waitUntilReady(amount, timeUnit);
}

@Override
public ${model.name} waitUntilCondition(OkHttpClient client, Config config, String namespace, ${model.name} item, Predicate<${model.name}> condition, long amount, TimeUnit timeUnit) throws InterruptedException {
return new ${model.name}OperationsImpl(client, config).withItem(item).inNamespace(namespace).withName(item.getMetadata().getName()).waitUntilCondition(condition, amount, timeUnit);
}
}
Loading