use of com.netflix.spinnaker.halyard.deploy.spinnaker.v1.SpinnakerRuntimeSettings in project halyard by spinnaker.
the class DistributedDeployer method reapOrcaServerGroups.
private <T extends Account> Set<Integer> reapOrcaServerGroups(AccountDeploymentDetails<T> details, SpinnakerRuntimeSettings runtimeSettings, DistributedService<Orca, T> orcaService) {
if (runtimeSettings.getServiceSettings(orcaService.getService()).getSkipLifeCycleManagement()) {
return Collections.emptySet();
}
RunningServiceDetails runningOrcaDetails = orcaService.getRunningServiceDetails(details, runtimeSettings);
Map<Integer, List<RunningServiceDetails.Instance>> instances = runningOrcaDetails.getInstances();
List<Integer> versions = new ArrayList<>(instances.keySet());
versions.sort(Integer::compareTo);
Set<Integer> unknownVersions = disableOrcaServerGroups(details, runtimeSettings, orcaService, runningOrcaDetails);
Map<Integer, Integer> executionsByServerGroupVersion = new HashMap<>();
for (Integer version : versions) {
if (unknownVersions.contains(version)) {
executionsByServerGroupVersion.put(version, // we make the assumption that there is non-0 work for the unknown versions
1);
} else {
executionsByServerGroupVersion.put(version, 0);
}
}
ServiceSettings orcaSettings = runtimeSettings.getServiceSettings(orcaService.getService());
cleanupServerGroups(details, orcaService, orcaSettings, executionsByServerGroupVersion, versions);
return unknownVersions;
}
use of com.netflix.spinnaker.halyard.deploy.spinnaker.v1.SpinnakerRuntimeSettings 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);
}
use of com.netflix.spinnaker.halyard.deploy.spinnaker.v1.SpinnakerRuntimeSettings 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);
}
}
use of com.netflix.spinnaker.halyard.deploy.spinnaker.v1.SpinnakerRuntimeSettings 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));
});
}
use of com.netflix.spinnaker.halyard.deploy.spinnaker.v1.SpinnakerRuntimeSettings in project halyard by spinnaker.
the class OrcaService method getProfiles.
@Override
public List<Profile> getProfiles(DeploymentConfiguration deploymentConfiguration, SpinnakerRuntimeSettings endpoints) {
List<Profile> profiles = super.getProfiles(deploymentConfiguration, endpoints);
String filename = "orca.yml";
String path = Paths.get(getConfigOutputPath(), filename).toString();
Profile profile = orcaProfileFactory.getProfile(filename, path, deploymentConfiguration, endpoints);
profiles.add(profile);
return profiles;
}
Aggregations