use of com.netflix.spinnaker.halyard.config.model.v1.node.Account in project halyard by spinnaker.
the class GoogleDistributedService method getRunningServiceDetails.
@Override
default RunningServiceDetails getRunningServiceDetails(AccountDeploymentDetails<GoogleAccount> details, SpinnakerRuntimeSettings runtimeSettings) {
ServiceSettings settings = runtimeSettings.getServiceSettings(getService());
RunningServiceDetails result = new RunningServiceDetails();
// All GCE load balancing is done via consul
result.setLoadBalancer(new RunningServiceDetails.LoadBalancer().setExists(true));
Compute compute = GoogleProviderUtils.getCompute(details);
GoogleAccount account = details.getAccount();
List<InstanceGroupManager> migs;
try {
migs = compute.instanceGroupManagers().list(account.getProject(), settings.getLocation()).execute().getItems();
if (migs == null) {
migs = Collections.emptyList();
}
} catch (IOException e) {
throw new HalException(FATAL, "Failed to load MIGS: " + e.getMessage(), e);
}
boolean consulEnabled = getSidecars(runtimeSettings).stream().anyMatch(s -> s.getService().getType().equals(SpinnakerService.Type.CONSUL_CLIENT));
Set<String> healthyConsulInstances = consulEnabled ? getConsulServerService().connectToPrimaryService(details, runtimeSettings).serviceHealth(getService().getCanonicalName(), true).stream().map(s -> s != null && s.getNode() != null ? s.getNode().getNodeName() : null).filter(Objects::nonNull).collect(Collectors.toSet()) : new HashSet<>();
String serviceName = getService().getServiceName();
migs = migs.stream().filter(ig -> ig.getName().startsWith(serviceName + "-v")).collect(Collectors.toList());
Map<Integer, List<RunningServiceDetails.Instance>> instances = migs.stream().reduce(new HashMap<>(), (map, mig) -> {
Names names = Names.parseName(mig.getName());
Integer version = names.getSequence();
List<RunningServiceDetails.Instance> computeInstances;
try {
List<ManagedInstance> managedInstances = compute.instanceGroupManagers().listManagedInstances(account.getProject(), settings.getLocation(), mig.getName()).execute().getManagedInstances();
if (managedInstances == null) {
managedInstances = new ArrayList<>();
}
computeInstances = managedInstances.stream().map(i -> {
String instanceUrl = i.getInstance();
String instanceStatus = i.getInstanceStatus();
boolean running = instanceStatus != null && instanceStatus.equalsIgnoreCase("running");
String instanceName = instanceUrl.substring(instanceUrl.lastIndexOf('/') + 1, instanceUrl.length());
return new RunningServiceDetails.Instance().setId(instanceName).setLocation(settings.getLocation()).setRunning(running).setHealthy(!consulEnabled || healthyConsulInstances.contains(instanceName));
}).collect(Collectors.toList());
} catch (IOException e) {
throw new HalException(FATAL, "Failed to load target pools for " + serviceName, e);
}
map.put(version, computeInstances);
return map;
}, (m1, m2) -> {
m1.putAll(m2);
return m1;
});
result.setInstances(instances);
return result;
}
use of com.netflix.spinnaker.halyard.config.model.v1.node.Account in project halyard by spinnaker.
the class KubernetesEditAccountCommand method editAccount.
@Override
protected Account editAccount(KubernetesAccount account) {
boolean contextSet = context != null && !context.isEmpty();
if (contextSet && !clearContext) {
account.setContext(context);
} else if (!contextSet && clearContext) {
account.setContext(null);
} else if (contextSet && clearContext) {
throw new IllegalArgumentException("Set either --context or --clear-context");
}
account.setKubeconfigFile(isSet(kubeconfigFile) ? kubeconfigFile : account.getKubeconfigFile());
account.setConfigureImagePullSecrets(isSet(configureImagePullSecrets) ? configureImagePullSecrets : account.getConfigureImagePullSecrets());
account.setServiceAccount(isSet(serviceAccount) ? serviceAccount : account.getServiceAccount());
try {
account.setNamespaces(updateStringList(account.getNamespaces(), namespaces, addNamespace, removeNamespace));
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException("Set either --namespaces or --[add/remove]-namespace");
}
try {
account.setOmitNamespaces(updateStringList(account.getOmitNamespaces(), omitNamespaces, addOmitNamespace, removeOmitNamespace));
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException("Set either --omit-namespaces or --[add/remove]-omit-namespace");
}
try {
account.setKinds(updateStringList(account.getKinds(), kinds, addKind, removeKind));
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException("Set either --kinds or --[add/remove]-kind");
}
try {
account.setOmitKinds(updateStringList(account.getOmitKinds(), omitKinds, addOmitKind, removeOmitKind));
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException("Set either --omit-kinds or --[add/remove]-omit-kind");
}
try {
List<String> oldRegistries = account.getDockerRegistries().stream().map(DockerRegistryReference::getAccountName).collect(Collectors.toList());
List<DockerRegistryReference> newRegistries = updateStringList(oldRegistries, dockerRegistries, addDockerRegistry, removeDockerRegistry).stream().map(s -> new DockerRegistryReference().setAccountName(s)).collect(Collectors.toList());
account.setDockerRegistries(newRegistries);
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException("Set either --docker-registries or --[add/remove]-docker-registry");
}
try {
account.setOAuthScopes(updateStringList(account.getOAuthScopes(), oAuthScopes, addOAuthScope, removeOAuthScope));
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException("Set either --oauth-scopes or --[add/remove]-oauth-scope");
}
account.setOAuthServiceAccount(isSet(oAuthServiceAccount) ? oAuthServiceAccount : account.getOAuthServiceAccount());
account.setNamingStrategy(isSet(namingStrategy) ? namingStrategy : account.getNamingStrategy());
account.setSkin(isSet(skin) ? skin : account.getSkin());
return account;
}
use of com.netflix.spinnaker.halyard.config.model.v1.node.Account in project halyard by spinnaker.
the class AbstractAddAccountCommand method executeThis.
@Override
protected void executeThis() {
String accountName = getAccountName();
Account account = buildAccount(accountName);
account.setRequiredGroupMembership(requiredGroupMembership);
account.setProviderVersion(providerVersion);
String providerName = getProviderName();
String currentDeployment = getCurrentDeployment();
new OperationHandler<Void>().setFailureMesssage("Failed to add account " + accountName + " for provider " + providerName + ".").setSuccessMessage("Successfully added account " + accountName + " for provider " + providerName + ".").setOperation(Daemon.addAccount(currentDeployment, providerName, !noValidate, account)).get();
}
use of com.netflix.spinnaker.halyard.config.model.v1.node.Account in project halyard by spinnaker.
the class AbstractAddAccountCommand method options.
@Override
protected List<String> options(String fieldName) {
String currentDeployment = getCurrentDeployment();
String accountName = getAccountName("hal-default-account");
Account account = buildAccount(accountName);
String providerName = getProviderName();
return new OperationHandler<List<String>>().setFailureMesssage("Failed to get options for field " + fieldName).setOperation(Daemon.getNewAccountOptions(currentDeployment, providerName, fieldName, account)).get();
}
use of com.netflix.spinnaker.halyard.config.model.v1.node.Account in project halyard by spinnaker.
the class AbstractEditAccountCommand method executeThis.
@Override
protected void executeThis() {
String accountName = getAccountName();
String providerName = getProviderName();
String currentDeployment = getCurrentDeployment();
// Disable validation here, since we don't want an illegal config to prevent us from fixing it.
Account account = new OperationHandler<Account>().setFailureMesssage("Failed to get account " + accountName + " for provider " + providerName + ".").setOperation(Daemon.getAccount(currentDeployment, providerName, accountName, false)).get();
int originaHash = account.hashCode();
account = editAccount((T) account);
account.setRequiredGroupMembership(updateStringList(account.getRequiredGroupMembership(), requiredGroupMembership, addRequiredGroupMembership, removeRequiredGroupMembership));
account.setProviderVersion(isSet(providerVersion) ? providerVersion : account.getProviderVersion());
if (originaHash == account.hashCode()) {
AnsiUi.failure("No changes supplied.");
return;
}
new OperationHandler<Void>().setFailureMesssage("Failed to edit account " + accountName + " for provider " + providerName + ".").setSuccessMessage("Successfully edited account " + accountName + " for provider " + providerName + ".").setOperation(Daemon.setAccount(currentDeployment, providerName, accountName, !noValidate, account)).get();
}
Aggregations