private void removePortProfiles(ContainerHostRemovalTaskState state, ArrayList<String> hostPortProfileLinks, String subTaskLink) { if (subTaskLink == null) { // create counter subtask to remove every host port profile. Go to REMOVED_PORT_PROFILES when complete createCounterSubTask(state, hostPortProfileLinks.size(), SubStage.REMOVED_PORT_PROFILES, (link) -> removePortProfiles(state, hostPortProfileLinks, link)); return; } // delete host port profiles for (String profileLink : hostPortProfileLinks) { sendRequest(Operation.createDelete(this, profileLink) .setCompletion((o, ex) -> { if (ex != null) { failTask("Failed to delete host port profile: %s", ex); return; } completeSubTasksCounter(subTaskLink, null); })); } }
private void queryPortProfiles(ContainerHostRemovalTaskState state) { QueryTask q = QueryUtil .buildQuery(HostPortProfileService.HostPortProfileState.class, false); QueryUtil.addListValueClause(q, HostPortProfileService.HostPortProfileState.FIELD_HOST_LINK, state.resourceLinks); ServiceDocumentQuery<HostPortProfileService.HostPortProfileState> query = new ServiceDocumentQuery<>( getHost(), HostPortProfileService.HostPortProfileState.class); QueryUtil.addBroadcastOption(q); ArrayList<String> hostPortProfileLinks = new ArrayList<>(); query.query(q, (r) -> { if (r.hasException()) { failTask("Failure retrieving query results", r.getException()); return; } else if (r.hasResult()) { hostPortProfileLinks.add(r.getDocumentSelfLink()); } else { // if there are no host port profiles, go to the next stage if (hostPortProfileLinks.isEmpty()) { proceedTo(SubStage.REMOVED_PORT_PROFILES); return; } removePortProfiles(state, hostPortProfileLinks, null); proceedTo(SubStage.REMOVING_PORT_PROFILES); } }); }