Check if we still need more nodes from the given zone and reduce the
zoneReplicationFactor count accordingly.

@param requiredRepFactor
@param zoneId
@return
337678
private boolean checkZoneRequirement(HashMap<Integer, Integer> requiredRepFactor, int zoneId) {
        if(requiredRepFactor.containsKey(zoneId)) {
            if(requiredRepFactor.get(zoneId) == 0) {
                return false;
            } else {
                requiredRepFactor.put(zoneId, requiredRepFactor.get(zoneId) - 1);
                return true;
            }
        }
        return false;

    }
1337088
public static Cluster swapRandomPartitionsWithinZone(final Cluster nextCandidateCluster,
                                                         final int zoneId) {
        Cluster returnCluster = Cluster.cloneCluster(nextCandidateCluster);
        Random r = new Random();

        List<Integer> nodeIdsInZone = new ArrayList<Integer>(nextCandidateCluster.getNodeIdsInZone(zoneId));

        if(nodeIdsInZone.size() == 0) {
            return returnCluster;
        }

        // Select random stealer node
        int stealerNodeOffset = r.nextInt(nodeIdsInZone.size());
        Integer stealerNodeId = nodeIdsInZone.get(stealerNodeOffset);

        // Select random stealer partition
        List<Integer> stealerPartitions = returnCluster.getNodeById(stealerNodeId)
                                                       .getPartitionIds();
        if(stealerPartitions.size() == 0) {
            return nextCandidateCluster;
        }
        int stealerPartitionOffset = r.nextInt(stealerPartitions.size());
        int stealerPartitionId = stealerPartitions.get(stealerPartitionOffset);

        // Select random donor node
        List<Integer> donorNodeIds = new ArrayList<Integer>();
        donorNodeIds.addAll(nodeIdsInZone);
        donorNodeIds.remove(stealerNodeId);

        if(donorNodeIds.isEmpty()) { // No donor nodes!
            return returnCluster;
        }
        int donorIdOffset = r.nextInt(donorNodeIds.size());
        Integer donorNodeId = donorNodeIds.get(donorIdOffset);

        // Select random donor partition
        List<Integer> donorPartitions = returnCluster.getNodeById(donorNodeId).getPartitionIds();
        int donorPartitionOffset = r.nextInt(donorPartitions.size());
        int donorPartitionId = donorPartitions.get(donorPartitionOffset);

        return swapPartitions(returnCluster,
                              stealerNodeId,
                              stealerPartitionId,
                              donorNodeId,
                              donorPartitionId);
    }
1033558
public OvhOrder domain_zone_new_POST(Boolean minimized, String zoneName) throws IOException {
		String qPath = "/order/domain/zone/new";
		StringBuilder sb = path(qPath);
		HashMap<String, Object>o = new HashMap<String, Object>();
		addBody(o, "minimized", minimized);
		addBody(o, "zoneName", zoneName);
		String resp = exec(qPath, "POST", sb.toString(), o);
		return convertTo(resp, OvhOrder.class);
	}
1357243
public static AnnotationTypeRequiredMemberBuilder getInstance(
            Context context, ClassDoc classDoc,
            AnnotationTypeRequiredMemberWriter writer) {
        return new AnnotationTypeRequiredMemberBuilder(context, classDoc,
                    writer,
                    VisibleMemberMap.ANNOTATION_TYPE_MEMBER_REQUIRED);
    }
612402
@Override
    public ChronoZonedDateTime<D> atZone(ZoneId zoneId) {
        return ChronoZonedDateTimeImpl.ofBest(this, zoneId, null);
    }
848838
public static boolean checkPartitionBelongsToNode(int partition,
                                                      int nodeId,
                                                      Cluster cluster,
                                                      StoreDefinition storeDef) {
        List<Integer> nodePartitions = cluster.getNodeById(nodeId).getPartitionIds();
        List<Integer> replicatingPartitions = new RoutingStrategyFactory().updateRoutingStrategy(storeDef,
                                                                                                 cluster)
                                                                          .getReplicatingPartitionList(partition);
        replicatingPartitions.retainAll(nodePartitions);
        return replicatingPartitions.size() > 0;
    }
