Search in sources :

Example 1 with EndpointState

use of com.vmware.photon.controller.model.resources.EndpointService.EndpointState in project photon-model by vmware.

the class AzureComputeEnumerationAdapterService method collectRegions.

private void collectRegions(EnumerationContext ctx, ComputeEnumerationSubStages next) {
    Operation getEndpoint = Operation.createGet(this, ctx.request.endpointLink);
    DeferredResult<EndpointState> getEndpointDR = sendWithDeferredResult(getEndpoint, EndpointState.class);
    getEndpointDR.thenCompose(endpoint -> {
        Operation getRegions = Operation.createPost(this, AzureRegionEnumerationAdapterService.SELF_LINK).setBody(endpoint);
        return sendWithDeferredResult(getRegions, RegionEnumerationResponse.class);
    }).whenComplete((regionsResponse, e) -> {
        if (e != null) {
            logWarning("Resource enumeration failed at stage %s with exception %s", ctx.stage, Utils.toString(e));
            handleError(ctx, e);
        } else {
            ctx.regions.putAll(regionsResponse.regions.stream().collect(Collectors.toMap(r -> r.regionId, r -> r)));
            ctx.regionIds.addAll(ctx.regions.keySet());
            ctx.subStage = next;
            handleSubStage(ctx);
        }
    });
}
Also used : EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) PowerState(com.vmware.photon.controller.model.resources.ComputeService.PowerState) Arrays(java.util.Arrays) ComputeEnumerateResourceRequest(com.vmware.photon.controller.model.adapterapi.ComputeEnumerateResourceRequest) ServiceTypeCluster(com.vmware.photon.controller.model.util.ClusterUtil.ServiceTypeCluster) LifecycleState(com.vmware.photon.controller.model.resources.ComputeService.LifecycleState) DISK_CONTROLLER_NUMBER(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.DISK_CONTROLLER_NUMBER) Action1(rx.functions.Action1) StringUtils(org.apache.commons.lang3.StringUtils) Azure(com.microsoft.azure.management.Azure) Utils(com.vmware.xenon.common.Utils) Pair(org.apache.commons.lang3.tuple.Pair) SubnetState(com.vmware.photon.controller.model.resources.SubnetService.SubnetState) Map(java.util.Map) StorageDescription(com.vmware.photon.controller.model.resources.StorageDescriptionService.StorageDescription) OSDisk(com.microsoft.azure.management.compute.OSDisk) ResourceEnumerationTaskService(com.vmware.photon.controller.model.tasks.ResourceEnumerationTaskService) NetworkInterfaceState(com.vmware.photon.controller.model.resources.NetworkInterfaceService.NetworkInterfaceState) StatelessService(com.vmware.xenon.common.StatelessService) Set(java.util.Set) NetworkInterfaceService(com.vmware.photon.controller.model.resources.NetworkInterfaceService) StorageAccountTypes(com.microsoft.azure.management.compute.StorageAccountTypes) TagService(com.vmware.photon.controller.model.resources.TagService) CompletionHandler(com.vmware.xenon.common.Operation.CompletionHandler) SOURCE_TASK_LINK(com.vmware.photon.controller.model.constants.PhotonModelConstants.SOURCE_TASK_LINK) InstanceViewStatus(com.microsoft.azure.management.compute.InstanceViewStatus) DeferredResult(com.vmware.xenon.common.DeferredResult) UriUtils(com.vmware.xenon.common.UriUtils) ComputeService(com.vmware.photon.controller.model.resources.ComputeService) NumericRange(com.vmware.xenon.services.common.QueryTask.NumericRange) AZURE_DATA_DISK_CACHING(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AZURE_DATA_DISK_CACHING) ImageReferenceInner(com.microsoft.azure.management.compute.implementation.ImageReferenceInner) VirtualMachinesInner(com.microsoft.azure.management.compute.implementation.VirtualMachinesInner) ComputeDescriptionService(com.vmware.photon.controller.model.resources.ComputeDescriptionService) PhotonModelUtils(com.vmware.photon.controller.model.resources.util.PhotonModelUtils) RegionInfo(com.vmware.photon.controller.model.adapterapi.RegionEnumerationResponse.RegionInfo) TagsUtil(com.vmware.photon.controller.model.adapters.util.TagsUtil) ArrayList(java.util.ArrayList) TagState(com.vmware.photon.controller.model.resources.TagService.TagState) ServiceStateCollectionUpdateRequest(com.vmware.xenon.common.ServiceStateCollectionUpdateRequest) Query(com.vmware.xenon.services.common.QueryTask.Query) EnumerationStages(com.vmware.photon.controller.model.adapters.util.enums.EnumerationStages) OperatingSystemTypes(com.microsoft.azure.management.compute.OperatingSystemTypes) BiConsumer(java.util.function.BiConsumer) AZURE_DIAGNOSTIC_STORAGE_ACCOUNT_LINK(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AZURE_DIAGNOSTIC_STORAGE_ACCOUNT_LINK) AZURE_STORAGE_ACCOUNT_URI(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AZURE_STORAGE_ACCOUNT_URI) VirtualMachineInner(com.microsoft.azure.management.compute.implementation.VirtualMachineInner) AdapterUtils(com.vmware.photon.controller.model.adapters.util.AdapterUtils) DataDisk(com.microsoft.azure.management.compute.DataDisk) ResourceState(com.vmware.photon.controller.model.resources.ResourceState) QueryUtils(com.vmware.photon.controller.model.query.QueryUtils) ENVIRONMENT_NAME_AZURE(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription.ENVIRONMENT_NAME_AZURE) QueryTop(com.vmware.photon.controller.model.query.QueryUtils.QueryTop) CUSTOM_OS_TYPE(com.vmware.photon.controller.model.ComputeProperties.CUSTOM_OS_TYPE) ComputeStateWithDescription(com.vmware.photon.controller.model.resources.ComputeService.ComputeStateWithDescription) PhotonModelConstants(com.vmware.photon.controller.model.constants.PhotonModelConstants) ComputeEnumerateAdapterRequest(com.vmware.photon.controller.model.adapters.util.ComputeEnumerateAdapterRequest) RegionEnumerationResponse(com.vmware.photon.controller.model.adapterapi.RegionEnumerationResponse) QuerySpecification(com.vmware.xenon.services.common.QueryTask.QuerySpecification) PhotonModelUriUtils.createInventoryUri(com.vmware.photon.controller.model.util.PhotonModelUriUtils.createInventoryUri) AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) QueryTask(com.vmware.xenon.services.common.QueryTask) AZURE_RESOURCE_GROUP_NAME(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AZURE_RESOURCE_GROUP_NAME) OSType(com.vmware.photon.controller.model.ComputeProperties.OSType) AzureUriPaths(com.vmware.photon.controller.model.adapters.azure.AzureUriPaths) AZURE_MANAGED_DISK_TYPE(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AZURE_MANAGED_DISK_TYPE) ComputeType(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription.ComputeType) AzureSdkClients(com.vmware.photon.controller.model.adapters.azure.utils.AzureSdkClients) AzureUtils.injectOperationContext(com.vmware.photon.controller.model.adapters.azure.utils.AzureUtils.injectOperationContext) CUSTOM_PROP_ENDPOINT_LINK(com.vmware.photon.controller.model.constants.PhotonModelConstants.CUSTOM_PROP_ENDPOINT_LINK) URI(java.net.URI) TagsUtil.newTagState(com.vmware.photon.controller.model.adapters.util.TagsUtil.newTagState) EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) AzureConstants(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants) AzureConstants.getQueryResultLimit(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.getQueryResultLimit) ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) 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) List(java.util.List) AzureUtils(com.vmware.photon.controller.model.adapters.azure.utils.AzureUtils) AzureUtils.getResourceGroupName(com.vmware.photon.controller.model.adapters.azure.utils.AzureUtils.getResourceGroupName) TAG_KEY_TYPE(com.vmware.photon.controller.model.constants.PhotonModelConstants.TAG_KEY_TYPE) Entry(java.util.Map.Entry) NetworkInterfacesInner(com.microsoft.azure.management.network.implementation.NetworkInterfacesInner) QueryOption(com.vmware.xenon.services.common.QueryTask.QuerySpecification.QueryOption) InstanceViewTypes(com.microsoft.azure.management.compute.InstanceViewTypes) TagsUtil.setTagLinksToResourceState(com.vmware.photon.controller.model.adapters.util.TagsUtil.setTagLinksToResourceState) Builder(com.vmware.xenon.services.common.QueryTask.Query.Builder) DiskService(com.vmware.photon.controller.model.resources.DiskService) AzureUtils.isDiskManaged(com.vmware.photon.controller.model.adapters.azure.utils.AzureUtils.isDiskManaged) Default(com.vmware.photon.controller.model.adapters.azure.utils.AzureDeferredResultServiceCallback.Default) QueryByPages(com.vmware.photon.controller.model.query.QueryUtils.QueryByPages) AZURE_OSDISK_CACHING(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AZURE_OSDISK_CACHING) PublicIPAddress(com.microsoft.azure.management.network.PublicIPAddress) HashMap(java.util.HashMap) HashSet(java.util.HashSet) AuthCredentialsService(com.vmware.xenon.services.common.AuthCredentialsService) TagsUtil.updateLocalTagStates(com.vmware.photon.controller.model.adapters.util.TagsUtil.updateLocalTagStates) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) EnumerationAction(com.vmware.photon.controller.model.adapterapi.EnumerationAction) AzureResourceType(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AzureResourceType) ExecutorService(java.util.concurrent.ExecutorService) Iterator(java.util.Iterator) NetworkInterfaceIPConfigurationInner(com.microsoft.azure.management.network.implementation.NetworkInterfaceIPConfigurationInner) Operation(com.vmware.xenon.common.Operation) Page(com.microsoft.azure.Page) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) NetworkInterfaceReferenceInner(com.microsoft.azure.management.compute.implementation.NetworkInterfaceReferenceInner) AzureDeferredResultServiceCallback(com.vmware.photon.controller.model.adapters.azure.utils.AzureDeferredResultServiceCallback) NetworkInterfaceInner(com.microsoft.azure.management.network.implementation.NetworkInterfaceInner) Collections(java.util.Collections) OperationJoin(com.vmware.xenon.common.OperationJoin) RESOURCE_GROUP_NAME(com.vmware.photon.controller.model.ComputeProperties.RESOURCE_GROUP_NAME) RegionEnumerationResponse(com.vmware.photon.controller.model.adapterapi.RegionEnumerationResponse) Operation(com.vmware.xenon.common.Operation)

Example 2 with EndpointState

use of com.vmware.photon.controller.model.resources.EndpointService.EndpointState in project photon-model by vmware.

the class AzureSubscriptionEndpointCreationService method handleSubscriptionEndpointCreationRequest.

private void handleSubscriptionEndpointCreationRequest(AzureSubscriptionEndpointCreationRequest request, Operation parentOp) {
    // If request.subscriptionId is null, just complete the parentOp
    if (request.subscriptionId == null) {
        parentOp.complete();
        return;
    }
    // Fail the request if resourceReference to Azure EA endpoint is not provided
    if (request.resourceReference == null) {
        parentOp.fail(new IllegalArgumentException("reference to parent endpointLink is required"));
    }
    Operation endpointStateOp = Operation.createGet(request.resourceReference).setCompletion((o, e) -> {
        if (e != null) {
            parentOp.fail(e);
            return;
        }
        EndpointState endpointState = o.getBody(EndpointState.class);
        createSubscriptionEndpoint(endpointState, request, parentOp);
    });
    this.sendRequest(endpointStateOp);
}
Also used : EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) Operation(com.vmware.xenon.common.Operation)

Example 3 with EndpointState

use of com.vmware.photon.controller.model.resources.EndpointService.EndpointState in project photon-model by vmware.

the class AzureSubscriptionEndpointCreationService method createSubscriptionEndpoint.

