Skip to content

Commit

Permalink
[WFLY-8355] fix JDR zip file reporting, due to embedded server usage
Browse files Browse the repository at this point in the history
  • Loading branch information
bmaxwell committed Mar 14, 2017
1 parent dcaec3c commit 358e716
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 24 deletions.
Expand Up @@ -28,16 +28,12 @@
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;

import org.jboss.as.cli.scriptsupport.CLI;
import org.jboss.as.cli.scriptsupport.CLI.Result;

import org.jboss.as.controller.client.helpers.ClientConstants;
import org.jboss.as.controller.OperationFailedException;
import org.jboss.as.controller.client.helpers.ClientConstants;
import org.jboss.as.controller.client.helpers.Operations;

import org.jboss.as.jdr.logger.JdrLogger;

import org.jboss.dmr.ModelNode;

/**
Expand Down Expand Up @@ -110,10 +106,13 @@ public static void main(String[] args) {
// Try to run JDR on the Wildfly JVM
CLI cli = CLI.newInstance();
boolean embedded = false;
JdrReport report = null;
try {
System.out.println(String.format("Trying to connect to %s %s:%s", protocol, host, port));
cli.connect(protocol, host, port, null, null);
} catch (IllegalStateException ex) {
String startEmbeddedServer = "embed-server" + ((config != null && ! config.isEmpty()) ? (" --server-config=" + config) : "");
System.out.println("Starting embedded server");
String startEmbeddedServer = "embed-server --std-out=echo " + ((config != null && ! config.isEmpty()) ? (" --server-config=" + config) : "");
cli.getCommandContext().handleSafe(startEmbeddedServer);
embedded = true;
}
Expand All @@ -123,41 +122,48 @@ public static void main(String[] args) {
if(Operations.isSuccessfulOutcome(response) || !embedded) {
reportFailure(response);
ModelNode result = response.get(ClientConstants.RESULT);
String startTime = result.get("start-time").asString();
String endTime = result.get("end-time").asString();
String reportLocation = result.get("report-location").asString();
System.out.println("JDR started: " + startTime);
System.out.println("JDR ended: " + endTime);
System.out.println("JDR location: " + reportLocation);
report = new JdrReport(result);
} else {
standaloneCollect(cli, protocol, host, port);
report = standaloneCollect(cli, protocol, host, port);
}
} catch(IllegalStateException ise) {
System.out.println(ise.getMessage());
standaloneCollect(cli, protocol, host, port);
report = standaloneCollect(cli, protocol, host, port);
} finally {
if(cli != null) {
try {
cli.disconnect();
if(embedded)
cli.getCommandContext().handleSafe("stop-embedded-server");
else
cli.disconnect();
} catch(Exception e) {
System.out.println("Caught exception while disconnecting: " + e.getMessage());
}
}
}
printJdrReportInfo(report);
System.exit(0);
}

private static void standaloneCollect(CLI cli, String protocol, String host, int port) {
private static void printJdrReportInfo(JdrReport report) {
if(report != null) {
System.out.println("JDR started: " + report.getStartTime().toString());
System.out.println("JDR ended: " + report.getEndTime().toString());
System.out.println("JDR location: " + report.getLocation());
System.out.flush();
}
}

private static JdrReport standaloneCollect(CLI cli, String protocol, String host, int port) {
// Unable to connect to a running server, so proceed without it
JdrReportService reportService = new JdrReportService();
JdrReport report = null;
try {
JdrReport response = reportService.standaloneCollect(cli, protocol, host, port);
System.out.println("JDR started: " + response.getStartTime().toString());
System.out.println("JDR ended: " + response.getEndTime().toString());
System.out.println("JDR location: " + response.getLocation());
report = reportService.standaloneCollect(cli, protocol, host, port);
} catch (OperationFailedException e) {
System.out.println("Failed to complete the JDR report: " + e.getMessage());
}
return report;
}

private static void reportFailure(final ModelNode node) {
Expand Down
19 changes: 18 additions & 1 deletion jdr/jboss-as-jdr/src/main/java/org/jboss/as/jdr/JdrReport.java
Expand Up @@ -21,16 +21,22 @@
*/
package org.jboss.as.jdr;

import static org.jboss.as.jdr.logger.JdrLogger.ROOT_LOGGER;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Properties;
import static org.jboss.as.jdr.logger.JdrLogger.ROOT_LOGGER;

import org.jboss.dmr.ModelNode;

/**
* Provides metadata about and access to the data collected by a {@link JdrReportCollector}.
Expand Down Expand Up @@ -59,9 +65,20 @@ public class JdrReport {
private String location;
private String jdrUuid;

private static DateFormat DATE_FORMAT = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy");

public JdrReport() {
}

public JdrReport(ModelNode result) {
try {
setStartTime(DATE_FORMAT.parse(result.get("start-time").asString()));
setEndTime(DATE_FORMAT.parse(result.get("end-time").asString()));
} catch(ParseException pe) {
}
setLocation(result.get("report-location").asString());
}

/**
* Indicates the time the JDR report collection was initiated.
*/
Expand Down
Expand Up @@ -43,4 +43,9 @@ private JdrReportSubsystemAdd() {
protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {
JdrReportService.addService(context.getServiceTarget());
}
}

@Override
protected boolean requiresRuntime(OperationContext context) {
return context.getProcessType().isServer();
}
}
Expand Up @@ -42,5 +42,8 @@ protected void performRuntime(OperationContext context, ModelNode operation, Mod
// TODO remove any other services we add in JdrReportSubsystemAdd
}


}
@Override
protected boolean requiresRuntime(OperationContext context) {
return context.getProcessType().isServer();
}
}
Expand Up @@ -69,6 +69,7 @@ public List<JdrCommand> getCommands() throws Exception {
);
}

@Override
public PluginId getPluginId() {
return pluginId;
}
Expand Down

0 comments on commit 358e716

Please sign in to comment.