Search in sources :

Example 6 with Node

use of com.netflix.spinnaker.halyard.config.model.v1.node.Node in project halyard by spinnaker.

the class Front50ProfileFactory method setProfile.

@Override
public void setProfile(Profile profile, DeploymentConfiguration deploymentConfiguration, SpinnakerRuntimeSettings endpoints) {
    PersistentStorage persistentStorage = deploymentConfiguration.getPersistentStorage();
    if (persistentStorage.getPersistentStoreType() == null) {
        throw new HalException(Problem.Severity.FATAL, "No persistent storage type was configured.");
    }
    List<String> files = backupRequiredFiles(persistentStorage, deploymentConfiguration.getName());
    Map<String, Map<String, Object>> persistentStorageMap = new HashMap<>();
    NodeIterator children = persistentStorage.getChildren();
    Node child = children.getNext();
    while (child != null) {
        if (child instanceof PersistentStore) {
            PersistentStore persistentStore = (PersistentStore) child;
            URI connectionUri = null;
            if (persistentStore instanceof RedisPersistentStore) {
                try {
                    connectionUri = new URI(endpoints.getServices().getRedis().getBaseUrl());
                } catch (URISyntaxException e) {
                    throw new RuntimeException("Malformed redis URL, this is a bug.");
                }
            }
            persistentStore.setConnectionInfo(connectionUri);
            PersistentStore.PersistentStoreType persistentStoreType = persistentStore.persistentStoreType();
            Map persistentStoreMap = objectMapper.convertValue(persistentStore, Map.class);
            persistentStoreMap.put("enabled", persistentStoreType.equals(persistentStorage.getPersistentStoreType()));
            persistentStorageMap.put(persistentStoreType.getId(), persistentStoreMap);
        }
        child = children.getNext();
    }
    Map<String, Object> spinnakerObjectMap = new HashMap<>();
    spinnakerObjectMap.put("spinnaker", persistentStorageMap);
    super.setProfile(profile, deploymentConfiguration, endpoints);
    profile.appendContents(yamlToString(spinnakerObjectMap)).appendContents(profile.getBaseContents()).setRequiredFiles(files);
}
Also used : HashMap(java.util.HashMap) HalException(com.netflix.spinnaker.halyard.core.error.v1.HalException) RedisPersistentStore(com.netflix.spinnaker.halyard.config.model.v1.persistentStorage.RedisPersistentStore) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) RedisPersistentStore(com.netflix.spinnaker.halyard.config.model.v1.persistentStorage.RedisPersistentStore) HashMap(java.util.HashMap) Map(java.util.Map)

Example 7 with Node

use of com.netflix.spinnaker.halyard.config.model.v1.node.Node in project halyard by spinnaker.

the class KubernetesAccountValidator method validate.

@Override
public void validate(ConfigProblemSetBuilder psBuilder, KubernetesAccount account) {
    DeploymentConfiguration deploymentConfiguration;
    // TODO(lwander) this is still a little messy - I should use the filters to get the necessary docker account
    Node parent = account.getParent();
    while (!(parent instanceof DeploymentConfiguration)) {
        // Note this will crash in the above check if the halconfig representation is corrupted
        // (that's ok, because it indicates a more serious error than we want to validate).
        parent = parent.getParent();
    }
    deploymentConfiguration = (DeploymentConfiguration) parent;
    validateKindConfig(psBuilder, account);
    // TODO(lwander) validate all config with clouddriver's v2 creds
    switch(account.getProviderVersion()) {
        case V1:
            final List<String> dockerRegistryNames = account.getDockerRegistries().stream().map(DockerRegistryReference::getAccountName).collect(Collectors.toList());
            validateDockerRegistries(psBuilder, deploymentConfiguration, dockerRegistryNames, Provider.ProviderType.KUBERNETES);
            validateKubeconfig(psBuilder, account);
        case V2:
            break;
        default:
            throw new IllegalStateException("Unknown provider version " + account.getProviderVersion());
    }
}
Also used : Node(com.netflix.spinnaker.halyard.config.model.v1.node.Node) DeploymentConfiguration(com.netflix.spinnaker.halyard.config.model.v1.node.DeploymentConfiguration)

