Search in sources :

Example 1 with VersionRule

use of org.apache.servicecomb.serviceregistry.version.VersionRule in project incubator-servicecomb-java-chassis by apache.

the class TestCompatiblePathVersionMapper method createVersionRule_32767.

@Test
public void createVersionRule_32767() {
    VersionRule versionRule = mapper.getOrCreate("v32767");
    Assert.assertEquals("32767.0.0+", versionRule.getVersionRule());
}
Also used : VersionRule(org.apache.servicecomb.serviceregistry.version.VersionRule) Test(org.junit.Test)

Example 2 with VersionRule

use of org.apache.servicecomb.serviceregistry.version.VersionRule in project incubator-servicecomb-java-chassis by apache.

the class LocalServiceRegistryClientImpl method findServiceInstances.

@Override
public MicroserviceInstances findServiceInstances(String selfMicroserviceId, String appId, String serviceName, String strVersionRule, String revision) {
    int currentRevision = this.revision.get();
    List<MicroserviceInstance> allInstances = new ArrayList<>();
    MicroserviceInstances microserviceInstances = new MicroserviceInstances();
    FindInstancesResponse response = new FindInstancesResponse();
    if (revision != null && currentRevision == Integer.parseInt(revision)) {
        microserviceInstances.setNeedRefresh(false);
        return microserviceInstances;
    }
    microserviceInstances.setRevision(String.valueOf(currentRevision));
    VersionRule versionRule = VersionRuleUtils.getOrCreate(strVersionRule);
    Microservice latestMicroservice = findLatest(appId, serviceName, versionRule);
    if (latestMicroservice == null) {
        response.setInstances(allInstances);
        microserviceInstances.setInstancesResponse(response);
        return microserviceInstances;
    }
    Version latestVersion = VersionUtils.getOrCreate(latestMicroservice.getVersion());
    for (Entry<String, Microservice> entry : microserviceIdMap.entrySet()) {
        Microservice microservice = entry.getValue();
        if (!isSameMicroservice(microservice, appId, serviceName)) {
            continue;
        }
        Version version = VersionUtils.getOrCreate(entry.getValue().getVersion());
        if (!versionRule.isMatch(version, latestVersion)) {
            continue;
        }
        Map<String, MicroserviceInstance> instances = microserviceInstanceMap.get(entry.getValue().getServiceId());
        allInstances.addAll(instances.values());
    }
    response.setInstances(allInstances);
    microserviceInstances.setInstancesResponse(response);
    return microserviceInstances;
}
Also used : Microservice(org.apache.servicecomb.serviceregistry.api.registry.Microservice) Version(org.apache.servicecomb.serviceregistry.version.Version) MicroserviceInstances(org.apache.servicecomb.serviceregistry.client.http.MicroserviceInstances) ArrayList(java.util.ArrayList) MicroserviceInstance(org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance) FindInstancesResponse(org.apache.servicecomb.serviceregistry.api.response.FindInstancesResponse) VersionRule(org.apache.servicecomb.serviceregistry.version.VersionRule)

Example 3 with VersionRule

use of org.apache.servicecomb.serviceregistry.version.VersionRule in project incubator-servicecomb-java-chassis by apache.

the class LocalServiceRegistryClientImpl method getMicroserviceId.

@Override
public String getMicroserviceId(String appId, String microserviceName, String strVersionRule) {
    VersionRule versionRule = VersionRuleUtils.getOrCreate(strVersionRule);
    Microservice latest = findLatest(appId, microserviceName, versionRule);
    return latest != null ? latest.getServiceId() : null;
}
Also used : Microservice(org.apache.servicecomb.serviceregistry.api.registry.Microservice) VersionRule(org.apache.servicecomb.serviceregistry.version.VersionRule)

Example 4 with VersionRule

use of org.apache.servicecomb.serviceregistry.version.VersionRule in project incubator-servicecomb-java-chassis by apache.

the class OperationInstancesDiscoveryFilter method initOperationNodes.

protected Map<String, DiscoveryTreeNode> initOperationNodes(DiscoveryTreeNode parent, Map<MicroserviceVersionMeta, Map<String, MicroserviceInstance>> versionMap) {
    Map<String, DiscoveryTreeNode> tmpChildren = new ConcurrentHashMapEx<>();
    versionMap.keySet().stream().sorted(Comparator.comparing(MicroserviceVersion::getVersion)).forEach(meta -> {
        for (OperationMeta operationMeta : meta.getMicroserviceMeta().getOperations()) {
            tmpChildren.computeIfAbsent(operationMeta.getMicroserviceQualifiedName(), qualifiedName -> {
                VersionRule versionRule = VersionRuleUtils.getOrCreate(meta.getVersion().getVersion() + "+");
                return new DiscoveryTreeNode().attribute(VERSION_RULE, versionRule).subName(parent, versionRule.getVersionRule()).data(new HashMap<>());
            });
        }
    });
    return tmpChildren;
}
Also used : MicroserviceVersion(org.apache.servicecomb.serviceregistry.consumer.MicroserviceVersion) DiscoveryTreeNode(org.apache.servicecomb.serviceregistry.discovery.DiscoveryTreeNode) OperationMeta(org.apache.servicecomb.core.definition.OperationMeta) ConcurrentHashMapEx(org.apache.servicecomb.foundation.common.concurrent.ConcurrentHashMapEx) VersionRule(org.apache.servicecomb.serviceregistry.version.VersionRule)

Example 5 with VersionRule

use of org.apache.servicecomb.serviceregistry.version.VersionRule in project incubator-servicecomb-java-chassis by apache.

the class TestCompatiblePathVersionMapper method getOrCreate.

@Test
public void getOrCreate() {
    VersionRule versionRule = mapper.getOrCreate("v1");
    Assert.assertEquals("1.0.0-2.0.0", versionRule.getVersionRule());
}
Also used : VersionRule(org.apache.servicecomb.serviceregistry.version.VersionRule) Test(org.junit.Test)

Aggregations

VersionRule (org.apache.servicecomb.serviceregistry.version.VersionRule)5 Microservice (org.apache.servicecomb.serviceregistry.api.registry.Microservice)2 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1 OperationMeta (org.apache.servicecomb.core.definition.OperationMeta)1 ConcurrentHashMapEx (org.apache.servicecomb.foundation.common.concurrent.ConcurrentHashMapEx)1 MicroserviceInstance (org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance)1 FindInstancesResponse (org.apache.servicecomb.serviceregistry.api.response.FindInstancesResponse)1 MicroserviceInstances (org.apache.servicecomb.serviceregistry.client.http.MicroserviceInstances)1 MicroserviceVersion (org.apache.servicecomb.serviceregistry.consumer.MicroserviceVersion)1 DiscoveryTreeNode (org.apache.servicecomb.serviceregistry.discovery.DiscoveryTreeNode)1 Version (org.apache.servicecomb.serviceregistry.version.Version)1