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

com.spotinst.sdkjava.model.repo.ocean.gke.SpotOceanGkeLaunchSpecRepo Maven / Gradle / Ivy

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

import com.spotinst.sdkjava.exception.ExceptionHelper;
import com.spotinst.sdkjava.exception.SpotinstHttpException;
import com.spotinst.sdkjava.model.ISpotOceanGKELaunchSpecRepo;
import com.spotinst.sdkjava.model.RepoGenericResponse;
import com.spotinst.sdkjava.model.api.ocean.gke.ApiLaunchSpecSpecification;
import com.spotinst.sdkjava.model.bl.ocean.gke.LaunchSpecSpecification;
import com.spotinst.sdkjava.model.converters.ocean.gke.OceanGkeConverter;
import com.spotinst.sdkjava.model.service.ocean.gke.SpotOceanGkeClusterService;

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

public class SpotOceanGkeLaunchSpecRepo implements ISpotOceanGKELaunchSpecRepo {

    @Override
    public RepoGenericResponse create(LaunchSpecSpecification oceanGKECreateLaunchSpecRes, String authToken, String account) {
        RepoGenericResponse retVal;

        try {
            ApiLaunchSpecSpecification
                    apiLaunchSpecSpecification = OceanGkeConverter.toDal(oceanGKECreateLaunchSpecRes);
            ApiLaunchSpecSpecification apiCreateLaunchSpec =
                    SpotOceanGkeClusterService.createLaunchSpec(apiLaunchSpecSpecification, authToken, account);
            LaunchSpecSpecification CreatedLaunchSpec = OceanGkeConverter.toBl(
                    apiCreateLaunchSpec);
            retVal = new RepoGenericResponse<>(CreatedLaunchSpec);
        }
        catch (SpotinstHttpException ex) {
            retVal = ExceptionHelper.handleHttpException(ex);
        }

        return retVal;
    }

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

        try {
            ApiLaunchSpecSpecification apiLaunchSpecSpecification =
                    SpotOceanGkeClusterService.getLaunchSpec(authToken, account, launchSpecId);

            LaunchSpecSpecification launchSpecs =OceanGkeConverter.toBl(apiLaunchSpecSpecification);
            retVal = new RepoGenericResponse<>(launchSpecs);
        }
        catch (SpotinstHttpException e) {
            retVal = ExceptionHelper.handleHttpException(e);
        }

        return retVal;
    }

    @Override
    public RepoGenericResponse> getAllStatus(String authToken, String account,String oceanId) {
        RepoGenericResponse> retVal;

        try {
            List apiLaunchSpecSpecification =
                    SpotOceanGkeClusterService.getAllLaunchSpec(authToken, account, oceanId);
            List launchSpecs = apiLaunchSpecSpecification.stream().map(OceanGkeConverter::toBl).collect(Collectors.toList());
            retVal = new RepoGenericResponse<>(launchSpecs);
        }
        catch (SpotinstHttpException e) {
            retVal = ExceptionHelper.handleHttpException(e);
        }

        return retVal;
    }

    @Override
    public RepoGenericResponse update(String launchSpecId, LaunchSpecSpecification launchSpecToUpdate, String authToken,
                                               String account) {
        RepoGenericResponse retVal;

        try {
            ApiLaunchSpecSpecification
                    apiLaunchSpecSpecification = OceanGkeConverter.toDal(launchSpecToUpdate);
            Boolean success =
                    SpotOceanGkeClusterService
                            .updateLaunchSpec(apiLaunchSpecSpecification, launchSpecId, authToken, account);
            retVal = new RepoGenericResponse<>(success);
        }
        catch (SpotinstHttpException e) {
            retVal = ExceptionHelper.handleHttpException(e);
        }

        return retVal;
    }

    @Override
    public RepoGenericResponse delete(String launchSpecId, String authToken, String account) {
        RepoGenericResponse retVal;

        try {
            Boolean updated = SpotOceanGkeClusterService.deleteLaunchSpec(launchSpecId, authToken, account);
            retVal = new RepoGenericResponse<>(updated);

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

        return retVal;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy