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);
}
});
}
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);
}
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);
}
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;
}
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);
});
}
Aggregations