{{- if (empty .Values.configMapOverrideName) -}}
apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ .Release.Name }}-config
data:
  janusgraph.properties: |-
    gremlin.graph=org.janusgraph.core.JanusGraphFactory

    {{- $eshostname := (index .Values.properties "index.search.hostname") | default (printf "%s-elasticsearch-client" .Release.Name | trunc 63 | trimSuffix "-")}}
    {{- range $key, $val := .Values.properties }}
    {{- if ne $key "index.search.hostname" }}
    {{ $key }}={{ $val }}
    {{- end -}}
    {{ end }}

    {{- if eq (index .Values.properties "index.search.backend") "elasticsearch" "es"}}
    index.search.hostname={{ $eshostname }}
    {{- end }}
  gremlin-server.yaml: |-
    host: 0.0.0.0
    port: 8182
    scriptEvaluationTimeout: 30000
    channelizer: org.apache.tinkerpop.gremlin.server.channel.WsAndHttpChannelizer
    graphs: {
      graph: conf/gremlin-server/janusgraph.properties
    }
    plugins:
      - janusgraph.imports
    scriptEngines: {
      gremlin-groovy: {
        imports: [java.lang.Math],
        staticImports: [java.lang.Math.PI],
        scripts: [scripts/empty-sample.groovy]}}
    serializers:
      - { className: org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV1d0, config: { ioRegistries: [org.janusgraph.graphdb.tinkerpop.JanusGraphIoRegistry] }}
      - { className: org.apache.tinkerpop.gremlin.driver.ser.GryoLiteMessageSerializerV1d0, config: {ioRegistries: [org.janusgraph.graphdb.tinkerpop.JanusGraphIoRegistry] }}
      - { className: org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV1d0, config: { serializeResultToString: true }}
      - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerGremlinV1d0, config: { ioRegistries: [org.janusgraph.graphdb.tinkerpop.JanusGraphIoRegistryV1d0] }}
      - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerGremlinV2d0, config: { ioRegistries: [org.janusgraph.graphdb.tinkerpop.JanusGraphIoRegistry] }}
      - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV1d0, config: { ioRegistries: [org.janusgraph.graphdb.tinkerpop.JanusGraphIoRegistryV1d0] }}
    processors:
      - { className: org.apache.tinkerpop.gremlin.server.op.session.SessionOpProcessor, config: { sessionTimeout: 28800000 }}
      - { className: org.apache.tinkerpop.gremlin.server.op.traversal.TraversalOpProcessor, config: { cacheExpirationTime: 600000, cacheMaxSize: 1000 }}
    metrics: {
      consoleReporter: {enabled: true, interval: 180000},
      csvReporter: {enabled: true, interval: 180000, fileName: /tmp/gremlin-server-metrics.csv},
      jmxReporter: {enabled: true},
      slf4jReporter: {enabled: true, interval: 180000},
      gangliaReporter: {enabled: false, interval: 180000, addressingMode: MULTICAST},
      graphiteReporter: {enabled: false, interval: 180000}}
    maxInitialLineLength: 4096
    maxHeaderSize: 8192
    maxChunkSize: 8192
    maxContentLength: 65536
    maxAccumulationBufferComponents: 1024
    resultIterationBatchSize: 64
    writeBufferLowWaterMark: 32768
    writeBufferHighWaterMark: 65536
    {{- end -}}
