Check that all nodes in the new cluster have a corresponding entry in
storeRepository and innerStores. add a NodeStore if not present, is
needed as with rebalancing we can add new nodes on the fly.
776569
private void checkAndAddNodeStore() {
        for(Node node: metadata.getCluster().getNodes()) {
            if(!routedStore.getInnerStores().containsKey(node.getId())) {
                if(!storeRepository.hasNodeStore(getName(), node.getId())) {
                    storeRepository.addNodeStore(node.getId(), createNodeStore(node));
                }
                routedStore.getInnerStores().put(node.getId(),
                                                 storeRepository.getNodeStore(getName(),
                                                                              node.getId()));
            }
        }
    }
408985
private Entry insertBreadthFirst(ClusKernel newPoint, Budget budget, long timestamp) {
    	//check all leaf nodes and get the one with the closest entry to newPoint
		Node bestFit = findBestLeafNode(newPoint);
    	bestFit.makeOlder(timestamp, negLambda);
    	Entry parent = bestFit.getEntries()[0].getParentEntry(); 	
    	// Search for an Entry with a weight under the threshold.
   	    Entry irrelevantEntry = bestFit.getIrrelevantEntry(this.weightThreshold);
        int numFreeEntries = bestFit.numFreeEntries();
        Entry newEntry = new Entry(newPoint.getCenter().length,
    			newPoint, timestamp, parent, bestFit);
        //if there is space, add it to the node ( doesn't ever occur, since nodes are created with 3 entries) 
        if (numFreeEntries>0){
        	bestFit.addEntry(newEntry, timestamp);
        }
        //if outdated cluster in this best fitting node, replace it
         else if (irrelevantEntry != null) {
	        irrelevantEntry.overwriteOldEntry(newEntry);
        }
        //if there is space/outdated cluster on path to top, split. Else merge without split
        else {
        	if (existsOutdatedEntryOnPath(bestFit)||!this.hasMaximalSize()){
	            // We have to split.
	        	insertHereWithSplit(newEntry, bestFit, timestamp);
	        }
        	else {
	            mergeEntryWithoutSplit(bestFit, newEntry,
	                    timestamp);
	        }
        }
        //update all nodes on path to top.
        if (bestFit.getEntries()[0].getParentEntry()!=null)
        	updateToTop(bestFit.getEntries()[0].getParentEntry().getNode());
        return null;
    }
1349997
public static void doMetaCheck(AdminClient adminClient, List<String> metaKeys) {
            Map<String, Integer> roStoreToReplicationFactorMap = new HashMap<String, Integer>();
            Collection<Node> allNodes = adminClient.getAdminClientCluster().getNodes();

            for(String key: metaKeys) {
                Map<String, Map<Object, List<String>>> storeDefToNodeMap = new HashMap<String, Map<Object, List<String>>>(); 
                Map<Object, List<String>> metadataNodeValueMap = new HashMap<Object, List<String>>();
                
                Collection<String> allNodeNames = new ArrayList<String>();

                Boolean checkResult = true;
                for(Node node: allNodes) {
                    String nodeName = "Host '" + node.getHost() + "' : ID " + node.getId();
                    allNodeNames.add(nodeName);

                    Versioned<String> versioned = adminClient.metadataMgmtOps.getRemoteMetadata(node.getId(),
                                                                                                key);
                    if(versioned == null || versioned.getValue() == null) {
                        throw new VoldemortException("Value returned from node " + node.getId()
                                                     + " was null");
                    } else if(key.compareTo(MetadataStore.STORES_KEY) == 0) {
                        List<StoreDefinition> storeDefinitions = new StoreDefinitionsMapper().readStoreList(new StringReader(versioned.getValue()));
                        for(StoreDefinition storeDef: storeDefinitions) {
                            String storeName = storeDef.getName();

                            if(storeDef.getType().compareTo(ReadOnlyStorageConfiguration.TYPE_NAME) == 0) {
                                roStoreToReplicationFactorMap.put(storeName, storeDef.getReplicationFactor());
                            }

                            if(storeDefToNodeMap.containsKey(storeName) == false) {
                                storeDefToNodeMap.put(storeName,
                                                      new HashMap<Object, List<String>>());
                            }
                            Map<Object, List<String>> storeDefMap = storeDefToNodeMap.get(storeName);
                            addMetadataValue(storeDefMap, storeDef, nodeName);
                            
                            // Try a random Get against one key for store/Node
                            checkGetStore(adminClient, storeDef, node);
                        }
                    } else {
                        if(key.compareTo(MetadataStore.CLUSTER_KEY) == 0
                           || key.compareTo(MetadataStore.REBALANCING_SOURCE_CLUSTER_XML) == 0) {
                            Cluster cluster = new ClusterMapper().readCluster(new StringReader(versioned.getValue()));
                            addMetadataValue(metadataNodeValueMap, cluster, nodeName);
                        } else if(key.compareTo(MetadataStore.SERVER_STATE_KEY) == 0) {
                            VoldemortState voldemortStateValue = VoldemortState.valueOf(versioned.getValue());
                            addMetadataValue(metadataNodeValueMap, voldemortStateValue, nodeName);
                        } else {
                            throw new VoldemortException("Incorrect metadata key");
                        }

                    }
                }

                if(metadataNodeValueMap.size() > 0) {
                    checkResult &= checkDiagnostics("Key " + key,
                                                    metadataNodeValueMap,
                                                    allNodeNames);
                }

                if(storeDefToNodeMap.size() > 0) {
                    for(Map.Entry<String, Map<Object, List<String>>> storeNodeValueEntry: storeDefToNodeMap.entrySet()) {
                        String storeName = storeNodeValueEntry.getKey();
                        Map<Object, List<String>> storeDefMap = storeNodeValueEntry.getValue();
                        checkResult &= checkDiagnostics("Store " + storeName,
                                                        storeDefMap,
                                                        allNodeNames);
                        for(QuotaType type : QuotaType.values()) {
                          Map<Object, List<String>> quotaNodeValues = new HashMap<Object, List<String>>();
                          String keyName = "Store:" + storeName + "_QuotaType_"+ type;
                          for(Node node: allNodes) {                          
                            String nodeName = "Host '" + node.getHost() + "' : ID " + node.getId();
                            Versioned<String> quotaValue = adminClient.quotaMgmtOps.getQuotaForNode(storeName, type, node.getId());
                            if(quotaValue == null || quotaValue.getValue() == null) {
                              continue;
                            }
                            addMetadataValue( quotaNodeValues , quotaValue.getValue() , nodeName);
                          }

                          if(quotaNodeValues.size() > 0) {
                            boolean result = checkDiagnostics(keyName,
                                quotaNodeValues,
                                allNodeNames);
                            checkResult &= result;
                          }
                        }
                    }
                }

                System.out.println(key + " metadata check : " + (checkResult ? "PASSED" : "FAILED"));
            }

            validateROFiles(adminClient, allNodes, roStoreToReplicationFactorMap);
        }
