001/*
002 * (C) Copyright 2014 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *
016 * Contributors:
017 *     bdelbosc
018 */
019
020package org.nuxeo.elasticsearch.config;
021
022import java.io.Serializable;
023
024import org.nuxeo.common.xmap.annotation.XNode;
025import org.nuxeo.common.xmap.annotation.XObject;
026
027/**
028 * XMap descriptor to configure a remote Elasticsearch connection
029 */
030@XObject(value = "elasticSearchRemote")
031public class ElasticSearchRemoteConfig implements Serializable {
032
033    private static final long serialVersionUID = 1L;
034
035    @XNode("@enabled")
036    protected boolean isEnabled = true;
037
038    @XNode("@clusterName")
039    protected String clusterName;
040
041    @XNode("@addressList")
042    protected String addressList;
043
044    @XNode("@clientTransportSniff")
045    protected boolean clientTransportSniff = false;
046
047    @XNode("@clientTransportIgnoreClusterName")
048    protected boolean clientTransportIgnoreClusterName = false;
049
050    @XNode("@clientTransportPingTimeout")
051    protected String clientTransportPingTimeout = "5s";
052
053    @XNode("@clientTransportNodesSamplerInterval")
054    protected String clientTransportNodesSamplerInterval = "5s";
055
056    // @since 8.3
057    @XNode("@useExternalVersion")
058    protected boolean externalVersion = true;
059
060    public String getClusterName() {
061        return clusterName;
062    }
063
064    public void setClusterName(String clusterName) {
065        this.clusterName = clusterName;
066    }
067
068    public String[] getAddresses() {
069        if (addressList != null) {
070            return addressList.split(",");
071        }
072        return null;
073    }
074
075    public boolean isIgnoreClusterName() {
076        return clientTransportIgnoreClusterName;
077    }
078
079    public boolean isClusterSniff() {
080        return clientTransportSniff;
081    }
082
083    public String getPingTimeout() {
084        return clientTransportPingTimeout;
085    }
086
087    public String getSamplerInterval() {
088        return clientTransportNodesSamplerInterval;
089    }
090
091    public boolean isEnabled() {
092        return isEnabled;
093    }
094
095    public void setEnabled(boolean isEnabled) {
096        this.isEnabled = isEnabled;
097    }
098
099    public boolean useExternalVersion() {
100        return externalVersion;
101    }
102
103    @Override
104    public String toString() {
105        if (isEnabled()) {
106            return String.format("EsRemoteConfig(%s, [%s])", getClusterName(), addressList);
107        }
108        return "EsRemoteConfig disabled";
109    }
110}