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

com.spotinst.sdkjava.model.SpotinstElastigroupRepoGcp 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.gcp.ApiElastigroupGcp;
import com.spotinst.sdkjava.model.api.gcp.ApiElastigroupScaleDownResponseGcp;
import com.spotinst.sdkjava.model.api.gcp.ApiElastigroupScaleUpResponseGcp;
import com.spotinst.sdkjava.model.bl.elastigroup.gcp.ElastigroupGcp;
import com.spotinst.sdkjava.model.bl.elastigroup.gcp.ElastigroupScaleDownResponseGcp;
import com.spotinst.sdkjava.model.bl.elastigroup.gcp.ElastigroupScaleUpResponseGcp;
import com.spotinst.sdkjava.model.converters.elastigroup.gcp.ElastigroupConverterGcp;

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


class SpotinstElastigroupRepoGcp implements ISpotinstElastigroupRepoGcp {

    @Override
    public RepoGenericResponse create(ElastigroupGcp elastigroupToCreate, String authToken,
                                                      String account) {
        RepoGenericResponse retVal;

        try {
            ApiElastigroupGcp             apiElastigroupToCreate = ElastigroupConverterGcp.toDal(elastigroupToCreate);
            SpotinstElastigroupServiceGcp elastigroupServiceGcp = new SpotinstElastigroupServiceGcp();

            ApiElastigroupGcp             apiCreatedElastigroup  = elastigroupServiceGcp.createElastigroup(apiElastigroupToCreate, authToken, account);

            ElastigroupGcp createdElastigroup = ElastigroupConverterGcp.toBl(apiCreatedElastigroup);
            retVal = new RepoGenericResponse<>(createdElastigroup);
        }
        catch (SpotinstHttpException ex) {
            retVal = ExceptionHelper.handleHttpException(ex);
        }

        return retVal;
    }


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

        try {
            Boolean updated = SpotinstElastigroupServiceGcp.deleteElastigroup(elastigroupId, authToken, account);
            retVal = new RepoGenericResponse<>(updated);

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

        return retVal;
    }

    @Override
    public RepoGenericResponse update(String elastigroupId, ElastigroupGcp groupUpdate, String authToken,
                                               String account) {
        RepoGenericResponse retVal;

        try {
            ApiElastigroupGcp apiElastigroup = ElastigroupConverterGcp.toDal(groupUpdate);
            Boolean success =
                    SpotinstElastigroupServiceGcp.updateGroup(elastigroupId, apiElastigroup, authToken, account);
            retVal = new RepoGenericResponse<>(success);
        }
        catch (SpotinstHttpException e) {
            retVal = ExceptionHelper.handleHttpException(e);
        }

        return retVal;
    }

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

        try {
            List apiElastigroups =
                    SpotinstElastigroupServiceGcp.getAllGroups(authToken, account);
            List elastigroups =
                    apiElastigroups.stream().map(ElastigroupConverterGcp::toBl).collect(Collectors.toList());
            retVal = new RepoGenericResponse<>(elastigroups);
        }
        catch (SpotinstHttpException e) {
            retVal = ExceptionHelper.handleHttpException(e);
        }

        return retVal;
    }


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

        try {
            ApiElastigroupGcp apiElastigroup =
                    SpotinstElastigroupServiceGcp.getGroup(elastigroupId, authToken, account);
            ElastigroupGcp elastigroup = ElastigroupConverterGcp.toBl(apiElastigroup);
            retVal = new RepoGenericResponse<>(elastigroup);
        }
        catch (SpotinstHttpException e) {
            retVal = ExceptionHelper.handleHttpException(e);
        }

        return retVal;
    }


    @Override
    public RepoGenericResponse lockInstance(String authToken, String accountId, String ttlInMinutes, String instanceId) {
        RepoGenericResponse retVal;

        try {
            Boolean success = SpotinstElastigroupServiceGcp.lockInstance(authToken, accountId, ttlInMinutes, instanceId);
            retVal = new RepoGenericResponse<>(success);
        }
        catch (SpotinstHttpException ex) {
            retVal = ExceptionHelper.handleHttpException(ex);
        }

        return retVal;
    }

    @Override
    public RepoGenericResponse unlockInstance(String authToken, String accountId, String instanceId) {
        RepoGenericResponse retVal;

        try {
            Boolean success = SpotinstElastigroupServiceGcp.unlockInstance(authToken, accountId, instanceId);
            retVal = new RepoGenericResponse<>(success);
        }
        catch (SpotinstHttpException ex) {
            retVal = ExceptionHelper.handleHttpException(ex);
        }

        return retVal;
    }

    @Override
    public RepoGenericResponse> scaleUp(String elastigroupId, String adjustment, String authToken, String account) {
        RepoGenericResponse> scaleUp;

        try {
            List apiElastigroupScalingResponse =
                    SpotinstElastigroupServiceGcp.scaleUpGroup(elastigroupId, adjustment, authToken, account);

            List elastigroupScalingResponse =
                    apiElastigroupScalingResponse.stream().map(ElastigroupConverterGcp::toBl).collect(Collectors.toList());
            scaleUp = new RepoGenericResponse<>(elastigroupScalingResponse);


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

        return scaleUp;
    }

    @Override
    public RepoGenericResponse > scaleDown(String elastigroupId, String adjustment, String authToken, String account) {
        RepoGenericResponse> scaleDown;

        try {
            List apiElastigroupScalingResponse =
                    SpotinstElastigroupServiceGcp.scaleDownGroup(elastigroupId, adjustment, authToken, account);

            List elastigroupScalingResponse =
                    apiElastigroupScalingResponse.stream().map(ElastigroupConverterGcp::toBl).collect(Collectors.toList());
            scaleDown = new RepoGenericResponse<>(elastigroupScalingResponse);
        } catch (SpotinstHttpException e) {
            scaleDown = ExceptionHelper.handleHttpException(e);
        }

        return scaleDown;
    }


}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy