Search in sources :

Example 1 with Version

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;
}
Also used : Microservice(org.apache.servicecomb.serviceregistry.api.registry.Microservice) Version(org.apache.servicecomb.serviceregistry.version.Version)

Example 2 with Version

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;
        }
    }
}
Also used : Version(org.apache.servicecomb.serviceregistry.version.Version)

Example 3 with Version

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());
}
Also used : Expectations(mockit.Expectations) Version(org.apache.servicecomb.serviceregistry.version.Version) Test(org.junit.Test)

Example 4 with Version

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;
}
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)

Aggregations

Version (org.apache.servicecomb.serviceregistry.version.Version)4 Microservice (org.apache.servicecomb.serviceregistry.api.registry.Microservice)2 ArrayList (java.util.ArrayList)1 Expectations (mockit.Expectations)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 VersionRule (org.apache.servicecomb.serviceregistry.version.VersionRule)1 Test (org.junit.Test)1