Search in sources :

Example 86 with HalException

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

the class HalconfigParser method saveConfigTo.

private void saveConfigTo(Path path) {
    Halconfig local = (Halconfig) DaemonTaskHandler.getContext();
    if (local == null) {
        throw new HalException(new ConfigProblemBuilder(Severity.WARNING, "No halconfig changes have been made, nothing to write").build());
    }
    AtomicFileWriter writer = null;
    try {
        writer = new AtomicFileWriter(path);
        writer.write(yamlParser.dump(objectMapper.convertValue(local, Map.class)));
        writer.commit();
    } catch (IOException e) {
        throw new HalException(Severity.FATAL, "Failure writing your halconfig to path \"" + halconfigPath + "\": " + e.getMessage(), e);
    } finally {
        DaemonTaskHandler.setContext(null);
        if (writer != null) {
            writer.close();
        }
    }
}
Also used : Halconfig(com.netflix.spinnaker.halyard.config.model.v1.node.Halconfig) AtomicFileWriter(com.netflix.spinnaker.halyard.core.AtomicFileWriter) ConfigProblemBuilder(com.netflix.spinnaker.halyard.config.problem.v1.ConfigProblemBuilder) HalException(com.netflix.spinnaker.halyard.core.error.v1.HalException) IOException(java.io.IOException)

Example 87 with HalException

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

the class SubscriptionService method deleteSubscription.

public void deleteSubscription(String deploymentName, String pubsubName, String subscriptionName) {
    Pubsub pubsub = pubsubService.getPubsub(deploymentName, pubsubName);
    boolean removed = pubsub.getSubscriptions().removeIf(subscription -> ((Subscription) subscription).getName().equals(subscriptionName));
    if (!removed) {
        throw new HalException(new ConfigProblemBuilder(Severity.FATAL, "Subscription \"" + subscriptionName + "\" wasn't found").build());
    }
}
Also used : Pubsub(com.netflix.spinnaker.halyard.config.model.v1.node.Pubsub) ConfigProblemBuilder(com.netflix.spinnaker.halyard.config.problem.v1.ConfigProblemBuilder) HalException(com.netflix.spinnaker.halyard.core.error.v1.HalException) Subscription(com.netflix.spinnaker.halyard.config.model.v1.node.Subscription)

Example 88 with HalException

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

the class Node method backupLocalFiles.

public List<String> backupLocalFiles(String outputPath) {
    List<String> files = new ArrayList<>();
    Consumer<Node> fileFinder = n -> files.addAll(n.localFiles().stream().map(f -> {
        try {
            f.setAccessible(true);
            String fPath = (String) f.get(n);
            if (fPath == null) {
                return null;
            }
            File fFile = new File(fPath);
            String fName = fFile.getName();
            // Hash the path to uniquely flatten all files into the output directory
            Path newName = Paths.get(outputPath, Math.abs(fPath.hashCode()) + "-" + fName);
            File parent = newName.toFile().getParentFile();
            if (!parent.exists()) {
                parent.mkdirs();
            } else if (fFile.getParent().equals(parent.toString())) {
                // Don't move paths that are already in the right folder
                return fPath;
            }
            Files.copy(Paths.get(fPath), newName, REPLACE_EXISTING);
            f.set(n, newName.toString());
            return newName.toString();
        } catch (IllegalAccessException e) {
            throw new RuntimeException("Failed to get local files for node " + n.getNodeName(), e);
        } catch (IOException e) {
            throw new HalException(FATAL, "Failed to backup user file: " + e.getMessage(), e);
        } finally {
            f.setAccessible(false);
        }
    }).filter(Objects::nonNull).collect(Collectors.toList()));
    recursiveConsume(fileFinder);
    return files;
}
Also used : Arrays(java.util.Arrays) Getter(lombok.Getter) HalException(com.netflix.spinnaker.halyard.core.error.v1.HalException) HashMap(java.util.HashMap) ConfigProblemSetBuilder(com.netflix.spinnaker.halyard.config.problem.v1.ConfigProblemSetBuilder) ArrayList(java.util.ArrayList) REMOVED(com.netflix.spinnaker.halyard.config.model.v1.node.NodeDiff.ChangeType.REMOVED) Map(java.util.Map) JsonIgnore(com.fasterxml.jackson.annotation.JsonIgnore) REPLACE_EXISTING(java.nio.file.StandardCopyOption.REPLACE_EXISTING) Method(java.lang.reflect.Method) Path(java.nio.file.Path) GlobalApplicationOptions(com.netflix.spinnaker.halyard.core.GlobalApplicationOptions) Files(java.nio.file.Files) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) FileUtils(org.apache.commons.io.FileUtils) IOException(java.io.IOException) Field(java.lang.reflect.Field) Collectors(java.util.stream.Collectors) EDITED(com.netflix.spinnaker.halyard.config.model.v1.node.NodeDiff.ChangeType.EDITED) File(java.io.File) InvocationTargetException(java.lang.reflect.InvocationTargetException) Objects(java.util.Objects) Consumer(java.util.function.Consumer) ADDED(com.netflix.spinnaker.halyard.config.model.v1.node.NodeDiff.ChangeType.ADDED) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) FATAL(com.netflix.spinnaker.halyard.core.problem.v1.Problem.Severity.FATAL) Paths(java.nio.file.Paths) CRC32(java.util.zip.CRC32) Path(java.nio.file.Path) HalException(com.netflix.spinnaker.halyard.core.error.v1.HalException) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Objects(java.util.Objects) File(java.io.File)

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