993381
void setNewNodes() {

        int index = tTable.getIndexCount();

        nPrimaryNode = new NodeAVLMemoryPointer(this);

        NodeAVL n = nPrimaryNode;

        for (int i = 1; i < index; i++) {
            n.nNext = new NodeAVLMemoryPointer(this);
            n       = n.nNext;
        }
    }
864521
def AddDatastore(self, urn):
    
    if urn not in self._datastores:
      self._datastores.add(urn)
      return True
    return False
862136
public List<Entry> storeSkipExisting(List<Entry> entries) throws MissingParentException {
        List<Entry> skippedEntries = new LinkedList<Entry>();
        for (Entry e : entries) {
            try {
                store(e);
            } catch (EntryAlreadyExistsException ex) {
                skippedEntries.add(e);
            }
        }
        return skippedEntries;
    }
991379
public static void validateClusterStores(final Cluster cluster,
                                             final List<StoreDefinition> storeDefs) {
        // Constructing a StoreRoutingPlan has the (desirable in this
        // case) side-effect of verifying that the store definition is congruent
        // with the cluster definition. If there are issues, exceptions are
        // thrown.
        for(StoreDefinition storeDefinition: storeDefs) {
            new StoreRoutingPlan(cluster, storeDefinition);
        }
        return;
    }
162140
public final void containsNoDuplicates() {
    List<Entry<?>> duplicates = newArrayList();
    for (Multiset.Entry<?> entry : LinkedHashMultiset.create(actual()).entrySet()) {
      if (entry.getCount() > 1) {
        duplicates.add(entry);
      }
    }
    if (!duplicates.isEmpty()) {
      failWithoutActual(
          simpleFact("expected not to contain duplicates"),
          fact("but contained", duplicates),
          fullContents());
    }
  }
283571
@SuppressWarnings({ "unchecked", "rawtypes" })
    protected void addStoreToSession(String store) {

        Exception initializationException = null;

        storeNames.add(store);

        for(Node node: nodesToStream) {

            SocketDestination destination = null;
            SocketAndStreams sands = null;

            try {
                destination = new SocketDestination(node.getHost(),
                                                    node.getAdminPort(),
                                                    RequestFormatType.ADMIN_PROTOCOL_BUFFERS);
                sands = streamingSocketPool.checkout(destination);
                DataOutputStream outputStream = sands.getOutputStream();
                DataInputStream inputStream = sands.getInputStream();

                nodeIdStoreToSocketRequest.put(new Pair(store, node.getId()), destination);
                nodeIdStoreToOutputStreamRequest.put(new Pair(store, node.getId()), outputStream);
                nodeIdStoreToInputStreamRequest.put(new Pair(store, node.getId()), inputStream);
                nodeIdStoreToSocketAndStreams.put(new Pair(store, node.getId()), sands);
                nodeIdStoreInitialized.put(new Pair(store, node.getId()), false);

                remoteStoreDefs = adminClient.metadataMgmtOps.getRemoteStoreDefList(node.getId())
                                                             .getValue();

            } catch(Exception e) {
                logger.error(e);
                try {
                    close(sands.getSocket());
                    streamingSocketPool.checkin(destination, sands);
                } catch(Exception ioE) {
                    logger.error(ioE);
                }

                if(!faultyNodes.contains(node.getId()))
                    faultyNodes.add(node.getId());
                initializationException = e;
            }

        }

        if(initializationException != null)
            throw new VoldemortException(initializationException);

        if(store.equals("slop"))
            return;

        boolean foundStore = false;

        for(StoreDefinition remoteStoreDef: remoteStoreDefs) {
            if(remoteStoreDef.getName().equals(store)) {
                RoutingStrategyFactory factory = new RoutingStrategyFactory();
                RoutingStrategy storeRoutingStrategy = factory.updateRoutingStrategy(remoteStoreDef,
                                                                                     adminClient.getAdminClientCluster());

                storeToRoutingStrategy.put(store, storeRoutingStrategy);
                validateSufficientNodesAvailable(blackListedNodes, remoteStoreDef);
                foundStore = true;
                break;
            }
        }
        if(!foundStore) {
            logger.error("Store Name not found on the cluster");
            throw new VoldemortException("Store Name not found on the cluster");

        }

    }
