Search in sources :

Example 16 with ComputeDescription

use of com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription in project photon-model by vmware.

the class QueryUtilsTest method testQueryReferrers.

@Test
public void testQueryReferrers() throws Throwable {
    final ComputeDescription cd = ModelUtils.createComputeDescription(this, null, null);
    final Set<String> expected = new HashSet<>(Arrays.asList(ModelUtils.createCompute(this, cd).documentSelfLink, ModelUtils.createCompute(this, cd).documentSelfLink, ModelUtils.createCompute(this, cd).documentSelfLink, ModelUtils.createCompute(this, cd).documentSelfLink, ModelUtils.createCompute(this, cd).documentSelfLink));
    doTest(cd, expected, null);
    doTest(cd, expected, Arrays.asList());
    doTest(cd, expected, Arrays.asList("http://tenant"));
    doTest(cd, new HashSet<>(), Arrays.asList("http://tenant", "http://non-present-tenant"));
    doTest(cd, new HashSet<>(), Arrays.asList("http://non-present-tenant"));
}
Also used : ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription) HashSet(java.util.HashSet) BaseModelTest(com.vmware.photon.controller.model.helpers.BaseModelTest) Test(org.junit.Test)

Example 17 with ComputeDescription

use of com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription in project photon-model by vmware.

the class EndpointAllocationTaskService method createEndpoint.

