use of com.netflix.spinnaker.halyard.config.model.v1.node.PersistentStorage in project halyard by spinnaker.
the class EditPersistentStorageCommand method executeThis.
@Override
protected void executeThis() {
String currentDeployment = getCurrentDeployment();
// Disable validation here, since we don't want an illegal config to prevent us from fixing it.
PersistentStorage persistentStorage = new OperationHandler<PersistentStorage>().setFailureMesssage("Failed to get persistent storage.").setOperation(Daemon.getPersistentStorage(currentDeployment, false)).get();
int originalHash = persistentStorage.hashCode();
persistentStorage.setPersistentStoreType(isSet(type) ? type : persistentStorage.getPersistentStoreType());
if (originalHash == persistentStorage.hashCode()) {
AnsiUi.failure("No changes supplied.");
return;
}
new OperationHandler<Void>().setOperation(Daemon.setPersistentStorage(currentDeployment, !noValidate, persistentStorage)).setFailureMesssage("Failed to edit persistent storage.").setSuccessMessage("Successfully edited persistent storage.").get();
}
use of com.netflix.spinnaker.halyard.config.model.v1.node.PersistentStorage in project halyard by spinnaker.
the class PersistentStorageController method setPersistentStorage.
@RequestMapping(value = "/", method = RequestMethod.PUT)
DaemonTask<Halconfig, Void> setPersistentStorage(@PathVariable String deploymentName, @RequestParam(required = false, defaultValue = DefaultControllerValues.validate) boolean validate, @RequestParam(required = false, defaultValue = DefaultControllerValues.severity) Severity severity, @RequestBody Object rawPersistentStorage) {
PersistentStorage persistentStorage = objectMapper.convertValue(rawPersistentStorage, PersistentStorage.class);
UpdateRequestBuilder builder = new UpdateRequestBuilder();
Path configPath = halconfigDirectoryStructure.getConfigPath(deploymentName);
builder.setStage(() -> persistentStorage.stageLocalFiles(configPath));
builder.setUpdate(() -> persistentStorageService.setPersistentStorage(deploymentName, persistentStorage));
builder.setSeverity(severity);
Supplier<ProblemSet> doValidate = ProblemSet::new;
if (validate) {
doValidate = () -> persistentStorageService.validatePersistentStorage(deploymentName);
}
builder.setValidate(doValidate);
builder.setRevert(() -> halconfigParser.undoChanges());
builder.setSave(() -> halconfigParser.saveConfig());
builder.setClean(() -> halconfigParser.cleanLocalFiles(configPath));
return DaemonTaskHandler.submitTask(builder::build, "Edit persistent storage settings");
}
use of com.netflix.spinnaker.halyard.config.model.v1.node.PersistentStorage in project halyard by spinnaker.
the class PersistentStorageService method getPersistentStorage.
public PersistentStorage getPersistentStorage(String deploymentName) {
NodeFilter filter = new NodeFilter().setDeployment(deploymentName).setPersistentStorage();
List<PersistentStorage> matching = lookupService.getMatchingNodesOfType(filter, PersistentStorage.class);
switch(matching.size()) {
case 0:
PersistentStorage persistentStorage = new PersistentStorage();
setPersistentStorage(deploymentName, persistentStorage);
return persistentStorage;
case 1:
return matching.get(0);
default:
throw new RuntimeException("It shouldn't be possible to have multiple persistentStorage nodes. This is a bug.");
}
}
use of com.netflix.spinnaker.halyard.config.model.v1.node.PersistentStorage in project halyard by spinnaker.
the class PersistentStorageService method setPersistentStorage.
public void setPersistentStorage(String deploymentName, PersistentStorage newPersistentStorage) {
DeploymentConfiguration deploymentConfiguration = deploymentService.getDeploymentConfiguration(deploymentName);
deploymentConfiguration.setPersistentStorage(newPersistentStorage);
}
use of com.netflix.spinnaker.halyard.config.model.v1.node.PersistentStorage in project halyard by spinnaker.
the class Front50ProfileFactory method setProfile.
@Override
public void setProfile(Profile profile, DeploymentConfiguration deploymentConfiguration, SpinnakerRuntimeSettings endpoints) {
PersistentStorage persistentStorage = deploymentConfiguration.getPersistentStorage();
if (persistentStorage.getPersistentStoreType() == null) {
throw new HalException(Problem.Severity.FATAL, "No persistent storage type was configured.");
}
List<String> files = backupRequiredFiles(persistentStorage, deploymentConfiguration.getName());
Map<String, Map<String, Object>> persistentStorageMap = new HashMap<>();
NodeIterator children = persistentStorage.getChildren();
Node child = children.getNext();
while (child != null) {
if (child instanceof PersistentStore) {
PersistentStore persistentStore = (PersistentStore) child;
URI connectionUri = null;
if (persistentStore instanceof RedisPersistentStore) {
try {
connectionUri = new URI(endpoints.getServices().getRedis().getBaseUrl());
} catch (URISyntaxException e) {
throw new RuntimeException("Malformed redis URL, this is a bug.");
}
}
persistentStore.setConnectionInfo(connectionUri);
PersistentStore.PersistentStoreType persistentStoreType = persistentStore.persistentStoreType();
Map persistentStoreMap = objectMapper.convertValue(persistentStore, Map.class);
persistentStoreMap.put("enabled", persistentStoreType.equals(persistentStorage.getPersistentStoreType()));
persistentStorageMap.put(persistentStoreType.getId(), persistentStoreMap);
}
child = children.getNext();
}
Map<String, Object> spinnakerObjectMap = new HashMap<>();
spinnakerObjectMap.put("spinnaker", persistentStorageMap);
super.setProfile(profile, deploymentConfiguration, endpoints);
profile.appendContents(yamlToString(spinnakerObjectMap)).appendContents(profile.getBaseContents()).setRequiredFiles(files);
}
Aggregations