Search in sources :

Example 21 with ComputeState

use of com.vmware.photon.controller.model.resources.ComputeService.ComputeState in project photon-model by vmware.

the class AzureCostStatsService method setCustomProperty.

private void setCustomProperty(Context context, String key, String value, Stages next) {
    context.computeHostDesc.customProperties.put(key, value);
    ComputeState accountState = new ComputeState();
    accountState.customProperties = new HashMap<>();
    accountState.customProperties.put(key, value);
    sendRequest(Operation.createPatch(UriUtils.extendUri(getInventoryServiceUri(), context.computeHostDesc.documentSelfLink)).setBody(accountState).setCompletion((operation, exception) -> {
        if (exception != null) {
            handleError(context, null, exception, false);
            return;
        }
        context.stage = next;
        handleRequest(context);
    }));
}
Also used : AzureCostConstants(com.vmware.photon.controller.model.adapters.azure.constants.AzureCostConstants) AzureStatsNormalizer(com.vmware.photon.controller.model.adapters.azure.utils.AzureStatsNormalizer) AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) Arrays(java.util.Arrays) DateTimeZone(org.joda.time.DateTimeZone) ServiceTypeCluster(com.vmware.photon.controller.model.util.ClusterUtil.ServiceTypeCluster) QueryTask(com.vmware.xenon.services.common.QueryTask) ServiceDocument(com.vmware.xenon.common.ServiceDocument) AzureUriPaths(com.vmware.photon.controller.model.adapters.azure.AzureUriPaths) StringUtils(org.apache.commons.lang3.StringUtils) ComputeType(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription.ComputeType) EndpointAllocationTaskService(com.vmware.photon.controller.model.tasks.EndpointAllocationTaskService) SingleResourceStatsCollectionTaskState(com.vmware.photon.controller.model.tasks.monitoring.SingleResourceStatsCollectionTaskService.SingleResourceStatsCollectionTaskState) Utils(com.vmware.xenon.common.Utils) BufferedSink(okio.BufferedSink) Map(java.util.Map) AzureService(com.vmware.photon.controller.model.adapters.azure.model.cost.AzureService) URI(java.net.URI) AzureSubscriptionsEnumerationRequest(com.vmware.photon.controller.model.adapters.azure.ea.enumeration.AzureSubscriptionsEnumerationService.AzureSubscriptionsEnumerationRequest) Builder(com.vmware.xenon.services.common.QueryTask.Builder) Path(java.nio.file.Path) EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) Interceptor(okhttp3.Interceptor) ComputeStatsResponse(com.vmware.photon.controller.model.adapterapi.ComputeStatsResponse) AzureDetailedBillHandler(com.vmware.photon.controller.model.adapters.azure.ea.utils.AzureDetailedBillHandler) Request(okhttp3.Request) ComputeStatsRequest(com.vmware.photon.controller.model.adapterapi.ComputeStatsRequest) StatelessService(com.vmware.xenon.common.StatelessService) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) OldEaSummarizedBillElement(com.vmware.photon.controller.model.adapters.azure.model.cost.OldEaSummarizedBillElement) TaskManager(com.vmware.photon.controller.model.adapters.util.TaskManager) Set(java.util.Set) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) AzureSubscriptionsEnumerationService(com.vmware.photon.controller.model.adapters.azure.ea.enumeration.AzureSubscriptionsEnumerationService) AzureCostHelper(com.vmware.photon.controller.model.adapters.azure.ea.utils.AzureCostHelper) List(java.util.List) Stream(java.util.stream.Stream) UriUtils(com.vmware.xenon.common.UriUtils) Entry(java.util.Map.Entry) QueryOption(com.vmware.xenon.services.common.QueryTask.QuerySpecification.QueryOption) INTERNAL_REQUEST_TIMEOUT_SECONDS(com.vmware.photon.controller.model.adapters.azure.constants.AzureCostConstants.INTERNAL_REQUEST_TIMEOUT_SECONDS) ResourceMetrics(com.vmware.photon.controller.model.monitoring.ResourceMetricsService.ResourceMetrics) SingleResourceTaskCollectionStage(com.vmware.photon.controller.model.tasks.monitoring.SingleResourceStatsCollectionTaskService.SingleResourceTaskCollectionStage) Okio(okio.Okio) QueryByPages(com.vmware.photon.controller.model.query.QueryUtils.QueryByPages) OperationContext(com.vmware.xenon.common.OperationContext) AtomicDouble(com.google.common.util.concurrent.AtomicDouble) HashMap(java.util.HashMap) Function(java.util.function.Function) AzureResource(com.vmware.photon.controller.model.adapters.azure.model.cost.AzureResource) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) EndpointConfigRequest(com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest) Query(com.vmware.xenon.services.common.QueryTask.Query) CollectionUtils(org.apache.commons.collections.CollectionUtils) EaBillLinkElement(com.vmware.photon.controller.model.adapters.azure.model.cost.EaBillLinkElement) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) AUTO_DISCOVERED_ENTITY(com.vmware.photon.controller.model.constants.PhotonModelConstants.AUTO_DISCOVERED_ENTITY) EaBillLinks(com.vmware.photon.controller.model.adapters.azure.model.cost.EaBillLinks) BiConsumer(java.util.function.BiConsumer) Response(okhttp3.Response) EndpointType(com.vmware.photon.controller.model.constants.PhotonModelConstants.EndpointType) Call(okhttp3.Call) Callback(okhttp3.Callback) AzureSubscription(com.vmware.photon.controller.model.adapters.azure.model.cost.AzureSubscription) ComputeStats(com.vmware.photon.controller.model.adapterapi.ComputeStatsResponse.ComputeStats) ExecutorService(java.util.concurrent.ExecutorService) OldApi(com.vmware.photon.controller.model.adapters.azure.model.cost.OldApi) AdapterUtils(com.vmware.photon.controller.model.adapters.util.AdapterUtils) ServiceErrorResponse(com.vmware.xenon.common.ServiceErrorResponse) Files(java.nio.file.Files) Operation(com.vmware.xenon.common.Operation) QueryUtils(com.vmware.photon.controller.model.query.QueryUtils) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) TypeName(com.vmware.xenon.common.ServiceDocumentDescription.TypeName) ServiceStat(com.vmware.xenon.common.ServiceStats.ServiceStat) File(java.io.File) QueryTop(com.vmware.photon.controller.model.query.QueryUtils.QueryTop) BillParsingStatus(com.vmware.photon.controller.model.adapters.azure.model.cost.BillParsingStatus) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) LocalDate(org.joda.time.LocalDate) ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) OkHttpClient(okhttp3.OkHttpClient) Paths(java.nio.file.Paths) ClusterUtil(com.vmware.photon.controller.model.util.ClusterUtil) ComputeStateWithDescription(com.vmware.photon.controller.model.resources.ComputeService.ComputeStateWithDescription) PhotonModelConstants(com.vmware.photon.controller.model.constants.PhotonModelConstants) ServiceDocumentDescription(com.vmware.xenon.common.ServiceDocumentDescription) Comparator(java.util.Comparator) QuerySpecification(com.vmware.xenon.services.common.QueryTask.QuerySpecification) OperationJoin(com.vmware.xenon.common.OperationJoin) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState)

