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

com.spotinst.sdkjava.model.SpotinstElastigroupDeploymentRepoAzure 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.azure.elastiGroup.V3.Deployment.ApiCreateDeploymentAzure;
import com.spotinst.sdkjava.model.api.azure.elastiGroup.V3.Deployment.ApiGetDeploymentAzure;
import com.spotinst.sdkjava.model.api.azure.elastiGroup.V3.Deployment.ApiGroupDeploymentDetailsAzure;
import com.spotinst.sdkjava.model.api.azure.elastiGroup.V3.Deployment.ApiGroupDeploymentRequestAzure;
import com.spotinst.sdkjava.model.bl.azure.elastiGroup.V3.Deployment.DeploymentDetails.GroupDeploymentDetailsAzure;
import com.spotinst.sdkjava.model.bl.azure.elastiGroup.V3.Deployment.GroupDeploymentCreateAzure;
import com.spotinst.sdkjava.model.bl.azure.elastiGroup.V3.Deployment.GroupDeploymentGetAzure;
import com.spotinst.sdkjava.model.converters.ElastigroupDeploymentConverterAzure;
import com.spotinst.sdkjava.model.converters.ElastigroupDeploymentDetailsConverterAzure;
import com.spotinst.sdkjava.model.filters.SortQueryParam;
import com.spotinst.sdkjava.model.service.elastigroup.azure.v3.SpotinstElastigroupServiceAzure;

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

public class SpotinstElastigroupDeploymentRepoAzure implements ISpotinstElastigroupDeploymentRepoAzure {

    public RepoGenericResponse create(
            GroupDeploymentCreationRequestAzure deploymentCreationRequestAzure, String authToken, String account,
            String groupId) {
        RepoGenericResponse retVal;
        SpotinstElastigroupServiceAzure serviceAzure = new SpotinstElastigroupServiceAzure();

        try {
            ApiGroupDeploymentRequestAzure apiDeploymentCreationRequest =
                    ElastigroupDeploymentConverterAzure.toDal(deploymentCreationRequestAzure);

            ApiCreateDeploymentAzure apiCreatedDeployment =
                    serviceAzure.createDeployment(apiDeploymentCreationRequest, authToken, account, groupId);
            GroupDeploymentCreateAzure
                    createdDeployment = ElastigroupDeploymentConverterAzure.toBlCreate(apiCreatedDeployment);
            retVal = new RepoGenericResponse<>(createdDeployment);
        }
        catch (SpotinstHttpException ex) {
            retVal = ExceptionHelper.handleHttpException(ex);
        }

        return retVal;
    }

    public RepoGenericResponse> getAll(String groupId, String authToken, String account,
                                                                     Integer limit, SortQueryParam sortQueryParam) {
        RepoGenericResponse> retVal;
        SpotinstElastigroupServiceAzure                       serviceAzure = new SpotinstElastigroupServiceAzure();

        try {
            List apiDeployments =
                    serviceAzure.getAllDeployments(groupId, authToken, account, limit, sortQueryParam);

            List deployments =
                    apiDeployments.stream().map(ElastigroupDeploymentConverterAzure::toBlGet).collect(Collectors.toList());

            retVal = new RepoGenericResponse<>(deployments);
        }
        catch (SpotinstHttpException ex) {
            retVal = ExceptionHelper.handleHttpException(ex);
        }

        return retVal;
    }

    public RepoGenericResponse get(String deploymentId, String authToken, String account,
                                                               String groupId) {
        RepoGenericResponse retVal;
        SpotinstElastigroupServiceAzure                 serviceAzure = new SpotinstElastigroupServiceAzure();

        try {
            ApiGetDeploymentAzure apiDeployment =
                    serviceAzure.getDeployment(deploymentId, authToken, account, groupId);

            GroupDeploymentGetAzure deployment = ElastigroupDeploymentConverterAzure.toBlGet(apiDeployment);

            retVal = new RepoGenericResponse<>(deployment);
        }
        catch (SpotinstHttpException ex) {
            retVal = ExceptionHelper.handleHttpException(ex);
        }

        return retVal;
    }

    public RepoGenericResponse getDetails(String deploymentId, String authToken, String account,
                                                                String groupId) {
        RepoGenericResponse retVal;
        SpotinstElastigroupServiceAzure           serviceAzure = new SpotinstElastigroupServiceAzure();

        try {
            ApiGroupDeploymentDetailsAzure apiDeployment = serviceAzure.getDeploymentDetails(deploymentId, authToken, account, groupId);

            GroupDeploymentDetailsAzure deployment = ElastigroupDeploymentDetailsConverterAzure.toBl(apiDeployment);

            retVal = new RepoGenericResponse<>(deployment);
        }
        catch (SpotinstHttpException ex) {
            retVal = ExceptionHelper.handleHttpException(ex);
        }

        return retVal;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy