diff --git a/imagetool/src/main/java/com/oracle/weblogic/imagetool/aru/InstalledPatch.java b/imagetool/src/main/java/com/oracle/weblogic/imagetool/aru/InstalledPatch.java index 64bf982e..5cae6aad 100644 --- a/imagetool/src/main/java/com/oracle/weblogic/imagetool/aru/InstalledPatch.java +++ b/imagetool/src/main/java/com/oracle/weblogic/imagetool/aru/InstalledPatch.java @@ -10,6 +10,7 @@ import com.oracle.weblogic.imagetool.logging.LoggingFacade; import com.oracle.weblogic.imagetool.logging.LoggingFactory; +import com.oracle.weblogic.imagetool.util.Utils; public class InstalledPatch { private static final LoggingFacade logger = LoggingFactory.getLogger(InstalledPatch.class); @@ -25,10 +26,14 @@ public class InstalledPatch { * @return a simple list of InstalledPatch */ public static List getPatchList(String oraclePatches) { + logger.entering(oraclePatches); List result = new ArrayList<>(); + if (Utils.isEmptyString(oraclePatches)) { + return result; + } String[] tokens = oraclePatches.split(";"); if (tokens.length % 3 != 0) { - logger.severe("Too many tokens in oracle patches " + tokens.length); + logger.severe("IMG-0095", tokens.length); } for (int i = 0; i < tokens.length; i++) { InstalledPatch found = new InstalledPatch(); @@ -42,6 +47,7 @@ public static List getPatchList(String oraclePatches) { result.add(found); } + logger.exiting(result.size()); return result; } diff --git a/imagetool/src/main/java/com/oracle/weblogic/imagetool/cli/menu/UpdateImage.java b/imagetool/src/main/java/com/oracle/weblogic/imagetool/cli/menu/UpdateImage.java index b13d0db4..f94a381c 100644 --- a/imagetool/src/main/java/com/oracle/weblogic/imagetool/cli/menu/UpdateImage.java +++ b/imagetool/src/main/java/com/oracle/weblogic/imagetool/cli/menu/UpdateImage.java @@ -141,8 +141,9 @@ public CommandResponse call() throws Exception { return new CommandResponse(-1, "IMG-0055"); } - FmwInstallerType installerType = FmwInstallerType.fromValue( - baseImageProperties.getProperty("wlsType", "WLS")); + FmwInstallerType installerType = FmwInstallerType.fromProductList( + baseImageProperties.getProperty("oracleInstalledProducts")); + logger.info("IMG-0094", installerType); // resolve required patches handlePatchFiles(installerType, installedPatches); diff --git a/imagetool/src/main/java/com/oracle/weblogic/imagetool/installer/FmwInstallerType.java b/imagetool/src/main/java/com/oracle/weblogic/imagetool/installer/FmwInstallerType.java index b2f7d3a7..e8177947 100644 --- a/imagetool/src/main/java/com/oracle/weblogic/imagetool/installer/FmwInstallerType.java +++ b/imagetool/src/main/java/com/oracle/weblogic/imagetool/installer/FmwInstallerType.java @@ -6,9 +6,13 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; +import java.util.Set; import java.util.stream.Collectors; +import java.util.stream.Stream; import com.oracle.weblogic.imagetool.aru.AruProduct; +import com.oracle.weblogic.imagetool.logging.LoggingFacade; +import com.oracle.weblogic.imagetool.logging.LoggingFactory; import com.oracle.weblogic.imagetool.util.Utils; /** @@ -20,63 +24,63 @@ public enum FmwInstallerType { // data from https://updates.oracle.com/Orion/Services/metadata?table=aru_products // Oracle WebLogic Server - WLS(Arrays.asList(AruProduct.WLS, AruProduct.COH, AruProduct.FMWPLAT), + WLS(Utils.toSet(AruProduct.WLS, AruProduct.COH, AruProduct.FMWPLAT), InstallerType.WLS), - WLSSLIM(Utils.list(WLS.products), + WLSSLIM(Utils.toSet(WLS.products), InstallerType.WLSSLIM), - WLSDEV(Utils.list(WLS.products), + WLSDEV(Utils.toSet(WLS.products), InstallerType.WLSDEV), // Oracle WebLogic Server Infrastructure (JRF) - FMW(Utils.list(WLS.products, AruProduct.JRF, AruProduct.JDEV), + FMW(Utils.toSet(WLS.products, AruProduct.JRF, AruProduct.JDEV), InstallerType.FMW), // Oracle Service Bus - OSB(Utils.list(FMW.products, AruProduct.OSB), + OSB(Utils.toSet(FMW.products, AruProduct.OSB), InstallerType.FMW, InstallerType.OSB), // Oracle SOA Suite - SOA(Utils.list(FMW.products, AruProduct.SOA), + SOA(Utils.toSet(FMW.products, AruProduct.SOA), InstallerType.FMW, InstallerType.SOA), // Oracle SOA Suite (with Service Bus) - SOA_OSB(Utils.list(FMW.products, AruProduct.SOA, AruProduct.OSB), + SOA_OSB(Utils.toSet(FMW.products, AruProduct.SOA, AruProduct.OSB), InstallerType.FMW, InstallerType.SOA, InstallerType.OSB), // Oracle SOA Suite (with Service Bus and B2B) - SOA_OSB_B2B(Utils.list(FMW.products, AruProduct.SOA, AruProduct.OSB), + SOA_OSB_B2B(Utils.toSet(FMW.products, AruProduct.SOA, AruProduct.OSB), InstallerType.FMW, InstallerType.SOA, InstallerType.OSB, InstallerType.B2B), // Oracle Managed File Transfer - MFT(Utils.list(FMW.products, AruProduct.MFT), + MFT(Utils.toSet(FMW.products, AruProduct.MFT), InstallerType.FMW, InstallerType.MFT), // Oracle Identity Manager - IDM(Utils.list(FMW.products, AruProduct.IDM), + IDM(Utils.toSet(FMW.products, AruProduct.IDM), InstallerType.FMW, InstallerType.IDM), // Oracle Identity Manager - IDM_WLS(Collections.singletonList(AruProduct.IDM), + IDM_WLS(Collections.singleton(AruProduct.IDM), InstallerType.IDM), // Oracle Access Manager - OAM(Utils.list(FMW.products, AruProduct.OAM), + OAM(Utils.toSet(FMW.products, AruProduct.OAM), InstallerType.FMW, InstallerType.OAM), // Oracle Identity Governance - OIG(Utils.list(FMW.products, AruProduct.SOA, AruProduct.OSB, AruProduct.IDM), + OIG(Utils.toSet(FMW.products, AruProduct.SOA, AruProduct.OSB, AruProduct.IDM), InstallerType.FMW, InstallerType.SOA, InstallerType.OSB, InstallerType.IDM), // Oracle Unified Directory - OUD(Collections.singletonList(AruProduct.OUD), + OUD(Collections.singleton(AruProduct.OUD), InstallerType.OUD), // Oracle Unified Directory - OUD_WLS(Utils.list(FMW.products, AruProduct.OUD), + OUD_WLS(Utils.toSet(FMW.products, AruProduct.OUD), InstallerType.FMW, InstallerType.OUD), // Oracle WebCenter Content - WCC(Utils.list(FMW.products, AruProduct.WCC), + WCC(Utils.toSet(FMW.products, AruProduct.WCC), InstallerType.FMW, InstallerType.WCC), // Oracle WebCenter Portal - WCP(Utils.list(FMW.products, AruProduct.WCP), + WCP(Utils.toSet(FMW.products, AruProduct.WCP), InstallerType.FMW, InstallerType.WCP), // Oracle WebCenter Sites - WCS(Utils.list(FMW.products, AruProduct.WCS), + WCS(Utils.toSet(FMW.products, AruProduct.WCS), InstallerType.FMW, InstallerType.WCS) ; private final InstallerType[] installers; - private final List products; - FmwInstallerType(List products, InstallerType... installers) { + private final Set products; + FmwInstallerType(Set products, InstallerType... installers) { this.installers = installers; this.products = products; } @@ -89,7 +93,7 @@ public String installerListString() { return Arrays.stream(installers).map(Object::toString).collect(Collectors.joining(", ")); } - public List products() { + public Set products() { return products; } @@ -109,6 +113,8 @@ public static FmwInstallerType fromValue(String value) { private static final List weblogicServerTypes = Arrays.asList(WLS, WLSDEV, WLSSLIM); + private static final LoggingFacade logger = LoggingFactory.getLogger(FmwInstallerType.class); + /** * Return a list of all WebLogic Server types (not JRF types). * @return list of WLS enum types. @@ -116,4 +122,38 @@ public static FmwInstallerType fromValue(String value) { public static boolean isBaseWeblogicServer(FmwInstallerType value) { return weblogicServerTypes.contains(value); } + + /** + * Derive the FmwInstallerType from a list of product families. + * These product families are found in inventory/registry.xml. + * @param products a comma-separated list of product families + * @return the best match for the list of product families + */ + public static FmwInstallerType fromProductList(String products) { + logger.entering(products); + // create a set from the comma-separated list + Set productSet = Stream.of(products.split(",")) + .filter(e -> !"TOPLINK".equals(e)) // skip TOPLINK product (WLS always contains TOPLINK) + .filter(e -> !"BPM".equals(e)) // skip BPM product (SOA always contains BPM) + .map(e -> "INFRA".equals(e) ? "JRF" : e) // map -> replaces any occurrence of INFRA with JRF + .map(AruProduct::valueOf) // convert String to AruProduct enum + .collect(Collectors.toSet()); + + logger.finer("Derived product set {0} from {1}", productSet, products); + + for (FmwInstallerType type : values()) { + // Use the product set to compare products, but remove products that CIE does not include in registry.xml + Set aruProducts = type.products().stream() + .filter(e -> !AruProduct.FMWPLAT.equals(e)) // never shows up on installed product family + .filter(e -> !AruProduct.JDEV.equals(e)) // never shows up on installed product family + .collect(Collectors.toSet()); + + if (aruProducts.equals(productSet)) { + logger.exiting(type); + return type; + } + } + logger.exiting(WLS); + return WLS; + } } diff --git a/imagetool/src/main/java/com/oracle/weblogic/imagetool/util/Utils.java b/imagetool/src/main/java/com/oracle/weblogic/imagetool/util/Utils.java index f49cd6cb..6f11b595 100644 --- a/imagetool/src/main/java/com/oracle/weblogic/imagetool/util/Utils.java +++ b/imagetool/src/main/java/com/oracle/weblogic/imagetool/util/Utils.java @@ -21,16 +21,18 @@ import java.nio.file.StandardCopyOption; import java.nio.file.attribute.PosixFilePermissions; import java.text.MessageFormat; -import java.util.ArrayList; +import java.util.Arrays; import java.util.Base64; import java.util.Collection; import java.util.Collections; import java.util.Comparator; import java.util.Enumeration; +import java.util.HashSet; import java.util.List; import java.util.Objects; import java.util.Properties; import java.util.ResourceBundle; +import java.util.Set; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Collectors; @@ -51,7 +53,7 @@ public class Utils { private static final LoggingFacade logger = LoggingFactory.getLogger(Utils.class); @NonNls - private static ResourceBundle bundle = ResourceBundle.getBundle("ImageTool"); + private static final ResourceBundle bundle = ResourceBundle.getBundle("ImageTool"); private Utils() { // hide constructor, usage of this class is only static utilities @@ -306,8 +308,7 @@ public static void deleteFilesRecursively(String pathDir) throws IOException { } if (Files.exists(tmpDir)) { - logger.warning("Unable to cleanup temp directory, it is safe to remove this directory manually " - + tmpDir.toString()); + logger.warning("IMG-0038", tmpDir); } } } @@ -751,16 +752,27 @@ public static void removeIntermediateDockerImages(String builder, String buildId } /** - * Create a new list from an existing collection and adding additional elements, if desired. + * Create a new set from an existing collection and adding additional elements, if desired. * @param start a set of elements to start from * @param elements zero to many additional elements to add to the new list - * @param the class of the elements to add - * @return a new list of element T + * @param the class of the elements in the Set + * @return a new set of the specified T */ @SafeVarargs - public static List list(Collection start, T... elements) { - List result = new ArrayList<>(start); + public static Set toSet(Collection start, T... elements) { + Set result = new HashSet<>(start); Collections.addAll(result, elements); return result; } + + /** + * Create a new Set from a list of elements. + * @param array elements to be added to the Set + * @param the class of the elements in the Set + * @return a set of the specified T + */ + @SafeVarargs + public static Set toSet(T... array) { + return toSet(Arrays.asList(array)); + } } diff --git a/imagetool/src/main/resources/ImageTool.properties b/imagetool/src/main/resources/ImageTool.properties index 6ec8dae8..82e5739e 100644 --- a/imagetool/src/main/resources/ImageTool.properties +++ b/imagetool/src/main/resources/ImageTool.properties @@ -36,7 +36,7 @@ IMG-0034=Patch ID {0} has multiple versions, please retry the command using one IMG-0035=additionalBuildFile could not be copied: {0} IMG-0036=Unable to find installer inventory file: {0} IMG-0037=Failed to find patch {0} for version {1} -IMG-0038=NO LONGER USED +IMG-0038=Unable to cleanup temp directory, it is safe to remove this directory manually: {0} IMG-0039=Using middleware installers ([[green: {0}]]) version [[cyan: {1}]] IMG-0040=When providing custom response files, a response file must be provided for each of the installers {0}. Found {1}, expected {2}. IMG-0041=Using provided installer response file: {0} for {1} install @@ -92,3 +92,5 @@ IMG-0090=Rebasing WDT models. A domain was not found in the source image at {0} IMG-0091=Reading settings from the source image {0} IMG-0092=ORACLE_HOME already exists in {0} (--fromImage), skipping middleware installs IMG-0093=Patching skipped. Using CREATE to patch --fromImage with an existing ORACLE_HOME is not supported. To create a patched image, use CREATE with a linux base image and apply the WebLogic install and patches at the same time. +IMG-0094=Source image installer type: ([[green: {0}]]) +IMG-0095=Unable to parse response for Oracle patches in fromImage: {0} diff --git a/imagetool/src/main/resources/probe-env/inspect-image-long.sh b/imagetool/src/main/resources/probe-env/inspect-image-long.sh index f3a39a38..fd7b0f57 100644 --- a/imagetool/src/main/resources/probe-env/inspect-image-long.sh +++ b/imagetool/src/main/resources/probe-env/inspect-image-long.sh @@ -40,10 +40,7 @@ fi if [ -n "$ORACLE_HOME" ]; then echo oracleHome="$ORACLE_HOME" - WLS_TYPE=$(cat "$ORACLE_HOME"/inventory/registry.xml 2> /dev/null | grep -q 'WebLogic Server for FMW' && printf "fmw") - if [ -n "$WLS_TYPE" ]; then - echo wlsType="$WLS_TYPE" - fi + if [ -n "$JAVA_HOME" ]; then echo wlsVersion="$("$JAVA_HOME"/bin/java -cp "$ORACLE_HOME"/wlserver/server/lib/weblogic.jar weblogic.version 2> /dev/null | grep -oE -m 1 '([[:digit:]\.]+)' | head -1)" fi diff --git a/imagetool/src/main/resources/probe-env/inspect-image.sh b/imagetool/src/main/resources/probe-env/inspect-image.sh index c82e1ac4..26a574cb 100644 --- a/imagetool/src/main/resources/probe-env/inspect-image.sh +++ b/imagetool/src/main/resources/probe-env/inspect-image.sh @@ -40,10 +40,7 @@ fi if [ -n "$ORACLE_HOME" ]; then echo oracleHome="$ORACLE_HOME" - WLS_TYPE=$(cat "$ORACLE_HOME"/inventory/registry.xml 2> /dev/null | grep -q 'WebLogic Server for FMW' && printf "fmw") - if [ -n "$WLS_TYPE" ]; then - echo wlsType="$WLS_TYPE" - fi + if [ -n "$JAVA_HOME" ]; then echo wlsVersion="$("$JAVA_HOME"/bin/java -cp "$ORACLE_HOME"/wlserver/server/lib/weblogic.jar weblogic.version 2> /dev/null | grep -oE -m 1 '([[:digit:]\.]+)' | head -1)" fi diff --git a/imagetool/src/test/java/com/oracle/weblogic/imagetool/installer/InstallerTest.java b/imagetool/src/test/java/com/oracle/weblogic/imagetool/installer/InstallerTest.java index 4f54be0a..92a738f8 100644 --- a/imagetool/src/test/java/com/oracle/weblogic/imagetool/installer/InstallerTest.java +++ b/imagetool/src/test/java/com/oracle/weblogic/imagetool/installer/InstallerTest.java @@ -6,6 +6,7 @@ import java.util.Arrays; import com.oracle.weblogic.imagetool.aru.AruProduct; +import com.oracle.weblogic.imagetool.util.Utils; import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; @@ -30,12 +31,18 @@ void fmwInstallerTypeListTest() { @Test void fmwInstallerProductIds() { - assertEquals(Arrays.asList(AruProduct.WLS, AruProduct.COH, AruProduct.FMWPLAT), FmwInstallerType.WLS.products(), + AruProduct[] list1 = {AruProduct.WLS, AruProduct.COH, AruProduct.FMWPLAT}; + assertEquals(Utils.toSet(list1), FmwInstallerType.WLS.products(), "WLS product list is incorrect or out of order"); - assertEquals(Arrays.asList(AruProduct.WLS, AruProduct.COH, AruProduct.FMWPLAT, AruProduct.JRF, AruProduct.JDEV), - FmwInstallerType.FMW.products(), "FMW product list is incorrect or out of order"); - assertEquals(Arrays.asList(AruProduct.WLS, AruProduct.COH, AruProduct.FMWPLAT, AruProduct.JRF, AruProduct.JDEV, - AruProduct.SOA), FmwInstallerType.SOA.products(), "SOA product list is incorrect or out of order"); + + AruProduct[] list2 = {AruProduct.WLS, AruProduct.COH, AruProduct.FMWPLAT, AruProduct.JRF, AruProduct.JDEV}; + assertEquals(Utils.toSet(list2), FmwInstallerType.FMW.products(), + "FMW product list is incorrect or out of order"); + + AruProduct[] list3 = {AruProduct.WLS, AruProduct.COH, AruProduct.FMWPLAT, AruProduct.JRF, AruProduct.JDEV, + AruProduct.SOA}; + assertEquals(Utils.toSet(list3), FmwInstallerType.SOA.products(), + "SOA product list is incorrect or out of order"); } @Test @@ -45,5 +52,12 @@ void fmwInstallerFromValue() { assertEquals(FmwInstallerType.FMW, FmwInstallerType.fromValue("fmw"), "fromValue fmw failed for FmwInstallerType"); } + + @Test + void fromProductList() { + assertEquals(FmwInstallerType.WLS, FmwInstallerType.fromProductList("WLS,COH,TOPLINK")); + assertEquals(FmwInstallerType.FMW, FmwInstallerType.fromProductList("INFRA,WLS,COH,TOPLINK")); + assertEquals(FmwInstallerType.SOA_OSB, FmwInstallerType.fromProductList("INFRA,WLS,COH,TOPLINK,BPM,SOA,OSB")); + } }