use of com.vmware.photon.controller.model.util.ServiceEndpointLocator 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);
}
Aggregations