From d82a3d1e4acaf14ccd742cfbd3585ec17dfc217c Mon Sep 17 00:00:00 2001 From: himanikh Date: Fri, 13 Mar 2020 13:15:22 -0700 Subject: [PATCH 1/2] Create FormatIntWithPercentD --- FormatIntWithPercentD | 74 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 FormatIntWithPercentD diff --git a/FormatIntWithPercentD b/FormatIntWithPercentD new file mode 100644 index 0000000..a221cbd --- /dev/null +++ b/FormatIntWithPercentD @@ -0,0 +1,74 @@ +package com.amazon.rds.bourne.connector.controlplaneapi.patching.serviceconfigurator; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; + +import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class FormatIntWithPercentD { + private static final Logger LOG = LoggerFactory.getLogger(VMWApplianceConfigurationHelper.class); + + public void runProcess(final ProcessBuilder pb, final String successOutput) { + int exitValue; + Process p = null; + final StringBuilder stdoutSB = new StringBuilder(); + final StringBuilder stderrSB = new StringBuilder(); + boolean isConfigured = false; + try { + p = pb.start(); + try (BufferedReader stdoutBR = new BufferedReader(new InputStreamReader(p.getInputStream(), + StandardCharsets.UTF_8)); + BufferedReader stderrBR = new BufferedReader(new InputStreamReader(p.getErrorStream(), + StandardCharsets.UTF_8))) { + String line; + while ((line = stdoutBR.readLine()) != null) { + stdoutSB.append(line); + stdoutSB.append("\n"); + if (StringUtils.equalsIgnoreCase(line, successOutput)) { + isConfigured = true; + } + } + + while ((line = stderrBR.readLine()) != null) { + stderrSB.append(line); + stderrSB.append("\n"); + } + + exitValue = p.waitFor(); + } + } catch (final Exception e) { + throw new RuntimeException("Got exception running process to configure VMW appliance.", e); + } finally { + try { + if (p != null) { + p.destroy(); + if (p.getInputStream() != null) { + p.getInputStream().close(); + } + if (p.getOutputStream() != null) { + p.getOutputStream().close(); + } + if (p.getErrorStream() != null) { + p.getErrorStream().close(); + } + } + } catch (final IOException e) { + LOG.warn("Got exception in closing process streams", e); + } + } + + if (exitValue != 0 || !isConfigured) { + final String msg = String.format( + "Process did not complete successfully. Exit value [%s]. stdout [%s]. stderr[%s].", + exitValue, stdoutSB.toString(), stderrSB.toString()); + throw new RuntimeException(msg); + } else { + LOG.info("VMW appliance configured successfully. stdout [{}]. stderr [{}].", stdoutSB.toString(), + stderrSB.toString()); + } + } +} From 755a32375d0b0c0a0bbd321d810806844948256f Mon Sep 17 00:00:00 2001 From: himanikh Date: Fri, 13 Mar 2020 13:22:09 -0700 Subject: [PATCH 2/2] Update MissingPagination.java --- MissingPagination.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/MissingPagination.java b/MissingPagination.java index 765ee3f..e278e96 100644 --- a/MissingPagination.java +++ b/MissingPagination.java @@ -5,9 +5,6 @@ import com.amazonaws.services.cloudformation.AmazonCloudFormationClientBuilder; import com.amazonaws.services.cloudformation.model.AmazonCloudFormationException; import com.amazonaws.services.cloudformation.model.GetTemplateRequest; -import com.amazonaws.services.cloudformation.model.GetTemplateResult; -import com.amazonaws.services.cloudformation.model.ListStacksResult; -import com.amazonaws.services.cloudformation.model.StackSummary; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;