Skip to content
Open
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
package com.spotinst.sdkjava.client.http;

import org.apache.http.annotation.Contract;
import org.apache.http.annotation.ThreadingBehavior;
import org.apache.http.client.methods.HttpPost;

import java.net.URI;

public class GetRequestWithBody extends HttpPost {
/**
* Created by Saikumar Jalda on 03 Mar 2022
*
*/

@Contract(threading = ThreadingBehavior.UNSAFE)
public class GetRequestWithBody extends HttpPost {
@Override
public String getMethod() {
return "GET";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,4 +323,5 @@ private static RestResponse buildRestResponse(HttpResponse response) throws Spot

return retVal;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
import com.spotinst.sdkjava.model.bl.elastigroup.aws.*;
import com.spotinst.sdkjava.model.requests.elastigroup.*;
import com.spotinst.sdkjava.model.requests.elastigroup.aws.*;
import com.spotinst.sdkjava.model.bl.elastigroup.aws.SuspendedScalingPolicy;
import com.spotinst.sdkjava.model.responses.elastigroup.aws.CodeDeployBGDeploymentResponse;
import com.sun.org.apache.xpath.internal.operations.Bool;

import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
Expand Down Expand Up @@ -223,6 +224,15 @@ public static void main(String[] args) throws IOException {
// Beanstalk Reimport
System.out.println("----------Beanstalk Reimport--------------");
beanstalkReimport(elastigroupClient, groupId);

//Create codeDeploy B/G deployment
System.out.println("----------Create CodeDeploy B/G Deployment--------------");
deploymentId = createCodeDeployBGDeployment(elastigroupClient, "elastigroup-id").get(0).getId();

//Get codeDeploy B/G deployment
System.out.println("----------Get CodeDeploy B/G Deployment--------------");
String getDeploymentId = getCodeDeployBGDeployment(elastigroupClient, "elastigroup-id").get(0).getId();

}

private static void getInstanceHealthiness(SpotinstElastigroupClient elastigroupClient, String elastigroupId) {
Expand Down Expand Up @@ -1311,4 +1321,85 @@ private static Elastigroup beanstalkReimport(SpotinstElastigroupClient client, S
System.out.println(String.format("Instance ID: %s", response.getId()));
return response;
}

private static List<CodeDeployBGDeploymentResponse> createCodeDeployBGDeployment(SpotinstElastigroupClient elastigroupClient,
String elastigroupId) {

//Build Tags
Tag.Builder tagsBuilder = Tag.Builder.get();
Tag tags =
tagsBuilder.setTagKey("ver").setTagValue("pink").build();
List<Tag> tagsArrayList = new ArrayList<>();
tagsArrayList.add(tags);

//Build deploymentGroup
ElastigroupDeploymentGroup.Builder deploymentGroupBuilder = ElastigroupDeploymentGroup.Builder.get();
ElastigroupDeploymentGroup deploymentGroup =
deploymentGroupBuilder.setApplicationName("appTest").setDeploymentGroupName("deploymentGroupName").build();
List<ElastigroupDeploymentGroup> deploymentGroupArrayList = new ArrayList<>();
deploymentGroupArrayList.add(deploymentGroup);

//Build CodeDeploy
ElastigroupCodeDeployBGDeployment.Builder codeDeployBuilder = ElastigroupCodeDeployBGDeployment.Builder.get();
ElastigroupCodeDeployBGDeployment codeDeploy =
codeDeployBuilder.setTimeout(20).setTags(tagsArrayList).setDeploymentGroups(deploymentGroupArrayList).build();

//Build Create CodeDeploy Deployment Request
ElastigroupCreateCodeDeployRequest.Builder createCodeDeployRequestBuilder = ElastigroupCreateCodeDeployRequest.Builder.get();
ElastigroupCreateCodeDeployRequest createCodeDeployRequest =
createCodeDeployRequestBuilder.setCodeDeployBGDeployment(codeDeploy).build();

System.out.println("Create Deployment Request for elastigroup:" + elastigroupId);
System.out.println(createCodeDeployRequest.toJson());

List<CodeDeployBGDeploymentResponse> codeDeployBGDeploymentResponse =
elastigroupClient.createCodeDeployBGDeployment(createCodeDeployRequest, elastigroupId);

System.out.println("Create deployment for elastigroup: " + elastigroupId + " with id " + codeDeployBGDeploymentResponse.get(0).getId() +
" with groupid " + codeDeployBGDeploymentResponse.get(0).getGroupId() +
" and state " + codeDeployBGDeploymentResponse.get(0).getState());

return codeDeployBGDeploymentResponse;

}

private static List<CodeDeployBGDeploymentResponse> getCodeDeployBGDeployment(SpotinstElastigroupClient elastigroupClient,
String elastigroupId) {

//Build Tag
Tag.Builder tagsBuilder = Tag.Builder.get();
Tag tags =
tagsBuilder.setTagKey("ver").setTagValue("pink").build();
List<Tag> tagsArrayList = new ArrayList<>();
tagsArrayList.add(tags);

//Build deploymentGroup
ElastigroupDeploymentGroup.Builder deploymentGroupBuilder = ElastigroupDeploymentGroup.Builder.get();
ElastigroupDeploymentGroup deploymentGroup =
deploymentGroupBuilder.setApplicationName("appTest").setDeploymentGroupName("deploymentGroupName").build();
List<ElastigroupDeploymentGroup> deploymentGroupArrayList = new ArrayList<>();
deploymentGroupArrayList.add(deploymentGroup);

//Build CodeDeploy
ElastigroupCodeDeployBGDeployment.Builder codeDeployBuilder = ElastigroupCodeDeployBGDeployment.Builder.get();
ElastigroupCodeDeployBGDeployment codeDeploy =
codeDeployBuilder.setTimeout(120).setTags(tagsArrayList).setDeploymentGroups(deploymentGroupArrayList).build();

//Build Get CodeDeploy Deployment Request
ElastigroupGetCodeDeployRequest.Builder getCodeDeployRequestBuilder = ElastigroupGetCodeDeployRequest.Builder.get();
ElastigroupGetCodeDeployRequest getCodeDeployRequest =
getCodeDeployRequestBuilder.setCodeDeployBGDeployment(codeDeploy).build();

System.out.println("Get Deployment Request for elastigroup:" + elastigroupId);
System.out.println(getCodeDeployRequest.toJson());

List<CodeDeployBGDeploymentResponse> codeDeployBGDeploymentResponse =
elastigroupClient.getCodeDeployBGDeployment(getCodeDeployRequest, elastigroupId);

System.out.println("Get deployment for elastigroup: " + elastigroupId + " with id " + codeDeployBGDeploymentResponse.get(0).getId() +
" with groupid " + codeDeployBGDeploymentResponse.get(0).getGroupId() +
" and state " + codeDeployBGDeploymentResponse.get(0).getState());

return codeDeployBGDeploymentResponse;
}
}
87 changes: 87 additions & 0 deletions src/main/java/com/spotinst/sdkjava/model/ElastigroupConverter.java
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.spotinst.sdkjava.enums.aws.elastigroup.AwsTerminationPolicyEnum;
import com.spotinst.sdkjava.model.api.elastigroup.aws.*;
import com.spotinst.sdkjava.model.bl.elastigroup.aws.*;
import com.spotinst.sdkjava.model.responses.elastigroup.aws.CodeDeployBGDeploymentResponse;

import java.util.LinkedList;
import java.util.List;
Expand Down Expand Up @@ -4060,7 +4061,93 @@ public static ElastigroupGetInstanceStatusResponse toBl(

}
return retVal;
}

public static ApiElastigroupCodeDeployBGDeployment toDal(ElastigroupCodeDeployBGDeployment codeDeployBGDeployment) {
ApiElastigroupCodeDeployBGDeployment retVal = null;

if (codeDeployBGDeployment != null) {
retVal = new ApiElastigroupCodeDeployBGDeployment();

if (codeDeployBGDeployment.isTimeoutSet()) {
retVal.setTimeout(codeDeployBGDeployment.getTimeout());
}

if (codeDeployBGDeployment.isTagsSet()) {
if (codeDeployBGDeployment.getTags() != null) {
List<ApiTag> tags =
codeDeployBGDeployment.getTags().stream().map(ElastigroupConverter::toDal)
.collect(Collectors.toList());
retVal.setTags(tags);
}
}

if (codeDeployBGDeployment.isDeploymentGroupsSet()) {
if (codeDeployBGDeployment.getDeploymentGroups() != null) {
List<ApiDeploymentGroup> deploymentGroups =
codeDeployBGDeployment.getDeploymentGroups().stream().map((ElastigroupConverter::toDal))
.collect(Collectors.toList());
retVal.setDeploymentGroups(deploymentGroups);
}
}
}
return retVal;
}

public static CodeDeployBGDeploymentResponse toBl(ApiCodeDeployBGDeploymentResponse apiCodeDeployBGResponse) {
CodeDeployBGDeploymentResponse retVal = null;

if (apiCodeDeployBGResponse != null) {

retVal = new CodeDeployBGDeploymentResponse();

if (apiCodeDeployBGResponse.isIdSet()) {
retVal.setId(apiCodeDeployBGResponse.getId());
}

if (apiCodeDeployBGResponse.isGroupIdSet()) {
retVal.setGroupId(apiCodeDeployBGResponse.getGroupId());
}

if (apiCodeDeployBGResponse.isStateSet()) {
retVal.setState(apiCodeDeployBGResponse.getState());
}

if (apiCodeDeployBGResponse.isConfigSet()) {
retVal.setConfig(apiCodeDeployBGResponse.getConfig());
}

}
return retVal;
}

private static CodeDeployConfig toBl(ApiCodeDeployConfig apiCodeDeployConfig) {
CodeDeployConfig retVal = null;

if (apiCodeDeployConfig != null) {

retVal = new CodeDeployConfig();

if (apiCodeDeployConfig.isTimeoutSet()) {
retVal.setTimeout(apiCodeDeployConfig.getTimeout());
}

if (apiCodeDeployConfig.isTagsSet()) {
List<Tag> tags =
apiCodeDeployConfig.getTag().stream().map(ElastigroupConverter::toBl)
.collect(Collectors.toList());
retVal.setTags(tags);
}

if (apiCodeDeployConfig.isDeploymentGroupsSet()) {
List<ElastigroupDeploymentGroup> deploymentGroups =
apiCodeDeployConfig.getDeploymentGroups().stream().map(ElastigroupConverter::toBl)
.collect(Collectors.toList());
retVal.setDeploymentGroups(deploymentGroups);
}

}
return retVal;
}

public static ElastigroupGetBeanstalkMaintenanceStatusResponse toBl(ApiElastigroupGetBeanstalkMaintenanceStatusResponse apiGetBeanstalkStatus) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.spotinst.sdkjava.model.requests.elastigroup.ElastigroupInstanceLockRequest;
import com.spotinst.sdkjava.model.requests.elastigroup.ElastigroupInstanceUnLockRequest;
import com.spotinst.sdkjava.model.requests.elastigroup.aws.*;
import com.spotinst.sdkjava.model.responses.elastigroup.aws.CodeDeployBGDeploymentResponse;

import java.util.List;

Expand Down Expand Up @@ -136,4 +137,8 @@ RepoGenericResponse<Boolean> deallocateStatefulInstance(String elastigroupId, St
RepoGenericResponse<Elastigroup> beanstalkReimport(String groupId, String authToken, String account);

RepoGenericResponse<Boolean> amiBackup(String elastigroupId, String authToken, String account);

RepoGenericResponse<List<CodeDeployBGDeploymentResponse>> createCodeDeployBGDeployment(ElastigroupCreateCodeDeployRequest request, String elastigroupId, String authToken, String account);

RepoGenericResponse<List<CodeDeployBGDeploymentResponse>> getCodeDeployBGDeployment(ElastigroupGetCodeDeployRequest request, String elastigroupId, String authToken, String account);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.spotinst.sdkjava.model.requests.elastigroup.ElastigroupInstanceLockRequest;
import com.spotinst.sdkjava.model.requests.elastigroup.ElastigroupInstanceUnLockRequest;
import com.spotinst.sdkjava.model.requests.elastigroup.aws.*;
import com.spotinst.sdkjava.model.responses.elastigroup.aws.CodeDeployBGDeploymentResponse;
import com.spotinst.sdkjava.utils.TimeUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -1430,4 +1431,52 @@ public Boolean amiBackup(String groupId) {

return retVal;
}

public List<CodeDeployBGDeploymentResponse> createCodeDeployBGDeployment(ElastigroupCreateCodeDeployRequest request, String elastigroupId) {

List<CodeDeployBGDeploymentResponse> codeDeployBGDeploymentResponses;

RepoGenericResponse <List<CodeDeployBGDeploymentResponse>> getCodeDeployResponse =
getSpotinstElastigroupRepo().createCodeDeployBGDeployment(request, elastigroupId, authToken, account);

if(getCodeDeployResponse.isRequestSucceed()){
codeDeployBGDeploymentResponses = getCodeDeployResponse.getValue();
}
else {
List<HttpError> httpExceptions = getCodeDeployResponse.getHttpExceptions();
HttpError httpException = httpExceptions.get(0);
LOGGER.error(String.format(
"Error encountered while attempting to get the instance types by region. Code: %s. Message: %s.",

httpException.getCode(), httpException.getMessage()));

throw new SpotinstHttpException(httpException.getMessage());
}

return codeDeployBGDeploymentResponses;

}

public List<CodeDeployBGDeploymentResponse> getCodeDeployBGDeployment(ElastigroupGetCodeDeployRequest request, String elastigroupId) {

List<CodeDeployBGDeploymentResponse> codeDeployBGDeploymentResponses;

RepoGenericResponse<List<CodeDeployBGDeploymentResponse>> getCodeDeployResponse =
getSpotinstElastigroupRepo().getCodeDeployBGDeployment(request, elastigroupId, authToken, account);

if (getCodeDeployResponse.isRequestSucceed()) {
codeDeployBGDeploymentResponses = getCodeDeployResponse.getValue();
} else {
List<HttpError> httpExceptions = getCodeDeployResponse.getHttpExceptions();
HttpError httpException = httpExceptions.get(0);
LOGGER.error(String.format(
"Error encountered while attempting to get the instance types by region. Code: %s. Message: %s.",

httpException.getCode(), httpException.getMessage()));

throw new SpotinstHttpException(httpException.getMessage());
}

return codeDeployBGDeploymentResponses;
}
}
Loading