Search in sources :

Example 41 with Account

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;
}
Also used : HalException(com.netflix.spinnaker.halyard.core.error.v1.HalException) ManagedInstance(com.google.api.services.compute.model.ManagedInstance) ServiceAccount(com.google.api.services.compute.model.ServiceAccount) DaemonTaskHandler(com.netflix.spinnaker.halyard.core.tasks.v1.DaemonTaskHandler) AttachedDisk(com.google.api.services.compute.model.AttachedDisk) SidecarService(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.distributed.SidecarService) GoogleJsonResponseException(com.google.api.client.googleapis.json.GoogleJsonResponseException) Names(com.netflix.frigga.Names) Map(java.util.Map) Provider(com.netflix.spinnaker.halyard.config.model.v1.node.Provider) URI(java.net.URI) SpinnakerService(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.SpinnakerService) Path(java.nio.file.Path) InstanceTemplate(com.google.api.services.compute.model.InstanceTemplate) ServiceInterfaceFactory(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ServiceInterfaceFactory) VaultConnectionDetails(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.distributed.VaultConnectionDetails) URIBuilder(org.apache.http.client.utils.URIBuilder) Set(java.util.Set) NetworkInterface(com.google.api.services.compute.model.NetworkInterface) Operation(com.google.api.services.compute.model.Operation) Collectors(java.util.stream.Collectors) AttachedDiskInitializeParams(com.google.api.services.compute.model.AttachedDiskInitializeParams) Objects(java.util.Objects) List(java.util.List) InstanceProperties(com.google.api.services.compute.model.InstanceProperties) VaultConfigMount(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.distributed.VaultConfigMount) FATAL(com.netflix.spinnaker.halyard.core.problem.v1.Problem.Severity.FATAL) GoogleDiskType(com.netflix.spinnaker.clouddriver.google.model.GoogleDiskType) Problem(com.netflix.spinnaker.halyard.core.problem.v1.Problem) DaemonTaskInterrupted(com.netflix.spinnaker.halyard.core.tasks.v1.DaemonTaskInterrupted) ServiceSettings(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ServiceSettings) Compute(com.google.api.services.compute.Compute) Metadata(com.google.api.services.compute.model.Metadata) VaultConfigMountSet(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.distributed.VaultConfigMountSet) HashMap(java.util.HashMap) ArtifactService(com.netflix.spinnaker.halyard.deploy.services.v1.ArtifactService) RunningServiceDetails(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.RunningServiceDetails) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) AccountDeploymentDetails(com.netflix.spinnaker.halyard.deploy.deployment.v1.AccountDeploymentDetails) AccessConfig(com.google.api.services.compute.model.AccessConfig) GoogleAccount(com.netflix.spinnaker.halyard.config.model.v1.providers.google.GoogleAccount) ResolvedConfiguration(com.netflix.spinnaker.halyard.deploy.services.v1.GenerateService.ResolvedConfiguration) RandomStringUtils(org.apache.commons.lang.RandomStringUtils) InstanceGroupManager(com.google.api.services.compute.model.InstanceGroupManager) IOException(java.io.IOException) SpinnakerRuntimeSettings(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.SpinnakerRuntimeSettings) VaultServerService(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.VaultServerService) TimeUnit(java.util.concurrent.TimeUnit) GCEUtil(com.netflix.spinnaker.clouddriver.google.deploy.GCEUtil) Profile(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.profile.Profile) Paths(java.nio.file.Paths) DistributedService(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.distributed.DistributedService) ConfigSource(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ConfigSource) Collections(java.util.Collections) GoogleAccount(com.netflix.spinnaker.halyard.config.model.v1.providers.google.GoogleAccount) ManagedInstance(com.google.api.services.compute.model.ManagedInstance) HalException(com.netflix.spinnaker.halyard.core.error.v1.HalException) Names(com.netflix.frigga.Names) RunningServiceDetails(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.RunningServiceDetails) List(java.util.List) ArrayList(java.util.ArrayList) InstanceGroupManager(com.google.api.services.compute.model.InstanceGroupManager) ServiceSettings(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ServiceSettings) IOException(java.io.IOException) Compute(com.google.api.services.compute.Compute) Objects(java.util.Objects) ManagedInstance(com.google.api.services.compute.model.ManagedInstance)

Example 42 with Account

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;
}
Also used : DockerRegistryReference(com.netflix.spinnaker.halyard.config.model.v1.providers.containers.DockerRegistryReference) DockerRegistryReference(com.netflix.spinnaker.halyard.config.model.v1.providers.containers.DockerRegistryReference) LocalFileConverter(com.netflix.spinnaker.halyard.cli.command.v1.converter.LocalFileConverter) Parameters(com.beust.jcommander.Parameters) List(java.util.List) Parameter(com.beust.jcommander.Parameter) AbstractEditAccountCommand(com.netflix.spinnaker.halyard.cli.command.v1.config.providers.account.AbstractEditAccountCommand) Account(com.netflix.spinnaker.halyard.config.model.v1.node.Account) KubernetesAccount(com.netflix.spinnaker.halyard.config.model.v1.providers.kubernetes.KubernetesAccount) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList)

Example 43 with 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();
}
Also used : Account(com.netflix.spinnaker.halyard.config.model.v1.node.Account) OperationHandler(com.netflix.spinnaker.halyard.cli.services.v1.OperationHandler)

Example 44 with Account

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();
}
Also used : Account(com.netflix.spinnaker.halyard.config.model.v1.node.Account) ArrayList(java.util.ArrayList) List(java.util.List)

Example 45 with Account

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();
}
Also used : Account(com.netflix.spinnaker.halyard.config.model.v1.node.Account) OperationHandler(com.netflix.spinnaker.halyard.cli.services.v1.OperationHandler)

Aggregations

Account (com.netflix.spinnaker.halyard.config.model.v1.node.Account)19 List (java.util.List)13 Provider (com.netflix.spinnaker.halyard.config.model.v1.node.Provider)11 KubernetesAccount (com.netflix.spinnaker.halyard.config.model.v1.providers.kubernetes.KubernetesAccount)11 HalException (com.netflix.spinnaker.halyard.core.error.v1.HalException)11 Collectors (java.util.stream.Collectors)10 DeploymentConfiguration (com.netflix.spinnaker.halyard.config.model.v1.node.DeploymentConfiguration)9 ConfigProblemBuilder (com.netflix.spinnaker.halyard.config.problem.v1.ConfigProblemBuilder)8 ArrayList (java.util.ArrayList)8 AbstractCanaryAccount (com.netflix.spinnaker.halyard.config.model.v1.canary.AbstractCanaryAccount)7 Path (java.nio.file.Path)7 OperationHandler (com.netflix.spinnaker.halyard.cli.services.v1.OperationHandler)6 ArtifactAccount (com.netflix.spinnaker.halyard.config.model.v1.node.ArtifactAccount)6 DockerRegistryReference (com.netflix.spinnaker.halyard.config.model.v1.providers.containers.DockerRegistryReference)6 GoogleAccount (com.netflix.spinnaker.halyard.config.model.v1.providers.google.GoogleAccount)6 UpdateRequestBuilder (com.netflix.spinnaker.halyard.core.DaemonResponse.UpdateRequestBuilder)6 ServiceSettings (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ServiceSettings)6 IOException (java.io.IOException)5 Collections (java.util.Collections)5 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5