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);
}
}
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;
}
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);
}
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);
}
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.");
}
}
});
}
Aggregations