1062285
public static void validateUserStoreNamesOnNode(AdminClient adminClient,
                                                    Integer nodeId,
                                                    List<String> storeNames) {
        List<StoreDefinition> storeDefList = adminClient.metadataMgmtOps.getRemoteStoreDefList(nodeId)
                                                                        .getValue();
        Map<String, Boolean> existingStoreNames = new HashMap<String, Boolean>();
        for(StoreDefinition storeDef: storeDefList) {
            existingStoreNames.put(storeDef.getName(), true);
        }
        for(String storeName: storeNames) {
            if(!Boolean.TRUE.equals(existingStoreNames.get(storeName))) {
                Utils.croak("Store " + storeName + " does not exist!");
            }
        }
    }
203601
protected boolean isSlopDead(Cluster cluster, Set<String> storeNames, Slop slop) {
        // destination node , no longer exists
        if(!cluster.getNodeIds().contains(slop.getNodeId())) {
            return true;
        }

        // destination store, no longer exists
        if(!storeNames.contains(slop.getStoreName())) {
            return true;
        }

        // else. slop is alive
        return false;
    }
325629
private int updateSizes(DBIDs ids, WritableDataStore<ModifiableDBIDs> labels, WritableIntegerDataStore newSizes) {
    // to count the unclustered all over
    int countUnmerged = 0;
    for(DBIDIter iter = ids.iter(); iter.valid(); iter.advance()) {
      // checking the point's new cluster size after the clustering step
      int newClusterSize = labels.get(iter).size();
      newSizes.putInt(iter, newClusterSize);
      // the point is alone in the cluster --> not merged with other points
      if(newClusterSize == 1) {
        countUnmerged++;
      }
    }
    return countUnmerged;
  }
328167
def has_datastore(self):
        # type: () -> bool
        
        success, result = self._read_from_hdx('datastore', self.data['id'], 'resource_id',
                                              self.actions()['datastore_search'])
        if not success:
            logger.debug(result)
        else:
            if result:
                return True
        return False
634902
public void addExistingItem(final ItemsNodeInterval newNode) {
        Preconditions.checkState(newNode.getItems().size() == 1, "Invalid node=%s", newNode);
        final Item item = newNode.getItems().get(0);

        addNode(newNode,
                new AddNodeCallback() {
                    @Override
                    public boolean onExistingNode(final NodeInterval existingNode) {
                        final ItemsInterval existingOrNewNodeItems = ((ItemsNodeInterval) existingNode).getItemsInterval();
                        existingOrNewNodeItems.add(item);
                        // There is no new node added but instead we just populated the list of items for the already existing node
                        return false;
                    }

                    @Override
                    public boolean shouldInsertNode(final NodeInterval insertionNode) {
                        // Always want to insert node in the tree when we find the right place.
                        return true;
                    }
                });
    }
123400
@Override
    public IEntityStore newEntityStore() throws GroupsException {
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Creating new Grouper GrouperEntityGroupStoreFactory");
        }
        return (IEntityStore) new GrouperEntityGroupStoreFactory().newGroupStore();
    }
1338999
private long addBlock(Block block, List<BlockWithLocations> results) {
    ArrayList<String> machineSet =
      new ArrayList<String>(blocksMap.numNodes(block));
    for (Iterator<DatanodeDescriptor> it =
      blocksMap.nodeIterator(block); it.hasNext();) {
      String storageID = it.next().getStorageID();
      // filter invalidate replicas
      LightWeightHashSet<Block> blocks = recentInvalidateSets.get(storageID);
      if (blocks == null || !blocks.contains(block)) {
        machineSet.add(storageID);
      }
    }
    if (machineSet.size() == 0) {
      return 0;
    } else {
      results.add(new BlockWithLocations(block,
        machineSet.toArray(new String[machineSet.size()])));
      return block.getNumBytes();
    }
  }
362171
def add(self, items):
        """"""
        with _presub_lock:
            self.load_from_cloud()
            for entry in utils.ensure_listable(items):
                # add new entries, but only if they're unique
                if entry not in self.current:
                    self.current.append(entry)
            self.save_to_cloud()