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"));
}
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));
}
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"));
}
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+"));
}
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;
}
Aggregations