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 getIdentifier() { 062 return identifier; 063 } 064 065 @Override 066 public String getRemoteId() { 067 return remoteId; 068 } 069 070 @Override 071 public Configuration getConfiguration() { 072 return configuration; 073 } 074 075 @Override 076 public String getUserName() { 077 return userName; 078 } 079 080 @Override 081 public Set<FileResource> getGlobalFileSet() { 082 return globalFileSet; 083 } 084 085 @Override 086 public Set<FileResource> getLocalFileSet() { 087 return localFileSet; 088 } 089 090 @Override 091 public Optional<Integer> getDriverMemory() { 092 return driverMemory; 093 } 094 095 @Override 096 public Optional<Integer> getPriority() { 097 return priority; 098 } 099 100 @Override 101 public Optional<Boolean> getPreserveEvaluators() { 102 return preserveEvaluators; 103 } 104 105 @Override 106 public Optional<Integer> getMaxApplicationSubmissions() { 107 return maxApplicationSubmissions; 108 } 109 110 public static Builder newBuilder() { 111 return new Builder(); 112 } 113 114 /** 115 * Builder used to create JobSubmissionEvent instances. 116 */ 117 public static final class Builder implements org.apache.reef.util.Builder<JobSubmissionEvent> { 118 private String identifier; 119 private String remoteId; 120 private Configuration configuration; 121 private String userName; 122 private Set<FileResource> globalFileSet = new HashSet<>(); 123 private Set<FileResource> localFileSet = new HashSet<>(); 124 private Integer driverMemory; 125 private Integer priority; 126 private String queue; 127 private Boolean preserveEvaluators; 128 private Integer maxApplicationSubmissions; 129 130 /** 131 * @see JobSubmissionEvent#getIdentifier() 132 */ 133 public Builder setIdentifier(final String identifier) { 134 this.identifier = identifier; 135 return this; 136 } 137 138 /** 139 * @see JobSubmissionEvent#getRemoteId() 140 */ 141 public Builder setRemoteId(final String remoteId) { 142 this.remoteId = remoteId; 143 return this; 144 } 145 146 /** 147 * @see JobSubmissionEvent#getConfiguration() 148 */ 149 public Builder setConfiguration(final Configuration configuration) { 150 this.configuration = configuration; 151 return this; 152 } 153 154 /** 155 * @see JobSubmissionEvent#getUserName() 156 */ 157 public Builder setUserName(final String userName) { 158 this.userName = userName; 159 return this; 160 } 161 162 /** 163 * Add an entry to the globalFileSet. 164 * @see JobSubmissionEvent#getGlobalFileSet() 165 */ 166 public Builder addGlobalFile(final FileResource globalFile) { 167 this.globalFileSet.add(globalFile); 168 return this; 169 } 170 171 /** 172 * Add an entry to the localFileSet. 173 * @see JobSubmissionEvent#getLocalFileSet() 174 */ 175 public Builder addLocalFile(final FileResource localFile) { 176 this.localFileSet.add(localFile); 177 return this; 178 } 179 180 /** 181 * @see JobSubmissionEvent#getDriverMemory() 182 */ 183 public Builder setDriverMemory(final Integer driverMemory) { 184 this.driverMemory = driverMemory; 185 return this; 186 } 187 188 /** 189 * @see JobSubmissionEvent#getPriority() 190 */ 191 public Builder setPriority(final Integer priority) { 192 this.priority = priority; 193 return this; 194 } 195 196 /** 197 * @see JobSubmissionEvent#getPreserveEvaluators() 198 */ 199 public Builder setPreserveEvaluators(final Boolean preserveEvaluators) { 200 this.preserveEvaluators = preserveEvaluators; 201 return this; 202 } 203 204 /** 205 * @see JobSubmissionEvent#getMaxApplicationSubmissions() 206 */ 207 public Builder setMaxApplicationSubmissions(final Integer maxApplicationSubmissions) { 208 this.maxApplicationSubmissions = maxApplicationSubmissions; 209 return this; 210 } 211 212 @Override 213 public JobSubmissionEvent build() { 214 return new JobSubmissionEventImpl(this); 215 } 216 } 217}