static private boolean checkIfProxyIsOpen(Proxy proxy) { boolean connected = false; int tries = 0; int port = proxy.getPort(); while (!connected && tries < connectRetries) { tries++; try { log.info("Attempting to connect to localhost:" + port + "..."); Socket testSocket = new Socket("localhost", port); log.info("Connection opened"); connected = testSocket.isConnected(); testSocket.close(); } catch (IOException e) { DaemonTaskHandler.safeSleep(TimeUnit.SECONDS.toMillis(5)); } } return connected; }
static private boolean checkIfProxyIsOpen(Proxy proxy) { boolean connected = false; int tries = 0; int port = proxy.getPort(); while (!connected && tries < connectRetries) { tries++; try { log.info("Attempting to connect to localhost:" + port + "..."); Socket testSocket = new Socket("localhost", port); log.info("Connection opened"); connected = testSocket.isConnected(); testSocket.close(); } catch (IOException e) { DaemonTaskHandler.safeSleep(TimeUnit.SECONDS.toMillis(5)); } } return connected; }
private static void waitOnOperation(Supplier<Operation> operationSupplier) { Operation operation = operationSupplier.get(); while (!operation.getStatus().equals("DONE")) { if (operation.getError() != null) { throw new HalException(FATAL, String.join("\n", operation.getError() .getErrors() .stream() .map(e -> e.getCode() + ": " + e.getMessage()).collect(Collectors.toList()))); } operation = operationSupplier.get(); DaemonTaskHandler.safeSleep(TimeUnit.SECONDS.toMillis(1)); } }
private static void waitOnOperation(Supplier<Operation> operationSupplier) { Operation operation = operationSupplier.get(); while (!operation.getStatus().equals("DONE")) { if (operation.getError() != null) { throw new HalException(FATAL, String.join("\n", operation.getError() .getErrors() .stream() .map(e -> e.getCode() + ": " + e.getMessage()).collect(Collectors.toList()))); } operation = operationSupplier.get(); DaemonTaskHandler.safeSleep(TimeUnit.SECONDS.toMillis(1)); } }
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()); } } }
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()); } } }
private void monitor(Supplier<Pipeline> getPipeline) { String status; Pipeline pipeline; Set<String> loggedTasks = new HashSet<>(); try { pipeline = getPipeline.get(); status = pipeline.getStatus(); while (status.equalsIgnoreCase("running") || status.equalsIgnoreCase("not_started")) { logPipelineOutput(pipeline, loggedTasks); DaemonTaskHandler.safeSleep(TimeUnit.SECONDS.toMillis(10)); pipeline = getPipeline.get(); status = pipeline.getStatus(); } } catch (RetrofitError e) { throw new HalException(new ProblemBuilder(Problem.Severity.FATAL, "Failed to monitor task: " + e.getMessage()).build()); } logPipelineOutput(pipeline, loggedTasks); if (status.equalsIgnoreCase("terminal")) { Problem problem = findExecutionError(pipeline); throw new HalException(problem); } }
private void monitor(Supplier<Pipeline> getPipeline) { String status; Pipeline pipeline; Set<String> loggedTasks = new HashSet<>(); try { pipeline = getPipeline.get(); status = pipeline.getStatus(); while (status.equalsIgnoreCase("running") || status.equalsIgnoreCase("not_started")) { logPipelineOutput(pipeline, loggedTasks); DaemonTaskHandler.safeSleep(TimeUnit.SECONDS.toMillis(10)); pipeline = getPipeline.get(); status = pipeline.getStatus(); } } catch (RetrofitError e) { throw new HalException(new ProblemBuilder(Problem.Severity.FATAL, "Failed to monitor task: " + e.getMessage()).build()); } logPipelineOutput(pipeline, loggedTasks); if (status.equalsIgnoreCase("terminal")) { Problem problem = findExecutionError(pipeline); throw new HalException(problem); } }
DaemonTaskHandler.safeSleep(TimeUnit.SECONDS.toMillis(1)); status = jobExecutor.updateJob(jobId);
DaemonTaskHandler.safeSleep(TimeUnit.SECONDS.toMillis(1)); status = jobExecutor.updateJob(jobId);
@Override public Jedis connectToPrimaryService(AccountDeploymentDetails<KubernetesAccount> details, SpinnakerRuntimeSettings runtimeSettings) { ServiceSettings settings = runtimeSettings.getServiceSettings(this); List<String> command = Arrays.stream(connectCommand(details, runtimeSettings).split(" ")).collect(Collectors.toList()); JobRequest request = new JobRequest().setTokenizedCommand(command); String jobId = getJobExecutor().startJob(request); // Wait for the proxy to spin up. DaemonTaskHandler.safeSleep(TimeUnit.SECONDS.toMillis(5)); JobStatus status = getJobExecutor().updateJob(jobId); // This should be a long-running job. if (status.getState() == JobStatus.State.COMPLETED) { throw new HalException(Problem.Severity.FATAL, "Unable to establish a proxy against Redis:\n" + status.getStdOut() + "\n" + status.getStdErr()); } return new Jedis("localhost", settings.getPort()); }
@Override public Jedis connectToPrimaryService(AccountDeploymentDetails<KubernetesAccount> details, SpinnakerRuntimeSettings runtimeSettings) { ServiceSettings settings = runtimeSettings.getServiceSettings(this); List<String> command = Arrays.stream(connectCommand(details, runtimeSettings).split(" ")).collect(Collectors.toList()); JobRequest request = new JobRequest().setTokenizedCommand(command); String jobId = getJobExecutor().startJob(request); // Wait for the proxy to spin up. DaemonTaskHandler.safeSleep(TimeUnit.SECONDS.toMillis(5)); JobStatus status = getJobExecutor().updateJob(jobId); // This should be a long-running job. if (status.getState() == JobStatus.State.COMPLETED) { throw new HalException(Problem.Severity.FATAL, "Unable to establish a proxy against Redis:\n" + status.getStdOut() + "\n" + status.getStdErr()); } return new Jedis("localhost", settings.getPort()); }
DaemonTaskHandler.safeSleep(TimeUnit.SECONDS.toMillis(2)); status = jobExecutor.updateJob(proxy.jobId);
DaemonTaskHandler.safeSleep(TimeUnit.SECONDS.toMillis(2)); status = jobExecutor.updateJob(proxy.jobId);
DaemonTaskHandler.safeSleep(TimeUnit.SECONDS.toMillis(10));
DaemonTaskHandler.safeSleep(TimeUnit.SECONDS.toMillis(10));
@Override default <S> S connectToInstance(AccountDeploymentDetails<KubernetesAccount> details, SpinnakerRuntimeSettings runtimeSettings, SpinnakerService<S> sidecar, String instanceId) { ServiceSettings settings = runtimeSettings.getServiceSettings(sidecar); String namespace = getNamespace(settings); int localPort = SocketUtils.findAvailableTcpPort(); int targetPort = settings.getPort(); List<String> command = KubernetesV1ProviderUtils.kubectlPortForwardCommand(details, namespace, instanceId, targetPort, localPort); JobRequest request = new JobRequest().setTokenizedCommand(command); String jobId = getJobExecutor().startJob(request); // Wait for the proxy to spin up. DaemonTaskHandler.safeSleep(TimeUnit.SECONDS.toMillis(5)); JobStatus status = getJobExecutor().updateJob(jobId); // This should be a long-running job. if (status.getState() == JobStatus.State.COMPLETED) { throw new HalException(Problem.Severity.FATAL, "Unable to establish a proxy against " + getServiceName() + ":\n" + status.getStdOut() + "\n" + status.getStdErr()); } return getServiceInterfaceFactory().createService(settings.getScheme() + "://localhost:" + localPort, sidecar); }
@Override default <S> S connectToInstance(AccountDeploymentDetails<KubernetesAccount> details, SpinnakerRuntimeSettings runtimeSettings, SpinnakerService<S> sidecar, String instanceId) { ServiceSettings settings = runtimeSettings.getServiceSettings(sidecar); String namespace = getNamespace(settings); int localPort = SocketUtils.findAvailableTcpPort(); int targetPort = settings.getPort(); List<String> command = KubernetesV1ProviderUtils.kubectlPortForwardCommand(details, namespace, instanceId, targetPort, localPort); JobRequest request = new JobRequest().setTokenizedCommand(command); String jobId = getJobExecutor().startJob(request); // Wait for the proxy to spin up. DaemonTaskHandler.safeSleep(TimeUnit.SECONDS.toMillis(5)); JobStatus status = getJobExecutor().updateJob(jobId); // This should be a long-running job. if (status.getState() == JobStatus.State.COMPLETED) { throw new HalException(Problem.Severity.FATAL, "Unable to establish a proxy against " + getServiceName() + ":\n" + status.getStdOut() + "\n" + status.getStdErr()); } return getServiceInterfaceFactory().createService(settings.getScheme() + "://localhost:" + localPort, sidecar); }
DaemonTaskHandler.message("Waiting for service to be ready..."); while (!executor.isReady(service.getNamespace(settings), service.getServiceName())) { DaemonTaskHandler.safeSleep(TimeUnit.SECONDS.toMillis(5));
ready = version.equals(runningVersion); DaemonTaskHandler.safeSleep(TimeUnit.SECONDS.toMillis(2));