forked from fabric8io/kubernetes-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PodOperationContext.java
178 lines (148 loc) · 5.21 KB
/
PodOperationContext.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/**
* Copyright (C) 2015 Red Hat, Inc.
*
* 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.fabric8.kubernetes.client.dsl.internal;
import io.fabric8.kubernetes.client.dsl.ExecListener;
import io.fabric8.kubernetes.client.utils.URLUtils.URLBuilder;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import java.io.InputStream;
import java.io.OutputStream;
@Builder(toBuilder = true)
@NoArgsConstructor
@AllArgsConstructor
@Getter
public class PodOperationContext {
@Getter
public static final class StreamContext {
private OutputStream outputStream;
public StreamContext(OutputStream outputStream) {
this.outputStream = outputStream;
}
public StreamContext() {
}
}
private String containerId;
private StreamContext output;
private StreamContext error;
private StreamContext errorChannel;
private boolean redirectingIn;
private InputStream in;
private boolean tty;
private boolean terminatedStatus;
private boolean timestamps;
private String sinceTimestamp;
private Integer sinceSeconds;
private Integer tailingLines;
private Integer logWaitTimeout;
private boolean prettyOutput;
private ExecListener execListener;
private Integer limitBytes;
private Integer bufferSize;
private String file;
private String dir;
private boolean terminateOnError;
private boolean rolling;
public PodOperationContext withContainerId(String containerId) {
return this.toBuilder().containerId(containerId).build();
}
public PodOperationContext withIn(InputStream in) {
return this.toBuilder().in(in).build();
}
public PodOperationContext withTty(boolean tty) {
return this.toBuilder().tty(tty).build();
}
public PodOperationContext withTerminatedStatus(boolean terminatedStatus) {
return this.toBuilder().terminatedStatus(terminatedStatus).build();
}
public PodOperationContext withTimestamps(boolean timestamps) {
return this.toBuilder().timestamps(timestamps).build();
}
public PodOperationContext withSinceTimestamp(String sinceTimestamp) {
return this.toBuilder().sinceTimestamp(sinceTimestamp).build();
}
public PodOperationContext withSinceSeconds(Integer sinceSeconds) {
return this.toBuilder().sinceSeconds(sinceSeconds).build();
}
public PodOperationContext withTailingLines(Integer tailingLines) {
return this.toBuilder().tailingLines(tailingLines).build();
}
public PodOperationContext withPrettyOutput(boolean prettyOutput) {
return this.toBuilder().prettyOutput(prettyOutput).build();
}
public PodOperationContext withExecListener(ExecListener execListener) {
return this.toBuilder().execListener(execListener).build();
}
public PodOperationContext withLimitBytes(Integer limitBytes) {
return this.toBuilder().limitBytes(limitBytes).build();
}
public PodOperationContext withBufferSize(Integer bufferSize) {
return this.toBuilder().bufferSize(bufferSize).build();
}
public PodOperationContext withFile(String file) {
return this.toBuilder().file(file).build();
}
public PodOperationContext withDir(String dir) {
return this.toBuilder().dir(dir).build();
}
public PodOperationContext withLogWaitTimeout(Integer logWaitTimeout) {
return this.toBuilder().logWaitTimeout(logWaitTimeout).build();
}
public String getLogParameters() {
StringBuilder sb = new StringBuilder();
sb.append("log?pretty=").append(prettyOutput);
if (containerId != null && !containerId.isEmpty()) {
sb.append("&container=").append(containerId);
}
if (terminatedStatus) {
sb.append("&previous=true");
}
if (sinceSeconds != null) {
sb.append("&sinceSeconds=").append(sinceSeconds);
} else if (sinceTimestamp != null) {
sb.append("&sinceTime=").append(sinceTimestamp);
}
if (tailingLines != null) {
sb.append("&tailLines=").append(tailingLines);
}
if (limitBytes != null) {
sb.append("&limitBytes=").append(limitBytes);
}
if (timestamps) {
sb.append("×tamps=true");
}
return sb.toString();
}
public void addQueryParameters(URLBuilder httpUrlBuilder) {
if (containerId != null && !containerId.isEmpty()) {
httpUrlBuilder.addQueryParameter("container", containerId);
}
if (tty) {
httpUrlBuilder.addQueryParameter("tty", "true");
}
if (in != null || redirectingIn) {
httpUrlBuilder.addQueryParameter("stdin", "true");
}
boolean debug = ExecWebSocketListener.LOGGER.isDebugEnabled();
if (output != null || debug) {
httpUrlBuilder.addQueryParameter("stdout", "true");
}
if (error != null || terminateOnError || debug) {
httpUrlBuilder.addQueryParameter("stderr", "true");
}
}
}