本文整理汇总了Java中com.ecwid.consul.v1.QueryParams类的典型用法代码示例。如果您正苦于以下问题:Java QueryParams类的具体用法?Java QueryParams怎么用?Java QueryParams使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
QueryParams类属于com.ecwid.consul.v1包,在下文中一共展示了QueryParams类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: lookupRouterMessage
import com.ecwid.consul.v1.QueryParams; //导入依赖的package包/类
public ConsulRouterResp lookupRouterMessage(String serviceName, long lastConsulIndex) {
QueryParams queryParams = new QueryParams(ConsulConstants.CONSUL_BLOCK_TIME_SECONDS, lastConsulIndex);
Response<GetValue> orgResponse = client.getKVValue(serviceName, queryParams);
GetValue getValue = orgResponse.getValue();
if (getValue != null && StringUtils.isNoneBlank(getValue.getValue())) {
String router = new String(Base64.decodeBase64(getValue.getValue()));
ConsulRouterResp response = ConsulRouterResp.newResponse()//
.withValue(router)//
.withConsulIndex(orgResponse.getConsulIndex())//
.withConsulLastContact(orgResponse.getConsulLastContact())//
.withConsulKnowLeader(orgResponse.isConsulKnownLeader())//
.build();
return response;
}
return null;
}
示例2: run
import com.ecwid.consul.v1.QueryParams; //导入依赖的package包/类
@Override
public void run() {
Set<String> sessionIds = Sets.newHashSet();
for (ConsulSession session : sessions) {
try {
String sessionId = session.getSessionId();
if (!sessionIds.contains(sessionId)) {
client.renewSession(sessionId, QueryParams.DEFAULT);
sessionIds.add(sessionId);
}
log.debug("Sending consul heartbeat for: " + sessionId);
} catch (Throwable e) {
failedsessions.addAll(sessions);
sessions.clear();
log.error(e.getMessage(), e);
}
}
}
示例3: testEmptyResolution
import com.ecwid.consul.v1.QueryParams; //导入依赖的package包/类
@Test
public void testEmptyResolution() throws Exception {
final Response<List<CatalogService>> response = composeResponse(new ArrayList<>());
new Expectations() {{
catalogClient.getCatalogService(SERVICE_NAME, QueryParams.DEFAULT);
result = response;
times = 1;
}};
final List<NameResolverEvent<?>> events = runTest(resolver, 1);
assertEquals(1, events.size());
final NameResolverEvent e = events.get(0);
assertEquals(NameResolverEventType.ON_ADDRESSES, e.type);
assertTrue(((List) e.payload).isEmpty());
}
示例4: testFailingResolution
import com.ecwid.consul.v1.QueryParams; //导入依赖的package包/类
@Test
public void testFailingResolution() throws Exception {
new Expectations() {{
catalogClient.getCatalogService(SERVICE_NAME, QueryParams.DEFAULT);
result = new RuntimeException();
maxTimes = 5;
}};
final List<NameResolverEvent<?>> events = runTest(resolver, 5);
// allow for an off by 1
assertTrue(events.size() >= 4);
assertTrue(events.size() <= 5);
for (final NameResolverEvent<?> event : events) {
assertEquals(NameResolverEventType.ON_ERROR, event.type);
final Status s = (Status) event.payload;
assertEquals(Status.UNAVAILABLE.getCode(), s.getCode());
assertTrue(s.getCause() instanceof RuntimeException);
}
}
示例5: beforeClass
import com.ecwid.consul.v1.QueryParams; //导入依赖的package包/类
@BeforeClass
public static void beforeClass() {
assumeTrue(CanConnect.to(new InetSocketAddress(CONSUL_HOST, CONSUL_PORT)));
ConsulClient client = new ConsulClient();
Response<List<CatalogService>> response = client.getCatalogService("vault",
QueryParams.DEFAULT);
if (response.getValue().isEmpty()) {
NewService service = new NewService();
service.setAddress("localhost");
service.setPort(8200);
service.setId("vault");
service.setName("vault");
client.agentServiceRegister(service);
}
}
示例6: getKVBinaryValues
import com.ecwid.consul.v1.QueryParams; //导入依赖的package包/类
@Override
public Response<List<GetBinaryValue>> getKVBinaryValues(String keyPrefix, String token, QueryParams queryParams) {
UrlParameters recurseParam = new SingleUrlParameters("recurse");
UrlParameters tokenParam = token != null ? new SingleUrlParameters("token", token) : null;
RawResponse rawResponse = rawClient.makeGetRequest("/v1/kv/" + keyPrefix, recurseParam, tokenParam, queryParams);
if (rawResponse.getStatusCode() == 200) {
List<GetBinaryValue> value = GsonFactory.getGson().fromJson(rawResponse.getContent(), new TypeToken<List<GetBinaryValue>>() {
}.getType());
return new Response<List<GetBinaryValue>>(value, rawResponse);
} else if (rawResponse.getStatusCode() == 404) {
return new Response<List<GetBinaryValue>>(null, rawResponse);
} else {
throw new OperationException(rawResponse);
}
}
示例7: getSessionInfo
import com.ecwid.consul.v1.QueryParams; //导入依赖的package包/类
@Override
public Response<Session> getSessionInfo(String session, QueryParams queryParams) {
RawResponse rawResponse = rawClient.makeGetRequest("/v1/session/info/" + session, queryParams);
if (rawResponse.getStatusCode() == 200) {
List<Session> value = GsonFactory.getGson().fromJson(rawResponse.getContent(), new TypeToken<List<Session>>() {
}.getType());
if (value.isEmpty()) {
return new Response<Session>(null, rawResponse);
} else if (value.size() == 1) {
return new Response<Session>(value.get(0), rawResponse);
} else {
throw new ConsulException("Strange response (list size=" + value.size() + ")");
}
} else {
throw new OperationException(rawResponse);
}
}
示例8: getKVKeysOnly
import com.ecwid.consul.v1.QueryParams; //导入依赖的package包/类
@Override
public Response<List<String>> getKVKeysOnly(String keyPrefix, String separator, String token, QueryParams queryParams) {
UrlParameters separatorParam = separator != null ? new SingleUrlParameters("separator", separator) : null;
UrlParameters tokenParam = token != null ? new SingleUrlParameters("token", token) : null;
RawResponse rawResponse = rawClient.makeGetRequest("/v1/kv/" + keyPrefix, separatorParam, tokenParam, queryParams);
if (rawResponse.getStatusCode() == 200) {
List<String> value = GsonFactory.getGson().fromJson(rawResponse.getContent(), new TypeToken<List<String>>() {
}.getType());
return new Response<List<String>>(value, rawResponse);
} else if (rawResponse.getStatusCode() == 404) {
return new Response<List<String>>(null, rawResponse);
} else {
throw new OperationException(rawResponse);
}
}
示例9: getKVBinaryValue
import com.ecwid.consul.v1.QueryParams; //导入依赖的package包/类
@Override
public Response<GetBinaryValue> getKVBinaryValue(String key, String token, QueryParams queryParams) {
UrlParameters tokenParams = token != null ? new SingleUrlParameters("token", token) : null;
RawResponse rawResponse = rawClient.makeGetRequest("/v1/kv/" + key, tokenParams, queryParams);
if (rawResponse.getStatusCode() == 200) {
List<GetBinaryValue> value = GsonFactory.getGson().fromJson(rawResponse.getContent(), new TypeToken<List<GetBinaryValue>>(){}.getType());
if (value.size() == 0) {
return new Response<GetBinaryValue>(null, rawResponse);
} else if (value.size() == 1) {
return new Response<GetBinaryValue>(value.get(0), rawResponse);
} else {
throw new ConsulException("Strange response (list size=" + value.size() + ")");
}
} else if (rawResponse.getStatusCode() == 404) {
return new Response<GetBinaryValue>(null, rawResponse);
} else {
throw new OperationException(rawResponse);
}
}
示例10: getKVValues
import com.ecwid.consul.v1.QueryParams; //导入依赖的package包/类
@Override
public Response<List<GetValue>> getKVValues(String keyPrefix, String token, QueryParams queryParams) {
UrlParameters recurseParam = new SingleUrlParameters("recurse");
UrlParameters tokenParam = token != null ? new SingleUrlParameters("token", token) : null;
RawResponse rawResponse = rawClient.makeGetRequest("/v1/kv/" + keyPrefix, recurseParam, tokenParam, queryParams);
if (rawResponse.getStatusCode() == 200) {
List<GetValue> value = GsonFactory.getGson().fromJson(rawResponse.getContent(), new TypeToken<List<GetValue>>() {
}.getType());
return new Response<List<GetValue>>(value, rawResponse);
} else if (rawResponse.getStatusCode() == 404) {
return new Response<List<GetValue>>(null, rawResponse);
} else {
throw new OperationException(rawResponse);
}
}
示例11: getServiceInstances
import com.ecwid.consul.v1.QueryParams; //导入依赖的package包/类
@Override
protected List<ServerInstance> getServiceInstances(String serviceName) {
List<ServiceInstance> instances = new ArrayList<>();
Response<List<HealthService>> healthServices = consulClient.getHealthServices(serviceName, true, QueryParams.DEFAULT);
for (HealthService healthService : healthServices.getValue()) {
if (isPassingChecks(healthService)) {
String host = findHost(healthService);
instances.add(new DefaultServiceInstance(serviceName, host,
healthService.getService().getPort(), false, getMetadata(healthService)));
}
}
return convertToServerInstanceList(instances);
}
示例12: lookupHealthService
import com.ecwid.consul.v1.QueryParams; //导入依赖的package包/类
public ConsulServiceResp lookupHealthService(String serviceName, long lastConsulIndex) {
QueryParams queryParams = new QueryParams(ConsulConstants.CONSUL_BLOCK_TIME_SECONDS, lastConsulIndex);
Response<List<HealthService>> orgResponse = client.getHealthServices(serviceName, true, queryParams);
if (orgResponse != null && orgResponse.getValue() != null && !orgResponse.getValue().isEmpty()) {
List<HealthService> HealthServices = orgResponse.getValue();
List<ConsulService> ConsulServcies = Lists.newArrayList();
for (HealthService orgService : HealthServices) {
Service org = orgService.getService();
ConsulService newService = ConsulService.newSalukiService()//
.withAddress(org.getAddress())//
.withName(org.getService())//
.withId(org.getId())//
.withPort(org.getPort().toString())//
.withTags(org.getTags())//
.build();
ConsulServcies.add(newService);
}
if (!ConsulServcies.isEmpty()) {
ConsulServiceResp response = ConsulServiceResp.newResponse()//
.withValue(ConsulServcies)//
.withConsulIndex(orgResponse.getConsulIndex())//
.withConsulLastContact(orgResponse.getConsulLastContact())//
.withConsulKnowLeader(orgResponse.isConsulKnownLeader())//
.build();
return response;
}
}
return null;
}
示例13: testFixedResolution
import com.ecwid.consul.v1.QueryParams; //导入依赖的package包/类
@Test
public void testFixedResolution() throws Exception {
final CatalogService service = new CatalogService();
service.setAddress("localhost");
service.setServicePort(8080);
final List<CatalogService> services = new ArrayList<>();
services.add(service);
final Response<List<CatalogService>> response = composeResponse(services);
new Expectations() {{
catalogClient.getCatalogService(SERVICE_NAME, QueryParams.DEFAULT);
result = response;
times = 1;
}};
final List<NameResolverEvent<?>> events = runTest(resolver, 1);
assertEquals(1, events.size());
final NameResolverEvent e = events.get(0);
assertEquals(NameResolverEventType.ON_ADDRESSES, e.type);
final List<EquivalentAddressGroup> addressGroups = (List<EquivalentAddressGroup>) e.payload;
assertEquals(1, addressGroups.size());
final List<SocketAddress> addresses = addressGroups.get(0).getAddresses();
assertEquals(1, addresses.size());
final InetSocketAddress inetAddress = (InetSocketAddress) addresses.get(0);
assertEquals("localhost", inetAddress.getHostName());
assertEquals(8080, inetAddress.getPort());
}
示例14: testRemoved
import com.ecwid.consul.v1.QueryParams; //导入依赖的package包/类
@Test
@Repeat(iterations = 5)
public void testRemoved() throws Exception {
final Response<List<GetValue>> initialResponse = randomListGetValueResponse();
final GetValue removed = initialResponse.getValue().get(randomInt(initialResponse.getValue().size() -1));
final List<GetValue> updatedList = Lists.newArrayList(initialResponse.getValue());
updatedList.remove(removed);
final Response<List<GetValue>> initialResponseMinus = randomResponse(updatedList);
//noinspection unchecked
when(client.getKVValues(eq(rootPath), any(QueryParams.class))).thenReturn(initialResponse, initialResponseMinus);
UpdateListener listener = new UpdateListener();
configSource.addUpdateListener(listener);
configSource.runOnce();
assertThat(configSource.getLatestIndex(), is(initialResponse.getConsulIndex()));
configSource.runOnce();
assertThat(configSource.getLatestIndex(), is(initialResponseMinus.getConsulIndex()));
assertThat(listener.events.get(), is(2));
assertThat(configSource.getCurrentData().values(), not(hasItem(decodeVal(removed.getValue()))));
WatchedUpdateResult result = listener.results.get(1);
assertThat(result.getDeleted().values(), hasItem(decodeVal(removed.getValue())));
assertThat(result.getAdded().isEmpty(), is(true));
assertThat(result.getChanged().isEmpty(), is(true));
assertThat(result.isIncremental(), is(true));
}
示例15: deleteKVValues
import com.ecwid.consul.v1.QueryParams; //导入依赖的package包/类
@Override
public Response<Void> deleteKVValues(String key, String token, QueryParams queryParams) {
UrlParameters recurseParam = new SingleUrlParameters("recurse");
UrlParameters tokenParam = token != null ? new SingleUrlParameters("token", token) : null;
RawResponse rawResponse = rawClient.makeDeleteRequest("/v1/kv/" + key, tokenParam, recurseParam, queryParams);
if (rawResponse.getStatusCode() == 200) {
return new Response<Void>(null, rawResponse);
} else {
throw new OperationException(rawResponse);
}
}