private void selectHost(ContainerVolumeProvisionTaskState state, Consumer<ComputeState> callback) { getContextContainerStates(state, (states) -> { getContextContainerDescriptions(states, (descriptions) -> { List<ContainerState> containerStatesForVolume = getDependantContainerStates( descriptions, states, volumeDescription); if (containerStatesForVolume.isEmpty()) { String err = String.format( "No container states depending on volume description [%s] found.", volumeDescription.name); failTask(err, null); } else { String hostLink = containerStatesForVolume.get(0).parentLink; getHost(hostLink, (host) -> { callback.accept(host); }); } }); }); }
private void getContextContainerDescriptions( Map<String, List<ContainerState>> containersByDescriptionLink, Consumer<List<ContainerDescription>> callback) { if ((containersByDescriptionLink == null) || (containersByDescriptionLink.isEmpty())) { callback.accept(Collections.emptyList()); return; } QueryTask q = QueryUtil.buildQuery(ContainerDescription.class, true); QueryUtil.addExpandOption(q); QueryUtil.addListValueClause(q, ContainerDescription.FIELD_NAME_SELF_LINK, containersByDescriptionLink.keySet()); q.taskInfo.isDirect = false; List<ContainerDescription> result = new ArrayList<>(); new ServiceDocumentQuery<ContainerDescription>(getHost(), ContainerDescription.class) .query(q, (r) -> { if (r.hasException()) { failTask("Exception while selecting container descriptions", r.getException()); } else if (r.hasResult()) { result.add(r.getResult()); } else { callback.accept(result); } }); }
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); } }); }); }
private void createAndSendContainerVolumeRequest(ContainerVolumeProvisionTaskState state, ServiceTaskCallback taskCallback, String volumeSelfLink) { AdapterRequest volumeRequest = new AdapterRequest(); volumeRequest.resourceReference = UriUtils.buildUri(getHost(), volumeSelfLink); volumeRequest.serviceTaskCallback = taskCallback; if (Boolean.TRUE.equals(volumeDescription.external)) { // The volume is defined as external, just validate that it exists actually. volumeRequest.operationTypeId = VolumeOperationType.INSPECT.id; } else { volumeRequest.operationTypeId = VolumeOperationType.CREATE.id; } volumeRequest.customProperties = state.customProperties; sendRequest(Operation.createPatch(getHost(), state.instanceAdapterReference.toString()) .setBody(volumeRequest) .setContextId(getSelfId()) .setCompletion((o, e) -> { if (e != null) { failTask("AdapterRequest failed for volume: " + volumeSelfLink, e); return; } logInfo("Volume provisioning started for: %s", volumeSelfLink); })); }
new ServiceDocumentQuery<ContainerState>(getHost(), ContainerState.class) .query(q, (r) -> {
QueryUtil.addExpandOption(queryTask); new ServiceDocumentQuery<ComputeState>(getHost(), ComputeState.class) .query(queryTask, (r) -> { if (r.hasException()) {