use of com.vmware.photon.controller.model.resources.ResourcePoolService.ResourcePoolState 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.ResourcePoolService.ResourcePoolState in project photon-model by vmware.
the class TestAWSEnumerationAtScale method initResourcePoolAndComputeHost.
/**
* Creates the state associated with the resource pool, compute host and the VM to be created.
* @throws Throwable
*/
public void initResourcePoolAndComputeHost() throws Throwable {
// Create a resource pool where the VM will be housed
ResourcePoolState resourcePool = createAWSResourcePool(this.host);
AuthCredentialsServiceState auth = createAWSAuthentication(this.host, this.accessKey, this.secretKey);
this.endpointState = TestAWSSetupUtils.createAWSEndpointState(this.host, auth.documentSelfLink, resourcePool.documentSelfLink);
// create a compute host for the AWS EC2 VM
this.computeHost = createAWSComputeHost(this.host, this.endpointState, zoneId, regionId, this.isAwsClientMock, this.awsMockEndpointReference, null);
}
use of com.vmware.photon.controller.model.resources.ResourcePoolService.ResourcePoolState in project photon-model by vmware.
the class StatsCollectionTaskService method initializeQuery.
private void initializeQuery(Operation op, StatsCollectionTaskState currentState, ResourcePoolState resourcePoolState) {
// load the RP state, if not already
if (resourcePoolState == null) {
sendRequest(Operation.createGet(UriUtils.extendUri(ClusterUtil.getClusterUri(getHost(), ServiceTypeCluster.INVENTORY_SERVICE), currentState.resourcePoolLink)).setCompletion((o, e) -> {
if (e != null) {
if (e instanceof ServiceNotFoundException || o.getStatusCode() == Operation.STATUS_CODE_NOT_FOUND) {
logInfo(() -> String.format("Resource pool %s seems to have been deleted", currentState.resourcePoolLink));
} else {
logWarning(() -> String.format("Error retrieving resource pool %s: %s", currentState.resourcePoolLink, Utils.toString(e)));
}
sendSelfPatch(new StatsCollectionTaskState(), TaskStage.FAILED, patchBody -> {
patchBody.taskInfo.failure = Utils.toServiceErrorResponse(e);
});
return;
}
ResourcePoolState loadedRpState = o.getBody(ResourcePoolState.class);
initializeQuery(op, currentState, loadedRpState);
}));
return;
}
int resultLimit = DEFAULT_QUERY_RESULT_LIMIT;
try {
resultLimit = (QUERY_RESULT_LIMIT != null) ? Integer.valueOf(QUERY_RESULT_LIMIT) : DEFAULT_QUERY_RESULT_LIMIT;
} catch (NumberFormatException e) {
// use the default;
logWarning(STATS_QUERY_RESULT_LIMIT + " is not a number; Using a default value of " + DEFAULT_QUERY_RESULT_LIMIT);
}
Query resourcePoolStateQuery = resourcePoolState.query;
// Customize default resource pool Query.
if (currentState.customizationClauses != null && !currentState.customizationClauses.isEmpty()) {
currentState.customizationClauses.stream().forEach(q -> {
resourcePoolStateQuery.addBooleanClause(q);
});
}
QueryTask.Builder queryTaskBuilder = QueryTask.Builder.createDirectTask().setQuery(resourcePoolStateQuery).setResultLimit(resultLimit);
QueryTask qTask = queryTaskBuilder.build();
QueryUtils.startInventoryQueryTask(this, qTask).whenComplete((queryRsp, queryEx) -> {
if (queryEx != null) {
TaskUtils.sendFailurePatch(this, new StatsCollectionTaskState(), queryEx);
return;
}
StatsCollectionTaskState patchBody = new StatsCollectionTaskState();
if (queryRsp.results.nextPageLink == null) {
patchBody.taskInfo = TaskUtils.createTaskState(TaskStage.FINISHED);
} else {
patchBody.taskInfo = TaskUtils.createTaskState(TaskStage.STARTED);
patchBody.taskSubStage = StatsCollectionStage.GET_RESOURCES;
patchBody.nextPageLink = queryRsp.results.nextPageLink;
}
TaskUtils.sendPatch(this, patchBody);
});
}
Aggregations