Search in sources :

Example 1 with ProblemBuilder

use of com.netflix.spinnaker.halyard.core.problem.v1.ProblemBuilder in project halyard by spinnaker.

the class ConfigParser method read.

public <T> T read(Path path, Class<T> tClass) {
    try {
        InputStream is = new FileInputStream(path.toFile());
        Object obj = yamlParser.load(is);
        return objectMapper.convertValue(obj, tClass);
    } catch (IllegalArgumentException e) {
        throw new HalException(new ProblemBuilder(Problem.Severity.FATAL, "Failed to load " + tClass.getSimpleName() + " config: " + e.getMessage()).build());
    } catch (FileNotFoundException e) {
        throw new HalException(new ProblemBuilder(Problem.Severity.FATAL, "Failed to find " + tClass.getSimpleName() + " config: " + e.getMessage()).build());
    }
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) HalException(com.netflix.spinnaker.halyard.core.error.v1.HalException) FileNotFoundException(java.io.FileNotFoundException) FileInputStream(java.io.FileInputStream) ProblemBuilder(com.netflix.spinnaker.halyard.core.problem.v1.ProblemBuilder)

Example 2 with ProblemBuilder

use of com.netflix.spinnaker.halyard.core.problem.v1.ProblemBuilder in project halyard by spinnaker.

the class ConfigParser method atomicWrite.

public void atomicWrite(Path path, Object obj) {
    String contents = yamlToString(obj);
    AtomicFileWriter writer = null;
    try {
        writer = new AtomicFileWriter(path);
        writer.write(contents);
        writer.commit();
    } catch (IOException ioe) {
        ioe.printStackTrace();
        throw new HalException(new ProblemBuilder(Problem.Severity.FATAL, "Failed to write config for profile " + path.toFile().getName() + ": " + ioe.getMessage()).build());
    } finally {
        if (writer != null) {
            writer.close();
        }
    }
}
Also used : AtomicFileWriter(com.netflix.spinnaker.halyard.core.AtomicFileWriter) HalException(com.netflix.spinnaker.halyard.core.error.v1.HalException) IOException(java.io.IOException) ProblemBuilder(com.netflix.spinnaker.halyard.core.problem.v1.ProblemBuilder)

Example 3 with ProblemBuilder

use of com.netflix.spinnaker.halyard.core.problem.v1.ProblemBuilder in project halyard by spinnaker.

the class OrcaRunner method monitor.

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);
    }
}
Also used : HalException(com.netflix.spinnaker.halyard.core.error.v1.HalException) Problem(com.netflix.spinnaker.halyard.core.problem.v1.Problem) RetrofitError(retrofit.RetrofitError) ProblemBuilder(com.netflix.spinnaker.halyard.core.problem.v1.ProblemBuilder)

Example 4 with ProblemBuilder

use of com.netflix.spinnaker.halyard.core.problem.v1.ProblemBuilder in project halyard by spinnaker.

the class VaultServerService method getToken.

public String getToken(String deploymentName, Vault vault) {
    String result = "";
    InitStatus initStatus;
    try {
        initStatus = vault.initStatus();
    } catch (RetrofitError e) {
        throw handleVaultError(e, "check init status");
    }
    if (!initStatus.isInitialized()) {
        try {
            InitResponse init = vault.init(new InitRequest().setSecretShares(3).setSecretThreshold(3));
            result = init.getRootToken();
            for (String key : init.getKeys()) {
                vault.unseal(new UnsealRequest().setKey(key));
            }
        } catch (RetrofitError e) {
            throw handleVaultError(e, "init vault");
        }
    }
    SealStatus sealStatus;
    try {
        sealStatus = vault.sealStatus();
    } catch (RetrofitError e) {
        throw handleVaultError(e, "check seal status");
    }
    if (sealStatus.isSealed()) {
        throw new HalException(Problem.Severity.FATAL, "Your vault is in a sealed state, no config can be written.");
    }
    File vaultTokenFile = halconfigDirectoryStructure.getVaultTokenPath(deploymentName).toFile();
    if (result.isEmpty()) {
        try {
            result = IOUtils.toString(new FileInputStream(vaultTokenFile));
        } catch (IOException e) {
            throw new HalException(new ProblemBuilder(Problem.Severity.FATAL, "Unable to read vault token: " + e.getMessage()).setRemediation("This file is needed for storing credentials to your vault server. " + "If you have deployed vault by hand, make sure Halyard can authenticate using the token in that file.").build());
        }
    } else {
        try {
            IOUtils.write(result.getBytes(), new FileOutputStream(vaultTokenFile));
        } catch (IOException e) {
            throw new HalException(Problem.Severity.FATAL, "Unable to write vault token: " + e.getMessage());
        }
    }
    return result;
}
Also used : HalException(com.netflix.spinnaker.halyard.core.error.v1.HalException) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) ProblemBuilder(com.netflix.spinnaker.halyard.core.problem.v1.ProblemBuilder) FileOutputStream(java.io.FileOutputStream) File(java.io.File) RetrofitError(retrofit.RetrofitError)

Example 5 with ProblemBuilder

use of com.netflix.spinnaker.halyard.core.problem.v1.ProblemBuilder in project halyard by spinnaker.

the class DistributedDeployer method deploy.

