001/* 002 * Copyright (c) 2007-2017 Xplenty, Inc. All Rights Reserved. 003 * 004 * Project and contact information: http://www.cascading.org/ 005 * 006 * This file is part of the Cascading project. 007 * 008 * Licensed under the Apache License, Version 2.0 (the "License"); 009 * you may not use this file except in compliance with the License. 010 * You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, software 015 * distributed under the License is distributed on an "AS IS" BASIS, 016 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 017 * See the License for the specific language governing permissions and 018 * limitations under the License. 019 */ 020 021package cascading.stats.tez; 022 023import java.util.Collection; 024import java.util.Collections; 025import java.util.HashMap; 026import java.util.Map; 027import javax.annotation.Nullable; 028 029import cascading.stats.CascadingStats; 030import cascading.stats.FlowSliceStats; 031import cascading.stats.ProvidesCounters; 032 033public class TezSliceStats extends FlowSliceStats<TezNodeStats.Kind> implements ProvidesCounters 034 { 035 private static final String LINE_SEPARATOR = System.getProperty( "line.separator" ); 036 037 public static class TezAttempt extends FlowSliceAttempt 038 { 039 @Override 040 public String getProcessAttemptID() 041 { 042 return null; 043 } 044 045 @Override 046 public int getEventId() 047 { 048 return 0; 049 } 050 051 @Override 052 public int getProcessDuration() 053 { 054 return 0; 055 } 056 057 @Override 058 public String getProcessStatus() 059 { 060 return null; 061 } 062 063 @Override 064 public String getStatusURL() 065 { 066 return null; 067 } 068 069 @Override 070 public CascadingStats.Status getStatus() 071 { 072 return null; 073 } 074 075 @Override 076 public String getProcessHostname() 077 { 078 return null; 079 } 080 } 081 082 private String id; 083 private TezNodeStats.Kind kind; 084 private final CascadingStats.Status parentStatus; 085 private CascadingStats.Status status; 086 private long submitTime; 087 private long startTime; 088 private long finishTime; 089 private String successfulAttemptID; 090 private String diagnostics; 091 092 private String vertexID; 093 private String taskID; 094 private long lastFetch = -1; 095 private Map<String, Map<String, Long>> counters = Collections.emptyMap(); 096 097 private Map<Integer, FlowSliceAttempt> attempts = new HashMap<>(); 098 099 TezSliceStats( String id, TezNodeStats.Kind kind, CascadingStats.Status parentStatus, String vertexID, String taskID ) 100 { 101 this.id = id; 102 this.kind = kind; 103 this.parentStatus = parentStatus; 104 this.vertexID = vertexID; 105 this.taskID = taskID; 106 } 107 108 public void setSubmitTime( long submitTime ) 109 { 110 this.submitTime = submitTime; 111 } 112 113 public void setStartTime( long startTime ) 114 { 115 this.startTime = startTime; 116 } 117 118 public void setFinishTime( long finishTime ) 119 { 120 this.finishTime = finishTime; 121 } 122 123 public void setSuccessfulAttemptID( String successfulAttemptID ) 124 { 125 this.successfulAttemptID = successfulAttemptID; 126 } 127 128 @Override 129 public String getID() 130 { 131 return id; 132 } 133 134 @Override 135 public long getProcessStartTime() 136 { 137 return submitTime; // start and submit are the same 138 } 139 140 @Override 141 public long getProcessRunTime() 142 { 143 return startTime; // when the slice began running 144 } 145 146 @Override 147 public long getProcessFinishTime() 148 { 149 return finishTime; // when the slice completed running 150 } 151 152 public void setDiagnostics( String diagnostics ) 153 { 154 this.diagnostics = diagnostics; 155 } 156 157 public CascadingStats.Status getParentStatus() 158 { 159 return parentStatus; 160 } 161 162 protected void setStatus( @Nullable CascadingStats.Status status ) 163 { 164 if( status != null ) 165 this.status = status; 166 } 167 168 @Override 169 public CascadingStats.Status getStatus() 170 { 171 return status; 172 } 173 174 @Override 175 public TezNodeStats.Kind getKind() 176 { 177 return kind; 178 } 179 180 public String[] getDiagnostics() 181 { 182 if( diagnostics == null ) 183 return new String[ 0 ]; 184 185 return diagnostics.split( LINE_SEPARATOR ); // how tez packs the diags 186 } 187 188 @Override 189 public Map<String, Map<String, Long>> getCounters() 190 { 191 return counters; 192 } 193 194 public String getProcessSliceID() 195 { 196 return taskID; 197 } 198 199 @Override 200 public String getProcessNodeID() 201 { 202 return vertexID; 203 } 204 205 @Override 206 public String getProcessStepID() 207 { 208 return null; 209 } 210 211 @Override 212 public String getProcessStatus() 213 { 214 return null; 215 } 216 217 @Override 218 public float getProcessProgress() 219 { 220 return 0; 221 } 222 223 public Map<Integer, FlowSliceAttempt> getAttempts() 224 { 225 return attempts; 226 } 227 228 public void setCounters( @Nullable Map<String, Map<String, Long>> counters ) 229 { 230 if( counters != null ) 231 this.counters = counters; 232 } 233 234 public void setLastFetch( long lastFetch ) 235 { 236 this.lastFetch = lastFetch; 237 } 238 239 @Override 240 public long getLastSuccessfulCounterFetchTime() 241 { 242 return lastFetch; 243 } 244 245 @Override 246 public Collection<String> getCounterGroups() 247 { 248 return getCounters().keySet(); 249 } 250 251 @Override 252 public Collection<String> getCountersFor( String group ) 253 { 254 return getCounters().get( group ).keySet(); 255 } 256 257 @Override 258 public Collection<String> getCountersFor( Class<? extends Enum> group ) 259 { 260 return getCountersFor( group.getDeclaringClass().getName() ); 261 } 262 263 @Override 264 public long getCounterValue( Enum counter ) 265 { 266 return getCounterValue( counter.getDeclaringClass().getName(), counter.name() ); 267 } 268 269 @Override 270 public long getCounterValue( String group, String name ) 271 { 272 if( getCounters() == null || getCounters().get( group ) == null ) 273 return 0; 274 275 Long value = getCounters().get( group ).get( name ); 276 277 if( value == null ) 278 return 0; 279 280 return value; 281 } 282 283 public void addAttempt( Object event ) 284 { 285// attempts.put( event.getEventId(), new TezAttempt( event ) ); 286 } 287 288 @Override 289 public String toString() 290 { 291 final StringBuilder sb = new StringBuilder(); 292 sb.append( "TezSliceStats" ); 293 sb.append( "{id='" ).append( id ).append( '\'' ); 294 sb.append( '}' ); 295 return sb.toString(); 296 } 297 }