private void createSubscriptionEndpoint(EndpointState azureEaEndpoint, AzureSubscriptionEndpointCreationRequest request, Operation parentOp) {
    Operation authOp = Operation.createPost(UriUtils.extendUri(getInventoryServiceUri(), AuthCredentialsService.FACTORY_LINK));
    Operation cdOp = Operation.createPost(UriUtils.extendUri(getInventoryServiceUri(), ComputeDescriptionService.FACTORY_LINK));
    Operation csOp = Operation.createPost(UriUtils.extendUri(getInventoryServiceUri(), ComputeService.FACTORY_LINK));
    Operation endPointOp = Operation.createPost(UriUtils.extendUri(getInventoryServiceUri(), EndpointService.FACTORY_LINK));
    AuthCredentialsServiceState authCredentialsState = createAuthCredentialsState(azureEaEndpoint, request);
    EndpointState endpointState = createEndpointState(azureEaEndpoint, request);
    ComputeDescription computeDescState = AzureUtils.constructAzureSubscriptionComputeDescription(endpointState.documentSelfLink, azureEaEndpoint.tenantLinks, request.subscriptionId, null, null, endpointState.computeLink);
    authOp.setBody(authCredentialsState);
    OperationSequence sequence = OperationSequence.create(authOp).setCompletion((ops, exs) -> {
        if (exs != null) {
            handleFailure(exs, parentOp);
            return;
        }
        Operation o = ops.get(authOp.getId());
        AuthCredentialsServiceState authState = o.getBody(AuthCredentialsServiceState.class);
        computeDescState.authCredentialsLink = authState.documentSelfLink;
        endpointState.authCredentialsLink = authState.documentSelfLink;
        cdOp.setBody(computeDescState);
    }).next(cdOp).setCompletion((ops, exs) -> {
        if (exs != null) {
            handleFailure(exs, parentOp);
            return;
        }
        Operation o = ops.get(cdOp.getId());
        ComputeDescription cd = o.getBody(ComputeDescription.class);
        ComputeState cs = AzureUtils.constructAzureSubscriptionComputeState(endpointState.documentSelfLink, cd.documentSelfLink, azureEaEndpoint.tenantLinks, request.subscriptionId, azureEaEndpoint.resourcePoolLink, getCustomPropertiesMap(endpointState, request), null, endpointState.computeLink);
        csOp.setBody(cs);
        endpointState.computeDescriptionLink = cd.documentSelfLink;
    }).next(csOp).setCompletion((ops, exs) -> {
        if (exs != null) {
            handleFailure(exs, parentOp);
            return;
        }
        Operation o = ops.get(csOp.getId());
        ComputeState cs = o.getBody(ComputeState.class);
        endpointState.computeLink = cs.documentSelfLink;
        endPointOp.setBody(endpointState);
    }).next(endPointOp).setCompletion((ops, exs) -> {
        if (exs != null) {
            handleFailure(exs, parentOp);
            return;
        }
        Operation o = ops.get(endPointOp.getId());
        EndpointState es = o.getBody(EndpointState.class);
        parentOp.setBody(es);
        parentOp.complete();
    });
    sequence.sendWith(this);
}
Also used : EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription) OperationSequence(com.vmware.xenon.common.OperationSequence) Operation(com.vmware.xenon.common.Operation)

