|
13 | 13 |
|
14 | 14 | import java.io.File;
|
15 | 15 | import java.net.InetAddress;
|
| 16 | +import java.net.URL; |
| 17 | +import java.net.URI; |
16 | 18 | import java.time.Instant;
|
17 | 19 | import java.util.ArrayList;
|
18 | 20 | import java.util.Arrays;
|
|
22 | 24 | import java.util.stream.Collectors;
|
23 | 25 |
|
24 | 26 | import static edu.caltech.ipac.firefly.core.Util.Opt.ifNotNull;
|
| 27 | +import static edu.caltech.ipac.firefly.core.Util.Try; |
25 | 28 | import static edu.caltech.ipac.firefly.core.background.JobInfo.*;
|
26 | 29 | import static edu.caltech.ipac.firefly.core.background.JobInfo.Phase.COMPLETED;
|
27 |
| -import static edu.caltech.ipac.firefly.core.background.JobInfo.Phase.ERROR; |
28 | 30 | import static edu.caltech.ipac.firefly.core.background.JobManager.getAllUserJobs;
|
29 | 31 | import static edu.caltech.ipac.firefly.core.background.JobManager.updateJobInfo;
|
30 |
| -import static edu.caltech.ipac.firefly.server.query.UwsJobProcessor.*; |
31 |
| -import static edu.caltech.ipac.util.StringUtils.*; |
32 |
| -import static edu.caltech.ipac.firefly.core.Util.Try; |
| 32 | +import static edu.caltech.ipac.firefly.server.query.UwsJobProcessor.convertToJobList; |
| 33 | +import static edu.caltech.ipac.firefly.server.query.UwsJobProcessor.getUwsJobInfo; |
| 34 | +import static edu.caltech.ipac.firefly.server.query.UwsJobProcessor.parse; |
| 35 | +import static edu.caltech.ipac.util.StringUtils.applyIfNotEmpty; |
| 36 | +import static edu.caltech.ipac.util.StringUtils.getInt; |
| 37 | +import static edu.caltech.ipac.util.StringUtils.isEmpty; |
33 | 38 |
|
34 | 39 | public class JobUtil {
|
35 | 40 | // Services are defined as strings with three fields (url|serviceId|serviceType), separated by commas. Only url is required; the others are optional.
|
@@ -97,18 +102,22 @@ public static int importJobHistories(String svcDef) {
|
97 | 102 | String url = svcParts[0].trim();
|
98 | 103 | String svcId = svcParts.length > 1 ? svcParts[1].trim() : null;
|
99 | 104 | String svcType = svcParts.length > 2 ? svcParts[2].trim() : null;
|
100 |
| - |
101 | 105 | if (url.isEmpty()) return count;
|
102 | 106 |
|
103 |
| - LOG.debug("Importing job histories from %s; svcId=%s svcType=%s".formatted(url, svcId, svcType)); |
| 107 | + URL urlObs= Try.it(() -> new URI(url).toURL()).getOrElse((URL)null); |
| 108 | + String paramStr= urlObs == null ? "" : urlObs.getQuery(); |
| 109 | + String urlBase= (!isEmpty(paramStr) && url.contains("?")) ? url.split("\\?")[0] : url; |
| 110 | + |
104 | 111 | List<JobInfo> history = getAllUserJobs();
|
105 | 112 |
|
106 |
| - HttpServiceInput input = HttpServiceInput.createWithCredential(url); |
| 113 | + HttpServiceInput input = HttpServiceInput.createWithCredential(urlBase); |
| 114 | + if (!isEmpty(paramStr)) input.setRequestUrl(input.getRequestUrl()+"?"+paramStr); |
| 115 | + LOG.info("Importing job histories from %s; svcId=%s svcType=%s".formatted(input.getRequestUrl(), svcId, svcType)); |
107 | 116 | Ref<List<JobInfo>> jobList = new Ref<>();
|
108 | 117 | HttpServices.getData(input, r -> {
|
109 | 118 | Try.it(() -> {
|
110 | 119 | Document doc = parse(r.getResponseBodyAsStream());
|
111 |
| - jobList.set(convertToJobList(doc, url)); |
| 120 | + jobList.set(convertToJobList(doc, urlBase)); |
112 | 121 | }).getOrElse(e -> {
|
113 | 122 | LOG.error("Failed to import job histories from %s: %s".formatted(url, e.getMessage()));
|
114 | 123 | });
|
|
0 commit comments