Skip to content

Commit

Permalink
Parse data from TRSS url
Browse files Browse the repository at this point in the history
- TKG Parse data from TRSS url

related:adoptium#558

Signed-off-by: Anna Babu Palathingal <anna.bp@ibm.com>
  • Loading branch information
annaibm committed Jul 4, 2024
1 parent 8fa1aa0 commit 7021053
Showing 1 changed file with 35 additions and 11 deletions.
46 changes: 35 additions & 11 deletions src/org/testKitGen/TestDivider.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.StringReader;
import java.io.FileReader;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
Expand Down Expand Up @@ -229,19 +230,34 @@ private Map<String, Integer> getDataFromTRSS() {
String command = "curl --silent --max-time 120 -L " + URL;
System.out.println("Attempting to get test duration data from TRSS.");
System.out.println(command);
Process process;
try {
process = Runtime.getRuntime().exec(command);
Process process = Runtime.getRuntime().exec(command);
try (InputStream responseStream = process.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(responseStream))) {
String line;
StringBuilder responseBuilder = new StringBuilder();
while ((line = reader.readLine()) != null) {
responseBuilder.append(line);
}
String responseData = responseBuilder.toString();
if (!responseData.isEmpty()) {
try (Reader stringReader = new StringReader(responseData)) {
parseDuration(stringReader, map);
} catch (ParseException e) {
System.out.println("Error parsing the data: " + e.getMessage());
e.printStackTrace();
}
} else {
System.out.println("No data received from TRSS.");
}
} catch (IOException e) {
System.out.println("Error reading input from TRSS: " + e.getMessage());
e.printStackTrace();
}
} catch (IOException e) {
System.out.println("Warning: cannot get data from TRSS.");
return map;
}
try (InputStream responseStream = process.getInputStream();
Reader responseReader = new BufferedReader(new InputStreamReader(responseStream))) {
parseDuration(responseReader, map);
} catch (IOException | ParseException e) {
System.out.println("Warning: cannot parse data from TRSS.");
System.out.println("Error executing curl command or reading input from TRSS: " + e.getMessage());
e.printStackTrace();
return map;
}
return map;
}
Expand Down Expand Up @@ -276,7 +292,15 @@ private Queue<Map.Entry<String, Integer>> createDurationQueue() {
Map<String, Integer> testsInvalid = new HashMap<>();
for (String test : allTests) {
if (matchTRSS.contains(test) || matchCache.contains(test)) {
int duration = TRSSMap.containsKey(test) ? TRSSMap.get(test) : cacheMap.get(test);
int duration;
if (TRSSMap.containsKey(test)) {
duration = TRSSMap.get(test);
System.out.println("TRSSMap.get(" + test + "): " + duration);
} else {
duration = cacheMap.get(test);
System.out.println("cacheMap.get(" + test + "): " + duration);
}
// int duration = TRSSMap.containsKey(test) ? TRSSMap.get(test) : cacheMap.get(test);
if (duration > 0) {
durationQueue.offer(new AbstractMap.SimpleEntry<>(test, duration));
} else {
Expand Down

0 comments on commit 7021053

Please sign in to comment.