io.alauda.kubernetes.client.dsl.internal.CustomResourceOperationsImpl Maven / Gradle / Ivy
/**
* Copyright (C) 2018 Alauda
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.alauda.kubernetes.client.dsl.internal;
import io.alauda.kubernetes.api.model.Doneable;
import io.alauda.kubernetes.api.model.HasMetadata;
import io.alauda.kubernetes.api.model.KubernetesResource;
import io.alauda.kubernetes.api.model.KubernetesResourceList;
import io.alauda.kubernetes.api.model.apiextensions.CustomResourceDefinition;
import io.alauda.kubernetes.client.Config;
import io.alauda.kubernetes.client.dsl.Gettable;
import io.alauda.kubernetes.client.dsl.MixedOperation;
import io.alauda.kubernetes.client.dsl.NonNamespaceOperation;
import io.alauda.kubernetes.client.dsl.Replaceable;
import io.alauda.kubernetes.client.dsl.Resource;
import io.alauda.kubernetes.client.dsl.base.HasMetadataOperation;
import io.alauda.kubernetes.internal.KubernetesDeserializer;
import okhttp3.OkHttpClient;
import java.io.InputStream;
import java.lang.reflect.InvocationTargetException;
/**
*/
public class CustomResourceOperationsImpl> extends HasMetadataOperation> implements MixedOperation> {
public CustomResourceOperationsImpl(OkHttpClient httpClient, Config configuration, CustomResourceDefinition crd, Class resourceType, Class resourceListType, Class doneType) {
this(httpClient, configuration, apiGroup(crd), apiVersion(crd), resourceT(crd), null, null, false, null, null, false, resourceType, resourceListType, doneType);
}
public CustomResourceOperationsImpl(OkHttpClient client, Config config, String apiGroup, String apiVersion, String resourceT, String namespace, String name, Boolean cascading, T item, String resourceVersion, Boolean reloadingFromServer, Class type, Class listType, Class doneableType) {
super(client, config, apiGroup, apiVersion, resourceT, namespace, name, cascading, item, resourceVersion, reloadingFromServer, type, listType, doneableType);
this.apiGroupVersion = getAPIGroup() + "/" + getAPIVersion();
KubernetesDeserializer.registerCustomKind(type.getSimpleName(), type);
if (KubernetesResource.class.isAssignableFrom(listType)) {
KubernetesDeserializer.registerCustomKind(listType.getSimpleName(), (Class extends KubernetesResource>) listType);
}
}
protected static String apiGroup(CustomResourceDefinition crd) {
return crd.getSpec().getGroup();
}
protected static String apiVersion(CustomResourceDefinition crd) {
return crd.getSpec().getVersion();
}
protected static String resourceT(CustomResourceDefinition crd) {
return crd.getSpec().getNames().getPlural();
}
protected static String name(CustomResourceDefinition crd) {
return crd.getMetadata().getName();
}
@Override
public NonNamespaceOperation> inAnyNamespace() {
return inNamespace(null);
}
@Override
public NonNamespaceOperation> inNamespace(String namespace) {
return new CustomResourceOperationsImpl<>(client, getConfig(), getAPIGroup(), getAPIVersion(), getResourceT(), namespace, getName(), isCascading(), getItem(), getResourceVersion(), isReloadingFromServer(), getType(), getListType(), getDoneableType());
}
@Override
public Resource withName(String name) {
if (name == null || name.length() == 0) {
throw new IllegalArgumentException("Name must be provided.");
}
return new CustomResourceOperationsImpl<>(client, getConfig(), getAPIGroup(), getAPIVersion(), getResourceT(), getNamespace(), name, isCascading(), getItem(), getResourceVersion(), isReloadingFromServer(), getType(), getListType(), getDoneableType());
}
@Override
public Replaceable lockResourceVersion(String resourceVersion) {
return new CustomResourceOperationsImpl<>(client, getConfig(), getAPIGroup(), getAPIVersion(), getResourceT(), getNamespace(), getName(), isCascading(), getItem(), resourceVersion, isReloadingFromServer(), getType(), getListType(), getDoneableType());
}
@Override
protected Resource createItemOperation(T item) throws InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException {
return new CustomResourceOperationsImpl<>(client, getConfig(), getAPIGroup(), getAPIVersion(), getResourceT(), getNamespace(), getName(), isCascading(), item, getResourceVersion(), isReloadingFromServer(), getType(), getListType(), getDoneableType());
}
@Override
public Resource load(InputStream is) {
return new CustomResourceOperationsImpl<>(client, getConfig(), getAPIGroup(), getAPIVersion(), getResourceT(), getNamespace(), getName(), isCascading(), unmarshal(is, getType()), getResourceVersion(), isReloadingFromServer(), getType(), getListType(), getDoneableType());
}
@Override
public Gettable fromServer() {
return new CustomResourceOperationsImpl<>(client, getConfig(), getAPIGroup(), getAPIVersion(), getResourceT(), getNamespace(), getName(), isCascading(), getItem(), getResourceVersion(), true, getType(), getListType(), getDoneableType());
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy