List of usage examples for com.squareup.okhttp Response isSuccessful
public boolean isSuccessful()
From source file:com.twitter.heron.scheduler.kubernetes.AppsV1beta1Controller.java
License:Open Source License
boolean deleteStatefulSet() { try {//from w w w. j a va 2 s .c o m final V1DeleteOptions options = new V1DeleteOptions(); options.setGracePeriodSeconds(0L); options.setPropagationPolicy(KubernetesConstants.DELETE_OPTIONS_PROPAGATION_POLICY); final Response response = client.deleteNamespacedStatefulSetCall(getTopologyName(), getNamespace(), options, null, null, null, null, null, null).execute(); if (!response.isSuccessful()) { LOG.log(Level.SEVERE, "Error killing topology message: " + response.message()); KubernetesUtils.logResponseBodyIfPresent(LOG, response); throw new TopologyRuntimeManagementException(KubernetesUtils.errorMessageFromResponse(response)); } } catch (IOException | ApiException e) { KubernetesUtils.logExceptionWithDetails(LOG, "Error deleting topology", e); return false; } return true; }
From source file:com.twitter.heron.scheduler.kubernetes.AppsV1beta1Controller.java
License:Open Source License
boolean isStatefulSet() { try {/*from www . j av a2 s . com*/ final Response response = client .readNamespacedStatefulSetCall(getTopologyName(), getNamespace(), null, null, null, null, null) .execute(); return response.isSuccessful(); } catch (IOException | ApiException e) { LOG.warning("isStatefulSet check " + e.getMessage()); } return false; }
From source file:com.twitter.heron.scheduler.kubernetes.KubernetesCompat.java
License:Open Source License
boolean killTopology(String kubernetesUri, String topology, String namespace) { final CoreV1Api client = new CoreV1Api(new ApiClient().setBasePath(kubernetesUri)); // old version deployed topologies as naked pods try {// w ww. jav a 2 s . c o m final String labelSelector = KubernetesConstants.LABEL_TOPOLOGY + "=" + topology; final Response response = client.deleteCollectionNamespacedPodCall(namespace, null, null, null, null, labelSelector, null, null, null, null, null, null).execute(); if (!response.isSuccessful()) { LOG.log(Level.SEVERE, "Error killing topology message: " + response.message()); KubernetesUtils.logResponseBodyIfPresent(LOG, response); throw new TopologyRuntimeManagementException(KubernetesUtils.errorMessageFromResponse(response)); } } catch (IOException | ApiException e) { LOG.log(Level.SEVERE, "Error killing topology " + e.getMessage()); if (e instanceof ApiException) { LOG.log(Level.SEVERE, "Error details:\n" + ((ApiException) e).getResponseBody()); } return false; } return true; }
From source file:com.weather.hackathon.model.LayersFetcher.java
License:Open Source License
/** * Requests a new set of available tiles in the background. A successful load will notify the * {@link LayersResultListener} if one has been {@link #setLayersResultListener(LayersResultListener) set}. * * <p/> Only successful fetches are reported. Errors are logged and ignored. Listener's callback * {@link LayersResultListener#onLayersReceived(Collection) method} will be called on the same thread that * created this instance.//from w w w . j av a 2s . c o m * * <p/> The layers fetched will contain the {@link Layer#getTimestamp() timestamp} of the newest tiles for * that layer. */ public void fetchAsync() { Request request = new Request.Builder().url("http://hackathon.weather.com/Maps/jsonserieslist.do").build(); httpClient.newCall(request).enqueue(new Callback() { @Override public void onFailure(Request request, IOException e) { Log.e(TAG, "Unable to retrieve list of layers", e); } @Override public void onResponse(Response response) throws IOException { try { if (response.isSuccessful()) { final String json = response.body().string(); final Collection<Layer> layers = Layers.parseJson(json); handler.post(new Runnable() { @Override public void run() { if (layersResultListener != null) { layersResultListener.onLayersReceived(layers); } } }); } else { Log.e(TAG, "Error request list of layers. statusCode=" + response.code()); } } catch (JsonSyntaxException e) { Log.e(TAG, "Unable to parse list of layers", e); } } }); }
From source file:com.xjeffrose.xio2.http.server.FileHandlerTest.java
License:Apache License
@Test public void testHandle() throws Exception { Server s = Http.newServer();//from w w w. ja v a 2 s . c o m s.bind(9012, new FileHandler("src/test/resources")); s.serve(); OkHttpClient client = new OkHttpClient(); Request request = new Request.Builder().url("http://localhost:9012/test.txt").build(); Response response = client.newCall(request).execute(); if (!response.isSuccessful()) throw new IOException("Unexpected code " + response); assertTrue(response.isSuccessful()); assertEquals(response.code(), 200); assertEquals("this is a test.txt", response.body().string()); }
From source file:com.xjeffrose.xio2.http.server.ServerTest.java
License:Apache License
@Test(expected = IOException.class) public void testServe() throws Exception { s.bind(9000);/* ww w . ja va2s.co m*/ s.serve(); Request request = new Request.Builder().url("http://localhost:9000/").build(); Response response = client.newCall(request).execute(); if (!response.isSuccessful()) throw new IOException("Unexpected code " + response); assertEquals(response.code(), 404); }
From source file:com.xjeffrose.xio2.http.server.ServerTest.java
License:Apache License
@Test public void testAddRoute() throws Exception { s.serve(9003, testHandler);/*from w w w. ja v a 2 s .c om*/ Request request = new Request.Builder().url("http://localhost:9003/test").build(); Response response = client.newCall(request).execute(); if (!response.isSuccessful()) throw new IOException("Unexpected code " + response); assertTrue(response.isSuccessful()); assertEquals(response.code(), 200); assertEquals("THIS IS BODY", response.body().string()); }
From source file:com.xjeffrose.xio2.http.server.ServerTest.java
License:Apache License
@Test public void testAddRouteMany() throws Exception { s.serve(9004, testHandler);/*from w w w . j a v a 2 s .c om*/ Request request = new Request.Builder().url("http://localhost:9004/test").build(); // Simulate 1500 obj's / second final int reqs = 1500; for (int i = 0; i < reqs; i++) { Response response = client.newCall(request).execute(); if (!response.isSuccessful()) throw new IOException("Unexpected code " + response); assertTrue(response.isSuccessful()); assertEquals(response.code(), 200); assertEquals("THIS IS BODY", response.body().string()); } }
From source file:com.xjeffrose.xio2.http.server.ServerTest.java
License:Apache License
@Test public void testSsl() throws Exception { OkHttpClient unsafeClient = getUnsafeOkHttpClient(); s.serve(9005, testHttpsHandler);/*from w w w .j a va 2 s.c o m*/ Request request = new Request.Builder().url("https://localhost:9005/test").build(); Response response = unsafeClient.newCall(request).execute(); if (!response.isSuccessful()) throw new IOException("Unexpected code " + response); assertEquals(response.code(), 200); assertEquals("THIS IS BODY", response.body().string()); }
From source file:com.xjeffrose.xio2.http.server.ServerTest.java
License:Apache License
@Test public void testSslMany() throws Exception { OkHttpClient unsafeClient = getUnsafeOkHttpClient(); s.serve(9006, testHttpsHandler);//w ww . j av a2s .c om Request request = new Request.Builder().url("https://localhost:9006/test").build(); // Simulate 100 req's / second final int reqs = 100; for (int i = 0; i < reqs; i++) { Response response = unsafeClient.newCall(request).execute(); if (!response.isSuccessful()) throw new IOException("Unexpected code " + response); assertTrue(response.isSuccessful()); assertEquals(response.code(), 200); assertEquals("THIS IS BODY", response.body().string()); } }