Search in sources :

Example 1 with RegionEnumerationResponse

use of com.vmware.photon.controller.model.adapterapi.RegionEnumerationResponse in project photon-model by vmware.

the class AWSRegionEnumerationAdapterService method handlePost.

@Override
public void handlePost(Operation post) {
    List<RegionInfo> regions = Arrays.stream(Regions.values()).map(r -> new RegionInfo(r.getName(), r.getName())).collect(Collectors.toList());
    RegionEnumerationResponse result = new RegionEnumerationResponse();
    result.regions = regions;
    post.setBody(result);
    post.complete();
}
Also used : Arrays(java.util.Arrays) List(java.util.List) StatelessService(com.vmware.xenon.common.StatelessService) Operation(com.vmware.xenon.common.Operation) RegionEnumerationResponse(com.vmware.photon.controller.model.adapterapi.RegionEnumerationResponse) RegionInfo(com.vmware.photon.controller.model.adapterapi.RegionEnumerationResponse.RegionInfo) Collectors(java.util.stream.Collectors) AWSUriPaths(com.vmware.photon.controller.model.adapters.awsadapter.AWSUriPaths) Regions(com.amazonaws.regions.Regions) RegionEnumerationResponse(com.vmware.photon.controller.model.adapterapi.RegionEnumerationResponse) RegionInfo(com.vmware.photon.controller.model.adapterapi.RegionEnumerationResponse.RegionInfo)

Example 2 with RegionEnumerationResponse

use of com.vmware.photon.controller.model.adapterapi.RegionEnumerationResponse in project photon-model by vmware.

the class TestVSphereEnumerationTask method testGetAvailableRegions.

@Test
public void testGetAvailableRegions() throws Throwable {
    Assume.assumeFalse(isMock());
    startAdditionalServices();
    this.host.waitForServiceAvailable(VSphereUriPaths.VSPHERE_REGION_ENUMERATION_ADAPTER_SERVICE);
    URI uri = UriUtils.buildUri(ServiceHost.LOCAL_HOST, host.getPort(), UriPaths.AdapterTypePath.REGION_ENUMERATION_ADAPTER.adapterLink(PhotonModelConstants.EndpointType.vsphere.toString().toLowerCase()), null);
    Operation post = Operation.createPost(uri);
    post.setBody(createEndpoint((a) -> {
    }, (b) -> {
    }));
    Operation operation = host.getTestRequestSender().sendAndWait(post);
    RegionEnumerationResponse result = operation.getBody(RegionEnumerationResponse.class);
    assertTrue(!result.regions.isEmpty());
}
Also used : PowerState(com.vmware.photon.controller.model.resources.ComputeService.PowerState) ServiceTypeCluster(com.vmware.photon.controller.model.util.ClusterUtil.ServiceTypeCluster) QueryTask(com.vmware.xenon.services.common.QueryTask) TimeoutException(java.util.concurrent.TimeoutException) LifecycleState(com.vmware.photon.controller.model.resources.ComputeService.LifecycleState) Random(java.util.Random) Utils(com.vmware.xenon.common.Utils) EndpointService(com.vmware.photon.controller.model.resources.EndpointService) ResourcePoolService(com.vmware.photon.controller.model.resources.ResourcePoolService) ServiceDocumentQueryResult(com.vmware.xenon.common.ServiceDocumentQueryResult) URI(java.net.URI) EnumSet(java.util.EnumSet) EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) SubnetService(com.vmware.photon.controller.model.resources.SubnetService) ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription) TestUtils(com.vmware.photon.controller.model.tasks.TestUtils) ServiceHost(com.vmware.xenon.common.ServiceHost) ResourceGroupService(com.vmware.photon.controller.model.resources.ResourceGroupService) NetworkInterfaceService(com.vmware.photon.controller.model.resources.NetworkInterfaceService) TagService(com.vmware.photon.controller.model.resources.TagService) StorageDescriptionService(com.vmware.photon.controller.model.resources.StorageDescriptionService) UriUtils(com.vmware.xenon.common.UriUtils) ComputeService(com.vmware.photon.controller.model.resources.ComputeService) QueryOption(com.vmware.xenon.services.common.QueryTask.QuerySpecification.QueryOption) TaskOption(com.vmware.photon.controller.model.tasks.TaskOption) ComputeProperties(com.vmware.photon.controller.model.ComputeProperties) HashMap(java.util.HashMap) ComputeDescriptionService(com.vmware.photon.controller.model.resources.ComputeDescriptionService) ResourceMetricsService(com.vmware.photon.controller.model.monitoring.ResourceMetricsService) CUSTOM_PROP_STORAGE_SHARED(com.vmware.photon.controller.model.ComputeProperties.CUSTOM_PROP_STORAGE_SHARED) Query(com.vmware.xenon.services.common.QueryTask.Query) UriPaths(com.vmware.photon.controller.model.UriPaths) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) Assume(org.junit.Assume) Assert.assertNotNull(org.junit.Assert.assertNotNull) Operation(com.vmware.xenon.common.Operation) QueryUtils(com.vmware.photon.controller.model.query.QueryUtils) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Test(org.junit.Test) VimNames(com.vmware.photon.controller.model.adapters.vsphere.util.VimNames) NetworkService(com.vmware.photon.controller.model.resources.NetworkService) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) RESOURCE_TYPE_KEY(com.vmware.photon.controller.model.ComputeProperties.RESOURCE_TYPE_KEY) PhotonModelConstants(com.vmware.photon.controller.model.constants.PhotonModelConstants) RegionEnumerationResponse(com.vmware.photon.controller.model.adapterapi.RegionEnumerationResponse) Assert.assertEquals(org.junit.Assert.assertEquals) RegionEnumerationResponse(com.vmware.photon.controller.model.adapterapi.RegionEnumerationResponse) Operation(com.vmware.xenon.common.Operation) URI(java.net.URI) Test(org.junit.Test)