private void createEndpoint(EndpointAllocationTaskState currentState) {
    List<String> createdDocumentLinks = new ArrayList<>();
    EndpointState es = currentState.endpointState;
    Map<String, String> endpointProperties = currentState.endpointState.endpointProperties;
    es.endpointProperties = null;
    if (es.documentSelfLink == null) {
        es.documentSelfLink = UriUtils.buildUriPath(EndpointService.FACTORY_LINK, this.getHost().nextUUID());
    }
    // merge endpoint and task tenant links
    if (es.tenantLinks == null || es.tenantLinks.isEmpty()) {
        es.tenantLinks = currentState.tenantLinks;
    } else if (currentState.tenantLinks != null) {
        currentState.tenantLinks.forEach(tl -> {
            if (!es.tenantLinks.contains(tl)) {
                es.tenantLinks.add(tl);
            }
        });
    }
    Operation endpointOp = Operation.createPost(this, EndpointService.FACTORY_LINK);
    ComputeDescription computeDescription = configureDescription(currentState, es);
    ComputeState computeState = configureCompute(currentState, es, endpointProperties);
    Operation cdOp = createComputeDescriptionOp(currentState, computeDescription.documentSelfLink);
    Operation compOp = createComputeStateOp(currentState, computeState.documentSelfLink);
    // pool link
    if (currentState.enumerationRequest != null && currentState.enumerationRequest.resourcePoolLink != null) {
        es.resourcePoolLink = currentState.enumerationRequest.resourcePoolLink;
        computeState.resourcePoolLink = es.resourcePoolLink;
    }
    OperationSequence sequence;
    if (es.authCredentialsLink == null) {
        AuthCredentialsServiceState auth = configureAuth(es);
        Operation authOp = Operation.createPost(createInventoryUri(this.getHost(), AuthCredentialsService.FACTORY_LINK)).setBody(auth);
        sequence = OperationSequence.create(authOp).setCompletion((ops, exs) -> {
            if (exs != null) {
                long firstKey = exs.keySet().iterator().next();
                exs.values().forEach(ex -> logWarning(() -> String.format("Error in " + "sequence to create auth credentials: %s", ex.getMessage())));
                sendFailurePatch(this, currentState, exs.get(firstKey));
                return;
            }
            Operation o = ops.get(authOp.getId());
            AuthCredentialsServiceState authState = o.getBody(AuthCredentialsServiceState.class);
            computeDescription.authCredentialsLink = authState.documentSelfLink;
            es.authCredentialsLink = authState.documentSelfLink;
            cdOp.setBody(computeDescription);
        }).next(cdOp);
    } else {
        cdOp.setBody(computeDescription);
        sequence = OperationSequence.create(cdOp);
    }
    sequence = sequence.setCompletion((ops, exs) -> {
        if (exs != null) {
            long firstKey = exs.keySet().iterator().next();
            exs.values().forEach(ex -> logWarning(() -> String.format("Error in " + "sequence to create compute description: %s", ex.getMessage())));
            sendFailurePatch(this, currentState, exs.get(firstKey));
            return;
        }
        Operation o = ops.get(cdOp.getId());
        ComputeDescription desc = o.getBody(ComputeDescription.class);
        if (!currentState.accountAlreadyExists) {
            createdDocumentLinks.add(desc.documentSelfLink);
        }
        computeState.descriptionLink = desc.documentSelfLink;
        es.computeDescriptionLink = desc.documentSelfLink;
    });
    // Don't create resource pool, if a resource pool link was passed.
    if (es.resourcePoolLink == null) {
        Operation poolOp = createResourcePoolOp(es);
        sequence = sequence.next(poolOp).setCompletion((ops, exs) -> {
            if (exs != null) {
                long firstKey = exs.keySet().iterator().next();
                exs.values().forEach(ex -> logWarning(() -> String.format("Error creating resource" + " pool: %s", ex.getMessage())));
                sendFailurePatch(this, currentState, exs.get(firstKey));
                return;
            }
            Operation o = ops.get(poolOp.getId());
            ResourcePoolState poolState = o.getBody(ResourcePoolState.class);
            createdDocumentLinks.add(poolState.documentSelfLink);
            es.resourcePoolLink = poolState.documentSelfLink;
            computeState.resourcePoolLink = es.resourcePoolLink;
            compOp.setBody(computeState);
        });
    } else {
        Operation getPoolOp = Operation.createGet(this, es.resourcePoolLink);
        sequence = sequence.next(getPoolOp).setCompletion((ops, exs) -> {
            if (exs != null) {
                long firstKey = exs.keySet().iterator().next();
                exs.values().forEach(ex -> logWarning(() -> String.format("Error retrieving resource" + " pool: %s", ex.getMessage())));
                sendFailurePatch(this, currentState, exs.get(firstKey));
                return;
            }
            Operation o = ops.get(getPoolOp.getId());
            ResourcePoolState poolState = o.getBody(ResourcePoolState.class);
            if (poolState.customProperties != null) {
                String endpointLink = poolState.customProperties.get(ENDPOINT_LINK_PROP_NAME);
                if (endpointLink != null && endpointLink.equals(es.documentSelfLink)) {
                    sendFailurePatch(this, currentState, new IllegalStateException("Passed resource pool is associated with a different endpoint."));
                    return;
                }
            }
            es.resourcePoolLink = poolState.documentSelfLink;
            computeState.resourcePoolLink = es.resourcePoolLink;
            compOp.setBody(computeState);
        });
    }
    sequence.next(compOp).setCompletion((ops, exs) -> {
        if (exs != null) {
            long firstKey = exs.keySet().iterator().next();
            exs.values().forEach(ex -> logWarning(() -> String.format("Error in " + "sequence to create compute state: %s", ex.getMessage())));
            sendFailurePatch(this, currentState, exs.get(firstKey));
            return;
        }
        Operation csOp = ops.get(compOp.getId());
        ComputeState c = csOp.getBody(ComputeState.class);
        if (!currentState.accountAlreadyExists) {
            createdDocumentLinks.add(c.documentSelfLink);
        }
        es.computeLink = c.documentSelfLink;
        endpointOp.setBody(es);
    }).next(endpointOp).setCompletion((ops, exs) -> {
        if (exs != null) {
            long firstKey = exs.keySet().iterator().next();
            exs.values().forEach(ex -> logWarning(() -> String.format("Error in " + "sequence to create endpoint state: %s", ex.getMessage())));
            sendFailurePatch(this, currentState, exs.get(firstKey));
            return;
        }
        Operation esOp = ops.get(endpointOp.getId());
        EndpointState endpoint = esOp.getBody(EndpointState.class);
        createdDocumentLinks.add(endpoint.documentSelfLink);
        // propagate the endpoint properties to the next stage
        endpoint.endpointProperties = endpointProperties;
        EndpointAllocationTaskState state = createUpdateSubStageTask(SubStage.INVOKE_ADAPTER);
        state.endpointState = endpoint;
        state.createdDocumentLinks = createdDocumentLinks;
        sendSelfPatch(state);
    }).sendWith(this);
}
Also used : AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) CertificateInfoServiceErrorResponse(com.vmware.photon.controller.model.support.CertificateInfoServiceErrorResponse) ServiceTypeCluster(com.vmware.photon.controller.model.util.ClusterUtil.ServiceTypeCluster) ServiceDocument(com.vmware.xenon.common.ServiceDocument) Utils(com.vmware.xenon.common.Utils) EndpointService(com.vmware.photon.controller.model.resources.EndpointService) Map(java.util.Map) CUSTOM_PROP_ENDPOINT_LINK(com.vmware.photon.controller.model.constants.PhotonModelConstants.CUSTOM_PROP_ENDPOINT_LINK) ResourcePoolService(com.vmware.photon.controller.model.resources.ResourcePoolService) URI(java.net.URI) SINGLE_ASSIGNMENT(com.vmware.xenon.common.ServiceDocumentDescription.PropertyUsageOption.SINGLE_ASSIGNMENT) EnumSet(java.util.EnumSet) EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription) ENDPOINT_LINK_PROP_NAME(com.vmware.photon.controller.model.ComputeProperties.ENDPOINT_LINK_PROP_NAME) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) ServiceHost(com.vmware.xenon.common.ServiceHost) PhotonModelAdaptersConfigAccessService(com.vmware.photon.controller.model.adapters.registry.PhotonModelAdaptersConfigAccessService) OPTIONAL(com.vmware.xenon.common.ServiceDocumentDescription.PropertyUsageOption.OPTIONAL) List(java.util.List) RequestType(com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest.RequestType) TaskUtils.sendFailurePatch(com.vmware.photon.controller.model.tasks.TaskUtils.sendFailurePatch) CompletionHandler(com.vmware.xenon.common.Operation.CompletionHandler) SOURCE_TASK_LINK(com.vmware.photon.controller.model.constants.PhotonModelConstants.SOURCE_TASK_LINK) DeferredResult(com.vmware.xenon.common.DeferredResult) UriUtils(com.vmware.xenon.common.UriUtils) ComputeService(com.vmware.photon.controller.model.resources.ComputeService) TaskState(com.vmware.xenon.common.TaskState) TaskService(com.vmware.xenon.services.common.TaskService) AdapterTypePath(com.vmware.photon.controller.model.UriPaths.AdapterTypePath) STORE_ONLY(com.vmware.xenon.common.ServiceDocumentDescription.PropertyIndexingOption.STORE_ONLY) ResourcePoolState(com.vmware.photon.controller.model.resources.ResourcePoolService.ResourcePoolState) HashMap(java.util.HashMap) ComputeDescriptionService(com.vmware.photon.controller.model.resources.ComputeDescriptionService) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) EndpointConfigRequest(com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest) AuthCredentialsService(com.vmware.xenon.services.common.AuthCredentialsService) UriPaths(com.vmware.photon.controller.model.UriPaths) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) OperationSequence(com.vmware.xenon.common.OperationSequence) SERVICE_USE(com.vmware.xenon.common.ServiceDocumentDescription.PropertyUsageOption.SERVICE_USE) ResourceEnumerationTaskState(com.vmware.photon.controller.model.tasks.ResourceEnumerationTaskService.ResourceEnumerationTaskState) Operation(com.vmware.xenon.common.Operation) CertificateInfo(com.vmware.photon.controller.model.support.CertificateInfo) ScheduledTaskState(com.vmware.photon.controller.model.tasks.ScheduledTaskService.ScheduledTaskState) TaskStage(com.vmware.xenon.common.TaskState.TaskStage) TimeUnit(java.util.concurrent.TimeUnit) PhotonModelAdapterConfig(com.vmware.photon.controller.model.adapters.registry.PhotonModelAdaptersRegistryService.PhotonModelAdapterConfig) ClusterUtil(com.vmware.photon.controller.model.util.ClusterUtil) LocalizableValidationException(com.vmware.xenon.common.LocalizableValidationException) PropertyIndexingOption(com.vmware.xenon.common.ServiceDocumentDescription.PropertyIndexingOption) OperationJoin(com.vmware.xenon.common.OperationJoin) PhotonModelUriUtils.createInventoryUri(com.vmware.photon.controller.model.util.PhotonModelUriUtils.createInventoryUri) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) ResourcePoolState(com.vmware.photon.controller.model.resources.ResourcePoolService.ResourcePoolState) ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription) OperationSequence(com.vmware.xenon.common.OperationSequence) ArrayList(java.util.ArrayList) Operation(com.vmware.xenon.common.Operation) EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState)

