/
InlongClusterServiceImpl.java
1434 lines (1322 loc) · 72.6 KB
/
InlongClusterServiceImpl.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.inlong.manager.service.cluster;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.google.common.base.Joiner;
import com.google.common.collect.Sets;
import com.google.gson.Gson;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.inlong.common.constant.Constants;
import org.apache.inlong.common.constant.MQType;
import org.apache.inlong.common.pojo.audit.AuditConfig;
import org.apache.inlong.common.pojo.audit.MQInfo;
import org.apache.inlong.common.pojo.dataproxy.DataProxyCluster;
import org.apache.inlong.common.pojo.dataproxy.DataProxyConfig;
import org.apache.inlong.common.pojo.dataproxy.DataProxyConfigResponse;
import org.apache.inlong.common.pojo.dataproxy.DataProxyNodeInfo;
import org.apache.inlong.common.pojo.dataproxy.DataProxyNodeResponse;
import org.apache.inlong.common.pojo.dataproxy.DataProxyTopicInfo;
import org.apache.inlong.common.pojo.dataproxy.MQClusterInfo;
import org.apache.inlong.manager.common.consts.InlongConstants;
import org.apache.inlong.manager.common.enums.ClusterType;
import org.apache.inlong.manager.common.enums.ErrorCodeEnum;
import org.apache.inlong.manager.common.enums.GroupStatus;
import org.apache.inlong.manager.common.enums.UserTypeEnum;
import org.apache.inlong.manager.common.exceptions.BusinessException;
import org.apache.inlong.manager.common.util.CommonBeanUtils;
import org.apache.inlong.manager.common.util.Preconditions;
import org.apache.inlong.manager.dao.entity.InlongClusterEntity;
import org.apache.inlong.manager.dao.entity.InlongClusterNodeEntity;
import org.apache.inlong.manager.dao.entity.InlongClusterTagEntity;
import org.apache.inlong.manager.dao.entity.InlongGroupEntity;
import org.apache.inlong.manager.dao.mapper.InlongClusterEntityMapper;
import org.apache.inlong.manager.dao.mapper.InlongClusterNodeEntityMapper;
import org.apache.inlong.manager.dao.mapper.InlongClusterTagEntityMapper;
import org.apache.inlong.manager.dao.mapper.InlongGroupEntityMapper;
import org.apache.inlong.manager.dao.mapper.InlongStreamEntityMapper;
import org.apache.inlong.manager.pojo.cluster.BindTagRequest;
import org.apache.inlong.manager.pojo.cluster.ClusterInfo;
import org.apache.inlong.manager.pojo.cluster.ClusterNodeRequest;
import org.apache.inlong.manager.pojo.cluster.ClusterNodeResponse;
import org.apache.inlong.manager.pojo.cluster.ClusterPageRequest;
import org.apache.inlong.manager.pojo.cluster.ClusterRequest;
import org.apache.inlong.manager.pojo.cluster.ClusterTagPageRequest;
import org.apache.inlong.manager.pojo.cluster.ClusterTagRequest;
import org.apache.inlong.manager.pojo.cluster.ClusterTagResponse;
import org.apache.inlong.manager.pojo.cluster.pulsar.PulsarClusterDTO;
import org.apache.inlong.manager.pojo.common.PageResult;
import org.apache.inlong.manager.pojo.common.UpdateResult;
import org.apache.inlong.manager.pojo.group.InlongGroupBriefInfo;
import org.apache.inlong.manager.pojo.group.InlongGroupPageRequest;
import org.apache.inlong.manager.pojo.group.pulsar.InlongPulsarDTO;
import org.apache.inlong.manager.pojo.stream.InlongStreamBriefInfo;
import org.apache.inlong.manager.pojo.user.UserInfo;
import org.apache.inlong.manager.service.cluster.node.InlongClusterNodeOperator;
import org.apache.inlong.manager.service.cluster.node.InlongClusterNodeOperatorFactory;
import org.apache.inlong.manager.service.repository.DataProxyConfigRepository;
import org.apache.inlong.manager.service.user.UserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
/**
* Inlong cluster service layer implementation
*/
@Service
public class InlongClusterServiceImpl implements InlongClusterService {
private static final Logger LOGGER = LoggerFactory.getLogger(InlongClusterServiceImpl.class);
private static final Gson GSON = new Gson();
@Autowired
private UserService userService;
@Autowired
private InlongGroupEntityMapper groupMapper;
@Autowired
private InlongStreamEntityMapper streamMapper;
@Autowired
private InlongClusterOperatorFactory clusterOperatorFactory;
@Autowired
private InlongClusterNodeOperatorFactory clusterNodeOperatorFactory;
@Autowired
private InlongClusterTagEntityMapper clusterTagMapper;
@Autowired
private InlongClusterEntityMapper clusterMapper;
@Autowired
private InlongClusterNodeEntityMapper clusterNodeMapper;
@Lazy
@Autowired
private DataProxyConfigRepository proxyRepository;
@Override
public Integer saveTag(ClusterTagRequest request, String operator) {
LOGGER.debug("begin to save cluster tag {}", request);
Preconditions.expectNotNull(request, "inlong cluster request cannot be empty");
Preconditions.expectNotBlank(request.getClusterTag(), ErrorCodeEnum.INVALID_PARAMETER,
"cluster tag cannot be empty");
// check if the cluster tag already exist
String clusterTag = request.getClusterTag();
InlongClusterTagEntity exist = clusterTagMapper.selectByTag(clusterTag);
if (exist != null) {
String errMsg = String.format("inlong cluster tag [%s] already exist", clusterTag);
LOGGER.error(errMsg);
throw new BusinessException(errMsg);
}
InlongClusterTagEntity entity = CommonBeanUtils.copyProperties(request, InlongClusterTagEntity::new);
entity.setCreator(operator);
entity.setModifier(operator);
clusterTagMapper.insert(entity);
LOGGER.info("success to save cluster tag={} by user={}", request, operator);
return entity.getId();
}
@Override
public Integer saveTag(ClusterTagRequest request, UserInfo opInfo) {
// check if the cluster tag already exist
InlongClusterTagEntity exist = clusterTagMapper.selectByTag(request.getClusterTag());
if (exist != null) {
throw new BusinessException(ErrorCodeEnum.RECORD_DUPLICATE,
String.format("inlong cluster tag [%s] already exist", request.getClusterTag()));
}
InlongClusterTagEntity entity = CommonBeanUtils.copyProperties(request, InlongClusterTagEntity::new);
entity.setCreator(opInfo.getName());
entity.setModifier(opInfo.getName());
clusterTagMapper.insert(entity);
return entity.getId();
}
@Override
public ClusterTagResponse getTag(Integer id, String currentUser) {
Preconditions.expectNotNull(id, "inlong cluster tag id cannot be empty");
InlongClusterTagEntity entity = clusterTagMapper.selectById(id);
if (entity == null) {
LOGGER.error("inlong cluster tag not found by id={}", id);
throw new BusinessException(ErrorCodeEnum.CLUSTER_NOT_FOUND);
}
userService.checkUser(entity.getInCharges(), currentUser,
"Current user does not have permission to get cluster tag");
ClusterTagResponse response = CommonBeanUtils.copyProperties(entity, ClusterTagResponse::new);
LOGGER.debug("success to get cluster tag info by id={}", id);
return response;
}
@Override
public ClusterTagResponse getTag(Integer id, UserInfo opInfo) {
InlongClusterTagEntity entity = clusterTagMapper.selectById(id);
if (entity == null) {
throw new BusinessException(ErrorCodeEnum.CLUSTER_NOT_FOUND,
String.format("inlong cluster tag not found by id=%s", id));
}
// only the person in charges can query
userService.checkUser(entity.getInCharges(), opInfo.getName(),
"Current user does not have permission to get cluster tag");
return CommonBeanUtils.copyProperties(entity, ClusterTagResponse::new);
}
@Override
public PageResult<ClusterTagResponse> listTag(ClusterTagPageRequest request) {
PageHelper.startPage(request.getPageNum(), request.getPageSize());
Page<InlongClusterTagEntity> entityPage = (Page<InlongClusterTagEntity>) clusterTagMapper
.selectByCondition(request);
List<ClusterTagResponse> tagList = CommonBeanUtils.copyListProperties(entityPage, ClusterTagResponse::new);
PageResult<ClusterTagResponse> pageResult = new PageResult<>(tagList,
entityPage.getTotal(), entityPage.getPageNum(), entityPage.getPageSize());
LOGGER.debug("success to list cluster tag by {}", request);
return pageResult;
}
@Override
public List<ClusterTagResponse> listTag(ClusterTagPageRequest request, UserInfo opInfo) {
List<InlongClusterTagEntity> filterResult = new ArrayList<>();
List<InlongClusterTagEntity> clusterTagEntities = clusterTagMapper.selectByCondition(request);
if (CollectionUtils.isNotEmpty(clusterTagEntities)) {
for (InlongClusterTagEntity tagEntity : clusterTagEntities) {
// only the person in charges can query
if (!opInfo.getAccountType().equals(UserTypeEnum.ADMIN.getCode())) {
List<String> inCharges = Arrays.asList(tagEntity.getInCharges().split(InlongConstants.COMMA));
if (!inCharges.contains(opInfo.getName())) {
continue;
}
}
filterResult.add(tagEntity);
}
}
return CommonBeanUtils.copyListProperties(filterResult, ClusterTagResponse::new);
}
@Override
@Transactional(rollbackFor = Throwable.class, isolation = Isolation.REPEATABLE_READ)
public Boolean updateTag(ClusterTagRequest request, String operator) {
LOGGER.debug("begin to update cluster tag={}", request);
Preconditions.expectNotNull(request, "inlong cluster request cannot be empty");
Integer id = request.getId();
Preconditions.expectNotNull(id, "cluster tag id cannot be empty");
InlongClusterTagEntity exist = clusterTagMapper.selectById(id);
if (exist == null) {
LOGGER.warn("inlong cluster tag was not exist for id={}", id);
return true;
}
// append cluster tag if value is empty
if (StringUtils.isEmpty(request.getClusterTag())) {
request.setClusterTag(exist.getClusterTag());
}
String newClusterTag = request.getClusterTag();
String errMsg = String.format("cluster tag has already updated with name=%s, curVersion=%s",
exist.getClusterTag(), request.getVersion());
if (!Objects.equals(exist.getVersion(), request.getVersion())) {
LOGGER.error(errMsg);
throw new BusinessException(ErrorCodeEnum.CONFIG_EXPIRED);
}
userService.checkUser(exist.getInCharges(), operator,
"Current user does not have permission to update cluster tag");
// if the cluster tag was changed, need to check whether the new tag already exists
String oldClusterTag = exist.getClusterTag();
if (!newClusterTag.equals(oldClusterTag)) {
InlongClusterTagEntity tagConflict = clusterTagMapper.selectByTag(newClusterTag);
if (tagConflict != null) {
String tagErrMsg = String.format("inlong cluster tag [%s] already exist", newClusterTag);
LOGGER.error(tagErrMsg);
throw new BusinessException(tagErrMsg);
}
// check if there are some InlongGroups that uses this tag
this.assertNoInlongGroupExists(oldClusterTag);
// update the associated cluster tag in inlong_cluster
List<InlongClusterEntity> clusterEntities = clusterMapper.selectByKey(oldClusterTag, null, null);
if (CollectionUtils.isNotEmpty(clusterEntities)) {
clusterEntities.forEach(entity -> {
Set<String> tagSet = Sets.newHashSet(entity.getClusterTags().split(InlongConstants.COMMA));
tagSet.remove(oldClusterTag);
tagSet.add(newClusterTag);
String updateTags = Joiner.on(",").join(tagSet);
entity.setClusterTags(updateTags);
entity.setModifier(operator);
if (InlongConstants.AFFECTED_ONE_ROW != clusterMapper.updateById(entity)) {
LOGGER.error("cluster has already updated with name={}, type={}, curVersion={}",
entity.getName(), entity.getType(), entity.getVersion());
throw new BusinessException(ErrorCodeEnum.CONFIG_EXPIRED);
}
});
}
}
CommonBeanUtils.copyProperties(request, exist, true);
exist.setModifier(operator);
if (InlongConstants.AFFECTED_ONE_ROW != clusterTagMapper.updateByIdSelective(exist)) {
LOGGER.error(errMsg);
throw new BusinessException(ErrorCodeEnum.CONFIG_EXPIRED);
}
LOGGER.info("success to update cluster tag={}", request);
return true;
}
@Override
@Transactional(rollbackFor = Throwable.class, isolation = Isolation.REPEATABLE_READ)
public Boolean updateTag(ClusterTagRequest request, UserInfo opInfo) {
InlongClusterTagEntity exist = clusterTagMapper.selectById(request.getId());
if (exist == null) {
throw new BusinessException(ErrorCodeEnum.RECORD_NOT_FOUND,
String.format("inlong cluster tag was not exist for id=%s", request.getId()));
}
// only the person in charges can query
userService.checkUser(exist.getInCharges(), opInfo.getName(),
"Current user does not have permission to update cluster tag");
// check record version
Preconditions.expectEquals(exist.getVersion(), request.getVersion(),
ErrorCodeEnum.CONFIG_EXPIRED,
String.format("record has expired with record version=%d, request version=%d",
exist.getVersion(), request.getVersion()));
// check if the cluster tag was changed, need to check whether the new tag already exists
if (StringUtils.isNotEmpty(request.getClusterTag())) {
String newClusterTag = request.getClusterTag();
String oldClusterTag = exist.getClusterTag();
if (!newClusterTag.equals(oldClusterTag)) {
InlongClusterTagEntity tagConflict = clusterTagMapper.selectByTag(newClusterTag);
if (tagConflict != null) {
throw new BusinessException(ErrorCodeEnum.RECORD_DUPLICATE,
String.format("inlong cluster tag [%s] to changed already exist", newClusterTag));
}
// check if there are some InlongGroups that uses this tag
List<InlongGroupEntity> usedGroupEntity = groupMapper.selectByClusterTag(oldClusterTag);
if (CollectionUtils.isNotEmpty(usedGroupEntity)) {
throw new BusinessException(ErrorCodeEnum.RECORD_IN_USED,
String.format("inlong cluster tag [%s] was used by inlong group", oldClusterTag));
}
// update the associated cluster tag in inlong_cluster
List<InlongClusterEntity> clusterEntities = clusterMapper.selectByKey(oldClusterTag, null, null);
if (CollectionUtils.isNotEmpty(clusterEntities)) {
clusterEntities.forEach(entity -> {
Set<String> tagSet = Sets.newHashSet(entity.getClusterTags().split(InlongConstants.COMMA));
tagSet.remove(oldClusterTag);
tagSet.add(newClusterTag);
String updateTags = Joiner.on(",").join(tagSet);
entity.setClusterTags(updateTags);
entity.setModifier(opInfo.getName());
if (InlongConstants.AFFECTED_ONE_ROW != clusterMapper.updateById(entity)) {
throw new BusinessException(ErrorCodeEnum.CONFIG_EXPIRED,
String.format("cluster has already updated with name=%s, type=%s, curVersion=%s",
entity.getName(), entity.getType(), entity.getVersion()));
}
});
}
}
}
CommonBeanUtils.copyProperties(request, exist, true);
exist.setModifier(opInfo.getName());
if (InlongConstants.AFFECTED_ONE_ROW != clusterTagMapper.updateByIdSelective(exist)) {
throw new BusinessException(ErrorCodeEnum.CONFIG_EXPIRED);
}
return true;
}
@Override
public Boolean deleteTag(Integer id, String operator) {
Preconditions.expectNotNull(id, "cluster tag id cannot be empty");
InlongClusterTagEntity exist = clusterTagMapper.selectById(id);
if (exist == null || exist.getIsDeleted() > InlongConstants.UN_DELETED) {
LOGGER.error("inlong cluster tag not found by id={}", id);
return false;
}
userService.checkUser(exist.getInCharges(), operator,
"Current user does not have permission to delete cluster tag");
// check if there are some InlongGroups that uses this tag
String clusterTag = exist.getClusterTag();
this.assertNoInlongGroupExists(clusterTag);
// update the associated cluster tag in inlong_cluster
List<InlongClusterEntity> clusterEntities = clusterMapper.selectByKey(clusterTag, null, null);
if (CollectionUtils.isNotEmpty(clusterEntities)) {
clusterEntities.forEach(entity -> {
this.removeClusterTag(entity, clusterTag, operator);
});
}
exist.setIsDeleted(exist.getId());
exist.setModifier(operator);
if (InlongConstants.AFFECTED_ONE_ROW != clusterTagMapper.updateByIdSelective(exist)) {
LOGGER.error("cluster tag has already updated with name={}, curVersion={}",
exist.getClusterTag(), exist.getVersion());
throw new BusinessException(ErrorCodeEnum.CONFIG_EXPIRED);
}
LOGGER.info("success to delete cluster tag by id={}", id);
return true;
}
@Override
public Boolean deleteTag(Integer id, UserInfo opInfo) {
InlongClusterTagEntity exist = clusterTagMapper.selectById(id);
if (exist == null || exist.getIsDeleted() > InlongConstants.UN_DELETED) {
return true;
}
// only the person in charges can query
userService.checkUser(exist.getInCharges(), opInfo.getName(),
"Current user does not have permission to delete cluster tag");
// check if there are some InlongGroups that uses this tag
String clusterTag = exist.getClusterTag();
// check if there are some InlongGroups that uses this tag
List<InlongGroupEntity> usedGroupEntity = groupMapper.selectByClusterTag(clusterTag);
if (CollectionUtils.isNotEmpty(usedGroupEntity)) {
throw new BusinessException(ErrorCodeEnum.RECORD_IN_USED,
String.format("inlong cluster tag [%s] was used by inlong group", clusterTag));
}
// update the associated cluster tag in inlong_cluster
List<InlongClusterEntity> clusterEntities = clusterMapper.selectByKey(clusterTag, null, null);
if (CollectionUtils.isNotEmpty(clusterEntities)) {
clusterEntities.forEach(entity -> {
this.removeClusterTag(entity, clusterTag, opInfo.getName());
});
}
exist.setIsDeleted(exist.getId());
exist.setModifier(opInfo.getName());
if (InlongConstants.AFFECTED_ONE_ROW != clusterTagMapper.updateByIdSelective(exist)) {
throw new BusinessException(ErrorCodeEnum.CONFIG_EXPIRED,
String.format("cluster tag has already updated with name=%s, curVersion=%s",
exist.getClusterTag(), exist.getVersion()));
}
return true;
}
@Override
public Integer save(ClusterRequest request, String operator) {
LOGGER.debug("begin to save inlong cluster={}", request);
Preconditions.expectNotNull(request, "inlong cluster request cannot be empty");
// check if the cluster already exist
String clusterTag = request.getClusterTags();
// The name cannot be modified and is automatically generated by the system
String name = request.getName();
if (StringUtils.isBlank(name)) {
name = UUID.randomUUID().toString();
request.setName(name);
}
String type = request.getType();
List<InlongClusterEntity> exist = clusterMapper.selectByKey(clusterTag, name, type);
if (CollectionUtils.isNotEmpty(exist)) {
String errMsg = String.format("inlong cluster already exist for cluster tag=%s name=%s type=%s",
clusterTag, name, type);
LOGGER.error(errMsg);
throw new BusinessException(errMsg);
}
InlongClusterOperator instance = clusterOperatorFactory.getInstance(request.getType());
Integer id = instance.saveOpt(request, operator);
LOGGER.info("success to save inlong cluster={} by user={}", request, operator);
return id;
}
@Override
public Integer save(ClusterRequest request, UserInfo opInfo) {
// The name cannot be modified and is automatically generated by the system
String name = request.getName();
if (StringUtils.isBlank(name)) {
name = UUID.randomUUID().toString();
request.setName(name);
}
// check if the cluster already exist
List<InlongClusterEntity> exist = clusterMapper.selectByKey(
request.getClusterTags(), request.getName(), request.getType());
if (CollectionUtils.isNotEmpty(exist)) {
throw new BusinessException(ErrorCodeEnum.RECORD_DUPLICATE,
String.format("inlong cluster already exist for cluster tag=%s name=%s type=%s",
request.getClusterTags(), request.getName(), request.getType()));
}
InlongClusterOperator instance = clusterOperatorFactory.getInstance(request.getType());
return instance.saveOpt(request, opInfo.getName());
}
@Override
public ClusterInfo get(Integer id, String currentUser) {
Preconditions.expectNotNull(id, "inlong cluster id cannot be empty");
InlongClusterEntity entity = clusterMapper.selectById(id);
if (entity == null) {
LOGGER.error("inlong cluster not found by id={}", id);
throw new BusinessException(ErrorCodeEnum.CLUSTER_NOT_FOUND);
}
String message = "Current user does not have permission to get cluster info";
userService.checkUser(entity.getInCharges(), currentUser, message);
InlongClusterOperator instance = clusterOperatorFactory.getInstance(entity.getType());
ClusterInfo clusterInfo = instance.getFromEntity(entity);
LOGGER.debug("success to get inlong cluster info by id={}", id);
return clusterInfo;
}
@Override
public ClusterInfo get(Integer id, UserInfo opInfo) {
InlongClusterEntity entity = clusterMapper.selectById(id);
if (entity == null) {
throw new BusinessException(ErrorCodeEnum.CLUSTER_NOT_FOUND,
String.format("inlong cluster not found by id=%s", id));
}
// only the person in charges can query
userService.checkUser(entity.getInCharges(), opInfo.getName(),
"Current user does not have permission to query cluster info");
InlongClusterOperator instance = clusterOperatorFactory.getInstance(entity.getType());
return instance.getFromEntity(entity);
}
@Override
public PageResult<ClusterInfo> list(ClusterPageRequest request) {
PageHelper.startPage(request.getPageNum(), request.getPageSize());
Page<InlongClusterEntity> entityPage = (Page<InlongClusterEntity>) clusterMapper.selectByCondition(request);
List<ClusterInfo> list = entityPage.stream()
.map(entity -> {
InlongClusterOperator instance = clusterOperatorFactory.getInstance(entity.getType());
return instance.getFromEntity(entity);
})
.collect(Collectors.toList());
PageResult<ClusterInfo> pageResult = new PageResult<>(
list, entityPage.getTotal(),
entityPage.getPageNum(), entityPage.getPageSize());
LOGGER.debug("success to list inlong cluster by {}", request);
return pageResult;
}
@Override
public List<ClusterInfo> list(ClusterPageRequest request, UserInfo opInfo) {
// get and filter records
List<InlongClusterEntity> clusterEntities = clusterMapper.selectByCondition(request);
List<InlongClusterEntity> filterResult = new ArrayList<>();
for (InlongClusterEntity entity : clusterEntities) {
// only the person in charges can query
if (!opInfo.getAccountType().equals(UserTypeEnum.ADMIN.getCode())) {
List<String> inCharges = Arrays.asList(entity.getInCharges().split(InlongConstants.COMMA));
if (!inCharges.contains(opInfo.getName())) {
continue;
}
}
filterResult.add(entity);
}
// transfer records
return filterResult.stream().map(entity -> {
InlongClusterOperator instance = clusterOperatorFactory.getInstance(entity.getType());
return instance.getFromEntity(entity);
}).collect(Collectors.toList());
}
@Override
public List<ClusterInfo> listByTagAndType(String clusterTag, String clusterType) {
List<InlongClusterEntity> clusterEntities = clusterMapper.selectByKey(clusterTag, null, clusterType);
if (CollectionUtils.isEmpty(clusterEntities)) {
throw new BusinessException(String.format("cannot find any cluster by tag %s and type %s",
clusterTag, clusterType));
}
List<ClusterInfo> clusterInfos = clusterEntities.stream()
.map(entity -> {
InlongClusterOperator operator = clusterOperatorFactory.getInstance(entity.getType());
return operator.getFromEntity(entity);
})
.collect(Collectors.toList());
LOGGER.debug("success to list inlong cluster by tag={}", clusterTag);
return clusterInfos;
}
@Override
public ClusterInfo getOne(String clusterTag, String name, String type) {
List<InlongClusterEntity> entityList = clusterMapper.selectByKey(clusterTag, name, type);
if (CollectionUtils.isEmpty(entityList)) {
throw new BusinessException(String.format("cluster not found by tag=%s, name=%s, type=%s",
clusterTag, name, type));
}
InlongClusterEntity entity = entityList.get(0);
InlongClusterOperator instance = clusterOperatorFactory.getInstance(entity.getType());
ClusterInfo result = instance.getFromEntity(entity);
LOGGER.debug("success to get inlong cluster by tag={}, name={}, type={}", clusterTag, name, type);
return result;
}
@Override
public Boolean update(ClusterRequest request, String operator) {
LOGGER.debug("begin to update inlong cluster: {}", request);
Preconditions.expectNotNull(request, "inlong cluster info cannot be empty");
Integer id = request.getId();
InlongClusterEntity entity = clusterMapper.selectById(id);
if (entity == null) {
LOGGER.error("inlong cluster not found by id={}", id);
throw new BusinessException(ErrorCodeEnum.CLUSTER_NOT_FOUND);
}
chkUnmodifiableParams(entity, request);
// check whether the cluster already exists
String clusterTag = request.getClusterTags();
List<InlongClusterEntity> exist = clusterMapper.selectByKey(
clusterTag, request.getName(), request.getType());
if (CollectionUtils.isNotEmpty(exist) && !Objects.equals(id, exist.get(0).getId())) {
String errMsg = String.format("inlong cluster already exist for cluster tag=%s name=%s type=%s",
clusterTag, request.getName(), request.getType());
LOGGER.error(errMsg);
throw new BusinessException(errMsg);
}
String message = "Current user does not have permission to update cluster info";
userService.checkUser(entity.getInCharges(), operator, message);
InlongClusterOperator instance = clusterOperatorFactory.getInstance(request.getType());
instance.updateOpt(request, operator);
LOGGER.info("success to update inlong cluster: {} by {}", request, operator);
return true;
}
@Override
public Boolean update(ClusterRequest request, UserInfo opInfo) {
InlongClusterEntity entity = clusterMapper.selectById(request.getId());
if (entity == null) {
throw new BusinessException(ErrorCodeEnum.CLUSTER_NOT_FOUND,
String.format("inlong cluster not found by id=%s", request.getId()));
}
// only the person in charges can query
userService.checkUser(entity.getInCharges(), opInfo.getName(),
"Current user does not have permission to update cluster info");
// check parameters
chkUnmodifiableParams(entity, request);
// check whether the cluster already exists
List<InlongClusterEntity> exist = clusterMapper.selectByKey(
request.getClusterTags(), request.getName(), request.getType());
if (CollectionUtils.isNotEmpty(exist) && !Objects.equals(request.getId(), exist.get(0).getId())) {
throw new BusinessException(ErrorCodeEnum.RECORD_DUPLICATE,
String.format("inlong cluster already exist for cluster tag=%s name=%s type=%s",
request.getClusterTags(), request.getName(), request.getType()));
}
// update record
InlongClusterOperator instance = clusterOperatorFactory.getInstance(request.getType());
instance.updateOpt(request, opInfo.getName());
return true;
}
@Override
public UpdateResult updateByKey(ClusterRequest request, String operator) {
LOGGER.debug("begin to update inlong cluster: {}", request);
Preconditions.expectNotNull(request, "inlong cluster info cannot be null");
String name = request.getName();
String type = request.getType();
InlongClusterEntity entity = clusterMapper.selectByNameAndType(name, type);
if (entity == null) {
throw new BusinessException(ErrorCodeEnum.CLUSTER_NOT_FOUND,
String.format("inlong cluster not found by name=%s, type=%s", name, type));
}
request.setId(entity.getId());
// check unmodifiable parameters
chkUnmodifiableParams(entity, request);
// check permission
String message = "Current user does not have permission to update cluster info";
userService.checkUser(entity.getInCharges(), operator, message);
// update record
InlongClusterOperator instance = clusterOperatorFactory.getInstance(request.getType());
instance.updateOpt(request, operator);
LOGGER.info("success to update inlong cluster: {} by {}", request, operator);
return new UpdateResult(entity.getId(), true, request.getVersion() + 1);
}
@Override
public Boolean bindTag(BindTagRequest request, String operator) {
LOGGER.info("begin to bind or unbind cluster tag: {}", request);
Preconditions.expectNotNull(request, "inlong cluster info cannot be empty");
String clusterTag = request.getClusterTag();
Preconditions.expectNotBlank(clusterTag, ErrorCodeEnum.INVALID_PARAMETER, "cluster tag cannot be empty");
InlongClusterTagEntity exist = clusterTagMapper.selectByTag(clusterTag);
userService.checkUser(exist.getInCharges(), operator,
"Current user does not have permission to bind or unbind cluster tag");
if (CollectionUtils.isNotEmpty(request.getBindClusters())) {
request.getBindClusters().forEach(id -> {
InlongClusterEntity entity = clusterMapper.selectById(id);
Set<String> tagSet = Sets.newHashSet(entity.getClusterTags().split(InlongConstants.COMMA));
tagSet.add(clusterTag);
String updateTags = Joiner.on(",").join(tagSet);
InlongClusterEntity updateEntity = clusterMapper.selectById(id);
updateEntity.setClusterTags(updateTags);
updateEntity.setModifier(operator);
if (InlongConstants.AFFECTED_ONE_ROW != clusterMapper.updateById(updateEntity)) {
LOGGER.error("cluster has already updated with name={}, type={}, curVersion={}",
updateEntity.getName(), updateEntity.getType(), updateEntity.getVersion());
throw new BusinessException(ErrorCodeEnum.CONFIG_EXPIRED);
}
});
}
if (CollectionUtils.isNotEmpty(request.getUnbindClusters())) {
request.getUnbindClusters().forEach(id -> {
InlongClusterEntity entity = clusterMapper.selectById(id);
this.removeClusterTag(entity, clusterTag, operator);
});
}
LOGGER.info("success to bind or unbind cluster tag {} by {}", request, operator);
return true;
}
@Override
public Boolean bindTag(BindTagRequest request, UserInfo opInfo) {
InlongClusterTagEntity exist = clusterTagMapper.selectByTag(request.getClusterTag());
// only the person in charges can bing tag
userService.checkUser(exist.getInCharges(), opInfo.getName(),
"Current user does not have permission to bind or unbind cluster tag");
if (CollectionUtils.isNotEmpty(request.getBindClusters())) {
request.getBindClusters().forEach(id -> {
InlongClusterEntity entity = clusterMapper.selectById(id);
Set<String> tagSet = Sets.newHashSet(entity.getClusterTags().split(InlongConstants.COMMA));
tagSet.add(request.getClusterTag());
String updateTags = Joiner.on(",").join(tagSet);
InlongClusterEntity updateEntity = clusterMapper.selectById(id);
updateEntity.setClusterTags(updateTags);
updateEntity.setModifier(opInfo.getName());
if (InlongConstants.AFFECTED_ONE_ROW != clusterMapper.updateById(updateEntity)) {
throw new BusinessException(ErrorCodeEnum.CONFIG_EXPIRED,
String.format("cluster has already updated with name=%s, type=%s, curVersion=%s",
updateEntity.getName(), updateEntity.getType(), updateEntity.getVersion()));
}
});
}
if (CollectionUtils.isNotEmpty(request.getUnbindClusters())) {
request.getUnbindClusters().forEach(id -> {
InlongClusterEntity entity = clusterMapper.selectById(id);
Set<String> tagSet = Sets.newHashSet(entity.getClusterTags().split(InlongConstants.COMMA));
tagSet.remove(request.getClusterTag());
String updateTags = Joiner.on(",").join(tagSet);
entity.setClusterTags(updateTags);
entity.setModifier(opInfo.getName());
if (InlongConstants.AFFECTED_ONE_ROW != clusterMapper.updateById(entity)) {
throw new BusinessException(ErrorCodeEnum.CONFIG_EXPIRED,
String.format("cluster has already updated with name=%s, type=%s, curVersion=%s",
entity.getName(), entity.getType(), entity.getVersion()));
}
});
}
return true;
}
@Override
public Boolean deleteByKey(String name, String type, String operator) {
Preconditions.expectNotBlank(name, ErrorCodeEnum.INVALID_PARAMETER, "cluster name should not be empty or null");
Preconditions.expectNotBlank(type, ErrorCodeEnum.INVALID_PARAMETER, "cluster type should not be empty or null");
InlongClusterEntity entity = clusterMapper.selectByNameAndType(name, type);
if (entity == null || entity.getIsDeleted() > InlongConstants.UN_DELETED) {
LOGGER.error("inlong cluster not found by clusterName={}, type={} or was already deleted",
name, type);
return false;
}
userService.checkUser(entity.getInCharges(), operator,
"Current user does not have permission to delete cluster info");
List<InlongClusterNodeEntity> nodeEntities = clusterNodeMapper.selectByParentId(entity.getId(), null);
if (CollectionUtils.isNotEmpty(nodeEntities)) {
String errMsg = String.format("there are undeleted nodes under the cluster [%s], "
+ "please delete the node first", entity.getName());
throw new BusinessException(errMsg);
}
entity.setIsDeleted(entity.getId());
entity.setModifier(operator);
if (InlongConstants.AFFECTED_ONE_ROW != clusterMapper.updateById(entity)) {
LOGGER.error("cluster has already updated with name={}, type={}, curVersion={}", entity.getName(),
entity.getType(), entity.getVersion());
throw new BusinessException(ErrorCodeEnum.CONFIG_EXPIRED);
}
LOGGER.info("success to delete inlong cluster for clusterName={}, type={} by user={}",
name, type, operator);
return true;
}
@Override
public Boolean delete(Integer id, String operator) {
Preconditions.expectNotNull(id, "cluster id cannot be empty");
InlongClusterEntity entity = clusterMapper.selectById(id);
Preconditions.expectNotNull(entity, ErrorCodeEnum.CLUSTER_NOT_FOUND,
ErrorCodeEnum.CLUSTER_NOT_FOUND.getMessage());
String message = "Current user does not have permission to delete cluster info";
userService.checkUser(entity.getInCharges(), operator, message);
List<InlongClusterNodeEntity> nodeEntities = clusterNodeMapper.selectByParentId(id, null);
if (CollectionUtils.isNotEmpty(nodeEntities)) {
String errMsg = String.format("there are undeleted nodes under the cluster [%s], "
+ "please delete the node first", entity.getName());
throw new BusinessException(errMsg);
}
entity.setIsDeleted(entity.getId());
entity.setModifier(operator);
if (InlongConstants.AFFECTED_ONE_ROW != clusterMapper.updateById(entity)) {
LOGGER.error("cluster has already updated with name={}, type={}, curVersion={}", entity.getName(),
entity.getType(), entity.getVersion());
throw new BusinessException(ErrorCodeEnum.CONFIG_EXPIRED);
}
LOGGER.info("success to delete inlong cluster for id={} by user={}", id, operator);
return true;
}
@Override
public Boolean delete(Integer id, UserInfo opInfo) {
InlongClusterEntity entity = clusterMapper.selectById(id);
Preconditions.expectNotNull(entity, ErrorCodeEnum.CLUSTER_NOT_FOUND,
ErrorCodeEnum.CONSUME_NOT_FOUND.getMessage());
// only the person in charges can delete
userService.checkUser(entity.getInCharges(), opInfo.getName(),
"Current user does not have permission to delete cluster info");
List<InlongClusterNodeEntity> nodeEntities = clusterNodeMapper.selectByParentId(id, null);
if (CollectionUtils.isNotEmpty(nodeEntities)) {
throw new BusinessException(ErrorCodeEnum.RECORD_IN_USED,
String.format("there are undeleted nodes under the cluster [%s], "
+ "please delete the node first", entity.getName()));
}
entity.setIsDeleted(entity.getId());
entity.setModifier(opInfo.getName());
if (InlongConstants.AFFECTED_ONE_ROW != clusterMapper.updateById(entity)) {
throw new BusinessException(ErrorCodeEnum.CONFIG_EXPIRED,
String.format("cluster has already updated with name=%s, type=%s, curVersion=%s",
entity.getName(), entity.getType(), entity.getVersion()));
}
return true;
}
@Override
public Integer saveNode(ClusterNodeRequest request, String operator) {
LOGGER.debug("begin to insert inlong cluster node={}", request);
Preconditions.expectNotNull(request, "cluster node info cannot be empty");
// check cluster node if exist
InlongClusterNodeEntity exist = clusterNodeMapper.selectByUniqueKey(request);
if (exist != null) {
String errMsg = String.format("inlong cluster node already exist for type=%s ip=%s port=%s",
request.getType(), request.getIp(), request.getPort());
LOGGER.error(errMsg);
throw new BusinessException(errMsg);
}
InlongClusterNodeOperator instance = clusterNodeOperatorFactory.getInstance(request.getType());
return instance.saveOpt(request, operator);
}
@Override
public Integer saveNode(ClusterNodeRequest request, UserInfo opInfo) {
// check cluster info
InlongClusterEntity entity = clusterMapper.selectById(request.getParentId());
Preconditions.expectNotNull(entity, ErrorCodeEnum.CLUSTER_NOT_FOUND,
String.format("inlong cluster not found by id=%s, or was already deleted", request.getParentId()));
// only the person in charges can query
userService.checkUser(entity.getInCharges(), opInfo.getName(),
String.format("No permission to add cluster node in cluster=%s", request.getParentId()));
// check cluster node if exist
InlongClusterNodeEntity exist = clusterNodeMapper.selectByUniqueKey(request);
if (exist != null) {
throw new BusinessException(ErrorCodeEnum.RECORD_DUPLICATE,
String.format("inlong cluster node already exist for type=%s ip=%s port=%s",
request.getType(), request.getIp(), request.getPort()));
}
// add record
InlongClusterNodeOperator instance = clusterNodeOperatorFactory.getInstance(request.getType());
return instance.saveOpt(request, opInfo.getName());
}
@Override
public ClusterNodeResponse getNode(Integer id, String currentUser) {
Preconditions.expectNotNull(id, "cluster node id cannot be empty");
InlongClusterNodeEntity entity = clusterNodeMapper.selectById(id);
if (entity == null) {
LOGGER.error("inlong cluster node not found by id={}", id);
throw new BusinessException(ErrorCodeEnum.CLUSTER_NOT_FOUND);
}
InlongClusterEntity cluster = clusterMapper.selectById(entity.getParentId());
String message = "Current user does not have permission to get cluster node";
userService.checkUser(cluster.getInCharges(), currentUser, message);
InlongClusterNodeOperator instance = clusterNodeOperatorFactory.getInstance(entity.getType());
return instance.getFromEntity(entity);
}
@Override
public ClusterNodeResponse getNode(Integer id, UserInfo opInfo) {
InlongClusterNodeEntity entity = clusterNodeMapper.selectById(id);
if (entity == null) {
throw new BusinessException(ErrorCodeEnum.CLUSTER_NOT_FOUND);
}
InlongClusterEntity cluster = clusterMapper.selectById(entity.getParentId());
// only the person in charges can query
userService.checkUser(cluster.getInCharges(), opInfo.getName(),
"Current user does not have permission to delete cluster info");
return CommonBeanUtils.copyProperties(entity, ClusterNodeResponse::new);
}
@Override
public PageResult<ClusterNodeResponse> listNode(ClusterPageRequest request, String currentUser) {
if (StringUtils.isNotBlank(request.getClusterTag())) {
List<ClusterNodeResponse> nodeList = listNodeByClusterTag(request);
return new PageResult<>(nodeList, (long) nodeList.size());
}
Integer parentId = request.getParentId();
Preconditions.expectNotNull(parentId, "Cluster id cannot be empty");
InlongClusterEntity cluster = clusterMapper.selectById(parentId);
String message = "Current user does not have permission to get cluster node list";
userService.checkUser(cluster.getInCharges(), currentUser, message);
PageHelper.startPage(request.getPageNum(), request.getPageSize());
Page<InlongClusterNodeEntity> entityPage =
(Page<InlongClusterNodeEntity>) clusterNodeMapper.selectByCondition(request);
List<ClusterNodeResponse> nodeList = CommonBeanUtils.copyListProperties(entityPage, ClusterNodeResponse::new);
PageResult<ClusterNodeResponse> pageResult = new PageResult<>(nodeList, entityPage.getTotal(),
entityPage.getPageNum(), entityPage.getPageSize());
LOGGER.debug("success to list inlong cluster node by {}", request);
return pageResult;
}
@Override
public List<ClusterNodeResponse> listNode(ClusterPageRequest request, UserInfo opInfo) {
if (StringUtils.isBlank(request.getClusterTag())) {
if (request.getParentId() == null) {
throw new BusinessException(ErrorCodeEnum.ID_IS_EMPTY,
"Cluster id cannot be empty");
}
InlongClusterEntity cluster = clusterMapper.selectById(request.getParentId());
// only the person in charges can query
userService.checkUser(cluster.getInCharges(), opInfo.getName(),
"Current user does not have permission to get cluster node list");
return CommonBeanUtils.copyListProperties(
clusterNodeMapper.selectByCondition(request), ClusterNodeResponse::new);
} else {
List<InlongClusterNodeEntity> allNodeList = new ArrayList<>();
List<InlongClusterEntity> clusterList =
clusterMapper.selectByKey(request.getClusterTag(), request.getName(), request.getType());
for (InlongClusterEntity cluster : clusterList) {
// only the person in charges can query
if (!opInfo.getAccountType().equals(UserTypeEnum.ADMIN.getCode())) {
List<String> inCharges = Arrays.asList(cluster.getInCharges().split(InlongConstants.COMMA));
if (!inCharges.contains(opInfo.getName())) {
continue;
}
}
allNodeList.addAll(clusterNodeMapper.selectByParentId(cluster.getId(), null));
}
return CommonBeanUtils.copyListProperties(allNodeList, ClusterNodeResponse::new);
}
}
@Override
public List<ClusterNodeResponse> listNodeByGroupId(String groupId, String clusterType, String protocolType) {
LOGGER.debug("begin to get cluster nodes for groupId={}, clusterType={}, protocol={}",
groupId, clusterType, protocolType);
List<InlongClusterNodeEntity> nodeEntities = getClusterNodes(groupId, clusterType, protocolType);
if (CollectionUtils.isEmpty(nodeEntities)) {
LOGGER.debug("not any cluster node for groupId={}, clusterType={}, protocol={}",
groupId, clusterType, protocolType);
return Collections.emptyList();
}
List<ClusterNodeResponse> result = CommonBeanUtils.copyListProperties(nodeEntities, ClusterNodeResponse::new);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("success to get nodes for groupId={}, clusterType={}, protocol={}, result size={}",
groupId, clusterType, protocolType, result);
}
return result;
}
@Override
public List<ClusterNodeResponse> listNodeByGroupId(
String groupId, String clusterType, String protocolType, UserInfo opInfo) {
InlongGroupEntity groupEntity = groupMapper.selectByGroupId(groupId);
if (groupEntity == null) {
throw new BusinessException(ErrorCodeEnum.GROUP_NOT_FOUND,
String.format("inlong group not exists for groupId=%s", groupId));
}
// only the person in charges can query
userService.checkUser(groupEntity.getInCharges(), opInfo.getName(),
String.format("Current user does not have permission to query for groupId=%s", groupId));
String clusterTag = groupEntity.getInlongClusterTag();
if (StringUtils.isBlank(clusterTag)) {
throw new BusinessException(ErrorCodeEnum.CLUSTER_TAG_NOT_FOUND,
String.format("not found any cluster tag for groupId=%s", groupId));
}
List<InlongClusterEntity> clusterList = clusterMapper.selectByKey(clusterTag, null, clusterType);
if (CollectionUtils.isEmpty(clusterList)) {
throw new BusinessException(ErrorCodeEnum.CLUSTER_NOT_FOUND,
String.format("not found any data proxy cluster for groupId=%s and clusterTag=%s",
groupId, clusterTag));
}
// TODO if more than one data proxy cluster, currently takes first
List<InlongClusterNodeEntity> nodeEntities =
clusterNodeMapper.selectByParentId(clusterList.get(0).getId(), protocolType);
if (CollectionUtils.isEmpty(nodeEntities)) {
return Collections.emptyList();
}
return CommonBeanUtils.copyListProperties(nodeEntities, ClusterNodeResponse::new);
}
public List<ClusterNodeResponse> listNodeByClusterTag(ClusterPageRequest request) {
List<InlongClusterEntity> clusterList = clusterMapper.selectByKey(request.getClusterTag(), request.getName(),
request.getType());
List<InlongClusterNodeEntity> allNodeList = new ArrayList<>();
for (InlongClusterEntity cluster : clusterList) {
List<InlongClusterNodeEntity> nodeList = clusterNodeMapper.selectByParentId(cluster.getId(), null);
allNodeList.addAll(nodeList);
}
return CommonBeanUtils.copyListProperties(allNodeList, ClusterNodeResponse::new);
}
@Override
public List<String> listNodeIpByType(String type) {
Preconditions.expectNotBlank(type, ErrorCodeEnum.INVALID_PARAMETER, "cluster type cannot be empty");