001/*
002 * (C) Copyright 2019 Nuxeo (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 *     Florent Guillaume
018 */
019package org.nuxeo.runtime.cluster;
020
021import static org.apache.commons.lang3.StringUtils.isBlank;
022
023import org.nuxeo.common.xmap.annotation.XNode;
024import org.nuxeo.common.xmap.annotation.XObject;
025import org.nuxeo.runtime.model.Descriptor;
026
027/**
028 * Descriptor of a cluster node.
029 *
030 * @since 11.1
031 */
032@XObject("clusterNode")
033public class ClusterNodeDescriptor implements Descriptor {
034
035    @XNode("@id")
036    // we don't call this field 'id' to avoid confusion with the getId() method
037    public String name;
038
039    @XNode("@enabled")
040    public String enabled;
041
042    @Override
043    public String getId() {
044        return UNIQUE_DESCRIPTOR_ID;
045    }
046
047    /**
048     * Gets the name (id) of the cluster node.
049     */
050    public String getName() {
051        return name;
052    }
053
054    /**
055     * Checks if cluster is enabled for this node. May return {@code null} if there is no configuration.
056     */
057    public Boolean getEnabled() {
058        return isBlank(enabled) ? null : Boolean.valueOf(enabled);
059    }
060
061    /**
062     * Empty constructor.
063     */
064    public ClusterNodeDescriptor() {
065    }
066
067    @Override
068    public ClusterNodeDescriptor merge(Descriptor o) {
069        ClusterNodeDescriptor other = (ClusterNodeDescriptor) o;
070        ClusterNodeDescriptor merged = new ClusterNodeDescriptor();
071        merged.name = other.name == null ? name : other.name;
072        merged.enabled = isBlank(other.enabled) ? enabled : other.enabled;
073        return merged;
074    }
075
076}