Search in sources :

Example 1 with ConfigProblemBuilder

use of com.netflix.spinnaker.halyard.config.problem.v1.ConfigProblemBuilder in project halyard by spinnaker.

the class GenerateService method generateConfig.

/**
 * Generate config for a given deployment.
 *
 * This involves a few steps:
 *
 *   1. Clear out old config generated in a prior run.
 *   2. Generate configuration using the halconfig as the source of truth, while collecting files needed by
 *      the deployment.
 *
 * @param deploymentName is the deployment whose config to generate
 * @param services is the list of services to generate configs for
 * @return a mapping from components to the profile's required local files.
 */
public ResolvedConfiguration generateConfig(String deploymentName, List<SpinnakerService.Type> services) {
    DaemonTaskHandler.newStage("Generating all Spinnaker profile files and endpoints");
    log.info("Generating config from \"" + halconfigPath + "\" with deploymentName \"" + deploymentName + "\"");
    File spinnakerStaging = halconfigDirectoryStructure.getStagingPath(deploymentName).toFile();
    DeploymentConfiguration deploymentConfiguration = deploymentService.getDeploymentConfiguration(deploymentName);
    DaemonTaskHandler.message("Building service endpoints");
    SpinnakerServiceProvider<DeploymentDetails> serviceProvider = serviceProviderFactory.create(deploymentConfiguration);
    SpinnakerRuntimeSettings runtimeSettings = serviceProvider.buildRuntimeSettings(deploymentConfiguration);
    // Step 1.
    try {
        FileUtils.deleteDirectory(spinnakerStaging);
    } catch (IOException e) {
        throw new HalException(new ConfigProblemBuilder(Severity.FATAL, "Unable to clear old spinnaker config: " + e.getMessage() + ".").build());
    }
    Path userProfilePath = halconfigDirectoryStructure.getUserProfilePath(deploymentName);
    List<String> userProfileNames = aggregateProfilesInPath(userProfilePath.toString(), "");
    // Step 2.
    Map<SpinnakerService.Type, Map<String, Profile>> serviceProfiles = new HashMap<>();
    for (SpinnakerService service : serviceProvider.getServices()) {
        boolean isDesiredService = services.stream().filter(s -> s.equals(service.getType())).count() > 0;
        if (!isDesiredService) {
            continue;
        }
        ServiceSettings settings = runtimeSettings.getServiceSettings(service);
        if (settings == null || !settings.getEnabled()) {
            continue;
        }
        List<Profile> profiles = service.getProfiles(deploymentConfiguration, runtimeSettings);
        String pluralModifier = profiles.size() == 1 ? "" : "s";
        String profileMessage = "Generated " + profiles.size() + " profile" + pluralModifier;
        Map<String, Profile> outputProfiles = processProfiles(spinnakerStaging, profiles);
        List<Profile> customProfiles = userProfileNames.stream().map(s -> (Optional<Profile>) service.customProfile(deploymentConfiguration, runtimeSettings, Paths.get(userProfilePath.toString(), s), s)).filter(Optional::isPresent).map(Optional::get).collect(Collectors.toList());
        pluralModifier = customProfiles.size() == 1 ? "" : "s";
        profileMessage += " and discovered " + customProfiles.size() + " custom profile" + pluralModifier + " for " + service.getCanonicalName();
        DaemonTaskHandler.message(profileMessage);
        mergeProfilesAndPreserveProperties(outputProfiles, processProfiles(spinnakerStaging, customProfiles));
        serviceProfiles.put(service.getType(), outputProfiles);
    }
    return new ResolvedConfiguration().setServiceProfiles(serviceProfiles).setRuntimeSettings(runtimeSettings);
}
Also used : DeploymentDetails(com.netflix.spinnaker.halyard.deploy.deployment.v1.DeploymentDetails) Path(java.nio.file.Path) Arrays(java.util.Arrays) Autowired(org.springframework.beans.factory.annotation.Autowired) HalException(com.netflix.spinnaker.halyard.core.error.v1.HalException) HashMap(java.util.HashMap) ServiceProviderFactory(com.netflix.spinnaker.halyard.deploy.deployment.v1.ServiceProviderFactory) DaemonTaskHandler(com.netflix.spinnaker.halyard.core.tasks.v1.DaemonTaskHandler) ArrayList(java.util.ArrayList) Map(java.util.Map) JsonIgnore(com.fasterxml.jackson.annotation.JsonIgnore) Severity(com.netflix.spinnaker.halyard.core.problem.v1.Problem.Severity) SpinnakerService(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.SpinnakerService) Path(java.nio.file.Path) DeploymentDetails(com.netflix.spinnaker.halyard.deploy.deployment.v1.DeploymentDetails) FileUtils(org.apache.commons.io.FileUtils) IOException(java.io.IOException) SpinnakerRuntimeSettings(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.SpinnakerRuntimeSettings) DeploymentConfiguration(com.netflix.spinnaker.halyard.config.model.v1.node.DeploymentConfiguration) ConfigParser(com.netflix.spinnaker.halyard.deploy.config.v1.ConfigParser) Collectors(java.util.stream.Collectors) HalconfigDirectoryStructure(com.netflix.spinnaker.halyard.config.config.v1.HalconfigDirectoryStructure) File(java.io.File) ConfigProblemBuilder(com.netflix.spinnaker.halyard.config.problem.v1.ConfigProblemBuilder) Slf4j(lombok.extern.slf4j.Slf4j) Component(org.springframework.stereotype.Component) List(java.util.List) DeploymentService(com.netflix.spinnaker.halyard.config.services.v1.DeploymentService) Profile(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.profile.Profile) Paths(java.nio.file.Paths) Data(lombok.Data) Optional(java.util.Optional) ServiceSettings(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ServiceSettings) SpinnakerServiceProvider(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.SpinnakerServiceProvider) Collections(java.util.Collections) Optional(java.util.Optional) HashMap(java.util.HashMap) HalException(com.netflix.spinnaker.halyard.core.error.v1.HalException) ServiceSettings(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ServiceSettings) SpinnakerRuntimeSettings(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.SpinnakerRuntimeSettings) IOException(java.io.IOException) SpinnakerService(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.SpinnakerService) Profile(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.profile.Profile) ConfigProblemBuilder(com.netflix.spinnaker.halyard.config.problem.v1.ConfigProblemBuilder) File(java.io.File) HashMap(java.util.HashMap) Map(java.util.Map) DeploymentConfiguration(com.netflix.spinnaker.halyard.config.model.v1.node.DeploymentConfiguration)

