use of com.vmware.photon.controller.model.resources.EndpointService.EndpointState in project photon-model by vmware.
the class AzureSubscriptionEndpointsEnumerationServiceTest method testAddFirstAzureSubscription.
private void testAddFirstAzureSubscription() throws Throwable {
// Request for creating computes for 1 Azure Subscriptions
AzureSubscription subscription = getAzureSubscription(SUBSCRIPTION_ID_1, ACCOUNT_ID_1);
createAzureEndpointsForSubscriptions(Collections.singletonList(subscription));
// Query the Endpoints to assert
ServiceDocumentQueryResult result = this.host.getExpandedFactoryState(UriUtils.buildUri(this.host, EndpointService.FACTORY_LINK));
Assert.assertEquals(2, result.documents.size());
// Assert the created Endpoint and other resources
result.documents.remove(this.endpointLink);
EndpointState endpointStateCreated = Utils.fromJson(result.documents.values().iterator().next(), EndpointState.class);
assertCreatedEndpoint(endpointStateCreated, SUBSCRIPTION_ID_1);
this.createdEndpointLinks.add(endpointStateCreated.documentSelfLink);
// Assert the root compute under the endpoint
ComputeState computeStateCreated = getServiceSynchronously(endpointStateCreated.computeLink, ComputeState.class);
assertCreatedComputeState(computeStateCreated, SUBSCRIPTION_ID_1, ACCOUNT_ID_1);
// Assert the partial AuthCredentialsState
AuthCredentialsServiceState authCreated = getServiceSynchronously(endpointStateCreated.authCredentialsLink, AuthCredentialsServiceState.class);
assertAuthCredentialState(authCreated, SUBSCRIPTION_ID_1);
}
use of com.vmware.photon.controller.model.resources.EndpointService.EndpointState in project photon-model by vmware.
the class AzureSubscriptionEndpointCreationServiceTest method testSubscriptionEndpointCreation.
@Test
public void testSubscriptionEndpointCreation() throws Throwable {
AzureSubscriptionEndpointCreationRequest request = new AzureSubscriptionEndpointCreationRequest();
request.resourceReference = UriUtils.buildUri(this.host, this.eaEndPointLink);
request.subscriptionId = SUBSCRIPTION_ID;
request.accountId = ACCOUNT_ID;
Operation endPointCreationOp = Operation.createPatch(this.host, AzureSubscriptionEndpointCreationService.SELF_LINK);
endPointCreationOp.setBody(request);
TestRequestSender sender = new TestRequestSender(this.host);
EndpointState subscriptionEndpoint = sender.sendAndWait(endPointCreationOp, EndpointState.class);
// Assert the subscriptionEndpoint created
Assert.assertEquals(this.eaEndPointLink, subscriptionEndpoint.parentLink);
Assert.assertNotNull(subscriptionEndpoint.endpointProperties.get(EndpointConfigRequest.USER_LINK_KEY));
Assert.assertEquals(SUBSCRIPTION_ID, subscriptionEndpoint.endpointProperties.get(EndpointConfigRequest.USER_LINK_KEY));
ComputeState cs = getServiceSynchronously(subscriptionEndpoint.computeLink, ComputeState.class);
Assert.assertNotNull(cs.customProperties.get(AzureConstants.AZURE_ACCOUNT_OWNER_EMAIL_ID));
Assert.assertEquals(ACCOUNT_ID, cs.customProperties.get(AzureConstants.AZURE_ACCOUNT_OWNER_EMAIL_ID));
Assert.assertNotNull(cs.customProperties.get(AzureConstants.AZURE_SUBSCRIPTION_ID_KEY));
Assert.assertEquals(SUBSCRIPTION_ID, cs.customProperties.get(AzureConstants.AZURE_SUBSCRIPTION_ID_KEY));
}
use of com.vmware.photon.controller.model.resources.EndpointService.EndpointState in project photon-model by vmware.
the class VSphereRegionEnumerationAdapterService method handlePost.
@Override
public void handlePost(Operation post) {
if (!post.hasBody()) {
post.fail(new IllegalArgumentException("body is required"));
return;
}
EndpointState request = post.getBody(EndpointState.class);
DeferredResult<AuthCredentialsServiceState> credentialsDr;
if (request.authCredentialsLink == null) {
credentialsDr = new DeferredResult<>();
credentialsDr.complete(new AuthCredentialsServiceState());
} else {
Operation getCredentials = Operation.createGet(createInventoryUri(this.getHost(), request.authCredentialsLink));
credentialsDr = sendWithDeferredResult(getCredentials, AuthCredentialsServiceState.class);
}
credentialsDr.whenComplete((AuthCredentialsServiceState creds, Throwable t) -> {
if (t != null) {
post.fail(t);
return;
}
VSphereIOThreadPoolAllocator.getPool(this).submit(() -> {
BasicConnection connection = new BasicConnection();
try {
EndpointAdapterUtils.Retriever retriever = EndpointAdapterUtils.Retriever.of(request.endpointProperties);
VSphereEndpointAdapterService.endpoint().accept(request, retriever);
VSphereEndpointAdapterService.credentials().accept(creds, retriever);
connection.setURI(URI.create("https://" + request.endpointProperties.get(HOST_NAME_KEY) + "/sdk"));
connection.setUsername(creds.privateKeyId);
connection.setPassword(EncryptionUtils.decrypt(creds.privateKey));
connection.setIgnoreSslErrors(true);
connection.connect();
DatacenterLister lister = new DatacenterLister(connection);
RegionEnumerationResponse res = new RegionEnumerationResponse();
res.regions = lister.listAllDatacenters().stream().map(dc -> new RegionEnumerationResponse.RegionInfo(DatacenterLister.prettifyPath(dc.path), VimUtils.convertMoRefToString(dc.object))).collect(Collectors.toList());
post.setBody(res);
post.complete();
} catch (Exception e) {
post.fail(e);
} finally {
connection.closeQuietly();
}
});
});
}
use of com.vmware.photon.controller.model.resources.EndpointService.EndpointState in project photon-model by vmware.
the class EndpointServiceTest method buildValidStartState.
private static EndpointService.EndpointState buildValidStartState() {
EndpointService.EndpointState endpointState = new EndpointService.EndpointState();
endpointState.id = UUID.randomUUID().toString();
endpointState.endpointProperties = new HashMap<>();
endpointState.endpointProperties.put("regionId", "us-west-1");
endpointState.endpointProperties.put("privateKeyId", "privateKeyId");
endpointState.endpointProperties.put("privateKey", "privateKey");
endpointState.endpointType = "aws";
endpointState.name = "aws-test-endpoint";
endpointState.desc = "aws-test-endpoint description";
endpointState.tenantLinks = new ArrayList<>();
endpointState.tenantLinks.add("tenant-linkA");
endpointState.authCredentialsLink = "http://authCredentialsLink";
endpointState.resourcePoolLink = "http://resourcePoolLink";
endpointState.computeLink = "aws-host-computeLink";
endpointState.computeDescriptionLink = "aws-host-computeDescriptionLink";
return endpointState;
}
use of com.vmware.photon.controller.model.resources.EndpointService.EndpointState in project photon-model by vmware.
the class TestAWSImageEnumerationTask method testImageEnumeration_delete.
private void testImageEnumeration_delete(boolean isPublic, String imageFilter) throws Throwable {
Assume.assumeFalse(this.isMock);
EndpointState endpointState = createEndpointState();
// Those images should not be touched by this image enum. {{
//
// Pre-create public and private image in different end-point
EndpointState azureEndpointState = createDummyEndpointState(EndpointType.azure);
ImageState publicImageState_diffEP = createImageState(azureEndpointState, true, PUBLIC);
ImageState privateImageState_diffEP = createImageState(azureEndpointState, true, PRIVATE);
// Pre-create public and private image in same end-point but different region
ImageState publicImageState_diffRegion = createImageState(endpointState, false, PUBLIC);
ImageState privateImageState_diffRegion = createImageState(endpointState, false, PRIVATE);
// }}
// Create one stale image that should be deleted by this enumeration
ImageState staleImageState = createImageState(endpointState, true, isPublic);
// Validate the 3 image states are preCREATED: 1 stale and 2 vSphere
int preCreatedCount = 1 + 2 + 2;
queryDocumentsAndAssertExpectedCount(getHost(), preCreatedCount, ImageService.FACTORY_LINK, EXACT_COUNT);
// Under TESTING
kickOffImageEnumeration(endpointState, isPublic, imageFilter);
// Validate 1 image state is CREATED and the 2 vSphere are UNtouched
int postEnumCount = 1 + 2 + 2;
// since we are not deleting stale resource anymore, just disassociating
postEnumCount++;
// them
ServiceDocumentQueryResult imagesAfterEnum = queryDocumentsAndAssertExpectedCount(getHost(), postEnumCount, ImageService.FACTORY_LINK, EXACT_COUNT);
// Validate 1 stale image state is DISASSOCIATED
ImageState staleImage = Utils.fromJson(imagesAfterEnum.documents.get(staleImageState.documentSelfLink), ImageState.class);
Assert.assertTrue("Dummy image should have been disassociated.", staleImage.endpointLinks.isEmpty());
// Validate vSphere images are untouched
Assert.assertTrue("Private images from other endpoints should not have been deleted.", imagesAfterEnum.documentLinks.contains(privateImageState_diffEP.documentSelfLink));
Assert.assertTrue("Public images from other endpoints should not have been deleted.", imagesAfterEnum.documentLinks.contains(publicImageState_diffEP.documentSelfLink));
Assert.assertTrue("Private images from same endpoints but different region should not have been deleted.", imagesAfterEnum.documentLinks.contains(privateImageState_diffRegion.documentSelfLink));
Assert.assertTrue("Public images from other endpoints should not have been deleted.", imagesAfterEnum.documentLinks.contains(publicImageState_diffRegion.documentSelfLink));
}
Aggregations