Search in sources :

Example 1 with WritableMetadataService

use of org.apache.dubbo.metadata.WritableMetadataService in project dubbo by alibaba.

the class ProtocolPortsMetadataCustomizer method customize.

@Override
public void customize(ServiceInstance serviceInstance) {
    WritableMetadataService writableMetadataService = WritableMetadataService.getDefaultExtension();
    Map<String, Integer> protocols = new HashMap<>();
    writableMetadataService.getExportedURLs().stream().map(URL::valueOf).forEach(url -> {
        // TODO, same protocol listen on different ports will override with each other.
        protocols.put(url.getProtocol(), url.getPort());
    });
    setEndpoints(serviceInstance, protocols);
}
Also used : HashMap(java.util.HashMap) WritableMetadataService(org.apache.dubbo.metadata.WritableMetadataService)

Example 2 with WritableMetadataService

use of org.apache.dubbo.metadata.WritableMetadataService in project dubbo by alibaba.

the class MetadataServiceURLParamsMetadataCustomizer method resolveMetadataPropertyValue.

private String resolveMetadataPropertyValue(ServiceInstance serviceInstance) {
    WritableMetadataService writableMetadataService = getDefaultExtension();
    String serviceInterface = MetadataService.class.getName();
    String group = serviceInstance.getServiceName();
    String version = MetadataService.VERSION;
    SortedSet<String> urls = writableMetadataService.getExportedURLs(serviceInterface, group, version);
    return getMetadataServiceParameter(toURLs(urls));
}
Also used : WritableMetadataService(org.apache.dubbo.metadata.WritableMetadataService)

Example 3 with WritableMetadataService

use of org.apache.dubbo.metadata.WritableMetadataService in project dubbo by alibaba.

the class ServiceInstanceMetadataCustomizer method customize.

@Override
public void customize(ServiceInstance serviceInstance) {
    ExtensionLoader<MetadataParamsFilter> loader = ExtensionLoader.getExtensionLoader(MetadataParamsFilter.class);
    Set<MetadataParamsFilter> paramsFilters = loader.getSupportedExtensionInstances();
    WritableMetadataService localMetadataService = WritableMetadataService.getDefaultExtension();
    // pick the first interface metadata available.
    // FIXME, check the same key in different urls has the same value
    MetadataInfo metadataInfo = localMetadataService.getMetadataInfos().values().iterator().next();
    MetadataInfo.ServiceInfo serviceInfo = metadataInfo.getServices().values().iterator().next();
    Map<String, String> allParams = new HashMap<>(serviceInfo.getUrl().getParameters());
    // load instance params users want to load.
    // TODO, duplicate logic with that in ApplicationConfig
    Set<InfraAdapter> adapters = ExtensionLoader.getExtensionLoader(InfraAdapter.class).getSupportedExtensionInstances();
    if (CollectionUtils.isNotEmpty(adapters)) {
        Map<String, String> inputParameters = new HashMap<>();
        inputParameters.put(APPLICATION_KEY, ApplicationModel.getName());
        for (InfraAdapter adapter : adapters) {
            Map<String, String> extraParameters = adapter.getExtraAttributes(inputParameters);
            if (CollectionUtils.isNotEmptyMap(extraParameters)) {
                extraParameters.forEach(allParams::putIfAbsent);
            }
        }
    }
    if (CollectionUtils.isEmpty(paramsFilters)) {
        serviceInstance.getMetadata().putAll(allParams);
        return;
    }
    paramsFilters.forEach(filter -> {
        String[] included = filter.instanceParamsIncluded();
        if (included == null) {
            serviceInstance.getMetadata().putAll(allParams);
        } else {
            for (String p : included) {
                if (allParams.get(p) != null) {
                    serviceInstance.getMetadata().put(p, allParams.get(p));
                }
            }
        }
    });
}
Also used : MetadataInfo(org.apache.dubbo.metadata.MetadataInfo) MetadataParamsFilter(org.apache.dubbo.metadata.MetadataParamsFilter) HashMap(java.util.HashMap) WritableMetadataService(org.apache.dubbo.metadata.WritableMetadataService) InfraAdapter(org.apache.dubbo.common.infra.InfraAdapter)

Aggregations

WritableMetadataService (org.apache.dubbo.metadata.WritableMetadataService)3 HashMap (java.util.HashMap)2 InfraAdapter (org.apache.dubbo.common.infra.InfraAdapter)1 MetadataInfo (org.apache.dubbo.metadata.MetadataInfo)1 MetadataParamsFilter (org.apache.dubbo.metadata.MetadataParamsFilter)1