com.spotinst.sdkjava.model.repo.ocean.aks.SpotOceanAzureAksClusterRepo Maven / Gradle / Ivy
package com.spotinst.sdkjava.model.repo.ocean.aks;
import com.spotinst.sdkjava.exception.ExceptionHelper;
import com.spotinst.sdkjava.exception.SpotinstHttpException;
import com.spotinst.sdkjava.model.ISpotOceanAzureAksClusterRepo;
import com.spotinst.sdkjava.model.RepoGenericResponse;
import com.spotinst.sdkjava.model.SpotOceanAzureAksClusterService;
import com.spotinst.sdkjava.model.api.ocean.aks.*;
import com.spotinst.sdkjava.model.bl.ocean.aks.*;
import com.spotinst.sdkjava.model.requests.ocean.aks.GetAksClusterNodesRequest;
import java.util.List;
import java.util.stream.Collectors;
public class SpotOceanAzureAksClusterRepo implements ISpotOceanAzureAksClusterRepo {
@Override
public RepoGenericResponse create(OceanClusterAks clusterToCreate, String authToken, String account) {
RepoGenericResponse retVal;
try {
ApiClusterAks apiClusterAks = ClusterConverterAks.toDal(clusterToCreate);
ApiClusterAks apiCreatedCluster = SpotOceanAzureAksClusterService.createAksCluster(apiClusterAks, authToken, account);
OceanClusterAks createdOceanCluster = ClusterConverterAks.toBl(apiCreatedCluster);
retVal = new RepoGenericResponse<>(createdOceanCluster);
}
catch (SpotinstHttpException ex) {
retVal = ExceptionHelper.handleHttpException(ex);
}
return retVal;
}
@Override
public RepoGenericResponse delete(String identifier, String authToken, String account) {
RepoGenericResponse retVal;
try {
Boolean updated = SpotOceanAzureAksClusterService.deleteAksCluster(identifier, authToken, account);
retVal = new RepoGenericResponse<>(updated);
}
catch (SpotinstHttpException e) {
retVal = ExceptionHelper.handleHttpException(e);
}
return retVal;
}
@Override
public RepoGenericResponse update(String clusterId, OceanClusterAks clusterUpdate, String authToken,
String account) {
RepoGenericResponse retVal;
ApiClusterAks apiOceanCluster = ClusterConverterAks.toDal(clusterUpdate);
try {
Boolean success = SpotOceanAzureAksClusterService
.updateAksCluster(clusterId, apiOceanCluster, authToken, account);
retVal = new RepoGenericResponse<>(success);
}
catch (SpotinstHttpException e) {
retVal = ExceptionHelper.handleHttpException(e);
}
return retVal;
}
@Override
public RepoGenericResponse get(String clusterId, String authToken, String account) {
RepoGenericResponse retVal;
try {
ApiClusterAks apiOceanCluster = SpotOceanAzureAksClusterService.getAksCluster(clusterId, authToken, account);
OceanClusterAks aksCluster = ClusterConverterAks.toBl(apiOceanCluster);
retVal = new RepoGenericResponse<>(aksCluster);
}
catch (SpotinstHttpException e) {
retVal = ExceptionHelper.handleHttpException(e);
}
return retVal;
}
@Override
public RepoGenericResponse> getAll(Void filter, String authToken, String account) {
RepoGenericResponse> retVal;
try {
List apiClusters =
SpotOceanAzureAksClusterService.getAllClusters(authToken, account);
List clusters =
apiClusters.stream().map(ClusterConverterAks::toBl).collect(Collectors.toList());
retVal = new RepoGenericResponse<>(clusters);
}
catch (SpotinstHttpException e) {
retVal = ExceptionHelper.handleHttpException(e);
}
return retVal;
}
@Override
public RepoGenericResponse getAzureAksClusterHeartBeatStatus(String clusterIdId, String authToken, String account) {
RepoGenericResponse retVal;
try {
ApiGetAzureAksClusterHeartBeatStatusResponse getClusterHeartBeatResponse = SpotOceanAzureAksClusterService
.getAzureAksClusterHeartBeatStatus( clusterIdId, authToken, account);
GetAzureAksClusterHeartBeatStatusResponse getClusterHeartBeat = ClusterConverterAks.toBl(getClusterHeartBeatResponse);
retVal = new RepoGenericResponse<>(getClusterHeartBeat);
}
catch (SpotinstHttpException ex) {
retVal = ExceptionHelper.handleHttpException(ex);
}
return retVal;
}
@Override
public RepoGenericResponse> getClusterNodes(GetAksClusterNodesRequest getClusterNodes, String clusterId, String authToken) {
RepoGenericResponse> retVal;
try {
List apiGetClusterNodes = SpotOceanAzureAksClusterService
.getClusterNodes(getClusterNodes, clusterId, authToken);
List getClusterNodesResponse = apiGetClusterNodes.stream().map(ClusterConverterAks::toBl)
.collect(Collectors.toList());
retVal = new RepoGenericResponse<>(getClusterNodesResponse);
}
catch (SpotinstHttpException e) {
retVal = ExceptionHelper.handleHttpException(e);
}
return retVal;
}
@Override
public RepoGenericResponse> detachVms(AksDetachInstances instances, String clusterId, String authToken, String account) {
RepoGenericResponse> retVal;
try {
ApiAksDetachInstances apiDetachInstances = ClusterConverterAks.toDal(instances);
List apiDetachInstancesResponse = SpotOceanAzureAksClusterService
.detachVms(apiDetachInstances, clusterId, authToken, account);
List detachInstancesResponse = apiDetachInstancesResponse.stream().map(ClusterConverterAks::toBl)
.collect(Collectors.toList());
retVal = new RepoGenericResponse<>(detachInstancesResponse);
}
catch (SpotinstHttpException e) {
retVal = ExceptionHelper.handleHttpException(e);
}
return retVal;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy