use of com.netflix.spinnaker.halyard.config.model.v1.providers.dcos.DCOSCluster in project halyard by spinnaker.
the class DCOSAddClusterCommand method executeThis.
@Override
protected void executeThis() {
DCOSCluster cluster = new DCOSCluster();
cluster.setName(getClusterName()).setDcosUrl(dcosUrl).setCaCertFile(caCertFile).setInsecureSkipTlsVerify(insecureSkipTlsVerify);
if (nonNull(loadBalancerImage)) {
final DCOSCluster.LoadBalancer loadBalancer = new DCOSCluster.LoadBalancer().setImage(loadBalancerImage).setServiceAccountSecret(loadBalancerServiceAccountSecret);
cluster.setLoadBalancer(loadBalancer);
}
new OperationHandler<Void>().setFailureMesssage("Failed to add cluster " + getClusterName() + " for provider " + getProviderName() + ".").setSuccessMessage("Successfully added cluster " + getClusterName() + " for provider " + getProviderName() + ".").setOperation(Daemon.addCluster(getCurrentDeployment(), getProviderName(), !noValidate, cluster)).get();
}
use of com.netflix.spinnaker.halyard.config.model.v1.providers.dcos.DCOSCluster in project halyard by spinnaker.
the class DCOSListClusterCommand method executeThis.
@Override
protected void executeThis() {
Provider provider = getProvider();
DCOSProvider dcosProvider = (DCOSProvider) provider;
List<DCOSCluster> clusters = dcosProvider.getClusters();
if (clusters.isEmpty()) {
AnsiUi.success("No configured clusters for " + getProviderName() + ".");
} else {
AnsiUi.success("Clusters for " + getProviderName() + ":");
clusters.forEach(cluster -> AnsiUi.listItem(cluster.getName()));
}
}
use of com.netflix.spinnaker.halyard.config.model.v1.providers.dcos.DCOSCluster in project halyard by spinnaker.
the class DCOSEditClusterCommand method executeThis.
@Override
protected void executeThis() {
String clusterName = getClusterName();
String providerName = getProviderName();
String currentDeployment = getCurrentDeployment();
// Disable validation here, since we don't want an illegal config to prevent us from fixing it.
DCOSCluster cluster = (DCOSCluster) new OperationHandler<Cluster>().setFailureMesssage("Failed to get cluster " + clusterName + " for provider " + providerName + ".").setOperation(Daemon.getCluster(currentDeployment, providerName, clusterName, false)).get();
int originalHash = cluster.hashCode();
if (!isStringEmpty(dcosUrl)) {
cluster.setDcosUrl(dcosUrl);
}
if (!isStringEmpty(caCertFile)) {
cluster.setCaCertFile(caCertFile);
}
if (removeCaCertFile) {
cluster.setCaCertFile(null);
}
if (Objects.nonNull(insecureSkipTlsVerify)) {
cluster.setInsecureSkipTlsVerify(insecureSkipTlsVerify);
}
if (!isStringEmpty(loadBalancerImage)) {
DCOSCluster.LoadBalancer loadBalancer = cluster.getLoadBalancer();
if (loadBalancer == null) {
loadBalancer = new DCOSCluster.LoadBalancer();
cluster.setLoadBalancer(loadBalancer);
}
loadBalancer.setImage(loadBalancerImage);
}
if (!isStringEmpty(loadBalancerServiceAccountSecret)) {
DCOSCluster.LoadBalancer loadBalancer = cluster.getLoadBalancer();
if (loadBalancer == null) {
loadBalancer = new DCOSCluster.LoadBalancer();
cluster.setLoadBalancer(loadBalancer);
}
loadBalancer.setServiceAccountSecret(loadBalancerServiceAccountSecret);
}
if (removeLoadBalancer) {
cluster.setLoadBalancer(null);
}
if (originalHash == cluster.hashCode()) {
AnsiUi.failure("No changes supplied.");
return;
}
new OperationHandler<Void>().setFailureMesssage("Failed to edit cluster " + clusterName + " for provider " + providerName + ".").setSuccessMessage("Successfully edited cluster " + clusterName + " for provider " + providerName + ".").setOperation(Daemon.setCluster(currentDeployment, providerName, clusterName, !noValidate, cluster)).get();
}
use of com.netflix.spinnaker.halyard.config.model.v1.providers.dcos.DCOSCluster 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