private void selectHosts(ContainerVolumeProvisionTaskState state, ContainerVolumeDescription volumeDescription, Consumer<List<ComputeState>> callback) { // If hosts are provided use them directly to try to provision the volume // (e.g. when External volume CRUD operations) List<String> providedHostLinks = ContainerVolumeAllocationTaskService .getProvidedHostIdsAsSelfLinks(state); if (providedHostLinks != null) { retrieveContainerHostsByLinks(state, providedHostLinks, (hosts) -> { List<String> disabledHosts = hosts.stream().filter((host) -> { return host.powerState != PowerState.ON; }).map(host -> host.address).collect(Collectors.toList()); if (disabledHosts.isEmpty()) { callback.accept(hosts); } else { String err = String.format( "Requested volume provisioning for disabled hosts: [%s].", disabledHosts); failTask(err, null); } }); return; } selectHost(state, (host) -> { callback.accept(Collections.singletonList(host)); }); }
private void getVolumeByName(ContainerVolumeProvisionTaskState state, String volumeName, Consumer<ContainerVolumeState> callback) { selectHost(state, (host) -> { List<ContainerVolumeState> volumeStates = new ArrayList<ContainerVolumeState>(); QueryTask queryTask = VolumeUtil .getVolumeByHostAndNameQueryTask(host.documentSelfLink, volumeName); new ServiceDocumentQuery<ContainerVolumeState>(getHost(), ContainerVolumeState.class) .query(queryTask, (r) -> { if (r.hasException()) { failTask("Failed to query for active volume by name '" + volumeName + "' in host '" + host.documentSelfLink + "'!", r.getException()); } else if (r.hasResult()) { if (volumeName.equals(r.getResult().name)) { volumeStates.add(r.getResult()); } } else { if (volumeStates.size() == 1) { callback.accept(volumeStates.get(0)); return; } failTask(volumeStates.size() + " active volume(s) found by name '" + volumeName + "' in host '" + host.documentSelfLink + "'!", null); } }); }); }