com.spotinst.sdkjava.model.AzureAksVngClient Maven / Gradle / Ivy
package com.spotinst.sdkjava.model;
import com.spotinst.sdkjava.exception.HttpError;
import com.spotinst.sdkjava.exception.SpotinstHttpException;
import com.spotinst.sdkjava.model.bl.ocean.aks.ClusterVirtualNodeGroup;
import com.spotinst.sdkjava.model.bl.ocean.aks.LaunchNodesInAksVNG;
import com.spotinst.sdkjava.model.bl.ocean.aks.LaunchNodesInAksVNGResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
public class AzureAksVngClient {
private static final Logger LOGGER = LoggerFactory.getLogger(AzureAksVngClient.class);
private String authToken;
private String account;
private ISpotAzureAksVngRepo aksVngRepo;
public ISpotAzureAksVngRepo getAksVngRepo() {
return aksVngRepo;
}
public AzureAksVngClient(String authToken, String account) {
this.authToken = authToken;
this.account = account;
setAksVngRepo();
}
public void setAksVngRepo() {
this.aksVngRepo = SpotinstRepoManager.getInstance().getAksVngRepo();
}
public ClusterVirtualNodeGroup createAksVng(ClusterVirtualNodeGroup clusterVirtualNodeGroup) {
ClusterVirtualNodeGroup retVal;
RepoGenericResponse creationResponse = getAksVngRepo().create(clusterVirtualNodeGroup, authToken, account);
if (creationResponse.isRequestSucceed()) {
retVal = creationResponse.getValue();
}
else {
List httpExceptions = creationResponse.getHttpExceptions();
HttpError httpException = httpExceptions.get(0);
LOGGER.error(
String.format("Error encountered while attempting to create AKS Virtual Node Group. Code: %s. Message: %s.",
httpException.getCode(), httpException.getMessage()));
throw new SpotinstHttpException(httpException.getMessage());
}
return retVal;
}
public Boolean updateAKSVng(String launchSpecId, ClusterVirtualNodeGroup aksVngUpdate) {
Boolean retVal;
RepoGenericResponse updateResponse = getAksVngRepo().update(launchSpecId, aksVngUpdate, authToken, account);
if (updateResponse.isRequestSucceed()) {
retVal = updateResponse.getValue();
}
else {
List httpExceptions = updateResponse.getHttpExceptions();
HttpError httpException = httpExceptions.get(0);
LOGGER.error(String.format("Error encountered while attempting to update AKS cluster Virtual Node Group. Code: %s. Message: %s.",
httpException.getCode(), httpException.getMessage()));
throw new SpotinstHttpException(httpException.getMessage());
}
return retVal;
}
public Boolean deleteAksVng(String vngId) {
Boolean retVal;
RepoGenericResponse clusterDeletionResponse = getAksVngRepo().delete(vngId, authToken, account);
if (clusterDeletionResponse.isRequestSucceed()) {
retVal = clusterDeletionResponse.getValue();
}
else {
List httpExceptions = clusterDeletionResponse.getHttpExceptions();
HttpError httpException = httpExceptions.get(0);
LOGGER.error(
String.format("Error encountered while attempting to delete AKS Virtual Node Group. Code: %s. Message: %s.",
httpException.getCode(), httpException.getMessage()));
throw new SpotinstHttpException(httpException.getMessage());
}
return retVal;
}
public ClusterVirtualNodeGroup getAksVng(String aksVngId) {
ClusterVirtualNodeGroup retVal;
RepoGenericResponse clusterRes = getAksVngRepo().get(aksVngId, authToken, account);
if (clusterRes.isRequestSucceed()) {
retVal = clusterRes.getValue();
}
else {
List httpExceptions = clusterRes.getHttpExceptions();
HttpError httpException = httpExceptions.get(0);
LOGGER.error(
String.format("Error encountered while attempting to get aks Virtual Node Group. Code: %s. Message: %s.",
httpException.getCode(), httpException.getMessage()));
throw new SpotinstHttpException(httpException.getMessage());
}
return retVal;
}
public List listAksVng(String oceanId) {
List retVal;
RepoGenericResponse> clusterRes = getAksVngRepo().list(authToken, account, oceanId);
if (clusterRes.isRequestSucceed()) {
retVal = clusterRes.getValue();
}
else {
List httpExceptions = clusterRes.getHttpExceptions();
HttpError httpException = httpExceptions.get(0);
LOGGER.error(
String.format("Error encountered while attempting to list AKS Virtual Node Group. Code: %s. Message: %s.",
httpException.getCode(), httpException.getMessage()));
throw new SpotinstHttpException(httpException.getMessage());
}
return retVal;
}
public List launchNodesInVNG(LaunchNodesInAksVNG lauchNodes, String vngId) {
List retVal;
RepoGenericResponse> launchNodesResponse = getAksVngRepo().launchNodesInVNG(lauchNodes, vngId, authToken, account);
if (launchNodesResponse.isRequestSucceed()) {
retVal = launchNodesResponse.getValue();
}
else {
List httpExceptions = launchNodesResponse.getHttpExceptions();
HttpError httpException = httpExceptions.get(0);
LOGGER.error(
String.format("Error encountered while attempting to launch nodes in Virtual Node Group. Code: %s. Message: %s.",
httpException.getCode(), httpException.getMessage()));
throw new SpotinstHttpException(httpException.getMessage());
}
return retVal;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy