use of com.vmware.photon.controller.model.adapters.util.enums.EnumerationStages in project photon-model by vmware.
the class GCPEnumerationAdapterService method getResourceGroup.
/**
* Method to retrieve the resource group on which the enumeration task will be performed.
* @param ctx The Enumeration Context.
* @param next The next enumeration sub stage.
*/
private void getResourceGroup(EnumerationContext ctx, EnumerationStages next) {
Consumer<Operation> onSuccess = op -> {
ctx.resourceGroup = op.getBody(ResourceGroupState.class);
validateResourceGroup(ctx, ctx.resourceGroup);
ctx.stage = next;
handleEnumerationRequest(ctx);
};
URI resourceGroupURI = UriUtils.buildUri(this.getHost(), ctx.computeHostDesc.groupLinks.iterator().next());
AdapterUtils.getServiceState(this, resourceGroupURI, onSuccess, getFailureConsumer(ctx));
}
use of com.vmware.photon.controller.model.adapters.util.enums.EnumerationStages in project photon-model by vmware.
the class GCPEnumerationAdapterService method getAccessToken.
/**
* Method to get the access token to send RESTful APIs later.
* Every access token is only valid for an hour.
* @param ctx The Enumeration Context.
* @param clientEmail The client email in service account's credential file.
* @param scopes The limitation of application's access.
* @param privateKey The key generated by private key in service account's credential file.
* @throws GeneralSecurityException The exception will be thrown when private key is invalid.
* @throws IOException The exception will be thrown when inputs are mal-formatted.
*/
private void getAccessToken(EnumerationContext ctx, String clientEmail, Collection<String> scopes, PrivateKey privateKey, EnumerationStages next) throws GeneralSecurityException, IOException {
Consumer<GCPAccessTokenResponse> onSuccess = response -> {
ctx.accessToken = response.access_token;
ctx.stage = next;
handleEnumerationRequest(ctx);
};
JSONWebToken jwt = new JSONWebToken(clientEmail, scopes, privateKey);
String assertion = jwt.getAssertion();
GCPUtils.getAccessToken(this, assertion, onSuccess, getFailureConsumer(ctx));
}
use of com.vmware.photon.controller.model.adapters.util.enums.EnumerationStages in project photon-model by vmware.
the class GCPEnumerationAdapterService method getHostComputeDescription.
/**
* Method to retrieve the parent compute host on which the enumeration task will be performed.
* @param ctx The Enumeration Context.
* @param next The next enumeration sub stage.
*/
private void getHostComputeDescription(EnumerationContext ctx, EnumerationStages next) {
Consumer<Operation> onSuccess = (op) -> {
ComputeStateWithDescription csd = op.getBody(ComputeStateWithDescription.class);
ctx.computeHostDesc = csd.description;
validateHost(ctx, ctx.computeHostDesc);
ctx.stage = next;
handleEnumerationRequest(ctx);
};
URI computeUri = UriUtils.extendUriWithQuery(UriUtils.buildUri(this.getHost(), ctx.enumRequest.resourceLink()), UriUtils.URI_PARAM_ODATA_EXPAND, Boolean.TRUE.toString());
AdapterUtils.getServiceState(this, computeUri, onSuccess, getFailureConsumer(ctx));
}
Aggregations