Example 2 with ConfigProblemBuilder

use of com.netflix.spinnaker.halyard.config.problem.v1.ConfigProblemBuilder in project halyard by spinnaker.

the class ServiceProviderFactory method createDeployableServiceProvider.

private SpinnakerServiceProvider createDeployableServiceProvider(DeploymentConfiguration deploymentConfiguration) {
    DeploymentEnvironment deploymentEnvironment = deploymentConfiguration.getDeploymentEnvironment();
    String accountName = deploymentEnvironment.getAccountName();
    if (accountName == null || accountName.isEmpty()) {
        throw new HalException(new ConfigProblemBuilder(Problem.Severity.FATAL, "An account name must be " + "specified as the desired place to run your simple clustered deployment.").build());
    }
    Account account = accountService.getAnyProviderAccount(deploymentConfiguration.getName(), accountName);
    Provider.ProviderType providerType = ((Provider) account.getParent()).providerType();
    switch(providerType) {
        case KUBERNETES:
            switch(account.getProviderVersion()) {
                case V1:
                    return kubernetesV1DistributedServiceProvider;
                case V2:
                    return kubectlServiceProvider;
                default:
                    return kubernetesV1DistributedServiceProvider;
            }
        case GOOGLE:
            return googleDistributedServiceProvider;
        default:
            throw new IllegalArgumentException("No Clustered Simple Deployment for " + providerType.getName());
    }
}
Also used : Account(com.netflix.spinnaker.halyard.config.model.v1.node.Account) DeploymentEnvironment(com.netflix.spinnaker.halyard.config.model.v1.node.DeploymentEnvironment) ConfigProblemBuilder(com.netflix.spinnaker.halyard.config.problem.v1.ConfigProblemBuilder) HalException(com.netflix.spinnaker.halyard.core.error.v1.HalException) LocalDebianServiceProvider(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.local.debian.LocalDebianServiceProvider) LocalGitServiceProvider(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.local.git.LocalGitServiceProvider) GoogleDistributedServiceProvider(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.distributed.google.GoogleDistributedServiceProvider) KubectlServiceProvider(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.distributed.kubernetes.v2.KubectlServiceProvider) BakeDebianServiceProvider(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.bake.debian.BakeDebianServiceProvider) SpinnakerServiceProvider(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.SpinnakerServiceProvider) Provider(com.netflix.spinnaker.halyard.config.model.v1.node.Provider) KubernetesV1DistributedServiceProvider(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.distributed.kubernetes.v1.KubernetesV1DistributedServiceProvider)

Example 3 with ConfigProblemBuilder

use of com.netflix.spinnaker.halyard.config.problem.v1.ConfigProblemBuilder in project halyard by spinnaker.

the class ProviderService method getProvider.

public Provider getProvider(String deploymentName, String providerName) {
    NodeFilter filter = new NodeFilter().setDeployment(deploymentName).setProvider(providerName);
    List<Provider> matching = lookupService.getMatchingNodesOfType(filter, Provider.class);
    switch(matching.size()) {
        case 0:
            throw new ConfigNotFoundException(new ConfigProblemBuilder(Severity.FATAL, "No provider with name \"" + providerName + "\" could be found").setRemediation("Create a new provider with name \"" + providerName + "\"").build());
        case 1:
            return matching.get(0);
        default:
            throw new IllegalConfigException(new ConfigProblemBuilder(Severity.FATAL, "More than one provider with name \"" + providerName + "\" found").setRemediation("Manually delete or rename duplicate providers with name \"" + providerName + "\" in your halconfig file").build());
    }
}
Also used : ConfigProblemBuilder(com.netflix.spinnaker.halyard.config.problem.v1.ConfigProblemBuilder) ConfigNotFoundException(com.netflix.spinnaker.halyard.config.error.v1.ConfigNotFoundException) IllegalConfigException(com.netflix.spinnaker.halyard.config.error.v1.IllegalConfigException) GoogleProvider(com.netflix.spinnaker.halyard.config.model.v1.providers.google.GoogleProvider) AzureProvider(com.netflix.spinnaker.halyard.config.model.v1.providers.azure.AzureProvider) AwsProvider(com.netflix.spinnaker.halyard.config.model.v1.providers.aws.AwsProvider) AppengineProvider(com.netflix.spinnaker.halyard.config.model.v1.providers.appengine.AppengineProvider) DockerRegistryProvider(com.netflix.spinnaker.halyard.config.model.v1.providers.dockerRegistry.DockerRegistryProvider) OracleBMCSProvider(com.netflix.spinnaker.halyard.config.model.v1.providers.oraclebmcs.OracleBMCSProvider) OpenstackProvider(com.netflix.spinnaker.halyard.config.model.v1.providers.openstack.OpenstackProvider) DCOSProvider(com.netflix.spinnaker.halyard.config.model.v1.providers.dcos.DCOSProvider) KubernetesProvider(com.netflix.spinnaker.halyard.config.model.v1.providers.kubernetes.KubernetesProvider)

Example 4 with ConfigProblemBuilder

use of com.netflix.spinnaker.halyard.config.problem.v1.ConfigProblemBuilder in project halyard by spinnaker.

the class ProviderService method getHasClustersProvider.

public HasClustersProvider getHasClustersProvider(String deploymentName, String providerName) {
    NodeFilter filter = new NodeFilter().setDeployment(deploymentName).setProvider(providerName);
    Provider provider = getProvider(deploymentName, providerName);
    if (provider instanceof HasClustersProvider) {
        return (HasClustersProvider) provider;
    } else {
        throw new IllegalConfigException(new ConfigProblemBuilder(Severity.FATAL, "Provider \"" + providerName + "\" does not support configuring clusters via Halyard.").build());
    }
}
Also used : ConfigProblemBuilder(com.netflix.spinnaker.halyard.config.problem.v1.ConfigProblemBuilder) IllegalConfigException(com.netflix.spinnaker.halyard.config.error.v1.IllegalConfigException) GoogleProvider(com.netflix.spinnaker.halyard.config.model.v1.providers.google.GoogleProvider) AzureProvider(com.netflix.spinnaker.halyard.config.model.v1.providers.azure.AzureProvider) AwsProvider(com.netflix.spinnaker.halyard.config.model.v1.providers.aws.AwsProvider) AppengineProvider(com.netflix.spinnaker.halyard.config.model.v1.providers.appengine.AppengineProvider) DockerRegistryProvider(com.netflix.spinnaker.halyard.config.model.v1.providers.dockerRegistry.DockerRegistryProvider) OracleBMCSProvider(com.netflix.spinnaker.halyard.config.model.v1.providers.oraclebmcs.OracleBMCSProvider) OpenstackProvider(com.netflix.spinnaker.halyard.config.model.v1.providers.openstack.OpenstackProvider) DCOSProvider(com.netflix.spinnaker.halyard.config.model.v1.providers.dcos.DCOSProvider) KubernetesProvider(com.netflix.spinnaker.halyard.config.model.v1.providers.kubernetes.KubernetesProvider)

Example 5 with ConfigProblemBuilder

use of com.netflix.spinnaker.halyard.config.problem.v1.ConfigProblemBuilder in project halyard by spinnaker.

the class NotificationService method getNotification.

public Notification getNotification(String deploymentName, String notificationName) {
    NodeFilter filter = new NodeFilter().setDeployment(deploymentName).setNotification(notificationName);
    List<Notification> matching = lookupService.getMatchingNodesOfType(filter, Notification.class);
    switch(matching.size()) {
        case 0:
            throw new ConfigNotFoundException(new ConfigProblemBuilder(Severity.FATAL, "No notification type with name \"" + notificationName + "\" could be found").build());
        case 1:
            return matching.get(0);
        default:
            throw new IllegalConfigException(new ConfigProblemBuilder(Severity.FATAL, "More than one notification type with name \"" + notificationName + "\" found").build());
    }
}
Also used : ConfigProblemBuilder(com.netflix.spinnaker.halyard.config.problem.v1.ConfigProblemBuilder) ConfigNotFoundException(com.netflix.spinnaker.halyard.config.error.v1.ConfigNotFoundException) Notification(com.netflix.spinnaker.halyard.config.model.v1.node.Notification) SlackNotification(com.netflix.spinnaker.halyard.config.model.v1.notifications.SlackNotification) IllegalConfigException(com.netflix.spinnaker.halyard.config.error.v1.IllegalConfigException) NodeFilter(com.netflix.spinnaker.halyard.config.model.v1.node.NodeFilter)

Aggregations

ConfigProblemBuilder (com.netflix.spinnaker.halyard.config.problem.v1.ConfigProblemBuilder)39 ConfigNotFoundException (com.netflix.spinnaker.halyard.config.error.v1.ConfigNotFoundException)18 NodeFilter (com.netflix.spinnaker.halyard.config.model.v1.node.NodeFilter)17 HalException (com.netflix.spinnaker.halyard.core.error.v1.HalException)16 IllegalConfigException (com.netflix.spinnaker.halyard.config.error.v1.IllegalConfigException)10 DeploymentConfiguration (com.netflix.spinnaker.halyard.config.model.v1.node.DeploymentConfiguration)4 Versions (com.netflix.spinnaker.halyard.core.registry.v1.Versions)4 IOException (java.io.IOException)4 Account (com.netflix.spinnaker.halyard.config.model.v1.node.Account)3 ArtifactProvider (com.netflix.spinnaker.halyard.config.model.v1.node.ArtifactProvider)3 Ci (com.netflix.spinnaker.halyard.config.model.v1.node.Ci)3 Provider (com.netflix.spinnaker.halyard.config.model.v1.node.Provider)3 Pubsub (com.netflix.spinnaker.halyard.config.model.v1.node.Pubsub)3 AppengineProvider (com.netflix.spinnaker.halyard.config.model.v1.providers.appengine.AppengineProvider)3 AwsProvider (com.netflix.spinnaker.halyard.config.model.v1.providers.aws.AwsProvider)3 AzureProvider (com.netflix.spinnaker.halyard.config.model.v1.providers.azure.AzureProvider)3 DCOSProvider (com.netflix.spinnaker.halyard.config.model.v1.providers.dcos.DCOSProvider)3 DockerRegistryProvider (com.netflix.spinnaker.halyard.config.model.v1.providers.dockerRegistry.DockerRegistryProvider)3 GoogleProvider (com.netflix.spinnaker.halyard.config.model.v1.providers.google.GoogleProvider)3 KubernetesProvider (com.netflix.spinnaker.halyard.config.model.v1.providers.kubernetes.KubernetesProvider)3