Search in sources :

Example 1 with NodeIterator

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

the class ClouddriverBootstrapProfileFactory method disableAllProviders.

private void disableAllProviders(Providers providers) {
    NodeIterator providerNodes = providers.getChildren();
    Provider provider;
    while ((provider = (Provider) providerNodes.getNext()) != null) {
        provider.setEnabled(false);
    }
}
Also used : NodeIterator(com.netflix.spinnaker.halyard.config.model.v1.node.NodeIterator) Provider(com.netflix.spinnaker.halyard.config.model.v1.node.Provider) DockerRegistryProvider(com.netflix.spinnaker.halyard.config.model.v1.providers.dockerRegistry.DockerRegistryProvider)

Example 2 with NodeIterator

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

the class LookupService method getMatchingNodes.

/**
 * @param node is the node whose children we want to find.
 * @param filter is the filter to lookup by.
 * @return the children of the input node matching the filter.
 */
private List<Node> getMatchingNodes(Node node, NodeFilter filter) {
    log.trace("Checking for leaf nodes of node " + node.getNodeName());
    List<Node> result = new ArrayList<>();
    NodeIterator children = node.getChildren();
    Node recurse = children.getNext(filter);
    while (recurse != null) {
        result.addAll(getMatchingNodes(recurse, filter));
        recurse = children.getNext(filter);
    }
    // If we have visited this node, it must have matched the filter.
    result.add(node);
    return result;
}
Also used : NodeIterator(com.netflix.spinnaker.halyard.config.model.v1.node.NodeIterator) Node(com.netflix.spinnaker.halyard.config.model.v1.node.Node) ArrayList(java.util.ArrayList)

Example 3 with NodeIterator

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

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

the class RoscoProfileFactory method setProfile.

@Override
protected void setProfile(Profile profile, DeploymentConfiguration deploymentConfiguration, SpinnakerRuntimeSettings endpoints) {
    super.setProfile(profile, deploymentConfiguration, endpoints);
    Providers providers = deploymentConfiguration.getProviders();
    Providers otherProviders = getImageProviders(profile.getVersion());
    NodeIterator iterator = providers.getChildren();
    Provider child = (Provider) iterator.getNext();
    while (child != null) {
        if (child instanceof HasImageProvider) {
            NodeIterator otherIterator = otherProviders.getChildren();
            NodeFilter providerFilter = new NodeFilter().setProvider(child.getNodeName());
            HasImageProvider otherChild = (HasImageProvider) otherIterator.getNext(providerFilter);
            if (otherChild == null) {
                log.warn("images.yml has no images stored for " + child.getNodeName());
            } else {
                log.info("Adding default images for " + child.getNodeName());
                ((HasImageProvider) child).getBakeryDefaults().addDefaultImages(otherChild.getBakeryDefaults().getBaseImages());
            }
        }
        child = (Provider) iterator.getNext();
    }
    List<String> files = backupRequiredFiles(providers, deploymentConfiguration.getName());
    profile.appendContents(yamlToString(providers)).appendContents(profile.getBaseContents()).setRequiredFiles(files);
}
Also used : NodeIterator(com.netflix.spinnaker.halyard.config.model.v1.node.NodeIterator) Providers(com.netflix.spinnaker.halyard.config.model.v1.node.Providers) HasImageProvider(com.netflix.spinnaker.halyard.config.model.v1.node.HasImageProvider) Provider(com.netflix.spinnaker.halyard.config.model.v1.node.Provider) HasImageProvider(com.netflix.spinnaker.halyard.config.model.v1.node.HasImageProvider) NodeFilter(com.netflix.spinnaker.halyard.config.model.v1.node.NodeFilter)

Example 5 with NodeIterator

use of com.netflix.spinnaker.halyard.config.model.v1.node.NodeIterator 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)

Aggregations

NodeIterator (com.netflix.spinnaker.halyard.config.model.v1.node.NodeIterator)5 Node (com.netflix.spinnaker.halyard.config.model.v1.node.Node)3 Provider (com.netflix.spinnaker.halyard.config.model.v1.node.Provider)3 Strings (com.beust.jcommander.Strings)1 Lists (com.beust.jcommander.internal.Lists)1 DeploymentConfiguration (com.netflix.spinnaker.halyard.config.model.v1.node.DeploymentConfiguration)1 HasImageProvider (com.netflix.spinnaker.halyard.config.model.v1.node.HasImageProvider)1 NodeFilter (com.netflix.spinnaker.halyard.config.model.v1.node.NodeFilter)1 Providers (com.netflix.spinnaker.halyard.config.model.v1.node.Providers)1 Validator (com.netflix.spinnaker.halyard.config.model.v1.node.Validator)1 RedisPersistentStore (com.netflix.spinnaker.halyard.config.model.v1.persistentStorage.RedisPersistentStore)1 DockerRegistryReference (com.netflix.spinnaker.halyard.config.model.v1.providers.containers.DockerRegistryReference)1 DCOSAccount (com.netflix.spinnaker.halyard.config.model.v1.providers.dcos.DCOSAccount)1 DCOSCluster (com.netflix.spinnaker.halyard.config.model.v1.providers.dcos.DCOSCluster)1 DockerRegistryProvider (com.netflix.spinnaker.halyard.config.model.v1.providers.dockerRegistry.DockerRegistryProvider)1 ConfigProblemSetBuilder (com.netflix.spinnaker.halyard.config.problem.v1.ConfigProblemSetBuilder)1 DockerRegistryReferenceValidation.validateDockerRegistries (com.netflix.spinnaker.halyard.config.validate.v1.providers.dockerRegistry.DockerRegistryReferenceValidation.validateDockerRegistries)1 ValidatingFileReader (com.netflix.spinnaker.halyard.config.validate.v1.util.ValidatingFileReader)1 HalException (com.netflix.spinnaker.halyard.core.error.v1.HalException)1 ERROR (com.netflix.spinnaker.halyard.core.problem.v1.Problem.Severity.ERROR)1