Refactor :: remove 'async' on every http call

This commit is contained in:
Anthony Corbacho 2016-11-18 19:22:25 +01:00
parent dbb8ebd98a
commit e88420319c
3 changed files with 15 additions and 15 deletions

View file

@ -160,7 +160,7 @@ public class ZeppelinHubRepo implements NotebookRepo {
if (StringUtils.isBlank(ticket)) {
return "";
}
List<Instance> instances = restApiClient.asyncGetInstances(ticket);
List<Instance> instances = restApiClient.getInstances(ticket);
// TODO(anthony): Implement NotebookRepo Setting to let user switch token at runtime.
token = instances.get(0).token;
return token;
@ -191,7 +191,7 @@ public class ZeppelinHubRepo implements NotebookRepo {
return Collections.emptyList();
}
String token = getUserToken(subject.getUser());
String response = restApiClient.asyncGet(token, StringUtils.EMPTY);
String response = restApiClient.get(token, StringUtils.EMPTY);
List<NoteInfo> notes = GSON.fromJson(response, new TypeToken<List<NoteInfo>>() {}.getType());
if (notes == null) {
return Collections.emptyList();
@ -206,7 +206,7 @@ public class ZeppelinHubRepo implements NotebookRepo {
return EMPTY_NOTE;
}
String token = getUserToken(subject.getUser());
String response = restApiClient.asyncGet(token, noteId);
String response = restApiClient.get(token, noteId);
Note note = GSON.fromJson(response, Note.class);
if (note == null) {
return EMPTY_NOTE;
@ -223,14 +223,14 @@ public class ZeppelinHubRepo implements NotebookRepo {
String jsonNote = GSON.toJson(note);
String token = getUserToken(subject.getUser());
LOG.info("ZeppelinHub REST API saving note {} ", note.getId());
restApiClient.asyncPut(token, jsonNote);
restApiClient.put(token, jsonNote);
}
@Override
public void remove(String noteId, AuthenticationInfo subject) throws IOException {
String token = getUserToken(subject.getUser());
LOG.info("ZeppelinHub REST API removing note {} ", noteId);
restApiClient.asyncDel(token, noteId);
restApiClient.del(token, noteId);
}
@Override
@ -248,7 +248,7 @@ public class ZeppelinHubRepo implements NotebookRepo {
String content = GSON.toJson(ImmutableMap.of("message", checkpointMsg));
String token = getUserToken(subject.getUser());
String response = restApiClient.asyncPutWithResponseBody(token, endpoint, content);
String response = restApiClient.putWithResponseBody(token, endpoint, content);
return GSON.fromJson(response, Revision.class);
}
@ -261,7 +261,7 @@ public class ZeppelinHubRepo implements NotebookRepo {
String endpoint = Joiner.on("/").join(noteId, "checkpoint", revId);
String token = getUserToken(subject.getUser());
String response = restApiClient.asyncGet(token, endpoint);
String response = restApiClient.get(token, endpoint);
Note note = GSON.fromJson(response, Note.class);
if (note == null) {
@ -280,7 +280,7 @@ public class ZeppelinHubRepo implements NotebookRepo {
List<Revision> history = Collections.emptyList();
try {
String token = getUserToken(subject.getUser());
String response = restApiClient.asyncGet(token, endpoint);
String response = restApiClient.get(token, endpoint);
history = GSON.fromJson(response, new TypeToken<List<Revision>>(){}.getType());
} catch (IOException e) {
LOG.error("Cannot get note history", e);

View file

@ -125,7 +125,7 @@ public class ZeppelinhubRestApiHandler {
* @return
* @throws IOException
*/
public List<Instance> asyncGetInstances(String ticket) throws IOException {
public List<Instance> getInstances(String ticket) throws IOException {
InputStreamResponseListener listener = new InputStreamResponseListener();
Response response;
String url = zepelinhubUrl + "instances";
@ -154,12 +154,12 @@ public class ZeppelinhubRestApiHandler {
return new Gson().fromJson(data, listType);
}
public String asyncGet(String token, String argument) throws IOException {
public String get(String token, String argument) throws IOException {
String url = zepelinhubUrl + argument;
return sendToZeppelinHub(HttpMethod.GET, url, StringUtils.EMPTY, token, true);
}
public String asyncPutWithResponseBody(String token, String url, String json) throws IOException {
public String putWithResponseBody(String token, String url, String json) throws IOException {
if (StringUtils.isBlank(url) || StringUtils.isBlank(json)) {
LOG.error("Empty note, cannot send it to zeppelinHub");
throw new IOException("Cannot send emtpy note to zeppelinHub");
@ -167,7 +167,7 @@ public class ZeppelinhubRestApiHandler {
return sendToZeppelinHub(HttpMethod.PUT, zepelinhubUrl + url, json, token, true);
}
public void asyncPut(String token, String jsonNote) throws IOException {
public void put(String token, String jsonNote) throws IOException {
if (StringUtils.isBlank(jsonNote)) {
LOG.error("Cannot save empty note/string to ZeppelinHub");
return;
@ -175,7 +175,7 @@ public class ZeppelinhubRestApiHandler {
sendToZeppelinHub(HttpMethod.PUT, zepelinhubUrl, jsonNote, token, false);
}
public void asyncDel(String token, String argument) throws IOException {
public void del(String token, String argument) throws IOException {
if (StringUtils.isBlank(argument)) {
LOG.error("Cannot delete empty note from ZeppelinHub");
return;

View file

@ -43,10 +43,10 @@ public class ZeppelinHubRepoTest {
ZeppelinhubRestApiHandler mockedZeppelinhubHandler = mock(ZeppelinhubRestApiHandler.class);
byte[] response = Files.toByteArray(pathOfNotebooks);
when(mockedZeppelinhubHandler.asyncGet("", "")).thenReturn(new String(response));
when(mockedZeppelinhubHandler.get("", "")).thenReturn(new String(response));
response = Files.toByteArray(pathOfNotebook);
when(mockedZeppelinhubHandler.asyncGet("", "AAAAA")).thenReturn(new String(response));
when(mockedZeppelinhubHandler.get("", "AAAAA")).thenReturn(new String(response));
return mockedZeppelinhubHandler;
}