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

dev.galasa.kubernetes.internal.resources.StatefulSetImpl Maven / Gradle / Ivy

There is a newer version: 0.34.0
Show newest version
/*
 * Licensed Materials - Property of IBM
 * 
 * (c) Copyright IBM Corp. 2020.
 */
package dev.galasa.kubernetes.internal.resources;

import java.util.List;

import dev.galasa.kubernetes.IPodLog;
import dev.galasa.kubernetes.IStatefulSet;
import dev.galasa.kubernetes.KubernetesManagerException;
import dev.galasa.kubernetes.internal.KubernetesNamespaceImpl;
import io.kubernetes.client.openapi.apis.AppsV1Api;
import io.kubernetes.client.openapi.models.V1StatefulSet;
import io.kubernetes.client.util.Yaml;

/**
 * StatefulSet implementation
 * 
 * @author Michael Baylis
 *
 */
public class StatefulSetImpl extends ReplicaSetHolder implements IStatefulSet {
    
    private final KubernetesNamespaceImpl namespace;
    private V1StatefulSet statefulSet;

    public StatefulSetImpl(KubernetesNamespaceImpl namespace, V1StatefulSet deployment) {
        this.namespace   = namespace;
        this.statefulSet = deployment;
    }

    @Override
    public String getName() {
        return statefulSet.getMetadata().getName();
    }

    @Override
    public TYPE getType() {
        return TYPE.StatefulSet;
    }

    @Override
    public String getYaml() {
        return Yaml.dump(this.statefulSet);
    }
    
    @Override
    public void refresh() throws KubernetesManagerException {
       try {
           AppsV1Api api = new AppsV1Api(namespace.getCluster().getApi());
           
           V1StatefulSet newSet = api.readNamespacedStatefulSet(getName(), namespace.getId(), null, null, null);
           
           this.statefulSet = newSet;
       } catch(Exception e) {
           throw new KubernetesManagerException("Problem refreshing the resource YAML", e);
       }
    }

    @Override
    public List getPodLogs(String container) throws KubernetesManagerException {
        if (statefulSet.getSpec() == null || statefulSet.getSpec().getSelector() == null) {
            throw new KubernetesManagerException("Missing Selector");
        }

        return getPodLogs(this.namespace.getCluster().getApi(), this.statefulSet.getSpec().getSelector(), this.namespace.getId(), container);
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy