Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions FormatIntWithPercentD
Original file line number Diff line number Diff line change
@@ -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;
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

batch comment demo 1

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());
}
}
}
3 changes: 0 additions & 3 deletions MissingPagination.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down