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

com.alogic.kube.xscript.api.KubeList Maven / Gradle / Ivy

package com.alogic.kube.xscript.api;

import com.alogic.kube.model.CommonObject;
import com.alogic.kube.model.CommonObjectList;
import com.alogic.xscript.ExecuteWatcher;
import com.alogic.xscript.Logiclet;
import com.alogic.xscript.LogicletContext;
import com.alogic.xscript.doc.XsObject;
import com.alogic.xscript.doc.json.JsonObject;
import com.anysoft.util.Properties;
import com.anysoft.util.PropertiesConstants;
import io.kubernetes.client.openapi.ApiClient;
import io.kubernetes.client.openapi.ApiException;
import okhttp3.Response;
import org.apache.commons.lang3.StringUtils;

import java.io.IOException;
import java.util.List;

/**
 * 查询列表对象
 *
 * @since 1.6.16.14
 */
public class KubeList extends KubeQuery {
    protected String $break = "false";

    public KubeList(String tag, Logiclet p) {
        super(tag, p);
    }

    @Override
    public void configure(Properties p){
        super.configure(p);
        $break = PropertiesConstants.getRaw(p,"break",$break);
    }

    @Override
    protected void onExecute(ApiClient client, XsObject root, XsObject current, LogicletContext ctx, ExecuteWatcher watcher) {
        String path = getApiPath(ctx);
        if (StringUtils.isNotEmpty(path)) {
            Response response = null;
            try {
                response = KubeUtil.queryCall(client,path,this.getListParams(),ctx).execute();

                handleResult(ctx,response);

                if (response.isSuccessful()) {
                    CommonObjectList data = client.handleResponse(response, CommonObjectList.class);
                    if (data != null) {
                        List list = (List) data.getItems();
                        for (CommonObject obj : list) {
                            XsObject newDoc = new JsonObject("root", obj);
                            onSuperExecute(client, newDoc, newDoc, ctx, watcher);
                            boolean toBreak = PropertiesConstants.transform(ctx, $break, false);
                            if (toBreak) {
                                break;
                            }
                        }
                    }
                }
            }catch (IOException ex){
                log(String.format("Kube api call failed:%s",ex.getMessage()));
            }catch (ApiException e) {
                log(String.format("Kube api call failed:%d-%s",e.getCode(),e.getMessage()));
            }finally {
                if (response != null){
                    response.close();
                }
            }
        }else{
            log("Kube path is null,ignored.");
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy