Load/reload cluster nodes and order the nodes by its priority.
172700
protected void reloadNodes() {

        Hello hello = HelloParser.parse(disqueConnection.sync().hello());
        Collections.sort(hello.nodes, new Comparator<PrioritizedDisqueNode>() {
            @Override
            public int compare(PrioritizedDisqueNode o1, PrioritizedDisqueNode o2) {

                if (o1.priority == o2.priority) {
                    return o1.disqueNode.getPort() - o2.disqueNode.getPort();
                }
                return o1.priority - o2.priority;
            }
        });
        this.nodes.clear();

        for (PrioritizedDisqueNode node : hello.nodes) {
            if (isFiltered(node)) {
                continue;
            }

            this.nodes.add(node.disqueNode);
        }
    }
301837
def _start_nodes_sequentially(self, nodes):
        
        started_nodes = set()
        for node in copy(nodes):
            started = self._start_node(node)
            if started:
                started_nodes.add(node)
            # checkpoint cluster state
            self.repository.save_or_update(self)
        return started_nodes
430519
private ClusterDasVmSettings createClusterDasVmSettings(String restartPriority) {
        ClusterDasVmSettings clusterDasVmSettings = new ClusterDasVmSettings();
        clusterDasVmSettings.setRestartPriority(restartPriority);
        return clusterDasVmSettings;
    }
1332875
@Override
    public void reloadOwnedPartitions() {
        final IPartitionService partitionService = nodeEngine.getPartitionService();
        for (; ; ) {
            final PartitionIdSet expected = ownedPartitions.get();
            final Collection<Integer> partitions = partitionService.getMemberPartitions(nodeEngine.getThisAddress());
            final PartitionIdSet newSet = immutablePartitionIdSet(partitionService.getPartitionCount(), partitions);
            if (ownedPartitions.compareAndSet(expected, newSet)) {
                return;
            }
        }
    }
94019
def execute(self):
        """"""
        cluster_name = self.params.cluster
        creator = make_creator(self.params.config,
                               storage_path=self.params.storage)
        try:
            cluster = creator.load_cluster(cluster_name)
        except (ClusterNotFound, ConfigurationError) as e:
            log.error("Cannot load cluster `%s`: %s", cluster_name, e)
            return os.EX_NOINPUT
        print("Resuming cluster `%s` ..." % cluster_name)
        cluster.resume()
874142
private synchronized void reloadLocations() {
    map.clear();
    for (HadoopServer location : ServerRegistry.getInstance().getServers())
      map.put(location, new DFSLocation(provider, location));
  }
201717
def refresh_datasources(self, refreshAll=True):
        """"""
        session = db.session()
        DruidCluster = ConnectorRegistry.sources['druid'].cluster_class
        for cluster in session.query(DruidCluster).all():
            cluster_name = cluster.cluster_name
            valid_cluster = True
            try:
                cluster.refresh_datasources(refreshAll=refreshAll)
            except Exception as e:
                valid_cluster = False
                flash(
                    "Error while processing cluster '{}'\n{}".format(
                        cluster_name, utils.error_msg_from_exception(e)),
                    'danger')
                logging.exception(e)
                pass
            if valid_cluster:
                cluster.metadata_last_refreshed = datetime.now()
                flash(
                    _('Refreshed metadata from cluster [{}]').format(
                        cluster.cluster_name),
                    'info')
        session.commit()
        return redirect('/druiddatasourcemodelview/list/')
1097160
def start_cluster_server(self, num_gpus=1, rdma=False):
    """"""
    return TFNode.start_cluster_server(self, num_gpus, rdma)
165858
def _put_cluster(self, dic, params=None):
    """"""
    cluster = self._put('', ApiCluster, data=dic, params=params)
    self._update(cluster)
    return self
427291
protected void updateClusterCenters() {
		// compute the new centers of each cluster
		for (int i = 0; i < clusters.size; i++) {
			double mc = memberCount.get(i);
			double[] w = workClusters.get(i);
			double[] c = clusters.get(i);

			for (int j = 0; j < w.length; j++) {
				c[j] = w[j] / mc;
			}
		}
	}