Example 22 with ComputeState

use of com.vmware.photon.controller.model.resources.ComputeService.ComputeState in project photon-model by vmware.

the class AzureEndpointAdapterService method checkIfAccountExistsAndGetExistingDocuments.

private void checkIfAccountExistsAndGetExistingDocuments(EndpointConfigRequest req, Operation op) {
    String accountId = req.endpointProperties.get(USER_LINK_KEY);
    if (accountId != null && !accountId.isEmpty() && req.tenantLinks != null && !req.tenantLinks.isEmpty()) {
        QueryTask queryTask = QueryUtils.createAccountQuery(accountId, PhotonModelConstants.EndpointType.azure.name(), req.tenantLinks);
        queryTask.tenantLinks = req.tenantLinks;
        QueryUtils.startInventoryQueryTask(this, queryTask).whenComplete((qrt, e) -> {
            if (e != null) {
                logSevere(() -> String.format("Failure retrieving query results for azure compute host corresponding to" + "the account ID: %s", e.toString()));
                op.fail(e);
                return;
            }
            if (qrt.results.documentCount > 0) {
                req.accountAlreadyExists = true;
                Object state = qrt.results.documents.values().iterator().next();
                ComputeState computeHost = Utils.fromJson(state, ComputeState.class);
                req.existingComputeState = computeHost;
                getComputeDescription(req, computeHost.descriptionLink, op);
            } else {
                req.accountAlreadyExists = false;
                op.setBody(req);
                op.complete();
                return;
            }
        });
    } else {
        req.accountAlreadyExists = false;
        op.setBody(req);
        op.complete();
    }
}
Also used : ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) QueryTask(com.vmware.xenon.services.common.QueryTask)

Example 23 with ComputeState

use of com.vmware.photon.controller.model.resources.ComputeService.ComputeState in project photon-model by vmware.

the class TestVSphereProvisionFromImageLink method provisionVMAndGetState.

