Search in sources :

Example 1 with PersistentStore

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());
    }
}
Also used : ConfigProblemBuilder(com.netflix.spinnaker.halyard.config.problem.v1.ConfigProblemBuilder) ConfigNotFoundException(com.netflix.spinnaker.halyard.config.error.v1.ConfigNotFoundException) OracleBMCSPersistentStore(com.netflix.spinnaker.halyard.config.model.v1.persistentStorage.OracleBMCSPersistentStore) PersistentStore(com.netflix.spinnaker.halyard.config.model.v1.node.PersistentStore) S3PersistentStore(com.netflix.spinnaker.halyard.config.model.v1.persistentStorage.S3PersistentStore) AzsPersistentStore(com.netflix.spinnaker.halyard.config.model.v1.persistentStorage.AzsPersistentStore) GcsPersistentStore(com.netflix.spinnaker.halyard.config.model.v1.persistentStorage.GcsPersistentStore) IllegalConfigException(com.netflix.spinnaker.halyard.config.error.v1.IllegalConfigException) NodeFilter(com.netflix.spinnaker.halyard.config.model.v1.node.NodeFilter)

Example 2 with PersistentStore

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

Example 3 with PersistentStore

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

Example 4 with PersistentStore

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);
}
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

PersistentStore (com.netflix.spinnaker.halyard.config.model.v1.node.PersistentStore)3 OperationHandler (com.netflix.spinnaker.halyard.cli.services.v1.OperationHandler)1 ConfigNotFoundException (com.netflix.spinnaker.halyard.config.error.v1.ConfigNotFoundException)1 IllegalConfigException (com.netflix.spinnaker.halyard.config.error.v1.IllegalConfigException)1 NodeFilter (com.netflix.spinnaker.halyard.config.model.v1.node.NodeFilter)1 AzsPersistentStore (com.netflix.spinnaker.halyard.config.model.v1.persistentStorage.AzsPersistentStore)1 GcsPersistentStore (com.netflix.spinnaker.halyard.config.model.v1.persistentStorage.GcsPersistentStore)1 OracleBMCSPersistentStore (com.netflix.spinnaker.halyard.config.model.v1.persistentStorage.OracleBMCSPersistentStore)1 RedisPersistentStore (com.netflix.spinnaker.halyard.config.model.v1.persistentStorage.RedisPersistentStore)1 S3PersistentStore (com.netflix.spinnaker.halyard.config.model.v1.persistentStorage.S3PersistentStore)1 ConfigProblemBuilder (com.netflix.spinnaker.halyard.config.problem.v1.ConfigProblemBuilder)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