All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.spotinst.sdkjava.model.SpotStorageAzureVolumeRepo Maven / Gradle / Ivy

There is a newer version: 1.0.121
Show newest version
package com.spotinst.sdkjava.model;

import com.spotinst.sdkjava.exception.ExceptionHelper;
import com.spotinst.sdkjava.exception.SpotinstHttpException;
import com.spotinst.sdkjava.model.api.spotStorage.ApiAzureStorageVolume;
import com.spotinst.sdkjava.model.bl.spotStorage.AzureStorageVolume;
import com.spotinst.sdkjava.model.bl.spotStorage.AzureStorageVolumeConverter;

import java.util.List;
import java.util.stream.Collectors;

// TODO yael: lets talk with Ziv about the naming convetion - we may have to change
//  ALL names to end with Azure.  -->  AzureStorageVolume --> StorageVolumeAzure
public class SpotStorageAzureVolumeRepo implements ISpotStorageAzureVolumeRepo {

    @Override
    public RepoGenericResponse create(AzureStorageVolume volumeToCreate, String authToken,
                                                          String account) {

        RepoGenericResponse retVal;

        try {

            ApiAzureStorageVolume         apiVolumeToCreate = AzureStorageVolumeConverter.toDal(volumeToCreate);
            SpotStorageAzureVolumeService volumeService     = new SpotStorageAzureVolumeService();
            ApiAzureStorageVolume apiCreatedVolume = SpotStorageAzureVolumeService.createVolume(apiVolumeToCreate, authToken, account);


            AzureStorageVolume createVolume = AzureStorageVolumeConverter.toBl(apiCreatedVolume);
            retVal = new RepoGenericResponse<>(createVolume);
        }
        catch (SpotinstHttpException ex) {
            retVal = ExceptionHelper.handleHttpException(ex);
        }

        return retVal;
    }


    @Override
    public RepoGenericResponse delete(String volumeId, String authToken, String accountId) {
        RepoGenericResponse retVal;

        try {
            Boolean updated = SpotStorageAzureVolumeService.deleteVolume(volumeId, authToken, accountId);
            retVal = new RepoGenericResponse<>(updated);

        }
        catch (SpotinstHttpException e) {
            retVal = ExceptionHelper.handleHttpException(e);
        }

        return retVal;
    }

    @Override
    public RepoGenericResponse update(String volumeId, AzureStorageVolume volumeUpdate, String authToken,
                                               String account) {
        RepoGenericResponse retVal;

        ApiAzureStorageVolume apiVolume = AzureStorageVolumeConverter.toDal(volumeUpdate);

        try {
            Boolean success = SpotStorageAzureVolumeService.updateVolume(volumeId, apiVolume, authToken, account);
            retVal = new RepoGenericResponse<>(success);
        }
        catch (SpotinstHttpException e) {
            retVal = ExceptionHelper.handleHttpException(e);
        }

        return retVal;
    }

    @Override
    public RepoGenericResponse get(String volumeId, String authToken, String account) {
        RepoGenericResponse retVal;

        try {
            ApiAzureStorageVolume apiVolume          = SpotStorageAzureVolumeService.getVolume(volumeId, authToken, account);
            AzureStorageVolume    volumeAzureStorage = AzureStorageVolumeConverter.toBl(apiVolume);
            retVal = new RepoGenericResponse<>(volumeAzureStorage);
        }
        catch (SpotinstHttpException e) {
            retVal = ExceptionHelper.handleHttpException(e);
        }

        return retVal;
    }

    @Override
    public RepoGenericResponse> getAll(Void filter, String authToken, String account) {
        RepoGenericResponse> retVal;

        try {
            List apiVolumes = SpotStorageAzureVolumeService.getAllVolumes(authToken, account);
            List volumes =
                    apiVolumes.stream().map(AzureStorageVolumeConverter::toBl).collect(Collectors.toList());
            retVal = new RepoGenericResponse<>(volumes);
        }
        catch (SpotinstHttpException e) {
            retVal = ExceptionHelper.handleHttpException(e);
        }

        return retVal;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy