use of com.netflix.spinnaker.halyard.config.model.v1.node.PersistentStore in project halyard by spinnaker.
the class PersistentStorageService method getPersistentStore.
public PersistentStore getPersistentStore(String deploymentName, String persistentStoreType) {
NodeFilter filter = new NodeFilter().setDeployment(deploymentName).setPersistentStore(persistentStoreType);
List<PersistentStore> matching = lookupService.getMatchingNodesOfType(filter, PersistentStore.class);
switch(matching.size()) {
case 0:
throw new ConfigNotFoundException(new ConfigProblemBuilder(Problem.Severity.FATAL, "No persistent store with name \"" + persistentStoreType + "\" could be found").setRemediation("Create a new persistent store with name \"" + persistentStoreType + "\"").build());
case 1:
return matching.get(0);
default:
throw new IllegalConfigException(new ConfigProblemBuilder(Problem.Severity.FATAL, "More than one persistent store with name \"" + persistentStoreType + "\" found").setRemediation("Manually delete or rename duplicate persistent stores with name \"" + persistentStoreType + "\" in your halconfig file").build());
}
}
use of com.netflix.spinnaker.halyard.config.model.v1.node.PersistentStore 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.PersistentStore in project halyard by spinnaker.
the class AbstractPersistentStoreEditCommand method executeThis.
@Override
protected void executeThis() {
String persistentStoreType = getPersistentStoreType();
String currentDeployment = getCurrentDeployment();
// Disable validation here, since we don't want an illegal config to prevent us from fixing it.
PersistentStore persistentStore = new OperationHandler<PersistentStore>().setFailureMesssage("Failed to get persistent store \"" + persistentStoreType + "\".").setOperation(Daemon.getPersistentStore(currentDeployment, persistentStoreType, false)).get();
int originalHash = persistentStore.hashCode();
persistentStore = editPersistentStore((T) persistentStore);
if (originalHash == persistentStore.hashCode()) {
AnsiUi.failure("No changes supplied.");
return;
}
new OperationHandler<Void>().setFailureMesssage("Failed to edit persistent store \"" + persistentStoreType + "\".").setSuccessMessage("Successfully edited persistent store \"" + persistentStoreType + "\".").setOperation(Daemon.setPersistentStore(currentDeployment, persistentStoreType, !noValidate, persistentStore)).get();
}
use of com.netflix.spinnaker.halyard.config.model.v1.node.PersistentStore 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