use of org.apache.servicecomb.registry.api.registry.FindInstancesResponse 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;
}
use of org.apache.servicecomb.registry.api.registry.FindInstancesResponse in project java-chassis by ServiceComb.
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));
}
use of org.apache.servicecomb.registry.api.registry.FindInstancesResponse in project incubator-servicecomb-java-chassis by apache.
the class LocalRegistryStore method findServiceInstances.
// local registry do not care about version and revision
public MicroserviceInstances findServiceInstances(String appId, String serviceName, String versionRule, String revision) {
MicroserviceInstances microserviceInstances = new MicroserviceInstances();
FindInstancesResponse findInstancesResponse = new FindInstancesResponse();
List<MicroserviceInstance> instances = new ArrayList<>();
Collectors.toList();
microserviceInstanceMap.values().forEach(allInstances -> allInstances.values().stream().filter(aInstance -> {
Microservice service = microserviceMap.get(aInstance.getServiceId());
return service.getAppId().equals(appId) && service.getServiceName().equals(serviceName);
}).forEach(item -> instances.add(item)));
if (instances.isEmpty()) {
microserviceInstances.setMicroserviceNotExist(true);
} else {
findInstancesResponse.setInstances(instances);
microserviceInstances.setMicroserviceNotExist(false);
microserviceInstances.setInstancesResponse(findInstancesResponse);
}
return microserviceInstances;
}
use of org.apache.servicecomb.registry.api.registry.FindInstancesResponse in project incubator-servicecomb-java-chassis by apache.
the class RegistryUtils method convertCacheToMicroserviceInstances.
/**
* for compatibility
*/
public static MicroserviceInstances convertCacheToMicroserviceInstances(MicroserviceCache microserviceCache) {
MicroserviceInstances microserviceInstances = new MicroserviceInstances();
switch(microserviceCache.getStatus()) {
case SERVICE_NOT_FOUND:
microserviceInstances.setMicroserviceNotExist(true);
microserviceInstances.setNeedRefresh(false);
microserviceInstances.setRevision("");
microserviceInstances.setInstancesResponse(null);
return microserviceInstances;
case NO_CHANGE:
microserviceInstances.setMicroserviceNotExist(false);
microserviceInstances.setNeedRefresh(false);
microserviceInstances.setRevision(microserviceCache.getRevisionId());
return microserviceInstances;
case REFRESHED:
microserviceInstances.setMicroserviceNotExist(false);
microserviceInstances.setNeedRefresh(true);
microserviceInstances.setRevision(microserviceCache.getRevisionId());
FindInstancesResponse findInstancesResponse = new FindInstancesResponse();
findInstancesResponse.setInstances(new ArrayList<>(microserviceCache.getInstances()));
microserviceInstances.setInstancesResponse(findInstancesResponse);
return microserviceInstances;
default:
return null;
}
}
use of org.apache.servicecomb.registry.api.registry.FindInstancesResponse in project incubator-servicecomb-java-chassis by apache.
the class StaticMicroserviceVersions method addInstances.
protected void addInstances(List<MicroserviceInstance> instances) {
for (int idx = 0; idx < instances.size(); idx++) {
MicroserviceInstance instance = instances.get(idx);
instance.setServiceId(microservice.getServiceId());
instance.setInstanceId(microservice.getServiceId() + "-" + idx);
}
microserviceInstances.setMicroserviceNotExist(false);
microserviceInstances.setInstancesResponse(new FindInstancesResponse());
microserviceInstances.getInstancesResponse().setInstances(instances);
}
Aggregations