Search in sources :

Example 1 with FindInstancesResponse

use of org.apache.servicecomb.serviceregistry.api.response.FindInstancesResponse in project incubator-servicecomb-java-chassis by apache.

the class TestMicroserviceVersions method setUp.

@Before
public void setUp() throws Exception {
    microserviceInstances = new MicroserviceInstances();
    findInstancesResponse = new FindInstancesResponse();
}
Also used : MicroserviceInstances(org.apache.servicecomb.serviceregistry.client.http.MicroserviceInstances) FindInstancesResponse(org.apache.servicecomb.serviceregistry.api.response.FindInstancesResponse) Before(org.junit.Before)

Example 2 with FindInstancesResponse

use of org.apache.servicecomb.serviceregistry.api.response.FindInstancesResponse in project incubator-servicecomb-java-chassis by apache.

the class TestMicroserviceInstances method setUp.

@Before
public void setUp() throws Exception {
    microserviceInstances = new MicroserviceInstances();
    findInstancesResponse = new FindInstancesResponse();
    instances = new ArrayList<>();
    instances.add(Mockito.mock(MicroserviceInstance.class));
}
Also used : MicroserviceInstance(org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance) FindInstancesResponse(org.apache.servicecomb.serviceregistry.api.response.FindInstancesResponse) Before(org.junit.Before)

Example 3 with FindInstancesResponse

use of org.apache.servicecomb.serviceregistry.api.response.FindInstancesResponse in project incubator-servicecomb-java-chassis by apache.

the class TestAppManager method setUp.

@Before
public void setUp() throws Exception {
    microserviceInstances = new MicroserviceInstances();
    findInstancesResponse = new FindInstancesResponse();
    findInstancesResponse.setInstances(Collections.emptyList());
    microserviceInstances.setInstancesResponse(findInstancesResponse);
}
Also used : MicroserviceInstances(org.apache.servicecomb.serviceregistry.client.http.MicroserviceInstances) FindInstancesResponse(org.apache.servicecomb.serviceregistry.api.response.FindInstancesResponse) Before(org.junit.Before)

Example 4 with FindInstancesResponse

use of org.apache.servicecomb.serviceregistry.api.response.FindInstancesResponse in project incubator-servicecomb-java-chassis by apache.

the class TestMicroserviceManager method setUp.

@Before
public void setUp() throws Exception {
    microserviceInstances = new MicroserviceInstances();
    findInstancesResponse = new FindInstancesResponse();
    findInstancesResponse.setInstances(Collections.emptyList());
    microserviceInstances.setInstancesResponse(findInstancesResponse);
}
Also used : MicroserviceInstances(org.apache.servicecomb.serviceregistry.client.http.MicroserviceInstances) FindInstancesResponse(org.apache.servicecomb.serviceregistry.api.response.FindInstancesResponse) Before(org.junit.Before)

Example 5 with FindInstancesResponse

use of org.apache.servicecomb.serviceregistry.api.response.FindInstancesResponse 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

FindInstancesResponse (org.apache.servicecomb.serviceregistry.api.response.FindInstancesResponse)5 MicroserviceInstances (org.apache.servicecomb.serviceregistry.client.http.MicroserviceInstances)4 Before (org.junit.Before)4 MicroserviceInstance (org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance)2 ArrayList (java.util.ArrayList)1 Microservice (org.apache.servicecomb.serviceregistry.api.registry.Microservice)1 Version (org.apache.servicecomb.serviceregistry.version.Version)1 VersionRule (org.apache.servicecomb.serviceregistry.version.VersionRule)1