Search in sources :

Example 51 with EndpointState

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);
}
Also used : EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) ServiceDocumentQueryResult(com.vmware.xenon.common.ServiceDocumentQueryResult) AzureSubscription(com.vmware.photon.controller.model.adapters.azure.model.cost.AzureSubscription)

Example 52 with EndpointState

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));
}
Also used : AzureSubscriptionEndpointCreationRequest(com.vmware.photon.controller.model.adapters.azure.ea.enumeration.AzureSubscriptionEndpointCreationService.AzureSubscriptionEndpointCreationRequest) EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) TestRequestSender(com.vmware.xenon.common.test.TestRequestSender) Operation(com.vmware.xenon.common.Operation) Test(org.junit.Test)

Example 53 with EndpointState

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();
            }
        });
    });
}
Also used : RegionEnumerationResponse(com.vmware.photon.controller.model.adapterapi.RegionEnumerationResponse) Operation(com.vmware.xenon.common.Operation) EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) BasicConnection(com.vmware.photon.controller.model.adapters.vsphere.util.connection.BasicConnection) DatacenterLister(com.vmware.photon.controller.model.adapters.vsphere.util.finders.DatacenterLister) EndpointAdapterUtils(com.vmware.photon.controller.model.adapters.util.EndpointAdapterUtils)

Example 54 with EndpointState

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;
}
Also used : EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState)

Example 55 with 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));
}
Also used : EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) ServiceDocumentQueryResult(com.vmware.xenon.common.ServiceDocumentQueryResult) ImageState(com.vmware.photon.controller.model.resources.ImageService.ImageState)

Aggregations

EndpointState (com.vmware.photon.controller.model.resources.EndpointService.EndpointState)69 ComputeState (com.vmware.photon.controller.model.resources.ComputeService.ComputeState)23 Operation (com.vmware.xenon.common.Operation)22 Test (org.junit.Test)16 AuthCredentialsServiceState (com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState)15 ComputeDescription (com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription)14 EndpointAllocationTaskState (com.vmware.photon.controller.model.tasks.EndpointAllocationTaskService.EndpointAllocationTaskState)13 URI (java.net.URI)13 HashMap (java.util.HashMap)13 Query (com.vmware.xenon.services.common.QueryTask.Query)12 ComputeService (com.vmware.photon.controller.model.resources.ComputeService)11 UriUtils (com.vmware.xenon.common.UriUtils)11 Utils (com.vmware.xenon.common.Utils)11 List (java.util.List)11 ImageState (com.vmware.photon.controller.model.resources.ImageService.ImageState)10 ServiceDocument (com.vmware.xenon.common.ServiceDocument)10 Collectors (java.util.stream.Collectors)10 ResourcePoolState (com.vmware.photon.controller.model.resources.ResourcePoolService.ResourcePoolState)9 ArrayList (java.util.ArrayList)9 HashSet (java.util.HashSet)9