use of com.vmware.photon.controller.model.adapters.registry.PhotonModelAdaptersRegistryService.PhotonModelAdapterConfig in project photon-model by vmware.
the class ImageEnumerationTaskService method getImageEnumerationAdapterReference.
/**
* Go to {@link PhotonModelAdaptersRegistryService Service Registry} and get the
* 'image-enumeration' URI for passed end-point.
*
* @return <code>null</code> is returned if 'image-enumeration' adapter is not registered by
* passed end-point.
*
* @see PhotonModelAdapterConfig
* @see AdapterTypePath#IMAGE_ENUMERATION_ADAPTER
*/
private DeferredResult<SendImageEnumerationAdapterContext> getImageEnumerationAdapterReference(SendImageEnumerationAdapterContext ctx) {
// Use 'endpointType' (such as aws, azure) as AdapterConfig id/selfLink!
String configLink = buildUriPath(PhotonModelAdaptersConfigAccessService.SELF_LINK, ctx.endpointState.endpointType);
Operation getConfigOp = Operation.createGet(this, configLink);
return sendWithDeferredResult(getConfigOp, PhotonModelAdapterConfig.class).thenApply(endpointConfig -> {
// Lookup the 'image-enumeration' URI for passed end-point
if (endpointConfig.adapterEndpoints != null) {
String uriStr = endpointConfig.adapterEndpoints.get(AdapterTypePath.IMAGE_ENUMERATION_ADAPTER.key);
if (uriStr != null && !uriStr.isEmpty()) {
ctx.adapterRef = URI.create(uriStr);
}
}
logInfo(() -> String.format("[getImageEnumerationAdapterReference] adapterRef = %s: SUCCESS", ctx.adapterRef));
return ctx;
});
}
use of com.vmware.photon.controller.model.adapters.registry.PhotonModelAdaptersRegistryService.PhotonModelAdapterConfig in project photon-model by vmware.
the class PhotonModelAdaptersRegistryServiceTest method testCreateDeleteCreate.
@Test
public void testCreateDeleteCreate() {
PhotonModelAdapterConfig config = getPhotonModelAdapterConfig("testCreateDeleteCreate", "Test CreateDelete Create", "testCreateDeleteCreate.png", AdapterTypePath.ENUMERATION_ADAPTER.key, AdapterTypePath.INSTANCE_ADAPTER.key, AdapterTypePath.ENDPOINT_CONFIG_ADAPTER.key);
this.logger.info("register: " + config);
Operation registerOp = super.host.waitForResponse(Operation.createPost(super.host, PhotonModelAdaptersRegistryService.FACTORY_LINK).setBody(config));
Assert.assertNotNull(registerOp);
PhotonModelAdapterConfig body = registerOp.getBody(PhotonModelAdapterConfig.class);
this.logger.info("delete: " + body.documentSelfLink);
Operation deleteAdapterConfig = super.host.waitForResponse(Operation.createDelete(super.host, body.documentSelfLink));
Assert.assertEquals(200, deleteAdapterConfig.getStatusCode());
this.logger.info("get: " + body.documentSelfLink);
Operation getAdapterConfig = super.host.waitForResponse(Operation.createGet(super.host, body.documentSelfLink));
Assert.assertEquals(404, getAdapterConfig.getStatusCode());
{
this.logger.info("register again: " + config);
registerOp = super.host.waitForResponse(Operation.createPost(super.host, PhotonModelAdaptersRegistryService.FACTORY_LINK).setBody(config));
Assert.assertNotNull(registerOp);
Assert.assertEquals(200, registerOp.getStatusCode());
}
}
use of com.vmware.photon.controller.model.adapters.registry.PhotonModelAdaptersRegistryService.PhotonModelAdapterConfig in project photon-model by vmware.
the class EndpointAdapterUtils method registerEndpointAdapters.
/**
* Register end-point adapters into End-point Adapters Registry.
*
* @param host
* The host the end-point is running on.
* @param endpointType
* The type of the end-point.
* @param startedAdapterLinks
* The array of started adapter links.
* @param adapterLinksToRegister
* Map of adapter links (to be registered) to their adapter type key. e.g for
* standard adapters this is {@link com.vmware.photon.controller.model.UriPaths.AdapterTypePath#key}
* @param registryLocator
* ServiceEndpointLocator containing the host of the adapter registry. Can be null if the
* registry is on the same host.
* @see #handleEndpointRegistration(ServiceHost, EndpointType, Consumer, ServiceEndpointLocator)
*/
public static void registerEndpointAdapters(ServiceHost host, EndpointType endpointType, String[] startedAdapterLinks, Map<String, String> adapterLinksToRegister, ServiceEndpointLocator registryLocator) {
// Count all adapters - both FAILED and STARTED
AtomicInteger adaptersCountDown = new AtomicInteger(startedAdapterLinks.length);
// Keep started adapters only...
// - key = adapter type ket (e.g. AdapterTypePath.key)
// - value = adapter URI
Map<String, String> startedAdapters = new ConcurrentHashMap<>();
// Wait for all adapter services to start
host.registerForServiceAvailability((op, ex) -> {
if (ex != null) {
String adapterPath = op.getUri().getPath();
host.log(Level.WARNING, "Starting '%s' adapter [%s]: FAILED - %s", endpointType, adapterPath, Utils.toString(ex));
} else {
String adapterPath = op.getUri().getPath();
host.log(Level.FINE, "Starting '%s' adapter [%s]: SUCCESS", endpointType, adapterPath);
String adapterKey = adapterLinksToRegister.get(adapterPath);
if (adapterKey != null) {
startedAdapters.put(adapterKey, AdapterUriUtil.buildPublicAdapterUri(host, adapterPath).toString());
}
}
if (adaptersCountDown.decrementAndGet() == 0) {
// Once ALL Adapters are started register them into End-point Adapters Registry
host.log(Level.INFO, "Starting %d '%s' adapters: SUCCESS", startedAdapters.size(), endpointType);
// Populate end-point config with started adapters
Consumer<PhotonModelAdapterConfig> endpointConfigEnhancer = ep -> ep.adapterEndpoints.putAll(startedAdapters);
// Delegate to core end-point config/registration logic
handleEndpointRegistration(host, endpointType, endpointConfigEnhancer, registryLocator);
}
}, /* this services are not replicated */
false, startedAdapterLinks);
}
use of com.vmware.photon.controller.model.adapters.registry.PhotonModelAdaptersRegistryService.PhotonModelAdapterConfig in project photon-model by vmware.
the class PhotonModelAdaptersRegistryServiceTest method testRegisterAdapter.
@Test
public void testRegisterAdapter() throws Exception {
PhotonModelAdapterConfig config = getPhotonModelAdapterConfig("testRegisterAdapter", "Test Register Adapter", "testRegisterAdapter.png", AdapterTypePath.ENUMERATION_ADAPTER.key, AdapterTypePath.INSTANCE_ADAPTER.key, AdapterTypePath.ENDPOINT_CONFIG_ADAPTER.key);
Operation registerOp = Operation.createPost(super.host, PhotonModelAdaptersRegistryService.FACTORY_LINK).setBody(config);
Operation response = super.host.waitForResponse(registerOp);
Assert.assertNotNull(response);
this.logger.info("Response: " + response);
PhotonModelAdapterConfig body = response.getBody(PhotonModelAdapterConfig.class);
Operation getAdapterConfig = Operation.createGet(super.host, body.documentSelfLink);
PhotonModelAdapterConfig registered = super.host.waitForResponse(getAdapterConfig).getBody(PhotonModelAdapterConfig.class);
Assert.assertNotNull(registered);
Assert.assertEquals(config.name, registered.name);
Assert.assertEquals(config.customProperties.get(ICON), registered.customProperties.get(ICON));
Assert.assertEquals(config.adapterEndpoints.get(AdapterTypePath.ENDPOINT_CONFIG_ADAPTER.key), registered.adapterEndpoints.get(AdapterTypePath.ENDPOINT_CONFIG_ADAPTER.key));
}
use of com.vmware.photon.controller.model.adapters.registry.PhotonModelAdaptersRegistryService.PhotonModelAdapterConfig in project photon-model by vmware.
the class PhotonModelAdaptersRegistryServiceTest method testGetByEndpointType.
@Test
public void testGetByEndpointType() throws Exception {
String k1 = "k1";
String k2 = "k2";
String k3 = "k3";
PhotonModelAdapterConfig config1 = getPhotonModelAdapterConfig("testGetByEndpointType-1", "Test Get By Endpoint Type 1", "testGetByEndpointType-1.png", k1, k3);
Operation registerOp1 = Operation.createPost(super.host, PhotonModelAdaptersRegistryService.FACTORY_LINK).setBody(config1);
super.host.waitForResponse(registerOp1);
PhotonModelAdapterConfig config2 = getPhotonModelAdapterConfig("testGetByEndpointType-2", "Test Get By Endpoint Type 2", "testGetByEndpointType-2.png", k2, k3);
Operation registerOp2 = Operation.createPost(super.host, PhotonModelAdaptersRegistryService.FACTORY_LINK).setBody(config2);
super.host.waitForResponse(registerOp2);
Query query = Query.Builder.create().addKindFieldClause(PhotonModelAdapterConfig.class).addFieldClause(QuerySpecification.buildCompositeFieldName(PhotonModelAdapterConfig.FIELD_NAME_ADAPTER_ENDPOINTS, k2), "*", MatchType.WILDCARD).build();
QueryTask queryTask = QueryTask.Builder.createDirectTask().addOption(QueryOption.EXPAND_CONTENT).setQuery(query).build();
Operation queryOp = Operation.createPost(super.host, ServiceUriPaths.CORE_QUERY_TASKS).setReferer(getClass().getSimpleName()).setBody(queryTask);
Operation response = super.host.waitForResponse(queryOp);
QueryTask qTask = response.getBody(QueryTask.class);
Collection<Object> values = qTask.results.documents.values();
Assert.assertEquals(1, values.size());
JsonObject k2Config = (JsonObject) values.iterator().next();
Assert.assertEquals(config2.id, k2Config.getAsJsonPrimitive(PhotonModelAdapterConfig.FIELD_NAME_ID).getAsString());
}
Aggregations