Skip to content

Commit 54507b1

Browse files
merged from origin
Former-commit-id: b762e44e1b3abc15efeed4845e249c7b5c0e5291
2 parents 9eed663 + efe3cb7 commit 54507b1

File tree

3 files changed

+54
-12
lines changed

3 files changed

+54
-12
lines changed

src/main/java/com/oracle/weblogicx/imagebuilder/builder/util/ARUUtil.java

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
import java.io.File;
66
import java.io.IOException;
7+
import java.nio.file.Files;
8+
import java.nio.file.Paths;
79
import java.util.ArrayList;
810
import java.util.List;
911

@@ -16,6 +18,7 @@
1618
import org.apache.http.client.HttpResponseException;
1719
import org.w3c.dom.Document;
1820
import org.w3c.dom.Element;
21+
import org.w3c.dom.NamedNodeMap;
1922
import org.w3c.dom.Node;
2023
import org.w3c.dom.NodeList;
2124

@@ -24,6 +27,7 @@
2427
import static com.oracle.weblogicx.imagebuilder.builder.api.meta.MetaDataResolver.CACHE_KEY_SEPARATOR;
2528
import static com.oracle.weblogicx.imagebuilder.builder.util.Constants.CONFLICTCHECKER_URL;
2629
import static com.oracle.weblogicx.imagebuilder.builder.util.Constants.FMW_PROD_ID;
30+
import static com.oracle.weblogicx.imagebuilder.builder.util.Constants.GET_LSINVENTORY_URL;
2731
import static com.oracle.weblogicx.imagebuilder.builder.util.Constants.LATEST_PSU_URL;
2832
import static com.oracle.weblogicx.imagebuilder.builder.util.Constants.PATCH_SEARCH_URL;
2933
import static com.oracle.weblogicx.imagebuilder.builder.util.Constants.REL_URL;
@@ -158,6 +162,7 @@ public static List<String> getPatchesFor(String category, String version, List<S
158162

159163
/** Validate patches conflicts by passing a list of patches
160164
*
165+
* @param lsInventoryPath opatch lsinventory result path (null if non is passed)
161166
* @param patches A list of patches number
162167
* @param category wls or fmw
163168
* @param version version of the prduct
@@ -167,18 +172,55 @@ public static List<String> getPatchesFor(String category, String version, List<S
167172
* @throws IOException when failed to access the aru api
168173
*/
169174

170-
public static ValidationResult validatePatches(List<String> patches, String category, String version, String userId, String
171-
password) throws IOException {
175+
public static ValidationResult validatePatches(String lsInventoryPath, List<String> patches, String category,
176+
String version, String userId, String password) throws IOException {
172177

173178

174179
ValidationResult validationResult = new ValidationResult();
175180
validationResult.setSuccess(true);
176181
validationResult.setResults(null);
177182

178-
StringBuffer payload = new StringBuffer
179-
("<conflict_check_request><platform>2000</platform><target_patch_list/>");
180183
String releaseNumber = getReleaseNumber(category, version, userId, password);
181184

185+
StringBuffer payload = new StringBuffer
186+
("<conflict_check_request><platform>2000</platform>");
187+
188+
if (lsInventoryPath != null ) {
189+
String inventoryContent = new String(Files.readAllBytes(Paths.get(lsInventoryPath)));
190+
String upiPayload = "<inventory_upi_request><lsinventory_output>" + inventoryContent +
191+
"</lsinventory_output></inventory_upi_request>";
192+
193+
Document upiResult = HttpUtil.postCheckConflictRequest(GET_LSINVENTORY_URL, upiPayload, userId,
194+
password);
195+
196+
try {
197+
NodeList upi_list = XPathUtil.applyXPathReturnNodeList(upiResult,
198+
"/inventory_upi_response/upi");
199+
if (upi_list.getLength() > 0) {
200+
payload.append("<target_patch_list>");
201+
202+
for ( int ii=0; ii < upi_list.getLength(); ii++) {
203+
Node upi = upi_list.item(ii);
204+
NamedNodeMap m = upi.getAttributes();
205+
payload.append(String.format("<installed_patch upi=\"%s\"/>",
206+
m.getNamedItem("number").getNodeValue()));
207+
208+
}
209+
payload.append("</target_patch_list>");
210+
}
211+
else {
212+
payload.append("<target_patch_list/>");
213+
}
214+
} catch(XPathExpressionException xpe) {
215+
throw new IOException(xpe);
216+
217+
}
218+
219+
} else {
220+
payload.append("<target_patch_list/>");
221+
}
222+
223+
182224
for (String patch : patches) {
183225
payload.append(String.format("<candidate_patch_list rel_id=\"%s\">%s</conflict_check_request>",
184226
releaseNumber, patch));

src/main/java/com/oracle/weblogicx/imagebuilder/builder/util/Constants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public final class Constants {
2020
static final String PATCH_SEARCH_URL="https://updates.oracle"
2121
+ ".com/Orion/Services/search?product=%s&bug=%s&release=%s";
2222
static final String CONFLICTCHECKER_URL = "https://updates.oracle.com/Orion/Services/conflict_checks";
23+
static final String GET_LSINVENTORY_URL = "https://updates.oracle.com/Orion/Services/get_inventory_upi";
2324
static final String WLS_PROD_ID = "15991";
2425
static final String FMW_PROD_ID = "27638";
2526
public static final String CACHE_DIR_KEY = "cache.dir";

src/main/java/com/oracle/weblogicx/imagebuilder/builder/util/HttpUtil.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,6 @@ private static HttpClient getOraClient(String userId, String password) {
104104

105105
public static void downloadFile(String url, String fileName, String username, String password)
106106
throws IOException {
107-
// HttpClient httpClient;
108-
// if (username == null && password == null) {
109-
// httpClient = HttpClientBuilder.create().useSystemProperties().build();
110-
// } else {
111-
// httpClient = getOraClient(username, password);
112-
// }
113107
Executor.newInstance(getOraClient(username, password))
114108
.execute(Request.Get(url).connectTimeout(30000).socketTimeout(30000))
115109
.saveContent(new File(fileName));
@@ -141,10 +135,15 @@ public static Document postCheckConflictRequest(String url, String payload, Stri
141135
httpExecutor.use(cookieStore);
142136

143137
// Has to do search first, otherwise results in 302
144-
getXMLContent(REL_URL, username, password);
138+
// MUST use the same httpExecutor to maintain session
139+
140+
141+
httpExecutor
142+
.execute(Request.Get(REL_URL).connectTimeout(30000).socketTimeout(30000))
143+
.returnContent().asString();
145144

146145
HttpEntity entity = MultipartEntityBuilder.create().setMode(HttpMultipartMode.BROWSER_COMPATIBLE)
147-
.addPart(FormBodyPartBuilder.create("request_xml", new StringBody(payload, ContentType.TEXT_PLAIN)).build())
146+
.addTextBody("request_xml", payload)
148147
.build();
149148

150149
String xmlString =

0 commit comments

Comments
 (0)