52287
public static boolean validateLicense(LicenseApi licenseApi, int numberOfNodes, DrRoleType replicationRole,
            StartAction startAction)
    {
        // Delay the handling of an invalid license file until here so
        // that the leader can terminate the full cluster.
        if (licenseApi == null) {
            hostLog.fatal("VoltDB license is not valid.");
            return false;
        }

        // do some extra initialization here
        if (!licenseApi.secondaryInitialization()) {
            return false;
        }

        Calendar now = GregorianCalendar.getInstance();
        SimpleDateFormat sdf = new SimpleDateFormat("MMM d, yyyy");
        String expiresStr = sdf.format(licenseApi.expires().getTime());
        boolean valid = true;

        // make it really expire tomorrow to deal with timezone whiners
        Calendar yesterday = GregorianCalendar.getInstance();
        yesterday.add(Calendar.DATE, -1);

        if (yesterday.after(licenseApi.expires())) {
            if (licenseApi.hardExpiration()) {
                if (licenseApi.isAnyKindOfTrial()) {
                    hostLog.fatal("VoltDB trial license expired on " + expiresStr + ".");
                }
                else {
                    hostLog.fatal("VoltDB license expired on " + expiresStr + ".");
                }
                hostLog.fatal("Please contact sales@voltdb.com to request a new license.");
                return false;
            }
            else {
                // Expired commercial licenses are allowed but generate log messages.
                hostLog.error("Warning, VoltDB commercial license expired on " + expiresStr + ".");
                valid = false;
            }
        }

        // enforce DR replication constraint
        if (licenseApi.isDrReplicationAllowed() == false) {
            if (replicationRole != DrRoleType.NONE) {
                hostLog.fatal("Warning, VoltDB license does not allow use of DR replication.");
                return false;
            }
        } else if (licenseApi.isDrActiveActiveAllowed() == false) {
            if (replicationRole == DrRoleType.XDCR) {
                hostLog.fatal("Warning, VoltDB license does not allow use of XDCR.");
                return false;
            }
        }

        // check node count
        if (licenseApi.maxHostcount() < numberOfNodes) {
            hostLog.fatal("Attempting to " + (startAction.doesJoin() ? "join" : "start") + " with too many nodes ("
                    + numberOfNodes + "). " + "Current license only supports " + licenseApi.maxHostcount()
                    + ". Please contact VoltDB at info@voltdb.com.");
            return false;
        }

        // If this is a commercial license, and there is less than or equal to 30 days until expiration,
        // issue a "days remaining" warning message.
        long diff = licenseApi.expires().getTimeInMillis() - now.getTimeInMillis();
        // The original license is only a whole data (no minutes/millis).
        // There should thus be no issue with daylight savings time,
        // but just in case, if the diff is a negative number, round up to zero.
        if (diff < 0) {
            diff = 0;
        }
        long diffDays = diff / (24 * 60 * 60 * 1000);

        // print out trial success message
        if (licenseApi.isAnyKindOfTrial()) {
            consoleLog.info("Starting VoltDB with trial license. License expires on " + expiresStr + " (" + diffDays + " days remaining).");
            return true;
        }

        if (licenseApi.isAWSMarketplace()) {
            return true;
        }

        // print out a warning within a month for other licenses
        if ((diff > 0) && (diff <= 30))
        {
            String msg = "Warning: VoltDB license expires in " + diffDays + " day(s).";
            consoleLog.info(msg);
        }

        // this gets printed even if there are non-fatal problems, so it
        // injects the word "invalid" to make it clear this is the case
        String msg = String.format("Starting VoltDB with %scommercial license. " +
                                   "License for %d nodes expires on %s.",
                                   (valid ? "" : "invalid "),
                                   licenseApi.maxHostcount(),
                                   expiresStr);
        consoleLog.info(msg);

        return true;
    }
60835
public int getNodeIdForZoneNary(int zoneId, int zoneNary, int partitionId) {
        List<Integer> replicatingNodeIds = getReplicationNodeList(partitionId);

        int zoneNAry = -1;
        for(int replicatingNodeId: replicatingNodeIds) {
            Node replicatingNode = cluster.getNodeById(replicatingNodeId);
            // bump up the counter if we encounter a replica in the given zone
            if(replicatingNode.getZoneId() == zoneId) {
                zoneNAry++;
            }
            // when the counter matches up with the replicaNumber we need, we
            // are done.
            if(zoneNAry == zoneNary) {
                return replicatingNode.getId();
            }
        }
        if(zoneNAry == 0) {
            throw new VoldemortException("Could not find any replicas for the partition "
                                         + partitionId + " in given zone " + zoneId);
        } else {
            throw new VoldemortException("Could not find " + zoneNary
                                         + " replicas for the partition " + partitionId
                                         + " in given zone " + zoneId + ". Only found " + zoneNAry);
        }
    }
