Search in sources :

Example 1 with RedisPersistentStore

use of com.netflix.spinnaker.halyard.config.model.v1.persistentStorage.RedisPersistentStore 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

RedisPersistentStore (com.netflix.spinnaker.halyard.config.model.v1.persistentStorage.RedisPersistentStore)1 HalException (com.netflix.spinnaker.halyard.core.error.v1.HalException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1