private void getContainerNetworkDescription(ContainerNetworkProvisionTaskState state, Consumer<ContainerNetworkDescription> callbackFunction) { if (networkDescription != null) { callbackFunction.accept(networkDescription); return; } sendRequest(Operation.createGet(this, state.resourceDescriptionLink) .setCompletion( (o, e) -> { if (e != null) { failTask("Failure retrieving container network description state", e); return; } ContainerNetworkDescription desc = o .getBody(ContainerNetworkDescription.class); this.networkDescription = desc; callbackFunction.accept(desc); })); }
private void updateContainerNetworkStateWithContainerHostLink( ContainerNetworkState currentNetworkState, ComputeState host, Runnable callbackFunction) { ContainerNetworkState patch = new ContainerNetworkState(); patch.originatingHostLink = host.documentSelfLink; patch.parentLinks = new ArrayList<>(Arrays.asList(host.documentSelfLink)); if (currentNetworkState.driver == null || currentNetworkState.driver.isEmpty()) { String cluster = host.customProperties .get(ContainerHostService.DOCKER_HOST_CLUSTER_STORE_PROP_NAME); if (cluster != null && !cluster.isEmpty()) { patch.driver = ContainerNetworkDescription.NETWORK_DRIVER_OVERLAY; } } sendRequest(Operation .createPatch(this, currentNetworkState.documentSelfLink) .setBody(patch) .setCompletion( (o, e) -> { if (e != null) { logWarning("Error while updating network: %s", currentNetworkState.documentSelfLink); failTask(String.format("Error while updating network: %s", currentNetworkState.documentSelfLink), e); } else { callbackFunction.run(); } })); }
sendRequest(Operation .createPatch(this, currentNetworkState.documentSelfLink) .setBody(patch)
private void createAndSendContainerNetworkRequest(ContainerNetworkState networkState, ContainerNetworkProvisionTaskState state, ServiceTaskCallback taskCallback, String networkSelfLink) { getContainerNetworkDescription(state, (networkDescription) -> { AdapterRequest networkRequest = new AdapterRequest(); networkRequest.resourceReference = UriUtils.buildUri(getHost(), networkSelfLink); networkRequest.serviceTaskCallback = taskCallback; if (Boolean.TRUE.equals(networkDescription.external)) { // The network is defined as external, just validate that it exists actually. networkRequest.operationTypeId = NetworkOperationType.INSPECT.id; } else { networkRequest.operationTypeId = NetworkOperationType.CREATE.id; } networkRequest.customProperties = state.customProperties; sendRequest(Operation.createPatch(getHost(), state.instanceAdapterReference.toString()) .setBody(networkRequest) .setContextId(getSelfId()) .setCompletion((o, e) -> { if (e != null) { failTask("AdapterRequest failed for network: " + networkSelfLink, e); return; } logInfo("Network '%s' request started for: %s", networkRequest.operationTypeId, networkSelfLink); })); }); }