package enmasse.storage.controller.admin;

import com.fasterxml.jackson.databind.JsonNode;
import enmasse.storage.controller.model.FlavorConfig;
import enmasse.storage.controller.model.parser.FlavorConfigParser;

import java.io.IOException;
import java.util.Collections;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author Ulf Lilleengen
 */
public class FlavorManager implements ConfigManager, FlavorRepository {
    private volatile Map<String, FlavorConfig> flavorMap = Collections.emptyMap();
    private final FlavorConfigParser parser = new FlavorConfigParser();

    @Override
    public FlavorConfig getFlavor(String flavorName) {
        FlavorConfig flavor = flavorMap.get(flavorName);
        if (flavor == null) {
            String flavors = flavorMap.keySet().stream().collect(Collectors.joining(","));
            throw new IllegalArgumentException(String.format("No flavor with name '%s' exists, have [%s]", flavorName, flavors));
        }
        return flavor;
    }

    @Override
    public FlavorConfig getDefaultFlavor() {
        return new FlavorConfig.Builder().build();
    }

    @Override
    public void configUpdated(JsonNode jsonConfig) throws IOException {
        configUpdated(parser.parse(jsonConfig));
    }

    public void configUpdated(Map<String, FlavorConfig> flavorMap) {
        this.flavorMap = flavorMap;
    }
}

@@ -286,16 +286,81 @@
 il.Map;%0A
+import java.util.logging.Level;%0Aimport java.util.logging.Logger;%0A
 import j
@@ -494,16 +494,103 @@
 itory %7B%0A
+    private static final Logger log = Logger.getLogger(FlavorManager.class.getName());%0A
     priv
@@ -1518,16 +1518,249 @@
 vorMap;%0A
+        if (log.isLoggable(Level.INFO)) %7B%0A            String flavors = flavorMap.keySet().stream().collect(Collectors.joining(%22,%22));%0A            log.log(Level.INFO, String.format(%22Got new set of flavors: %5B%25s%5D%22, flavors));%0A        %7D%0A%0A
     %7D%0A%7D%0A

Add logging when flavors are updated