Skip to content

Commit 5dd5142

Browse files
committed
Add release to search for patches and change the key to bugnumber.releasenumber
Former-commit-id: 9617bb4fbe05b82631149a530bba276044c2a6a5
1 parent 04fb34b commit 5dd5142

File tree

4 files changed

+81
-149
lines changed

4 files changed

+81
-149
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
@@ -225,7 +225,8 @@ public CommandResponse call() throws Exception {
225225
}
226226

227227
if (patches != null && !patches.isEmpty()) {
228-
List<String> bugKeys = ARUUtil.getPatchesFor(installerType.toString(), patches, userSession);
228+
List<String> bugKeys = ARUUtil.getPatchesFor(installerType.toString(), installerVersion, patches,
229+
userSession);
229230
patchKeys.addAll(bugKeys);
230231
}
231232

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
@@ -8,8 +8,9 @@ public class ARUConstants {
88
static final String LATEST_PSU_URL =
99
"https://updates.oracle.com/Orion/Services/search?product=%s&release=%s";
1010
static final String ARU_LANG_URL = "https://updates.oracle.com/Orion/Services/metadata?table=aru_languages";
11-
static final String PATCH_SEARCH_URL="https://updates.oracle.com/Orion/Services/search?product=%s&bug=%s";
12-
11+
static final String PATCH_SEARCH_URL="https://updates.oracle"
12+
+ ".com/Orion/Services/search?product=%s&bug=%s&release=%s";
13+
static final String CONFLICTCHECKER_URL = "https://updates.oracle.com/Orion/Services/conflict_checks";
1314
static final String WLS_PROD_ID = "15991";
1415
static final String FMW_PROD_ID = "27638";
1516

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

Lines changed: 43 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package com.oracle.weblogicx.imagebuilder.builder.util;
22

3+
import com.oracle.weblogicx.imagebuilder.builder.api.model.User;
4+
import com.oracle.weblogicx.imagebuilder.builder.api.model.UserSession;
5+
36
import java.io.File;
47
import java.io.IOException;
58
import java.util.ArrayList;
@@ -10,9 +13,6 @@
1013
import javax.xml.parsers.ParserConfigurationException;
1114
import javax.xml.xpath.XPathExpressionException;
1215

13-
import com.oracle.weblogicx.imagebuilder.builder.api.model.InstallerType;
14-
import com.oracle.weblogicx.imagebuilder.builder.api.model.User;
15-
import com.oracle.weblogicx.imagebuilder.builder.api.model.UserSession;
1616
import org.apache.http.HttpStatus;
1717
import org.apache.http.client.HttpResponseException;
1818
import org.w3c.dom.Document;
@@ -21,7 +21,13 @@
2121
import org.w3c.dom.NodeList;
2222

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

2632
public class ARUUtil {
2733

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

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

10887
/**
10988
* Download the latest PSU for given category and release
@@ -119,47 +98,6 @@ public static String getLatestPSUFor(String category, String version, UserSessio
11998
return getLatestPSU(category, releaseNumber, user.getEmail(), String.valueOf(user.getPassword()));
12099
}
121100

122-
/**
123-
* Download a list of WLS patches
124-
*
125-
* @param patches A list of patches number
126-
* @param userId userid for support account
127-
* @param password password for support account
128-
* @throws IOException when failed to access the aru api
129-
*/
130-
public static List<String> getWLSPatches(List<String> patches, String userId, String password) throws
131-
IOException {
132-
List<String> results = new ArrayList<>();
133-
for (String patch : patches) {
134-
String rs = getPatch("wls", patch, userId, password);
135-
if (rs != null) {
136-
results.add(rs);
137-
}
138-
}
139-
return results;
140-
}
141-
142-
/**
143-
* Download a list of FMW patches
144-
*
145-
* @param patches A list of patches number
146-
* @param userId userid for support account
147-
* @param password password for support account
148-
* @return list of bug numbers
149-
* @throws IOException when failed to access the aru api
150-
*/
151-
public static List<String> getFMWPatches(String category, List<String> patches, String userId, String password)
152-
throws
153-
IOException {
154-
List<String> results = new ArrayList<>();
155-
for (String patch : patches) {
156-
String rs = getPatch("fmw", patch, userId, password);
157-
if (rs != null) {
158-
results.add(rs);
159-
}
160-
}
161-
return results;
162-
}
163101

164102
/**
165103
* Download a list of FMW patches
@@ -169,12 +107,13 @@ public static List<String> getFMWPatches(String category, List<String> patches,
169107
* @return List of bug numbers
170108
* @throws IOException when failed to access the aru api
171109
*/
172-
public static List<String> getPatchesFor(String category, List<String> patches, UserSession userSession)
110+
public static List<String> getPatchesFor(String category, String version, List<String> patches, UserSession
111+
userSession)
173112
throws
174113
IOException {
175114
List<String> results = new ArrayList<>();
176115
for (String patch : patches) {
177-
String rs = getPatch(category, patch, userSession);
116+
String rs = getPatch(category, version, patch, userSession);
178117
if (rs != null) {
179118
results.add(rs);
180119
}
@@ -184,42 +123,28 @@ public static List<String> getPatchesFor(String category, List<String> patches,
184123
/**
185124
*
186125
* @param patches A list of patches number
187-
* @param category
188-
* @param version
126+
* @param category wls or fmw
127+
* @param version version of the prduct
189128
* @param userId userid for support account
190129
* @param password password for support account
191130
* @throws IOException when failed to access the aru api
192131
*/
193132

194-
public static void validatePatches(List<String> patches, String category, String version, String userId, String
133+
public static void validatePatches(List<String> patches, String category, String version, String userId, String
195134
password) throws IOException {
196135

197136
// TODO
198137

199138
// find the release number first based on the version
200139
// build the xml
140+
//String payload = null;
201141

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>
214-
215-
// Run against POST /Orion/Services/conflict_checks
142+
//HttpUtil.checkConflicts(CONFLICTCHECKER_URL, payload, userId, password);
216143

217144
}
218145

219146
private static Document getAllReleases(String category, String userId, String password) throws IOException {
220147

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)
223148

224149
Document allReleases = HttpUtil.getXMLContent(REL_URL, userId, password);
225150

@@ -272,31 +197,33 @@ private static String getLatestPSU(String category, String release, String userI
272197
return savePatch(allPatches, userId, password);
273198
}
274199

275-
private static String getPatch(String category, String patchNumber, String userId, String password) throws
200+
private static String getPatch(String category, String version, String bugNumber, String userId, String password)
201+
throws
276202
IOException {
277203

278-
// HTTP_STATUS=$(curl -v -w "%{http_code}" -b cookies.txt -L --header 'Authorization: Basic ${basicauth}' "https://updates.oracle.com/Orion/Services/search?product=15991&release=$releaseid&include_prereqs=true" -o latestpsu.xml)
279-
204+
String releaseNumber = getReleaseNumber(category, version, userId, password );
280205
String url;
281206
if ("wls".equalsIgnoreCase(category))
282-
url = String.format(PATCH_SEARCH_URL, WLS_PROD_ID, patchNumber);
207+
url = String.format(PATCH_SEARCH_URL, WLS_PROD_ID, bugNumber, releaseNumber);
283208
else
284-
url = String.format(PATCH_SEARCH_URL, FMW_PROD_ID, patchNumber);
209+
url = String.format(PATCH_SEARCH_URL, FMW_PROD_ID, bugNumber, releaseNumber);
285210

286211
Document allPatches = HttpUtil.getXMLContent(url, userId, password);
287212

288213
return savePatch(allPatches, userId, password);
289214
}
290215

291-
private static String getPatch(String category, String patchNumber, UserSession userSession) throws IOException {
216+
private static String getPatch(String category, String version, String bugNumber, UserSession userSession) throws
217+
IOException {
292218

293-
// HTTP_STATUS=$(curl -v -w "%{http_code}" -b cookies.txt -L --header 'Authorization: Basic ${basicauth}' "https://updates.oracle.com/Orion/Services/search?product=15991&release=$releaseid&include_prereqs=true" -o latestpsu.xml)
219+
User user = userSession.getUser();
220+
String releaseNumber = getReleaseNumber(category, version, user.getEmail(), String.valueOf(user.getPassword()));
294221

295222
String url;
296223
if ("wls".equalsIgnoreCase(category))
297-
url = String.format(PATCH_SEARCH_URL, WLS_PROD_ID, patchNumber);
224+
url = String.format(PATCH_SEARCH_URL, WLS_PROD_ID, bugNumber, releaseNumber);
298225
else
299-
url = String.format(PATCH_SEARCH_URL, FMW_PROD_ID, patchNumber);
226+
url = String.format(PATCH_SEARCH_URL, FMW_PROD_ID, bugNumber, releaseNumber);
300227

301228
Document allPatches = HttpUtil.getXMLContent(url, userSession);
302229

@@ -316,6 +243,10 @@ private static String savePatch(Document allPatches, UserSession userSession) th
316243

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

246+
String releaseNumber = XPathUtil.applyXPathReturnString(allPatches,
247+
"string/results/patch[1]/release/@id)");
248+
249+
String key = bugName + "." + releaseNumber;
319250

320251
int index = downLoadLink.indexOf("patch_file=");
321252

@@ -324,11 +255,11 @@ private static String savePatch(Document allPatches, UserSession userSession) th
324255
index+"patch_file=".length());
325256
// this hasMatchingKeyValue is to make sure that the file value is same as the intended location.
326257
// cache dir can be changed
327-
if (!new File(fileName).exists() || !META_RESOLVER.hasMatchingKeyValue(bugName, fileName)) {
258+
if (!new File(fileName).exists() || !META_RESOLVER.hasMatchingKeyValue(key, fileName)) {
328259
HttpUtil.downloadFile(downLoadHost+downLoadLink, fileName, userSession);
329-
META_RESOLVER.addToCache(bugName, fileName);
260+
META_RESOLVER.addToCache(key, fileName);
330261
} else {
331-
System.out.println(String.format("patch %s already downloaded for bug %s", fileName, bugName));
262+
System.out.println(String.format("patch %s already downloaded for bug %s", fileName, key));
332263
}
333264
return bugName;
334265
}
@@ -353,6 +284,10 @@ private static String savePatch(Document allPatches, String userId, String passw
353284

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

287+
String releaseNumber = XPathUtil.applyXPathReturnString(allPatches,
288+
"string/results/patch[1]/release/@id)");
289+
290+
String key = bugName + "." + releaseNumber;
356291

357292
int index = downLoadLink.indexOf("patch_file=");
358293

@@ -361,11 +296,11 @@ private static String savePatch(Document allPatches, String userId, String passw
361296
index+"patch_file=".length());
362297
// this hasMatchingKeyValue is to make sure that the file value is same as the intended location.
363298
// cache dir can be changed
364-
if (!new File(fileName).exists() || !META_RESOLVER.hasMatchingKeyValue(bugName, fileName)) {
299+
if (!new File(fileName).exists() || !META_RESOLVER.hasMatchingKeyValue(key, fileName)) {
365300
HttpUtil.downloadFile(downLoadHost+downLoadLink, fileName, userId, password);
366-
META_RESOLVER.addToCache(bugName, fileName);
301+
META_RESOLVER.addToCache(key, fileName);
367302
} else {
368-
System.out.println(String.format("patch %s already downloaded for bug %s", fileName, bugName));
303+
System.out.println(String.format("patch %s already downloaded for bug %s", fileName, key));
369304
}
370305
return bugName;
371306
}
@@ -403,10 +338,6 @@ public static boolean checkCredentials(UserSession userSession) {
403338
return retVal;
404339
}
405340

406-
public static void main(String args[]) throws Exception {
407-
ARUUtil.getLatestWLSPSU("12.2.1.3.0","[email protected]", "iJCPiUah7jdmLk1E");
408-
}
409-
410341

411342
}
412343

0 commit comments

Comments
 (0)