1
1
package com .oracle .weblogicx .imagebuilder .builder .util ;
2
2
3
+ import com .oracle .weblogicx .imagebuilder .builder .api .model .User ;
4
+ import com .oracle .weblogicx .imagebuilder .builder .api .model .UserSession ;
5
+
3
6
import java .io .File ;
4
7
import java .io .IOException ;
5
8
import java .util .ArrayList ;
10
13
import javax .xml .parsers .ParserConfigurationException ;
11
14
import javax .xml .xpath .XPathExpressionException ;
12
15
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 ;
16
16
import org .apache .http .HttpStatus ;
17
17
import org .apache .http .client .HttpResponseException ;
18
18
import org .w3c .dom .Document ;
21
21
import org .w3c .dom .NodeList ;
22
22
23
23
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 ;
25
31
26
32
public class ARUUtil {
27
33
@@ -77,33 +83,6 @@ public static void getAllFMWReleases(String userId, String password) throws IOEx
77
83
getAllReleases ("fmw" , userId , password );
78
84
}
79
85
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
- }
107
86
108
87
/**
109
88
* Download the latest PSU for given category and release
@@ -119,47 +98,6 @@ public static String getLatestPSUFor(String category, String version, UserSessio
119
98
return getLatestPSU (category , releaseNumber , user .getEmail (), String .valueOf (user .getPassword ()));
120
99
}
121
100
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
- }
163
101
164
102
/**
165
103
* Download a list of FMW patches
@@ -169,12 +107,13 @@ public static List<String> getFMWPatches(String category, List<String> patches,
169
107
* @return List of bug numbers
170
108
* @throws IOException when failed to access the aru api
171
109
*/
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 )
173
112
throws
174
113
IOException {
175
114
List <String > results = new ArrayList <>();
176
115
for (String patch : patches ) {
177
- String rs = getPatch (category , patch , userSession );
116
+ String rs = getPatch (category , version , patch , userSession );
178
117
if (rs != null ) {
179
118
results .add (rs );
180
119
}
@@ -184,42 +123,28 @@ public static List<String> getPatchesFor(String category, List<String> patches,
184
123
/**
185
124
*
186
125
* @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
189
128
* @param userId userid for support account
190
129
* @param password password for support account
191
130
* @throws IOException when failed to access the aru api
192
131
*/
193
132
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
195
134
password ) throws IOException {
196
135
197
136
// TODO
198
137
199
138
// find the release number first based on the version
200
139
// build the xml
140
+ //String payload = null;
201
141
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);
216
143
217
144
}
218
145
219
146
private static Document getAllReleases (String category , String userId , String password ) throws IOException {
220
147
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)
223
148
224
149
Document allReleases = HttpUtil .getXMLContent (REL_URL , userId , password );
225
150
@@ -272,31 +197,33 @@ private static String getLatestPSU(String category, String release, String userI
272
197
return savePatch (allPatches , userId , password );
273
198
}
274
199
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
276
202
IOException {
277
203
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 );
280
205
String url ;
281
206
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 );
283
208
else
284
- url = String .format (PATCH_SEARCH_URL , FMW_PROD_ID , patchNumber );
209
+ url = String .format (PATCH_SEARCH_URL , FMW_PROD_ID , bugNumber , releaseNumber );
285
210
286
211
Document allPatches = HttpUtil .getXMLContent (url , userId , password );
287
212
288
213
return savePatch (allPatches , userId , password );
289
214
}
290
215
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 {
292
218
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 ()));
294
221
295
222
String url ;
296
223
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 );
298
225
else
299
- url = String .format (PATCH_SEARCH_URL , FMW_PROD_ID , patchNumber );
226
+ url = String .format (PATCH_SEARCH_URL , FMW_PROD_ID , bugNumber , releaseNumber );
300
227
301
228
Document allPatches = HttpUtil .getXMLContent (url , userSession );
302
229
@@ -316,6 +243,10 @@ private static String savePatch(Document allPatches, UserSession userSession) th
316
243
317
244
String bugName = XPathUtil .applyXPathReturnString (allPatches , "/results/patch[1]/name" );
318
245
246
+ String releaseNumber = XPathUtil .applyXPathReturnString (allPatches ,
247
+ "string/results/patch[1]/release/@id)" );
248
+
249
+ String key = bugName + "." + releaseNumber ;
319
250
320
251
int index = downLoadLink .indexOf ("patch_file=" );
321
252
@@ -324,11 +255,11 @@ private static String savePatch(Document allPatches, UserSession userSession) th
324
255
index +"patch_file=" .length ());
325
256
// this hasMatchingKeyValue is to make sure that the file value is same as the intended location.
326
257
// 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 )) {
328
259
HttpUtil .downloadFile (downLoadHost +downLoadLink , fileName , userSession );
329
- META_RESOLVER .addToCache (bugName , fileName );
260
+ META_RESOLVER .addToCache (key , fileName );
330
261
} 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 ));
332
263
}
333
264
return bugName ;
334
265
}
@@ -353,6 +284,10 @@ private static String savePatch(Document allPatches, String userId, String passw
353
284
354
285
String bugName = XPathUtil .applyXPathReturnString (allPatches , "/results/patch[1]/name" );
355
286
287
+ String releaseNumber = XPathUtil .applyXPathReturnString (allPatches ,
288
+ "string/results/patch[1]/release/@id)" );
289
+
290
+ String key = bugName + "." + releaseNumber ;
356
291
357
292
int index = downLoadLink .indexOf ("patch_file=" );
358
293
@@ -361,11 +296,11 @@ private static String savePatch(Document allPatches, String userId, String passw
361
296
index +"patch_file=" .length ());
362
297
// this hasMatchingKeyValue is to make sure that the file value is same as the intended location.
363
298
// 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 )) {
365
300
HttpUtil .downloadFile (downLoadHost +downLoadLink , fileName , userId , password );
366
- META_RESOLVER .addToCache (bugName , fileName );
301
+ META_RESOLVER .addToCache (key , fileName );
367
302
} 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 ));
369
304
}
370
305
return bugName ;
371
306
}
@@ -403,10 +338,6 @@ public static boolean checkCredentials(UserSession userSession) {
403
338
return retVal ;
404
339
}
405
340
406
- public static void main (String args []) throws Exception {
407
- ARUUtil .
getLatestWLSPSU (
"12.2.1.3.0" ,
"[email protected] " ,
"iJCPiUah7jdmLk1E" );
408
- }
409
-
410
341
411
342
}
412
343
0 commit comments