20
20
import org .w3c .dom .NodeList ;
21
21
22
22
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 ;
24
30
25
31
public class ARUUtil {
26
32
@@ -76,33 +82,6 @@ public static void getAllFMWReleases(String userId, String password) throws IOEx
76
82
getAllReleases ("fmw" , userId , password );
77
83
}
78
84
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
- }
106
85
107
86
/**
108
87
* Download the latest PSU for given category and release
@@ -119,46 +98,19 @@ public static String getLatestPSUFor(String category, String version, String use
119
98
}
120
99
121
100
/**
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
128
107
*/
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 );
139
111
}
140
112
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
+
162
114
163
115
/**
164
116
* Download a list of FMW patches
@@ -169,57 +121,92 @@ public static List<String> getFMWPatches(String category, List<String> patches,
169
121
* @return List of bug numbers
170
122
* @throws IOException when failed to access the aru api
171
123
*/
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 )
173
125
throws
174
126
IOException {
175
127
List <String > results = new ArrayList <>();
176
128
for (String patch : patches ) {
177
- String rs = getPatch (category , patch , userId , password );
129
+ String rs = getPatch (category , version , patch , userId , password );
178
130
if (rs != null ) {
179
131
results .add (rs );
180
132
}
181
133
}
182
134
return results ;
183
135
}
136
+
184
137
/**
185
138
*
186
139
* @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
189
142
* @param userId userid for support account
190
143
* @param password password for support account
191
144
* @throws IOException when failed to access the aru api
192
145
*/
193
146
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
195
148
password ) throws IOException {
196
149
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 );
198
180
199
- // find the release number first based on the version
200
- // build the xml
181
+ if (n instanceof Element )
182
+ element .appendChild (copyNode );
183
+ }
201
184
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 );
214
191
215
- // Run against POST /Orion/Services/conflict_checks
192
+ return true ;
216
193
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 ;
217
206
}
218
207
219
208
private static Document getAllReleases (String category , String userId , String password ) throws IOException {
220
209
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
210
224
211
Document allReleases = HttpUtil .getXMLContent (REL_URL , userId , password );
225
212
@@ -259,25 +246,43 @@ private static Document getAllReleases(String category, String userId, String p
259
246
260
247
private static String getLatestPSU (String category , String release , String userId , String password ) throws
261
248
IOException {
262
- return getPatchOrPSU (category , release , userId , password , LATEST_PSU_URL );
263
- }
264
249
265
- private static String getPatchOrPSU (String category , String release , String userId , String password , String searchURL ) throws IOException {
266
250
String expression ;
267
251
if ("wls" .equalsIgnoreCase (category ))
268
- expression = String .format (searchURL , WLS_PROD_ID , release );
252
+ expression = String .format (LATEST_PSU_URL , WLS_PROD_ID , release );
269
253
else
270
- expression = String .format (searchURL , FMW_PROD_ID , release );
254
+ expression = String .format (LATEST_PSU_URL , FMW_PROD_ID , release );
255
+
271
256
Document allPatches = HttpUtil .getXMLContent (expression , userId , password );
272
257
return savePatch (allPatches , userId , password );
273
258
}
274
259
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
276
261
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 );
281
286
}
282
287
283
288
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
293
298
294
299
String bugName = XPathUtil .applyXPathReturnString (allPatches , "/results/patch[1]/name" );
295
300
301
+ String releaseNumber = XPathUtil .applyXPathReturnString (allPatches ,
302
+ "string(/results/patch[1]/release/@id)" );
303
+
304
+ String key = bugName + "." + releaseNumber ;
296
305
297
306
int index = downLoadLink .indexOf ("patch_file=" );
298
307
@@ -301,11 +310,11 @@ private static String savePatch(Document allPatches, String userId, String passw
301
310
index +"patch_file=" .length ());
302
311
// this hasMatchingKeyValue is to make sure that the file value is same as the intended location.
303
312
// 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 )) {
305
314
HttpUtil .downloadFile (downLoadHost +downLoadLink , fileName , userId , password );
306
- META_RESOLVER .addToCache (bugName , fileName );
315
+ META_RESOLVER .addToCache (key , fileName );
307
316
} 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 ));
309
318
}
310
319
return bugName ;
311
320
}
@@ -345,10 +354,6 @@ public static boolean checkCredentials(String username, String password) {
345
354
return true ;
346
355
}
347
356
348
- public static void main (String args []) throws Exception {
349
- ARUUtil .
getLatestWLSPSU (
"12.2.1.3.0" ,
"[email protected] " ,
"iJCPiUah7jdmLk1E" );
350
- }
351
-
352
357
353
358
}
354
359
0 commit comments