Search in sources :

Example 6 with MetadataReport

use of org.apache.dubbo.metadata.report.MetadataReport in project dubbo by alibaba.

the class AbstractMetadataReportFactory method getMetadataReport.

@Override
public MetadataReport getMetadataReport(URL url) {
    url = url.setPath(MetadataReport.class.getName()).removeParameters(EXPORT_KEY, REFER_KEY);
    String key = url.toServiceString();
    MetadataReport metadataReport = SERVICE_STORE_MAP.get(key);
    if (metadataReport != null) {
        return metadataReport;
    }
    // Lock the metadata access process to ensure a single instance of the metadata instance
    LOCK.lock();
    try {
        metadataReport = SERVICE_STORE_MAP.get(key);
        if (metadataReport != null) {
            return metadataReport;
        }
        metadataReport = createMetadataReport(url);
        if (metadataReport == null) {
            throw new IllegalStateException("Can not create metadata Report " + url);
        }
        SERVICE_STORE_MAP.put(key, metadataReport);
        return metadataReport;
    } finally {
        // Release the lock
        LOCK.unlock();
    }
}
Also used : MetadataReport(org.apache.dubbo.metadata.report.MetadataReport)

Example 7 with MetadataReport

use of org.apache.dubbo.metadata.report.MetadataReport in project dubbo by alibaba.

the class RemoteMetadataServiceImpl method getMetadata.

public MetadataInfo getMetadata(ServiceInstance instance) {
    SubscriberMetadataIdentifier identifier = new SubscriberMetadataIdentifier(instance.getServiceName(), ServiceInstanceMetadataUtils.getExportedServicesRevision(instance));
    String registryCluster = instance.getExtendParams().get(REGISTRY_CLUSTER_KEY);
    MetadataReport metadataReport = getMetadataReports().get(registryCluster);
    if (metadataReport == null) {
        metadataReport = getMetadataReports().entrySet().iterator().next().getValue();
    }
    return metadataReport.getAppMetadata(identifier, instance.getExtendParams());
}
Also used : MetadataReport(org.apache.dubbo.metadata.report.MetadataReport) SubscriberMetadataIdentifier(org.apache.dubbo.metadata.report.identifier.SubscriberMetadataIdentifier)

Example 8 with MetadataReport

use of org.apache.dubbo.metadata.report.MetadataReport in project dubbo by alibaba.

the class RemoteMetadataServiceImpl method publishMetadata.

public void publishMetadata(String serviceName) {
    Map<String, MetadataInfo> metadataInfos = localMetadataService.getMetadataInfos();
    metadataInfos.forEach((registryCluster, metadataInfo) -> {
        if (!metadataInfo.hasReported()) {
            SubscriberMetadataIdentifier identifier = new SubscriberMetadataIdentifier(serviceName, metadataInfo.calAndGetRevision());
            metadataInfo.getExtendParams().put(REGISTRY_CLUSTER_KEY, registryCluster);
            MetadataReport metadataReport = getMetadataReports().get(registryCluster);
            if (metadataReport == null) {
                metadataReport = getMetadataReports().entrySet().iterator().next().getValue();
            }
            logger.info("Publishing metadata to " + metadataReport.getClass().getSimpleName());
            if (logger.isDebugEnabled()) {
                logger.debug(metadataInfo.toString());
            }
            metadataReport.publishAppMetadata(identifier, metadataInfo);
            metadataInfo.markReported();
        }
    });
}
Also used : MetadataInfo(org.apache.dubbo.metadata.MetadataInfo) MetadataReport(org.apache.dubbo.metadata.report.MetadataReport) SubscriberMetadataIdentifier(org.apache.dubbo.metadata.report.identifier.SubscriberMetadataIdentifier)

Example 9 with MetadataReport

use of org.apache.dubbo.metadata.report.MetadataReport in project dubbo by alibaba.

the class FailoverMetadataReportTest method clearFailoverFactory.

private void clearFailoverFactory() {
    MetadataReportFactory factory = reportLoader.getExtension(mockURL.getProtocol());
    try {
        Field reportCache = AbstractMetadataReportFactory.class.getDeclaredField("SERVICE_STORE_MAP");
        if (!reportCache.isAccessible()) {
            ReflectUtils.makeAccessible(reportCache);
        }
        Map<String, MetadataReport> serviceStore = (Map<String, MetadataReport>) reportCache.get(factory);
        if (serviceStore != null) {
            for (Iterator<Map.Entry<String, MetadataReport>> iterator = serviceStore.entrySet().iterator(); iterator.hasNext(); ) {
                Map.Entry<String, MetadataReport> entry = iterator.next();
                if (entry.getKey().startsWith(mockURL.getProtocol())) {
                    iterator.remove();
                }
            }
        }
    } catch (NoSuchFieldException | IllegalAccessException ignored) {
    }
}
Also used : Field(java.lang.reflect.Field) MetadataReport(org.apache.dubbo.metadata.report.MetadataReport) MetadataReportFactory(org.apache.dubbo.metadata.report.MetadataReportFactory) AbstractMetadataReportFactory(org.apache.dubbo.metadata.report.support.AbstractMetadataReportFactory) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

MetadataReport (org.apache.dubbo.metadata.report.MetadataReport)9 SubscriberMetadataIdentifier (org.apache.dubbo.metadata.report.identifier.SubscriberMetadataIdentifier)4 HashMap (java.util.HashMap)2 Map (java.util.Map)2 MetadataInfo (org.apache.dubbo.metadata.MetadataInfo)2 MetadataReportFactory (org.apache.dubbo.metadata.report.MetadataReportFactory)2 MetadataIdentifier (org.apache.dubbo.metadata.report.identifier.MetadataIdentifier)2 AbstractMetadataReportFactory (org.apache.dubbo.metadata.report.support.AbstractMetadataReportFactory)2 Field (java.lang.reflect.Field)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 URL (org.apache.dubbo.common.URL)1 FullServiceDefinition (org.apache.dubbo.metadata.definition.model.FullServiceDefinition)1 ServiceDefinition (org.apache.dubbo.metadata.definition.model.ServiceDefinition)1 ServiceMetadataIdentifier (org.apache.dubbo.metadata.report.identifier.ServiceMetadataIdentifier)1 Test (org.junit.jupiter.api.Test)1