如何使用java客户端连接到Argo工作流



我正在尝试实现argo工作流示例中的一个简单操作(https://github.com/argoproj/argo-workflows/blob/master/sdks/java/client/docs/WorkflowServiceApi.md),我可以用API来做,但我需要从Java应用程序来做。Java SDK似乎甚至没有连接到Argo API。但用户界面正在发挥作用。

public static void main(String[] args) {
ApiClient defaultClient = Configuration.getDefaultApiClient();
String url = "http://xxx.xxx.xxx.xxx:2746";
defaultClient.setBasePath(url);
WorkflowServiceApi apiInstance = new WorkflowServiceApi(defaultClient);
String namespace = "argo"; // String |
String name = "hello-argo"; // String |
String getOptionsResourceVersion = "argoproj.io/v1alpha1"; // String | resourceVersion sets a constraint on what resource versions a request may be served from. See https://kubernetes.io/docs/reference/using-api/api-concepts/#resource-versions for details.  Defaults to unset +optional
String fields = ""; // String | Fields to be included or excluded in the response. e.g. "spec,status.phase", "-status.nodes".
try {
IoArgoprojWorkflowV1alpha1Workflow result = apiInstance.workflowServiceGetWorkflow(namespace, name, getOptionsResourceVersion, fields);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling WorkflowServiceApi#workflowServiceGetWorkflow");
System.err.println("Status code: " + e.getCode());
System.err.println("Reason: " + e.getResponseBody());
System.err.println("Response headers: " + e.getResponseHeaders());
e.printStackTrace();
}
}

错误如下:

Exception when calling WorkflowServiceApi#workflowServiceGetWorkflow
Status code: 0
Reason: null
Response headers: null
io.argoproj.workflow.ApiException: java.io.IOException: unexpected end of stream on http://xxx.xxx.xxx.xxx:2746/...
at io.argoproj.workflow.ApiClient.execute(ApiClient.java:930)
at io.argoproj.workflow.apis.WorkflowServiceApi.workflowServiceGetWorkflowWithHttpInfo(WorkflowServiceApi.java:486)
at io.argoproj.workflow.apis.WorkflowServiceApi.workflowServiceGetWorkflow(WorkflowServiceApi.java:463)
at Argo.main(Argo.java:20)
Caused by: java.io.IOException: unexpected end of stream on http://xxx.xxx.xxx.xxx:2746/...
at okhttp3.internal.http1.Http1ExchangeCodec.readResponseHeaders(Http1ExchangeCodec.kt:202)
at okhttp3.internal.connection.Exchange.readResponseHeaders(Exchange.kt:106)
at okhttp3.internal.http.CallServerInterceptor.intercept(CallServerInterceptor.kt:79)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
at io.argoproj.workflow.ApiClient$2.intercept(ApiClient.java:1267)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.kt:34)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.kt:95)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.kt:83)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.kt:76)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
at okhttp3.internal.connection.RealCall.getResponseWithInterceptorChain$okhttp(RealCall.kt:201)
at okhttp3.internal.connection.RealCall.execute(RealCall.kt:154)
at io.argoproj.workflow.ApiClient.execute(ApiClient.java:926)
... 3 more
Caused by: java.io.EOFException: n not found: limit=0 content=…
at okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.kt:332)
at okhttp3.internal.http1.HeadersReader.readLine(HeadersReader.kt:29)`enter code here`
at okhttp3.internal.http1.Http1ExchangeCodec.readResponseHeaders(Http1ExchangeCodec.kt:178)
... 19 more
import io.argoproj.workflow.ApiClient;
import io.argoproj.workflow.ApiException;
import io.argoproj.workflow.Configuration;
import io.argoproj.workflow.models.*;
import io.argoproj.workflow.apis.WorkflowServiceApi;
import io.kubernetes.client.openapi.models.V1Container;
import io.kubernetes.client.openapi.models.V1ObjectMeta;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
public class Argo {
public static void main(String[] args) {
ApiClient defaultClient = Configuration.getDefaultApiClient();
defaultClient.setVerifyingSsl(false);
String url = "https://xxx.xxx.xxx.xxx:2746";
defaultClient.setBasePath(url);
WorkflowServiceApi apiInstance = new WorkflowServiceApi(defaultClient);
String namespace = "argo"; // String |
WorkflowCreateRequest body = new WorkflowCreateRequest();// WorkflowCreateRequest |
CreateOptions options = new CreateOptions();
Workflow workflow = new Workflow();
workflow.setApiVersion("argoproj.io/v1alpha1");
V1ObjectMeta meta = new V1ObjectMeta();
meta.setNamespace("argo");
meta.setName("hello-java-client");
WorkflowSpec spec = new WorkflowSpec();
spec.setEntrypoint("argosay");
Template template = new Template();
template.setName("argosay");
V1Container v1Container = new V1Container();
v1Container.setName("pod");
v1Container.setImage("docker/whalesay:latest");
v1Container.setCommand(List.of("cowsay"));
v1Container.setArgs(List.of("test java client"));
template.setContainer(v1Container);
spec.setTemplates(List.of(template));
workflow.setMetadata(meta);
workflow.setSpec(spec);
body.setNamespace("argo");
body.setServerDryRun(false);
body.setWorkflow(workflow);
try {
Workflow result = apiInstance.workflowServiceCreateWorkflow(namespace, body);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling WorkflowServiceApi#workflowServiceCreateWorkflow");
System.err.println("Status code: " + e.getCode());
System.err.println("Reason: " + e.getResponseBody());
System.err.println("Response headers: " + e.getResponseHeaders());
e.printStackTrace();
}

尝试字段的一些有意义的值

String fields = "items.spec,items.status.phase";

最新更新