@Override
public RemoteAction deploy(DistributedServiceProvider<T> serviceProvider, AccountDeploymentDetails<T> deploymentDetails, ResolvedConfiguration resolvedConfiguration, List<SpinnakerService.Type> serviceTypes) {
    SpinnakerRuntimeSettings runtimeSettings = resolvedConfiguration.getRuntimeSettings();
    DaemonTaskHandler.newStage("Deploying Spinnaker");
    // First deploy all services not owned by Spinnaker
    for (DistributedService distributedService : serviceProvider.getPrioritizedDistributedServices(serviceTypes)) {
        SpinnakerService service = distributedService.getService();
        ServiceSettings settings = resolvedConfiguration.getServiceSettings(service);
        if (!settings.getEnabled() || settings.getSkipLifeCycleManagement()) {
            continue;
        }
        DaemonTaskHandler.newStage("Determining status of " + distributedService.getServiceName());
        boolean safeToUpdate = settings.getSafeToUpdate();
        RunningServiceDetails runningServiceDetails = distributedService.getRunningServiceDetails(deploymentDetails, runtimeSettings);
        if (distributedService.isRequiredToBootstrap() || !safeToUpdate) {
            deployServiceManually(deploymentDetails, resolvedConfiguration, distributedService, safeToUpdate);
        } else {
            DaemonResponse.StaticRequestBuilder<Void> builder = new DaemonResponse.StaticRequestBuilder<>(() -> {
                if (runningServiceDetails.getLatestEnabledVersion() == null) {
                    DaemonTaskHandler.newStage("Deploying " + distributedService.getServiceName() + " via provider API");
                    deployServiceManually(deploymentDetails, resolvedConfiguration, distributedService, safeToUpdate);
                } else {
                    DaemonTaskHandler.newStage("Deploying " + distributedService.getServiceName() + " via red/black");
                    Orca orca = serviceProvider.getDeployableService(SpinnakerService.Type.ORCA_BOOTSTRAP, Orca.class).connectToPrimaryService(deploymentDetails, runtimeSettings);
                    deployServiceWithOrca(deploymentDetails, resolvedConfiguration, orca, distributedService);
                }
                return null;
            });
            DaemonTaskHandler.submitTask(builder::build, "Deploy " + distributedService.getServiceName());
        }
    }
    DaemonTaskHandler.message("Waiting on deployments to complete");
    DaemonTaskHandler.reduceChildren(null, (t1, t2) -> null, (t1, t2) -> null).getProblemSet().throwifSeverityExceeds(Problem.Severity.WARNING);
    DistributedService<Orca, T> orca = serviceProvider.getDeployableService(SpinnakerService.Type.ORCA);
    Set<Integer> unknownVersions = reapOrcaServerGroups(deploymentDetails, runtimeSettings, orca);
    reapRoscoServerGroups(deploymentDetails, runtimeSettings, serviceProvider.getDeployableService(SpinnakerService.Type.ROSCO));
    if (!unknownVersions.isEmpty()) {
        String versions = String.join(", ", unknownVersions.stream().map(orca::getVersionedName).collect(Collectors.toList()));
        throw new HalException(new ProblemBuilder(Problem.Severity.ERROR, "The following orca versions (" + versions + ") could not safely be drained of work.").setRemediation("Please make sure that no pipelines are running, and manually destroy the server groups at those versions.").build());
    }
    return new RemoteAction();
}
Also used : Orca(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.OrcaService.Orca) HalException(com.netflix.spinnaker.halyard.core.error.v1.HalException) ServiceSettings(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ServiceSettings) SpinnakerRuntimeSettings(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.SpinnakerRuntimeSettings) SpinnakerService(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.SpinnakerService) ProblemBuilder(com.netflix.spinnaker.halyard.core.problem.v1.ProblemBuilder) DistributedService(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.distributed.DistributedService) DaemonResponse(com.netflix.spinnaker.halyard.core.DaemonResponse) RunningServiceDetails(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.RunningServiceDetails) RemoteAction(com.netflix.spinnaker.halyard.core.RemoteAction)

Aggregations

ProblemBuilder (com.netflix.spinnaker.halyard.core.problem.v1.ProblemBuilder)8 HalException (com.netflix.spinnaker.halyard.core.error.v1.HalException)6 IOException (java.io.IOException)3 Problem (com.netflix.spinnaker.halyard.core.problem.v1.Problem)2 FileInputStream (java.io.FileInputStream)2 RetrofitError (retrofit.RetrofitError)2 ByteArrayContent (com.google.api.client.http.ByteArrayContent)1 StorageObject (com.google.api.services.storage.model.StorageObject)1 AtomicFileWriter (com.netflix.spinnaker.halyard.core.AtomicFileWriter)1 DaemonResponse (com.netflix.spinnaker.halyard.core.DaemonResponse)1 RemoteAction (com.netflix.spinnaker.halyard.core.RemoteAction)1 ProblemSet (com.netflix.spinnaker.halyard.core.problem.v1.ProblemSet)1 RunningServiceDetails (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.RunningServiceDetails)1 SpinnakerRuntimeSettings (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.SpinnakerRuntimeSettings)1 Orca (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.OrcaService.Orca)1 ServiceSettings (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ServiceSettings)1 SpinnakerService (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.SpinnakerService)1 DistributedService (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.distributed.DistributedService)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1