Search in sources :

Example 1 with VersionRule

use of org.apache.servicecomb.registry.version.VersionRule in project java-chassis by ServiceComb.

the class TestVersionRuleUtils method fixed.

@Test
public void fixed() {
    VersionRule versionRule = VersionRuleUtils.getOrCreate("1");
    Assert.assertThat(versionRule, Matchers.instanceOf(FixedVersionRule.class));
    Assert.assertSame(versionRule, VersionRuleUtils.getOrCreate("1"));
}
Also used : FixedVersionRule(org.apache.servicecomb.registry.version.VersionRuleFixedParser.FixedVersionRule) StartFromVersionRule(org.apache.servicecomb.registry.version.VersionRuleStartFromParser.StartFromVersionRule) LatestVersionRule(org.apache.servicecomb.registry.version.VersionRuleLatestParser.LatestVersionRule) VersionRule(org.apache.servicecomb.registry.version.VersionRule) FixedVersionRule(org.apache.servicecomb.registry.version.VersionRuleFixedParser.FixedVersionRule) RangeVersionRule(org.apache.servicecomb.registry.version.VersionRuleRangeParser.RangeVersionRule) Test(org.junit.Test)

Example 2 with VersionRule

use of org.apache.servicecomb.registry.version.VersionRule in project java-chassis by ServiceComb.

the class TestVersionRuleUtils method latest.

@Test
public void latest() {
    VersionRule versionRule = VersionRuleUtils.getOrCreate(DefinitionConst.VERSION_RULE_LATEST);
    Assert.assertThat(versionRule, Matchers.instanceOf(LatestVersionRule.class));
    Assert.assertSame(versionRule, VersionRuleUtils.getOrCreate(DefinitionConst.VERSION_RULE_LATEST));
}
Also used : LatestVersionRule(org.apache.servicecomb.registry.version.VersionRuleLatestParser.LatestVersionRule) StartFromVersionRule(org.apache.servicecomb.registry.version.VersionRuleStartFromParser.StartFromVersionRule) LatestVersionRule(org.apache.servicecomb.registry.version.VersionRuleLatestParser.LatestVersionRule) VersionRule(org.apache.servicecomb.registry.version.VersionRule) FixedVersionRule(org.apache.servicecomb.registry.version.VersionRuleFixedParser.FixedVersionRule) RangeVersionRule(org.apache.servicecomb.registry.version.VersionRuleRangeParser.RangeVersionRule) Test(org.junit.Test)

Example 3 with VersionRule

use of org.apache.servicecomb.registry.version.VersionRule in project java-chassis by ServiceComb.

the class TestVersionRuleUtils method range.

@Test
public void range() {
    VersionRule versionRule = VersionRuleUtils.getOrCreate("1-2");
    Assert.assertThat(versionRule, Matchers.instanceOf(RangeVersionRule.class));
    Assert.assertSame(versionRule, VersionRuleUtils.getOrCreate("1-2"));
}
Also used : RangeVersionRule(org.apache.servicecomb.registry.version.VersionRuleRangeParser.RangeVersionRule) StartFromVersionRule(org.apache.servicecomb.registry.version.VersionRuleStartFromParser.StartFromVersionRule) LatestVersionRule(org.apache.servicecomb.registry.version.VersionRuleLatestParser.LatestVersionRule) VersionRule(org.apache.servicecomb.registry.version.VersionRule) FixedVersionRule(org.apache.servicecomb.registry.version.VersionRuleFixedParser.FixedVersionRule) RangeVersionRule(org.apache.servicecomb.registry.version.VersionRuleRangeParser.RangeVersionRule) Test(org.junit.Test)

Example 4 with VersionRule

use of org.apache.servicecomb.registry.version.VersionRule in project java-chassis by ServiceComb.

the class TestVersionRuleUtils method startFrom.

@Test
public void startFrom() {
    VersionRule versionRule = VersionRuleUtils.getOrCreate("1+");
    Assert.assertThat(versionRule, Matchers.instanceOf(StartFromVersionRule.class));
    Assert.assertSame(versionRule, VersionRuleUtils.getOrCreate("1+"));
}
Also used : StartFromVersionRule(org.apache.servicecomb.registry.version.VersionRuleStartFromParser.StartFromVersionRule) StartFromVersionRule(org.apache.servicecomb.registry.version.VersionRuleStartFromParser.StartFromVersionRule) LatestVersionRule(org.apache.servicecomb.registry.version.VersionRuleLatestParser.LatestVersionRule) VersionRule(org.apache.servicecomb.registry.version.VersionRule) FixedVersionRule(org.apache.servicecomb.registry.version.VersionRuleFixedParser.FixedVersionRule) RangeVersionRule(org.apache.servicecomb.registry.version.VersionRuleRangeParser.RangeVersionRule) Test(org.junit.Test)

Example 5 with VersionRule

use of org.apache.servicecomb.registry.version.VersionRule in project java-chassis by ServiceComb.

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) {
        microserviceInstances.setMicroserviceNotExist(true);
        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.registry.api.registry.Microservice) Version(org.apache.servicecomb.foundation.common.Version) MicroserviceInstances(org.apache.servicecomb.registry.api.registry.MicroserviceInstances) ArrayList(java.util.ArrayList) MicroserviceInstance(org.apache.servicecomb.registry.api.registry.MicroserviceInstance) FindInstancesResponse(org.apache.servicecomb.registry.api.registry.FindInstancesResponse) VersionRule(org.apache.servicecomb.registry.version.VersionRule)

Aggregations

VersionRule (org.apache.servicecomb.registry.version.VersionRule)8 Test (org.junit.Test)6 FixedVersionRule (org.apache.servicecomb.registry.version.VersionRuleFixedParser.FixedVersionRule)4 LatestVersionRule (org.apache.servicecomb.registry.version.VersionRuleLatestParser.LatestVersionRule)4 RangeVersionRule (org.apache.servicecomb.registry.version.VersionRuleRangeParser.RangeVersionRule)4 StartFromVersionRule (org.apache.servicecomb.registry.version.VersionRuleStartFromParser.StartFromVersionRule)4 Microservice (org.apache.servicecomb.registry.api.registry.Microservice)2 ArrayList (java.util.ArrayList)1 Version (org.apache.servicecomb.foundation.common.Version)1 FindInstancesResponse (org.apache.servicecomb.registry.api.registry.FindInstancesResponse)1 MicroserviceInstance (org.apache.servicecomb.registry.api.registry.MicroserviceInstance)1 MicroserviceInstances (org.apache.servicecomb.registry.api.registry.MicroserviceInstances)1