Example 8 with Node

use of com.netflix.spinnaker.halyard.config.model.v1.node.Node in project halyard by spinnaker.

the class DCOSAccountValidator method validateClusters.

private void validateClusters(final ConfigProblemSetBuilder problems, final DCOSAccount account) {
    final NodeIterator children = account.getParent().getChildren();
    Node n = children.getNext();
    Set<String> definedClusters = new HashSet<>();
    while (n != null) {
        if (n instanceof DCOSCluster) {
            definedClusters.add(((DCOSCluster) n).getName());
        }
        n = children.getNext();
    }
    final Set<String> accountClusters = account.getClusters().stream().map(c -> c.getName()).collect(Collectors.toSet());
    accountClusters.removeAll(definedClusters);
    accountClusters.forEach(c -> problems.addProblem(ERROR, "Cluster \"" + c.toString() + "\" not defined for provider").setRemediation("Add cluster to the provider or remove from the account").setOptions(Lists.newArrayList(definedClusters)));
    Set<List<String>> credentials = new HashSet<>();
    account.getClusters().forEach(c -> {
        final List<String> key = Lists.newArrayList(c.getName(), c.getUid());
        if (credentials.contains(key)) {
            problems.addProblem(ERROR, "Account contains duplicate credentials for cluster \"" + c.getName() + "\" and user id \"" + c.getUid() + "\".").setRemediation("Remove the duplicate credentials");
        } else {
            credentials.add(key);
        }
        // we can connect without a password
        if (Strings.isStringEmpty(c.getPassword()) && Strings.isStringEmpty(c.getServiceKeyFile())) {
            problems.addProblem(WARNING, "Account has no password or service key.  Unless the cluster has security disabled this may be an error").setRemediation("Add a password or service key.");
        }
        if (!Strings.isStringEmpty(c.getPassword()) && !Strings.isStringEmpty(c.getServiceKeyFile())) {
            problems.addProblem(ERROR, "Account has both a password and service key").setRemediation("Remove either the password or service key.");
        }
        if (!Strings.isStringEmpty(c.getServiceKeyFile())) {
            String resolvedServiceKey = ValidatingFileReader.contents(problems, c.getServiceKeyFile());
            if (Strings.isStringEmpty(resolvedServiceKey)) {
                problems.addProblem(ERROR, "The supplied service key file does not exist or is empty.").setRemediation("Supply a valid service key file.");
            }
        }
    });
}
Also used : NodeIterator(com.netflix.spinnaker.halyard.config.model.v1.node.NodeIterator) DockerRegistryReference(com.netflix.spinnaker.halyard.config.model.v1.providers.containers.DockerRegistryReference) NodeIterator(com.netflix.spinnaker.halyard.config.model.v1.node.NodeIterator) Set(java.util.Set) ERROR(com.netflix.spinnaker.halyard.core.problem.v1.Problem.Severity.ERROR) Lists(com.beust.jcommander.internal.Lists) DeploymentConfiguration(com.netflix.spinnaker.halyard.config.model.v1.node.DeploymentConfiguration) ConfigProblemSetBuilder(com.netflix.spinnaker.halyard.config.problem.v1.ConfigProblemSetBuilder) Collectors(java.util.stream.Collectors) HashSet(java.util.HashSet) DCOSAccount(com.netflix.spinnaker.halyard.config.model.v1.providers.dcos.DCOSAccount) Component(org.springframework.stereotype.Component) List(java.util.List) WARNING(com.netflix.spinnaker.halyard.core.problem.v1.Problem.Severity.WARNING) Strings(com.beust.jcommander.Strings) Validator(com.netflix.spinnaker.halyard.config.model.v1.node.Validator) DockerRegistryReferenceValidation.validateDockerRegistries(com.netflix.spinnaker.halyard.config.validate.v1.providers.dockerRegistry.DockerRegistryReferenceValidation.validateDockerRegistries) DCOSCluster(com.netflix.spinnaker.halyard.config.model.v1.providers.dcos.DCOSCluster) ValidatingFileReader(com.netflix.spinnaker.halyard.config.validate.v1.util.ValidatingFileReader) Provider(com.netflix.spinnaker.halyard.config.model.v1.node.Provider) Node(com.netflix.spinnaker.halyard.config.model.v1.node.Node) Node(com.netflix.spinnaker.halyard.config.model.v1.node.Node) List(java.util.List) DCOSCluster(com.netflix.spinnaker.halyard.config.model.v1.providers.dcos.DCOSCluster) HashSet(java.util.HashSet)

