List of usage examples for com.squareup.okhttp Response code
int code
To view the source code for com.squareup.okhttp Response code.
Click Source Link
From source file:com.oneops.crawler.OneOpsFacade.java
License:Apache License
public int forceDeploy(Environment env, Platform platform, String userName) throws IOException, OneOpsException { Map<String, Platform> platformMap = env.getPlatforms(); if (platformMap == null || platformMap.size() == 0) { return 400; }//from w w w .j a va 2 s. c o m StringBuilder excludePlatforms = new StringBuilder(); if (platform != null) { for (String platformName : platformMap.keySet()) { if (!platformName.equals(platform.getName())) { if (excludePlatforms.length() > 0) excludePlatforms.append(","); excludePlatforms.append(platformMap.get(platformName).getId()); } } } HashMap<String, String> params = new HashMap<>(); params.put("exclude", excludePlatforms.toString()); log.info("deploying environment id: " + env.getId()); RequestBody body = RequestBody.create(JSON, gson.toJson(params)); String url = transistorBaseUrl + "/transistor/rest/environments/" + env.getId() + "/deployments/deploy"; Request request = new Request.Builder().url(url).addHeader("X-Cms-User", userName) .addHeader("Content-Type", "application/json").post(body).build(); Response response = client.newCall(request).execute(); String responseBody = response.body().string(); int responseCode = response.code(); log.info("OO response body: " + responseBody + ", code: " + responseCode); if (responseCode >= 300) { throw new OneOpsException("Error while doing deployment. Response from OneOps: " + responseBody + " ResponseCode : " + responseCode); } return responseCode; }
From source file:com.oneops.crawler.OneOpsFacade.java
License:Apache License
public int disablePlatform(Platform platform, String userName) throws IOException, OneOpsException { log.info("disabling platform id: " + platform.getId()); String url = transistorBaseUrl + "/transistor/rest/platforms/" + platform.getId() + "/disable"; RequestBody body = RequestBody.create(JSON, ""); Request request = new Request.Builder().url(url).header("X-Cms-User", userName) .addHeader("Content-Type", "application/json").put(body).build(); Response response = client.newCall(request).execute(); String responseBody = response.body().string(); Map<String, Double> release = gson.fromJson(responseBody, Map.class); log.info("Response from OneOps for disable-platform api: " + release); int responseCode = response.code(); if (responseCode >= 300) { throw new OneOpsException("Could not disable platform, response from OneOps: " + responseBody + ", response code: " + responseCode); }/* www . j a v a2 s. co m*/ return responseCode; }
From source file:com.oneops.crawler.OneOpsFacade.java
License:Apache License
public int sendNotification(NotificationMessage msg) throws IOException, OneOpsException { String url = antennaBaseUrl + "/antenna/rest/notify/"; log.info(url + " sending notification: " + gson.toJson(msg)); RequestBody body = RequestBody.create(JSON, gson.toJson(msg)); Request request = new Request.Builder().url(url).addHeader("Content-Type", "application/json").post(body) .build();//from ww w.j ava 2 s . com Response response = client.newCall(request).execute(); String responseBody = response.body().string(); int responseCode = response.code(); if (responseCode >= 300) { throw new OneOpsException("Error while sending notification. Response from OneOps: " + responseBody + " ResponseCode : " + responseCode); } log.info("OO response body from antenna notify request: " + responseBody + ", code: " + responseCode); return responseCode; }
From source file:com.oneops.crawler.OneOpsFacade.java
License:Apache License
public int cancelDeployment(Deployment deployment, String userName) throws IOException { String url = adapterBaseUrl + "/adapter/rest/dj/simple/deployments/" + deployment.getDeploymentId() + "/cancel"; log.info("calling cancel deploy api: " + url); Request request = new Request.Builder().url(url).get().build(); Response response = client.newCall(request).execute(); String responseBody = response.body().string(); int responseCode = response.code(); log.info("OO response body for cance deployment: " + responseBody + ", code: " + responseCode); return responseCode; }
From source file:com.oneops.crawler.OneOpsFacade.java
License:Apache License
public Deployment scaleDown(long platformId, int scaleDownByNumber, int minComputesInEachCloud, String userId) throws IOException, OneOpsException { HashMap<String, String> params = new HashMap<>(); params.put("scaleDownBy", String.valueOf(scaleDownByNumber)); params.put("minComputesInEachCloud", String.valueOf(minComputesInEachCloud)); RequestBody body = RequestBody.create(JSON, gson.toJson(params)); String url = transistorBaseUrl + "/transistor/rest/platforms/" + +platformId + "/deployments/scaledown"; log.info("scaling down platform id: {} , url: {}", platformId, url); Request request = new Request.Builder().url(url).addHeader("X-Cms-User", userId) .addHeader("Content-Type", "application/json").post(body).build(); Response response = client.newCall(request).execute(); String responseBody = response.body().string(); int responseCode = response.code(); log.info("OO response body: {}, code: {}", responseBody, responseCode); if (responseCode >= 300) { throw new OneOpsException("Error while scaling down platform: " + platformId + ". Response from OneOps: " + responseBody + " ResponseCode : " + responseCode); }//w w w . j a v a 2 s . com if (!StringUtils.isEmpty(responseBody)) { return gson.fromJson(responseBody, Deployment.class); } return null; }
From source file:com.oneops.crawler.OneOpsFacade.java
License:Apache License
public int disableVerify(Environment env, String userName) throws IOException, OneOpsException { String envCiJson = getCiJson(env.getId()); envCiJson = envCiJson.replace("\"verify\":\"default\"", "\"verify\":\"false\""); envCiJson = envCiJson.replace("\"verify\":\"true\"", "\"verify\":\"false\""); RequestBody body = RequestBody.create(JSON, envCiJson); String url = adapterBaseUrl + "/adapter/rest/cm/simple/cis/" + env.getId(); Request request = new Request.Builder().url(url).addHeader("X-Cms-User", userName) .addHeader("Content-Type", "application/json").put(body).build(); Response response = client.newCall(request).execute(); String responseBody = response.body().string(); int responseCode = response.code(); log.info("OO response body: " + responseBody + ", code: " + responseCode); if (!response.isSuccessful()) { throw new OneOpsException("Error while disabling verify. Response from OneOps: " + responseBody + " ResponseCode : " + responseCode); }/*ww w .ja v a2s. com*/ return responseCode; }
From source file:com.oneops.crawler.OneOpsFacade.java
License:Apache License
public String getCiJson(long ciId) throws IOException { String url = adapterBaseUrl + "/adapter/rest/cm/simple/cis/" + ciId; Request request = new Request.Builder().url(url).get().build(); Response response = client.newCall(request).execute(); String responseBody = response.body().string(); int responseCode = response.code(); if (!response.isSuccessful()) { throw new RuntimeException("Error in getCi api. Response from OneOps: " + responseBody + " ResponseCode : " + responseCode); }/*w ww . java 2 s . co m*/ return responseBody; }
From source file:com.oneops.crawler.ThanosClient.java
License:Apache License
public ArrayList<CloudResourcesUtilizationStats> getStats(String path) throws IOException { String url = baseUrl + "?nspath=" + path; log.info("Calling thanos api: " + url); Request request = new Request.Builder().url(url).get().build(); Response response = client.newCall(request).execute(); String responseBody = response.body().string(); int responseCode = response.code(); log.info("Thanos api response code: " + responseCode); if (responseCode >= 300) { throw new RuntimeException("Error while calling Thanos api. Response from Thanos: " + responseBody + " ResponseCode : " + responseCode); }// ww w . ja v a 2 s . c o m ArrayList<CloudResourcesUtilizationStats> cloudResourcesUtilizationStats = new ArrayList<>(); if (StringUtils.isEmpty(responseBody)) { return cloudResourcesUtilizationStats; } log.info("response body: " + responseBody); ThanosServerResponse thanosServerResponse = gson.fromJson(responseBody, ThanosServerResponse.class); return thanosServerResponse.getCloudResourcesUtilizationStats(); }
From source file:com.oneops.crawler.ThanosClient.java
License:Apache License
public void updateStatus(String path, String status) throws IOException { HashMap payload = new HashMap(); payload.put("nspath", path); payload.put("status", status); RequestBody body = RequestBody.create(JSON, gson.toJson(payload)); Request request = new Request.Builder().url(baseUrl).addHeader("Authorization", "Bearer " + getAuthToken()) .addHeader("Content-Type", "application/json").post(body).build(); Response response = client.newCall(request).execute(); String responseBody = response.body().string(); int responseCode = response.code(); log.info("Thanos response body: " + responseBody + ", code: " + responseCode); if (responseCode >= 300) { throw new RuntimeException("Error while updating status on thanos. Response: " + responseBody + " ResponseCode : " + responseCode); }/*from ww w . ja va2 s .c om*/ }
From source file:com.pangbo.android.thirdframworks.retrofit.OkHttpCall.java
License:Apache License
private Response<T> parseResponse(com.squareup.okhttp.Response rawResponse) throws IOException { ResponseBody rawBody = rawResponse.body(); // Remove the body's source (the only stateful object) so we can pass the response along. rawResponse = rawResponse.newBuilder() .body(new NoContentResponseBody(rawBody.contentType(), rawBody.contentLength())).build(); int code = rawResponse.code(); if (code < 200 || code >= 300) { try {/*w ww.j a v a2 s .c o m*/ // Buffer the entire body to avoid future I/O. ResponseBody bufferedBody = Utils.readBodyToBytesIfNecessary(rawBody); return Response.error(bufferedBody, rawResponse); } finally { Utils.closeQuietly(rawBody); } } if (code == 204 || code == 205) { return Response.success(null, rawResponse); } ExceptionCatchingRequestBody catchingBody = new ExceptionCatchingRequestBody(rawBody); try { T body = responseConverter.convert(catchingBody); return Response.success(body, rawResponse); } catch (RuntimeException e) { // If the underlying source threw an exception, propagate that rather than indicating it was // a runtime exception. catchingBody.throwIfCaught(); throw e; } }