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

com.spotinst.sdkjava.model.ElastigroupSuspendProcessesRequest Maven / Gradle / Ivy

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

import com.spotinst.sdkjava.enums.ProcessNameEnum;
import com.spotinst.sdkjava.exception.SpotinstValidationException;

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

/**
 * Created by yossi.elman on 24/05/2020.
 */

public class ElastigroupSuspendProcessesRequest {
    //region Members
    private String                  elastigroupId;
    private List suspensions;
    //endregion


    public String getElastigroupId() {
        return elastigroupId;
    }

    private void setElastigroupId(String elastigroupId) {
        this.elastigroupId = elastigroupId;
    }

    public List getSuspensions() {
        return suspensions;
    }

    private void setSuspensions(List suspensions) {
        this.suspensions = suspensions;
    }

    //region Builder
    public static class Builder {
        private ElastigroupSuspendProcessesRequest request;

        private Builder() {
            this.request = new ElastigroupSuspendProcessesRequest();
        }

        public static Builder get() {
            return new Builder();
        }

        public Builder setElastigroupId(final String elastigroupId) {
            request.setElastigroupId(elastigroupId);
            return this;
        }

        public Builder setSuspensions(final List suspensions) {
            request.setSuspensions(suspensions);
            return this;
        }

        public ElastigroupSuspendProcessesRequest build() {

            if (request.getElastigroupId() == null) {
                throw new SpotinstValidationException(
                        "Invalid Request - elastigroupId must be set");
            }

            List suspensions = request.getSuspensions();

            List withDuplicates =
                    suspensions.stream().map(ProcessSuspension::getName).collect(Collectors.toList());

            Set unique =
                    suspensions.stream().map(ProcessSuspension::getName).collect(Collectors.toSet());

            if (unique.size() != withDuplicates.size()) {
                throw new SpotinstValidationException(
                        "Invalid Request - suspensions cannot contain 2 elements with the same 'name'");
            }

            return request;
        }
    }
    //endregion
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy