10
10
import xyz .erupt .annotation .EruptI18n ;
11
11
import xyz .erupt .annotation .constant .AnnotationConst ;
12
12
import xyz .erupt .annotation .expr .ExprBool ;
13
- import xyz .erupt .annotation .fun .DataProxy ;
14
- import xyz .erupt .annotation .fun .TagsFetchHandler ;
15
13
import xyz .erupt .annotation .sub_erupt .Layout ;
16
14
import xyz .erupt .annotation .sub_erupt .RowOperation ;
17
15
import xyz .erupt .annotation .sub_erupt .Tpl ;
24
22
import xyz .erupt .annotation .sub_field .sub_edit .Search ;
25
23
import xyz .erupt .annotation .sub_field .sub_edit .TagsType ;
26
24
import xyz .erupt .cloud .server .base .CloudServerConst ;
27
- import xyz .erupt .cloud .server .node .MetaNode ;
28
- import xyz .erupt .cloud .server .node .NodeManager ;
29
- import xyz .erupt .core .config .GsonFactory ;
30
- import xyz .erupt .core .util .Erupts ;
31
- import xyz .erupt .jpa .dao .EruptDao ;
32
25
import xyz .erupt .jpa .model .MetaModelUpdateVo ;
33
- import xyz .erupt .linq .lambda .LambdaSee ;
34
- import xyz .erupt .tpl .engine .EngineConst ;
35
26
import xyz .erupt .upms .handler .ViaMenuValueCtrl ;
36
27
37
- import javax .annotation .Resource ;
38
28
import javax .persistence .*;
39
- import java .util .Collection ;
40
- import java .util .List ;
41
- import java .util .Map ;
42
- import java .util .Optional ;
43
- import java .util .function .Function ;
44
29
45
30
/**
46
31
* @author YuePeng
52
37
@ Entity
53
38
@ Table (name = "e_cloud_node" )
54
39
@ Erupt (
55
- name = "节点配置" , dataProxy = CloudNode .class ,
40
+ name = "节点配置" , dataProxy = CloudNodeProcess .class ,
56
41
rowOperation = @ RowOperation (
57
42
title = "查看令牌" , icon = "fa fa-shield" , mode = RowOperation .Mode .SINGLE ,
58
43
show = @ ExprBool (exprHandler = ViaMenuValueCtrl .class , params = CloudServerConst .CLOUD_ACCESS_TOKEN_PERMISSION ),
61
46
)
62
47
@ Component
63
48
@ EruptI18n
64
- public class CloudNode extends MetaModelUpdateVo implements DataProxy <CloudNode >, TagsFetchHandler , Tpl .TplHandler {
65
-
66
- public static final String NODE_NAME = LambdaSee .field (CloudNode ::getNodeName );
67
-
68
- public static final String ACCESS_TOKEN = LambdaSee .field (CloudNode ::getAccessToken );
49
+ public class CloudNode extends MetaModelUpdateVo {
69
50
70
51
@ Column (unique = true )
71
52
@ EruptField (
@@ -110,7 +91,7 @@ public class CloudNode extends MetaModelUpdateVo implements DataProxy<CloudNode>
110
91
@ Transient
111
92
@ EruptField (
112
93
views = @ View (title = "实例数" , className = "text-center" , width = "70px"
113
- , tpl = @ Tpl (path = "/tpl/node-instance.ftl" , width = "400px" , tplHandler = CloudNode .class )
94
+ , tpl = @ Tpl (path = "/tpl/node-instance.ftl" , width = "400px" , tplHandler = CloudNodeProcess .class )
114
95
)
115
96
)
116
97
private Integer instanceNum ;
@@ -124,7 +105,7 @@ public class CloudNode extends MetaModelUpdateVo implements DataProxy<CloudNode>
124
105
@ EruptField (
125
106
views = @ View (title = "负责人" , sortable = true ),
126
107
edit = @ Edit (title = "负责人" , type = EditType .TAGS ,
127
- tagsType = @ TagsType (fetchHandler = CloudNode .class ), notNull = true )
108
+ tagsType = @ TagsType (fetchHandler = CloudNodeProcess .class ), notNull = true )
128
109
)
129
110
private String duty ;
130
111
@@ -148,75 +129,5 @@ public class CloudNode extends MetaModelUpdateVo implements DataProxy<CloudNode>
148
129
)
149
130
private String remark ;
150
131
151
- @ Transient
152
- @ Resource
153
- private NodeManager nodeManager ;
154
-
155
- @ Transient
156
- @ Resource
157
- private EruptDao eruptDao ;
158
-
159
- @ Override
160
- public void afterUpdate (CloudNode cloudNode ) {
161
- DataProxy .super .afterUpdate (cloudNode );
162
- }
163
-
164
- @ Override
165
- public void beforeAdd (CloudNode cloudNode ) {
166
- if (null == cloudNode .getAccessToken ()) cloudNode .setAccessToken (Erupts .generateCode (16 ).toUpperCase ());
167
- }
168
-
169
- @ Override
170
- public void beforeUpdate (CloudNode cloudNode ) {
171
- this .beforeAdd (cloudNode );
172
- }
173
-
174
- @ Override
175
- public void afterFetch (Collection <Map <String , Object >> list ) {
176
- for (Map <String , Object > map : list ) {
177
- Optional .ofNullable (map .get (ACCESS_TOKEN )).ifPresent (it -> {
178
- String token = it .toString ();
179
- map .put (ACCESS_TOKEN , token .substring (0 , 3 ) + "******" + token .substring (token .length () - 3 ));
180
- });
181
- map .put (LambdaSee .field (CloudNode ::getEruptNum ), '-' );
182
- map .put (LambdaSee .field (CloudNode ::getInstanceNum ), '-' );
183
- map .put (LambdaSee .field (CloudNode ::getVersion ), '-' );
184
- map .put (LambdaSee .field (CloudNode ::getEruptModuleNum ), '-' );
185
- try {
186
- MetaNode metaNode = nodeManager .getNode (map .get (NODE_NAME ).toString ());
187
- Optional .ofNullable (nodeManager .getNode (map .get (NODE_NAME ).toString ())).ifPresent (metaNode1 -> {
188
- Function <Collection <String >, Object > function = (it ) -> null == it ? 0 : String .format ("<a href='javascript:alert(`%s`);'>%d</a>" , String .join ("\\ u000a" , it ), it .size ());
189
- map .put (LambdaSee .field (CloudNode ::getEruptNum ), function .apply (metaNode .getErupts ()));
190
- map .put (LambdaSee .field (CloudNode ::getInstanceNum ), metaNode .getLocations ().size ());
191
- map .put (LambdaSee .field (CloudNode ::getEruptModuleNum ), function .apply (metaNode .getEruptModules ()));
192
- map .put (LambdaSee .field (CloudNode ::getVersion ), metaNode .getVersion ());
193
- });
194
- } catch (Exception e ) {
195
- map .put (LambdaSee .field (CloudNode ::getVersion ), String .format ("<span style='color:#f00'>%s</span>" , e .getMessage ()));
196
- log .warn ("node warn → " + map .get (NODE_NAME ), e );
197
- }
198
- }
199
- }
200
-
201
- @ Override
202
- public void afterDelete (CloudNode cloudNode ) {
203
- nodeManager .removeNode (cloudNode .getNodeName ());
204
- }
205
-
206
- @ Override
207
- public List <String > fetchTags (String [] params ) {
208
- return eruptDao .getJdbcTemplate ().queryForList ("select name from e_upms_user" , String .class );
209
- }
210
-
211
- @ Override
212
- public void bindTplData (Map <String , Object > binding , String [] params ) {
213
- CloudNode cloudNode = (CloudNode ) binding .get (EngineConst .INJECT_ROW );
214
- MetaNode metaNode = nodeManager .getNode (cloudNode .getNodeName ());
215
- if (null == metaNode ) {
216
- binding .put ("instances" , "[]" );
217
- } else {
218
- binding .put ("instances" , GsonFactory .getGson ().toJson (metaNode .getLocations ()));
219
- }
220
- }
221
132
222
133
}
0 commit comments