server/src/main/java/com/orientechnologies/orient/server/distributed/OModifiableDistributedConfiguration.java
public void setServerOwner(final String iClusterName, final String iServerName) {
    if (iClusterName == null)
      throw new IllegalArgumentException("cluster name cannot be null");

    synchronized (configuration) {
      final ODocument clusters = configuration.field(CLUSTERS);
      ODocument cluster = clusters.field(iClusterName);

      if (cluster == null)
        // CREATE IT
        cluster = createCluster(iClusterName);
      else {
        // CHECK IF THE OWNER IS ALREADY CONFIGURED
        final String owner = cluster.field(OWNER);
        if (owner != null && !iServerName.equalsIgnoreCase(owner))
          throw new ODistributedException("Cannot overwrite ownership of cluster '" + iClusterName + "' to the server '"
              + iServerName + "', because server '" + owner + "' was already configured as owner");
      }

      List<String> serverList = getClusterConfiguration(iClusterName).field(SERVERS);
      if (serverList == null) {
        serverList = initClusterServers(cluster);
      }

      if (!serverList.isEmpty() && serverList.get(0).equals(iServerName))
        // ALREADY OWNER
        return;

      // REMOVE THE NODE IF ANY
      boolean removed = false;
      for (Iterator<String> it = serverList.iterator(); it.hasNext();) {
        if (it.next().equals(iServerName)) {
          it.remove();
          removed = true;
          break;
        }
      }

      if( !removed )
        throw new ODistributedException("Cannot set ownership of cluster '" + iClusterName + "' to the server '"
            + iServerName + "', because the server has no that cluster (sharding)");

      // ADD THE NODE AS FIRST OF THE LIST = MASTER
      serverList.add(0, iServerName);

      incrementVersion();
    }
  }
public void setServerOwner(final String iClusterName, final String iServerName) {
    if (iClusterName == null)
      throw new IllegalArgumentException("cluster name cannot be null");

    synchronized (configuration) {
      final ODocument clusters = configuration.field(CLUSTERS);
      ODocument cluster = clusters.field(iClusterName);

      if (cluster == null)
        // CREATE IT
        cluster = createCluster(iClusterName);
      else {
        // CHECK IF THE OWNER IS ALREADY CONFIGURED
        final String owner = cluster.field(OWNER);
        if (owner != null && !iServerName.equalsIgnoreCase(owner))
          throw new ODistributedException("Cannot overwrite ownership of cluster '" + iClusterName + "' to the server '"
              + iServerName + "', because server '" + owner + "' was already configured as owner");
      }

      List<String> serverList = getClusterConfiguration(iClusterName).field(SERVERS);
      if (serverList == null) {
        serverList = initClusterServers(cluster);
      }

      if (!serverList.isEmpty() && serverList.get(0).equals(iServerName))
        // ALREADY OWNER
        return;

      // REMOVE THE NODE IF ANY
      boolean removed = false;
      for (Iterator<String> it = serverList.iterator(); it.hasNext();) {
        if (it.next().equals(iServerName)) {
          it.remove();
          removed = true;
          break;
        }
      }

      if( !removed )
        throw new ODistributedException("Cannot set ownership of cluster '" + iClusterName + "' to the server '"
            + iServerName + "', because the server has no that cluster (sharding)");

      // ADD THE NODE AS FIRST OF THE LIST = MASTER
      serverList.add(0, iServerName);

      incrementVersion();
    }
  }
Sets the server as owner for the given cluster. The owner server is the first in server list.<br>
NOTE: It must be executed in distributed database lock.

@param iClusterName
Cluster name or *. Does not accept null.