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, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.apache.hadoop.yarn.api.records.timeline;
019
020import org.apache.hadoop.classification.InterfaceAudience.Public;
021import org.apache.hadoop.classification.InterfaceStability.Evolving;
022
023import javax.xml.bind.annotation.XmlAccessType;
024import javax.xml.bind.annotation.XmlAccessorType;
025import javax.xml.bind.annotation.XmlElement;
026import javax.xml.bind.annotation.XmlRootElement;
027import java.util.ArrayList;
028import java.util.List;
029
030/**
031 * A class that holds a list of put errors. This is the response returned when a
032 * list of {@link TimelineEntity} objects is added to the timeline. If there are errors
033 * in storing individual entity objects, they will be indicated in the list of
034 * errors.
035 */
036@XmlRootElement(name = "response")
037@XmlAccessorType(XmlAccessType.NONE)
038@Public
039@Evolving
040public class TimelinePutResponse {
041
042  private List<TimelinePutError> errors = new ArrayList<TimelinePutError>();
043
044  public TimelinePutResponse() {
045
046  }
047
048  /**
049   * Get a list of {@link TimelinePutError} instances
050   * 
051   * @return a list of {@link TimelinePutError} instances
052   */
053  @XmlElement(name = "errors")
054  public List<TimelinePutError> getErrors() {
055    return errors;
056  }
057
058  /**
059   * Add a single {@link TimelinePutError} instance into the existing list
060   * 
061   * @param error
062   *          a single {@link TimelinePutError} instance
063   */
064  public void addError(TimelinePutError error) {
065    errors.add(error);
066  }
067
068  /**
069   * Add a list of {@link TimelinePutError} instances into the existing list
070   * 
071   * @param errors
072   *          a list of {@link TimelinePutError} instances
073   */
074  public void addErrors(List<TimelinePutError> errors) {
075    this.errors.addAll(errors);
076  }
077
078  /**
079   * Set the list to the given list of {@link TimelinePutError} instances
080   * 
081   * @param errors
082   *          a list of {@link TimelinePutError} instances
083   */
084  public void setErrors(List<TimelinePutError> errors) {
085    this.errors.clear();
086    this.errors.addAll(errors);
087  }
088
089  /**
090   * A class that holds the error code for one entity.
091   */
092  @XmlRootElement(name = "error")
093  @XmlAccessorType(XmlAccessType.NONE)
094  @Public
095  @Evolving
096  public static class TimelinePutError {
097
098    /**
099     * Error code returned when no start time can be found when putting an
100     * entity. This occurs when the entity does not already exist in the store
101     * and it is put with no start time or events specified.
102     */
103    public static final int NO_START_TIME = 1;
104    /**
105     * Error code returned if an IOException is encountered when putting an
106     * entity.
107     */
108    public static final int IO_EXCEPTION = 2;
109
110    /**
111     * Error code returned if the user specifies the timeline system reserved
112     * filter key
113     */
114    public static final int SYSTEM_FILTER_CONFLICT = 3;
115
116    /**
117     * Error code returned if the user is denied to access the timeline data
118     */
119    public static final int ACCESS_DENIED = 4;
120
121    /**
122     * Error code returned if the entity doesn't have an valid domain ID
123     */
124    public static final int NO_DOMAIN = 5;
125
126    /**
127     * Error code returned if the user is denied to relate the entity to another
128     * one in different domain
129     */
130    public static final int FORBIDDEN_RELATION = 6;
131
132    private String entityId;
133    private String entityType;
134    private int errorCode;
135
136    /**
137     * Get the entity Id
138     * 
139     * @return the entity Id
140     */
141    @XmlElement(name = "entity")
142    public String getEntityId() {
143      return entityId;
144    }
145
146    /**
147     * Set the entity Id
148     * 
149     * @param entityId
150     *          the entity Id
151     */
152    public void setEntityId(String entityId) {
153      this.entityId = entityId;
154    }
155
156    /**
157     * Get the entity type
158     * 
159     * @return the entity type
160     */
161    @XmlElement(name = "entitytype")
162    public String getEntityType() {
163      return entityType;
164    }
165
166    /**
167     * Set the entity type
168     * 
169     * @param entityType
170     *          the entity type
171     */
172    public void setEntityType(String entityType) {
173      this.entityType = entityType;
174    }
175
176    /**
177     * Get the error code
178     * 
179     * @return an error code
180     */
181    @XmlElement(name = "errorcode")
182    public int getErrorCode() {
183      return errorCode;
184    }
185
186    /**
187     * Set the error code to the given error code
188     * 
189     * @param errorCode
190     *          an error code
191     */
192    public void setErrorCode(int errorCode) {
193      this.errorCode = errorCode;
194    }
195
196  }
197
198}