com.spotinst.sdkjava.model.repo.ocean.ecs.SpotOceanEcsClusterRepo Maven / Gradle / Ivy
package com.spotinst.sdkjava.model.repo.ocean.ecs;
import com.spotinst.sdkjava.exception.ExceptionHelper;
import com.spotinst.sdkjava.exception.SpotinstHttpException;
import com.spotinst.sdkjava.model.bl.ocean.ecs.OceanEcsCluster;
import com.spotinst.sdkjava.model.ISpotOceanEcsClusterRepo;
import com.spotinst.sdkjava.model.api.ocean.ecs.*;
import com.spotinst.sdkjava.model.RepoGenericResponse;
import com.spotinst.sdkjava.model.service.ocean.ecs.SpotOceanEcsClusterService;
import com.spotinst.sdkjava.model.converters.ocean.ecs.OceanEcsConverter;
import java.util.List;
import java.util.stream.Collectors;
public class SpotOceanEcsClusterRepo implements ISpotOceanEcsClusterRepo {
@Override
public RepoGenericResponse create(OceanEcsCluster clusterToCreate, String authToken, String account) {
RepoGenericResponse retVal;
try {
ApiOceanEcsCluster apiOceanEcsClusterToCreate = OceanEcsConverter.toDal(clusterToCreate);
ApiOceanEcsCluster apiCreatedCluster = SpotOceanEcsClusterService.createEcsCluster(apiOceanEcsClusterToCreate, authToken, account);
OceanEcsCluster createdOceanEcsCluster = OceanEcsConverter.toBl(apiCreatedCluster);
retVal = new RepoGenericResponse<>(createdOceanEcsCluster);
}
catch (SpotinstHttpException ex) {
retVal = ExceptionHelper.handleHttpException(ex);
}
return retVal;
}
@Override
public RepoGenericResponse update(String clusterId, OceanEcsCluster clusterUpdate, String authToken,
String account) {
RepoGenericResponse retVal;
ApiOceanEcsCluster apiOceanEcsCluster = OceanEcsConverter.toDal(clusterUpdate);
try {
Boolean isSucceeded = SpotOceanEcsClusterService
.updateEcsCluster(clusterId, apiOceanEcsCluster, authToken, account);
retVal = new RepoGenericResponse<>(isSucceeded );
}
catch (SpotinstHttpException e) {
retVal = ExceptionHelper.handleHttpException(e);
}
return retVal;
}
@Override
public RepoGenericResponse get(String clusterId, String authToken, String account) {
RepoGenericResponse retVal;
try {
ApiOceanEcsCluster
apiOceanEcsCluster = SpotOceanEcsClusterService.getEcsCluster(clusterId, authToken, account);
OceanEcsCluster oceanK8sCluster = OceanEcsConverter.toBl(apiOceanEcsCluster);
retVal = new RepoGenericResponse<>(oceanK8sCluster);
}
catch (SpotinstHttpException e) {
retVal = ExceptionHelper.handleHttpException(e);
}
return retVal;
}
@Override
public RepoGenericResponse delete(String identifier, String authToken, String account) {
RepoGenericResponse retVal;
try {
Boolean isDeleted = SpotOceanEcsClusterService.deleteEcsCluster(identifier, authToken, account);
retVal = new RepoGenericResponse<>(isDeleted );
}
catch (SpotinstHttpException e) {
retVal = ExceptionHelper.handleHttpException(e);
}
return retVal;
}
@Override
public RepoGenericResponse> getAll(Void filter, String authToken, String account) {
RepoGenericResponse> retVal;
try {
List apigetAllLaunchSpec =
SpotOceanEcsClusterService.getAllEcsCluster(authToken, account);
List allEcsCluster =
apigetAllLaunchSpec.stream().map(OceanEcsConverter::toBl).collect(Collectors.toList());
retVal = new RepoGenericResponse<>(allEcsCluster);
}
catch (SpotinstHttpException ex) {
retVal = ExceptionHelper.handleHttpException(ex);
}
return retVal;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy