Search in sources :

Example 1 with ProfileFactory

use of com.netflix.spinnaker.halyard.deploy.spinnaker.v1.profile.ProfileFactory in project halyard by spinnaker.

the class RegistryBackedArchiveProfileBuilder method build.

public List<Profile> build(DeploymentConfiguration deploymentConfiguration, String baseOutputPath, SpinnakerArtifact artifact, String archiveName) {
    String version = artifactService.getArtifactVersion(deploymentConfiguration.getName(), artifact);
    InputStream is;
    try {
        is = profileRegistry.readArchiveProfile(artifact.getName(), version, archiveName);
    } catch (IOException e) {
        throw new HalException(Problem.Severity.FATAL, "Error retrieving contents of archive " + archiveName + ".tar.gz", e);
    }
    TarArchiveInputStream tis;
    try {
        tis = (TarArchiveInputStream) new ArchiveStreamFactory().createArchiveInputStream("tar", is);
    } catch (ArchiveException e) {
        throw new HalException(Problem.Severity.FATAL, "Failed to unpack tar archive", e);
    }
    try {
        List<Profile> result = new ArrayList<>();
        ArchiveEntry profileEntry = tis.getNextEntry();
        while (profileEntry != null) {
            if (profileEntry.isDirectory()) {
                profileEntry = tis.getNextEntry();
                continue;
            }
            String entryName = profileEntry.getName();
            String profileName = String.join("/", artifact.getName(), archiveName, entryName);
            String outputPath = Paths.get(baseOutputPath, archiveName, entryName).toString();
            String contents = IOUtils.toString(tis);
            result.add((new ProfileFactory() {

                @Override
                protected void setProfile(Profile profile, DeploymentConfiguration deploymentConfiguration, SpinnakerRuntimeSettings endpoints) {
                    profile.setContents(profile.getBaseContents());
                }

                @Override
                protected Profile getBaseProfile(String name, String version, String outputFile) {
                    return new Profile(name, version, outputFile, contents);
                }

                @Override
                protected boolean showEditWarning() {
                    return false;
                }

                @Override
                protected ArtifactService getArtifactService() {
                    return artifactService;
                }

                @Override
                public SpinnakerArtifact getArtifact() {
                    return artifact;
                }

                @Override
                protected String commentPrefix() {
                    return null;
                }
            }).getProfile(profileName, outputPath, deploymentConfiguration, null));
            profileEntry = tis.getNextEntry();
        }
        return result;
    } catch (IOException e) {
        throw new HalException(Problem.Severity.FATAL, "Failed to read profile entry", e);
    }
}
Also used : SpinnakerArtifact(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.SpinnakerArtifact) TarArchiveInputStream(org.apache.commons.compress.archivers.tar.TarArchiveInputStream) InputStream(java.io.InputStream) HalException(com.netflix.spinnaker.halyard.core.error.v1.HalException) ArtifactService(com.netflix.spinnaker.halyard.deploy.services.v1.ArtifactService) ArrayList(java.util.ArrayList) ArchiveEntry(org.apache.commons.compress.archivers.ArchiveEntry) IOException(java.io.IOException) SpinnakerRuntimeSettings(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.SpinnakerRuntimeSettings) ArchiveException(org.apache.commons.compress.archivers.ArchiveException) TarArchiveInputStream(org.apache.commons.compress.archivers.tar.TarArchiveInputStream) ArchiveStreamFactory(org.apache.commons.compress.archivers.ArchiveStreamFactory) DeploymentConfiguration(com.netflix.spinnaker.halyard.config.model.v1.node.DeploymentConfiguration)

Example 2 with ProfileFactory

use of com.netflix.spinnaker.halyard.deploy.spinnaker.v1.profile.ProfileFactory in project halyard by spinnaker.

the class SpinnakerService method customProfile.

public Optional<Profile> customProfile(DeploymentConfiguration deploymentConfiguration, SpinnakerRuntimeSettings runtimeSettings, Path profilePath, String profileName) {
    return customProfileOutputPath(profileName).flatMap(outputPath -> {
        SpinnakerArtifact artifact = getArtifact();
        ProfileFactory factory = new CustomProfileFactory() {

            @Override
            public SpinnakerArtifact getArtifact() {
                return artifact;
            }

            protected ArtifactService getArtifactService() {
                return artifactService;
            }

            @Override
            protected Path getUserProfilePath() {
                return profilePath;
            }
        };
        return Optional.of(factory.getProfile(profileName, outputPath, deploymentConfiguration, runtimeSettings));
    });
}
Also used : SpinnakerArtifact(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.SpinnakerArtifact) CustomProfileFactory(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.profile.CustomProfileFactory) ProfileFactory(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.profile.ProfileFactory) CustomProfileFactory(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.profile.CustomProfileFactory)

Example 3 with ProfileFactory

use of com.netflix.spinnaker.halyard.deploy.spinnaker.v1.profile.ProfileFactory in project halyard by spinnaker.

the class SpinnakerMonitoringDaemonService method getProfiles.

