use of com.netflix.exhibitor.core.automanage.RemoteInstanceRequest in project exhibitor by soabase.
the class ClusterResource method makeRemoteRequest.
private String makeRemoteRequest(String methodName, String hostname, boolean responseIsJson, Callable<String> proc, Object... values) throws Exception {
String remoteResponse;
String errorMessage;
if (hostname.equals("localhost") || hostname.equals(context.getExhibitor().getThisJVMHostname())) {
remoteResponse = proc.call();
errorMessage = "";
} else {
try {
RemoteInstanceRequest request = new RemoteInstanceRequest(context.getExhibitor(), hostname);
RemoteInstanceRequest.Result result = request.makeRequest(context.getExhibitor().getRemoteInstanceRequestClient(), methodName, values);
remoteResponse = result.remoteResponse;
errorMessage = result.errorMessage;
} catch (Exception e) {
remoteResponse = "{}";
errorMessage = e.getMessage();
if (errorMessage == null) {
errorMessage = "Unknown";
}
}
}
ObjectMapper mapper = new ObjectMapper();
ObjectNode node = JsonNodeFactory.instance.objectNode();
if (responseIsJson) {
node.put("response", mapper.readTree(mapper.getJsonFactory().createJsonParser(remoteResponse)));
} else {
node.put("response", remoteResponse);
}
node.put("errorMessage", errorMessage);
node.put("success", errorMessage.length() == 0);
return JsonUtil.writeValueAsString(node);
}
use of com.netflix.exhibitor.core.automanage.RemoteInstanceRequest in project exhibitor by soabase.
the class ConfigManager method checkNextInstanceState.
private ConfigCollection checkNextInstanceState(ConfigCollection config, List<String> rollingHostNames, int rollingHostNamesIndex) {
if ((rollingHostNamesIndex + 1) >= rollingHostNames.size()) {
// we're done - switch back to single config
return new ConfigCollectionImpl(config.getRollingConfig(), null);
}
ConfigCollection newCollection = new ConfigCollectionImpl(config.getRootConfig(), config.getRollingConfig(), rollingHostNames, rollingHostNamesIndex + 1);
RollingReleaseState state = new RollingReleaseState(new InstanceState(), newCollection);
if (state.getCurrentRollingHostname().equals(exhibitor.getThisJVMHostname())) {
return newCollection;
}
RollingConfigAdvanceAttempt activeAttempt = rollingConfigAdvanceAttempt.get();
RemoteInstanceRequest.Result result;
if ((activeAttempt == null) || !activeAttempt.getHostname().equals(state.getCurrentRollingHostname()) || (activeAttempt.getAttemptCount() < maxAttempts)) {
RemoteInstanceRequest remoteInstanceRequest = new RemoteInstanceRequest(exhibitor, state.getCurrentRollingHostname());
result = callRemoteInstanceRequest(remoteInstanceRequest);
if (activeAttempt == null) {
activeAttempt = new RollingConfigAdvanceAttempt(state.getCurrentRollingHostname());
rollingConfigAdvanceAttempt.set(activeAttempt);
}
activeAttempt.incrementAttemptCount();
if (result.errorMessage.length() != 0) {
if (activeAttempt.getAttemptCount() >= maxAttempts) {
exhibitor.getLog().add(ActivityLog.Type.INFO, "Exhausted attempts to connect to " + remoteInstanceRequest.getHostname() + " - skipping and moving on to next instance");
// it must be down. Skip it.
newCollection = checkNextInstanceState(config, rollingHostNames, rollingHostNamesIndex + 1);
} else {
exhibitor.getLog().add(ActivityLog.Type.INFO, "Could not connect to " + remoteInstanceRequest.getHostname() + " - attempt #" + activeAttempt.getAttemptCount());
newCollection = null;
}
}
} else {
newCollection = null;
}
return newCollection;
}
Aggregations