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     */
018    package org.apache.hadoop.yarn.api.records.timeline;
019    
020    import org.apache.hadoop.classification.InterfaceAudience.Public;
021    import org.apache.hadoop.classification.InterfaceStability.Unstable;
022    
023    import javax.xml.bind.annotation.XmlAccessType;
024    import javax.xml.bind.annotation.XmlAccessorType;
025    import javax.xml.bind.annotation.XmlElement;
026    import javax.xml.bind.annotation.XmlRootElement;
027    import java.util.ArrayList;
028    import 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    @Unstable
040    public 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      @Unstable
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        private String entityId;
111        private String entityType;
112        private int errorCode;
113    
114        /**
115         * Get the entity Id
116         * 
117         * @return the entity Id
118         */
119        @XmlElement(name = "entity")
120        public String getEntityId() {
121          return entityId;
122        }
123    
124        /**
125         * Set the entity Id
126         * 
127         * @param entityId
128         *          the entity Id
129         */
130        public void setEntityId(String entityId) {
131          this.entityId = entityId;
132        }
133    
134        /**
135         * Get the entity type
136         * 
137         * @return the entity type
138         */
139        @XmlElement(name = "entitytype")
140        public String getEntityType() {
141          return entityType;
142        }
143    
144        /**
145         * Set the entity type
146         * 
147         * @param entityType
148         *          the entity type
149         */
150        public void setEntityType(String entityType) {
151          this.entityType = entityType;
152        }
153    
154        /**
155         * Get the error code
156         * 
157         * @return an error code
158         */
159        @XmlElement(name = "errorcode")
160        public int getErrorCode() {
161          return errorCode;
162        }
163    
164        /**
165         * Set the error code to the given error code
166         * 
167         * @param errorCode
168         *          an error code
169         */
170        public void setErrorCode(int errorCode) {
171          this.errorCode = errorCode;
172        }
173    
174      }
175    
176    }