use of com.netflix.spinnaker.halyard.config.model.v1.node.Halconfig in project halyard by spinnaker.
the class HalconfigParser method cleanLocalFiles.
/**
* Deletes all files in the staging directory that are not referenced in the hal config.
*/
public void cleanLocalFiles(Path stagingDirectoryPath) {
if (!GlobalApplicationOptions.getInstance().isUseRemoteDaemon()) {
return;
}
Halconfig halconfig = getHalconfig();
Set<String> referencedFiles = new HashSet<String>();
Consumer<Node> fileFinder = n -> referencedFiles.addAll(n.localFiles().stream().map(f -> {
try {
f.setAccessible(true);
return (String) f.get(n);
} catch (IllegalAccessException e) {
throw new RuntimeException("Failed to clean staging directory: " + e.getMessage(), e);
} finally {
f.setAccessible(false);
}
}).filter(Objects::nonNull).collect(Collectors.toSet()));
halconfig.recursiveConsume(fileFinder);
Set<String> existingStagingFiles = ((List<File>) FileUtils.listFiles(stagingDirectoryPath.toFile(), TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE)).stream().map(f -> f.getAbsolutePath()).collect(Collectors.toSet());
existingStagingFiles.removeAll(referencedFiles);
try {
for (String f : existingStagingFiles) {
FileUtils.forceDelete(new File(f));
}
} catch (IOException e) {
throw new HalException(FATAL, "Failed to clean staging directory: " + e.getMessage(), e);
}
}
use of com.netflix.spinnaker.halyard.config.model.v1.node.Halconfig in project halyard by spinnaker.
the class ArtifactProviderController method setArtifactProvider.
@RequestMapping(value = "/{providerName:.+}", method = RequestMethod.PUT)
DaemonTask<Halconfig, Void> setArtifactProvider(@PathVariable String deploymentName, @PathVariable String providerName, @RequestParam(required = false, defaultValue = DefaultControllerValues.validate) boolean validate, @RequestParam(required = false, defaultValue = DefaultControllerValues.severity) Severity severity, @RequestBody Object rawArtifactProvider) {
ArtifactProvider provider = objectMapper.convertValue(rawArtifactProvider, Artifacts.translateArtifactProviderType(providerName));
UpdateRequestBuilder builder = new UpdateRequestBuilder();
Path configPath = halconfigDirectoryStructure.getConfigPath(deploymentName);
builder.setStage(() -> provider.stageLocalFiles(configPath));
builder.setUpdate(() -> providerService.setArtifactProvider(deploymentName, provider));
builder.setSeverity(severity);
Supplier<ProblemSet> doValidate = ProblemSet::new;
if (validate) {
doValidate = () -> providerService.validateArtifactProvider(deploymentName, providerName);
}
builder.setValidate(doValidate);
builder.setRevert(() -> halconfigParser.undoChanges());
builder.setSave(() -> halconfigParser.saveConfig());
builder.setClean(() -> halconfigParser.cleanLocalFiles(configPath));
return DaemonTaskHandler.submitTask(builder::build, "Edit the " + providerName + " provider");
}
use of com.netflix.spinnaker.halyard.config.model.v1.node.Halconfig in project halyard by spinnaker.
the class BakeryController method addBaseImage.
@RequestMapping(value = "/defaults/baseImage/", method = RequestMethod.POST)
DaemonTask<Halconfig, Void> addBaseImage(@PathVariable String deploymentName, @PathVariable String providerName, @RequestParam(required = false, defaultValue = DefaultControllerValues.validate) boolean validate, @RequestParam(required = false, defaultValue = DefaultControllerValues.severity) Severity severity, @RequestBody Object rawBaseImage) {
BaseImage baseImage = objectMapper.convertValue(rawBaseImage, Providers.translateBaseImageType(providerName));
UpdateRequestBuilder builder = new UpdateRequestBuilder();
Path configPath = halconfigDirectoryStructure.getConfigPath(deploymentName);
builder.setStage(() -> baseImage.stageLocalFiles(configPath));
builder.setSeverity(severity);
// TODO(lwander): Would be good to indicate when an added base image id conflicts with an existing base image id.
builder.setUpdate(() -> bakeryService.addBaseImage(deploymentName, providerName, baseImage));
Supplier<ProblemSet> doValidate = ProblemSet::new;
if (validate) {
doValidate = () -> bakeryService.validateBaseImage(deploymentName, providerName, baseImage.getBaseImage().getId());
}
builder.setValidate(doValidate);
builder.setRevert(() -> halconfigParser.undoChanges());
builder.setSave(() -> halconfigParser.saveConfig());
builder.setClean(() -> halconfigParser.cleanLocalFiles(configPath));
return DaemonTaskHandler.submitTask(builder::build, "Add " + baseImage.getNodeName() + " base image");
}
use of com.netflix.spinnaker.halyard.config.model.v1.node.Halconfig in project halyard by spinnaker.
the class PersistentStorageController method setPersistentStore.
@RequestMapping(value = "/{persistentStoreType:.+}", method = RequestMethod.PUT)
DaemonTask<Halconfig, Void> setPersistentStore(@PathVariable String deploymentName, @PathVariable String persistentStoreType, @RequestParam(required = false, defaultValue = DefaultControllerValues.validate) boolean validate, @RequestParam(required = false, defaultValue = DefaultControllerValues.severity) Severity severity, @RequestBody Object rawPersistentStore) {
PersistentStore persistentStore = objectMapper.convertValue(rawPersistentStore, PersistentStorage.translatePersistentStoreType(persistentStoreType));
UpdateRequestBuilder builder = new UpdateRequestBuilder();
Path configPath = halconfigDirectoryStructure.getConfigPath(deploymentName);
builder.setStage(() -> persistentStore.stageLocalFiles(configPath));
builder.setUpdate(() -> persistentStorageService.setPersistentStore(deploymentName, persistentStore));
builder.setSeverity(severity);
Supplier<ProblemSet> doValidate = ProblemSet::new;
if (validate) {
doValidate = () -> persistentStorageService.validatePersistentStore(deploymentName, persistentStoreType);
}
builder.setValidate(doValidate);
builder.setRevert(() -> halconfigParser.undoChanges());
builder.setSave(() -> halconfigParser.saveConfig());
builder.setClean(() -> halconfigParser.cleanLocalFiles(configPath));
return DaemonTaskHandler.submitTask(builder::build, "Edit persistent store");
}
use of com.netflix.spinnaker.halyard.config.model.v1.node.Halconfig in project halyard by spinnaker.
the class PubsubController method setPubsub.
@RequestMapping(value = "/{pubsubName:.+}", method = RequestMethod.PUT)
DaemonTask<Halconfig, Void> setPubsub(@PathVariable String deploymentName, @PathVariable String pubsubName, @RequestParam(required = false, defaultValue = DefaultControllerValues.validate) boolean validate, @RequestParam(required = false, defaultValue = DefaultControllerValues.severity) Severity severity, @RequestBody Object rawPubsub) {
Pubsub pubsub = objectMapper.convertValue(rawPubsub, Pubsubs.translatePubsubType(pubsubName));
UpdateRequestBuilder builder = new UpdateRequestBuilder();
Path configPath = halconfigDirectoryStructure.getConfigPath(deploymentName);
builder.setStage(() -> pubsub.stageLocalFiles(configPath));
builder.setUpdate(() -> pubsubService.setPubsub(deploymentName, pubsub));
builder.setSeverity(severity);
Supplier<ProblemSet> doValidate = ProblemSet::new;
if (validate) {
doValidate = () -> pubsubService.validatePubsub(deploymentName, pubsubName);
}
builder.setValidate(doValidate);
builder.setRevert(() -> halconfigParser.undoChanges());
builder.setSave(() -> halconfigParser.saveConfig());
builder.setClean(() -> halconfigParser.cleanLocalFiles(configPath));
return DaemonTaskHandler.submitTask(builder::build, "Edit the " + pubsubName + " pubsub");
}
Aggregations