use of org.apache.servicecomb.serviceregistry.version.Version in project incubator-servicecomb-java-chassis by apache.
the class LocalServiceRegistryClientImpl method findLatest.
protected Microservice findLatest(String appId, String serviceName, VersionRule versionRule) {
Version latestVersion = null;
Microservice latest = null;
for (Entry<String, Microservice> entry : microserviceIdMap.entrySet()) {
Microservice microservice = entry.getValue();
if (!isSameMicroservice(microservice, appId, serviceName)) {
continue;
}
Version version = VersionUtils.getOrCreate(microservice.getVersion());
if (!versionRule.isAccept(version)) {
continue;
}
if (latestVersion == null || version.compareTo(latestVersion) > 0) {
latestVersion = version;
latest = microservice;
}
}
return latest;
}
use of org.apache.servicecomb.serviceregistry.version.Version in project incubator-servicecomb-java-chassis by apache.
the class AbstractServiceRegistry method needSetFrameworkVersion.
private boolean needSetFrameworkVersion() {
if (serviceCenterInfo == null) {
LOGGER.warn("Server startup when service center not started and cannot retrieve version info, assume latest.");
return true;
} else {
Version scVersion = VersionUtils.getOrCreate(serviceCenterInfo.getVersion());
Version frameworkVersion = VersionUtils.getOrCreate(Const.SERVICECENTER_FRAMEWORK_VERSION);
if (scVersion.compareTo(frameworkVersion) >= 0) {
return true;
} else {
return false;
}
}
}
use of org.apache.servicecomb.serviceregistry.version.Version in project incubator-servicecomb-java-chassis by apache.
the class TestMicroserviceVersions method createAndInitMicroserviceVersionRule.
@Test
public void createAndInitMicroserviceVersionRule(@Mocked MicroserviceVersion microserviceVersion) {
String microserviceId = "1";
createMicroservice(microserviceId);
Version version = new Version("1.0.0");
new Expectations() {
{
microserviceVersion.getVersion();
result = version;
microserviceVersion.getMicroservice();
result = microservices.get(microserviceId);
}
};
microserviceVersions.getVersions().put(microserviceId, microserviceVersion);
MicroserviceVersionRule microserviceVersionRule = microserviceVersions.createAndInitMicroserviceVersionRule("1.0.0");
Assert.assertSame(microserviceVersion, microserviceVersionRule.getLatestMicroserviceVersion());
}
use of org.apache.servicecomb.serviceregistry.version.Version 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;
}
Aggregations