private ComputeState provisionVMAndGetState() throws Throwable {
    if (isMock()) {
        return null;
    }
    // Create a resource pool where the VM will be housed
    this.resourcePool = createResourcePool();
    this.auth = createAuth();
    this.computeHostDescription = createComputeDescription();
    this.computeHost = createComputeHost(this.computeHostDescription);
    EndpointState ep = createEndpointState(this.computeHost, this.computeHostDescription);
    this.endpoint = TestUtils.doPost(this.host, ep, EndpointState.class, UriUtils.buildUri(this.host, EndpointService.FACTORY_LINK));
    enumerateComputes(this.computeHost, this.endpoint);
    doRefresh();
    snapshotFactoryState("images", ImageService.class);
    String imageLink = findImage();
    ComputeDescription desc = createVmDescription();
    ComputeState vm = createVmState(desc, imageLink);
    // kick off a provision task to do the actual VM creation
    ProvisionComputeTaskState outTask = createProvisionTask(vm);
    awaitTaskEnd(outTask);
    return getComputeState(vm);
}
Also used : EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) ProvisionComputeTaskState(com.vmware.photon.controller.model.tasks.ProvisionComputeTaskService.ProvisionComputeTaskState) ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription)

Example 24 with ComputeState

use of com.vmware.photon.controller.model.resources.ComputeService.ComputeState in project photon-model by vmware.

the class TestVSphereProvisionFromImageLink method deployFromLibrary.

@Test
public void deployFromLibrary() throws Throwable {
    ComputeState vm = null;
    try {
        vm = provisionVMAndGetState();
        if (vm == null) {
            return;
        }
        snapshotFactoryState("ready", ComputeService.class);
        snapshotFactoryState("ready", DiskService.class);
    } finally {
        if (vm != null) {
            deleteVmAndWait(vm);
        }
    }
}
Also used : ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) Test(org.junit.Test)

Example 25 with ComputeState

use of com.vmware.photon.controller.model.resources.ComputeService.ComputeState in project photon-model by vmware.

the class TestVSphereProvisionFromImageLink method createVmState.

private ComputeState createVmState(ComputeDescription vmDescription, String imageLink) throws Throwable {
    ComputeState computeState = new ComputeState();
    computeState.id = vmDescription.name;
    computeState.documentSelfLink = computeState.id;
    computeState.descriptionLink = vmDescription.documentSelfLink;
    computeState.resourcePoolLink = this.resourcePool.documentSelfLink;
    computeState.adapterManagementReference = getAdapterManagementReference();
    computeState.name = vmDescription.name;
    computeState.powerState = PowerState.ON;
    computeState.parentLink = this.computeHost.documentSelfLink;
    if (this.endpoint != null) {
        computeState.endpointLink = this.endpoint.documentSelfLink;
        computeState.endpointLinks = new HashSet<>(1);
        computeState.endpointLinks.add(this.endpoint.documentSelfLink);
    }
    computeState.networkInterfaceLinks = new ArrayList<>(1);
    computeState.diskLinks = new ArrayList<>(1);
    DiskState bootDisk = createBootDisk(imageLink);
    computeState.diskLinks.add(bootDisk.documentSelfLink);
    CustomProperties.of(computeState).put(ComputeProperties.RESOURCE_GROUP_NAME, this.vcFolder).put(ComputeProperties.PLACEMENT_LINK, selectPlacement());
    ComputeState returnState = TestUtils.doPost(this.host, computeState, ComputeState.class, UriUtils.buildUri(this.host, ComputeService.FACTORY_LINK));
    return returnState;
}
Also used : ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) DiskState(com.vmware.photon.controller.model.resources.DiskService.DiskState)

Aggregations

ComputeState (com.vmware.photon.controller.model.resources.ComputeService.ComputeState)214 Operation (com.vmware.xenon.common.Operation)93 ArrayList (java.util.ArrayList)63 QueryTask (com.vmware.xenon.services.common.QueryTask)58 ComputeDescription (com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription)57 HashMap (java.util.HashMap)54 List (java.util.List)51 Map (java.util.Map)50 Utils (com.vmware.xenon.common.Utils)45 Test (org.junit.Test)45 UriUtils (com.vmware.xenon.common.UriUtils)44 URI (java.net.URI)42 Collectors (java.util.stream.Collectors)42 ComputeService (com.vmware.photon.controller.model.resources.ComputeService)40 DiskState (com.vmware.photon.controller.model.resources.DiskService.DiskState)40 EndpointState (com.vmware.photon.controller.model.resources.EndpointService.EndpointState)40 StatelessService (com.vmware.xenon.common.StatelessService)40 Query (com.vmware.xenon.services.common.QueryTask.Query)40 AuthCredentialsServiceState (com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState)38 ComputeType (com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription.ComputeType)36