# Change log format early 
{{- if .Values.payara.uniformLogFormatter }}
set-log-attributes --target server-config com.sun.enterprise.server.logging.GFFileHandler.formatter='com.sun.enterprise.server.logging.UniformLogFormatter'
set-log-attributes --target server-config java.util.logging.ConsoleHandler.formatter='com.sun.enterprise.server.logging.UniformLogFormatter'
set-log-attributes --target {{ .Values.payara.config }} com.sun.enterprise.server.logging.GFFileHandler.formatter='com.sun.enterprise.server.logging.UniformLogFormatter'
set-log-attributes --target {{ .Values.payara.config }} java.util.logging.ConsoleHandler.formatter='com.sun.enterprise.server.logging.UniformLogFormatter'
{{ end }}

#Set Failed to retrieve metric logs off
{{- if .Values.payara.disableMetricsServiceLogs }}
set-log-levels --target={{ .Values.payara.config }} fish.payara.microprofile.metrics.MetricsService=OFF
{{ end }}

# disable deploy-xml-validation
{{- if .Values.payara.disableXmlValidation }}
set configs.config.server-config.admin-service.das-config.deploy-xml-validation=none
set configs.config.{{ .Values.payara.config }}.admin-service.das-config.deploy-xml-validation=none
{{ end }}

set {{ .Values.payara.config }}.network-config.protocols.protocol.https-internal.ssl.cert-nickname=internal
set configs.config.{{ .Values.payara.config }}.network-config.protocols.protocol.https-internal.http.http2-enabled=false
set resources.jdbc-connection-pool.hopsworksPool.property.user={{ .Values.variables.hopsworks_mysql_user }}
set resources.jdbc-connection-pool.hopsworksPool.property.password=${ENV=HOPSWORKS_MYSQL_PASSWORD}
set resources.jdbc-connection-pool.hopsworksPool.property.url=jdbc:mysql://{{ include "hopsworks.consul.mysqlAddress" . }}
set resources.jdbc-connection-pool.ejbTimerPool.property.user={{ .Values.variables.hopsworks_mysql_user }}
set resources.jdbc-connection-pool.ejbTimerPool.property.password=${ENV=HOPSWORKS_MYSQL_PASSWORD}
set resources.jdbc-connection-pool.ejbTimerPool.property.url=jdbc:mysql://{{ include "hopsworks.consul.mysqlAddress" . }}/glassfish_timers
set configs.config.{{ .Values.payara.config }}.thread-pools.thread-pool.http-thread-pool.max-thread-pool-size={{ .Values.payara.httpthreadpool.maxthreadpoolsize }}
set configs.config.{{ .Values.payara.config }}.thread-pools.thread-pool.http-thread-pool.min-thread-pool-size={{ .Values.payara.httpthreadpool.minthreadpoolsize }}
set configs.config.{{ .Values.payara.config }}.thread-pools.thread-pool.http-thread-pool.idle-thread-timeout-seconds={{ .Values.payara.httpthreadpool.idletimeout }}
set configs.config.{{ .Values.payara.config }}.thread-pools.thread-pool.http-thread-pool.max-queue-size={{ .Values.payara.httpthreadpool.maxqueuesize }}
set {{ .Values.payara.config }}.network-config.network-listeners.network-listener.http-listener-1.enabled={{ .Values.payara.httpListener1Enabled }}
set resources.managed-executor-service.concurrent/jupyterExecutorService.thread-priority={{ .Values.payara.executorService.jupyter.threadPriority }}
set resources.managed-executor-service.concurrent/jupyterExecutorService.core-pool-size={{ .Values.payara.executorService.jupyter.corePoolSize }}
set resources.managed-executor-service.concurrent/jupyterExecutorService.maximum-pool-size={{ .Values.payara.executorService.jupyter.maximumPoolSize }}
set resources.managed-executor-service.concurrent/jupyterExecutorService.task-queue-capacity={{ .Values.payara.executorService.jupyter.taskQueueCapacity }}
set resources.mail-resource.mail/BBCMail.from={{ .Values.payara.mail.from }}
set resources.mail-resource.mail/BBCMail.host={{ .Values.payara.mail.smtp }}
set resources.mail-resource.mail/BBCMail.password=${ENV=MAIL_PASSWORD}
set resources.mail-resource.mail/BBCMail.user={{ .Values.payara.mail.email }}
set resources.mail-resource.mail/BBCMail.property.mail-smtp-socketFactory-port={{ .Values.payara.mail.smtp_ssl_port }}
set resources.mail-resource.mail/BBCMail.property.mail-smtp-port={{ .Values.payara.mail.smtp_port }}
# Enable debug
set {{ .Values.payara.config }}.java-config.debug-enabled={{ .Values.payara.debug }}

create-jvm-options --target={{ .Values.payara.config }} -- "-DjvmRoute=$\{com.sun.aas.instanceName\}"

# Keep this bellow to not fail other commands
# LDAP configuration 
set resources.external-jndi-resource.ldap/LdapResource.enabled={{ or .Values.payara.ldap.enabled .Values.payara.kerberos.enabled }}
set resources.external-jndi-resource.ldap/LdapResource.property.java\.naming\.provider\.url={{ .Values.payara.ldap.property.provider_url }}
set resources.external-jndi-resource.ldap/LdapResource.property.java\.naming\.security\.authentication={{ .Values.payara.ldap.property.security.authentication }}
set 'resources.external-jndi-resource.ldap/LdapResource.property.java\.naming\.security\.principal={{ .Values.payara.ldap.property.security.principal }}'
set 'resources.external-jndi-resource.ldap/LdapResource.property.java\.naming\.security\.credentials=${ENV=LDAP_SECURITY_CREDENTIALS}'
set resources.external-jndi-resource.ldap/LdapResource.property.java\.naming\.referral={{ .Values.payara.ldap.property.referral }}
set resources.external-jndi-resource.ldap/LdapResource.factory-class={{ .Values.payara.ldap.factory_class }}
set 'resources.external-jndi-resource.ldap/LdapResource.jndi-lookup-name={{ .Values.payara.ldap.jndilookupname }}'
set resources.external-jndi-resource.ldap/LdapResource.res-type={{ .Values.payara.ldap.res_type }}
set resources.external-jndi-resource.ldap/LdapResource.property.{{ .Values.variables.ldap_attr_binary | replace "." "\\." }}={{ .Values.payara.ldap.property.attributes_binary }}
{{- range $additional_props := .Values.payara.ldap.property.additional_props }}
set 'resources.external-jndi-resource.ldap/LdapResource.property.{{ $additional_props.key }}={{ $additional_props.value }}'
{{- end }}