Search in sources :

Example 1 with IPAddressAllocationTaskState

use of com.vmware.photon.controller.model.tasks.IPAddressAllocationTaskService.IPAddressAllocationTaskState in project photon-model by vmware.

the class IPAddressAllocationTaskServiceTest method createIpAddressDeallocationTask.

private static IPAddressAllocationTaskState createIpAddressDeallocationTask(List<String> ipAddressResourceLinks) {
    IPAddressAllocationTaskState deallocationTask = new IPAddressAllocationTaskState();
    deallocationTask.requestType = IPAddressAllocationTaskState.RequestType.DEALLOCATE;
    deallocationTask.ipAddressLinks = ipAddressResourceLinks;
    return deallocationTask;
}
Also used : IPAddressAllocationTaskState(com.vmware.photon.controller.model.tasks.IPAddressAllocationTaskService.IPAddressAllocationTaskState)

Example 2 with IPAddressAllocationTaskState

use of com.vmware.photon.controller.model.tasks.IPAddressAllocationTaskService.IPAddressAllocationTaskState in project photon-model by vmware.

the class IPAddressAllocationTaskServiceTest method createIpAddressAllocationTask.

private static IPAddressAllocationTaskState createIpAddressAllocationTask(String subnetLink, String connectedResourceLink) {
    IPAddressAllocationTaskState allocationTask = new IPAddressAllocationTaskState();
    allocationTask.subnetLink = subnetLink;
    allocationTask.requestType = IPAddressAllocationTaskState.RequestType.ALLOCATE;
    allocationTask.connectedResourceToRequiredIpCountMap = new HashMap<>();
    allocationTask.connectedResourceToRequiredIpCountMap.put(connectedResourceLink, 1);
    return allocationTask;
}
Also used : IPAddressAllocationTaskState(com.vmware.photon.controller.model.tasks.IPAddressAllocationTaskService.IPAddressAllocationTaskState)

Example 3 with IPAddressAllocationTaskState

use of com.vmware.photon.controller.model.tasks.IPAddressAllocationTaskService.IPAddressAllocationTaskState in project photon-model by vmware.

the class IPAddressAllocationTaskServiceTest method createIpAddressAllocationTask.

private static IPAddressAllocationTaskState createIpAddressAllocationTask(String subnetLink, Map<String, Integer> connectedResourceToRequiredIpCountMap) {
    IPAddressAllocationTaskState allocationTask = new IPAddressAllocationTaskState();
    allocationTask.subnetLink = subnetLink;
    allocationTask.requestType = IPAddressAllocationTaskState.RequestType.ALLOCATE;
    allocationTask.connectedResourceToRequiredIpCountMap = connectedResourceToRequiredIpCountMap;
    return allocationTask;
}
Also used : IPAddressAllocationTaskState(com.vmware.photon.controller.model.tasks.IPAddressAllocationTaskService.IPAddressAllocationTaskState)

Example 4 with IPAddressAllocationTaskState

use of com.vmware.photon.controller.model.tasks.IPAddressAllocationTaskService.IPAddressAllocationTaskState in project photon-model by vmware.

the class ResourceIPDeallocationTaskService method startDeallocatingIPs.

private void startDeallocatingIPs(ResourceIPDeallocationTaskState state, ResourceIPDeallocationContext ctx, String subTaskLink) {
    if (subTaskLink == null) {
        createSubTaskCallback(state, ctx, link -> startDeallocatingIPs(state, ctx, link));
        return;
    }
    logFine("Starting deallocate of (%s) IPs for compute resource [%s] using sub task %s", ctx.networkInterfaceToIPAddressMap.size(), ctx.resourceLink, subTaskLink);
    List<DeferredResult<Operation>> deallocateOperationDRs = new ArrayList<>();
    ctx.networkInterfaceToIPAddressMap.keySet().forEach(networkInterfaceLink -> {
        String ipAddressLink = ctx.networkInterfaceToIPAddressMap.get(networkInterfaceLink);
        IPAddressAllocationTaskState deallocationTaskState = new IPAddressAllocationTaskState();
        deallocationTaskState.serviceTaskCallback = ServiceTaskCallback.create(UriUtils.buildUri(getHost(), subTaskLink));
        deallocationTaskState.serviceTaskCallback.onSuccessFinishTask();
        // Similar to instance deletes - a failure for one network interface deallocate will fail the task
        deallocationTaskState.serviceTaskCallback.onErrorFailTask();
        deallocationTaskState.requestType = IPAddressAllocationTaskState.RequestType.DEALLOCATE;
        deallocationTaskState.connectedResourceLink = networkInterfaceLink;
        deallocationTaskState.ipAddressLinks = new ArrayList<>();
        deallocationTaskState.ipAddressLinks.add(ipAddressLink);
        deallocationTaskState.tenantLinks = state.tenantLinks;
        Operation deallocateNisOperation = Operation.createPost(this, IPAddressAllocationTaskService.FACTORY_LINK).setBody(deallocationTaskState);
        DeferredResult<Operation> deallocateOperationDR = sendWithDeferredResult(deallocateNisOperation);
        deallocateOperationDRs.add(deallocateOperationDR);
    });
    DeferredResult.allOf(deallocateOperationDRs).exceptionally(t -> {
        String msg = "Failure deallocating IP addresses for a computeResource: [%s]";
        logWarning(msg, state.resourceLink, t.getMessage());
        failTask(t, msg, state.resourceLink);
        return null;
    });
}
Also used : IPAddressAllocationTaskState(com.vmware.photon.controller.model.tasks.IPAddressAllocationTaskService.IPAddressAllocationTaskState) ArrayList(java.util.ArrayList) Operation(com.vmware.xenon.common.Operation) DeferredResult(com.vmware.xenon.common.DeferredResult)

Aggregations

IPAddressAllocationTaskState (com.vmware.photon.controller.model.tasks.IPAddressAllocationTaskService.IPAddressAllocationTaskState)4 DeferredResult (com.vmware.xenon.common.DeferredResult)1 Operation (com.vmware.xenon.common.Operation)1 ArrayList (java.util.ArrayList)1