use of com.vmware.photon.controller.model.resources.EndpointService.EndpointState in project photon-model by vmware.
the class TestAWSSetupUtils method createAWSEndpointState.
public static EndpointState createAWSEndpointState(VerificationHost host, String authLink, String resPoolLink) throws Throwable {
EndpointState endpoint = new EndpointState();
endpoint.endpointType = EndpointType.aws.name();
endpoint.id = EndpointType.aws.name() + "-id";
endpoint.name = EndpointType.aws.name() + "-name";
endpoint.authCredentialsLink = authLink;
endpoint.endpointProperties = Collections.emptyMap();
endpoint.tenantLinks = Collections.singletonList(EndpointType.aws.name() + "-tenant");
endpoint.resourcePoolLink = resPoolLink;
return TestUtils.doPost(host, endpoint, EndpointState.class, UriUtils.buildUri(host, EndpointService.FACTORY_LINK));
}
use of com.vmware.photon.controller.model.resources.EndpointService.EndpointState in project photon-model by vmware.
the class AWSInstanceTypeService method getEndpointState.
/**
* Retrieve endpoint state by the provided endpointLink.
*/
private DeferredResult<Context> getEndpointState(Context context) {
AssertUtil.assertNotEmpty(context.endpointLink, "endpointLink is required.");
Operation endpointOp = Operation.createGet(UriUtils.buildUri(getHost(), context.endpointLink));
return sendWithDeferredResult(endpointOp, EndpointState.class).thenApply(endpointState -> {
// Store endpoint state in the context.
context.endpointState = endpointState;
return context;
});
}
use of com.vmware.photon.controller.model.resources.EndpointService.EndpointState in project photon-model by vmware.
the class TestAWSCostAdapterService method testAwsCostAdapterEndToEnd.
@Test
public void testAwsCostAdapterEndToEnd() throws Throwable {
if (this.isMock || new LocalDate(DateTimeZone.UTC).getDayOfMonth() == 1) {
return;
}
ResourcePoolState resourcePool = TestAWSSetupUtils.createAWSResourcePool(this.host);
EndpointState endpointState = new EndpointState();
endpointState.resourcePoolLink = resourcePool.documentSelfLink;
endpointState.endpointType = PhotonModelConstants.EndpointType.aws.name();
endpointState.name = "test-aws-endpoint";
endpointState.endpointProperties = new HashMap<>();
endpointState.endpointProperties.put(EndpointConfigRequest.PRIVATE_KEY_KEY, this.secretKey);
endpointState.endpointProperties.put(EndpointConfigRequest.PRIVATE_KEYID_KEY, this.accessKey);
EndpointAllocationTaskState endpointAllocationTaskState = new EndpointAllocationTaskState();
endpointAllocationTaskState.endpointState = endpointState;
endpointAllocationTaskState.tenantLinks = Collections.singletonList("tenant-1");
EndpointAllocationTaskState returnState = postServiceSynchronously(EndpointAllocationTaskService.FACTORY_LINK, endpointAllocationTaskState, EndpointAllocationTaskState.class);
EndpointAllocationTaskState completeState = this.waitForServiceState(EndpointAllocationTaskState.class, returnState.documentSelfLink, state -> TaskState.TaskStage.FINISHED.ordinal() <= state.taskInfo.stage.ordinal());
System.setProperty(AWSCostStatsService.BILLS_BACK_IN_TIME_MONTHS_KEY, "1");
triggerStatsCollection(resourcePool);
verifyPersistedStats(completeState, AWSConstants.COST, 2);
// Check if second iteration of adapter succeeds.
triggerStatsCollection(resourcePool);
verifyPersistedStats(completeState, AWSConstants.AWS_ACCOUNT_BILL_PROCESSED_TIME_MILLIS, 2);
System.clearProperty(AWSCostStatsService.BILLS_BACK_IN_TIME_MONTHS_KEY);
}
use of com.vmware.photon.controller.model.resources.EndpointService.EndpointState in project photon-model by vmware.
the class AzureSubscriptionsEnumerationService method queryExistingComputeStatesOfEndpoints.
private void queryExistingComputeStatesOfEndpoints(AzureSubscriptionsEnumerationContext enumerationContext, AzureCostComputeEnumerationStages nextStage, Collection<EndpointState> subscriptionEndpoints) {
// Get the compute states for already existing subscription endpoints and
// if needed patch them with custom properties
Map<String, ComputeState> computeLinkToState = new ConcurrentHashMap<>();
Collection<Operation> getComputeOps = subscriptionEndpoints.stream().map(endpointState -> Operation.createGet(UriUtils.extendUri(getInventoryServiceUri(), endpointState.computeLink)).setCompletion((o, t) -> {
if (t != null) {
logSevere(() -> String.format("Failed getting compute state" + "for %s due to %s", endpointState.computeLink, Utils.toString(t)));
return;
}
ComputeState cs = o.getBody(ComputeState.class);
// Only add custom properties if it does not have it already
if (!hasAzureEaCustomProperties(cs)) {
ComputeState comWithProps = new ComputeState();
String subscriptionId = endpointState.endpointProperties.get(EndpointConfigRequest.USER_LINK_KEY);
comWithProps.customProperties = getPropertiesMap(enumerationContext, enumerationContext.idToSubscription.get(subscriptionId), false);
computeLinkToState.put(cs.documentSelfLink, comWithProps);
}
})).collect(Collectors.toList());
joinOperationAndSendRequest(getComputeOps, enumerationContext, (enumCtx) -> patchExitingSubscriptionComputes(enumCtx, nextStage, computeLinkToState));
}
use of com.vmware.photon.controller.model.resources.EndpointService.EndpointState in project photon-model by vmware.
the class AzureSubscriptionsEnumerationService method updateExistingResources.
private void updateExistingResources(AzureSubscriptionsEnumerationContext enumerationContext, AzureCostComputeEnumerationStages nextStage) {
// Query the subscriptions which we want to create to check if they already exist
Query azureSubscriptionEndpointQuery = createQueryForAzureSubscriptionEndpoints(enumerationContext);
// Use max page size since we are collectDocuments EndpointStates
QueryByPages<EndpointState> querySubscriptionEndpoints = new QueryByPages<>(getHost(), azureSubscriptionEndpointQuery, EndpointState.class, enumerationContext.parent.tenantLinks).setMaxPageSize(QueryUtils.MAX_RESULT_LIMIT).setClusterType(ServiceTypeCluster.INVENTORY_SERVICE);
querySubscriptionEndpoints.collectDocuments(Collectors.toList()).whenComplete((subscriptionEndpoints, t) -> {
if (t != null) {
getFailureConsumer(enumerationContext).accept(t);
return;
}
if (subscriptionEndpoints.isEmpty()) {
enumerationContext.stage = nextStage;
handleAzureSubscriptionsEnumerationRequest(enumerationContext);
return;
}
queryExistingComputeStatesOfEndpoints(enumerationContext, nextStage, subscriptionEndpoints);
});
}
Aggregations