use of com.vmware.photon.controller.model.tasks.EndpointAllocationTaskService.EndpointAllocationTaskState in project photon-model by vmware.
the class AzureSubscriptionsEnumerationServiceTest method testAddNonEaAzureSubscriptionLater.
private void testAddNonEaAzureSubscriptionLater() throws Throwable {
// Create Azure non-ea endpoints
EndpointState nonEaEp3 = createNonEaEndpointState(SUBSCRIPTION_ID_2);
EndpointAllocationTaskState state3 = createEndpoint(nonEaEp3);
this.existingSubsComputeLink3 = state3.endpointState.computeLink;
AzureSubscription subscription1 = getAzureSubscription(SUBSCRIPTION_ID_1, ACCOUNT_EMAIL_ID_1);
AzureSubscription subscription2 = getAzureSubscription(SUBSCRIPTION_ID_2, ACCOUNT_EMAIL_ID_2);
AzureSubscription existingSubscription2 = getAzureSubscription(SUBSCRIPTION_EXISTING_2, ACCOUNT_EMAIL_ID_2);
createAzureCostComputesForSubscriptions(Arrays.asList(subscription1, subscription2, existingSubscription2));
// Query for Azure Computes created with CLIENT_ID as enrollment Number
QueryTask task = createQueryTaskForAzureComputes(ENROLLMENT_NUMNBER, Collections.singletonList(TENANT_ID));
QueryTask queryTaskResponse = executQuerySynchronously(task);
assertQueryTaskResponse(queryTaskResponse, 7);
}
use of com.vmware.photon.controller.model.tasks.EndpointAllocationTaskService.EndpointAllocationTaskState in project photon-model by vmware.
the class TestAWSImageEnumerationTask method createEndpointState.
private EndpointState createEndpointState() throws Throwable {
EndpointType endpointType = EndpointType.aws;
EndpointState endpoint;
{
endpoint = new EndpointState();
endpoint.endpointType = endpointType.name();
endpoint.id = endpointType.name() + "-id";
endpoint.name = endpointType.name() + "-name";
endpoint.endpointProperties = new HashMap<>();
endpoint.endpointProperties.put(PRIVATE_KEY_KEY, this.secretKey);
endpoint.endpointProperties.put(PRIVATE_KEYID_KEY, this.accessKey);
}
EndpointAllocationTaskState allocateEndpoint = new EndpointAllocationTaskState();
allocateEndpoint.endpointState = endpoint;
allocateEndpoint.options = this.isMock ? EnumSet.of(TaskOption.IS_MOCK) : null;
allocateEndpoint.taskInfo = new TaskState();
allocateEndpoint.taskInfo.isDirect = true;
allocateEndpoint.tenantLinks = Arrays.asList(endpointType.name() + "-tenant");
allocateEndpoint = TestUtils.doPost(this.host, allocateEndpoint, EndpointAllocationTaskState.class, UriUtils.buildUri(this.host, EndpointAllocationTaskService.FACTORY_LINK));
return allocateEndpoint.endpointState;
}
use of com.vmware.photon.controller.model.tasks.EndpointAllocationTaskService.EndpointAllocationTaskState 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.tasks.EndpointAllocationTaskService.EndpointAllocationTaskState in project photon-model by vmware.
the class EndpointServiceTests method testShouldFailOnCreatingDuplicateEndpoint.
public void testShouldFailOnCreatingDuplicateEndpoint(EndpointState ep) throws Throwable {
if (!this.isMock) {
EndpointAllocationTaskState createEndpoint = new EndpointAllocationTaskState();
createEndpoint.endpointState = ep;
createEndpoint.options = this.isMock ? EnumSet.of(TaskOption.IS_MOCK) : null;
createEndpoint.checkForEndpointUniqueness = Boolean.TRUE;
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
getServiceSynchronously(endpointState.documentSelfLink, EndpointState.class);
// Run the task again with the same endpoint
EndpointAllocationTaskState duplicateEndpointTask = TestUtils.doPost(this.host, createEndpoint, EndpointAllocationTaskState.class, UriUtils.buildUri(this.host, EndpointAllocationTaskService.FACTORY_LINK));
EndpointAllocationTaskState failedTask = this.host.waitForFailedTask(EndpointAllocationTaskState.class, duplicateEndpointTask.documentSelfLink);
assertEquals(failedTask.taskInfo.stage, TaskState.TaskStage.FAILED);
}
}
use of com.vmware.photon.controller.model.tasks.EndpointAllocationTaskService.EndpointAllocationTaskState in project photon-model by vmware.
the class EndpointServiceTests method testCreateEndpoint.
public void testCreateEndpoint(EndpointService.EndpointState ep) throws Throwable {
EndpointAllocationTaskState validateEndpoint = new EndpointAllocationTaskState();
validateEndpoint.endpointState = ep;
validateEndpoint.options = this.isMock ? EnumSet.of(TaskOption.IS_MOCK) : null;
EndpointAllocationTaskState outTask = TestUtils.doPost(this.host, validateEndpoint, 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);
assertNotNull(endpoint);
assertNotNull(endpoint.authCredentialsLink);
assertNotNull(endpoint.computeLink);
assertNotNull(endpoint.computeDescriptionLink);
AuthCredentialsService.AuthCredentialsServiceState credentials = getServiceSynchronously(endpoint.authCredentialsLink, AuthCredentialsService.AuthCredentialsServiceState.class);
assertNotNull(credentials);
assertEquals(ep.endpointProperties.get(PRIVATE_KEYID_KEY), credentials.privateKeyId);
assertEquals(ep.endpointProperties.get(PRIVATE_KEY_KEY), credentials.privateKey);
ComputeDescriptionService.ComputeDescription cd = getServiceSynchronously(endpoint.computeDescriptionLink, ComputeDescriptionService.ComputeDescription.class);
assertNotNull(cd);
assertEquals(credentials.documentSelfLink, cd.authCredentialsLink);
assertEquals(this.regionId, cd.regionId);
assertEquals(this.environmentName, cd.environmentName);
ComputeService.ComputeState cs = getServiceSynchronously(endpoint.computeLink, ComputeService.ComputeState.class);
assertNotNull(cs);
assertNotNull(cs.adapterManagementReference);
assertEquals(ComputeDescriptionService.ComputeDescription.ComputeType.ENDPOINT_HOST, cs.type);
assertEquals(this.environmentName, cs.environmentName);
assertEquals(ComputeService.PowerState.ON, cs.powerState);
}
Aggregations