001/**
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *   http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied.  See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 */
019package org.apache.reef.runtime.common.client.api;
020
021import org.apache.reef.runtime.common.files.FileResource;
022import org.apache.reef.tang.Configuration;
023import org.apache.reef.util.BuilderUtils;
024import org.apache.reef.util.Optional;
025
026import java.util.HashSet;
027import java.util.Set;
028
029/**
030 * Default POJO implementation of JobSubmissionEvent.
031 * Use newBuilder to construct an instance.
032 */
033public final class JobSubmissionEventImpl implements JobSubmissionEvent {
034  private final String identifier;
035  private final String remoteId;
036  private final Configuration configuration;
037  private final String userName;
038  private final Set<FileResource> globalFileSet;
039  private final Set<FileResource> localFileSet;
040  private final Optional<Integer> driverMemory;
041  private final Optional<Integer> priority;
042  private final Optional<String> queue;
043
044  private JobSubmissionEventImpl(final Builder builder) {
045    this.identifier = BuilderUtils.notNull(builder.identifier);
046    this.remoteId = BuilderUtils.notNull(builder.remoteId);
047    this.configuration = BuilderUtils.notNull(builder.configuration);
048    this.userName = BuilderUtils.notNull(builder.userName);
049    this.globalFileSet = BuilderUtils.notNull(builder.globalFileSet);
050    this.localFileSet = BuilderUtils.notNull(builder.localFileSet);
051    this.driverMemory = Optional.ofNullable(builder.driverMemory);
052    this.priority = Optional.ofNullable(builder.priority);
053    this.queue = Optional.ofNullable(builder.queue);
054  }
055
056  @Override
057  public String getIdentifier() {
058    return identifier;
059  }
060
061  @Override
062  public String getRemoteId() {
063    return remoteId;
064  }
065
066  @Override
067  public Configuration getConfiguration() {
068    return configuration;
069  }
070
071  @Override
072  public String getUserName() {
073    return userName;
074  }
075
076  @Override
077  public Set<FileResource> getGlobalFileSet() {
078    return globalFileSet;
079  }
080
081  @Override
082  public Set<FileResource> getLocalFileSet() {
083    return localFileSet;
084  }
085
086  @Override
087  public Optional<Integer> getDriverMemory() {
088    return driverMemory;
089  }
090
091  @Override
092  public Optional<Integer> getPriority() {
093    return priority;
094  }
095
096  @Override
097  public Optional<String> getQueue() {
098    return queue;
099  }
100
101  public static Builder newBuilder() {
102    return new Builder();
103  }
104
105  /**
106   * Builder used to create JobSubmissionEvent instances.
107   */
108  public static final class Builder implements org.apache.reef.util.Builder<JobSubmissionEvent> {
109    private String identifier;
110    private String remoteId;
111    private Configuration configuration;
112    private String userName;
113    private Set<FileResource> globalFileSet = new HashSet<>();
114    private Set<FileResource> localFileSet = new HashSet<>();
115    private Integer driverMemory;
116    private Integer priority;
117    private String queue;
118
119    /**
120     * @see JobSubmissionEvent#getIdentifier()
121     */
122    public Builder setIdentifier(final String identifier) {
123      this.identifier = identifier;
124      return this;
125    }
126
127    /**
128     * @see JobSubmissionEvent#getRemoteId()
129     */
130    public Builder setRemoteId(final String remoteId) {
131      this.remoteId = remoteId;
132      return this;
133    }
134
135    /**
136     * @see JobSubmissionEvent#getConfiguration()
137     */
138    public Builder setConfiguration(final Configuration configuration) {
139      this.configuration = configuration;
140      return this;
141    }
142
143    /**
144     * @see JobSubmissionEvent#getUserName()
145     */
146    public Builder setUserName(final String userName) {
147      this.userName = userName;
148      return this;
149    }
150
151    /**
152     * Add an entry to the globalFileSet
153     * @see JobSubmissionEvent#getGlobalFileSet()
154     */
155    public Builder addGlobalFile(final FileResource globalFile) {
156      this.globalFileSet.add(globalFile);
157      return this;
158    }
159
160    /**
161     * Add an entry to the localFileSet
162     * @see JobSubmissionEvent#getLocalFileSet()
163     */
164    public Builder addLocalFile(final FileResource localFile) {
165      this.localFileSet.add(localFile);
166      return this;
167    }
168
169    /**
170     * @see JobSubmissionEvent#getDriverMemory()
171     */
172    public Builder setDriverMemory(final Integer driverMemory) {
173      this.driverMemory = driverMemory;
174      return this;
175    }
176
177    /**
178     * @see JobSubmissionEvent#getPriority()
179     */
180    public Builder setPriority(final Integer priority) {
181      this.priority = priority;
182      return this;
183    }
184
185    /**
186     * @see JobSubmissionEvent#getQueue()
187     */
188    public Builder setQueue(final String queue) {
189      this.queue = queue;
190      return this;
191    }
192
193    @Override
194    public JobSubmissionEvent build() {
195      return new JobSubmissionEventImpl(this);
196    }
197  }
198}