use of com.vmware.photon.controller.model.tasks.EndpointAllocationTaskService.EndpointAllocationTaskState in project photon-model by vmware.
the class TestAWSCostAdapterService method verifyPersistedStats.
private void verifyPersistedStats(EndpointAllocationTaskState completeState, String metric, int expectedCount) {
this.host.waitFor("Timeout waiting for stats", () -> {
QueryTask.QuerySpecification querySpec = new QueryTask.QuerySpecification();
querySpec.query = QueryTask.Query.Builder.create().addKindFieldClause(ResourceMetrics.class).addFieldClause(ServiceDocument.FIELD_NAME_SELF_LINK, UriUtils.buildUriPath(ResourceMetricsService.FACTORY_LINK, UriUtils.getLastPathSegment(completeState.endpointState.computeLink)), QueryTask.QueryTerm.MatchType.PREFIX).addRangeClause(buildCompositeFieldName(ResourceMetrics.FIELD_NAME_ENTRIES, metric), createDoubleRange(0.0, Double.MAX_VALUE, true, true)).build();
querySpec.options.add(QueryTask.QuerySpecification.QueryOption.EXPAND_CONTENT);
ServiceDocumentQueryResult result = this.host.createAndWaitSimpleDirectQuery(querySpec, expectedCount, expectedCount);
boolean statsCollected = true;
for (Object metrics : result.documents.values()) {
ResourceMetrics rawMetrics = Utils.fromJson(metrics, ResourceMetrics.class);
Double rawMetric = rawMetrics.entries.get(metric);
if (rawMetric != null) {
continue;
}
statsCollected = false;
}
if (metric.equalsIgnoreCase(AWSConstants.COST)) {
List<ResourceMetrics> accountOneTimeCharges = result.documents.values().stream().map(o -> Utils.fromJson(o, ResourceMetrics.class)).filter(m -> m.entries.containsKey(PhotonModelConstants.ACCOUNT_ONE_TIME_CHARGES)).collect(Collectors.toList());
if (accountOneTimeCharges.size() != result.documentCount) {
statsCollected = false;
}
}
return statsCollected;
});
}
use of com.vmware.photon.controller.model.tasks.EndpointAllocationTaskService.EndpointAllocationTaskState in project photon-model by vmware.
the class EndpointRemovalTaskServiceTest method createEndpoint.
private static EndpointState createEndpoint(BaseModelTest test) throws Throwable {
EndpointState endpoint = createEndpointState();
// Create endpoint
EndpointAllocationTaskState startState = createEndpointAllocationRequest(endpoint);
startState.adapterReference = UriUtils.buildUri(test.getHost(), MockSuccessEndpointAdapter.SELF_LINK);
EndpointAllocationTaskState returnState = test.postServiceSynchronously(EndpointAllocationTaskService.FACTORY_LINK, startState, EndpointAllocationTaskState.class);
EndpointAllocationTaskState completeState = test.waitForServiceState(EndpointAllocationTaskState.class, returnState.documentSelfLink, state -> TaskState.TaskStage.FINISHED.ordinal() <= state.taskInfo.stage.ordinal());
assertThat(completeState.taskInfo.stage, is(TaskState.TaskStage.FINISHED));
EndpointAllocationTaskState taskState = getServiceSynchronously(test, completeState.documentSelfLink, EndpointAllocationTaskState.class);
assertNotNull(taskState);
assertNotNull(taskState.endpointState);
ServiceDocument endpointState = taskState.endpointState;
assertNotNull(endpointState.documentSelfLink);
return getServiceSynchronously(test, endpointState.documentSelfLink, EndpointState.class);
}
use of com.vmware.photon.controller.model.tasks.EndpointAllocationTaskService.EndpointAllocationTaskState in project photon-model by vmware.
the class EndpointServiceTests method testCreateAndThenValidate.
public void testCreateAndThenValidate(EndpointService.EndpointState ep) throws Throwable {
EndpointAllocationTaskState createEndpoint = new EndpointAllocationTaskState();
createEndpoint.endpointState = ep;
createEndpoint.options = this.isMock ? EnumSet.of(TaskOption.IS_MOCK) : null;
EndpointAllocationTaskState outTask = TestUtils.doPost(this.host, createEndpoint, EndpointAllocationTaskState.class, UriUtils.buildUri(this.host, EndpointAllocationTaskService.FACTORY_LINK));
this.host.waitForFinishedTask(EndpointAllocationTaskState.class, outTask.documentSelfLink);
EndpointAllocationTaskState taskState = getServiceSynchronously(outTask.documentSelfLink, EndpointAllocationTaskState.class);
assertNotNull(taskState);
assertNotNull(taskState.endpointState);
ServiceDocument endpointState = taskState.endpointState;
assertNotNull(endpointState.documentSelfLink);
// check endpoint document was created
EndpointService.EndpointState endpoint = getServiceSynchronously(endpointState.documentSelfLink, EndpointService.EndpointState.class);
// now do validation
EndpointAllocationTaskState validateEndpoint = new EndpointAllocationTaskState();
validateEndpoint.endpointState = endpoint;
validateEndpoint.options = this.isMock ? EnumSet.of(TaskOption.IS_MOCK) : EnumSet.noneOf(TaskOption.class);
validateEndpoint.options.add(TaskOption.VALIDATE_ONLY);
EndpointAllocationTaskState validateEndpointTask = TestUtils.doPost(this.host, validateEndpoint, EndpointAllocationTaskState.class, UriUtils.buildUri(this.host, EndpointAllocationTaskService.FACTORY_LINK));
this.host.waitForFinishedTask(EndpointAllocationTaskState.class, validateEndpointTask.documentSelfLink);
}
use of com.vmware.photon.controller.model.tasks.EndpointAllocationTaskService.EndpointAllocationTaskState in project photon-model by vmware.
the class EndpointAllocationTaskServiceTest method createEndpointAllocationRequest.
private static EndpointAllocationTaskState createEndpointAllocationRequest(EndpointState endpoint) {
EndpointAllocationTaskState endpointAllocationTaskState = new EndpointAllocationTaskState();
endpointAllocationTaskState.endpointState = endpoint;
if (endpoint != null) {
endpointAllocationTaskState.tenantLinks = endpoint.tenantLinks;
}
return endpointAllocationTaskState;
}
use of com.vmware.photon.controller.model.tasks.EndpointAllocationTaskService.EndpointAllocationTaskState in project photon-model by vmware.
the class EndpointServiceTests method testValidateCredentials.
public void testValidateCredentials(EndpointService.EndpointState endpoint) throws Throwable {
EndpointAllocationTaskState validateEndpoint = new EndpointAllocationTaskState();
validateEndpoint.options = this.isMock ? EnumSet.of(TaskOption.VALIDATE_ONLY, TaskOption.IS_MOCK) : EnumSet.of(TaskOption.VALIDATE_ONLY);
validateEndpoint.endpointState = endpoint;
EndpointAllocationTaskState outTask = TestUtils.doPost(this.host, validateEndpoint, EndpointAllocationTaskState.class, UriUtils.buildUri(this.host, EndpointAllocationTaskService.FACTORY_LINK));
this.host.waitForFinishedTask(EndpointAllocationTaskState.class, outTask.documentSelfLink);
}
Aggregations