Search in sources :

Example 46 with HalException

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

the class ClusterService method deleteCluster.

public void deleteCluster(String deploymentName, String providerName, String clusterName) {
    final HasClustersProvider clustersProvider = providerService.getHasClustersProvider(deploymentName, providerName);
    final List<Cluster> clusters = (List<Cluster>) clustersProvider.getClusters();
    boolean removed = clusters.removeIf(cluster -> cluster.getName().equals(clusterName));
    if (!removed) {
        throw new HalException(Problem.Severity.FATAL, "Cluster \"" + clusterName + "\" wasn't found");
    }
}
Also used : HasClustersProvider(com.netflix.spinnaker.halyard.config.model.v1.node.HasClustersProvider) HalException(com.netflix.spinnaker.halyard.core.error.v1.HalException) Cluster(com.netflix.spinnaker.halyard.config.model.v1.node.Cluster) List(java.util.List)

Example 47 with HalException

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

the class RemoteAction method commitScript.

public void commitScript(Path path) {
    AtomicFileWriter writer = null;
    try {
        writer = new AtomicFileWriter(path);
        writer.write(script);
        writer.commit();
    } catch (IOException ioe) {
        ioe.printStackTrace();
        throw new HalException(Problem.Severity.FATAL, "Failed to write config for profile " + path.toFile().getName() + ": " + ioe.getMessage());
    } finally {
        if (writer != null) {
            writer.close();
        }
    }
    path.toFile().setExecutable(true);
    scriptPath = path.toString();
}
Also used : HalException(com.netflix.spinnaker.halyard.core.error.v1.HalException) IOException(java.io.IOException)

Example 48 with HalException

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

the class CanaryAccountService method deleteAccount.

public void deleteAccount(String deploymentName, String serviceIntegrationName, String accountName) {
    AbstractCanaryServiceIntegration serviceIntegration = getServiceIntegration(deploymentName, serviceIntegrationName);
    boolean removed = serviceIntegration.getAccounts().removeIf(account -> ((AbstractCanaryAccount) account).getName().equals(accountName));
    if (!removed) {
        throw new HalException(new ConfigProblemBuilder(Severity.FATAL, "Canary account \"" + accountName + "\" wasn't found").build());
    }
}
Also used : AbstractCanaryServiceIntegration(com.netflix.spinnaker.halyard.config.model.v1.canary.AbstractCanaryServiceIntegration) ConfigProblemBuilder(com.netflix.spinnaker.halyard.config.problem.v1.ConfigProblemBuilder) HalException(com.netflix.spinnaker.halyard.core.error.v1.HalException) AbstractCanaryAccount(com.netflix.spinnaker.halyard.config.model.v1.canary.AbstractCanaryAccount)

Example 49 with HalException

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

the class MasterService method deleteMaster.

public void deleteMaster(String deploymentName, String ciName, String masterName) {
    Ci ci = ciService.getCi(deploymentName, ciName);
    boolean removed = ci.getMasters().removeIf(master -> ((Master) master).getName().equals(masterName));
    if (!removed) {
        throw new HalException(new ConfigProblemBuilder(Severity.FATAL, "Master \"" + masterName + "\" wasn't found").build());
    }
}
Also used : Master(com.netflix.spinnaker.halyard.config.model.v1.node.Master) Ci(com.netflix.spinnaker.halyard.config.model.v1.node.Ci) ConfigProblemBuilder(com.netflix.spinnaker.halyard.config.problem.v1.ConfigProblemBuilder) HalException(com.netflix.spinnaker.halyard.core.error.v1.HalException)

Example 50 with HalException

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

the class HalconfigParser method cleanLocalFiles.

/**
 * Deletes all files in the staging directory that are not referenced in the hal config.
 */
public void cleanLocalFiles(Path stagingDirectoryPath) {
    if (!GlobalApplicationOptions.getInstance().isUseRemoteDaemon()) {
        return;
    }
    Halconfig halconfig = getHalconfig();
    Set<String> referencedFiles = new HashSet<String>();
    Consumer<Node> fileFinder = n -> referencedFiles.addAll(n.localFiles().stream().map(f -> {
        try {
            f.setAccessible(true);
            return (String) f.get(n);
        } catch (IllegalAccessException e) {
            throw new RuntimeException("Failed to clean staging directory: " + e.getMessage(), e);
        } finally {
            f.setAccessible(false);
        }
    }).filter(Objects::nonNull).collect(Collectors.toSet()));
    halconfig.recursiveConsume(fileFinder);
    Set<String> existingStagingFiles = ((List<File>) FileUtils.listFiles(stagingDirectoryPath.toFile(), TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE)).stream().map(f -> f.getAbsolutePath()).collect(Collectors.toSet());
    existingStagingFiles.removeAll(referencedFiles);
    try {
        for (String f : existingStagingFiles) {
            FileUtils.forceDelete(new File(f));
        }
    } catch (IOException e) {
        throw new HalException(FATAL, "Failed to clean staging directory: " + e.getMessage(), e);
    }
}
Also used : Autowired(org.springframework.beans.factory.annotation.Autowired) HalException(com.netflix.spinnaker.halyard.core.error.v1.HalException) DaemonTaskHandler(com.netflix.spinnaker.halyard.core.tasks.v1.DaemonTaskHandler) Yaml(org.yaml.snakeyaml.Yaml) Halconfig(com.netflix.spinnaker.halyard.config.model.v1.node.Halconfig) HashSet(java.util.HashSet) ByteArrayInputStream(java.io.ByteArrayInputStream) Map(java.util.Map) ParseConfigException(com.netflix.spinnaker.halyard.config.error.v1.ParseConfigException) Severity(com.netflix.spinnaker.halyard.core.problem.v1.Problem.Severity) TrueFileFilter(org.apache.commons.io.filefilter.TrueFileFilter) Path(java.nio.file.Path) GlobalApplicationOptions(com.netflix.spinnaker.halyard.core.GlobalApplicationOptions) ScannerException(org.yaml.snakeyaml.scanner.ScannerException) Set(java.util.Set) FileUtils(org.apache.commons.io.FileUtils) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) Collectors(java.util.stream.Collectors) File(java.io.File) FileNotFoundException(java.io.FileNotFoundException) AtomicFileWriter(com.netflix.spinnaker.halyard.core.AtomicFileWriter) Objects(java.util.Objects) Consumer(java.util.function.Consumer) ConfigProblemBuilder(com.netflix.spinnaker.halyard.config.problem.v1.ConfigProblemBuilder) Slf4j(lombok.extern.slf4j.Slf4j) Component(org.springframework.stereotype.Component) List(java.util.List) FATAL(com.netflix.spinnaker.halyard.core.problem.v1.Problem.Severity.FATAL) Paths(java.nio.file.Paths) ParserException(org.yaml.snakeyaml.parser.ParserException) Node(com.netflix.spinnaker.halyard.config.model.v1.node.Node) InputStream(java.io.InputStream) Halconfig(com.netflix.spinnaker.halyard.config.model.v1.node.Halconfig) Node(com.netflix.spinnaker.halyard.config.model.v1.node.Node) HalException(com.netflix.spinnaker.halyard.core.error.v1.HalException) IOException(java.io.IOException) Objects(java.util.Objects) List(java.util.List) File(java.io.File) HashSet(java.util.HashSet)

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