com.alogic.kube.xscript.api.KubeGet Maven / Gradle / Ivy
package com.alogic.kube.xscript.api;
import com.alogic.kube.model.CommonObject;
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 io.kubernetes.client.openapi.ApiClient;
import io.kubernetes.client.openapi.ApiException;
import okhttp3.Response;
import org.apache.commons.lang3.StringUtils;
import java.io.IOException;
/**
* 查询单个对象
*
* @since 1.6.16.14
*/
public class KubeGet extends KubeQuery {
public KubeGet(String tag, Logiclet p) {
super(tag, p);
}
@Override
public void configure(Properties p){
super.configure(p);
}
@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()) {
CommonObject obj = client.handleResponse(response, CommonObject.class);
if (obj != null){
XsObject newDoc = new JsonObject("root",obj);
onSuperExecute(client,newDoc,newDoc,ctx,watcher);
}
}
}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