-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SPOTAUT-9153 Implementation of EMR Scaler Routes #133
base: master
Are you sure you want to change the base?
Changes from 2 commits
44da47e
5b52b4f
f6f7ce4
fd9c2f7
e679de4
9a53785
2f80f35
b3bc1fc
3957604
5b67659
0d93dfb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.spotinst.sdkjava.model; | ||
|
||
import com.spotinst.sdkjava.exception.SpotinstNotSupportedException; | ||
import com.spotinst.sdkjava.model.api.mrScaler.aws.ApiMrScalerListInstancesAws; | ||
|
||
import java.util.List; | ||
|
||
public interface ISpotinstMrScalerListInstancesRepo extends IRepository<ApiMrScalerListInstancesAws, Void, String> { | ||
default RepoGenericResponse<List<ApiMrScalerListInstancesAws>> listMrScalerInstances(String mrScalerId, String authToken, String account){ | ||
throw new SpotinstNotSupportedException(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.spotinst.sdkjava.model; | ||
|
||
import com.spotinst.sdkjava.exception.SpotinstNotSupportedException; | ||
import com.spotinst.sdkjava.model.api.mrScaler.aws.ApiMrScalerListScalersAws; | ||
|
||
import java.util.List; | ||
|
||
public interface ISpotinstMrScalerListScalersRepo extends IRepository<ApiMrScalerListScalersAws, Void, String> { | ||
default RepoGenericResponse<List<ApiMrScalerListScalersAws>> listMrScalers(String mrScalerId, String authToken, String account){ | ||
throw new SpotinstNotSupportedException(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.spotinst.sdkjava.model; | ||
|
||
import com.spotinst.sdkjava.exception.SpotinstNotSupportedException; | ||
import com.spotinst.sdkjava.model.api.mrScaler.aws.ApiMrScalerScaleDownAws; | ||
|
||
import java.util.List; | ||
|
||
public interface ISpotinstMrScalerScaleDownRepo extends IRepository<ApiMrScalerScaleDownAws, Void, String> { | ||
default RepoGenericResponse<List<ApiMrScalerScaleDownAws>> scaleDownMrScaler(String mrScalerId, Integer adjustment, String authToken, String account){ | ||
throw new SpotinstNotSupportedException(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.spotinst.sdkjava.model; | ||
|
||
import com.spotinst.sdkjava.exception.SpotinstNotSupportedException; | ||
import com.spotinst.sdkjava.model.api.mrScaler.aws.ApiMrScalerScaleUpAws; | ||
|
||
import java.util.List; | ||
|
||
public interface ISpotinstMrScalerScaleUpRepo extends IRepository<ApiMrScalerScaleUpAws, Void, String> { | ||
default RepoGenericResponse<List<ApiMrScalerScaleUpAws>> scaleUpMrScaler(String mrScalerId, Integer adjustment, String authToken, String account){ | ||
throw new SpotinstNotSupportedException(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
import com.spotinst.sdkjava.exception.HttpError; | ||
import com.spotinst.sdkjava.exception.SpotinstHttpException; | ||
import com.spotinst.sdkjava.model.api.mrScaler.aws.*; | ||
import com.spotinst.sdkjava.model.requests.mrScaler.aws.*; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
|
@@ -13,10 +14,15 @@ public class SpotinstMrScalerAwsClient { | |
private static final Logger LOGGER = LoggerFactory.getLogger(SpotinstSpectrumClient.class); | ||
|
||
//region Members | ||
private String authToken; | ||
private String account; | ||
private ISpotinstMrScalerAwsRepo spotinstMrScalerRepo; | ||
private ISpotinstMrScalerOperatorAwsRepo spotinstMrScalerOperatorAwsRepo; | ||
private String authToken; | ||
private String account; | ||
private Integer adjustment; | ||
private ISpotinstMrScalerAwsRepo spotinstMrScalerRepo; | ||
private ISpotinstMrScalerOperatorAwsRepo spotinstMrScalerOperatorAwsRepo; | ||
private ISpotinstMrScalerListInstancesRepo sportMrScalerListInstancesRepo; | ||
private ISpotinstMrScalerListScalersRepo spotinstMrScalerListScalersRepo; | ||
private ISpotinstMrScalerScaleUpRepo spotinstMrScalerScaleUpRepo; | ||
private ISpotinstMrScalerScaleDownRepo spotinstMrScalerScaleDownRepo; | ||
|
||
public ISpotinstMrScalerAwsRepo getSpotinstMrScalerRepo() { | ||
return this.spotinstMrScalerRepo; | ||
|
@@ -34,6 +40,38 @@ public void setSpotinstMrScalerOperatorAwsRepo() { | |
this.spotinstMrScalerOperatorAwsRepo = SpotinstRepoManager.getInstance().getSpotinstMrScalerOperatorAwsRepo(); | ||
} | ||
|
||
public ISpotinstMrScalerListInstancesRepo getSpotinstMrScalerListInstancesRepo(){ | ||
return this.sportMrScalerListInstancesRepo; | ||
} | ||
|
||
public void setSportMrScalerListInstancesRepo(){ | ||
this.sportMrScalerListInstancesRepo = SpotinstRepoManager.getInstance().getSpotinstMrScalerListInstancesRepo(); | ||
} | ||
|
||
public ISpotinstMrScalerListScalersRepo getSpotinstMrScalerListScalersRepo(){ | ||
return this.spotinstMrScalerListScalersRepo; | ||
} | ||
|
||
public void setSpotinstMrScalerListScalersRepo(){ | ||
this.spotinstMrScalerListScalersRepo = SpotinstRepoManager.getInstance().getSpotinstMrScalerListScalersRepo(); | ||
} | ||
|
||
public ISpotinstMrScalerScaleUpRepo getSpotinstMrScalerScaleUpRepo(){ | ||
return this.spotinstMrScalerScaleUpRepo; | ||
} | ||
|
||
public void setSpotinstMrScalerScaleUpRepo(){ | ||
this.spotinstMrScalerScaleUpRepo = SpotinstRepoManager.getInstance().getSpotinstMrScalerScaleUpRepo(); | ||
} | ||
|
||
public ISpotinstMrScalerScaleDownRepo getSpotinstMrScalerScaleDownRepo(){ | ||
return this.spotinstMrScalerScaleDownRepo; | ||
} | ||
|
||
public void setSpotinstMrScalerScaleDownRepo(){ | ||
this.spotinstMrScalerScaleDownRepo = SpotinstRepoManager.getInstance().getSpotinstMrScalerScaleDownRepo(); | ||
} | ||
|
||
/** | ||
* This Object is used to store the users account and token information and then make requests to the | ||
* AWS MrScaler endpoints. | ||
|
@@ -47,6 +85,10 @@ public SpotinstMrScalerAwsClient(String authToken, String account) { | |
|
||
setSpotinstMrScalerRepo(); | ||
setSpotinstMrScalerOperatorAwsRepo(); | ||
setSportMrScalerListInstancesRepo(); | ||
setSpotinstMrScalerListScalersRepo(); | ||
setSpotinstMrScalerScaleUpRepo(); | ||
setSpotinstMrScalerScaleDownRepo(); | ||
} | ||
|
||
|
||
|
@@ -157,6 +199,109 @@ public ApiMrScalerAws getMrScaler(ApiMrScalerAwsGetRequest mrScalerAwsGetRequest | |
return retVal; | ||
} | ||
|
||
/** | ||
* This method is used to Get a list of all instances and instances groups in the cluster | ||
* | ||
* | ||
* @return a list of instances | ||
*/ | ||
public List<ApiMrScalerListInstancesAws> listMrScalerInstances( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Client class shouldn't have any reference of Api level objects. |
||
ApiMrScalerListInstancesRequest mrScalerListInstancesRequest) { | ||
List<ApiMrScalerListInstancesAws> retVal; | ||
String clusterToGet = mrScalerListInstancesRequest.getMrScalerId(); | ||
RepoGenericResponse<List<ApiMrScalerListInstancesAws>> mrScalerListInstances = getSpotinstMrScalerListInstancesRepo().listMrScalerInstances(clusterToGet, authToken, account); | ||
|
||
if(mrScalerListInstances.isRequestSucceed()){ | ||
retVal = mrScalerListInstances.getValue(); | ||
} | ||
else { | ||
List<HttpError> httpExceptions = mrScalerListInstances.getHttpExceptions(); | ||
HttpError httpException = httpExceptions.get(0); | ||
LOGGER.error(String.format("Error encountered while attempting to get a list of all instances and instances groups in the cluster. Code: %s. Message: %s.", | ||
httpException.getCode(), httpException.getMessage())); | ||
throw new SpotinstHttpException(httpException.getMessage()); | ||
} | ||
|
||
return retVal; | ||
} | ||
|
||
/** | ||
* This method is used to Scaler cluster | ||
* | ||
* | ||
* @return a list of Scaler cluster | ||
*/ | ||
public List<ApiMrScalerListScalersAws> listMrScalers(ApiMrScalerListMrScalersRequest mrScalerListScalersRequest) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need the ApiMrScalerListMrScalersRequest object. We can directly pass the MrScalerId. |
||
List<ApiMrScalerListScalersAws> retVal; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Client class shouldn't have any reference of Api level objects. |
||
String clusterToGet = mrScalerListScalersRequest.getMrScalerId(); | ||
RepoGenericResponse<List<ApiMrScalerListScalersAws>> mrScalerListScalers = getSpotinstMrScalerListScalersRepo().listMrScalers(clusterToGet, authToken, account); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Client class shouldn't have any reference of Api level objects. |
||
|
||
if(mrScalerListScalers.isRequestSucceed()){ | ||
retVal = mrScalerListScalers.getValue(); | ||
} | ||
else { | ||
List<HttpError> httpExceptions = mrScalerListScalers.getHttpExceptions(); | ||
HttpError httpException = httpExceptions.get(0); | ||
LOGGER.error(String.format("Error encountered while attempting to get a list of Scaler cluster. Code: %s. Message: %s.", | ||
httpException.getCode(), httpException.getMessage())); | ||
throw new SpotinstHttpException(httpException.getMessage()); | ||
} | ||
|
||
return retVal; | ||
} | ||
|
||
/** | ||
* This method is used to Scale Up the cluster | ||
* | ||
* | ||
* @return a list of instances | ||
*/ | ||
public List<ApiMrScalerScaleUpAws> scaleUpMrScaler(ApiMrScalerScaleUpRequest mrScalerScaleUpRequest) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need the ApiMrScalerScaleUpRequest object. We can directly pass the MrScalerId and adjustment |
||
List<ApiMrScalerScaleUpAws> retVal; | ||
String clusterToGet = mrScalerScaleUpRequest.getMrScalerId(); | ||
Integer adjustment = mrScalerScaleUpRequest.getAdjustment(); | ||
RepoGenericResponse<List<ApiMrScalerScaleUpAws>> mrScalerScaleUp = getSpotinstMrScalerScaleUpRepo().scaleUpMrScaler(clusterToGet, adjustment, authToken, account); | ||
|
||
if(mrScalerScaleUp.isRequestSucceed()){ | ||
retVal = mrScalerScaleUp.getValue(); | ||
} | ||
else { | ||
List<HttpError> httpExceptions = mrScalerScaleUp.getHttpExceptions(); | ||
HttpError httpException = httpExceptions.get(0); | ||
LOGGER.error(String.format("Error encountered while attempting to Scale Up the cluster. Code: %s. Message: %s.", | ||
httpException.getCode(), httpException.getMessage())); | ||
throw new SpotinstHttpException(httpException.getMessage()); | ||
} | ||
|
||
return retVal; | ||
} | ||
|
||
/** | ||
* This method is used to Scale Down the cluster | ||
* | ||
* | ||
* @return a list of instances | ||
*/ | ||
public List<ApiMrScalerScaleDownAws> scaleDownMrScaler(ApiMrScalerScaleDownRequest mrScalerScaleDownRequest) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment as previous function. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Client class shouldn't have any reference of Api level objects. |
||
List<ApiMrScalerScaleDownAws> retVal; | ||
String clusterToGet = mrScalerScaleDownRequest.getMrScalerId(); | ||
Integer adjustment = mrScalerScaleDownRequest.getAdjustment(); | ||
RepoGenericResponse<List<ApiMrScalerScaleDownAws>> mrScalerScaleDown = getSpotinstMrScalerScaleDownRepo().scaleDownMrScaler(clusterToGet, adjustment, authToken, account); | ||
|
||
if(mrScalerScaleDown.isRequestSucceed()){ | ||
retVal = mrScalerScaleDown.getValue(); | ||
} | ||
else { | ||
List<HttpError> httpExceptions = mrScalerScaleDown.getHttpExceptions(); | ||
HttpError httpException = httpExceptions.get(0); | ||
LOGGER.error(String.format("Error encountered while attempting to Scale Down the cluster. Code: %s. Message: %s.", | ||
httpException.getCode(), httpException.getMessage())); | ||
throw new SpotinstHttpException(httpException.getMessage()); | ||
} | ||
|
||
return retVal; | ||
} | ||
|
||
/** | ||
* This method is used to get all AWS MrScaler Clusters | ||
* | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should return BL object list