List of usage examples for com.squareup.okhttp Request.Builder Request.Builder
Request.Builder
From source file:com.netflix.spinnaker.clouddriver.artifacts.config.BaseHttpArtifactCredentials.java
License:Apache License
protected ResponseBody fetchUrl(HttpUrl url) throws IOException { Request request = new Request.Builder().headers(headers).url(url).build(); Response downloadResponse = okHttpClient.newCall(request).execute(); return downloadResponse.body(); }
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 . ja v a 2s . 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); }//from www .j a v a 2 s . c o 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 ava2 s.c o m*/ 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); }/* www.jav a2 s. c o m*/ 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); }/* w w w . j av a 2 s. c om*/ 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); }//from w ww .j a v a 2s. c o 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); }//from w ww . j a v a 2s. 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 www . j a v a 2 s. c om*/ }