Search in sources :

Example 1 with ArtifactService

use of com.netflix.spinnaker.halyard.deploy.services.v1.ArtifactService 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)

Aggregations

DeploymentConfiguration (com.netflix.spinnaker.halyard.config.model.v1.node.DeploymentConfiguration)1 HalException (com.netflix.spinnaker.halyard.core.error.v1.HalException)1 ArtifactService (com.netflix.spinnaker.halyard.deploy.services.v1.ArtifactService)1 SpinnakerArtifact (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.SpinnakerArtifact)1 SpinnakerRuntimeSettings (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.SpinnakerRuntimeSettings)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)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