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:#558

Signed-off-by: Anna Babu Palathingal <[email protected]>
  • Loading branch information
annaibm committed Jul 22, 2024
1 parent 4d4c26a commit 9db2ee5
Showing 1 changed file with 59 additions and 13 deletions.
72 changes: 59 additions & 13 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 @@ -226,21 +227,58 @@ private Map<String, Integer> getDataFromTRSS() {
String level = getLevel();
Map<String, Integer> map = new HashMap<String, Integer>();
String URL = constructURL(impl, plat, group, level);
String command = "curl --silent --max-time 120 -L " + URL;
String osName = System.getProperty("os.name").toLowerCase();
String responseFilePath = new File("response.json").getAbsolutePath();
String command;

if (osName.contains("win")) {
command = "cmd.exe /c curl --silent --max-time 120 -L -k \"" + URL + "\" -o " + responseFilePath;
} else {
command = "curl --silent --max-time 120 -L -k "+ URL + " -o " + responseFilePath;
}

System.out.println("Attempting to get test duration data from TRSS.");
System.out.println(command);
Process process;

try {
process = Runtime.getRuntime().exec(command);
} 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.");
Process process = Runtime.getRuntime().exec(command);
int exitCode = process.waitFor();

if (exitCode != 0) {
System.out.println("Curl command failed with exit code " + exitCode);
return map;
}

File responseFile = new File(responseFilePath);
System.out.println("Response data written to file: " + responseFile.getAbsolutePath());

if (!responseFile.exists() || responseFile.length() == 0) {
System.out.println("Response file does not exist or is empty.");
return map;
}

StringBuilder responseData = new StringBuilder();
try (BufferedReader fileReader = new BufferedReader(new FileReader(responseFile))) {
String line;
while ((line = fileReader.readLine()) != null) {
responseData.append(line).append(System.lineSeparator());
}
} catch (IOException e) {
System.out.println("Error reading the response file: " + e.getMessage());
e.printStackTrace();
return map;
}

System.out.println("Response Data: " + responseData.toString());

try (Reader fileReader = new FileReader(responseFile)) {
parseDuration(fileReader, map);
} catch (IOException | ParseException e) {
System.out.println("Error reading or parsing the response file: " + e.getMessage());
e.printStackTrace();
}
} catch (IOException | InterruptedException e) {
System.out.println("Error executing curl command or reading input from TRSS: " + e.getMessage());
e.printStackTrace();
}
return map;
Expand Down Expand Up @@ -276,7 +314,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 9db2ee5

Please sign in to comment.