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

com.spotinst.sdkjava.model.repo.elastigroup.azure.v3.SpotinstElastigroupRepoAzure Maven / Gradle / Ivy

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

import com.spotinst.sdkjava.enums.ElastigroupSeverityEnumAzure;
import com.spotinst.sdkjava.exception.ExceptionHelper;
import com.spotinst.sdkjava.exception.SpotinstHttpException;
import com.spotinst.sdkjava.model.GroupFilter;
import com.spotinst.sdkjava.model.ISpotinstElastigroupRepoAzure;
import com.spotinst.sdkjava.model.RepoGenericResponse;
import com.spotinst.sdkjava.model.api.azure.elastiGroup.V3.*;
import com.spotinst.sdkjava.model.bl.azure.elastiGroup.V3.*;
import com.spotinst.sdkjava.model.requests.elastigroup.azure.*;
import com.spotinst.sdkjava.model.service.elastigroup.azure.v3.SpotinstElastigroupServiceAzure;

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


public class SpotinstElastigroupRepoAzure implements ISpotinstElastigroupRepoAzure {

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

        try {
            ApiElastigroupAzure apiElastigroupToCreate = ElastigroupConverterAzure.toDal(elastigroupToCreate);
            SpotinstElastigroupServiceAzure A = new SpotinstElastigroupServiceAzure();
            ApiElastigroupAzure apiCreatedElastigroup =
                    A.createElastigroup(apiElastigroupToCreate, authToken, account);

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

        return retVal;
    }

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

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

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

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

        ApiElastigroupAzure apiElastigroup = ElastigroupConverterAzure.toDal(groupUpdate);

