Search in sources :

Example 6 with PhotonModelAdapterConfig

use of com.vmware.photon.controller.model.adapters.registry.PhotonModelAdaptersRegistryService.PhotonModelAdapterConfig in project photon-model by vmware.

the class PhotonModelAdaptersRegistryServiceTest method getPhotonModelAdapterConfig.

private PhotonModelAdapterConfig getPhotonModelAdapterConfig(String id, String name, String icon, String... keys) {
    PhotonModelAdapterConfig config = new PhotonModelAdapterConfig();
    config.id = id;
    config.name = name;
    config.documentSelfLink = config.id;
    Map<String, String> customProperties = new HashMap<>();
    customProperties.put(ICON, icon);
    config.customProperties = customProperties;
    Map<String, String> endpoints = new HashMap<>();
    for (String key : keys) {
        endpoints.put(key, key + "-" + id);
    }
    config.adapterEndpoints = endpoints;
    return config;
}
Also used : HashMap(java.util.HashMap) PhotonModelAdapterConfig(com.vmware.photon.controller.model.adapters.registry.PhotonModelAdaptersRegistryService.PhotonModelAdapterConfig)

Example 7 with PhotonModelAdapterConfig

use of com.vmware.photon.controller.model.adapters.registry.PhotonModelAdaptersRegistryService.PhotonModelAdapterConfig in project photon-model by vmware.

the class EndpointAdapterUtils method registerEndpoint.

private static void registerEndpoint(ServiceHost host, EndpointType endpointType, Consumer<PhotonModelAdapterConfig> endpointConfigEnhancer, ServiceEndpointLocator registryLocator) {
    PhotonModelAdapterConfig endpointConfig = new PhotonModelAdapterConfig();
    // By contract the id MUST equal to endpointType
    endpointConfig.id = endpointType.name();
    endpointConfig.documentSelfLink = endpointConfig.id;
    endpointConfig.name = endpointType.toString();
    endpointConfig.adapterEndpoints = new HashMap<>();
    if (endpointConfigEnhancer != null) {
        // Pass to enhancer to customize the end-point config.
        endpointConfigEnhancer.accept(endpointConfig);
    }
    URI uri = buildUri(ClusterUtil.getClusterUri(host, registryLocator), PhotonModelAdaptersRegistryService.FACTORY_LINK);
    Operation postEndpointConfigOp = Operation.createPost(uri).setReferer(host.getUri()).setBody(endpointConfig);
    host.sendWithDeferredResult(postEndpointConfigOp).whenComplete((o, e) -> {
        if (e != null) {
            host.log(Level.WARNING, "Registering %d '%s' adapters into End-point Adapters Registry: FAILED - %s", endpointConfig.adapterEndpoints.size(), endpointType, Utils.toString(e));
        } else {
            host.log(Level.INFO, "Registering %d '%s' adapters into End-point Adapters Registry: SUCCESS", endpointConfig.adapterEndpoints.size(), endpointType);
        }
    });
}
Also used : Operation(com.vmware.xenon.common.Operation) URI(java.net.URI) PhotonModelAdapterConfig(com.vmware.photon.controller.model.adapters.registry.PhotonModelAdaptersRegistryService.PhotonModelAdapterConfig)

Aggregations

PhotonModelAdapterConfig (com.vmware.photon.controller.model.adapters.registry.PhotonModelAdaptersRegistryService.PhotonModelAdapterConfig)7 Operation (com.vmware.xenon.common.Operation)6 Query (com.vmware.xenon.services.common.QueryTask.Query)2 URI (java.net.URI)2 HashMap (java.util.HashMap)2 Test (org.junit.Test)2 JsonObject (com.google.gson.JsonObject)1 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 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