571720
public boolean containsRequiredAnnotations(Collection<Class<? extends Annotation>> requiredAnnotations) {
        if (annotatedType instanceof BackedAnnotatedType<?>) {
            return containsAnnotation((BackedAnnotatedType<?>) annotatedType, requiredAnnotations);
        } else if (annotatedType instanceof UnbackedAnnotatedType<?>) {
            return containsAnnotation((UnbackedAnnotatedType<?>) annotatedType, requiredAnnotations);
        } else {
            throw new IllegalArgumentException("Unknown SlimAnnotatedType implementation: " + annotatedType.getClass().toString());
        }
    }
663427
protected final boolean checkRequiredAnnotations(Class<?> controllerClazz, Method actionMethod) {
        List<Class<? extends Annotation>> requiredAnnotations = getRequiredAnnotationClasses();
        if (requiredAnnotations == null || requiredAnnotations.size() == 0) {
            return true;
        }
        for (Class<? extends Annotation> requiredAnnotation : requiredAnnotations) {
            if (requiredAnnotation == null) {
                continue;
            }
            BitSet scopeSet = getAnnotationScope(requiredAnnotation);
            if (scopeSet.get(AnnotationScope.METHOD.ordinal())) {
                if (actionMethod.isAnnotationPresent(requiredAnnotation)) {
                    return checkAnnotation(actionMethod.getAnnotation(requiredAnnotation));
                }
            }
            if (scopeSet.get(AnnotationScope.CLASS.ordinal())) {
                if (controllerClazz.isAnnotationPresent(requiredAnnotation)) {
                    return checkAnnotation(actionMethod.getAnnotation(requiredAnnotation));
                }
            }
            if (scopeSet.get(AnnotationScope.ANNOTATION.ordinal())) {
                for (Annotation annotation : actionMethod.getAnnotations()) {
                    if (annotation.annotationType().isAnnotationPresent(requiredAnnotation)) {
                        return checkAnnotation(actionMethod.getAnnotation(requiredAnnotation));
                    }
                }
                for (Annotation annotation : controllerClazz.getAnnotations()) {
                    if (annotation.annotationType().isAnnotationPresent(requiredAnnotation)) {
                        return checkAnnotation(actionMethod.getAnnotation(requiredAnnotation));
                    }
                }
            }
        }
        return false;
    }
1348835
private int countLiveNodes(Block b, Iterator<DatanodeDescriptor> nodeIter) {
    int live = 0;
    Collection<DatanodeDescriptor> nodesCorrupt = null;
    if (corruptReplicas.size() != 0) {
      nodesCorrupt = corruptReplicas.getNodes(b);
    }
    while (nodeIter.hasNext()) {
      DatanodeDescriptor node = nodeIter.next();
      if (((nodesCorrupt != null) && (nodesCorrupt.contains(node))) ||
        node.isDecommissionInProgress() || node.isDecommissioned()) {
        // do nothing
      } else {
        live++;
      }
    }
    return live;
  }
157869
public String addConnectionRequirement(NodeTemplate target, String type, String varName) {
        Map<String, Object> requirement = new LinkedHashMap();
        
        String requirementName = "endpoint";
        Map requirementMap = new LinkedHashMap<String, Object>();
        requirement.put(requirementName, requirementMap);
        requirementMap.put("node", target.getName());
        requirementMap.put("type", type);
        if (!varName.isEmpty()) {
            Map<String, String> properties = new LinkedHashMap();
            properties.put("prop.name", varName);
            requirementMap.put("properties", properties);
        }
        requirements().add(requirement);
        
        return requirementName;
    }
