11/*
2- * Copyright 2015 the original author or authors.
2+ * Copyright 2015 the original author or authors.
33 * @https://github.com/scouter-project/scouter
44 *
5- * Licensed under the Apache License, Version 2.0 (the "License");
5+ * Licensed under the Apache License, Version 2.0 (the "License");
66 * you may not use this file except in compliance with the License.
77 * You may obtain a copy of the License at
88 *
1212 * distributed under the License is distributed on an "AS IS" BASIS,
1313 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1414 * See the License for the specific language governing permissions and
15- * limitations under the License.
15+ * limitations under the License.
1616 */
1717package scouter .client .tags ;
1818
19- import java .util .ArrayList ;
20- import java .util .List ;
21-
2219import scouter .client .model .TextProxy ;
2320import scouter .lang .AlertLevel ;
2421import scouter .lang .constants .TagConstants ;
2522import scouter .lang .value .DecimalValue ;
26- import scouter .lang .value .IP4Value ;
2723import scouter .lang .value .ListValue ;
2824import scouter .lang .value .TextHashValue ;
2925import scouter .lang .value .TextValue ;
3026import scouter .lang .value .Value ;
3127import scouter .lang .value .ValueEnum ;
3228import scouter .util .CastUtil ;
33- import scouter .util .IntSet ;
34- import scouter .util .StringSet ;
29+ import scouter .util .HashUtil ;
30+
31+ import java .util .ArrayList ;
32+ import java .util .List ;
3533
3634public class TagCountUtil {
37-
35+
3836 // This should be called background thread.
3937 public static List <String > loadTagString (int serverId , String date , List <Value > vList , String tagName ) {
4038 List <String > resultList = new ArrayList <String >();
4139 if (vList .size () == 0 ) return resultList ;
4240 Value sample = vList .get (0 );
43- switch (sample .getValueType ()) {
41+ switch (sample .getValueType ()) {
4442 case ValueEnum .TEXT_HASH :
4543 ListValue lv = new ListValue ();
4644 for (Value v : vList ) {
4745 lv .add (CastUtil .cint (v .toJavaObject ()));
4846 }
49- if (tagName .equals (TagConstants .NAME_OBJECT )){
47+ if (tagName .equals (TagConstants .NAME_OBJECT )) {
5048 TextProxy .object .load (date , lv , serverId );
5149 for (int i = 0 ; i < lv .size (); i ++) {
5250 resultList .add (TextProxy .object .getText (lv .getInt (i )));
@@ -81,12 +79,38 @@ public static List<String> loadTagString(int serverId, String date, List<Value>
8179 for (int i = 0 ; i < lv .size (); i ++) {
8280 resultList .add (TextProxy .error .getText (lv .getInt (i )));
8381 }
82+ } else if (tagName .equals (TagConstants .NAME_LOGIN )) {
83+ TextProxy .login .load (date , lv , serverId );
84+ for (int i = 0 ; i < lv .size (); i ++) {
85+ resultList .add (TextProxy .login .getText (lv .getInt (i )));
86+ }
87+ } else if (tagName .equals (TagConstants .NAME_DESC )) {
88+ TextProxy .desc .load (date , lv , serverId );
89+ for (int i = 0 ; i < lv .size (); i ++) {
90+ resultList .add (TextProxy .desc .getText (lv .getInt (i )));
91+ }
8492 }
93+
8594 break ;
8695 case ValueEnum .DECIMAL :
96+ ListValue lvDecimal = new ListValue ();
97+ for (Value v : vList ) {
98+ lvDecimal .add (CastUtil .cint (v .toJavaObject ()));
99+ }
100+
87101 if (tagName .equals (TagConstants .NAME_LEVEL )) {
88102 for (Value v : vList ) {
89- resultList .add (AlertLevel .getName ((byte )((DecimalValue )v ).value ));
103+ resultList .add (AlertLevel .getName ((byte ) ((DecimalValue ) v ).value ));
104+ }
105+ } else if (tagName .equals (TagConstants .NAME_LOGIN )) {
106+ TextProxy .login .load (date , lvDecimal , serverId );
107+ for (int i = 0 ; i < lvDecimal .size (); i ++) {
108+ resultList .add (TextProxy .login .getText (lvDecimal .getInt (i )));
109+ }
110+ } else if (tagName .equals (TagConstants .NAME_DESC )) {
111+ TextProxy .login .load (date , lvDecimal , serverId );
112+ for (int i = 0 ; i < lvDecimal .size (); i ++) {
113+ resultList .add (TextProxy .login .getText (lvDecimal .getInt (i )));
90114 }
91115 } else {
92116 for (Value v : vList ) {
@@ -104,38 +128,38 @@ public static List<String> loadTagString(int serverId, String date, List<Value>
104128 resultList .add (v .toString ());
105129 }
106130 break ;
107- default :
131+ default :
108132 for (Value v : vList ) {
109133 resultList .add (v .toString ());
110134 }
111135 break ;
112136 }
113137 return resultList ;
114138 }
115-
139+
116140 public static Value convertTagToValue (String tagName , String tagValue ) {
117141 if (tagName .equals (TagConstants .NAME_OBJECT )
118- || tagName .equals (TagConstants .NAME_SERVICE )
119- || tagName .equals (TagConstants .NAME_SERVICE_TIME_SUM )
120- || tagName .equals (TagConstants .NAME_SERVICE_KBYTE_SUM )
121- || tagName .equals (TagConstants .NAME_SERVICE_ERROR_SUM )
122- || tagName .equals (TagConstants .NAME_GROUP )
123- || tagName .equals (TagConstants .NAME_USER_AGENT )
124- || tagName .equals (TagConstants .NAME_REFERER )
125- || tagName .equals (TagConstants .NAME_CITY )
126- || tagName .equals (TagConstants .NAME_ERROR )
127- || TagConstants .serviceHashGroup .hasKey (tagName )
128- ) {
142+ || tagName .equals (TagConstants .NAME_SERVICE )
143+ || tagName .equals (TagConstants .NAME_SERVICE_TIME_SUM )
144+ || tagName .equals (TagConstants .NAME_SERVICE_KBYTE_SUM )
145+ || tagName .equals (TagConstants .NAME_SERVICE_ERROR_SUM )
146+ || tagName .equals (TagConstants .NAME_GROUP )
147+ || tagName .equals (TagConstants .NAME_USER_AGENT )
148+ || tagName .equals (TagConstants .NAME_REFERER )
149+ || tagName .equals (TagConstants .NAME_CITY )
150+ || tagName .equals (TagConstants .NAME_ERROR )
151+ || TagConstants .serviceHashGroup .hasKey (tagName )
152+ ) {
129153 return new TextHashValue (tagValue );
130154// } else if (tagName.equals(TagConstants.NAME_USERID)
131155// || tagName.equals(TagConstants.NAME_ELAPSED)
132156// || tagName.equals(TagConstants.NAME_SQLTIME)
133157// || tagName.equals(TagConstants.NAME_APITIME)){
134158// return new DecimalValue(Long.valueOf(tagValue));
135- } else if (tagName .equals (TagConstants .NAME_LEVEL )) {
159+ } else if (tagName .equals (TagConstants .NAME_LEVEL )) {
136160 return new DecimalValue (AlertLevel .getValue (tagValue ));
137- // } else if (tagName.equals(TagConstants.NAME_IP )) {
138- // return new IP4Value( tagValue);
161+ } else if (tagName .equals (TagConstants .NAME_LOGIN ) || tagName . equals ( TagConstants . NAME_DESC )) {
162+ return new DecimalValue ( HashUtil . hash ( tagValue ) );
139163 }
140164 return new TextValue (tagValue );
141165 }
0 commit comments