use of javax.xml.ws.Holder in project java-chassis by ServiceComb.
the class ServiceRegistryClientImpl method getMicroserviceInstance.
@Override
public List<MicroserviceInstance> getMicroserviceInstance(String consumerId, String providerId) {
Holder<GetInstancesResponse> holder = new Holder<>();
IpPort ipPort = IpPortManager.INSTANCE.get();
StringBuilder url = new StringBuilder(Const.MS_API_PATH);
url.append(Const.MICROSERVICE_PATH).append("/").append(providerId).append(Const.INSTANCES_PATH);
CountDownLatch countDownLatch = new CountDownLatch(1);
RestUtils.get(ipPort, url.toString(), new RequestParam().addHeader("X-ConsumerId", consumerId), syncHandler(countDownLatch, GetInstancesResponse.class, holder));
try {
countDownLatch.await();
if (holder.value != null) {
return holder.value.getInstances();
}
} catch (Exception e) {
LOGGER.error("query microservice instances {} failed", providerId, e);
}
return null;
}
use of javax.xml.ws.Holder in project java-chassis by ServiceComb.
the class ServiceRegistryClientImpl method updateMicroserviceProperties.
@Override
public boolean updateMicroserviceProperties(String microserviceId, Map<String, String> serviceProperties) {
Holder<HttpClientResponse> holder = new Holder<>();
IpPort ipPort = IpPortManager.INSTANCE.get();
StringBuilder url = new StringBuilder(Const.MS_API_PATH);
url.append(Const.MICROSERVICE_PATH).append("/").append(microserviceId).append(Const.PROPERTIES_PATH);
try {
UpdatePropertiesRequest request = new UpdatePropertiesRequest();
request.setProperties(serviceProperties);
byte[] body = JsonUtils.writeValueAsBytes(request);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("update properties of microservice: {}", new String(body, Charset.defaultCharset()));
}
CountDownLatch countDownLatch = new CountDownLatch(1);
RestUtils.put(ipPort, url.toString(), new RequestParam().setBody(body), syncHandler(countDownLatch, HttpClientResponse.class, holder));
countDownLatch.await();
if (holder.value != null) {
if (holder.value.statusCode() == Status.OK.getStatusCode()) {
return true;
}
LOGGER.warn(holder.value.statusMessage());
}
} catch (Exception e) {
LOGGER.error("update properties of microservice {} failed", microserviceId, e);
}
return false;
}
use of javax.xml.ws.Holder in project java-chassis by ServiceComb.
the class ServiceRegistryClientImpl method isSchemaExist.
@Override
public boolean isSchemaExist(String microserviceId, String schemaId) {
Holder<GetExistenceResponse> holder = new Holder<>();
IpPort ipPort = IpPortManager.INSTANCE.get();
CountDownLatch countDownLatch = new CountDownLatch(1);
RestUtils.get(ipPort, Const.MS_API_PATH + Const.EXISTENCE_PATH, new RequestParam().addQueryParam("type", "schema").addQueryParam("serviceId", microserviceId).addQueryParam("schemaId", schemaId), syncHandler(countDownLatch, GetExistenceResponse.class, holder));
try {
countDownLatch.await();
} catch (Exception e) {
LOGGER.error("query schema exist {}/{} fail", microserviceId, schemaId, e);
}
return holder.value != null;
}
use of javax.xml.ws.Holder in project java-chassis by ServiceComb.
the class ServiceRegistryClientImpl method registerSchema.
@Override
public boolean registerSchema(String microserviceId, String schemaId, String schemaContent) {
Holder<HttpClientResponse> holder = new Holder<>();
IpPort ipPort = IpPortManager.INSTANCE.get();
try {
CreateSchemaRequest request = new CreateSchemaRequest();
request.setSchema(schemaContent);
byte[] body = JsonUtils.writeValueAsBytes(request);
CountDownLatch countDownLatch = new CountDownLatch(1);
RestUtils.put(ipPort, Const.MS_API_PATH + Const.MICROSERVICE_PATH + "/" + microserviceId + Const.SCHEMA_PATH + "/" + schemaId, new RequestParam().setBody(body), syncHandler(countDownLatch, HttpClientResponse.class, holder));
countDownLatch.await();
boolean result = false;
if (holder.value != null) {
result = holder.value.statusCode() == Status.OK.getStatusCode();
}
LOGGER.info("register schema {}/{}, result {}", microserviceId, schemaId, result);
return result;
} catch (Exception e) {
LOGGER.error("query schema exist {}/{} fail", microserviceId, schemaId, e);
}
return false;
}
use of javax.xml.ws.Holder in project java-chassis by ServiceComb.
the class ServiceRegistryClientImpl method getSchema.
@Override
public String getSchema(String microserviceId, String schemaId) {
Holder<GetSchemaResponse> holder = new Holder<>();
IpPort ipPort = IpPortManager.INSTANCE.get();
CountDownLatch countDownLatch = new CountDownLatch(1);
RestUtils.get(ipPort, Const.MS_API_PATH + Const.MICROSERVICE_PATH + "/" + microserviceId + Const.SCHEMA_PATH + "/" + schemaId, new RequestParam(), syncHandler(countDownLatch, GetSchemaResponse.class, holder));
try {
countDownLatch.await();
} catch (Exception e) {
LOGGER.error("query schema exist {}/{} failed", microserviceId, schemaId, e);
}
if (holder.value != null) {
return holder.value.getSchema();
}
return null;
}
Aggregations