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();
}
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());
}
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());
}
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();
}
});
});
}
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();
}
});
}
Aggregations