Example 4 with EndpointState

use of com.vmware.photon.controller.model.resources.EndpointService.EndpointState in project photon-model by vmware.

the class AzureSubscriptionEndpointCreationService method createEndpointState.

private EndpointState createEndpointState(EndpointState azureEaEndpoint, AzureSubscriptionEndpointCreationRequest request) {
    EndpointState endpointState = new EndpointState();
    endpointState.documentSelfLink = UriUtils.buildUriPath(EndpointService.FACTORY_LINK, this.getHost().nextUUID());
    endpointState.endpointType = EndpointType.azure.name();
    endpointState.resourcePoolLink = azureEaEndpoint.resourcePoolLink;
    endpointState.tenantLinks = azureEaEndpoint.tenantLinks;
    Map<String, String> endpointProperties = new HashMap<>();
    endpointProperties.put(EndpointConfigRequest.USER_LINK_KEY, request.subscriptionId);
    endpointState.endpointProperties = endpointProperties;
    endpointState.parentLink = azureEaEndpoint.documentSelfLink;
    endpointState.name = String.format(COMPUTES_NAME_FORMAT, EndpointType.azure.name(), request.subscriptionId);
    return endpointState;
}
Also used : EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) HashMap(java.util.HashMap)

Example 5 with EndpointState

use of com.vmware.photon.controller.model.resources.EndpointService.EndpointState in project photon-model by vmware.

the class AzureSubscriptionEndpointsEnumerationService method fetchExistingSubscriptionEndpoints.

