Skip to content

Commit d334937

Browse files
Merge branch 'java-poc' of gitlab-odx.oracledx.com:weblogic/image-builder into java-poc
Former-commit-id: f9d9a81b7a86a47dcb08b886ff08bea1214fb715
2 parents 1497e10 + 6737879 commit d334937

File tree

3 files changed

+57
-22
lines changed

3 files changed

+57
-22
lines changed

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

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

3+
import java.io.File;
34
import java.io.IOException;
45
import java.util.List;
56

@@ -70,25 +71,27 @@ public static void getAllFMWReleases(String userId, String password) throws IOEx
7071
/**
7172
* Download the latest WLS patches(PSU) for the release
7273
*
73-
* @param release release number
74+
* @param version release number
7475
* @param userId userid for support account
7576
* @param password password for support account
7677
* @throws IOException when failed to access the aru api
7778
*/
78-
public static void getLatestWLSPatches(String release, String userId, String password) throws IOException {
79-
getLatestPSU("wls", release, userId, password);
79+
public static void getLatestWLSPSU(String version, String userId, String password) throws IOException {
80+
String releaseNumber = getReleaseNumber("wls", version, userId, password);
81+
getLatestPSU("wls", releaseNumber, userId, password);
8082
}
8183

8284
/**
8385
* Download the latest FMW patches(PSU) for the release
8486
*
85-
* @param release release number
87+
* @param version version number 12.2.1.3.0
8688
* @param userId userid for support account
8789
* @param password password for support account
8890
* @throws IOException when failed to access the aru api
8991
*/
90-
public static void getLatestFMWPatches(String release, String userId, String password) throws IOException {
91-
getLatestPSU("fmw", release, userId, password);
92+
public static void getLatestFMWPSU(String version, String userId, String password) throws IOException {
93+
String releaseNumber = getReleaseNumber("wls", version, userId, password);
94+
getLatestPSU("fmw", releaseNumber, userId, password);
9295
}
9396

9497
/**
@@ -187,7 +190,7 @@ private static Document getAllReleases(String category, String userId, String p
187190
}
188191

189192
doc.appendChild(element);
190-
XPathUtil.prettyPrint(doc);
193+
//XPathUtil.prettyPrint(doc);
191194

192195
return doc;
193196

@@ -210,7 +213,8 @@ private static void getLatestPSU(String category, String release, String userId
210213

211214
Document allPatches = HttpUtil.getXMLContent(expression, userId, password);
212215

213-
savepatch(allPatches, userId, password);
216+
//XPathUtil.prettyPrint(allPatches);
217+
savePatch(allPatches, userId, password);
214218
}
215219

216220
private static void getPatch(String category, String patchNumber, String userId, String password) throws
@@ -229,33 +233,38 @@ private static void getPatch(String category, String patchNumber, String userId,
229233

230234
Document allPatches = HttpUtil.getXMLContent(url, userId, password);
231235

232-
savepatch(allPatches, userId, password);
236+
savePatch(allPatches, userId, password);
233237

234238

235239

236240
}
237241

238-
private static void savepatch(Document allPatches, String userId, String password) throws IOException {
242+
private static void savePatch(Document allPatches, String userId, String password) throws IOException {
239243
try {
240244

241245
// TODO: needs to make sure there is one and some filtering if not sorting
242246

243247
String downLoadLink = XPathUtil.applyXPathReturnString(allPatches, "string"
244248
+ "(/results/patch[1]/files/file/download_url/text())");
245249

246-
String doloadHost = XPathUtil.applyXPathReturnString(allPatches, "string"
250+
String downLoadHost = XPathUtil.applyXPathReturnString(allPatches, "string"
247251
+ "(/results/patch[1]/files/file/download_url/@host)");
248252

249-
String bugname = XPathUtil.applyXPathReturnString(allPatches, "string"
250-
+ "(/results/patch[1]/name");
253+
String bugName = XPathUtil.applyXPathReturnString(allPatches, "/results/patch[1]/name");
251254

252-
// TODO find the download location
253255

254-
String fileName = bugname + ".zip";
256+
int index = downLoadLink.indexOf("patch_file=");
255257

256-
HttpUtil.downloadFile(doloadHost+downLoadLink, fileName, userId, password);
258+
if (index > 0) {
259+
String fileName = CacheDownLoadUtil.getDownloadRoot() + File.separator + downLoadLink.substring
260+
(index+"patch_file=".length());
257261

258-
// TODO need method to update the cache data table ?
262+
if (!CacheDownLoadUtil.existsInCache(bugName, fileName)) {
263+
HttpUtil.downloadFile(downLoadHost+downLoadLink, fileName, userId, password);
264+
}
265+
266+
CacheDownLoadUtil.updateTableOfContext(bugName, fileName);
267+
}
259268

260269
} catch (XPathExpressionException xpe) {
261270
throw new IOException(xpe);
@@ -278,7 +287,7 @@ private static String getReleaseNumber(String category, String version, String u
278287
}
279288

280289
public static void main(String args[]) throws Exception {
281-
String release = ARUUtil.getWLSReleaseNumber("121.2.1.3.0","[email protected]", "iJCPiUah7jdmLk1E");
290+
ARUUtil.getLatestWLSPSU("12.2.1.3.0","[email protected]", "iJCPiUah7jdmLk1E");
282291
}
283292

284293

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.oracle.weblogicx.imagebuilder.builder.util;
2+
3+
import java.io.File;
4+
import java.nio.file.Files;
5+
import java.nio.file.Path;
6+
import java.nio.file.Paths;
7+
8+
public class CacheDownLoadUtil {
9+
public static String getDownloadRoot() {
10+
return "/tmp";
11+
}
12+
13+
public static boolean existsInCache(String bugNumber, String fileName) {
14+
String fullPatchName = getDownloadRoot() + File.separator + fileName;
15+
Path path = Paths.get(fullPatchName);
16+
if (Files.exists(path))
17+
return true;
18+
else
19+
System.out.println("already downloaded");
20+
21+
return false;
22+
}
23+
24+
public static void updateTableOfContext(String bugNumber, String fileName) {}
25+
26+
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,13 @@ public static Document getXMLContent(String url, String username, String passwor
7979
* Downlod a file from the url
8080
*
8181
* @param url url of the aru server
82-
* @param destination full path to save the file
82+
* @param fileName full path to save the file
8383
* @param username userid for support account
8484
* @param password password for support account
8585
* @throws IOException when it fails to access the url
8686
*/
8787

88-
public static void downloadFile(String url, String destination, String username, String password)
88+
public static void downloadFile(String url, String fileName, String username, String password)
8989
throws IOException {
9090
RequestConfig.Builder config = RequestConfig.custom();
9191
config.setCircularRedirectsAllowed(true);
@@ -103,7 +103,7 @@ public static void downloadFile(String url, String destination, String username,
103103
httpExecutor.use(cookieStore);
104104

105105
httpExecutor.execute(Request.Get(url).connectTimeout(30000).socketTimeout(30000))
106-
.saveContent(new File(destination));
106+
.saveContent(new File(fileName));
107107

108108
}
109109

@@ -117,7 +117,7 @@ public static void downloadFile(String url, String destination, String username,
117117
* @return
118118
* @throws IOException
119119
*/
120-
120+
121121
public static String checkConflicts(String url, String payload, String username, String password)
122122
throws IOException {
123123
RequestConfig.Builder config = RequestConfig.custom();

0 commit comments

Comments
 (0)