use of com.google.cloud.dataproc.v1beta2.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.google.cloud.dataproc.v1beta2.JobStatus in project halyard by spinnaker.
the class KubernetesV2Executor method delete.
public void delete(String namespace, String service) {
List<String> command = kubernetesV2Utils.kubectlPrefix(account);
if (StringUtils.isNotEmpty(namespace)) {
command.add("-n=" + namespace);
}
command.add("delete");
command.add("deploy,svc,secret");
command.add("-l=cluster=" + service);
JobRequest request = new JobRequest().setTokenizedCommand(command);
String jobId = executor.startJob(request);
JobStatus status;
try {
status = executor.backoffWait(jobId);
} catch (InterruptedException e) {
throw new DaemonTaskInterrupted(e);
}
if (status.getState() != JobStatus.State.COMPLETED) {
throw new HalException(Problem.Severity.FATAL, String.join("\n", "Deleting service " + service + " never completed", status.getStdErr(), status.getStdOut()));
}
if (status.getResult() != JobStatus.Result.SUCCESS) {
throw new HalException(Problem.Severity.FATAL, String.join("\n", "Deleting service " + service + " failed", status.getStdErr(), status.getStdOut()));
}
}
use of com.google.cloud.dataproc.v1beta2.JobStatus in project halyard by spinnaker.
the class KubernetesV2Executor method deleteSpinnaker.
public void deleteSpinnaker(String namespace) {
List<String> command = kubernetesV2Utils.kubectlPrefix(account);
if (StringUtils.isNotEmpty(namespace)) {
command.add("-n=" + namespace);
}
command.add("delete");
command.add("deploy,svc,secret");
command.add("-l=app=spin");
JobRequest request = new JobRequest().setTokenizedCommand(command);
String jobId = executor.startJob(request);
JobStatus status;
try {
status = executor.backoffWait(jobId);
} catch (InterruptedException e) {
throw new DaemonTaskInterrupted(e);
}
if (status.getState() != JobStatus.State.COMPLETED) {
throw new HalException(Problem.Severity.FATAL, String.join("\n", "Deleting spinnaker never completed in " + namespace, status.getStdErr(), status.getStdOut()));
}
if (status.getResult() != JobStatus.Result.SUCCESS) {
throw new HalException(Problem.Severity.FATAL, String.join("\n", "Deleting spinnaker failed in " + namespace, status.getStdErr(), status.getStdOut()));
}
}
use of com.google.cloud.dataproc.v1beta2.JobStatus in project halyard by spinnaker.
the class KubernetesV2Executor method isReady.
public boolean isReady(String namespace, String service) {
log.info("Checking readiness for " + service);
List<String> command = kubernetesV2Utils.kubectlPrefix(account);
if (StringUtils.isNotEmpty(namespace)) {
command.add("-n=" + namespace);
}
command.add("get");
command.add("po");
command.add("-l=cluster=" + service);
command.add("-o=jsonpath='{.items[*].status.containerStatuses[*].ready}'");
// This command returns a space-separated string of true/false values indicating whether each of
// the pod's containers are READY.
// e.g., if we are querying two spin-orca pods and both pods' monitoring-daemon containers are
// READY but the orca containers are not READY, the output may be 'true false true false'.
JobRequest request = new JobRequest().setTokenizedCommand(command);
String jobId = executor.startJob(request);
JobStatus status;
try {
status = executor.backoffWait(jobId);
} catch (InterruptedException e) {
throw new DaemonTaskInterrupted(e);
}
if (status.getState() != JobStatus.State.COMPLETED) {
throw new HalException(Problem.Severity.FATAL, String.join("\n", "Unterminated readiness check for " + service + " in " + namespace, status.getStdErr(), status.getStdOut()));
}
if (status.getResult() == JobStatus.Result.SUCCESS) {
String readyStatuses = status.getStdOut();
if (readyStatuses.isEmpty()) {
return false;
}
readyStatuses = readyStatuses.substring(1, // Strip leading and trailing single quote
readyStatuses.length() - 1);
if (readyStatuses.isEmpty()) {
return false;
}
return Arrays.stream(readyStatuses.split(" ")).allMatch(s -> s.equals("true"));
} else {
throw new HalException(Problem.Severity.FATAL, String.join("\n", "Failed readiness check for " + service + " in " + namespace, status.getStdErr(), status.getStdOut()));
}
}
use of com.google.cloud.dataproc.v1beta2.JobStatus in project halyard by spinnaker.
the class KubernetesV2Executor method replace.
public void replace(String manifest) {
manifest = kubernetesV2Utils.prettify(manifest);
List<String> command = kubernetesV2Utils.kubectlPrefix(account);
command.add("replace");
command.add("--force");
command.add("-f");
// read from stdin
command.add("-");
JobRequest request = new JobRequest().setTokenizedCommand(command);
ByteArrayOutputStream stdout = new ByteArrayOutputStream();
ByteArrayOutputStream stderr = new ByteArrayOutputStream();
String jobId = executor.startJob(request, System.getenv(), new ByteArrayInputStream(manifest.getBytes()), stdout, stderr);
JobStatus status;
try {
status = executor.backoffWait(jobId);
} catch (InterruptedException e) {
throw new DaemonTaskInterrupted(e);
}
if (status.getState() != JobStatus.State.COMPLETED) {
throw new HalException(Problem.Severity.FATAL, String.join("\n", "Unterminated deployment of manifest:", manifest, stderr.toString(), stdout.toString()));
}
if (status.getResult() != JobStatus.Result.SUCCESS) {
throw new HalException(Problem.Severity.FATAL, String.join("\n", "Failed to deploy manifest:", manifest, stderr.toString(), stdout.toString()));
}
}
Aggregations