Search in sources :

Example 81 with HalException

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

the class BackupService method create.

public String create() {
    String halconfigDir = directoryStructure.getHalconfigDirectory();
    halconfigParser.backupConfig();
    Halconfig halconfig = halconfigParser.getHalconfig();
    halconfig.backupLocalFiles(directoryStructure.getBackupConfigDependenciesPath().toString());
    halconfig.makeLocalFilesRelative(halconfigDir);
    halconfigParser.saveConfig();
    String tarOutputName = String.format("halbackup-%s.tar", new Date()).replace(" ", "_").replace(":", "-");
    String halconfigTar = Paths.get(System.getProperty("user.home"), tarOutputName).toString();
    try {
        tarHalconfig(halconfigDir, halconfigTar);
    } catch (IOException e) {
        throw new HalException(Problem.Severity.FATAL, "Unable to safely backup halconfig " + e.getMessage(), e);
    } finally {
        halconfigParser.switchToBackupConfig();
        halconfigParser.getHalconfig();
        halconfigParser.saveConfig();
        halconfigParser.switchToPrimaryConfig();
    }
    return halconfigTar;
}
Also used : Halconfig(com.netflix.spinnaker.halyard.config.model.v1.node.Halconfig) HalException(com.netflix.spinnaker.halyard.core.error.v1.HalException) IOException(java.io.IOException) Date(java.util.Date)

Example 82 with HalException

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

the class DeploymentService method setDeploymentConfiguration.

public void setDeploymentConfiguration(String deploymentName, DeploymentConfiguration deploymentConfiguration) {
    Halconfig halconfig = halconfigParser.getHalconfig();
    List<DeploymentConfiguration> deploymentConfigurations = halconfig.getDeploymentConfigurations();
    int matchingIndex = -1;
    for (int i = 0; i < deploymentConfigurations.size(); i++) {
        DeploymentConfiguration test = deploymentConfigurations.get(i);
        if (test.getName().equals(deploymentName)) {
            matchingIndex = i;
            break;
        }
    }
    if (matchingIndex < 0) {
        throw new HalException(Severity.FATAL, "Could not find a deployment with name " + deploymentName);
    } else {
        deploymentConfigurations.set(matchingIndex, deploymentConfiguration);
    }
}
Also used : Halconfig(com.netflix.spinnaker.halyard.config.model.v1.node.Halconfig) HalException(com.netflix.spinnaker.halyard.core.error.v1.HalException) DeploymentConfiguration(com.netflix.spinnaker.halyard.config.model.v1.node.DeploymentConfiguration)

Example 83 with HalException

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

the class MetricStoresService method getMetricStore.

public MetricStore getMetricStore(String deploymentName, String metricStoreType) {
    NodeFilter filter = new NodeFilter().setDeployment(deploymentName).setMetricStores().setMetricStore(metricStoreType);
    List<MetricStore> matching = lookupService.getMatchingNodesOfType(filter, MetricStore.class);
    try {
        switch(matching.size()) {
            case 0:
                MetricStore metricStores = MetricStores.translateMetricStoreType(metricStoreType).newInstance();
                setMetricStore(deploymentName, metricStores);
                return metricStores;
            case 1:
                return matching.get(0);
            default:
                throw new RuntimeException("It shouldn't be possible to have multiple metricStore nodes of the same type. This is a bug.");
        }
    } catch (InstantiationException | IllegalAccessException e) {
        throw new HalException(new ConfigProblemBuilder(Severity.FATAL, "Can't create an empty metric store node " + "for metricStore type \"" + metricStoreType + "\"").build());
    }
}
Also used : MetricStore(com.netflix.spinnaker.halyard.config.model.v1.node.MetricStore) ConfigProblemBuilder(com.netflix.spinnaker.halyard.config.problem.v1.ConfigProblemBuilder) HalException(com.netflix.spinnaker.halyard.core.error.v1.HalException) NodeFilter(com.netflix.spinnaker.halyard.config.model.v1.node.NodeFilter)

Example 84 with HalException

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

the class DeploymentConfigurationValidator method validate.

