Skip to content
This repository has been archived by the owner on Jul 11, 2022. It is now read-only.

Commit

Permalink
[BZ 1069547] Separate CliExecutor's concerns.
Browse files Browse the repository at this point in the history
  • Loading branch information
metlos committed Jul 30, 2014
1 parent 2ff3e52 commit 468df67
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 116 deletions.
Expand Up @@ -387,9 +387,9 @@ protected OperationResult startServer() throws InterruptedException {
return operationResult;
}

ProcessExecutionResults results = CliExecutor
ProcessExecutionResults results = ServerControl
.onServer(context.getPluginConfiguration(), getMode(), context.getSystemInformation())
.startServer();
.lifecycle().startServer();
logExecutionResults(results);

if (results.getError() != null) {
Expand Down Expand Up @@ -429,21 +429,21 @@ protected OperationResult runCliCommand(Configuration parameters) throws Interru
result.setErrorMessage("waitTime parameter must be positive integer");
return result;
}
CliExecutor runner = CliExecutor.onServer(context.getPluginConfiguration(), getMode(),
ServerControl.Cli cli = ServerControl.onServer(context.getPluginConfiguration(), getMode(),
context.getSystemInformation()).waitingFor(waitTime * 1000)
.killingOnTimeout(Boolean.parseBoolean(parameters.getSimpleValue("killOnTimeout", "false")));
.killingOnTimeout(Boolean.parseBoolean(parameters.getSimpleValue("killOnTimeout", "false"))).cli();

ProcessExecutionResults results;
String commands = parameters.getSimpleValue("commands");
if (commands != null) {
results = runner.executeCliCommand(commands);
results = cli.executeCliCommand(commands);
} else {
File script = new File(parameters.getSimpleValue("file"));
if (!script.isAbsolute()) {
script = new File(serverPluginConfig.getHomeDir(), script.getPath());
}

results = runner.executeCliScript(script);
results = cli.executeCliScript(script);
}
logExecutionResults(results);

Expand Down Expand Up @@ -759,9 +759,9 @@ protected BundleHandoverResponse handleExecuteScript(BundleHandoverRequest hando
scriptFile = File.createTempFile(handoverRequest.getFilename(), ".tmp", context.getTemporaryDirectory());
FileUtil.writeFile(handoverRequest.getContent(), scriptFile);

ProcessExecutionResults results = CliExecutor.onServer(
ProcessExecutionResults results = ServerControl.onServer(
getServerPluginConfiguration().getPluginConfig(), getMode(), context.getSystemInformation())
.waitingFor(waitTime).killingOnTimeout(killOnTimeout).executeCliScript(scriptFile);
.waitingFor(waitTime).killingOnTimeout(killOnTimeout).cli().executeCliScript(scriptFile);

Throwable error = results.getError();
if (error != null) {
Expand Down
Expand Up @@ -83,15 +83,16 @@ public BundleDeployResult deployBundle(BundleDeployRequest request) {

BundleDeployResult result = new BundleDeployResult();

CliExecutor runner = onServer(request);
ServerControl control = onServer(request);

ASConnection connection = new ASConnection(
ASConnectionParams.createFrom(new ServerPluginConfiguration(request.getReferencedConfiguration())));

ProcessExecutionResults results;
BundleManagerProvider bmp = request.getBundleManagerProvider();
BundleResourceDeployment rd = request.getResourceDeployment();

StopResult stop = stopIfNeeded(connection, runner,
StopResult stop = stopIfNeeded(connection, control,
request.getResourceDeployment().getBundleDeployment().getConfiguration(), bmp, rd);

boolean startUp = stop.hasStopped;
Expand Down Expand Up @@ -127,7 +128,7 @@ public BundleDeployResult deployBundle(BundleDeployRequest request) {
command.append(" --override-modules=").append(overrideModules);
}

results = runner.executeCliCommand(command.toString());
results = control.cli().disconnected(true).executeCliCommand(command.toString());

switch (handleExecutionResults(results, bmp, rd, true)) {
case EXECUTION_ERROR:
Expand All @@ -143,7 +144,7 @@ public BundleDeployResult deployBundle(BundleDeployRequest request) {
}
} finally {
if (startUp) {
String errorMessage = startServer(connection, runner, bmp, rd);
String errorMessage = startServer(connection, control, bmp, rd);
if (errorMessage != null) {
result.setErrorMessage(errorMessage);
}
Expand Down Expand Up @@ -175,14 +176,14 @@ public BundlePurgeResult purgeBundle(BundlePurgeRequest request) {
return result;
}

CliExecutor runner = CliExecutor
ServerControl control = ServerControl
.onServer(request.getReferencedConfiguration(), AS7Mode.valueOf(request.getDestinationTarget().getPath()),
context.getSystemInformation()).disconnected(true);
context.getSystemInformation());

ASConnection connection = new ASConnection(
ASConnectionParams.createFrom(new ServerPluginConfiguration(request.getReferencedConfiguration())));

String errorMessage = rollbackPatches(runner, request.getBundleManagerProvider(),
String errorMessage = rollbackPatches(control, request.getBundleManagerProvider(),
request.getLiveResourceDeployment(), connection, pids);

if (errorMessage != null) {
Expand All @@ -200,7 +201,7 @@ private BundleDeployResult handleRevert(BundleDeployRequest request) {

BundleDeployResult result = new BundleDeployResult();

ProcessExecutionResults results = onServer(request).executeCliCommand("patch history");
ProcessExecutionResults results = onServer(request).cli().disconnected(true).executeCliCommand("patch history");
switch (handleExecutionResults(results, null, null, false)) {
case EXECUTION_ERROR:
result.setErrorMessage(
Expand Down Expand Up @@ -365,21 +366,21 @@ private String fullErrorMessage(String basicMessage, String[] patchIds, int atte
return message;
}

private CliExecutor onServer(BundleDeployRequest request) {
return CliExecutor.onServer(request.getReferencedConfiguration(),
private ServerControl onServer(BundleDeployRequest request) {
return ServerControl.onServer(request.getReferencedConfiguration(),
AS7Mode.valueOf(request.getDestinationTarget().getPath()),
context.getSystemInformation()).disconnected(true);
context.getSystemInformation());
}

private String rollbackPatches(CliExecutor runner, BundleManagerProvider bmp, BundleResourceDeployment rd,
private String rollbackPatches(ServerControl control, BundleManagerProvider bmp, BundleResourceDeployment rd,
ASConnection connection, String... pids) {

ProcessExecutionResults results;

Configuration deploymentConfiguration = rd.getBundleDeployment().getConfiguration();

//if the server is online, let's bring it down for the duration of the rollback.
StopResult stop = stopIfNeeded(connection, runner, deploymentConfiguration, bmp, rd);
StopResult stop = stopIfNeeded(connection, control, deploymentConfiguration, bmp, rd);
boolean serverWasUp = stop.hasStopped;

List<String> patchCommands = new ArrayList<String>();
Expand All @@ -389,10 +390,12 @@ private String rollbackPatches(CliExecutor runner, BundleManagerProvider bmp, Bu

String errorMessage = null;

ServerControl.Cli cli = control.cli().disconnected(true);

try {
int i = 0;
for (String command : patchCommands) {
results = runner.executeCliCommand(command);
results = cli.executeCliCommand(command);
switch (handleExecutionResults(results, bmp, rd, true)) {
case EXECUTION_ERROR:
return fullErrorMessage("Error trying to run patch rollback: " +
Expand All @@ -409,7 +412,7 @@ private String rollbackPatches(CliExecutor runner, BundleManagerProvider bmp, Bu
}
} finally {
if (serverWasUp) {
errorMessage = startServer(connection, runner, bmp, rd);
errorMessage = startServer(connection, control, bmp, rd);
}
}

Expand All @@ -432,7 +435,7 @@ private boolean isServerUp(ASConnection connection) {
return false;
}

private StopResult stopIfNeeded(ASConnection connection, CliExecutor runner,
private StopResult stopIfNeeded(ASConnection connection, ServerControl control,
Configuration bundleDeploymentConfiguration, BundleManagerProvider bmp, BundleResourceDeployment resourceDeployment) {

boolean doRestart = Boolean.valueOf(bundleDeploymentConfiguration.getSimpleValue("restart", "true"));
Expand All @@ -441,7 +444,7 @@ private StopResult stopIfNeeded(ASConnection connection, CliExecutor runner,
audit(bmp, resourceDeployment, "Stop", "Stop", null,
"The server is running. Stopping it before any operation on patches.");

ProcessExecutionResults results = runner.shutdownServer();
ProcessExecutionResults results = control.lifecycle().shutdownServer();
switch (handleExecutionResults(results, bmp, resourceDeployment, true)) {
case EXECUTION_ERROR:
return new StopResult(false, "Error trying to shutdown the server: " + results.getError().getMessage());
Expand All @@ -459,10 +462,10 @@ private StopResult stopIfNeeded(ASConnection connection, CliExecutor runner,
return new StopResult(false, null);
}

private String startServer(ASConnection connection, CliExecutor runner, BundleManagerProvider bmp, BundleResourceDeployment resourceDeployment) {
private String startServer(ASConnection connection, ServerControl control, BundleManagerProvider bmp, BundleResourceDeployment resourceDeployment) {
audit(bmp, resourceDeployment, "Start", "Start", null, "Starting the server back up.");

ProcessExecutionResults results = runner.startServer();
ProcessExecutionResults results = control.lifecycle().startServer();

switch (handleExecutionResults(results, bmp, resourceDeployment, false)) {
case EXECUTION_ERROR:
Expand Down

0 comments on commit 468df67

Please sign in to comment.