1
- // Copyright 2018, Oracle Corporation and/or its affiliates. All rights reserved.
1
+ // Copyright 2018,2019 Oracle Corporation and/or its affiliates. All rights reserved.
2
2
// Licensed under the Universal Permissive License v 1.0 as shown at
3
3
// http://oss.oracle.com/licenses/upl.
4
4
5
5
package oracle .kubernetes .operator ;
6
6
7
+ import static oracle .kubernetes .operator .KubernetesConstants .CONTAINER_NAME ;
8
+
7
9
import com .google .common .base .Charsets ;
8
10
import com .google .common .io .CharStreams ;
9
11
import io .kubernetes .client .ApiClient ;
10
12
import io .kubernetes .client .ApiException ;
11
- import io .kubernetes .client .Exec ;
12
13
import io .kubernetes .client .models .V1Pod ;
13
14
import java .io .IOException ;
14
15
import java .io .InputStream ;
20
21
import java .util .concurrent .ConcurrentHashMap ;
21
22
import java .util .concurrent .ConcurrentMap ;
22
23
import java .util .concurrent .TimeUnit ;
24
+ import java .util .function .Function ;
23
25
import oracle .kubernetes .operator .helpers .ClientPool ;
24
26
import oracle .kubernetes .operator .helpers .DomainPresenceInfo ;
25
27
import oracle .kubernetes .operator .helpers .ServerKubernetesObjects ;
26
28
import oracle .kubernetes .operator .logging .LoggingFacade ;
27
29
import oracle .kubernetes .operator .logging .LoggingFactory ;
28
30
import oracle .kubernetes .operator .logging .MessageKeys ;
29
31
import oracle .kubernetes .operator .steps .ReadHealthStep ;
32
+ import oracle .kubernetes .operator .utils .KubernetesExec ;
33
+ import oracle .kubernetes .operator .utils .KubernetesExecFactory ;
34
+ import oracle .kubernetes .operator .utils .KubernetesExecFactoryImpl ;
30
35
import oracle .kubernetes .operator .work .NextAction ;
31
36
import oracle .kubernetes .operator .work .Packet ;
32
37
import oracle .kubernetes .operator .work .Step ;
35
40
/** Creates an asynchronous step to read the WebLogic server state from a particular pod */
36
41
public class ServerStatusReader {
37
42
private static final LoggingFacade LOGGER = LoggingFactory .getLogger ("Operator" , "Operator" );
43
+ private static KubernetesExecFactory EXEC_FACTORY = new KubernetesExecFactoryImpl ();
44
+ private static Function <Step , Step > STEP_FACTORY = ReadHealthStep ::createReadHealthStep ;
38
45
39
46
private ServerStatusReader () {}
40
47
41
- public static Step createDomainStatusReaderStep (
48
+ static Step createDomainStatusReaderStep (
42
49
DomainPresenceInfo info , long timeoutSeconds , Step next ) {
43
50
return new DomainStatusReaderStep (info , timeoutSeconds , next );
44
51
}
@@ -47,7 +54,7 @@ private static class DomainStatusReaderStep extends Step {
47
54
private final DomainPresenceInfo info ;
48
55
private final long timeoutSeconds ;
49
56
50
- public DomainStatusReaderStep (DomainPresenceInfo info , long timeoutSeconds , Step next ) {
57
+ DomainStatusReaderStep (DomainPresenceInfo info , long timeoutSeconds , Step next ) {
51
58
super (next );
52
59
this .info = info ;
53
60
this .timeoutSeconds = timeoutSeconds ;
@@ -65,13 +72,13 @@ public NextAction apply(Packet packet) {
65
72
for (Map .Entry <String , ServerKubernetesObjects > entry : info .getServers ().entrySet ()) {
66
73
String serverName = entry .getKey ();
67
74
ServerKubernetesObjects sko = entry .getValue ();
68
- if (sko != null ) {
75
+ if (sko != null ) { // !! Impossible to have a null value in a concurrent map
69
76
V1Pod pod = sko .getPod ().get ();
70
77
if (pod != null ) {
71
78
Packet p = packet .clone ();
72
79
startDetails .add (
73
80
new StepAndPacket (
74
- createServerStatusReaderStep (sko , pod , serverName , timeoutSeconds , null ), p ));
81
+ createServerStatusReaderStep (sko , pod , serverName , timeoutSeconds ), p ));
75
82
}
76
83
}
77
84
}
@@ -90,13 +97,12 @@ public NextAction apply(Packet packet) {
90
97
* @param pod The pod
91
98
* @param serverName Server name
92
99
* @param timeoutSeconds Timeout in seconds
93
- * @param next Next step
94
100
* @return Created step
95
101
*/
96
- public static Step createServerStatusReaderStep (
97
- ServerKubernetesObjects sko , V1Pod pod , String serverName , long timeoutSeconds , Step next ) {
102
+ private static Step createServerStatusReaderStep (
103
+ ServerKubernetesObjects sko , V1Pod pod , String serverName , long timeoutSeconds ) {
98
104
return new ServerStatusReaderStep (
99
- sko , pod , serverName , timeoutSeconds , new ServerHealthStep (serverName , next ));
105
+ sko , pod , serverName , timeoutSeconds , new ServerHealthStep (serverName , null ));
100
106
}
101
107
102
108
private static class ServerStatusReaderStep extends Step {
@@ -105,7 +111,7 @@ private static class ServerStatusReaderStep extends Step {
105
111
private final String serverName ;
106
112
private final long timeoutSeconds ;
107
113
108
- public ServerStatusReaderStep (
114
+ ServerStatusReaderStep (
109
115
ServerKubernetesObjects sko , V1Pod pod , String serverName , long timeoutSeconds , Step next ) {
110
116
super (next );
111
117
this .sko = sko ;
@@ -120,7 +126,7 @@ public NextAction apply(Packet packet) {
120
126
ConcurrentMap <String , String > serverStateMap =
121
127
(ConcurrentMap <String , String >) packet .get (ProcessingConstants .SERVER_STATE_MAP );
122
128
123
- if (PodWatcher .isReady (pod , true )) {
129
+ if (PodWatcher .getReadyStatus (pod )) {
124
130
sko .getLastKnownStatus ().set (WebLogicConstants .RUNNING_STATE );
125
131
serverStateMap .put (serverName , WebLogicConstants .RUNNING_STATE );
126
132
return doNext (packet );
@@ -145,14 +151,10 @@ public NextAction apply(Packet packet) {
145
151
ClientPool helper = ClientPool .getInstance ();
146
152
ApiClient client = helper .take ();
147
153
try {
148
- proc =
149
- new Exec (client )
150
- .exec (
151
- pod ,
152
- new String [] {"/weblogic-operator/scripts/readState.sh" },
153
- KubernetesConstants .CONTAINER_NAME ,
154
- stdin ,
155
- tty );
154
+ KubernetesExec kubernetesExec = EXEC_FACTORY .create (client , pod , CONTAINER_NAME );
155
+ kubernetesExec .setStdin (stdin );
156
+ kubernetesExec .setTty (tty );
157
+ proc = kubernetesExec .exec ("/weblogic-operator/scripts/readState.sh" );
156
158
157
159
InputStream in = proc .getInputStream ();
158
160
if (proc .waitFor (timeoutSeconds , TimeUnit .SECONDS )) {
@@ -179,7 +181,7 @@ public NextAction apply(Packet packet) {
179
181
private static class ServerHealthStep extends Step {
180
182
private final String serverName ;
181
183
182
- public ServerHealthStep (String serverName , Step next ) {
184
+ ServerHealthStep (String serverName , Step next ) {
183
185
super (next );
184
186
this .serverName = serverName ;
185
187
}
@@ -193,7 +195,7 @@ public NextAction apply(Packet packet) {
193
195
194
196
if (WebLogicConstants .STATES_SUPPORTING_REST .contains (state )) {
195
197
packet .put (ProcessingConstants .SERVER_NAME , serverName );
196
- return doNext (ReadHealthStep . createReadHealthStep (getNext ()), packet );
198
+ return doNext (STEP_FACTORY . apply (getNext ()), packet );
197
199
}
198
200
199
201
return doNext (packet );
0 commit comments