001package org.kuali.common.devops.ubuntu;
002
003import static com.google.common.base.Optional.absent;
004
005import java.util.List;
006
007import org.kuali.common.aws.ec2.model.ImmutableTag;
008import org.kuali.common.core.build.ValidatingBuilder;
009import org.kuali.common.core.validate.annotation.IdiotProofImmutable;
010
011import com.amazonaws.services.ec2.model.Tag;
012import com.google.common.base.Optional;
013import com.google.common.collect.ImmutableList;
014
015@IdiotProofImmutable
016public final class MountVolumeRequest {
017
018        /**
019         * The tags are used to locate the volume to attach. The volume must already exist, must exactly match all of the tags, and there must only be one volume that matches.
020         */
021        private final ImmutableList<Tag> volumeTags;
022
023        /**
024         * The instance to attach the volume to
025         */
026        private final String instanceId;
027
028        /**
029         * The name of the device to attach the volume as
030         */
031        private final String device;
032
033        /**
034         * The path to mount the volume on
035         */
036        private final String path;
037
038        /**
039         * For example, {@code tomcat7:tomcat7}. This value is passed directly to the Unix {@code chown} command
040         */
041        private final Optional<String> ownership;
042
043        private MountVolumeRequest(Builder builder) {
044                this.volumeTags = ImmutableList.copyOf(ImmutableTag.copyOf(builder.volumeTags));
045                this.instanceId = builder.instanceId;
046                this.device = builder.device;
047                this.path = builder.path;
048                this.ownership = builder.ownership;
049        }
050
051        public static Builder builder() {
052                return new Builder();
053        }
054
055        public static class Builder extends ValidatingBuilder<MountVolumeRequest> {
056
057                private List<Tag> volumeTags;
058                private String instanceId;
059                private String device;
060                private String path;
061                private Optional<String> ownership = absent();
062
063                public Builder withVolumeTags(List<Tag> volumeTags) {
064                        this.volumeTags = volumeTags;
065                        return this;
066                }
067
068                public Builder withOwnership(Optional<String> ownership) {
069                        this.ownership = ownership;
070                        return this;
071                }
072
073                public Builder withOwnership(String ownership) {
074                        return withOwnership(Optional.of(ownership));
075                }
076
077                public Builder withInstanceId(String instanceId) {
078                        this.instanceId = instanceId;
079                        return this;
080                }
081
082                public Builder withPath(String path) {
083                        this.path = path;
084                        return this;
085                }
086
087                public Builder withDevice(String device) {
088                        this.device = device;
089                        return this;
090                }
091
092                @Override
093                public MountVolumeRequest build() {
094                        return validate(new MountVolumeRequest(this));
095                }
096        }
097
098        public List<Tag> getVolumeTags() {
099                return volumeTags;
100        }
101
102        public String getInstanceId() {
103                return instanceId;
104        }
105
106        public String getDevice() {
107                return device;
108        }
109
110        public String getPath() {
111                return path;
112        }
113
114        public Optional<String> getOwnership() {
115                return ownership;
116        }
117
118}