        try {
            Boolean success = SpotinstElastigroupServiceAzure.updateGroup(elastigroupId, apiElastigroup, authToken, account);
            retVal = new RepoGenericResponse<>(success);
        }
        catch (SpotinstHttpException e) {
            retVal = ExceptionHelper.handleHttpException(e);
        }
        return retVal;
    }

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

        try {
            List apiElastigroups = SpotinstElastigroupServiceAzure.getAllGroups(filter, authToken, account);
            List elastigroups =
                    apiElastigroups.stream().map(ElastigroupConverterAzure::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 {
            ApiElastigroupAzure apiElastigroup = SpotinstElastigroupServiceAzure.getGroup(elastigroupId, authToken, account);
            ElastigroupAzure    elastigroup    = ElastigroupConverterAzure.toBl(apiElastigroup);
            retVal = new RepoGenericResponse<>(elastigroup);
        }
        catch (SpotinstHttpException e) {
            retVal = ExceptionHelper.handleHttpException(e);
        }

        return retVal;
    }

    @Override
    public RepoGenericResponse getStatus(String groupId, String authToken, String account) {
        RepoGenericResponse status;

        try {
            ApiGetElastigroupStatusResponseAzure apiGetElastigroupeStatus =
                    SpotinstElastigroupServiceAzure.getGroupStatus(groupId, authToken, account);
            GetElastigroupStatusResponseAzure getGroupStatus = ElastigroupConverterAzure.toBl(apiGetElastigroupeStatus);
            status = new RepoGenericResponse<>(getGroupStatus);
        }

        catch (SpotinstHttpException ex) {
            status = ExceptionHelper.handleHttpException(ex);
        }

        return status;
    }

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

        try {
            List apiElastigroupScalingResponse =
                    SpotinstElastigroupServiceAzure.scaleGroupUp(groupId, adjustment, authToken, account);

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

        return scaleUp;
    }

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

        try {
            List apiElastigroupScalingResponse =
                    SpotinstElastigroupServiceAzure.scaleGroupDown(groupId, adjustment, authToken, account);

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

        return scaleDown;
    }

    @Override
    public RepoGenericResponse importGroupFromScaleSet(String resourceGroupName, String scaleSetName,
                                                                         String authToken, String account) {
        RepoGenericResponse retVal;

        try {
            ApiElastigroupAzure apiElastigroup = SpotinstElastigroupServiceAzure.importGroupFromScaleSet(resourceGroupName,
                                                    scaleSetName, authToken, account);
            ElastigroupAzure    elastigroup    = ElastigroupConverterAzure.toBl(apiElastigroup);
            retVal = new RepoGenericResponse<>(elastigroup);
        }
        catch (SpotinstHttpException e) {
            retVal = ExceptionHelper.handleHttpException(e);
        }

        return retVal;
    }

    @Override
    public RepoGenericResponse importGroupFromVirtualMachine(String resourceGroupName, String virtualMachineName,
                                                                         String authToken, String account) {
        RepoGenericResponse retVal;

        try {
            ApiElastigroupAzure apiElastigroup = SpotinstElastigroupServiceAzure.importGroupFromVirtualMachine(resourceGroupName,
                    virtualMachineName, authToken, account);
            ElastigroupAzure    elastigroup    = ElastigroupConverterAzure.toBl(apiElastigroup);
            retVal = new RepoGenericResponse<>(elastigroup);
        }
        catch (SpotinstHttpException e) {
            retVal = ExceptionHelper.handleHttpException(e);
        }

        return retVal;
    }

    @Override
    public RepoGenericResponse createVmSignal(CreateVmSignalRequestAzure elastigroupVmSignal, String authToken, String account) {
        RepoGenericResponse vmSignal;

        try {
            Boolean created = SpotinstElastigroupServiceAzure.createVmSignal(elastigroupVmSignal, authToken, account);
            vmSignal = new RepoGenericResponse<>(created);

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

        return vmSignal;
    }

    @Override
    public RepoGenericResponse updateCapacity(UpdateCapacityRequestAzure updateCapacity, String authToken, String account) {
        RepoGenericResponse isCapacityUpdated;

        try {
            ApiUpdateCapacityAzure apiUpdated = SpotinstElastigroupServiceAzure.updateCapacity(updateCapacity, authToken, account);
            UpdateCapacityAzure updateCapacityResponse =
                    ElastigroupConverterAzure.toBl(apiUpdated);
            isCapacityUpdated = new RepoGenericResponse<>(updateCapacityResponse);

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

        return isCapacityUpdated;
    }

    @Override
    public RepoGenericResponse> vmHealthiness(String groupId, String authToken, String account) {
        RepoGenericResponse> getVmHealthiness;

        try {
            List apiVmHealthiness = SpotinstElastigroupServiceAzure.vmHealthiness(groupId, authToken, account);
            List vmHealthinessResponse =
            apiVmHealthiness.stream().map(ElastigroupConverterAzure::toBl).collect(Collectors.toList());
            getVmHealthiness = new RepoGenericResponse<> (vmHealthinessResponse);

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

        return getVmHealthiness;
    }

    @Override
    public RepoGenericResponse suspendGroup(SuspendgroupRequestAzure requestAzure, String authToken, String account) {
        RepoGenericResponse suspendGroup;

        try {
            Boolean apiSuspendgroup = SpotinstElastigroupServiceAzure.suspendGroup(requestAzure, authToken, account);
            suspendGroup = new RepoGenericResponse<>(apiSuspendgroup);

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

        return suspendGroup;
    }

    @Override
    public RepoGenericResponse resumeGroup(ResumegroupRequestAzure groupId, String authToken, String account) {
        RepoGenericResponse resumeGroup;

        try {
            Boolean apiResumegroup = SpotinstElastigroupServiceAzure.resumeGroup(groupId, authToken, account);
            resumeGroup = new RepoGenericResponse<>(apiResumegroup);

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

        return resumeGroup;
    }

    @Override
    public RepoGenericResponse vmProtection(String groupId, String vmName, String authToken, String account,
                                                     Integer ttlInMinutes) {
        RepoGenericResponse vmProtect;

        try {
            Boolean apiVmProtect= SpotinstElastigroupServiceAzure.vmProtection(groupId, vmName, authToken, account, ttlInMinutes);
            vmProtect = new RepoGenericResponse<>(apiVmProtect);

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

        return vmProtect;
    }

    @Override
    public RepoGenericResponse vmRemoveProtection(String groupId, String vmName,
                                                     String authToken, String account) {
        RepoGenericResponse vmRemoveProtect;

        try {
            Boolean apiVmRemoveProtect= SpotinstElastigroupServiceAzure.vmRemoveProtection(groupId, vmName, authToken, account);
            vmRemoveProtect = new RepoGenericResponse<>(apiVmRemoveProtect);

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

        return vmRemoveProtect;
    }

    @Override
    public RepoGenericResponse detachVms(DetachVmsRequestAzure groupId, String authToken, String account) {
        RepoGenericResponse detachVms;

        try {
            ApiDetachVmsResponseAzure apiDetachedVms = SpotinstElastigroupServiceAzure.detachVms(groupId, authToken, account);
            DetachVmsResponseAzure detachedVms =
                    ElastigroupConverterAzure.toBl(apiDetachedVms);
            detachVms = new RepoGenericResponse<>(detachedVms);

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

        return detachVms;
    }

    @Override
    public RepoGenericResponse getElastilog(String elastigroupId, String authToken, String account,
                                                                       String fromDate, Integer limit, String resoucre_Id,
                                                                       ElastigroupSeverityEnumAzure severity, String toDate) {
        RepoGenericResponse retVal;

        try {
            ApiGetElastilogResponseAzure apiElastilog = SpotinstElastigroupServiceAzure.getElastilog(elastigroupId, authToken,
                    account, fromDate, limit, resoucre_Id, severity, toDate);
            GetElastilogResponseAzure elastilogAzure    = ElastigroupConverterAzure.toBl(apiElastilog);
            retVal = new RepoGenericResponse<>(elastilogAzure);
        }
        catch (SpotinstHttpException e) {
            retVal = ExceptionHelper.handleHttpException(e);
        }

        return retVal;
    }

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

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

        return retVal;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy