Search in sources :

Example 21 with HalException

use of com.netflix.spinnaker.halyard.core.error.v1.HalException in project halyard by spinnaker.

the class DistributedDeployer method flushInfrastructureCaches.

@Override
public void flushInfrastructureCaches(DistributedServiceProvider<T> serviceProvider, AccountDeploymentDetails<T> deploymentDetails, SpinnakerRuntimeSettings runtimeSettings) {
    try {
        Jedis jedis = (Jedis) serviceProvider.getDeployableService(SpinnakerService.Type.REDIS).connectToPrimaryService(deploymentDetails, runtimeSettings);
        RedisService.flushKeySpace(jedis, "com.netflix.spinnaker.clouddriver*");
    } catch (Exception e) {
        throw new HalException(Problem.Severity.FATAL, "Failed to flush redis cache: " + e.getMessage());
    }
}
Also used : Jedis(redis.clients.jedis.Jedis) HalException(com.netflix.spinnaker.halyard.core.error.v1.HalException) HalException(com.netflix.spinnaker.halyard.core.error.v1.HalException)

Example 22 with HalException

use of com.netflix.spinnaker.halyard.core.error.v1.HalException in project halyard by spinnaker.

the class LocalDeployer method flushInfrastructureCaches.

@Override
public void flushInfrastructureCaches(LocalServiceProvider serviceProvider, DeploymentDetails deploymentDetails, SpinnakerRuntimeSettings runtimeSettings) {
    try {
        Jedis jedis = new Jedis(runtimeSettings.getServiceSettings((SpinnakerService) serviceProvider.getLocalService(SpinnakerService.Type.REDIS)).getBaseUrl());
        RedisService.flushKeySpace(jedis, ClouddriverService.REDIS_KEY_SPACE);
    } catch (Exception e) {
        throw new HalException(Problem.Severity.FATAL, "Unable to flush key space: " + e.getMessage(), e);
    }
}
Also used : Jedis(redis.clients.jedis.Jedis) HalException(com.netflix.spinnaker.halyard.core.error.v1.HalException) HalException(com.netflix.spinnaker.halyard.core.error.v1.HalException)

Example 23 with HalException

use of com.netflix.spinnaker.halyard.core.error.v1.HalException in project halyard by spinnaker.

the class DaemonTaskHandler method reduceChildren.

public static <U, T> DaemonResponse<U> reduceChildren(U base, BiFunction<U, ? super T, U> accumulator, BinaryOperator<U> combiner) {
    DaemonTask task = getTask();
    if (task != null) {
        U responseBody = base;
        ProblemSet problemSet = new ProblemSet();
        DaemonResponse<U> response = new DaemonResponse<>(responseBody, problemSet);
        return (DaemonResponse) task.getChildren().stream().reduce(response, (o, t) -> {
            DaemonResponse<U> collector = (DaemonResponse<U>) o;
            DaemonTask child = (DaemonTask) t;
            DaemonResponse<T> childResponse;
            try {
                childResponse = task.reapChild(child);
            } catch (InterruptedException e) {
                throw new DaemonTaskInterrupted("Interrupted during reap", e);
            }
            DaemonTask.State state = child.getState();
            if (!state.isTerminal()) {
                throw new IllegalStateException("Child task " + child + " reaped but non-terminal.");
            }
            switch(state) {
                case FAILED:
                    throw new HalException(childResponse.getProblemSet().getProblems());
                case INTERRUPTED:
                    task.interrupt();
                    throw new DaemonTaskInterrupted(child.getFatalError());
                case TIMED_OUT:
                    task.timeout();
                    throw new DaemonTaskInterrupted("Child task timed out");
                case SUCCEEDED:
                    break;
                default:
                    throw new IllegalStateException("Unknown terminal state " + state);
            }
            collector.getProblemSet().addAll(childResponse.getProblemSet());
            collector.setResponseBody(accumulator.apply(collector.getResponseBody(), childResponse.getResponseBody()));
            return collector;
        }, (Object o1, Object o2) -> {
            DaemonResponse<U> r1 = (DaemonResponse<U>) o1;
            DaemonResponse<U> r2 = (DaemonResponse<U>) o2;
            r1.setResponseBody(combiner.apply(r1.getResponseBody(), r2.getResponseBody()));
            r1.getProblemSet().addAll(r2.getProblemSet());
            return r1;
        });
    } else {
        throw new IllegalStateException("You must be running a DaemonTask to reduce child tasks");
    }
}
Also used : Slf4j(lombok.extern.slf4j.Slf4j) JobExecutor(com.netflix.spinnaker.halyard.core.job.v1.JobExecutor) BiFunction(java.util.function.BiFunction) DaemonResponse(com.netflix.spinnaker.halyard.core.DaemonResponse) HalException(com.netflix.spinnaker.halyard.core.error.v1.HalException) ProblemSet(com.netflix.spinnaker.halyard.core.problem.v1.ProblemSet) DaemonLocalJobExecutor(com.netflix.spinnaker.halyard.core.job.v1.DaemonLocalJobExecutor) Supplier(java.util.function.Supplier) BinaryOperator(java.util.function.BinaryOperator) DaemonResponse(com.netflix.spinnaker.halyard.core.DaemonResponse) HalException(com.netflix.spinnaker.halyard.core.error.v1.HalException) ProblemSet(com.netflix.spinnaker.halyard.core.problem.v1.ProblemSet)

Example 24 with HalException

use of com.netflix.spinnaker.halyard.core.error.v1.HalException 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 25 with HalException

use of com.netflix.spinnaker.halyard.core.error.v1.HalException 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)

Aggregations

HalException (com.netflix.spinnaker.halyard.core.error.v1.HalException)88 IOException (java.io.IOException)37 ConfigProblemBuilder (com.netflix.spinnaker.halyard.config.problem.v1.ConfigProblemBuilder)17 ServiceSettings (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ServiceSettings)16 ArrayList (java.util.ArrayList)15 FileInputStream (java.io.FileInputStream)14 File (java.io.File)12 HashMap (java.util.HashMap)12 JobStatus (com.netflix.spinnaker.halyard.core.job.v1.JobStatus)11 RunningServiceDetails (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.RunningServiceDetails)11 Map (java.util.Map)11 JobRequest (com.netflix.spinnaker.halyard.core.job.v1.JobRequest)10 Field (java.lang.reflect.Field)9 SpinnakerRuntimeSettings (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.SpinnakerRuntimeSettings)8 Path (java.nio.file.Path)8 List (java.util.List)7 Compute (com.google.api.services.compute.Compute)6 Problem (com.netflix.spinnaker.halyard.core.problem.v1.Problem)6 Paths (java.nio.file.Paths)6 GoogleJsonResponseException (com.google.api.client.googleapis.json.GoogleJsonResponseException)5