use of com.vmware.photon.controller.model.resources.ComputeService.ComputeState in project photon-model by vmware.
the class AzureLifecycleOperationService method updateComputeState.
private void updateComputeState(AzureLifecycleOperationContext ctx) {
ComputeState state = new ComputeState();
state.powerState = getPowerState(ctx.request);
if (SUSPEND.equals(state.powerState)) {
// clear IP address in case of power-off
state.address = "";
}
Operation.createPatch(ctx.request.resourceReference).setBody(state).setCompletion((o, e) -> ctx.finish(e)).sendWith(this);
}
use of com.vmware.photon.controller.model.resources.ComputeService.ComputeState 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);
}
use of com.vmware.photon.controller.model.resources.ComputeService.ComputeState in project photon-model by vmware.
the class AzureSubscriptionsEnumerationService method createResources.
private void createResources(AzureSubscriptionsEnumerationContext enumerationContext, AzureCostComputeEnumerationStages nextStage) {
// Go through new subscriptions and create corresponding ComputeState
// and ComputeDescription for them
Collection<ComputeState> computesToCreate = new ArrayList<>();
// Create ComputeDescription
Collection<Operation> createComputeDescOps = enumerationContext.idToSubscription.values().stream().map(subscription -> Operation.createPost(UriUtils.extendUri(getInventoryServiceUri(), ComputeDescriptionService.FACTORY_LINK)).setBody(AzureUtils.constructAzureSubscriptionComputeDescription(enumerationContext.parent.endpointLink, enumerationContext.parent.tenantLinks, subscription.entityId, null, null, enumerationContext.parent.documentSelfLink)).setCompletion((o, e) -> {
if (e != null) {
logSevere(() -> String.format("Compute description creation " + " failed for azure subscription %s", subscription.entityId));
return;
}
ComputeDescription cd = o.getBody(ComputeDescription.class);
String csName = AzureUtils.constructSubscriptionName(subscription);
computesToCreate.add(AzureUtils.constructAzureSubscriptionComputeState(enumerationContext.parent.endpointLink, cd.documentSelfLink, enumerationContext.parent.tenantLinks, csName, enumerationContext.parent.resourcePoolLink, getPropertiesMap(enumerationContext, subscription, true), null, enumerationContext.parent.documentSelfLink));
})).collect(Collectors.toList());
joinOperationAndSendRequest(createComputeDescOps, enumerationContext, (subsEnumCtx) -> {
// Now create the ComputeState
Collection<Operation> createComputeOps = computesToCreate.stream().map(computeState -> Operation.createPost(UriUtils.extendUri(getInventoryServiceUri(), ComputeService.FACTORY_LINK)).setBody(computeState).setCompletion((o, e) -> {
if (e != null) {
logSevere(() -> String.format("Compute state creation failed for azure" + " subscription %s", computeState.name));
}
})).collect(Collectors.toList());
joinOperationAndSendRequest(createComputeOps, subsEnumCtx, (enumCtx) -> {
enumCtx.stage = nextStage;
handleAzureSubscriptionsEnumerationRequest(enumCtx);
});
});
}
use of com.vmware.photon.controller.model.resources.ComputeService.ComputeState in project photon-model by vmware.
the class AzureSubscriptionsEnumerationService method fetchExistingResources.
private void fetchExistingResources(AzureSubscriptionsEnumerationContext enumerationContext, AzureCostComputeEnumerationStages nextStage) {
Query azureComputesQuery = createQueryForAzureSubscriptionComputes(enumerationContext);
QueryByPages<ComputeState> querySubscriptionsComputes = new QueryByPages<>(getHost(), azureComputesQuery, ComputeState.class, enumerationContext.parent.tenantLinks);
querySubscriptionsComputes.setClusterType(ServiceTypeCluster.INVENTORY_SERVICE);
// Use max page size cause we collect ComputeStates
querySubscriptionsComputes.setMaxPageSize(QueryUtils.MAX_RESULT_LIMIT);
querySubscriptionsComputes.queryDocuments(computeState -> {
if (computeState.customProperties != null && computeState.customProperties.containsKey(AzureConstants.AZURE_SUBSCRIPTION_ID_KEY)) {
String subscriptionUuid = computeState.customProperties.get(AzureConstants.AZURE_SUBSCRIPTION_ID_KEY);
enumerationContext.idToSubscription.remove(subscriptionUuid);
}
}).whenComplete((aVoid, t) -> {
if (t != null) {
getFailureConsumer(enumerationContext).accept(t);
return;
}
enumerationContext.stage = nextStage;
handleAzureSubscriptionsEnumerationRequest(enumerationContext);
});
}
use of com.vmware.photon.controller.model.resources.ComputeService.ComputeState in project photon-model by vmware.
the class AzureCostStatsService method createAzureSubscriptionStats.
// Create Azure account stats
private void createAzureSubscriptionStats(Context context, AzureSubscription subscription) {
// convert the subscription daily costs to cumulative
AtomicDouble cumulativeValue = new AtomicDouble(0.0);
subscription.cost = subscription.cost.entrySet().stream().sorted(Comparator.comparing(Entry::getKey)).collect(Collectors.toMap(Entry::getKey, e -> cumulativeValue.addAndGet(e.getValue())));
Consumer<List<ComputeState>> subscriptionStatsProcessor = (subscriptionComputeStates) -> subscriptionComputeStates.forEach(subscriptionComputeState -> {
String statName = AzureStatsNormalizer.getNormalizedStatKeyValue(AzureCostConstants.COST);
String costUnit = AzureStatsNormalizer.getNormalizedUnitValue(AzureCostConstants.DEFAULT_CURRENCY_VALUE);
ComputeStats subscriptionStats = new ComputeStats();
subscriptionStats.computeLink = subscriptionComputeState.documentSelfLink;
subscriptionStats.statValues = new ConcurrentSkipListMap<>();
List<ServiceStat> costStats = new ArrayList<>();
for (Entry<Long, Double> cost : subscription.cost.entrySet()) {
ServiceStat azureAccountStat = AzureCostHelper.createServiceStat(statName, cost.getValue(), costUnit, cost.getKey());
costStats.add(azureAccountStat);
}
subscriptionStats.statValues.put(statName, costStats);
context.statsResponse.statsList.add(subscriptionStats);
});
processSubscriptionStats(context, subscription, subscriptionStatsProcessor);
}
Aggregations