Example 3 with RegionEnumerationResponse

use of com.vmware.photon.controller.model.adapterapi.RegionEnumerationResponse in project photon-model by vmware.

the class TestAzureEnumerationTask method testGetAvailableRegions.

@Test
public void testGetAvailableRegions() {
    Assume.assumeFalse(this.isMock);
    URI uri = UriUtils.buildUri(ServiceHost.LOCAL_HOST, host.getPort(), UriPaths.AdapterTypePath.REGION_ENUMERATION_ADAPTER.adapterLink(PhotonModelConstants.EndpointType.azure.toString().toLowerCase()), null);
    Operation post = Operation.createPost(uri);
    post.setBody(endpointState);
    Operation operation = host.getTestRequestSender().sendAndWait(post);
    RegionEnumerationResponse result = operation.getBody(RegionEnumerationResponse.class);
    assertTrue(!result.regions.isEmpty());
}
Also used : RegionEnumerationResponse(com.vmware.photon.controller.model.adapterapi.RegionEnumerationResponse) Operation(com.vmware.xenon.common.Operation) URI(java.net.URI) Test(org.junit.Test) BaseModelTest(com.vmware.photon.controller.model.helpers.BaseModelTest)

Example 4 with RegionEnumerationResponse

use of com.vmware.photon.controller.model.adapterapi.RegionEnumerationResponse 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 5 with RegionEnumerationResponse

use of com.vmware.photon.controller.model.adapterapi.RegionEnumerationResponse in project photon-model by vmware.

the class AzureRegionEnumerationAdapterService method handlePost.

@Override
public void handlePost(Operation post) {
    if (!post.hasBody()) {
        post.fail(new IllegalArgumentException("body is required"));
        return;
    }
    Context ctx = new Context(this, post.getBody(EndpointState.class));
    DeferredResult.completed(ctx).thenCompose(ctx::getAuthentication).thenCompose(ctx::getAzureClient).thenCompose(ctx::getAzureLocations).whenComplete((ignoreCtx, t) -> {
        try {
            if (t != null) {
                post.fail(t);
                return;
            }
            RegionEnumerationResponse result = new RegionEnumerationResponse();
            result.regions = ctx.azureLocations.stream().map(loc -> new RegionInfo(loc.displayName(), loc.name())).collect(Collectors.toList());
            post.setBodyNoCloning(result).complete();
        } finally {
            ctx.close();
        }
    });
}
Also used : EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) RegionEnumerationResponse(com.vmware.photon.controller.model.adapterapi.RegionEnumerationResponse) RegionInfo(com.vmware.photon.controller.model.adapterapi.RegionEnumerationResponse.RegionInfo)

Aggregations

RegionEnumerationResponse (com.vmware.photon.controller.model.adapterapi.RegionEnumerationResponse)6 Operation (com.vmware.xenon.common.Operation)5 EndpointState (com.vmware.photon.controller.model.resources.EndpointService.EndpointState)3 RegionInfo (com.vmware.photon.controller.model.adapterapi.RegionEnumerationResponse.RegionInfo)2 AuthCredentialsServiceState (com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState)2 URI (java.net.URI)2 Test (org.junit.Test)2 Regions (com.amazonaws.regions.Regions)1 ComputeProperties (com.vmware.photon.controller.model.ComputeProperties)1 CUSTOM_PROP_STORAGE_SHARED (com.vmware.photon.controller.model.ComputeProperties.CUSTOM_PROP_STORAGE_SHARED)1 RESOURCE_TYPE_KEY (com.vmware.photon.controller.model.ComputeProperties.RESOURCE_TYPE_KEY)1 UriPaths (com.vmware.photon.controller.model.UriPaths)1 AWSUriPaths (com.vmware.photon.controller.model.adapters.awsadapter.AWSUriPaths)1 EndpointAdapterUtils (com.vmware.photon.controller.model.adapters.util.EndpointAdapterUtils)1 VimNames (com.vmware.photon.controller.model.adapters.vsphere.util.VimNames)1 BasicConnection (com.vmware.photon.controller.model.adapters.vsphere.util.connection.BasicConnection)1 DatacenterLister (com.vmware.photon.controller.model.adapters.vsphere.util.finders.DatacenterLister)1 PhotonModelConstants (com.vmware.photon.controller.model.constants.PhotonModelConstants)1 BaseModelTest (com.vmware.photon.controller.model.helpers.BaseModelTest)1 ResourceMetricsService (com.vmware.photon.controller.model.monitoring.ResourceMetricsService)1