Skip to content

Commit 2f191c2

Browse files
merged with changes from origin
Former-commit-id: c3f997e8fb400f4ef28705b00e976d368d0ff92d
2 parents da7a385 + 460218c commit 2f191c2

File tree

4 files changed

+150
-126
lines changed

4 files changed

+150
-126
lines changed

src/main/java/com/oracle/weblogicx/imagebuilder/builder/cli/BuilderCLIDriver.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,8 @@ public CommandResponse call() throws Exception {
172172
}
173173

174174
if (patches != null && !patches.isEmpty()) {
175-
List<String> bugKeys = ARUUtil.getPatchesFor(installerType.toString(), patches, userId, password);
175+
List<String> bugKeys = ARUUtil.getPatchesFor(installerType.toString(), installerVersion,
176+
patches, userId, password);
176177
patchKeys.addAll(bugKeys);
177178
}
178179

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ public class ARUConstants {
1010
static final String LATEST_PSU_URL =
1111
"https://updates.oracle.com/Orion/Services/search?product=%s&release=%s";
1212
static final String ARU_LANG_URL = "https://updates.oracle.com/Orion/Services/metadata?table=aru_languages";
13-
static final String PATCH_SEARCH_URL="https://updates.oracle.com/Orion/Services/search?product=%s&bug=%s";
14-
13+
static final String PATCH_SEARCH_URL="https://updates.oracle"
14+
+ ".com/Orion/Services/search?product=%s&bug=%s&release=%s";
15+
static final String CONFLICTCHECKER_URL = "https://updates.oracle.com/Orion/Services/conflict_checks";
1516
static final String WLS_PROD_ID = "15991";
1617
static final String FMW_PROD_ID = "27638";
1718

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

Lines changed: 110 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,13 @@
2020
import org.w3c.dom.NodeList;
2121

2222
import static com.oracle.weblogicx.imagebuilder.builder.impl.meta.FileMetaDataResolver.META_RESOLVER;
23-
import static com.oracle.weblogicx.imagebuilder.builder.util.ARUConstants.*;
23+
import static com.oracle.weblogicx.imagebuilder.builder.util.ARUConstants.ARU_LANG_URL;
24+
import static com.oracle.weblogicx.imagebuilder.builder.util.ARUConstants.CONFLICTCHECKER_URL;
25+
import static com.oracle.weblogicx.imagebuilder.builder.util.ARUConstants.FMW_PROD_ID;
26+
import static com.oracle.weblogicx.imagebuilder.builder.util.ARUConstants.LATEST_PSU_URL;
27+
import static com.oracle.weblogicx.imagebuilder.builder.util.ARUConstants.PATCH_SEARCH_URL;
28+
import static com.oracle.weblogicx.imagebuilder.builder.util.ARUConstants.REL_URL;
29+
import static com.oracle.weblogicx.imagebuilder.builder.util.ARUConstants.WLS_PROD_ID;
2430

2531
public class ARUUtil {
2632

@@ -76,33 +82,6 @@ public static void getAllFMWReleases(String userId, String password) throws IOEx
7682
getAllReleases("fmw", userId, password);
7783
}
7884

79-
/**
80-
* Download the latest WLS patches(PSU) for the release
81-
*
82-
* @param version release number
83-
* @param userId userid for support account
84-
* @param password password for support account
85-
* @throws IOException when failed to access the aru api
86-
* @return String bug number
87-
*/
88-
public static String getLatestWLSPSU(String version, String userId, String password) throws IOException {
89-
String releaseNumber = getReleaseNumber("wls", version, userId, password);
90-
return getLatestPSU("wls", releaseNumber, userId, password);
91-
}
92-
93-
/**
94-
* Download the latest FMW patches(PSU) for the release
95-
*
96-
* @param version version number 12.2.1.3.0
97-
* @param userId userid for support account
98-
* @param password password for support account
99-
* @throws IOException when failed to access the aru api
100-
* @return String bug number
101-
*/
102-
public static String getLatestFMWPSU(String version, String userId, String password) throws IOException {
103-
String releaseNumber = getReleaseNumber("wls", version, userId, password);
104-
return getLatestPSU("fmw", releaseNumber, userId, password);
105-
}
10685

10786
/**
10887
* Download the latest PSU for given category and release
@@ -119,46 +98,19 @@ public static String getLatestPSUFor(String category, String version, String use
11998
}
12099

121100
/**
122-
* Download a list of WLS patches
123-
*
124-
* @param patches A list of patches number
125-
* @param userId userid for support account
126-
* @param password password for support account
127-
* @throws IOException when failed to access the aru api
101+
* Get list of PSU available for given category and release
102+
* @param category wls or fmw
103+
* @param version version number like 12.2.1.3.0
104+
* @param userId user
105+
* @return Document listing of all patches (full details)
106+
* @throws IOException when failed
128107
*/
129-
public static List<String> getWLSPatches(List<String> patches, String userId, String password) throws
130-
IOException {
131-
List<String> results = new ArrayList<>();
132-
for (String patch : patches) {
133-
String rs = getPatch("wls", patch, userId, password);
134-
if (rs != null) {
135-
results.add(rs);
136-
}
137-
}
138-
return results;
108+
public static Document getAllPSUFor(String category, String version, String userId, String password) throws IOException {
109+
String releaseNumber = getReleaseNumber(category, version, userId, password);
110+
return getAllPSU(category, releaseNumber, userId, password);
139111
}
140112

141-
/**
142-
* Download a list of FMW patches
143-
*
144-
* @param patches A list of patches number
145-
* @param userId userid for support account
146-
* @param password password for support account
147-
* @return list of bug numbers
148-
* @throws IOException when failed to access the aru api
149-
*/
150-
public static List<String> getFMWPatches(String category, List<String> patches, String userId, String password)
151-
throws
152-
IOException {
153-
List<String> results = new ArrayList<>();
154-
for (String patch : patches) {
155-
String rs = getPatch("fmw", patch, userId, password);
156-
if (rs != null) {
157-
results.add(rs);
158-
}
159-
}
160-
return results;
161-
}
113+
162114

163115
/**
164116
* Download a list of FMW patches
@@ -169,57 +121,92 @@ public static List<String> getFMWPatches(String category, List<String> patches,
169121
* @return List of bug numbers
170122
* @throws IOException when failed to access the aru api
171123
*/
172-
public static List<String> getPatchesFor(String category, List<String> patches, String userId, String password)
124+
public static List<String> getPatchesFor(String category, String version, List<String> patches, String userId, String password)
173125
throws
174126
IOException {
175127
List<String> results = new ArrayList<>();
176128
for (String patch : patches) {
177-
String rs = getPatch(category, patch, userId, password);
129+
String rs = getPatch(category, version, patch, userId, password);
178130
if (rs != null) {
179131
results.add(rs);
180132
}
181133
}
182134
return results;
183135
}
136+
184137
/**
185138
*
186139
* @param patches A list of patches number
187-
* @param category
188-
* @param version
140+
* @param category wls or fmw
141+
* @param version version of the prduct
189142
* @param userId userid for support account
190143
* @param password password for support account
191144
* @throws IOException when failed to access the aru api
192145
*/
193146

194-
public static void validatePatches(List<String> patches, String category, String version, String userId, String
147+
public static boolean validatePatches(List<String> patches, String category, String version, String userId, String
195148
password) throws IOException {
196149

197-
// TODO
150+
StringBuffer payload = new StringBuffer
151+
("<conflict_check_request><platform>2000</platform><target_patch_list/>");
152+
String releaseNumber = getReleaseNumber(category, version, userId, password);
153+
154+
for (String patch : patches) {
155+
payload.append(String.format("<candidate_patch_list rel_id=\"%s\">%s</conflict_check_request>",
156+
releaseNumber, patch));
157+
}
158+
payload.append("</conflict_check_request>");
159+
160+
Document result = HttpUtil.postCheckConflictRequest(CONFLICTCHECKER_URL, payload.toString(), userId, password);
161+
162+
try {
163+
NodeList conflictSets = XPathUtil.applyXPathReturnNodeList(result, "/conflict_sets");
164+
if (conflictSets.getLength() == 0) {
165+
166+
167+
try {
168+
String expression = "/conflict_check/conflict_sets/set/merge_patches";
169+
170+
NodeList nodeList = XPathUtil.applyXPathReturnNodeList(result, expression);
171+
172+
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
173+
DocumentBuilder builder = dbf.newDocumentBuilder();
174+
Document doc = builder.newDocument();
175+
Element element = doc.createElement("conflict_check_results");
176+
177+
for (int i = 0; i < nodeList.getLength(); i++) {
178+
Node n = nodeList.item(i);
179+
Node copyNode = doc.importNode(n, true);
198180

199-
// find the release number first based on the version
200-
// build the xml
181+
if (n instanceof Element )
182+
element.appendChild(copyNode);
183+
}
201184

202-
// <conflict_check_request>
203-
// <platform>912</platform>
204-
// <target_patch_list>
205-
// <installed_patch/>
206-
// </target_patch_list>
207-
// <candidate_patch_list>
208-
// <patch_group rel_id="80111060" language_id="0">7044721</patch_group>
209-
// <patch_group rel_id="80111060" language_id="0">7156923</patch_group>
210-
// <patch_group rel_id="80111060" language_id="0">7210195</patch_group>
211-
// <patch_group rel_id="80111060" language_id="0">7256747</patch_group>
212-
// </candidate_patch_list>
213-
//</conflict_check_request>
185+
doc.appendChild(element);
186+
System.out.println("===================================================");
187+
System.out.println("There are conflicts between the patches requested:-");
188+
System.out.println("===================================================");
189+
System.out.println("");
190+
XPathUtil.prettyPrint(doc);
214191

215-
// Run against POST /Orion/Services/conflict_checks
192+
return true;
216193

194+
195+
} catch (XPathExpressionException | ParserConfigurationException xpe) {
196+
throw new IOException(xpe);
197+
}
198+
199+
}
200+
201+
} catch (XPathExpressionException xpe) {
202+
throw new IOException(xpe);
203+
204+
}
205+
return false;
217206
}
218207

219208
private static Document getAllReleases(String category, String userId, String password) throws IOException {
220209

221-
//HTTP_STATUS=$(curl -v -w "%{http_code}" -b cookies.txt -L --header 'Authorization: Basic ${basicauth}'
222-
// "https://updates.oracle.com/Orion/Services/metadata?table=aru_releases" -o allarus.xml)
223210

224211
Document allReleases = HttpUtil.getXMLContent(REL_URL, userId, password);
225212

@@ -259,25 +246,43 @@ private static Document getAllReleases(String category, String userId, String p
259246

260247
private static String getLatestPSU(String category, String release, String userId, String password) throws
261248
IOException {
262-
return getPatchOrPSU(category, release, userId, password, LATEST_PSU_URL);
263-
}
264249

265-
private static String getPatchOrPSU(String category, String release, String userId, String password, String searchURL) throws IOException {
266250
String expression;
267251
if ("wls".equalsIgnoreCase(category))
268-
expression = String.format(searchURL, WLS_PROD_ID, release);
252+
expression = String.format(LATEST_PSU_URL, WLS_PROD_ID, release);
269253
else
270-
expression = String.format(searchURL, FMW_PROD_ID, release);
254+
expression = String.format(LATEST_PSU_URL, FMW_PROD_ID, release);
255+
271256
Document allPatches = HttpUtil.getXMLContent(expression, userId, password);
272257
return savePatch(allPatches, userId, password);
273258
}
274259

275-
private static String getPatch(String category, String patchNumber, String userId, String password) throws
260+
private static Document getAllPSU(String category, String release, String userId, String password) throws
276261
IOException {
277-
//HTTP_STATUS=$(curl -v -w "%{http_code}" -b cookies.txt -L --header 'Authorization: Basic ${basicauth}'
278-
// "https://updates.oracle.com/Orion/Services/search?product=15991&release=$releaseid&include_prereqs=true"
279-
// -o latestpsu.xml)
280-
return getPatchOrPSU(category, patchNumber, userId, password, PATCH_SEARCH_URL);
262+
263+
String expression;
264+
if ("wls".equalsIgnoreCase(category))
265+
expression = String.format(LATEST_PSU_URL, WLS_PROD_ID, release);
266+
else
267+
expression = String.format(LATEST_PSU_URL, FMW_PROD_ID, release);
268+
269+
return HttpUtil.getXMLContent(expression, userId, password);
270+
}
271+
272+
private static String getPatch(String category, String version, String bugNumber, String userId, String password)
273+
throws
274+
IOException {
275+
276+
String releaseNumber = getReleaseNumber(category, version, userId, password );
277+
String url;
278+
if ("wls".equalsIgnoreCase(category))
279+
url = String.format(PATCH_SEARCH_URL, WLS_PROD_ID, bugNumber, releaseNumber);
280+
else
281+
url = String.format(PATCH_SEARCH_URL, FMW_PROD_ID, bugNumber, releaseNumber);
282+
283+
Document allPatches = HttpUtil.getXMLContent(url, userId, password);
284+
285+
return savePatch(allPatches, userId, password);
281286
}
282287

283288
private static String savePatch(Document allPatches, String userId, String password) throws IOException {
@@ -293,6 +298,10 @@ private static String savePatch(Document allPatches, String userId, String passw
293298

294299
String bugName = XPathUtil.applyXPathReturnString(allPatches, "/results/patch[1]/name");
295300

301+
String releaseNumber = XPathUtil.applyXPathReturnString(allPatches,
302+
"string(/results/patch[1]/release/@id)");
303+
304+
String key = bugName + "." + releaseNumber;
296305

297306
int index = downLoadLink.indexOf("patch_file=");
298307

@@ -301,11 +310,11 @@ private static String savePatch(Document allPatches, String userId, String passw
301310
index+"patch_file=".length());
302311
// this hasMatchingKeyValue is to make sure that the file value is same as the intended location.
303312
// cache dir can be changed
304-
if (!new File(fileName).exists() || !META_RESOLVER.hasMatchingKeyValue(bugName, fileName)) {
313+
if (!new File(fileName).exists() || !META_RESOLVER.hasMatchingKeyValue(key, fileName)) {
305314
HttpUtil.downloadFile(downLoadHost+downLoadLink, fileName, userId, password);
306-
META_RESOLVER.addToCache(bugName, fileName);
315+
META_RESOLVER.addToCache(key, fileName);
307316
} else {
308-
System.out.println(String.format("patch %s already downloaded for bug %s", fileName, bugName));
317+
System.out.println(String.format("patch %s already downloaded for bug %s", fileName, key));
309318
}
310319
return bugName;
311320
}
@@ -345,10 +354,6 @@ public static boolean checkCredentials(String username, String password) {
345354
return true;
346355
}
347356

348-
public static void main(String args[]) throws Exception {
349-
ARUUtil.getLatestWLSPSU("12.2.1.3.0","[email protected]", "iJCPiUah7jdmLk1E");
350-
}
351-
352357

353358
}
354359

0 commit comments

Comments
 (0)