This project has retired. For details please refer to its Attic page.
Source code
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  private final Optional<Boolean> preserveEvaluators;
044  private final Optional<Integer> maxApplicationSubmissions;
045
046  private JobSubmissionEventImpl(final Builder builder) {
047    this.identifier = BuilderUtils.notNull(builder.identifier);
048    this.remoteId = BuilderUtils.notNull(builder.remoteId);
049    this.configuration = BuilderUtils.notNull(builder.configuration);
050    this.userName = BuilderUtils.notNull(builder.userName);
051    this.globalFileSet = BuilderUtils.notNull(builder.globalFileSet);
052    this.localFileSet = BuilderUtils.notNull(builder.localFileSet);
053    this.driverMemory = Optional.ofNullable(builder.driverMemory);
054    this.priority = Optional.ofNullable(builder.priority);
055    this.preserveEvaluators = Optional.ofNullable(builder.preserveEvaluators);
056    this.queue = Optional.ofNullable(builder.queue);
057    this.maxApplicationSubmissions = Optional.ofNullable(builder.maxApplicationSubmissions);
058  }
059
060  @Override
061  public String toString() {
062    return String.format(
063        "Job Submission :: user:%s id:%s remote:%s mem:%s queue:%s priority:%s" +
064        " preserve evaluators:%s max submissions:%s global:%s local:%s",
065        this.userName, this.identifier, this.remoteId, this.driverMemory, this.queue, this.priority,
066        this.preserveEvaluators, this.maxApplicationSubmissions, this.globalFileSet, this.localFileSet);
067  }
068
069  @Override
070  public String getIdentifier() {
071    return identifier;
072  }
073
074  @Override
075  public String getRemoteId() {
076    return remoteId;
077  }
078
079  @Override
080  public Configuration getConfiguration() {
081    return configuration;
082  }
083
084  @Override
085  public String getUserName() {
086    return userName;
087  }
088
089  @Override
090  public Set<FileResource> getGlobalFileSet() {
091    return globalFileSet;
092  }
093
094  @Override
095  public Set<FileResource> getLocalFileSet() {
096    return localFileSet;
097  }
098
099  @Override
100  public Optional<Integer> getDriverMemory() {
101    return driverMemory;
102  }
103
104  @Override
105  public Optional<Integer> getPriority() {
106    return priority;
107  }
108
109  @Override
110  public Optional<Boolean> getPreserveEvaluators() {
111    return preserveEvaluators;
112  }
113
114  @Override
115  public Optional<Integer> getMaxApplicationSubmissions() {
116    return maxApplicationSubmissions;
117  }
118
119  public static Builder newBuilder() {
120    return new Builder();
121  }
122
123  /**
124   * Builder used to create JobSubmissionEvent instances.
125   */
126  public static final class Builder implements org.apache.reef.util.Builder<JobSubmissionEvent> {
127    private String identifier;
128    private String remoteId;
129    private Configuration configuration;
130    private String userName;
131    private Set<FileResource> globalFileSet = new HashSet<>();
132    private Set<FileResource> localFileSet = new HashSet<>();
133    private Integer driverMemory;
134    private Integer priority;
135    private String queue;
136    private Boolean preserveEvaluators;
137    private Integer maxApplicationSubmissions;
138
139    /**
140     * @see JobSubmissionEvent#getIdentifier()
141     */
142    public Builder setIdentifier(final String identifier) {
143      this.identifier = identifier;
144      return this;
145    }
146
147    /**
148     * @see JobSubmissionEvent#getRemoteId()
149     */
150    public Builder setRemoteId(final String remoteId) {
151      this.remoteId = remoteId;
152      return this;
153    }
154
155    /**
156     * @see JobSubmissionEvent#getConfiguration()
157     */
158    public Builder setConfiguration(final Configuration configuration) {
159      this.configuration = configuration;
160      return this;
161    }
162
163    /**
164     * @see JobSubmissionEvent#getUserName()
165     */
166    public Builder setUserName(final String userName) {
167      this.userName = userName;
168      return this;
169    }
170
171    /**
172     * Add an entry to the globalFileSet.
173     * @see JobSubmissionEvent#getGlobalFileSet()
174     */
175    public Builder addGlobalFile(final FileResource globalFile) {
176      this.globalFileSet.add(globalFile);
177      return this;
178    }
179
180    /**
181     * Add an entry to the localFileSet.
182     * @see JobSubmissionEvent#getLocalFileSet()
183     */
184    public Builder addLocalFile(final FileResource localFile) {
185      this.localFileSet.add(localFile);
186      return this;
187    }
188
189    /**
190     * @see JobSubmissionEvent#getDriverMemory()
191     */
192    public Builder setDriverMemory(final Integer driverMemory) {
193      this.driverMemory = driverMemory;
194      return this;
195    }
196
197    /**
198     * @see JobSubmissionEvent#getPriority()
199     */
200    public Builder setPriority(final Integer priority) {
201      this.priority = priority;
202      return this;
203    }
204
205    /**
206     * @see JobSubmissionEvent#getPreserveEvaluators()
207     */
208    public Builder setPreserveEvaluators(final Boolean preserveEvaluators) {
209      this.preserveEvaluators = preserveEvaluators;
210      return this;
211    }
212
213    /**
214     * @see JobSubmissionEvent#getMaxApplicationSubmissions()
215     */
216    public Builder setMaxApplicationSubmissions(final Integer maxApplicationSubmissions) {
217      this.maxApplicationSubmissions = maxApplicationSubmissions;
218      return this;
219    }
220
221    @Override
222    public JobSubmissionEvent build() {
223      return new JobSubmissionEventImpl(this);
224    }
225  }
226}