List of usage examples for com.google.common.util.concurrent FutureCallback onSuccess
void onSuccess(@Nullable V result);
From source file:com.vmware.photon.controller.client.resource.ResourceTicketApi.java
/** * Get tasks associated with the specified resource ticket. * * @param resourceTicketId/* w w w. ja v a 2 s. c om*/ * @param responseCallback * @throws IOException */ public void getTasksForResourceTicketAsync(final String resourceTicketId, final FutureCallback<ResourceList<Task>> responseCallback) throws IOException { final String path = String.format("%s/%s/tasks", getBasePath(), resourceTicketId); ResourceList<Task> taskResourceList = new ResourceList<>(); FutureCallback<ResourceList<Task>> callback = new FutureCallback<ResourceList<Task>>() { @Override public void onSuccess(@Nullable ResourceList<Task> result) { if (taskResourceList.getItems() == null) { taskResourceList.setItems(result.getItems()); } else { taskResourceList.getItems().addAll(result.getItems()); } if (result.getNextPageLink() != null && !result.getNextPageLink().isEmpty()) { try { getObjectByPathAsync(result.getNextPageLink(), this, new TypeReference<ResourceList<Task>>() { }); } catch (IOException e) { e.printStackTrace(); } } else { responseCallback.onSuccess(taskResourceList); } } @Override public void onFailure(Throwable t) { responseCallback.onFailure(t); } }; getObjectByPathAsync(path, callback, new TypeReference<ResourceList<Task>>() { }); }
From source file:com.vmware.photon.controller.api.client.resource.FlavorRestApi.java
/** * Lists all flavors.// w w w .j a v a2 s .c o m * * @param responseCallback * @throws IOException */ @Override public void listAllAsync(final FutureCallback<ResourceList<Flavor>> responseCallback) throws IOException { ResourceList<Flavor> flavorResourceList = new ResourceList<>(); FutureCallback<ResourceList<Flavor>> callback = new FutureCallback<ResourceList<Flavor>>() { @Override public void onSuccess(@Nullable ResourceList<Flavor> result) { if (flavorResourceList.getItems() == null) { flavorResourceList.setItems(result.getItems()); } else { flavorResourceList.getItems().addAll(result.getItems()); } if (result.getNextPageLink() != null && !result.getNextPageLink().isEmpty()) { try { getObjectByPathAsync(result.getNextPageLink(), this, new TypeReference<ResourceList<Flavor>>() { }); } catch (IOException e) { e.printStackTrace(); } } else { responseCallback.onSuccess(flavorResourceList); } } @Override public void onFailure(Throwable t) { responseCallback.onFailure(t); } }; getObjectByPathAsync(getBasePath(), callback, new TypeReference<ResourceList<Flavor>>() { }); }
From source file:com.vmware.photon.controller.api.client.resource.ResourceTicketRestApi.java
/** * Get tasks associated with the specified resource ticket. * * @param resourceTicketId//from w ww . j a v a2 s.c om * @param responseCallback * @throws IOException */ @Override public void getTasksForResourceTicketAsync(final String resourceTicketId, final FutureCallback<ResourceList<Task>> responseCallback) throws IOException { final String path = String.format("%s/%s/tasks", getBasePath(), resourceTicketId); ResourceList<Task> taskResourceList = new ResourceList<>(); FutureCallback<ResourceList<Task>> callback = new FutureCallback<ResourceList<Task>>() { @Override public void onSuccess(@Nullable ResourceList<Task> result) { if (taskResourceList.getItems() == null) { taskResourceList.setItems(result.getItems()); } else { taskResourceList.getItems().addAll(result.getItems()); } if (result.getNextPageLink() != null && !result.getNextPageLink().isEmpty()) { try { getObjectByPathAsync(result.getNextPageLink(), this, new TypeReference<ResourceList<Task>>() { }); } catch (IOException e) { e.printStackTrace(); } } else { responseCallback.onSuccess(taskResourceList); } } @Override public void onFailure(Throwable t) { responseCallback.onFailure(t); } }; getObjectByPathAsync(path, callback, new TypeReference<ResourceList<Task>>() { }); }
From source file:com.vmware.photon.controller.api.client.resource.DeploymentApi.java
/** * Get all deployment vms./* w w w.j a v a 2 s.c o m*/ * * @param deploymentId * @return * @throws IOException */ public void getAllDeploymentVmsAsync(String deploymentId, final FutureCallback<ResourceList<Vm>> responseCallback) throws IOException { String path = String.format("%s/%s/vms", getBasePath(), deploymentId); ResourceList<Vm> vmResourceList = new ResourceList<>(); FutureCallback<ResourceList<Vm>> callback = new FutureCallback<ResourceList<Vm>>() { @Override public void onSuccess(@Nullable ResourceList<Vm> result) { if (vmResourceList.getItems() == null) { vmResourceList.setItems(result.getItems()); } else { vmResourceList.getItems().addAll(result.getItems()); } if (result.getNextPageLink() != null && !result.getNextPageLink().isEmpty()) { try { getObjectByPathAsync(result.getNextPageLink(), this, new TypeReference<ResourceList<Vm>>() { }); } catch (IOException e) { e.printStackTrace(); } } else { responseCallback.onSuccess(vmResourceList); } } @Override public void onFailure(Throwable t) { responseCallback.onFailure(t); } }; getObjectByPathAsync(path, callback, new TypeReference<ResourceList<Vm>>() { }); }
From source file:com.vmware.photon.controller.api.client.resource.DisksApi.java
/** * This method gets all tasks associated with a disk. * * @param diskId/* w w w . ja v a2 s . c o m*/ * @param responseCallback * @throws IOException */ public void getTasksForDiskAsync(final String diskId, final FutureCallback<ResourceList<Task>> responseCallback) throws IOException { String path = String.format("%s/%s/tasks", getBasePath(), diskId); ResourceList<Task> taskResourceList = new ResourceList<>(); FutureCallback<ResourceList<Task>> callback = new FutureCallback<ResourceList<Task>>() { @Override public void onSuccess(@Nullable ResourceList<Task> result) { if (taskResourceList.getItems() == null) { taskResourceList.setItems(result.getItems()); } else { taskResourceList.getItems().addAll(result.getItems()); } if (result.getNextPageLink() != null && !result.getNextPageLink().isEmpty()) { try { getObjectByPathAsync(result.getNextPageLink(), this, new TypeReference<ResourceList<Task>>() { }); } catch (IOException e) { e.printStackTrace(); } } else { responseCallback.onSuccess(taskResourceList); } } @Override public void onFailure(Throwable t) { responseCallback.onFailure(t); } }; getObjectByPathAsync(path, callback, new TypeReference<ResourceList<Task>>() { }); }
From source file:com.vmware.photon.controller.api.client.resource.ApiBase.java
/** * Deletes an object as async./*from ww w.j a v a 2 s. c o m*/ * * @param id * @param responseCallback * @throws IOException */ public final void deleteObjectAsync(final String id, final FutureCallback<Task> responseCallback) throws IOException { final String path = String.format("%s/%s", getBasePath(), id); this.restClient.performAsync(RestClient.Method.DELETE, path, null, new org.apache.http.concurrent.FutureCallback<HttpResponse>() { @Override public void completed(HttpResponse result) { Task task = null; try { restClient.checkResponse(result, HttpStatus.SC_CREATED); task = restClient.parseHttpResponse(result, new TypeReference<Task>() { }); } catch (Throwable e) { responseCallback.onFailure(e); } if (task != null) { Logger.getAnonymousLogger().log(Level.INFO, String .format("deleteObjectAsync returned task [%s] %s", this.toString(), path)); responseCallback.onSuccess(task); } else { Logger.getAnonymousLogger().log(Level.INFO, String.format("deleteObjectAsync failed [%s] %s", this.toString(), path)); } } @Override public void failed(Exception ex) { Logger.getAnonymousLogger().log(Level.INFO, "{}", ex); responseCallback.onFailure(ex); } @Override public void cancelled() { responseCallback.onFailure( new RuntimeException(String.format("deleteAsync %s was cancelled", path))); } }); }
From source file:com.vmware.photon.controller.api.client.resource.DeploymentRestApi.java
/** * Get all deployment vms.// w w w . ja v a2 s.co m * * @param deploymentId * @return * @throws IOException */ @Override public void getAllDeploymentVmsAsync(String deploymentId, final FutureCallback<ResourceList<Vm>> responseCallback) throws IOException { String path = String.format("%s/%s/vms", getBasePath(), deploymentId); ResourceList<Vm> vmResourceList = new ResourceList<>(); FutureCallback<ResourceList<Vm>> callback = new FutureCallback<ResourceList<Vm>>() { @Override public void onSuccess(@Nullable ResourceList<Vm> result) { if (vmResourceList.getItems() == null) { vmResourceList.setItems(result.getItems()); } else { vmResourceList.getItems().addAll(result.getItems()); } if (result.getNextPageLink() != null && !result.getNextPageLink().isEmpty()) { try { getObjectByPathAsync(result.getNextPageLink(), this, new TypeReference<ResourceList<Vm>>() { }); } catch (IOException e) { e.printStackTrace(); } } else { responseCallback.onSuccess(vmResourceList); } } @Override public void onFailure(Throwable t) { responseCallback.onFailure(t); } }; getObjectByPathAsync(path, callback, new TypeReference<ResourceList<Vm>>() { }); }
From source file:com.vmware.photon.controller.api.client.resource.DisksRestApi.java
/** * This method gets all tasks associated with a disk. * * @param diskId/* www.j a v a2 s. c o m*/ * @param responseCallback * @throws IOException */ @Override public void getTasksForDiskAsync(final String diskId, final FutureCallback<ResourceList<Task>> responseCallback) throws IOException { String path = String.format("%s/%s/tasks", getBasePath(), diskId); ResourceList<Task> taskResourceList = new ResourceList<>(); FutureCallback<ResourceList<Task>> callback = new FutureCallback<ResourceList<Task>>() { @Override public void onSuccess(@Nullable ResourceList<Task> result) { if (taskResourceList.getItems() == null) { taskResourceList.setItems(result.getItems()); } else { taskResourceList.getItems().addAll(result.getItems()); } if (result.getNextPageLink() != null && !result.getNextPageLink().isEmpty()) { try { getObjectByPathAsync(result.getNextPageLink(), this, new TypeReference<ResourceList<Task>>() { }); } catch (IOException e) { e.printStackTrace(); } } else { responseCallback.onSuccess(taskResourceList); } } @Override public void onFailure(Throwable t) { responseCallback.onFailure(t); } }; getObjectByPathAsync(path, callback, new TypeReference<ResourceList<Task>>() { }); }
From source file:com.vmware.photon.controller.clustermanager.clients.MesosClient.java
/** * This method calls into the Mesos API endpoint to retrieve the master leader ip addresses. * * @param connectionString connectionString of the master Node in the Cluster * @param callback callback that is invoked on completion of the operation. * @throws IOException/*from w w w . ja v a 2s.c o m*/ */ public void getMasterLeader(final String connectionString, final FutureCallback<String> callback) throws IOException { final RestClient restClient = new RestClient(connectionString, this.httpClient); org.apache.http.concurrent.FutureCallback futureCallback = new org.apache.http.concurrent.FutureCallback<HttpResponse>() { @Override public void completed(HttpResponse result) { final String leaderStringPrefix = "master@"; MasterState response; try { restClient.checkResponse(result, HttpStatus.SC_OK); response = objectMapper.readValue(result.getEntity().getContent(), new TypeReference<MasterState>() { }); } catch (Throwable e) { callback.onFailure(e); return; } if (StringUtils.isNotBlank(response.getLeader()) && response.getLeader().startsWith(leaderStringPrefix)) { callback.onSuccess(response.getLeader().replace(leaderStringPrefix, "http://")); } else { callback.onFailure(new RuntimeException("failed to get leader address.")); } } @Override public void failed(Exception ex) { callback.onFailure(ex); } @Override public void cancelled() { callback.onFailure(new RuntimeException("getMasterLeader was cancelled")); } }; restClient.performAsync(RestClient.Method.GET, MASTER_STATE_PATH, null, futureCallback); }
From source file:com.vmware.photon.controller.api.client.resource.DeploymentApi.java
/** * Lists all deployments.//from ww w . ja v a 2s .c o m * * @param responseCallback * @throws IOException */ public void listAllAsync(final FutureCallback<ResourceList<Deployment>> responseCallback) throws IOException { ResourceList<Deployment> deploymentResourceList = new ResourceList<>(); FutureCallback<ResourceList<Deployment>> callback = new FutureCallback<ResourceList<Deployment>>() { @Override public void onSuccess(@Nullable ResourceList<Deployment> result) { if (deploymentResourceList.getItems() == null) { deploymentResourceList.setItems(result.getItems()); } else { deploymentResourceList.getItems().addAll(result.getItems()); } if (result.getNextPageLink() != null && !result.getNextPageLink().isEmpty()) { try { getObjectByPathAsync(result.getNextPageLink(), this, new TypeReference<ResourceList<Deployment>>() { }); } catch (IOException e) { e.printStackTrace(); } } else { responseCallback.onSuccess(deploymentResourceList); } } @Override public void onFailure(Throwable t) { responseCallback.onFailure(t); } }; getObjectByPathAsync(getBasePath(), callback, new TypeReference<ResourceList<Deployment>>() { }); }