Search in sources :

Example 36 with ConfigProblemBuilder

use of com.netflix.spinnaker.halyard.config.problem.v1.ConfigProblemBuilder 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 37 with ConfigProblemBuilder

use of com.netflix.spinnaker.halyard.config.problem.v1.ConfigProblemBuilder in project halyard by spinnaker.

the class PubsubService method getAllPubsubs.

public List<Pubsub> getAllPubsubs(String deploymentName) {
    NodeFilter filter = new NodeFilter().setDeployment(deploymentName).withAnyPubsub();
    List<Pubsub> matching = lookupService.getMatchingNodesOfType(filter, Pubsub.class);
    if (matching.size() == 0) {
        throw new ConfigNotFoundException(new ConfigProblemBuilder(Severity.FATAL, "No pubsubs could be found").build());
    } else {
        return matching;
    }
}
Also used : Pubsub(com.netflix.spinnaker.halyard.config.model.v1.node.Pubsub) GooglePubsub(com.netflix.spinnaker.halyard.config.model.v1.pubsub.google.GooglePubsub) ConfigProblemBuilder(com.netflix.spinnaker.halyard.config.problem.v1.ConfigProblemBuilder) ConfigNotFoundException(com.netflix.spinnaker.halyard.config.error.v1.ConfigNotFoundException) NodeFilter(com.netflix.spinnaker.halyard.config.model.v1.node.NodeFilter)

Example 38 with ConfigProblemBuilder

use of com.netflix.spinnaker.halyard.config.problem.v1.ConfigProblemBuilder 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 39 with ConfigProblemBuilder

use of com.netflix.spinnaker.halyard.config.problem.v1.ConfigProblemBuilder in project halyard by spinnaker.

the class HalconfigValidator method validate.

@Override
public void validate(ConfigProblemSetBuilder p, Halconfig n) {
    try {
        String runningVersion = versionsService.getRunningHalyardVersion();
        String latestVersion = versionsService.getLatestHalyardVersion();
        if (StringUtils.isEmpty(latestVersion)) {
            log.warn("No latest version of halyard published.");
            return;
        }
        if (runningVersion.contains("SNAPSHOT")) {
            return;
        }
        if (Versions.lessThan(runningVersion, latestVersion)) {
            ConfigProblemBuilder problemBuilder = p.addProblem(Problem.Severity.WARNING, "There is a newer version of Halyard available (" + latestVersion + "), please update when possible");
            File updateScript = new File("/usr/local/bin/update-halyard");
            if (updateScript.exists() && !updateScript.isDirectory()) {
                problemBuilder.setRemediation("Run 'sudo update-halyard' to upgrade");
            } else {
                problemBuilder.setRemediation("Run 'sudo apt-get update && sudo apt-get install spinnaker-halyard -y' to upgrade");
            }
        }
    } catch (Exception e) {
        log.warn("Unexpected error comparing versions: " + e);
    }
}
Also used : ConfigProblemBuilder(com.netflix.spinnaker.halyard.config.problem.v1.ConfigProblemBuilder) File(java.io.File)

Aggregations

ConfigProblemBuilder (com.netflix.spinnaker.halyard.config.problem.v1.ConfigProblemBuilder)39 ConfigNotFoundException (com.netflix.spinnaker.halyard.config.error.v1.ConfigNotFoundException)18 NodeFilter (com.netflix.spinnaker.halyard.config.model.v1.node.NodeFilter)17 HalException (com.netflix.spinnaker.halyard.core.error.v1.HalException)16 IllegalConfigException (com.netflix.spinnaker.halyard.config.error.v1.IllegalConfigException)10 DeploymentConfiguration (com.netflix.spinnaker.halyard.config.model.v1.node.DeploymentConfiguration)4 Versions (com.netflix.spinnaker.halyard.core.registry.v1.Versions)4 IOException (java.io.IOException)4 Account (com.netflix.spinnaker.halyard.config.model.v1.node.Account)3 ArtifactProvider (com.netflix.spinnaker.halyard.config.model.v1.node.ArtifactProvider)3 Ci (com.netflix.spinnaker.halyard.config.model.v1.node.Ci)3 Provider (com.netflix.spinnaker.halyard.config.model.v1.node.Provider)3 Pubsub (com.netflix.spinnaker.halyard.config.model.v1.node.Pubsub)3 AppengineProvider (com.netflix.spinnaker.halyard.config.model.v1.providers.appengine.AppengineProvider)3 AwsProvider (com.netflix.spinnaker.halyard.config.model.v1.providers.aws.AwsProvider)3 AzureProvider (com.netflix.spinnaker.halyard.config.model.v1.providers.azure.AzureProvider)3 DCOSProvider (com.netflix.spinnaker.halyard.config.model.v1.providers.dcos.DCOSProvider)3 DockerRegistryProvider (com.netflix.spinnaker.halyard.config.model.v1.providers.dockerRegistry.DockerRegistryProvider)3 GoogleProvider (com.netflix.spinnaker.halyard.config.model.v1.providers.google.GoogleProvider)3 KubernetesProvider (com.netflix.spinnaker.halyard.config.model.v1.providers.kubernetes.KubernetesProvider)3