439339
private static ZoneId ofWithPrefix(String zoneId, int prefixLength, boolean checkAvailable) {
        String prefix = zoneId.substring(0, prefixLength);
        if (zoneId.length() == prefixLength) {
            return ofOffset(prefix, ZoneOffset.UTC);
        }
        if (zoneId.charAt(prefixLength) != '+' && zoneId.charAt(prefixLength) != '-') {
            return ZoneRegion.ofId(zoneId, checkAvailable);  // drop through to ZoneRulesProvider
        }
        try {
            ZoneOffset offset = ZoneOffset.of(zoneId.substring(prefixLength));
            if (offset == ZoneOffset.UTC) {
                return ofOffset(prefix, offset);
            }
            return ofOffset(prefix, offset);
        } catch (DateTimeException ex) {
            throw new DateTimeException("Invalid ID for offset-based ZoneId: " + zoneId, ex);
        }
    }
974
private function linkZone(Zone $zone, array $zoneData): void
    {
        $linkedZoneLayout = $this->layoutService->loadLayout($zoneData['layout_id']);
        $linkedZone = $linkedZoneLayout->getZone($zoneData['identifier']);
        $this->layoutService->linkZone($zone, $linkedZone);
    }
389334
public static Map<Integer, Integer> getMapOfContiguousPartitions(final Cluster cluster,
                                                                     int zoneId) {
        List<Integer> partitionIds = new ArrayList<Integer>(cluster.getPartitionIdsInZone(zoneId));
        Map<Integer, Integer> partitionIdToRunLength = Maps.newHashMap();

        if(partitionIds.isEmpty()) {
            return partitionIdToRunLength;
        }

        int lastPartitionId = partitionIds.get(0);
        int initPartitionId = lastPartitionId;

        for(int offset = 1; offset < partitionIds.size(); offset++) {
            int partitionId = partitionIds.get(offset);
            if(partitionId == lastPartitionId + 1) {
                lastPartitionId = partitionId;
                continue;
            }
            int runLength = lastPartitionId - initPartitionId + 1;

            partitionIdToRunLength.put(initPartitionId, runLength);

            initPartitionId = partitionId;
            lastPartitionId = initPartitionId;
        }

        int runLength = lastPartitionId - initPartitionId + 1;
        if(lastPartitionId == cluster.getNumberOfPartitions() - 1
           && partitionIdToRunLength.containsKey(0)) {
            // special case of contiguity that wraps around the ring.
            partitionIdToRunLength.put(initPartitionId, runLength + partitionIdToRunLength.get(0));
            partitionIdToRunLength.remove(0);
        } else {
            partitionIdToRunLength.put(initPartitionId, runLength);
        }

        return partitionIdToRunLength;
    }
60232
public Observable<ServiceResponse<Void>> deleteImageRegionsWithServiceResponseAsync(UUID projectId, List<String> regionIds) {
        if (projectId == null) {
            throw new IllegalArgumentException("Parameter projectId is required and cannot be null.");
        }
        if (regionIds == null) {
            throw new IllegalArgumentException("Parameter regionIds is required and cannot be null.");
        }
        if (this.client.apiKey() == null) {
            throw new IllegalArgumentException("Parameter this.client.apiKey() is required and cannot be null.");
        }
        Validator.validate(regionIds);
        String regionIdsConverted = this.client.serializerAdapter().serializeList(regionIds, CollectionFormat.CSV);
        return service.deleteImageRegions(projectId, regionIdsConverted, this.client.apiKey(), this.client.acceptLanguage(), this.client.userAgent())
            .flatMap(new Func1<Response<ResponseBody>, Observable<ServiceResponse<Void>>>() {
                @Override
                public Observable<ServiceResponse<Void>> call(Response<ResponseBody> response) {
                    try {
                        ServiceResponse<Void> clientResponse = deleteImageRegionsDelegate(response);
                        return Observable.just(clientResponse);
                    } catch (Throwable t) {
                        return Observable.error(t);
                    }
                }
            });
    }
847174
public void addZone(String id, Component zone, String constraints) {
        // is there already a zone with this id?
        Component previousZone = getZone(id);
        if (previousZone != null) {
            remove(previousZone);
            idToZones.remove(id);
        }

        if (zone instanceof JComponent) {
            JComponent jc = (JComponent) zone;
            if (jc.getBorder() == null || jc.getBorder() instanceof UIResource) {
                if (jc instanceof JLabel) {
                    jc.setBorder(
                            new CompoundBorder(zoneBorder, new EmptyBorder(0, 2, 0, 2)));
                    ((JLabel) jc).setText(" ");
                } else {
                    jc.setBorder(zoneBorder);
                }
            }
        }

        add(zone, constraints);
        idToZones.put(id, zone);
    }