Skip to content

Commit

Permalink
update all products with latest PSU or recommended patches, not just …
Browse files Browse the repository at this point in the history
…WLS (#290)
  • Loading branch information
ddsharpe committed Jul 6, 2021
1 parent 66e56f6 commit ca6c200
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -25,10 +26,14 @@ public class InstalledPatch {
* @return a simple list of InstalledPatch
*/
public static List<InstalledPatch> getPatchList(String oraclePatches) {
logger.entering(oraclePatches);
List<InstalledPatch> 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();
Expand All @@ -42,6 +47,7 @@ public static List<InstalledPatch> getPatchList(String oraclePatches) {
result.add(found);
}

logger.exiting(result.size());
return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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<AruProduct> products;
FmwInstallerType(List<AruProduct> products, InstallerType... installers) {
private final Set<AruProduct> products;
FmwInstallerType(Set<AruProduct> products, InstallerType... installers) {
this.installers = installers;
this.products = products;
}
Expand All @@ -89,7 +93,7 @@ public String installerListString() {
return Arrays.stream(installers).map(Object::toString).collect(Collectors.joining(", "));
}

public List<AruProduct> products() {
public Set<AruProduct> products() {
return products;
}

Expand All @@ -109,11 +113,47 @@ public static FmwInstallerType fromValue(String value) {

private static final List<FmwInstallerType> 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.
*/
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<AruProduct> 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<AruProduct> 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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);
}
}
}
Expand Down Expand Up @@ -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 <T> the class of the elements to add
* @return a new list of element T
* @param <T> the class of the elements in the Set
* @return a new set of the specified T
*/
@SafeVarargs
public static <T> List<T> list(Collection<? extends T> start, T... elements) {
List<T> result = new ArrayList<>(start);
public static <T> Set<T> toSet(Collection<? extends T> start, T... elements) {
Set<T> 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 <T> the class of the elements in the Set
* @return a set of the specified T
*/
@SafeVarargs
public static <T> Set<T> toSet(T... array) {
return toSet(Arrays.asList(array));
}
}
4 changes: 3 additions & 1 deletion imagetool/src/main/resources/ImageTool.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}
5 changes: 1 addition & 4 deletions imagetool/src/main/resources/probe-env/inspect-image-long.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 1 addition & 4 deletions imagetool/src/main/resources/probe-env/inspect-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
Expand All @@ -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"));
}
}

0 comments on commit ca6c200

Please sign in to comment.