44package com .oracle .weblogic .imagetool .aru ;
55
66import java .io .File ;
7+ import java .io .FileNotFoundException ;
78import java .io .IOException ;
89import java .io .StringWriter ;
910import java .net .UnknownHostException ;
1011import java .util .ArrayList ;
12+ import java .util .Collection ;
1113import java .util .Collections ;
1214import java .util .List ;
15+ import java .util .stream .Collectors ;
16+ import java .util .stream .Stream ;
1317import javax .xml .xpath .XPathExpressionException ;
1418
1519import com .github .mustachejava .DefaultMustacheFactory ;
3034import static com .oracle .weblogic .imagetool .util .Constants .CONFLICTCHECKER_URL ;
3135import static com .oracle .weblogic .imagetool .util .Constants .RECOMMENDED_PATCHES_URL ;
3236import static com .oracle .weblogic .imagetool .util .Constants .REL_URL ;
37+ import static com .oracle .weblogic .imagetool .util .Utils .not ;
3338
3439public class AruUtil {
3540
@@ -135,7 +140,10 @@ List<AruPatch> getLatestPsu(AruProduct product, String version, String userId, S
135140 Document aruRecommendations = retry (
136141 () -> getRecommendedPatchesMetadata (product , releaseNumber , userId , password ));
137142 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 ());
139147 } catch (NoPatchesFoundException | ReleaseNotFoundException ex ) {
140148 logger .exiting ();
141149 return Collections .emptyList ();
@@ -158,7 +166,21 @@ public List<AruPatch> getRecommendedPatches(FmwInstallerType type, String versio
158166 List <AruPatch > result = new ArrayList <>();
159167 for (AruProduct product : type .products ()) {
160168 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+ }
161182 if (!patches .isEmpty ()) {
183+ patches .forEach (p -> logger .info ("IMG-0068" , product .description (), p .patchId (), p .description ()));
162184 result .addAll (patches );
163185 }
164186 }
@@ -186,9 +208,15 @@ List<AruPatch> getRecommendedPatches(AruProduct product, String version, String
186208 String releaseNumber = getReleaseNumber (product , version , userId , password );
187209 Document aruRecommendations = retry (
188210 () -> 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)
192220 patches .forEach (p -> logger .fine ("Discarding recommended patch {0} {1}" , p .patchId (), p .description ()));
193221 logger .fine ("Recommended patch list contains a PSU, getting recommendations for PSU version {0}" ,
194222 psuVersion );
@@ -198,11 +226,11 @@ List<AruPatch> getRecommendedPatches(AruProduct product, String version, String
198226 Document psuOverrides = retry (
199227 () -> getRecommendedPatchesMetadata (product , psuReleaseNumber , userId , password ));
200228
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 ());
202233 }
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 ()));
206234 logger .exiting (patches );
207235 return patches ;
208236 } catch (ReleaseNotFoundException nf ) {
@@ -215,13 +243,15 @@ List<AruPatch> getRecommendedPatches(AruProduct product, String version, String
215243 }
216244 }
217245
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 );
225255 }
226256 return null ;
227257 }
@@ -435,12 +465,12 @@ List<List<String>> getPatchConflictSets(Document conflictCheckResult) throws IOE
435465 * @throws IOException if there is an error retrieving the XML from ARU
436466 * @throws XPathExpressionException if AruPatch failed while extracting patch data from the XML
437467 */
438- public List <AruPatch > getPatches (String bugNumber , String userId , String password )
468+ public Stream <AruPatch > getPatches (String bugNumber , String userId , String password )
439469 throws AruException , IOException , XPathExpressionException {
440470
441471 if (userId == null || password == null ) {
442472 // 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 ));
444474 }
445475
446476 String url = String .format (BUG_SEARCH_URL , bugNumber );
@@ -467,6 +497,18 @@ public List<AruPatch> getPatches(String bugNumber, String userId, String passwor
467497
468498 public String downloadAruPatch (AruPatch aruPatch , String targetDir , String username , String password )
469499 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 {
470512
471513 logger .entering (aruPatch );
472514
@@ -507,12 +549,16 @@ public int getRetryInterval() {
507549 return restInterval ;
508550 }
509551
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 ;
512558 }
513559
514560 // 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 {
516562 for (int i = 0 ; i < rest ().getMaxRetries (); i ++) {
517563 try {
518564 return call .process ();
0 commit comments