Skip to content
This repository was archived by the owner on Apr 18, 2024. It is now read-only.

Commit a234f79

Browse files
author
Jialin Qiao
authored
Merge pull request #17 from ljn55966005/dev-0.13.0-metircs
2 parents 1c98cd8 + 29a7091 commit a234f79

39 files changed

Lines changed: 5132 additions & 109 deletions

backend/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@
145145
<dependency>
146146
<groupId>org.apache.iotdb</groupId>
147147
<artifactId>iotdb-session</artifactId>
148-
<version>0.12.1</version>
148+
<version>0.12.5</version>
149149
<exclusions>
150150
<exclusion>
151151
<artifactId>logback-classic</artifactId>
@@ -157,7 +157,7 @@
157157
<dependency>
158158
<groupId>org.apache.iotdb</groupId>
159159
<artifactId>iotdb-jdbc</artifactId>
160-
<version>0.12.1</version>
160+
<version>0.12.5</version>
161161
<exclusions>
162162
<exclusion>
163163
<artifactId>logback-classic</artifactId>

backend/src/main/java/org/apache/iotdb/admin/common/exception/ErrorCode.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,10 @@ public class ErrorCode {
158158
public static final String SET_GROUP_FAIL = "IOTDB-0022";
159159
public static final String SET_GROUP_FAIL_MSG = "Failed to create storage group";
160160

161+
public static final String SET_GROUP_FAIL_EXISTS = "IOTDB-0095";
162+
public static final String SET_GROUP_FAIL__EXISTS_MSG =
163+
"Failed to create storage group, the storage group already exists";
164+
161165
public static final String DELETE_GROUP_FAIL = "IOTDB-0023";
162166
public static final String DELETE_GROUP_FAIL_MSG = "Failed to delete storage group";
163167

backend/src/main/java/org/apache/iotdb/admin/controller/FileController.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,17 @@ public ResponseEntity<Resource> downloadTemplateFile() throws BaseException {
115115
return getResponseEntity(resource);
116116
}
117117

118+
@ApiOperation("Download the query log file")
119+
@GetMapping("/downloadQueryLogFile")
120+
public ResponseEntity<Resource> downloadQueryLogFile(
121+
@RequestParam String SQLStatement, @RequestParam Long timeStamp) throws BaseException {
122+
Resource resource = new ClassPathResource("file/[Fake]QueryLog.txt");
123+
if (!resource.exists()) {
124+
throw new BaseException(ErrorCode.FILE_NOT_FOUND, ErrorCode.FILE_NOT_FOUND_MSG);
125+
}
126+
return getResponseEntity(resource);
127+
}
128+
118129
private ResponseEntity<Resource> getResponseEntity(Resource resource) {
119130
String contentType = "application/octet-stream";
120131

backend/src/main/java/org/apache/iotdb/admin/controller/IotDBController.java

Lines changed: 79 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -85,35 +85,67 @@ public BaseVO<DataCountVO> getDataCount(
8585
@GetMapping("/dataModel")
8686
@ApiOperation("Get IoTDB data model")
8787
public BaseVO<DataModelVO> getDataModel(
88-
@PathVariable("serverId") Integer serverId, HttpServletRequest request) throws BaseException {
88+
@PathVariable("serverId") Integer serverId,
89+
@RequestParam(value = "path", required = false, defaultValue = "root") String path,
90+
HttpServletRequest request)
91+
throws BaseException {
8992
check(request, serverId);
9093
Connection connection = connectionService.getById(serverId);
91-
DataModelVO dataModelVO = iotDBService.getDataModel(connection);
94+
DataModelVO dataModelVO = iotDBService.getDataModel(connection, path);
95+
return BaseVO.success("Get IoTDB data model successfully", dataModelVO);
96+
}
97+
98+
@GetMapping("/dataModel/detail")
99+
@ApiOperation("Get IoTDB data model in detail")
100+
public BaseVO<DataModelVO> getDataModelDetail(
101+
@PathVariable("serverId") Integer serverId,
102+
@RequestParam(value = "path", required = false, defaultValue = "root") String path,
103+
@RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
104+
@RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum,
105+
HttpServletRequest request)
106+
throws BaseException {
107+
check(request, serverId);
108+
Connection connection = connectionService.getById(serverId);
109+
DataModelVO dataModelVO = iotDBService.getDataModelDetail(connection, path, pageSize, pageNum);
92110
return BaseVO.success("Get IoTDB data model successfully", dataModelVO);
93111
}
94112

95113
@GetMapping("/storageGroups/info")
96114
@ApiOperation("Get information of the storage group list")
97-
public BaseVO<List<GroupInfoVO>> getAllStorageGroupsInfo(
98-
@PathVariable("serverId") Integer serverId, HttpServletRequest request) throws BaseException {
115+
public BaseVO<GroupInfoVO> getAllStorageGroupsInfo(
116+
@PathVariable("serverId") Integer serverId,
117+
@RequestParam(value = "pageSize", required = false, defaultValue = "15") Integer pageSize,
118+
@RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum,
119+
HttpServletRequest request)
120+
throws BaseException {
99121
check(request, serverId);
100122
Connection connection = connectionService.getById(serverId);
101123
List<String> groupNames = iotDBService.getAllStorageGroups(connection);
102-
List<GroupInfoVO> groupInfoList = new ArrayList<>();
103-
if (groupNames == null || groupNames.size() == 0) {
104-
return BaseVO.success("Get successfully", groupInfoList);
124+
List<String> subGroupNames = new ArrayList<>();
125+
int size = groupNames.size();
126+
int pageStart = pageNum == 1 ? 0 : (pageNum - 1) * pageSize;
127+
int pageEnd = size < pageNum * pageSize ? size : pageNum * pageSize;
128+
if (size > pageStart) {
129+
subGroupNames = groupNames.subList(pageStart, pageEnd);
130+
}
131+
List<GroupInfo> groupInfoList = new ArrayList<>();
132+
GroupInfoVO groupInfoVO = new GroupInfoVO();
133+
if (subGroupNames == null || subGroupNames.size() == 0) {
134+
return BaseVO.success("Get successfully", groupInfoVO);
105135
}
106136
String host = connection.getHost();
107-
List<Integer> deviceCounts = iotDBService.getDevicesCount(connection, groupNames);
108-
List<String> descriptions = groupService.getGroupDescription(host, groupNames);
109-
for (int i = 0; i < groupNames.size(); i++) {
110-
GroupInfoVO groupInfoVO = new GroupInfoVO();
111-
groupInfoVO.setGroupName(groupNames.get(i));
112-
groupInfoVO.setDeviceCount(deviceCounts.get(i));
113-
groupInfoVO.setDescription(descriptions.get(i));
114-
groupInfoList.add(groupInfoVO);
137+
List<Integer> deviceCounts = iotDBService.getDevicesCount(connection, subGroupNames);
138+
List<String> descriptions = groupService.getGroupDescription(host, subGroupNames);
139+
for (int i = 0; i < subGroupNames.size(); i++) {
140+
GroupInfo groupInfo = new GroupInfo();
141+
groupInfo.setGroupName(subGroupNames.get(i));
142+
groupInfo.setDeviceCount(deviceCounts.get(i));
143+
groupInfo.setDescription(descriptions.get(i));
144+
groupInfoList.add(groupInfo);
115145
}
116-
return BaseVO.success("Get successfully", groupInfoList);
146+
groupInfoVO.setGroupInfoList(groupInfoList);
147+
groupInfoVO.setGroupCount(size);
148+
return BaseVO.success("Get successfully", groupInfoVO);
117149
}
118150

119151
@GetMapping("/storageGroups")
@@ -130,8 +162,6 @@ public BaseVO<List<StorageGroupVO>> getAllStorageGroups(
130162
String host = connection.getHost();
131163
for (String groupName : groupNames) {
132164
StorageGroupVO storageGroupVO = new StorageGroupVO();
133-
Integer id = groupService.getGroupId(host, groupName);
134-
storageGroupVO.setGroupId(id);
135165
storageGroupVO.setGroupName(groupName);
136166
storageGroupVOList.add(storageGroupVO);
137167
}
@@ -161,7 +191,6 @@ public BaseVO saveStorageGroup(
161191
Connection connection = connectionService.getById(serverId);
162192
Long ttl = groupDTO.getTtl();
163193
String ttlUnit = groupDTO.getTtlUnit();
164-
checkTtl(ttl, ttlUnit);
165194
Integer groupId = groupDTO.getGroupId();
166195
groupDTO.setGroupName(groupName);
167196

@@ -175,6 +204,7 @@ public BaseVO saveStorageGroup(
175204
groupService.updateStorageGroupInfo(connection, groupDTO);
176205
}
177206
if (ttl != null && ttlUnit != null) {
207+
checkTtl(ttl, ttlUnit);
178208
if (ttl >= 0) {
179209
Long times = switchTime(ttlUnit);
180210
iotDBService.saveGroupTtl(connection, groupName, ttl * times);
@@ -323,12 +353,19 @@ public BaseVO<List<NodeTreeVO>> getDevicesNodeTreeByGroup(
323353
public BaseVO<NodeTreeVO> getDevicesTreeByGroup(
324354
@PathVariable("serverId") Integer serverId,
325355
@PathVariable("groupName") String groupName,
356+
@RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
357+
@RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum,
326358
HttpServletRequest request)
327359
throws BaseException {
328360
checkParameter(groupName);
329361
check(request, serverId);
330362
Connection connection = connectionService.getById(serverId);
331-
NodeTreeVO deviceList = iotDBService.getDeviceList(connection, groupName);
363+
NodeTreeVO deviceList = iotDBService.getDeviceList(connection, groupName, pageSize, pageNum);
364+
if (deviceList == null) {
365+
deviceList = new NodeTreeVO(groupName);
366+
}
367+
deviceList.setPageNum(pageNum);
368+
deviceList.setPageSize(pageSize);
332369
return BaseVO.success("Get successfully", deviceList);
333370
}
334371

@@ -430,8 +467,8 @@ public BaseVO<MeasuremtnInfoVO> getMeasurementsByDeviceName(
430467
@PathVariable("serverId") Integer serverId,
431468
@PathVariable("groupName") String groupName,
432469
@PathVariable("deviceName") String deviceName,
433-
@RequestParam("pageSize") Integer pageSize,
434-
@RequestParam("pageNum") Integer pageNum,
470+
@RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
471+
@RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum,
435472
@RequestParam(value = "keyword", required = false) String keyword,
436473
HttpServletRequest request)
437474
throws BaseException {
@@ -444,17 +481,26 @@ public BaseVO<MeasuremtnInfoVO> getMeasurementsByDeviceName(
444481
List<MeasurementVO> measurementVOList = new ArrayList<>();
445482
String host = connection.getHost();
446483
if (measurementDTOList != null) {
484+
List<String> timeseriesList = new ArrayList<>();
485+
for (MeasurementDTO measurementDTO : measurementDTOList) {
486+
timeseriesList.add(measurementDTO.getTimeseries());
487+
}
488+
List<String> batchNewValue =
489+
iotDBService.getBatchLastMeasurementValue(connection, timeseriesList);
490+
List<String> batchDataCount =
491+
iotDBService.getBatchDataCount(connection, deviceName, timeseriesList);
492+
int index = 0;
447493
for (MeasurementDTO measurementDTO : measurementDTOList) {
448494
MeasurementVO measurementVO = new MeasurementVO();
449495
BeanUtils.copyProperties(measurementDTO, measurementVO);
450496
String description =
451497
measurementService.getDescription(host, measurementDTO.getTimeseries());
452-
String newValue =
453-
iotDBService.getLastMeasurementValue(connection, measurementDTO.getTimeseries());
454-
Integer dataCount =
455-
iotDBService.getOneDataCount(connection, deviceName, measurementDTO.getTimeseries());
456-
measurementVO.setDataCount(dataCount);
457-
measurementVO.setNewValue(newValue);
498+
if (batchNewValue.size() != 0) {
499+
measurementVO.setNewValue(batchNewValue.get(index));
500+
}
501+
if (batchDataCount.size() != 0) {
502+
measurementVO.setDataCount(Integer.parseInt(batchDataCount.get(index)));
503+
}
458504
measurementVO.setDescription(description);
459505
ObjectMapper mapper = new ObjectMapper();
460506
List<List<String>> tags = new ArrayList<>();
@@ -488,6 +534,7 @@ public BaseVO<MeasuremtnInfoVO> getMeasurementsByDeviceName(
488534
throw new BaseException(ErrorCode.GET_MSM_FAIL, ErrorCode.GET_MSM_FAIL_MSG);
489535
}
490536
measurementVOList.add(measurementVO);
537+
index++;
491538
}
492539
}
493540
MeasuremtnInfoVO measuremtnInfoVO = new MeasuremtnInfoVO();
@@ -1121,9 +1168,7 @@ private void check(HttpServletRequest request, Integer serverId) throws BaseExce
11211168

11221169
private void checkParameter(String groupName) throws BaseException {
11231170
String checkName = StringUtils.removeStart(groupName, "root").toLowerCase();
1124-
if (!groupName.matches("^root\\.[^ ]+$")
1125-
|| checkName.contains(".root.")
1126-
|| checkName.matches("^[^ ]*\\.root$")) {
1171+
if (groupName.contains(".root.") || groupName.contains(".root")) {
11271172
throw new BaseException(ErrorCode.NO_SUP_CONTAIN_ROOT, ErrorCode.NO_SUP_CONTAIN_ROOT_MSG);
11281173
}
11291174
if (checkName.contains(".as.")
@@ -1229,6 +1274,9 @@ private String getTTL(Long time) {
12291274
}
12301275

12311276
private void checkTtl(Long ttl, String unit) throws BaseException {
1277+
if (ttl == null || unit == null) {
1278+
return;
1279+
}
12321280
if (Long.MAX_VALUE / switchTime(unit) < ttl) {
12331281
throw new BaseException(ErrorCode.TTL_OVER, ErrorCode.TTL_OVER_MSG);
12341282
}

0 commit comments

Comments
 (0)