2020import com .fasterxml .jackson .core .JsonFactory ;
2121import com .fasterxml .jackson .core .JsonParser ;
2222import com .fasterxml .jackson .core .JsonToken ;
23+ import com .fasterxml .jackson .databind .ObjectMapper ;
2324import com .vmware .vropsexport .exceptions .ExporterException ;
2425import com .vmware .vropsexport .models .NamedResource ;
2526import com .vmware .vropsexport .processors .ParentSplicer ;
@@ -93,7 +94,6 @@ public int process(
9394 }
9495
9596 // Process stat-list { stat [ ...
96- //
9797 expect (p , "stat-list" );
9898 expect (p , JsonToken .START_OBJECT );
9999 expect (p , "stat" );
@@ -102,7 +102,6 @@ public int process(
102102 while (p .nextToken () != JsonToken .END_ARRAY ) {
103103
104104 // Process timestamps[ ...
105- //
106105 expectCurrent (p , JsonToken .START_OBJECT );
107106 expect (p , "timestamps" );
108107 expect (p , JsonToken .START_ARRAY );
@@ -111,7 +110,6 @@ public int process(
111110 long ts = p .getLongValue ();
112111
113112 // Align timestamp if needed
114- //
115113 final int align = conf .getAlign () * 1000 ;
116114 if (align != 0 ) {
117115 ts = ((ts + align / 2 ) / align ) * align ;
@@ -125,13 +123,11 @@ public int process(
125123 expect (p , JsonToken .END_OBJECT );
126124
127125 // Keep skipping members until we've found the data node
128- //
129126 while (!expectMaybe (p , "data" )) {
130127 skipMember (p , null );
131128 }
132129
133130 // Process data[ ...
134- //
135131 expect (p , JsonToken .START_ARRAY );
136132 final int metricIdx = meta .getMetricIndex (statKey );
137133 int i = 0 ;
@@ -160,18 +156,15 @@ public int process(
160156 }
161157
162158 // End of stat-list and values object
163- //
164159 expect (p , JsonToken .END_OBJECT );
165160 expect (p , JsonToken .END_OBJECT );
166161 Rowset rs = new Rowset (resourceId , rows );
167162 rows = null ; // Make the GC release this a bit earlier
168163
169164 // Splice in properties
170- //
171165 if (dataProvider != null ) {
172166 if (meta .hasProperties ()) {
173167 // Put in resource id if requested.
174- //
175168 final int idIdx = meta .getPropertyIndex ("$resId" );
176169 if (idIdx != -1 ) {
177170 for (final Row row : rs .getRows ().values ()) {
@@ -180,7 +173,6 @@ public int process(
180173 }
181174
182175 // Put in name if requested
183- //
184176 final int nameIdx = meta .getPropertyIndex ("$resName" );
185177 if (nameIdx != -1 ) {
186178 final String name = dataProvider .getResourceName (resourceId );
@@ -190,7 +182,6 @@ public int process(
190182 }
191183
192184 // Splice in properties
193- //
194185 if (meta .needsPropertyLoad ()) {
195186 final Map <String , String > props = dataProvider .fetchProps (resourceId );
196187 for (final Map .Entry <String , String > e : props .entrySet ()) {
@@ -201,11 +192,25 @@ public int process(
201192 }
202193 }
203194 }
195+ // Splice in tags
196+ String tags = props .get ("summary|tagJson" );
197+ if (tags != null && !"none" .equals (tags )) {
198+ ObjectMapper om = new ObjectMapper ();
199+ List <Map <String , String >> parsed = om .readValue (tags , List .class );
200+ for (Map <String , String > tag : parsed ) {
201+ int idx = meta .getTagIndex (tag .get ("category" ));
202+ if (idx != -1 ) {
203+ String tagValue = tag .get ("name" );
204+ for (final Row row : rs .getRows ().values ()) {
205+ row .setProp (idx , tagValue );
206+ }
207+ }
208+ }
209+ }
204210 }
205211 }
206212
207213 // Splice in data from parent
208- //
209214 final RowMetadata pMeta = meta .forParent ();
210215 if (pMeta .isValid ()) {
211216 final long now = System .currentTimeMillis ();
@@ -218,7 +223,6 @@ public int process(
218223 cached = rowsetCache .get (cacheKey );
219224 }
220225 // Try cache first! Chances are we've seen this parent many times.
221- //
222226 if (cached != null ) {
223227 if (verbose ) {
224228 log .debug (
@@ -227,7 +231,6 @@ public int process(
227231 ParentSplicer .spliceRows (rs , cached );
228232 } else {
229233 // Not in cache. Fetch it the hard (and slow) way!
230- //
231234 if (verbose ) {
232235 log .debug (
233236 "Cache miss for parent "
@@ -261,7 +264,6 @@ public int process(
261264 }
262265
263266 // Compactify if needed
264- //
265267 if (conf .isCompact ()) {
266268 rs = compactify (rs , meta );
267269 }
@@ -277,13 +279,11 @@ public int process(
277279
278280 private Rowset compactify (final Rowset rs , final RowMetadata meta ) throws ExporterException {
279281 // No need to process empty rowsets
280- //
281282 if (rs .getRows ().size () == 0 ) {
282283 return rs ;
283284 }
284285
285286 // Calculate range according to compactification algorithm.
286- //
287287 final long startTime = System .currentTimeMillis ();
288288 final TreeMap <Long , Row > rows = rs .getRows ();
289289 final long start ;
@@ -316,7 +316,6 @@ private Rowset compactify(final Rowset rs, final RowMetadata meta) throws Export
316316 }
317317
318318 // Compactify everything that fits within the timerange into a single row
319- //
320319 final Row target = meta .newRow (ts );
321320 for (final Row r : rows .values ()) {
322321 if (r .getTimestamp () <= end && r .getTimestamp () >= start ) {
0 commit comments