@Override
public void validate(ConfigProblemSetBuilder p, DeploymentConfiguration n) {
    String timezone = n.getTimezone();
    if (Arrays.stream(TimeZone.getAvailableIDs()).noneMatch(t -> t.equals(timezone))) {
        p.addProblem(Problem.Severity.ERROR, "Timezone " + timezone + " does not match any known canonical timezone ID").setRemediation("Pick a timezone from those listed here: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones");
    }
    String version = n.getVersion();
    Versions versions = versionsService.getVersions();
    boolean localGit = n.getDeploymentEnvironment().getType() == DeploymentType.LocalGit;
    if (StringUtils.isEmpty(version)) {
        p.addProblem(Problem.Severity.WARNING, "You have not yet selected a version of Spinnaker to deploy.", "version");
        return;
    }
    Optional<Versions.IllegalVersion> illegalVersion = versions.getIllegalVersions().stream().filter(v -> v.getVersion().equals(version)).findAny();
    if (illegalVersion.isPresent()) {
        p.addProblem(Problem.Severity.ERROR, "Version \"" + version + "\" may no longer be deployed with Halyard: " + illegalVersion.get().getReason());
        return;
    }
    if (Versions.isBranch(version) && !localGit) {
        p.addProblem(Problem.Severity.FATAL, "You can't run Spinnaker from a branch when your deployment type isn't \"LocalGit\".").setRemediation("Either pick a version (hal version list) or set a different deployment type (hal config deploy edit --type <t>).");
        return;
    }
    try {
        if (!Versions.isBranch(version)) {
            versionsService.getBillOfMaterials(version);
        }
    } catch (HalException e) {
        if (localGit) {
            p.addProblem(Problem.Severity.FATAL, "Could not fetch your desired version.").setRemediation("Is it possible that you're trying to checkout a branch? Prefix the version with \"" + Versions.BRANCH_PREFIX + "\".");
            return;
        }
        p.extend(e);
        return;
    } catch (Exception e) {
        p.addProblem(Problem.Severity.FATAL, "Unexpected error trying to validate version \"" + version + "\": " + e.getMessage(), "version");
        return;
    }
    Optional<Versions.Version> releasedVersion = versions.getVersions().stream().filter(v -> Objects.equals(v.getVersion(), version)).findFirst();
    boolean isReleased = releasedVersion.isPresent();
    String runningVersion = versionsService.getRunningHalyardVersion();
    boolean halyardSnapshotRelease = runningVersion.endsWith("SNAPSHOT");
    if (isReleased && !localGit) {
        String minimumHalyardVersion = releasedVersion.get().getMinimumHalyardVersion();
        if (!halyardSnapshotRelease && !StringUtils.isEmpty(minimumHalyardVersion) && Versions.lessThan(runningVersion, minimumHalyardVersion)) {
            p.addProblem(Problem.Severity.ERROR, "Halyard version \"" + runningVersion + "\" is less than Halyard version \"" + minimumHalyardVersion + "\" required for Spinnaker \"" + version + "\"");
        }
    } else {
        // Checks if version is of the form X.Y.Z
        if (version.matches("\\d+\\.\\d+\\.\\d+")) {
            String majorMinor = Versions.toMajorMinor(version);
            Optional<Versions.Version> patchVersion = versions.getVersions().stream().map(v -> new ImmutablePair<>(v, Versions.toMajorMinor(v.getVersion()))).filter(v -> v.getRight() != null).filter(v -> v.getRight().equals(majorMinor)).map(ImmutablePair::getLeft).findFirst();
            if (patchVersion.isPresent()) {
                p.addProblem(Problem.Severity.WARNING, "Version \"" + version + "\" was patched by \"" + patchVersion.get().getVersion() + "\". Please upgrade when possible.").setRemediation("https://spinnaker.io/setup/install/upgrades/");
            } else {
                p.addProblem(Problem.Severity.WARNING, "Version \"" + version + "\" is no longer supported by the Spinnaker team. Please upgrade when possible.").setRemediation("https://spinnaker.io/setup/install/upgrades/");
            }
        } else {
            p.addProblem(Problem.Severity.WARNING, "Version \"" + version + "\" is not a released (validated) version of Spinnaker.", "version");
        }
    }
}
Also used : DeploymentEnvironment(com.netflix.spinnaker.halyard.config.model.v1.node.DeploymentEnvironment) Arrays(java.util.Arrays) TimeZone(java.util.TimeZone) Autowired(org.springframework.beans.factory.annotation.Autowired) HalException(com.netflix.spinnaker.halyard.core.error.v1.HalException) DeploymentType(com.netflix.spinnaker.halyard.config.model.v1.node.DeploymentEnvironment.DeploymentType) DeploymentConfiguration(com.netflix.spinnaker.halyard.config.model.v1.node.DeploymentConfiguration) ConfigProblemSetBuilder(com.netflix.spinnaker.halyard.config.problem.v1.ConfigProblemSetBuilder) StringUtils(org.apache.commons.lang3.StringUtils) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) Objects(java.util.Objects) Component(org.springframework.stereotype.Component) Validator(com.netflix.spinnaker.halyard.config.model.v1.node.Validator) Versions(com.netflix.spinnaker.halyard.core.registry.v1.Versions) Problem(com.netflix.spinnaker.halyard.core.problem.v1.Problem) Optional(java.util.Optional) VersionsService(com.netflix.spinnaker.halyard.config.services.v1.VersionsService) Versions(com.netflix.spinnaker.halyard.core.registry.v1.Versions) HalException(com.netflix.spinnaker.halyard.core.error.v1.HalException) HalException(com.netflix.spinnaker.halyard.core.error.v1.HalException)

Example 85 with HalException

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

the class AccountService method deleteAccount.

public void deleteAccount(String deploymentName, String providerName, String accountName) {
    Provider provider = providerService.getProvider(deploymentName, providerName);
    boolean removed = provider.getAccounts().removeIf(account -> ((Account) account).getName().equals(accountName));
    if (!removed) {
        throw new HalException(new ConfigProblemBuilder(Severity.FATAL, "Account \"" + accountName + "\" wasn't found").build());
    }
}
Also used : Account(com.netflix.spinnaker.halyard.config.model.v1.node.Account) ConfigProblemBuilder(com.netflix.spinnaker.halyard.config.problem.v1.ConfigProblemBuilder) HalException(com.netflix.spinnaker.halyard.core.error.v1.HalException) Provider(com.netflix.spinnaker.halyard.config.model.v1.node.Provider)

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