Example 18 with ComputeDescription

use of com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription in project photon-model by vmware.

the class EndpointAllocationTaskService method configureDescription.

private ComputeDescription configureDescription(EndpointAllocationTaskState currentState, EndpointState state) {
    ComputeDescription cd;
    if (currentState.accountAlreadyExists && currentState.existingComputeDescription != null) {
        cd = currentState.existingComputeDescription;
        if (cd.endpointLinks == null) {
            cd.endpointLinks = new HashSet<>();
        }
        cd.endpointLinks.add(state.documentSelfLink);
        if (cd.tenantLinks == null) {
            cd.tenantLinks = new ArrayList<>();
        }
        cd.tenantLinks.addAll(currentState.tenantLinks);
        return cd;
    }
    cd = new ComputeDescription();
    // setting up a host, so all have ENDPOINT_HOST as a child
    cd.tenantLinks = state.tenantLinks;
    cd.endpointLink = state.documentSelfLink;
    if (cd.endpointLinks == null) {
        cd.endpointLinks = new HashSet<>();
    }
    cd.endpointLinks.add(state.documentSelfLink);
    cd.computeHostLink = state.computeHostLink;
    cd.authCredentialsLink = state.authCredentialsLink;
    cd.name = state.name;
    cd.regionId = state.regionId;
    cd.id = UUID.randomUUID().toString();
    cd.customProperties = new HashMap<>();
    if (state.customProperties != null) {
        cd.customProperties.putAll(state.customProperties);
    }
    cd.customProperties.put(CUSTOM_PROP_ENPOINT_TYPE, state.endpointType);
    cd.customProperties.put(SOURCE_TASK_LINK, EndpointAllocationTaskService.FACTORY_LINK);
    return cd;
}
Also used : ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription)

