use of com.netflix.spinnaker.halyard.core.job.v1.JobStatus in project halyard by spinnaker.
the class GoogleProviderUtils method openSshTunnel.
static URI openSshTunnel(AccountDeploymentDetails<GoogleAccount> details, String instanceName, ServiceSettings service) throws InterruptedException {
int port = service.getPort();
String key = Proxy.buildKey(details.getDeploymentName(), instanceName, port);
Proxy proxy = proxyMap.getOrDefault(key, new Proxy());
JobExecutor jobExecutor = DaemonTaskHandler.getJobExecutor();
if (proxy.getJobId() == null || !jobExecutor.jobExists(proxy.getJobId())) {
String ip = getInstanceIp(details, instanceName);
String keyFile = getSshKeyFile();
log.info("Opening port " + port + " against instance " + instanceName);
boolean connected = false;
int tries = 0;
while (!connected && tries < openSshRetries) {
tries++;
proxy = openSshTunnel(ip, port, keyFile);
connected = checkIfProxyIsOpen(proxy);
if (!connected) {
if (!jobExecutor.jobExists(proxy.jobId) || jobExecutor.updateJob(proxy.jobId).getState() == JobStatus.State.COMPLETED) {
log.warn("SSH tunnel closed prematurely");
}
log.info("SSH tunnel never opened, retrying in case the instance hasn't started yet... (" + tries + "/" + openSshRetries + ")");
closeSshTunnel(proxy);
DaemonTaskHandler.safeSleep(TimeUnit.SECONDS.toMillis(10));
}
}
if (!connected) {
JobStatus status = jobExecutor.updateJob(proxy.getJobId());
throw new HalException(FATAL, "Unable to connect to instance " + instanceName + ": " + status.getStdErr());
}
proxyMap.put(key, proxy);
}
try {
return new URIBuilder().setScheme("http").setHost("localhost").setPort(proxy.getPort()).build();
} catch (URISyntaxException e) {
throw new RuntimeException("Failed to build URI for SSH connection", e);
}
}
use of com.netflix.spinnaker.halyard.core.job.v1.JobStatus in project halyard by spinnaker.
the class VaultService method publishSecret.
public void publishSecret(DeploymentConfiguration deploymentConfiguration, String name, String contents) {
String vaultAddress = deploymentConfiguration.getDeploymentEnvironment().getVault().getAddress();
String encodedContents = Base64.getEncoder().encodeToString(contents.getBytes());
String secretName = vaultSecretPrefix + name;
List<String> command = new ArrayList<>();
command.add("vault");
command.add("write");
command.add("--address");
command.add(vaultAddress);
command.add(secretName);
command.add(encodedContents);
JobRequest request = new JobRequest().setTokenizedCommand(command).setTimeoutMillis(TimeUnit.SECONDS.toMillis(vaultTimeoutSeconds));
String id = jobExecutor.startJob(request);
DaemonTaskHandler.safeSleep(TimeUnit.SECONDS.toMillis(5));
JobStatus status = jobExecutor.updateJob(id);
if (!status.getResult().equals(JobStatus.Result.SUCCESS)) {
throw new HalException(Problem.Severity.FATAL, "Failed to publish secret " + name + ": " + status.getStdOut() + status.getStdErr());
}
}
Aggregations