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

com.spotinst.sdkjava.model.repo.ocean.ecs.SpotOceanEcsLaunchSpecRepo Maven / Gradle / Ivy

There is a newer version: 1.0.121
Show newest version
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.ISpotOceanEcsLaunchSpecRepo;
import com.spotinst.sdkjava.model.RepoGenericResponse;
import com.spotinst.sdkjava.model.api.ocean.ecs.ApiClusterLaunchSpecification;
import com.spotinst.sdkjava.model.bl.ocean.ecs.ClusterLaunchSpecification;
import com.spotinst.sdkjava.model.converters.ocean.ecs.OceanEcsConverter;
import com.spotinst.sdkjava.model.service.ocean.ecs.SpotOceanEcsClusterService;

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

public class SpotOceanEcsLaunchSpecRepo implements ISpotOceanEcsLaunchSpecRepo {

    @Override
    public RepoGenericResponse create(ClusterLaunchSpecification launchSpecToCreate,
                                                                  String authToken, String account) {

        RepoGenericResponse retVal;

        try {
            ApiClusterLaunchSpecification apiLaunchSpecToCreate = OceanEcsConverter.toDal(launchSpecToCreate);
            ApiClusterLaunchSpecification apiCreatedLaunchSpec =
                    SpotOceanEcsClusterService.createLaunchSpec(apiLaunchSpecToCreate, authToken, account);
            ClusterLaunchSpecification createdLaunchSpec = OceanEcsConverter.toBl(apiCreatedLaunchSpec);
            retVal = new RepoGenericResponse<>(createdLaunchSpec);
        }
        catch (SpotinstHttpException ex) {
            retVal = ExceptionHelper.handleHttpException(ex);
        }

        return retVal;
    }

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

        try {
            Boolean isLaunchSpecDeleted =
                    SpotOceanEcsClusterService.deleteLaunchSpec(identifier, authToken, account);
            retVal = new RepoGenericResponse<>(isLaunchSpecDeleted);
        }
        catch (SpotinstHttpException ex) {
            retVal = ExceptionHelper.handleHttpException(ex);
        }

        return retVal;
    }

    @Override
    public RepoGenericResponse update(String identifier, ClusterLaunchSpecification launchSpecToUpdate,
                                               String authToken, String account) {
        RepoGenericResponse retVal;

        try {
            ApiClusterLaunchSpecification apiLaunchSpecToUpdate = OceanEcsConverter.toDal(launchSpecToUpdate);
            Boolean isLaunchSpecUpdated = SpotOceanEcsClusterService
                    .updateLaunchSpec(identifier, apiLaunchSpecToUpdate, authToken, account);
            retVal = new RepoGenericResponse<>(isLaunchSpecUpdated);
        }
        catch (SpotinstHttpException ex) {
            retVal = ExceptionHelper.handleHttpException(ex);
        }

        return retVal;
    }

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

        try {
            ApiClusterLaunchSpecification apiGetLaunchSpec =
                    SpotOceanEcsClusterService.getLaunchSpec(identifier, authToken, account);
            ClusterLaunchSpecification getLaunchSpec = OceanEcsConverter.toBl(apiGetLaunchSpec);
            retVal = new RepoGenericResponse<>(getLaunchSpec);
        }
        catch (SpotinstHttpException ex) {
            retVal = ExceptionHelper.handleHttpException(ex);
        }

        return retVal;
    }

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

        try {
            List apigetAllLaunchSpec =
                    SpotOceanEcsClusterService.getAllLaunchSpec(authToken, account);
            List allLaunchSpec =
                    apigetAllLaunchSpec.stream().map(OceanEcsConverter::toBl).collect(Collectors.toList());
            retVal = new RepoGenericResponse<>(allLaunchSpec);
        }
        catch (SpotinstHttpException ex) {
            retVal = ExceptionHelper.handleHttpException(ex);
        }

        return retVal;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy