Search in sources :

Example 1 with ServiceEndpointLocator

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);
}
Also used : PowerState(com.vmware.photon.controller.model.resources.ComputeService.PowerState) AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) HashMap(java.util.HashMap) ServiceEndpointLocator(com.vmware.photon.controller.model.util.ServiceEndpointLocator) Level(java.util.logging.Level) Utils(com.vmware.xenon.common.Utils) EndpointConfigRequest(com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest) Query(com.vmware.xenon.services.common.QueryTask.Query) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) Map(java.util.Map) BiConsumer(java.util.function.BiConsumer) EndpointType(com.vmware.photon.controller.model.constants.PhotonModelConstants.EndpointType) URI(java.net.URI) EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) INVENTORY_SERVICE(com.vmware.photon.controller.model.util.ClusterUtil.ServiceTypeCluster.INVENTORY_SERVICE) ServiceErrorResponse(com.vmware.xenon.common.ServiceErrorResponse) ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription) StatelessService(com.vmware.xenon.common.StatelessService) Operation(com.vmware.xenon.common.Operation) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) PHOTON_MODEL_ADAPTER_ENDPOINT_NOT_UNIQUE_MESSAGE_CODE(com.vmware.photon.controller.model.adapters.util.AdapterConstants.PHOTON_MODEL_ADAPTER_ENDPOINT_NOT_UNIQUE_MESSAGE_CODE) Collectors(java.util.stream.Collectors) ServiceHost(com.vmware.xenon.common.ServiceHost) PHOTON_MODEL_ADAPTER_ENDPOINT_NOT_UNIQUE_MESSAGE(com.vmware.photon.controller.model.adapters.util.AdapterConstants.PHOTON_MODEL_ADAPTER_ENDPOINT_NOT_UNIQUE_MESSAGE) QueryTop(com.vmware.photon.controller.model.query.QueryUtils.QueryTop) Consumer(java.util.function.Consumer) List(java.util.List) RequestType(com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest.RequestType) PhotonModelAdapterConfig(com.vmware.photon.controller.model.adapters.registry.PhotonModelAdaptersRegistryService.PhotonModelAdapterConfig) Stream(java.util.stream.Stream) ClusterUtil(com.vmware.photon.controller.model.util.ClusterUtil) LocalizableValidationException(com.vmware.xenon.common.LocalizableValidationException) DeferredResult(com.vmware.xenon.common.DeferredResult) UriUtils.buildUri(com.vmware.xenon.common.UriUtils.buildUri) Optional(java.util.Optional) PhotonModelAdaptersRegistryService(com.vmware.photon.controller.model.adapters.registry.PhotonModelAdaptersRegistryService) Builder(com.vmware.xenon.services.common.QueryTask.Query.Builder) Collections(java.util.Collections) OperationJoin(com.vmware.xenon.common.OperationJoin) PhotonModelUriUtils.createInventoryUri(com.vmware.photon.controller.model.util.PhotonModelUriUtils.createInventoryUri) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) PhotonModelAdapterConfig(com.vmware.photon.controller.model.adapters.registry.PhotonModelAdaptersRegistryService.PhotonModelAdapterConfig)

Aggregations

EndpointConfigRequest (com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest)1 RequestType (com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest.RequestType)1 PhotonModelAdaptersRegistryService (com.vmware.photon.controller.model.adapters.registry.PhotonModelAdaptersRegistryService)1 PhotonModelAdapterConfig (com.vmware.photon.controller.model.adapters.registry.PhotonModelAdaptersRegistryService.PhotonModelAdapterConfig)1 PHOTON_MODEL_ADAPTER_ENDPOINT_NOT_UNIQUE_MESSAGE (com.vmware.photon.controller.model.adapters.util.AdapterConstants.PHOTON_MODEL_ADAPTER_ENDPOINT_NOT_UNIQUE_MESSAGE)1 PHOTON_MODEL_ADAPTER_ENDPOINT_NOT_UNIQUE_MESSAGE_CODE (com.vmware.photon.controller.model.adapters.util.AdapterConstants.PHOTON_MODEL_ADAPTER_ENDPOINT_NOT_UNIQUE_MESSAGE_CODE)1 EndpointType (com.vmware.photon.controller.model.constants.PhotonModelConstants.EndpointType)1 QueryTop (com.vmware.photon.controller.model.query.QueryUtils.QueryTop)1 ComputeDescription (com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription)1 ComputeState (com.vmware.photon.controller.model.resources.ComputeService.ComputeState)1 PowerState (com.vmware.photon.controller.model.resources.ComputeService.PowerState)1 EndpointState (com.vmware.photon.controller.model.resources.EndpointService.EndpointState)1 ClusterUtil (com.vmware.photon.controller.model.util.ClusterUtil)1 INVENTORY_SERVICE (com.vmware.photon.controller.model.util.ClusterUtil.ServiceTypeCluster.INVENTORY_SERVICE)1 PhotonModelUriUtils.createInventoryUri (com.vmware.photon.controller.model.util.PhotonModelUriUtils.createInventoryUri)1 ServiceEndpointLocator (com.vmware.photon.controller.model.util.ServiceEndpointLocator)1 DeferredResult (com.vmware.xenon.common.DeferredResult)1 LocalizableValidationException (com.vmware.xenon.common.LocalizableValidationException)1 Operation (com.vmware.xenon.common.Operation)1 OperationJoin (com.vmware.xenon.common.OperationJoin)1