Source:
<code>public boolean doProvision(Collection<RemoteTaskRunnerWorkItem> pendingTasks, Collection<ZkWorker> zkWorkers) { synchronized (lock) { boolean didProvision = false; final WorkerSetupData workerSetupData = workerSetupDataRef.get(); final Predicate<ZkWorker> isValidWorker = createValidWorkerPredicate(workerSetupData); final int currValidWorkers = Collections2.filter(zkWorkers, isValidWorker).size(); final List<String> workerNodeIds = autoScalingStrategy.ipToIdLookup( Lists.newArrayList( Iterables.<ZkWorker, String>transform( zkWorkers, new Function<ZkWorker, String>() { @Override public String apply(ZkWorker input) { return input.getWorker().getIp(); } } ) ) ); currentlyProvisioning.removeAll(workerNodeIds); updateTargetWorkerCount(pendingTasks, zkWorkers); if (currentlyProvisioning.isEmpty()) { int want = targetWorkerCount - (currValidWorkers + currentlyProvisioning.size()); while (want > 0) { final AutoScalingData provisioned = autoScalingStrategy.provision(); if (provisioned == null) { break; } else { currentlyProvisioning.addAll(provisioned.getNodeIds()); lastProvisionTime = new DateTime(); scalingStats.addProvisionEvent(provisioned); want -= provisioned.getNodeIds().size(); didProvision = true; } } } else { <START> Duration durSinceLastProvision = new Duration(lastProvisionTime, new DateTime()); <END> log.info("%s provisioning. Current wait time: %s", currentlyProvisioning, durSinceLastProvision); if (durSinceLastProvision.isLongerThan(config.getMaxScalingDuration().toStandardDuration())) { log.makeAlert("Worker node provisioning taking too long!") .addData("millisSinceLastProvision", durSinceLastProvision.getMillis()) .addData("provisioningCount", currentlyProvisioning.size()) .emit(); List<String> nodeIps = autoScalingStrategy.idToIpLookup(Lists.newArrayList(currentlyProvisioning)); autoScalingStrategy.terminate(nodeIps); currentlyProvisioning.clear(); } } return didProvision; } }</code><technical_language>provisioning happen long currently provisioning? do want able provision here, a limit</technical_language>

Target:
public boolean doProvision(Collection<RemoteTaskRunnerWorkItem> pendingTasks, Collection<ZkWorker> zkWorkers) { synchronized (lock) { boolean didProvision = false; final WorkerSetupData workerSetupData = workerSetupDataRef.get(); if (workerSetupData == null) { log.warn("No workerSetupData available, cannot provision new workers."); return false; } final Predicate<ZkWorker> isValidWorker = createValidWorkerPredicate(config, workerSetupData); final int currValidWorkers = Collections2.filter(zkWorkers, isValidWorker).size(); final List<String> workerNodeIds = autoScalingStrategy.ipToIdLookup( Lists.newArrayList( Iterables.<ZkWorker, String>transform( zkWorkers, new Function<ZkWorker, String>() { @Override public String apply(ZkWorker input) { return input.getWorker().getIp(); } } ) ) ); currentlyProvisioning.removeAll(workerNodeIds); updateTargetWorkerCount(pendingTasks, zkWorkers); int want = targetWorkerCount - (currValidWorkers + currentlyProvisioning.size()); while (want > 0) { final AutoScalingData provisioned = autoScalingStrategy.provision(); final List<String> newNodes; if (provisioned == null || (newNodes = provisioned.getNodeIds()).isEmpty()) { break; } else { currentlyProvisioning.addAll(newNodes); lastProvisionTime = new DateTime(); scalingStats.addProvisionEvent(provisioned); want -= provisioned.getNodeIds().size(); didProvision = true; } } if (!currentlyProvisioning.isEmpty()) { Duration durSinceLastProvision = new Duration(lastProvisionTime, new DateTime()); log.info("%s provisioning. Current wait time: %s", currentlyProvisioning, durSinceLastProvision); if (durSinceLastProvision.isLongerThan(config.getMaxScalingDuration().toStandardDuration())) { log.makeAlert("Worker node provisioning taking too long!") .addData("millisSinceLastProvision", durSinceLastProvision.getMillis()) .addData("provisioningCount", currentlyProvisioning.size()) .emit(); List<String> nodeIps = autoScalingStrategy.idToIpLookup(Lists.newArrayList(currentlyProvisioning)); autoScalingStrategy.terminate(nodeIps); currentlyProvisioning.clear(); } } return didProvision; } }