Example 19 with ComputeDescription

use of com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription in project photon-model by vmware.

the class ResourceAllocationTaskService method createDiskResources.

/**
 * Create disks to attach to the compute resource. Use the disk description links to figure out
 * what type of disks to create.
 *
 * @param currentState
 * @param parentLink
 * @param computeResourceId
 */
private void createDiskResources(ResourceAllocationTaskState currentState, ComputeDescription cd, String parentLink, String computeResourceId, String name, List<String> networkLinks) {
    if (cd.diskDescLinks == null || cd.diskDescLinks.isEmpty()) {
        createComputeResource(currentState, cd, parentLink, computeResourceId, name, new ArrayList<>(), networkLinks);
        return;
    }
    DeferredResult<List<String>> result = DeferredResult.allOf(cd.diskDescLinks.stream().map(link -> {
        Operation op = Operation.createGet(this, link);
        return this.sendWithDeferredResult(op, DiskState.class);
    }).map(dr -> dr.thenCompose(d -> {
        String link = d.documentSelfLink;
        // create a new disk based off the template but use a
        // unique ID
        d.id = UUID.randomUUID().toString();
        d.documentSelfLink = null;
        d.tenantLinks = currentState.tenantLinks;
        if (d.customProperties == null) {
            d.customProperties = new HashMap<>();
        }
        d.descriptionLink = link;
        return this.sendWithDeferredResult(Operation.createPost(this, DiskService.FACTORY_LINK).setBody(d), DiskState.class);
    })).map(dsr -> dsr.thenApply(ds -> ds.documentSelfLink)).collect(Collectors.toList()));
    result.whenComplete((diskLinks, e) -> {
        if (e != null) {
            logWarning(() -> String.format("Failure creating disk: %s", e.toString()));
            this.sendFailureSelfPatch(e);
            return;
        }
        // we have created all the disks. Now create the compute host
        // resource
        createComputeResource(currentState, cd, parentLink, computeResourceId, name, diskLinks, networkLinks);
    });
}
Also used : QueryTask(com.vmware.xenon.services.common.QueryTask) ServiceDocument(com.vmware.xenon.common.ServiceDocument) HashMap(java.util.HashMap) ComputeDescriptionService(com.vmware.photon.controller.model.resources.ComputeDescriptionService) ArrayList(java.util.ArrayList) ComputeType(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription.ComputeType) HashSet(java.util.HashSet) Utils(com.vmware.xenon.common.Utils) UriPaths(com.vmware.photon.controller.model.UriPaths) Map(java.util.Map) ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription) Iterator(java.util.Iterator) NetworkInterfaceState(com.vmware.photon.controller.model.resources.NetworkInterfaceService.NetworkInterfaceState) Collection(java.util.Collection) ResourceDescriptionService(com.vmware.photon.controller.model.resources.ResourceDescriptionService) Operation(com.vmware.xenon.common.Operation) QueryUtils(com.vmware.photon.controller.model.query.QueryUtils) DiskState(com.vmware.photon.controller.model.resources.DiskService.DiskState) Occurance(com.vmware.xenon.services.common.QueryTask.Query.Occurance) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) TaskStage(com.vmware.xenon.common.TaskState.TaskStage) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) NetworkInterfaceService(com.vmware.photon.controller.model.resources.NetworkInterfaceService) DeferredResult(com.vmware.xenon.common.DeferredResult) UriUtils(com.vmware.xenon.common.UriUtils) ComputeService(com.vmware.photon.controller.model.resources.ComputeService) TaskState(com.vmware.xenon.common.TaskState) CUSTOM_DISPLAY_NAME(com.vmware.photon.controller.model.ComputeProperties.CUSTOM_DISPLAY_NAME) NetworkInterfaceDescription(com.vmware.photon.controller.model.resources.NetworkInterfaceDescriptionService.NetworkInterfaceDescription) DiskService(com.vmware.photon.controller.model.resources.DiskService) TaskService(com.vmware.xenon.services.common.TaskService) ArrayList(java.util.ArrayList) List(java.util.List) Operation(com.vmware.xenon.common.Operation)

