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    /**
133     * Error code returned if the entity start time is before the eviction
134     * period of old data.
135     */
136    public static final int EXPIRED_ENTITY = 7;
137
138    private String entityId;
139    private String entityType;
140    private int errorCode;
141
142    /**
143     * Get the entity Id
144     * 
145     * @return the entity Id
146     */
147    @XmlElement(name = "entity")
148    public String getEntityId() {
149      return entityId;
150    }
151
152    /**
153     * Set the entity Id
154     * 
155     * @param entityId
156     *          the entity Id
157     */
158    public void setEntityId(String entityId) {
159      this.entityId = entityId;
160    }
161
162    /**
163     * Get the entity type
164     * 
165     * @return the entity type
166     */
167    @XmlElement(name = "entitytype")
168    public String getEntityType() {
169      return entityType;
170    }
171
172    /**
173     * Set the entity type
174     * 
175     * @param entityType
176     *          the entity type
177     */
178    public void setEntityType(String entityType) {
179      this.entityType = entityType;
180    }
181
182    /**
183     * Get the error code
184     * 
185     * @return an error code
186     */
187    @XmlElement(name = "errorcode")
188    public int getErrorCode() {
189      return errorCode;
190    }
191
192    /**
193     * Set the error code to the given error code
194     * 
195     * @param errorCode
196     *          an error code
197     */
198    public void setErrorCode(int errorCode) {
199      this.errorCode = errorCode;
200    }
201
202  }
203
204}