Example 9 with Node

use of com.netflix.spinnaker.halyard.config.model.v1.node.Node 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 10 with Node

use of com.netflix.spinnaker.halyard.config.model.v1.node.Node in project halyard by spinnaker.

the class OptionsService method options.

public <T extends Node> FieldOptions options(NodeFilter filter, Class<T> nodeClass, String field) {
    ConfigProblemSetBuilder problemSetBuilder = new ConfigProblemSetBuilder(applicationContext);
    List<T> nodes = lookupService.getMatchingNodesOfType(filter, nodeClass);
    List<String> options = nodes.stream().map(n -> {
        problemSetBuilder.setNode(n);
        return n.fieldOptions(problemSetBuilder, field);
    }).reduce(new ArrayList<>(), (a, b) -> {
        a.addAll(b);
        return a;
    });
    return new FieldOptions().setOptions(options).setProblemSet(problemSetBuilder.build());
}
Also used : Component(org.springframework.stereotype.Component) List(java.util.List) Data(lombok.Data) DaemonResponse(com.netflix.spinnaker.halyard.core.DaemonResponse) Autowired(org.springframework.beans.factory.annotation.Autowired) Node(com.netflix.spinnaker.halyard.config.model.v1.node.Node) ProblemSet(com.netflix.spinnaker.halyard.core.problem.v1.ProblemSet) ConfigProblemSetBuilder(com.netflix.spinnaker.halyard.config.problem.v1.ConfigProblemSetBuilder) ApplicationContext(org.springframework.context.ApplicationContext) NodeFilter(com.netflix.spinnaker.halyard.config.model.v1.node.NodeFilter) ArrayList(java.util.ArrayList) ConfigProblemSetBuilder(com.netflix.spinnaker.halyard.config.problem.v1.ConfigProblemSetBuilder)

Aggregations

Node (com.netflix.spinnaker.halyard.config.model.v1.node.Node)7 HalException (com.netflix.spinnaker.halyard.core.error.v1.HalException)5 List (java.util.List)5 DeploymentConfiguration (com.netflix.spinnaker.halyard.config.model.v1.node.DeploymentConfiguration)4 ConfigProblemSetBuilder (com.netflix.spinnaker.halyard.config.problem.v1.ConfigProblemSetBuilder)4 ArrayList (java.util.ArrayList)4 Map (java.util.Map)4 Collectors (java.util.stream.Collectors)4 NodeIterator (com.netflix.spinnaker.halyard.config.model.v1.node.NodeIterator)3 GlobalApplicationOptions (com.netflix.spinnaker.halyard.core.GlobalApplicationOptions)3 FATAL (com.netflix.spinnaker.halyard.core.problem.v1.Problem.Severity.FATAL)3 File (java.io.File)3 IOException (java.io.IOException)3 JsonIgnore (com.fasterxml.jackson.annotation.JsonIgnore)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 ADDED (com.netflix.spinnaker.halyard.config.model.v1.node.NodeDiff.ChangeType.ADDED)2 EDITED (com.netflix.spinnaker.halyard.config.model.v1.node.NodeDiff.ChangeType.EDITED)2 REMOVED (com.netflix.spinnaker.halyard.config.model.v1.node.NodeDiff.ChangeType.REMOVED)2 NodeFilter (com.netflix.spinnaker.halyard.config.model.v1.node.NodeFilter)2 Validator (com.netflix.spinnaker.halyard.config.model.v1.node.Validator)2