Skip to content

Commit

Permalink
chore: handle new local deployment status format
Browse files Browse the repository at this point in the history
  • Loading branch information
jcosentino11 committed Mar 20, 2024
1 parent 45934c8 commit a18dae9
Showing 1 changed file with 46 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,58 @@ String getLocalDeploymentStatus() {
.build());
LOGGER.debug(String.format("deployment status response received for deployment ID %s is %s",
deploymentId, response));
String[] responseArray = response.split(":");
return responseArray[responseArray.length - 1].trim();

int[] cliVersion = getCliVersion();

// backwards compatibility w/ CLI <2.11.0
if (cliVersion[0] < 2 || cliVersion[0] == 2 && cliVersion[1] < 11) {
String[] responseArray = response.split(":");
return responseArray[responseArray.length - 1].trim();
}

return Arrays.stream(response.split("\n"))
.filter(line -> line.contains(":"))
.findFirst() // status is the first line
.map(statusLine -> statusLine.split(": "))
.map(statusParts -> statusParts.length == 2 ? statusParts[1] : null)
.orElse("UNKNOWN");
} catch (CommandExecutionException e) {
LOGGER.info("Exception occurred while getting the deployment status. Will try again", e);
}
return "";
}

private int[] getCliVersion() throws CommandExecutionException {
String resp = platform.commands().executeToString(CommandInput.builder()
.line(testContext.installRoot().resolve("bin").resolve("greengrass-cli").toString())
.addAllArgs(Arrays.asList("component", "details", "--name", "aws.greengrass.Cli"))
.build());
LOGGER.debug("CLI component details: {}", resp);

String versionPrefix = "version: ";
String versionStr = Arrays.stream(resp.split("\n"))
.filter(line -> line.toLowerCase().contains(versionPrefix))
.map(line -> line.substring(versionPrefix.length()))
.findFirst()
.orElse("2.0.0"); // same fallback that CLI itself uses
String[] versionParts = versionStr.split("\\.");
if (versionParts.length != 3) {
LOGGER.warn("Invalid CLI version detected ({}). Falling back to 2.0.0.", versionStr);
return new int[]{2, 0, 0};
}

try {
return new int[]{
Integer.parseInt(versionParts[0]),
Integer.parseInt(versionParts[1]),
Integer.parseInt(versionParts[2])
};
} catch (NumberFormatException e) {
LOGGER.warn("Invalid CLI version detected ({}). Falling back to 2.0.0.", versionStr);
return new int[]{2, 0, 0};
}
}

private boolean isComponentInState(String componentName, String componentStatus) {
String response = platform.commands().executeToString(CommandInput.builder()
.line(testContext.installRoot().resolve("bin").resolve("greengrass-cli").toString())
Expand Down

0 comments on commit a18dae9

Please sign in to comment.