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    public String getClusterName() {
057        return clusterName;
058    }
059
060    public void setClusterName(String clusterName) {
061        this.clusterName = clusterName;
062    }
063
064    public String[] getAddresses() {
065        if (addressList != null) {
066            return addressList.split(",");
067        }
068        return null;
069    }
070
071    public boolean isIgnoreClusterName() {
072        return clientTransportIgnoreClusterName;
073    }
074
075    public boolean isClusterSniff() {
076        return clientTransportSniff;
077    }
078
079    public String getPingTimeout() {
080        return clientTransportPingTimeout;
081    }
082
083    public String getSamplerInterval() {
084        return clientTransportNodesSamplerInterval;
085    }
086
087    public boolean isEnabled() {
088        return isEnabled;
089    }
090
091    public void setEnabled(boolean isEnabled) {
092        this.isEnabled = isEnabled;
093    }
094
095    @Override
096    public String toString() {
097        if (isEnabled()) {
098            return String.format("EsRemoteConfig(%s, [%s])", getClusterName(), addressList);
099        }
100        return "EsRemoteConfig disabled";
101    }
102}