package com.tinkerpop.gremlin.server;

import com.tinkerpop.gremlin.structure.Graph;
import com.tinkerpop.gremlin.structure.util.GraphFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.script.Bindings;
import javax.script.SimpleBindings;
import java.util.HashMap;
import java.util.Map;

/**
 * Traverser of {@link Graph} instances configured for the server to be passed to sessionless bindings. The
 * {@link Graph} instances are read from the {@link Settings} for Gremlin Server as defined in the configuration
 * file.
 */
public class Graphs {
    private static final Logger logger = LoggerFactory.getLogger(GremlinServer.class);

    private final Map<String, Graph> graphs = new HashMap<>();

    /**
     * Create a new instance using the {@link Settings} from Gremlin Server.
     */
    public Graphs(final Settings settings) {
        settings.graphs.entrySet().forEach(e -> {
            try {
                final Graph newGraph = GraphFactory.open(e.getValue());
                graphs.put(e.getKey(), newGraph);
                logger.info("Graph [{}] was successfully configured via [{}].", e.getKey(), e.getValue());
            } catch (RuntimeException re) {
                logger.warn("Graph [{}] configured at [{}] could not be instantiated and will not be available in Gremlin Server.  GraphFactory message: {}",
                        e.getKey(), e.getValue(), re.getMessage());
                if (re.getCause() != null) logger.debug("GraphFactory exception", re.getCause());
            }
        });
    }

    /**
     * Get a list of the {@link Graph} instances and their binding names as defined in the Gremlin Server
     * configuration file.  This {@link Map} is immutable.
     *
     * @return a {@link Map} where the key is the name of the {@link Graph} and the value is the {@link Graph} itself
     */
    public Map<String, Graph> getGraphs() {
        return graphs;
    }

    /**
     * Get the graphs list as a set of bindings.
     */
    public Bindings getGraphsAsBindings() {
        final Bindings bindings = new SimpleBindings();
        graphs.forEach(bindings::put);
        return bindings;
    }

    /**
     * Rollback transactions across all {@link com.tinkerpop.gremlin.structure.Graph} objects.
     */
    public void rollbackAll() {
        graphs.entrySet().forEach(e -> {
            final Graph g = e.getValue();
            if (g.features().graph().supportsTransactions())
                g.tx().rollback();
        });
    }

    /**
     * Commit transactions across all {@link com.tinkerpop.gremlin.structure.Graph} objects.
     */
    public void commitAll() {
        graphs.entrySet().forEach(e -> {
            final Graph g = e.getValue();
            if (g.features().graph().supportsTransactions())
                g.tx().commit();
        });
    }
}
@@ -1228,24 +1228,38 @@
 er.warn(
+String.format(
 %22Graph %5B
 %7B%7D%5D conf
@@ -1250,18 +1250,18 @@
 %22Graph %5B
-%7B%7D
+%25s
 %5D config
@@ -1269,18 +1269,18 @@
 red at %5B
-%7B%7D
+%25s
 %5D could 
@@ -1367,18 +1367,18 @@
 essage: 
-%7B%7D
+%25s
 %22,%0A     
@@ -1434,24 +1434,29 @@
 etMessage())
+, re)
 ;%0A          

Improve logging around graph instantion failure in Gremlin Server.