Skip to content

Commit

Permalink
Delegate changes to ShellUtils
Browse files Browse the repository at this point in the history
  • Loading branch information
jiacheliu3 committed Dec 16, 2019
1 parent ff51e4f commit b2f984b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 30 deletions.
19 changes: 12 additions & 7 deletions shell/src/main/java/alluxio/cli/bundler/InfoCollectorAll.java
Expand Up @@ -9,6 +9,8 @@
import alluxio.conf.Source;
import alluxio.util.ConfigurationUtils;

import alluxio.util.ShellUtils;
import alluxio.util.io.PathUtils;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import org.slf4j.Logger;
Expand Down Expand Up @@ -69,21 +71,24 @@ public static void main(String[] argv) throws IOException {
// TODO(jiacheng): get hosts from static util call
Set<String> allHosts = shellAll.getHosts();

// TODO(jiacheng): move this to RunCommandUtils
// TODO(jiacheng): move this to ShellUtils
for (String host : allHosts) {
LOG.info(String.format("Execute InfoCollector on host %s", host));

// TODO(jiacheng): Execute InfoCollector
// TODO(jiacheng): 1. Test local invocation no ssh
// TODO(jiacheng): 2. Test local invocation ssh
// TODO(jiacheng): 3. Test multi nodes invocation ssh
// TODO(jiacheng): 4. Test threadpool

LOG.info(String.format("Info bundle finished on host %s", host));
}

// TODO(jiacheng): Invoke this with ShellUtils
for (String host : allHosts) {
LOG.info(String.format("Collecting tarball from host %s", host));

InfoCollector shell = new InfoCollector(conf);
shell.run(argv);
// TODO(jiacheng): SCP collect tarball
}

// TODO(jiacheng): Generate final tarball

System.exit(ret);
}

Expand Down
3 changes: 3 additions & 0 deletions shell/src/main/java/alluxio/cli/bundler/RunCommandUtils.java
@@ -1,12 +1,15 @@
package alluxio.cli.bundler;

import alluxio.util.ShellUtils;
import alluxio.util.io.PathUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.StringWriter;
import java.util.Arrays;
import java.util.List;

public class RunCommandUtils {
private static final Logger LOG = LoggerFactory.getLogger(RunCommandUtils.class);
Expand Down
Expand Up @@ -61,9 +61,8 @@ public boolean hasSubCommand() {
return false;
}

// TODO(jiacheng): format this method
public String getMetricsJson() {
// Generate URL
// Generate URL from parameters
String masterAddr;
try {
masterAddr = mFsContext.getMasterAddress().getHostName();
Expand All @@ -72,14 +71,13 @@ public String getMetricsJson() {
e.printStackTrace();
return String.format("%s", e.getStackTrace());
}
// TODO(jiacheng): Where to get /metrics/json/ ?
String url = String.format("%s:%s/metrics/json/", masterAddr,
mFsContext.getClusterConf().get(PropertyKey.MASTER_WEB_PORT));
LOG.info(String.format("Metric address URL: %s", url));

// Create an instance of HttpClient.
// Create an instance of HttpClient and do Http Get
HttpClient client = new HttpClient();

// Create a method instance.
GetMethod method = new GetMethod(url);

// Provide custom retry handler is necessary
Expand All @@ -90,31 +88,19 @@ public String getMetricsJson() {
// Execute the method.
int statusCode = client.executeMethod(method);

if (statusCode != HttpStatus.SC_OK) {
System.err.println("Method failed: " + method.getStatusLine());
}

// Read the response body.
byte[] responseBody = method.getResponseBody();

// Deal with the response.
// Use caution: ensure correct character encoding and is not binary data
System.out.println(new String(responseBody));

return new String(responseBody);
return String.format("StatusCode: %s\nResponse%s", statusCode, new String(method.getResponseBody()));
} catch (HttpException e) {
System.err.println("Fatal protocol violation: " + e.getMessage());
LOG.error("Fatal protocol violation: " + e.getMessage());
e.printStackTrace();
return String.format("%s", e.getStackTrace());
} catch (IOException e) {
System.err.println("Fatal transport error: " + e.getMessage());
LOG.error("Fatal transport error: " + e.getMessage());
e.printStackTrace();
return String.format("%s", e.getStackTrace());
} finally {
// Release the connection.
method.releaseConnection();
}

// TODO(jiacheng): how to handle this
return "";
}

@Override
Expand Down Expand Up @@ -148,7 +134,6 @@ public int run(CommandLine cl) throws AlluxioException, IOException {
SleepUtils.sleepMs(LOG, 1000 * COLLECT_METRIC_INTERVAL);
}

// TODO(jiacheng): ret
return ret;
}

Expand Down

0 comments on commit b2f984b

Please sign in to comment.