Example 20 with ComputeDescription

use of com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription in project photon-model by vmware.

the class ResourceGroomerTaskService method populateEndpointLinksByDocumentLinks.

/**
 * Helper for creating corresponding object and parsing the response for given documentKind
 * to store selfLink and endpointLink.
 */
private static void populateEndpointLinksByDocumentLinks(Map<String, Object> documents, Map<String, Set<String>> endpointLinksByDocumentLinks, Map<String, String> endpointLinkByDocumentLinks) {
    for (Object document : documents.values()) {
        ServiceDocument doc = Utils.fromJson(document, ServiceDocument.class);
        Set<String> endpointLinks = new HashSet<>();
        if (doc.documentKind.equals(COMPUTE_STATE_DOCUMENT_KIND)) {
            ComputeState state = Utils.fromJson(document, ComputeState.class);
            if (state.endpointLinks != null) {
                state.endpointLinks.remove(null);
                endpointLinks.addAll(state.endpointLinks);
            }
            endpointLinksByDocumentLinks.put(state.documentSelfLink, endpointLinks);
            endpointLinkByDocumentLinks.put(state.documentSelfLink, state.endpointLink != null ? state.endpointLink : EMPTY_STRING);
        } else if (doc.documentKind.equals(DISK_STATE_DOCUMENT_KIND)) {
            DiskState state = Utils.fromJson(document, DiskState.class);
            if (state.customProperties != null && state.customProperties.containsKey(ResourceUtils.CUSTOM_PROP_NO_ENDPOINT)) {
                // skip resources that have never been attached to a particular endpoint
                continue;
            }
            if (state.endpointLinks != null) {
                state.endpointLinks.remove(null);
                endpointLinks.addAll(state.endpointLinks);
            }
            endpointLinksByDocumentLinks.put(state.documentSelfLink, endpointLinks);
            endpointLinkByDocumentLinks.put(state.documentSelfLink, state.endpointLink != null ? state.endpointLink : EMPTY_STRING);
        } else if (doc.documentKind.equals(COMPUTE_DESCRIPTION_DOCUMENT_KIND)) {
            ComputeDescription state = Utils.fromJson(document, ComputeDescription.class);
            // only deleting discovered resources
            if (!(state.customProperties != null && (ResourceEnumerationTaskService.FACTORY_LINK.equals(state.customProperties.get(SOURCE_TASK_LINK)) || EndpointAllocationTaskService.FACTORY_LINK.equals(state.customProperties.get(SOURCE_TASK_LINK))))) {
                continue;
            }
            if (state.endpointLinks != null) {
                state.endpointLinks.remove(null);
                endpointLinks.addAll(state.endpointLinks);
            }
            endpointLinksByDocumentLinks.put(state.documentSelfLink, endpointLinks);
            endpointLinkByDocumentLinks.put(state.documentSelfLink, state.endpointLink != null ? state.endpointLink : EMPTY_STRING);
        } else if (doc.documentKind.equals(NETWORK_STATE_DOCUMENT_KIND)) {
            NetworkState state = Utils.fromJson(document, NetworkState.class);
            if (state.endpointLinks != null) {
                state.endpointLinks.remove(null);
                endpointLinks.addAll(state.endpointLinks);
            }
            endpointLinksByDocumentLinks.put(state.documentSelfLink, endpointLinks);
            endpointLinkByDocumentLinks.put(state.documentSelfLink, state.endpointLink != null ? state.endpointLink : EMPTY_STRING);
        } else if (doc.documentKind.equals(NETWORK_INTERFACE_STATE_DOCUMENT_KIND)) {
            NetworkInterfaceState state = Utils.fromJson(document, NetworkInterfaceState.class);
            if (state.endpointLinks != null) {
                state.endpointLinks.remove(null);
                endpointLinks.addAll(state.endpointLinks);
            }
            endpointLinksByDocumentLinks.put(state.documentSelfLink, endpointLinks);
            endpointLinkByDocumentLinks.put(state.documentSelfLink, state.endpointLink != null ? state.endpointLink : EMPTY_STRING);
        } else if (doc.documentKind.equals(SECURITY_GROUP_STATE_DOCUMENT_KIND)) {
            SecurityGroupState state = Utils.fromJson(document, SecurityGroupState.class);
            if (state.endpointLinks != null) {
                state.endpointLinks.remove(null);
                endpointLinks.addAll(state.endpointLinks);
            }
            endpointLinksByDocumentLinks.put(state.documentSelfLink, endpointLinks);
            endpointLinkByDocumentLinks.put(state.documentSelfLink, state.endpointLink != null ? state.endpointLink : EMPTY_STRING);
        } else if (doc.documentKind.equals(SUBNET_STATE_DOCUMENT_KIND)) {
            SubnetState state = Utils.fromJson(document, SubnetState.class);
            if (state.endpointLinks != null) {
                state.endpointLinks.remove(null);
                endpointLinks.addAll(state.endpointLinks);
            }
            endpointLinksByDocumentLinks.put(state.documentSelfLink, endpointLinks);
            endpointLinkByDocumentLinks.put(state.documentSelfLink, state.endpointLink != null ? state.endpointLink : EMPTY_STRING);
        } else if (doc.documentKind.equals(LOAD_BALANCER_DOCUMENT_KIND)) {
            LoadBalancerState state = Utils.fromJson(document, LoadBalancerState.class);
            if (state.endpointLinks != null) {
                state.endpointLinks.remove(null);
                endpointLinks.addAll(state.endpointLinks);
            }
            endpointLinksByDocumentLinks.put(state.documentSelfLink, endpointLinks);
            endpointLinkByDocumentLinks.put(state.documentSelfLink, state.endpointLink != null ? state.endpointLink : EMPTY_STRING);
        } else if (doc.documentKind.equals(STORAGE_DESCRIPTION_DOCUMENT_KIND)) {
            StorageDescription state = Utils.fromJson(document, StorageDescription.class);
            if (state.endpointLinks != null) {
                state.endpointLinks.remove(null);
                endpointLinks.addAll(state.endpointLinks);
            }
            endpointLinksByDocumentLinks.put(state.documentSelfLink, endpointLinks);
            endpointLinkByDocumentLinks.put(state.documentSelfLink, state.endpointLink != null ? state.endpointLink : EMPTY_STRING);
        } else if (doc.documentKind.equals(RESOURCE_GROUP_DOCUMENT_KIND)) {
            ResourceGroupState state = Utils.fromJson(document, ResourceGroupState.class);
            if (state.customProperties != null && state.customProperties.containsKey(ResourceGroupService.PROPERTY_NAME_IS_USER_CREATED)) {
                continue;
            }
            if (state.customProperties != null && state.customProperties.containsKey(ResourceUtils.CUSTOM_PROP_NO_ENDPOINT)) {
                // skip resources that have never been attached to a particular endpoint
                continue;
            }
            if (state.endpointLinks != null) {
                state.endpointLinks.remove(null);
                endpointLinks.addAll(state.endpointLinks);
            }
            endpointLinksByDocumentLinks.put(state.documentSelfLink, endpointLinks);
            endpointLinkByDocumentLinks.put(state.documentSelfLink, state.endpointLink != null ? state.endpointLink : EMPTY_STRING);
        } else if (doc.documentKind.equals(IMAGE_STATE_KIND)) {
            ImageState state = Utils.fromJson(document, ImageState.class);
            if (state.endpointLinks != null) {
                state.endpointLinks.remove(null);
                endpointLinks.addAll(state.endpointLinks);
            }
            endpointLinksByDocumentLinks.put(state.documentSelfLink, endpointLinks);
            endpointLinkByDocumentLinks.put(state.documentSelfLink, state.endpointLink != null ? state.endpointLink : EMPTY_STRING);
        } else if (doc.documentKind.equals(ROUTER_STATE_KIND)) {
            RouterState state = Utils.fromJson(document, RouterState.class);
            if (state.endpointLinks != null) {
                state.endpointLinks.remove(null);
                endpointLinks.addAll(state.endpointLinks);
            }
            endpointLinksByDocumentLinks.put(state.documentSelfLink, endpointLinks);
            endpointLinkByDocumentLinks.put(state.documentSelfLink, state.endpointLink != null ? state.endpointLink : EMPTY_STRING);
        } else if (doc.documentKind.equals(AUTH_CREDENTIALS_SERVICE_STATE_KIND)) {
            AuthCredentialsServiceState state = Utils.fromJson(document, AuthCredentialsServiceState.class);
            if (state.customProperties != null && state.customProperties.get(CUSTOM_PROP_ENDPOINT_LINK) != null) {
                endpointLinkByDocumentLinks.put(state.documentSelfLink, state.customProperties.get(CUSTOM_PROP_ENDPOINT_LINK));
            } else {
                endpointLinkByDocumentLinks.put(state.documentSelfLink, EMPTY_STRING);
            }
        }
    }
}
Also used : ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription) NetworkInterfaceState(com.vmware.photon.controller.model.resources.NetworkInterfaceService.NetworkInterfaceState) SecurityGroupState(com.vmware.photon.controller.model.resources.SecurityGroupService.SecurityGroupState) ResourceGroupState(com.vmware.photon.controller.model.resources.ResourceGroupService.ResourceGroupState) RouterState(com.vmware.photon.controller.model.resources.RouterService.RouterState) DiskState(com.vmware.photon.controller.model.resources.DiskService.DiskState) SubnetState(com.vmware.photon.controller.model.resources.SubnetService.SubnetState) LoadBalancerState(com.vmware.photon.controller.model.resources.LoadBalancerService.LoadBalancerState) StorageDescription(com.vmware.photon.controller.model.resources.StorageDescriptionService.StorageDescription) AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) ServiceDocument(com.vmware.xenon.common.ServiceDocument) NetworkState(com.vmware.photon.controller.model.resources.NetworkService.NetworkState) HashSet(java.util.HashSet) ImageState(com.vmware.photon.controller.model.resources.ImageService.ImageState)

Aggregations

ComputeDescription (com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription)78 ComputeState (com.vmware.photon.controller.model.resources.ComputeService.ComputeState)39 Operation (com.vmware.xenon.common.Operation)21 ArrayList (java.util.ArrayList)21 QueryTask (com.vmware.xenon.services.common.QueryTask)17 Test (org.junit.Test)17 ComputeDescriptionService (com.vmware.photon.controller.model.resources.ComputeDescriptionService)15 ComputeService (com.vmware.photon.controller.model.resources.ComputeService)15 HashMap (java.util.HashMap)15 HashSet (java.util.HashSet)15 List (java.util.List)15 Utils (com.vmware.xenon.common.Utils)14 AuthCredentialsServiceState (com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState)14 URI (java.net.URI)14 QueryUtils (com.vmware.photon.controller.model.query.QueryUtils)13 ResourcePoolState (com.vmware.photon.controller.model.resources.ResourcePoolService.ResourcePoolState)12 ServiceDocumentQueryResult (com.vmware.xenon.common.ServiceDocumentQueryResult)12 UriUtils (com.vmware.xenon.common.UriUtils)12 ComputeType (com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription.ComputeType)11 EndpointState (com.vmware.photon.controller.model.resources.EndpointService.EndpointState)11