4
4
package com .oracle .weblogic .imagetool .aru ;
5
5
6
6
import java .io .File ;
7
+ import java .io .FileNotFoundException ;
7
8
import java .io .IOException ;
8
9
import java .io .StringWriter ;
9
10
import java .net .UnknownHostException ;
10
11
import java .util .ArrayList ;
12
+ import java .util .Collection ;
11
13
import java .util .Collections ;
12
14
import java .util .List ;
15
+ import java .util .stream .Collectors ;
16
+ import java .util .stream .Stream ;
13
17
import javax .xml .xpath .XPathExpressionException ;
14
18
15
19
import com .github .mustachejava .DefaultMustacheFactory ;
30
34
import static com .oracle .weblogic .imagetool .util .Constants .CONFLICTCHECKER_URL ;
31
35
import static com .oracle .weblogic .imagetool .util .Constants .RECOMMENDED_PATCHES_URL ;
32
36
import static com .oracle .weblogic .imagetool .util .Constants .REL_URL ;
37
+ import static com .oracle .weblogic .imagetool .util .Utils .not ;
33
38
34
39
public class AruUtil {
35
40
@@ -135,7 +140,10 @@ List<AruPatch> getLatestPsu(AruProduct product, String version, String userId, S
135
140
Document aruRecommendations = retry (
136
141
() -> getRecommendedPatchesMetadata (product , releaseNumber , userId , password ));
137
142
logger .exiting ();
138
- return AruPatch .removeStackPatchBundle (AruPatch .getPatches (aruRecommendations , "[./psu_bundle]" ));
143
+ return AruPatch .getPatches (aruRecommendations )
144
+ .filter (AruPatch ::isPsu )
145
+ .filter (not (AruPatch ::isStackPatchBundle ))
146
+ .collect (Collectors .toList ());
139
147
} catch (NoPatchesFoundException | ReleaseNotFoundException ex ) {
140
148
logger .exiting ();
141
149
return Collections .emptyList ();
@@ -158,7 +166,21 @@ public List<AruPatch> getRecommendedPatches(FmwInstallerType type, String versio
158
166
List <AruPatch > result = new ArrayList <>();
159
167
for (AruProduct product : type .products ()) {
160
168
List <AruPatch > patches = getRecommendedPatches (product , version , userId , password );
169
+ // temporary, until OHS stops using same release number and product ID for two different installs
170
+ if (type == FmwInstallerType .OHS ) {
171
+ if (product == AruProduct .OHS ) {
172
+ patches = patches .stream ().filter (p -> p .description ().contains (" DB19C " ))
173
+ .collect (Collectors .toList ());
174
+ } else if (product == AruProduct .OAM_WG ) {
175
+ patches = patches .stream ().filter (p -> p .description ().contains (" DB19c " ))
176
+ .collect (Collectors .toList ());
177
+ } else if (product == AruProduct .OSS ) {
178
+ patches = patches .stream ().filter (p -> p .description ().contains (" 19C " ))
179
+ .collect (Collectors .toList ());
180
+ }
181
+ }
161
182
if (!patches .isEmpty ()) {
183
+ patches .forEach (p -> logger .info ("IMG-0068" , product .description (), p .patchId (), p .description ()));
162
184
result .addAll (patches );
163
185
}
164
186
}
@@ -186,9 +208,15 @@ List<AruPatch> getRecommendedPatches(AruProduct product, String version, String
186
208
String releaseNumber = getReleaseNumber (product , version , userId , password );
187
209
Document aruRecommendations = retry (
188
210
() -> getRecommendedPatchesMetadata (product , releaseNumber , userId , password ));
189
- List <AruPatch > patches = AruPatch .removeStackPatchBundle (AruPatch .getPatches (aruRecommendations ));
190
- String psuVersion = getPsuVersion (patches );
191
- if (!Utils .isEmptyString (psuVersion )) {
211
+ // TODO: Need an option for the user to request the Coherence additional feature pack.
212
+ List <AruPatch > patches = AruPatch .getPatches (aruRecommendations )
213
+ .filter (not (AruPatch ::isStackPatchBundle )) //remove Stack Patch Bundle
214
+ .filter (not (AruPatch ::isCoherenceFeaturePack )) //remove COH feature pack
215
+ .collect (Collectors .toList ());
216
+ String psuVersion = getPsuVersion (product .description (), patches );
217
+ if (psuVersion != null ) {
218
+ //repeat the same process to get recommended patches, but use the PSU release instead of the GA release
219
+ // All the same patches are in the PSU release, but also the overlay patches (if any)
192
220
patches .forEach (p -> logger .fine ("Discarding recommended patch {0} {1}" , p .patchId (), p .description ()));
193
221
logger .fine ("Recommended patch list contains a PSU, getting recommendations for PSU version {0}" ,
194
222
psuVersion );
@@ -198,11 +226,11 @@ List<AruPatch> getRecommendedPatches(AruProduct product, String version, String
198
226
Document psuOverrides = retry (
199
227
() -> getRecommendedPatchesMetadata (product , psuReleaseNumber , userId , password ));
200
228
201
- patches = AruPatch .removeStackPatchBundle (AruPatch .getPatches (psuOverrides ));
229
+ patches = AruPatch .getPatches (psuOverrides )
230
+ .filter (not (AruPatch ::isStackPatchBundle )) // remove the Stack Patch Bundle patch, if returned
231
+ .filter (not (AruPatch ::isCoherenceFeaturePack )) // remove the Coherence feature pack, if returned
232
+ .collect (Collectors .toList ());
202
233
}
203
- // TODO: Need an option for the user to request the Coherence additional feature pack.
204
- patches = AruPatch .removeCoherenceFeaturePackPatch (patches );
205
- patches .forEach (p -> logger .info ("IMG-0068" , product .description (), p .patchId (), p .description ()));
206
234
logger .exiting (patches );
207
235
return patches ;
208
236
} catch (ReleaseNotFoundException nf ) {
@@ -215,13 +243,15 @@ List<AruPatch> getRecommendedPatches(AruProduct product, String version, String
215
243
}
216
244
}
217
245
218
- private String getPsuVersion (List <AruPatch > patches ) {
219
- for (AruPatch patch : patches ) {
220
- if (patch .isPsu ()) {
221
- // expected pattern "Oracle WebLogic Server 12.2.1.x.xxxxxx"
222
- String [] strings = patch .psuBundle ().split (" " );
223
- return strings [strings .length - 1 ];
224
- }
246
+ private String getPsuVersion (String productName , Collection <AruPatch > patches ) {
247
+ String psuBundle = patches .stream ()
248
+ .map (AruPatch ::psuBundle )
249
+ .filter (not (Utils ::isEmptyString ))
250
+ .findFirst ()
251
+ .orElse (null );
252
+
253
+ if (psuBundle != null ) {
254
+ return psuBundle .substring (productName .length () + 1 );
225
255
}
226
256
return null ;
227
257
}
@@ -435,12 +465,12 @@ List<List<String>> getPatchConflictSets(Document conflictCheckResult) throws IOE
435
465
* @throws IOException if there is an error retrieving the XML from ARU
436
466
* @throws XPathExpressionException if AruPatch failed while extracting patch data from the XML
437
467
*/
438
- public List <AruPatch > getPatches (String bugNumber , String userId , String password )
468
+ public Stream <AruPatch > getPatches (String bugNumber , String userId , String password )
439
469
throws AruException , IOException , XPathExpressionException {
440
470
441
471
if (userId == null || password == null ) {
442
472
// running in offline mode (no credentials to connect to ARU)
443
- return Collections . singletonList (new AruPatch ().patchId (bugNumber ));
473
+ return Stream . of (new AruPatch ().patchId (bugNumber ));
444
474
}
445
475
446
476
String url = String .format (BUG_SEARCH_URL , bugNumber );
@@ -467,6 +497,18 @@ public List<AruPatch> getPatches(String bugNumber, String userId, String passwor
467
497
468
498
public String downloadAruPatch (AruPatch aruPatch , String targetDir , String username , String password )
469
499
throws IOException {
500
+ try {
501
+ return retry (() -> downloadPatch (aruPatch , targetDir , username , password ));
502
+ } catch (AruException | RetryFailedException e ) {
503
+ logger .severe ("IMG-0120" );
504
+ throw logger .throwing (
505
+ new FileNotFoundException (Utils .getMessage ("IMG-0037" , aruPatch .patchId (), aruPatch .version ())));
506
+ }
507
+
508
+ }
509
+
510
+ private String downloadPatch (AruPatch aruPatch , String targetDir , String username , String password )
511
+ throws IOException {
470
512
471
513
logger .entering (aruPatch );
472
514
@@ -507,12 +549,16 @@ public int getRetryInterval() {
507
549
return restInterval ;
508
550
}
509
551
510
- private interface CallToRetry {
511
- Document process () throws IOException , XPathExpressionException , AruException ;
552
+ /**
553
+ * Similar to java.util.function.Supplier.
554
+ * @param <T> return type of the supplied method.
555
+ */
556
+ private interface MethodToRetry <T > {
557
+ T process () throws IOException , XPathExpressionException , AruException ;
512
558
}
513
559
514
560
// create an environment variable that can override the tries count (undocumented)
515
- private static Document retry (CallToRetry call ) throws AruException , RetryFailedException {
561
+ private static < T > T retry (MethodToRetry < T > call ) throws AruException , RetryFailedException {
516
562
for (int i = 0 ; i < rest ().getMaxRetries (); i ++) {
517
563
try {
518
564
return call .process ();
0 commit comments