1033894
def reorder_nodes_before_add_or_move(self, pos, newpos, newdepth, target,
                                         siblings, oldpath=None,
                                         movebranch=False):
        
        if (
                (pos == 'last-sibling') or
                (pos == 'right' and target == target.get_last_sibling())
        ):
            # easy, the last node
            last = target.get_last_sibling()
            newpath = last._inc_path()
            if movebranch:
                self.stmts.append(
                    self.get_sql_newpath_in_branches(oldpath, newpath))
        else:
            # do the UPDATE dance

            if newpos is None:
                siblings = target.get_siblings()
                siblings = {'left': siblings.filter(path__gte=target.path),
                            'right': siblings.filter(path__gt=target.path),
                            'first-sibling': siblings}[pos]
                basenum = target._get_lastpos_in_path()
                newpos = {'first-sibling': 1,
                          'left': basenum,
                          'right': basenum + 1}[pos]

            newpath = self.node_cls._get_path(target.path, newdepth, newpos)

            # If the move is amongst siblings and is to the left and there
            # are siblings to the right of its new position then to be on
            # the safe side we temporarily dump it on the end of the list
            tempnewpath = None
            if movebranch and len(oldpath) == len(newpath):
                parentoldpath = self.node_cls._get_basepath(
                    oldpath,
                    int(len(oldpath) / self.node_cls.steplen) - 1
                )
                parentnewpath = self.node_cls._get_basepath(
                    newpath, newdepth - 1)
                if (
                    parentoldpath == parentnewpath and
                    siblings and
                    newpath < oldpath
                ):
                    last = target.get_last_sibling()
                    basenum = last._get_lastpos_in_path()
                    tempnewpath = self.node_cls._get_path(
                        newpath, newdepth, basenum + 2)
                    self.stmts.append(
                        self.get_sql_newpath_in_branches(
                            oldpath, tempnewpath))

            # Optimisation to only move siblings which need moving
            # (i.e. if we've got holes, allow them to compress)
            movesiblings = []
            priorpath = newpath
            for node in siblings:
                # If the path of the node is already greater than the path
                # of the previous node it doesn't need shifting
                if node.path > priorpath:
                    break
                # It does need shifting, so add to the list
                movesiblings.append(node)
                # Calculate the path that it would be moved to, as that's
                # the next "priorpath"
                priorpath = node._inc_path()
            movesiblings.reverse()

            for node in movesiblings:
                # moving the siblings (and their branches) at the right of the
                # related position one step to the right
                sql, vals = self.get_sql_newpath_in_branches(
                    node.path, node._inc_path())
                self.stmts.append((sql, vals))

                if movebranch:
                    if oldpath.startswith(node.path):
                        # if moving to a parent, update oldpath since we just
                        # increased the path of the entire branch
                        oldpath = vals[0] + oldpath[len(vals[0]):]
                    if target.path.startswith(node.path):
                        # and if we moved the target, update the object
                        # django made for us, since the update won't do it
                        # maybe useful in loops
                        target.path = vals[0] + target.path[len(vals[0]):]
            if movebranch:
                # node to move
                if tempnewpath:
                    self.stmts.append(
                        self.get_sql_newpath_in_branches(
                            tempnewpath, newpath))
                else:
                    self.stmts.append(
                        self.get_sql_newpath_in_branches(
                            oldpath, newpath))
        return oldpath, newpath
1144813
def _dfs_postorder(node, visited):
    """"""
    if node.lo is not None:
        yield from _dfs_postorder(node.lo, visited)
    if node.hi is not None:
        yield from _dfs_postorder(node.hi, visited)
    if node not in visited:
        visited.add(node)
        yield node
1097628
function loadMore(batches, alertGroups, nextRequests, triagedRequests,
    triagedMaxStartRevision, started) {
  const minStartRevision = tr.b.math.Statistics.min(
      alertGroups, group => tr.b.math.Statistics.min(
          group.alerts, a => a.startRevision));

  if (!triagedMaxStartRevision ||
      (minStartRevision < triagedMaxStartRevision)) {
    for (const request of triagedRequests) {
      request.min_start_revision = minStartRevision;
      if (triagedMaxStartRevision) {
        request.max_start_revision = triagedMaxStartRevision;
      }
      batches.add(wrapRequest(request));
    }
  }

  for (const next of nextRequests) {
    // Always chase down cursors for triaged alerts.
    // Limit the number of alertGroups displayed to prevent OOM.
    if (next.bug_id === '*' ||
        (alertGroups.length < ENOUGH_GROUPS &&
        ((performance.now() - started) < ENOUGH_LOADING_MS))) {
      batches.add(wrapRequest(next));
    }
  }

  return minStartRevision;
}
554064
def flushall(args):
    
    cluster = Cluster.from_node(ClusterNode.from_uri(args.cluster))
    for node in cluster.masters:
        node.flushall()
777345
public synchronized void refreshNodes() throws IOException {
    hostsReader.refresh();
    LOG.info("After refresh Included hosts: " +
        hostsReader.getHostNames().size() +
        " Excluded hosts: " + hostsReader.getExcludedHosts().size());
    Set<String> newHosts = hostsReader.getHostNames();
    Set<String> newExcludes = hostsReader.getExcludedHosts();
    Set<ClusterNode> hostsToExclude = new HashSet<ClusterNode>();
    for (ClusterNode tmpNode : nameToNode.values()) {
      String host = tmpNode.getHost();
      // Check if not included or explicitly excluded.
      if (!newHosts.contains(host) || newExcludes.contains(host)) {
        hostsToExclude.add(tmpNode);
      }
    }
    for (ClusterNode node: hostsToExclude) {
      synchronized (node) {
        for (Map.Entry<ResourceType, RunnableIndices> entry :
          typeToIndices.entrySet()) {
          ResourceType type = entry.getKey();
          RunnableIndices r = entry.getValue();
          if (r.hasRunnable(node)) {
            LOG.info("Node " + node.getName() + " is no longer " +
              type + " runnable because it is excluded");
            r.deleteRunnable(node);
          }
        }
      }
    }
  }
142736
public final void reloadAll() {
        final List<String> list = new ArrayList<>();
        for (final RootDocument mongo : repositoryManager
                .getRootDocumentRepository().findAll()) {
            list.add(mongo.getDbName());
        }
        reset();
        for (final String dbname : list) {
            loadDocument(dbname);
        }
    }
135788
def prioSort(elements):
    """"""
    # Randomize the services before sorting so that equal priority
    # elements are load-balanced.
    random.shuffle(elements)

    sorted_elems = sorted(elements, key=getPriority)
    return sorted_elems