private void fetchExistingSubscriptionEndpoints(AzureSubscriptionEndpointsEnumerationContext enumerationContext, AzureSubscriptionEndpointComputeEnumerationStages nextStage) {
    Query azureEndpointsQuery = createQueryForAzureSubscriptionEndpoints(enumerationContext);
    // Use Top query with 10K max EndpointStates
    QueryTop<EndpointState> querySubscriptionEndpoints = new QueryTop<>(getHost(), azureEndpointsQuery, EndpointState.class, enumerationContext.parent.tenantLinks);
    querySubscriptionEndpoints.setClusterType(ServiceTypeCluster.INVENTORY_SERVICE);
    querySubscriptionEndpoints.queryDocuments(epState -> {
        if (epState.endpointProperties != null && epState.endpointProperties.containsKey(EndpointConfigRequest.USER_LINK_KEY)) {
            String subscriptionUuid = epState.endpointProperties.get(EndpointConfigRequest.USER_LINK_KEY);
            enumerationContext.idToSubscription.remove(subscriptionUuid);
        }
    }).whenComplete((aVoid, t) -> {
        if (t != null) {
            getFailureConsumer(enumerationContext).accept(t);
            return;
        }
        enumerationContext.stage = nextStage;
        handleAzureCostComputeEnumerationRequest(enumerationContext);
    });
}
Also used : EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) AdapterUtils(com.vmware.photon.controller.model.adapters.util.AdapterUtils) StatelessService(com.vmware.xenon.common.StatelessService) Collection(java.util.Collection) ServiceTypeCluster(com.vmware.photon.controller.model.util.ClusterUtil.ServiceTypeCluster) Operation(com.vmware.xenon.common.Operation) AzureUriPaths(com.vmware.photon.controller.model.adapters.azure.AzureUriPaths) BaseAdapterStage(com.vmware.photon.controller.model.adapters.util.BaseAdapterContext.BaseAdapterStage) BaseAdapterContext(com.vmware.photon.controller.model.adapters.util.BaseAdapterContext) Collectors(java.util.stream.Collectors) QueryTop(com.vmware.photon.controller.model.query.QueryUtils.QueryTop) ResourceRequest(com.vmware.photon.controller.model.adapterapi.ResourceRequest) Consumer(java.util.function.Consumer) Utils(com.vmware.xenon.common.Utils) EndpointConfigRequest(com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest) Query(com.vmware.xenon.services.common.QueryTask.Query) AzureSubscriptionEndpointCreationRequest(com.vmware.photon.controller.model.adapters.azure.ea.enumeration.AzureSubscriptionEndpointCreationService.AzureSubscriptionEndpointCreationRequest) ClusterUtil(com.vmware.photon.controller.model.util.ClusterUtil) Map(java.util.Map) UriUtils(com.vmware.xenon.common.UriUtils) EndpointType(com.vmware.photon.controller.model.constants.PhotonModelConstants.EndpointType) AzureSubscription(com.vmware.photon.controller.model.adapters.azure.model.cost.AzureSubscription) OperationJoin(com.vmware.xenon.common.OperationJoin) EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) Query(com.vmware.xenon.services.common.QueryTask.Query) QueryTop(com.vmware.photon.controller.model.query.QueryUtils.QueryTop)

Aggregations

EndpointState (com.vmware.photon.controller.model.resources.EndpointService.EndpointState)69 ComputeState (com.vmware.photon.controller.model.resources.ComputeService.ComputeState)23 Operation (com.vmware.xenon.common.Operation)22 Test (org.junit.Test)16 AuthCredentialsServiceState (com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState)15 ComputeDescription (com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription)14 EndpointAllocationTaskState (com.vmware.photon.controller.model.tasks.EndpointAllocationTaskService.EndpointAllocationTaskState)13 URI (java.net.URI)13 HashMap (java.util.HashMap)13 Query (com.vmware.xenon.services.common.QueryTask.Query)12 ComputeService (com.vmware.photon.controller.model.resources.ComputeService)11 UriUtils (com.vmware.xenon.common.UriUtils)11 Utils (com.vmware.xenon.common.Utils)11 List (java.util.List)11 ImageState (com.vmware.photon.controller.model.resources.ImageService.ImageState)10 ServiceDocument (com.vmware.xenon.common.ServiceDocument)10 Collectors (java.util.stream.Collectors)10 ResourcePoolState (com.vmware.photon.controller.model.resources.ResourcePoolService.ResourcePoolState)9 ArrayList (java.util.ArrayList)9 HashSet (java.util.HashSet)9