Search in sources :

Example 1 with PersistentStorage

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();
}
Also used : PersistentStorage(com.netflix.spinnaker.halyard.config.model.v1.node.PersistentStorage) OperationHandler(com.netflix.spinnaker.halyard.cli.services.v1.OperationHandler)

Example 2 with PersistentStorage

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");
}
Also used : Path(java.nio.file.Path) PersistentStorage(com.netflix.spinnaker.halyard.config.model.v1.node.PersistentStorage) UpdateRequestBuilder(com.netflix.spinnaker.halyard.core.DaemonResponse.UpdateRequestBuilder) ProblemSet(com.netflix.spinnaker.halyard.core.problem.v1.ProblemSet) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with PersistentStorage

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.");
    }
}
Also used : PersistentStorage(com.netflix.spinnaker.halyard.config.model.v1.node.PersistentStorage) NodeFilter(com.netflix.spinnaker.halyard.config.model.v1.node.NodeFilter)

Example 4 with PersistentStorage

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);
}
Also used : DeploymentConfiguration(com.netflix.spinnaker.halyard.config.model.v1.node.DeploymentConfiguration)

Example 5 with PersistentStorage

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);
}
Also used : HashMap(java.util.HashMap) HalException(com.netflix.spinnaker.halyard.core.error.v1.HalException) RedisPersistentStore(com.netflix.spinnaker.halyard.config.model.v1.persistentStorage.RedisPersistentStore) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) RedisPersistentStore(com.netflix.spinnaker.halyard.config.model.v1.persistentStorage.RedisPersistentStore) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

PersistentStorage (com.netflix.spinnaker.halyard.config.model.v1.node.PersistentStorage)5 NodeFilter (com.netflix.spinnaker.halyard.config.model.v1.node.NodeFilter)3 OperationHandler (com.netflix.spinnaker.halyard.cli.services.v1.OperationHandler)1 DeploymentConfiguration (com.netflix.spinnaker.halyard.config.model.v1.node.DeploymentConfiguration)1 RedisPersistentStore (com.netflix.spinnaker.halyard.config.model.v1.persistentStorage.RedisPersistentStore)1 UpdateRequestBuilder (com.netflix.spinnaker.halyard.core.DaemonResponse.UpdateRequestBuilder)1 HalException (com.netflix.spinnaker.halyard.core.error.v1.HalException)1 ProblemSet (com.netflix.spinnaker.halyard.core.problem.v1.ProblemSet)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 Path (java.nio.file.Path)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1