Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
com.spotinst.sdkjava.model.service.oceanCD.OceanCDService Maven / Gradle / Ivy
package com.spotinst.sdkjava.model.service.oceanCD;
import com.spotinst.sdkjava.client.response.BaseServiceEmptyResponse;
import com.spotinst.sdkjava.client.response.BaseSpotinstService;
import com.spotinst.sdkjava.client.rest.*;
import com.spotinst.sdkjava.exception.SpotinstHttpException;
import com.spotinst.sdkjava.model.api.oceanCD.ApiRolloutSpec;
import com.spotinst.sdkjava.model.api.oceanCD.ApiStrategy;
import com.spotinst.sdkjava.model.api.oceanCD.response.ApiRolloutStatus;
import com.spotinst.sdkjava.model.api.oceanCD.response.ApiRolloutsDetails;
import com.spotinst.sdkjava.model.requests.oceanCD.RolloutActions;
import com.spotinst.sdkjava.model.responses.oceanCD.CreateRolloutSpecApiResponse;
import com.spotinst.sdkjava.model.responses.oceanCD.CreateStrategyApiResponse;
import com.spotinst.sdkjava.model.responses.oceanCD.RolloutDetailsApiResponse;
import com.spotinst.sdkjava.model.responses.oceanCD.RolloutStatusApiResponse;
import org.apache.http.HttpStatus;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
/**
* Created by Janetlin Kiruba on 11/08/2022.
*/
public class OceanCDService extends BaseSpotinstService {
public static ApiStrategy createStrategy (ApiStrategy strategyRequest, String authToken) throws SpotinstHttpException {
// Init retVal
ApiStrategy retVal = null;
// Get endpoint
SpotinstHttpConfig config = SpotinstHttpContext.getInstance().getConfiguration();
String apiEndpoint = config.getEndpoint();
// Get the headers
Map headers = buildHeaders(authToken);
// Write to json
Map strategyReq = new HashMap<>();
strategyReq.put("strategy", strategyRequest);
String body = JsonMapper.toJson(strategyReq);
// Build URI
String uri = String.format("%s/ocean/cd/strategy", apiEndpoint);
// Send the request
RestResponse response = RestClient.sendPost(uri, body, headers, null);
// Handle the response.
CreateStrategyApiResponse strategyResponse =
getCastedResponse(response, CreateStrategyApiResponse.class);
if (strategyResponse.getResponse().getCount() > 0) {
retVal = strategyResponse.getResponse().getItems().get(0);
}
return retVal;
}
public static ApiStrategy getStrategy(String strategyName, String authToken) throws SpotinstHttpException {
// Init retVal
ApiStrategy retVal = new ApiStrategy();
// Get endpoint
SpotinstHttpConfig config = SpotinstHttpContext.getInstance().getConfiguration();
String apiEndpoint = config.getEndpoint();
// Get the headers for AWS.
Map headers = buildHeaders(authToken);
// Build URI
String uri = String.format("%s/ocean/cd/strategy/%s", apiEndpoint, strategyName);
// Send the request.
RestResponse response = RestClient.sendGet(uri, headers, null);
// Handle the response.
CreateStrategyApiResponse getStrategyResponse = getCastedResponse(response, CreateStrategyApiResponse.class);
if (getStrategyResponse.getResponse().getCount() > 0) {
retVal = getStrategyResponse.getResponse().getItems().get(0);
}
return retVal;
}
public static List getAllStrategies(String authToken) throws SpotinstHttpException {
// Init retVal
List retVal = new LinkedList<>();
// Get endpoint
SpotinstHttpConfig config = SpotinstHttpContext.getInstance().getConfiguration();
String apiEndpoint = config.getEndpoint();
// Get the headers for AWS.
Map headers = buildHeaders(authToken);
// Build URI
String uri = String.format("%s/ocean/cd/strategy", apiEndpoint);
// Send the request.
RestResponse response = RestClient.sendGet(uri, headers, null);
// Handle the response.
CreateStrategyApiResponse allStrategiesResponse = getCastedResponse(response, CreateStrategyApiResponse.class);
if (allStrategiesResponse.getResponse().getCount() > 0) {
retVal = allStrategiesResponse.getResponse().getItems();
}
return retVal;
}
public static Boolean updateStrategy(ApiStrategy strategyUpdateReq, String strategyName, String authToken) throws SpotinstHttpException {
//Init retVal
Boolean retVal = null;
// Get endpoint
SpotinstHttpConfig config = SpotinstHttpContext.getInstance().getConfiguration();
String apiEndpoint = config.getEndpoint();
// Get the headers
Map headers = buildHeaders(authToken);
// Build URI
String uri = String.format("%s/ocean/cd/strategy/%s", apiEndpoint, strategyName);
// Write to json
Map strategyRequest = new HashMap<>();
strategyRequest.put("strategy", strategyUpdateReq);
String body = JsonMapper.toJson(strategyRequest);
// Send the request.
RestResponse response = RestClient.sendPut(uri, body, headers, null);
// Handle the response.
BaseServiceEmptyResponse emptyResponse = getCastedResponse(response, BaseServiceEmptyResponse.class);
if (emptyResponse.getResponse().getStatus().getCode() == HttpStatus.SC_OK) {
retVal = true;
}
return retVal;
}
public static Boolean patchStrategy(ApiStrategy strategyUpdateReq, String strategyName, String authToken) throws SpotinstHttpException {
//Init retVal
Boolean retVal = null;
// Get endpoint
SpotinstHttpConfig config = SpotinstHttpContext.getInstance().getConfiguration();
String apiEndpoint = config.getEndpoint();
// Get the headers
Map headers = buildHeaders(authToken);
// Build URI
String uri = String.format("%s/ocean/cd/strategy/%s", apiEndpoint, strategyName);
// Write to json
Map strategyRequest = new HashMap<>();
strategyRequest.put("strategy", strategyUpdateReq);
String body = JsonMapper.toJson(strategyRequest);
// Send the request.
RestResponse response = RestClient.sendPatch(uri, body, headers, null);
// Handle the response.
BaseServiceEmptyResponse emptyResponse = getCastedResponse(response, BaseServiceEmptyResponse.class);
if (emptyResponse.getResponse().getStatus().getCode() == HttpStatus.SC_OK) {
retVal = true;
}
return retVal;
}
public static Boolean deleteStrategy(String strategyName, String authToken) throws SpotinstHttpException {
//Init retVal
Boolean retVal = null;
// Get endpoint
SpotinstHttpConfig config = SpotinstHttpContext.getInstance().getConfiguration();
String apiEndpoint = config.getEndpoint();
// Get the headers
Map headers = buildHeaders(authToken);
// Build URI
String uri = String.format("%s/ocean/cd/strategy/%s", apiEndpoint, strategyName);
// Send the request.
RestResponse response = RestClient.sendDelete(uri, null, headers, null);
// Handle the response.
BaseServiceEmptyResponse emptyResponse = getCastedResponse(response, BaseServiceEmptyResponse.class);
if (emptyResponse.getResponse().getStatus().getCode() == HttpStatus.SC_OK) {
retVal = true;
}
return retVal;
}
public static ApiRolloutSpec createRolloutSpec (ApiRolloutSpec rolloutSpecReq, String authToken) throws SpotinstHttpException {
// Init retVal
ApiRolloutSpec retVal = null;
// Get endpoint
SpotinstHttpConfig config = SpotinstHttpContext.getInstance().getConfiguration();
String apiEndpoint = config.getEndpoint();
// Get the headers
Map headers = buildHeaders(authToken);
// Write to json
Map strategyReq = new HashMap<>();
strategyReq.put("rolloutSpec", rolloutSpecReq);
String body = JsonMapper.toJson(strategyReq);
// Build URI
String uri = String.format("%s/ocean/cd/rolloutSpec", apiEndpoint);
// Send the request
RestResponse response = RestClient.sendPost(uri, body, headers, null);
// Handle the response.
CreateRolloutSpecApiResponse rolloutSpecResponse =
getCastedResponse(response, CreateRolloutSpecApiResponse.class);
if (rolloutSpecResponse.getResponse().getCount() > 0) {
retVal = rolloutSpecResponse.getResponse().getItems().get(0);
}
return retVal;
}
public static ApiRolloutSpec getRolloutSpec(String rolloutSpecName, String authToken) throws SpotinstHttpException {
// Init retVal
ApiRolloutSpec retVal = new ApiRolloutSpec();
// Get endpoint
SpotinstHttpConfig config = SpotinstHttpContext.getInstance().getConfiguration();
String apiEndpoint = config.getEndpoint();
// Get the headers for AWS.
Map headers = buildHeaders(authToken);
// Build URI
String uri = String.format("%s/ocean/cd/rolloutSpec/%s", apiEndpoint, rolloutSpecName);
// Send the request.
RestResponse response = RestClient.sendGet(uri, headers, null);
// Handle the response.
CreateRolloutSpecApiResponse getStrategyResponse = getCastedResponse(response, CreateRolloutSpecApiResponse.class);
if (getStrategyResponse.getResponse().getCount() > 0) {
retVal = getStrategyResponse.getResponse().getItems().get(0);
}
return retVal;
}
public static List getAllRolloutSpecs(String authToken) throws SpotinstHttpException {
// Init retVal
List retVal = new LinkedList<>();
// Get endpoint
SpotinstHttpConfig config = SpotinstHttpContext.getInstance().getConfiguration();
String apiEndpoint = config.getEndpoint();
// Get the headers for AWS.
Map headers = buildHeaders(authToken);
// Build URI
String uri = String.format("%s/ocean/cd/rolloutSpec", apiEndpoint);
// Send the request.
RestResponse response = RestClient.sendGet(uri, headers, null);
// Handle the response.
CreateRolloutSpecApiResponse allStrategiesResponse = getCastedResponse(response, CreateRolloutSpecApiResponse.class);
if (allStrategiesResponse.getResponse().getCount() > 0) {
retVal = allStrategiesResponse.getResponse().getItems();
}
return retVal;
}
public static Boolean updateRolloutSpec(ApiRolloutSpec rolloutSpecReq, String rolloutSpecName, String authToken) throws SpotinstHttpException {
//Init retVal
Boolean retVal = null;
// Get endpoint
SpotinstHttpConfig config = SpotinstHttpContext.getInstance().getConfiguration();
String apiEndpoint = config.getEndpoint();
// Get the headers
Map headers = buildHeaders(authToken);
// Build URI
String uri = String.format("%s/ocean/cd/rolloutSpec/%s", apiEndpoint, rolloutSpecName);
// Write to json
Map rolloutSpecRequest = new HashMap<>();
rolloutSpecRequest.put("rolloutSpec", rolloutSpecReq);
String body = JsonMapper.toJson(rolloutSpecRequest);
// Send the request.
RestResponse response = RestClient.sendPut(uri, body, headers, null);
// Handle the response.
BaseServiceEmptyResponse emptyResponse = getCastedResponse(response, BaseServiceEmptyResponse.class);
if (emptyResponse.getResponse().getStatus().getCode() == HttpStatus.SC_OK) {
retVal = true;
}
return retVal;
}
public static Boolean patchRolloutSpec(ApiRolloutSpec rolloutSpecReq, String rolloutSpecName, String authToken) throws SpotinstHttpException {
//Init retVal
Boolean retVal = null;
// Get endpoint
SpotinstHttpConfig config = SpotinstHttpContext.getInstance().getConfiguration();
String apiEndpoint = config.getEndpoint();
// Get the headers
Map headers = buildHeaders(authToken);
// Build URI
String uri = String.format("%s/ocean/cd/rolloutSpec/%s", apiEndpoint, rolloutSpecName);
// Write to json
Map rolloutSpecRequest = new HashMap<>();
rolloutSpecRequest.put("rolloutSpec", rolloutSpecReq);
String body = JsonMapper.toJson(rolloutSpecRequest);
// Send the request.
RestResponse response = RestClient.sendPatch(uri, body, headers, null);
// Handle the response.
BaseServiceEmptyResponse emptyResponse = getCastedResponse(response, BaseServiceEmptyResponse.class);
if (emptyResponse.getResponse().getStatus().getCode() == HttpStatus.SC_OK) {
retVal = true;
}
return retVal;
}
public static Boolean deleteRolloutSpec(String rolloutSpecName, String authToken) throws SpotinstHttpException {
//Init retVal
Boolean retVal = null;
// Get endpoint
SpotinstHttpConfig config = SpotinstHttpContext.getInstance().getConfiguration();
String apiEndpoint = config.getEndpoint();
// Get the headers
Map headers = buildHeaders(authToken);
// Build URI
String uri = String.format("%s/ocean/cd/rolloutSpec/%s", apiEndpoint, rolloutSpecName);
// Send the request.
RestResponse response = RestClient.sendDelete(uri, null, headers, null);
// Handle the response.
BaseServiceEmptyResponse emptyResponse = getCastedResponse(response, BaseServiceEmptyResponse.class);
if (emptyResponse.getResponse().getStatus().getCode() == HttpStatus.SC_OK) {
retVal = true;
}
return retVal;
}
public static ApiRolloutStatus getRolloutStatus(String rolloutId, String authToken) throws SpotinstHttpException {
// Init retVal
ApiRolloutStatus retVal = new ApiRolloutStatus();
// Get endpoint
SpotinstHttpConfig config = SpotinstHttpContext.getInstance().getConfiguration();
String apiEndpoint = config.getEndpoint();
// Get the headers for AWS.
Map headers = buildHeaders(authToken);
// Build URI
String uri = String.format("%s/ocean/cd/rollout/%s/status", apiEndpoint, rolloutId);
// Send the request.
RestResponse response = RestClient.sendGet(uri, headers, null);
// Handle the response.
RolloutStatusApiResponse getRolloutResponse = getCastedResponse(response, RolloutStatusApiResponse.class);
if (getRolloutResponse.getResponse().getCount() > 0) {
retVal = getRolloutResponse.getResponse().getItems().get(0);
}
return retVal;
}
public static List getAllRollouts(String fromDate, String authToken) throws SpotinstHttpException {
// Init retVal
List retVal = new LinkedList<>();
// Get endpoint
SpotinstHttpConfig config = SpotinstHttpContext.getInstance().getConfiguration();
String apiEndpoint = config.getEndpoint();
Map queryParams = new HashMap<>();
if (fromDate != null) {
queryParams.put("fromDate", fromDate);
}
// Get the headers for AWS.
Map headers = buildHeaders(authToken);
// Build URI
String uri = String.format("%s/ocean/cd/rollout", apiEndpoint);
// Send the request.
RestResponse response = RestClient.sendGet(uri, headers, queryParams);
// Handle the response.
RolloutDetailsApiResponse allRolloutsResponse = getCastedResponse(response, RolloutDetailsApiResponse.class);
if (allRolloutsResponse.getResponse().getCount() > 0) {
retVal = allRolloutsResponse.getResponse().getItems();
}
return retVal;
}
public static Boolean rolloutAction(RolloutActions rolloutActionsReq, String rolloutId, String authToken) throws SpotinstHttpException {
//Init retVal
Boolean retVal = null;
// Get endpoint
SpotinstHttpConfig config = SpotinstHttpContext.getInstance().getConfiguration();
String apiEndpoint = config.getEndpoint();
// Get the headers
Map headers = buildHeaders(authToken);
// Build URI
String uri = String.format("%s/ocean/cd/rollout/%s", apiEndpoint, rolloutId);
// Write to json
String body = JsonMapper.toJson(rolloutActionsReq);
// Send the request.
RestResponse response = RestClient.sendPut(uri, body, headers, null);
// Handle the response.
BaseServiceEmptyResponse emptyResponse = getCastedResponse(response, BaseServiceEmptyResponse.class);
if (emptyResponse.getResponse().getStatus().getCode() == HttpStatus.SC_OK) {
retVal = true;
}
return retVal;
}
}