@Override
public List<Profile> getProfiles(DeploymentConfiguration deploymentConfiguration, SpinnakerRuntimeSettings endpoints) {
    List<Profile> results = new ArrayList<>();
    for (Map.Entry<Type, ServiceSettings> entry : endpoints.getAllServiceSettings().entrySet()) {
        ServiceSettings settings = entry.getValue();
        if (settings.getMonitored() && settings.getEnabled()) {
            String serviceName = entry.getKey().getCanonicalName();
            String profileName = serviceRegistryProfileName(serviceName);
            String profilePath = Paths.get(REGISTRY_OUTPUT_PATH, serviceName + ".yml").toString();
            ProfileFactory factory = metricRegistryProfileFactoryBuilder.build(settings);
            results.add(factory.getProfile(profileName, profilePath, deploymentConfiguration, endpoints));
        }
    }
    String profileName = monitoringProfileName();
    String profilePath = Paths.get(CONFIG_OUTPUT_PATH, profileName).toString();
    results.add(spinnakerMonitoringDaemonProfileFactory.getProfile(profileName, profilePath, deploymentConfiguration, endpoints));
    return results;
}
Also used : ProfileFactory(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.profile.ProfileFactory) SpinnakerMonitoringDaemonProfileFactory(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.profile.SpinnakerMonitoringDaemonProfileFactory) Profile(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.profile.Profile)

Example 4 with ProfileFactory

use of com.netflix.spinnaker.halyard.deploy.spinnaker.v1.profile.ProfileFactory in project halyard by spinnaker.

the class ConsulClientService method getProfiles.

@Override
public List<Profile> getProfiles(DeploymentConfiguration deploymentConfiguration, SpinnakerRuntimeSettings endpoints) {
    List<Profile> result = new ArrayList<>();
    for (Map.Entry<Type, ServiceSettings> entry : endpoints.getAllServiceSettings().entrySet()) {
        ServiceSettings settings = entry.getValue();
        Type type = entry.getKey();
        if (!settings.getSidecar() && settings.getEnabled()) {
            String serviceName = type.getCanonicalName();
            String profileName = consulClientService(serviceName);
            String profilePath = Paths.get(CLIENT_OUTPUT_PATH, serviceName + ".json").toString();
            ProfileFactory factory = consulServiceProfileFactoryBuilder.build(type, settings);
            result.add(factory.getProfile(profileName, profilePath, deploymentConfiguration, endpoints));
        }
    }
    String profileName = clientProfileName;
    String profilePath = Paths.get(CLIENT_OUTPUT_PATH, profileName.split("/")[1]).toString();
    result.add(consulClientProfileFactory.getProfile(profileName, profilePath, deploymentConfiguration, endpoints));
    return result;
}
Also used : ProfileFactory(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.profile.ProfileFactory) ConsulClientProfileFactory(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.profile.consul.ConsulClientProfileFactory) Profile(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.profile.Profile)

Example 5 with ProfileFactory

use of com.netflix.spinnaker.halyard.deploy.spinnaker.v1.profile.ProfileFactory in project halyard by spinnaker.

the class MetricRegistryProfileFactoryBuilder method build.

public ProfileFactory build(ServiceSettings settings) {
    return new ProfileFactory() {

        @Override
        protected ArtifactService getArtifactService() {
            return artifactService;
        }

        @Override
        protected void setProfile(Profile profile, DeploymentConfiguration deploymentConfiguration, SpinnakerRuntimeSettings endpoints) {
            URI uri;
            try {
                String baseUrl;
                if (settings.getBasicAuthEnabled() != null && settings.getBasicAuthEnabled()) {
                    baseUrl = settings.getAuthBaseUrl();
                } else {
                    baseUrl = settings.getBaseUrl();
                }
                uri = new URIBuilder(baseUrl).setHost("localhost").setPath("/spectator/metrics").build();
            } catch (URISyntaxException e) {
                throw new HalException(Problem.Severity.FATAL, "Unable to build service URL: " + e.getMessage());
            }
            profile.appendContents("metrics_url: " + uri.toString());
        }

        @Override
        protected Profile getBaseProfile(String name, String version, String outputFile) {
            return new Profile(name, version, outputFile, "");
        }

        @Override
        public SpinnakerArtifact getArtifact() {
            return SpinnakerArtifact.SPINNAKER_MONITORING_DAEMON;
        }

        @Override
        protected String commentPrefix() {
            return "## ";
        }
    };
}
Also used : HalException(com.netflix.spinnaker.halyard.core.error.v1.HalException) SpinnakerRuntimeSettings(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.SpinnakerRuntimeSettings) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) DeploymentConfiguration(com.netflix.spinnaker.halyard.config.model.v1.node.DeploymentConfiguration) URIBuilder(org.apache.http.client.utils.URIBuilder)

Aggregations

ProfileFactory (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.profile.ProfileFactory)3 DeploymentConfiguration (com.netflix.spinnaker.halyard.config.model.v1.node.DeploymentConfiguration)2 HalException (com.netflix.spinnaker.halyard.core.error.v1.HalException)2 SpinnakerArtifact (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.SpinnakerArtifact)2 SpinnakerRuntimeSettings (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.SpinnakerRuntimeSettings)2 Profile (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.profile.Profile)2 ArtifactService (com.netflix.spinnaker.halyard.deploy.services.v1.ArtifactService)1 CustomProfileFactory (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.profile.CustomProfileFactory)1 SpinnakerMonitoringDaemonProfileFactory (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.profile.SpinnakerMonitoringDaemonProfileFactory)1 ConsulClientProfileFactory (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.profile.consul.ConsulClientProfileFactory)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 ArchiveEntry (org.apache.commons.compress.archivers.ArchiveEntry)1 ArchiveException (org.apache.commons.compress.archivers.ArchiveException)1 ArchiveStreamFactory (org.apache.commons.compress.archivers.ArchiveStreamFactory)1 TarArchiveInputStream (org.apache.commons.compress.archivers.tar.TarArchiveInputStream)1 URIBuilder (org.apache.http.client.utils.URIBuilder)1