use of org.apache.servicecomb.service.center.client.model.FindMicroserviceInstancesResponse in project java-chassis by ServiceComb.
the class ServiceCenterClient method findMicroserviceInstance.
@Override
public FindMicroserviceInstancesResponse findMicroserviceInstance(String consumerId, String appId, String serviceName, String versionRule, String revision) {
try {
Map<String, String> headers = new HashMap<>();
headers.put("X-ConsumerId", consumerId);
HttpResponse response = httpClient.getHttpRequest("/registry/instances?appId=" + URLEncoder.encode(appId, "UTF-8") + "&serviceName=" + HttpUtils.encodeURLParam(serviceName) + "&version=" + HttpUtils.encodeURLParam(versionRule) + "&rev=" + HttpUtils.encodeURLParam(revision), headers, null);
FindMicroserviceInstancesResponse result = new FindMicroserviceInstancesResponse();
if (response.getStatusCode() == HttpStatus.SC_OK) {
result.setModified(true);
result.setRevision(response.getHeader("X-Resource-Revision"));
result.setMicroserviceInstancesResponse(HttpUtils.deserialize(response.getContent(), MicroserviceInstancesResponse.class));
return result;
}
if (response.getStatusCode() == HttpStatus.SC_NOT_MODIFIED) {
result.setModified(false);
return result;
}
sendUnAuthorizedEvent(response);
throw new OperationException("get service instances list fails, statusCode = " + response.getStatusCode() + "; message = " + response.getMessage() + "; content = " + response.getContent());
} catch (IOException e) {
throw new OperationException("get service instances list fails", e);
}
}
use of org.apache.servicecomb.service.center.client.model.FindMicroserviceInstancesResponse in project java-chassis by ServiceComb.
the class ServiceCenterDiscovery method pullInstance.
private void pullInstance(SubscriptionKey k, SubscriptionValue v) {
if (myselfServiceId == null) {
// registration not ready
return;
}
try {
FindMicroserviceInstancesResponse instancesResponse = serviceCenterClient.findMicroserviceInstance(myselfServiceId, k.appId, k.serviceName, ALL_VERSION, v.revision);
if (instancesResponse.isModified()) {
List<MicroserviceInstance> instances = instancesResponse.getMicroserviceInstancesResponse().getInstances() == null ? Collections.emptyList() : instancesResponse.getMicroserviceInstancesResponse().getInstances();
setMicroserviceInfo(instances);
LOGGER.info("Instance changed event, " + "current: revision={}, instances={}; " + "origin: revision={}, instances={}; " + "appId={}, serviceName={}", instancesResponse.getRevision(), instanceToString(instances), v.revision, instanceToString(v.instancesCache), k.appId, k.serviceName);
v.instancesCache = instances;
v.revision = instancesResponse.getRevision();
eventBus.post(new InstanceChangedEvent(k.appId, k.serviceName, v.instancesCache));
}
} catch (Exception e) {
LOGGER.error("find service {}#{} instance failed.", k.appId, k.serviceName, e);
failedInstances.add(k);
}
}
Aggregations