Skip to content

Commit

Permalink
Merge pull request KostyaSha#221 from KostyaSha/printLog
Browse files Browse the repository at this point in the history
Print log for error
  • Loading branch information
KostyaSha authored Jan 31, 2018
2 parents 61c8d59 + 12c22f6 commit 74ad497
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
3 changes: 0 additions & 3 deletions .idea/codeStyleSettings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -169,21 +169,23 @@ public void launch(@Nonnull SlaveComputer computer, TaskListener listener) throw
final DockerCloud dockerCloud = dockerComputer.getCloud();
// Objects.requireNonNull(dockerCloud, "Cloud not found for computer " + computer.getName());
if (isNull(dockerCloud)) {
listener.error("Cloud not found for computer " + computer.getName());
throw new NullPointerException("Cloud not found for computer " + computer.getName());
listener.error("Cloud not found cloud for computer " + computer.getName());
throw new IllegalStateException("Cloud not found cloud for computer " + computer.getName());
}
final DockerClient connect = dockerCloud.getClient();
final DockerClient client = dockerCloud.getClient();
final DockerSlave node = dockerComputer.getNode();
if (isNull(node)) {
throw new NullPointerException("Node can't be null");
listener.error("Failed to run container for %s", computer.getName());
printLog(client, listener, containerId);
throw new IllegalStateException("Node can't be null, probably remote node disappeared.");
}
final DockerSlaveTemplate dockerSlaveTemplate = node.getDockerSlaveTemplate();
final DockerComputerJNLPLauncher launcher = (DockerComputerJNLPLauncher) dockerSlaveTemplate.getLauncher();

final String rootUrl = launcher.getJenkinsUrl(Jenkins.getInstance().getRootUrl());
// Objects.requireNonNull(rootUrl, "Jenkins root url is not specified!");
if (isNull(rootUrl)) {
throw new NullPointerException("Jenkins root url is not specified!");
throw new IllegalStateException("Jenkins root url is not specified!");
}

// exec jnlp connection in running container
Expand All @@ -208,7 +210,7 @@ public void launch(@Nonnull SlaveComputer computer, TaskListener listener) throw
"`$NO_RECONNECT_SLAVE='" + isNoReconnect() + WNL +
"\"@ | Out-File -FilePath c:\\config.ps1";

response = connect.execCreateCmd(containerId)
response = client.execCreateCmd(containerId)
.withTty(true)
.withAttachStdin(false)
.withAttachStderr(true)
Expand All @@ -230,7 +232,7 @@ public void launch(@Nonnull SlaveComputer computer, TaskListener listener) throw
"NO_RECONNECT_SLAVE=\"" + isNoReconnect() + NL +
"EOF" + "\n";

response = connect.execCreateCmd(containerId)
response = client.execCreateCmd(containerId)
.withTty(true)
.withAttachStdin(false)
.withAttachStderr(true)
Expand All @@ -242,7 +244,7 @@ public void launch(@Nonnull SlaveComputer computer, TaskListener listener) throw
LOG.info("Starting connection command for {}...", containerId);
logger.println("Starting connection command for " + containerId);

try (ExecStartResultCallback exec = connect
try (ExecStartResultCallback exec = client
.execStartCmd(response.getId())
.withDetach(true)
.withTty(true)
Expand All @@ -257,7 +259,7 @@ public void launch(@Nonnull SlaveComputer computer, TaskListener listener) throw
} catch (Exception ex) {
listener.error("Can't execute JNLP connection command: " + ex.getMessage().trim());
LOG.error("Can't execute JNLP connection command: '{}'", ex.getMessage().trim());
printLog(connect, listener, containerId);
printLog(client, listener, containerId);
node.terminate();
throw ex;
}
Expand All @@ -281,7 +283,7 @@ public void launch(@Nonnull SlaveComputer computer, TaskListener listener) throw
if (!dockerComputer.isOnline()) {
LOG.info("Launch timeout, terminating slave based on '{}'", containerId);
logger.println("Launch timeout, terminating slave.");
printLog(connect, listener, containerId);
printLog(client, listener, containerId);
node.terminate();
throw new IOException("Can't connect slave to jenkins");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,13 @@ private void provisionWithWait(DockerComputerSingle computer, TaskListener liste
containerLifecycle.getRemoveContainer().exec(client, cId);
throw new IllegalStateException("Jenkins root url is not specified!");
}

final DockerSlaveSingle node = computer.getNode();
if (isNull(node)) {
throw new NullPointerException("Node can't be null for " + computer.getName());
listener.error("Failed to run container for %s", imageId);
printLog(client, listener, containerId);
throw new IllegalStateException("Node for computer: '" + computer.getName() +
"' can't be null, probably remote node disappeared.");
}

// exec jnlp connection in running container
Expand Down

0 comments on commit 74ad497

Please sign in to comment.