Skip to content
This repository was archived by the owner on Apr 18, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@
<dependency>
<groupId>org.apache.iotdb</groupId>
<artifactId>iotdb-session</artifactId>
<version>0.12.1</version>
<version>0.12.5</version>
<exclusions>
<exclusion>
<artifactId>logback-classic</artifactId>
Expand All @@ -157,7 +157,7 @@
<dependency>
<groupId>org.apache.iotdb</groupId>
<artifactId>iotdb-jdbc</artifactId>
<version>0.12.1</version>
<version>0.12.5</version>
<exclusions>
<exclusion>
<artifactId>logback-classic</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@ public class ErrorCode {
public static final String SET_GROUP_FAIL = "IOTDB-0022";
public static final String SET_GROUP_FAIL_MSG = "Failed to create storage group";

public static final String SET_GROUP_FAIL_EXISTS = "IOTDB-0095";
public static final String SET_GROUP_FAIL__EXISTS_MSG =
"Failed to create storage group, the storage group already exists";

public static final String DELETE_GROUP_FAIL = "IOTDB-0023";
public static final String DELETE_GROUP_FAIL_MSG = "Failed to delete storage group";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,17 @@ public ResponseEntity<Resource> downloadTemplateFile() throws BaseException {
return getResponseEntity(resource);
}

@ApiOperation("Download the query log file")
@GetMapping("/downloadQueryLogFile")
public ResponseEntity<Resource> downloadQueryLogFile(
@RequestParam String SQLStatement, @RequestParam Long timeStamp) throws BaseException {
Resource resource = new ClassPathResource("file/[Fake]QueryLog.txt");
if (!resource.exists()) {
throw new BaseException(ErrorCode.FILE_NOT_FOUND, ErrorCode.FILE_NOT_FOUND_MSG);
}
return getResponseEntity(resource);
}

private ResponseEntity<Resource> getResponseEntity(Resource resource) {
String contentType = "application/octet-stream";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,35 +85,67 @@ public BaseVO<DataCountVO> getDataCount(
@GetMapping("/dataModel")
@ApiOperation("Get IoTDB data model")
public BaseVO<DataModelVO> getDataModel(
@PathVariable("serverId") Integer serverId, HttpServletRequest request) throws BaseException {
@PathVariable("serverId") Integer serverId,
@RequestParam(value = "path", required = false, defaultValue = "root") String path,
HttpServletRequest request)
throws BaseException {
check(request, serverId);
Connection connection = connectionService.getById(serverId);
DataModelVO dataModelVO = iotDBService.getDataModel(connection);
DataModelVO dataModelVO = iotDBService.getDataModel(connection, path);
return BaseVO.success("Get IoTDB data model successfully", dataModelVO);
}

@GetMapping("/dataModel/detail")
@ApiOperation("Get IoTDB data model in detail")
public BaseVO<DataModelVO> getDataModelDetail(
@PathVariable("serverId") Integer serverId,
@RequestParam(value = "path", required = false, defaultValue = "root") String path,
@RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
@RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum,
HttpServletRequest request)
throws BaseException {
check(request, serverId);
Connection connection = connectionService.getById(serverId);
DataModelVO dataModelVO = iotDBService.getDataModelDetail(connection, path, pageSize, pageNum);
return BaseVO.success("Get IoTDB data model successfully", dataModelVO);
}

@GetMapping("/storageGroups/info")
@ApiOperation("Get information of the storage group list")
public BaseVO<List<GroupInfoVO>> getAllStorageGroupsInfo(
@PathVariable("serverId") Integer serverId, HttpServletRequest request) throws BaseException {
public BaseVO<GroupInfoVO> getAllStorageGroupsInfo(
@PathVariable("serverId") Integer serverId,
@RequestParam(value = "pageSize", required = false, defaultValue = "15") Integer pageSize,
@RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum,
HttpServletRequest request)
throws BaseException {
check(request, serverId);
Connection connection = connectionService.getById(serverId);
List<String> groupNames = iotDBService.getAllStorageGroups(connection);
List<GroupInfoVO> groupInfoList = new ArrayList<>();
if (groupNames == null || groupNames.size() == 0) {
return BaseVO.success("Get successfully", groupInfoList);
List<String> subGroupNames = new ArrayList<>();
int size = groupNames.size();
int pageStart = pageNum == 1 ? 0 : (pageNum - 1) * pageSize;
int pageEnd = size < pageNum * pageSize ? size : pageNum * pageSize;
if (size > pageStart) {
subGroupNames = groupNames.subList(pageStart, pageEnd);
}
List<GroupInfo> groupInfoList = new ArrayList<>();
GroupInfoVO groupInfoVO = new GroupInfoVO();
if (subGroupNames == null || subGroupNames.size() == 0) {
return BaseVO.success("Get successfully", groupInfoVO);
}
String host = connection.getHost();
List<Integer> deviceCounts = iotDBService.getDevicesCount(connection, groupNames);
List<String> descriptions = groupService.getGroupDescription(host, groupNames);
for (int i = 0; i < groupNames.size(); i++) {
GroupInfoVO groupInfoVO = new GroupInfoVO();
groupInfoVO.setGroupName(groupNames.get(i));
groupInfoVO.setDeviceCount(deviceCounts.get(i));
groupInfoVO.setDescription(descriptions.get(i));
groupInfoList.add(groupInfoVO);
List<Integer> deviceCounts = iotDBService.getDevicesCount(connection, subGroupNames);
List<String> descriptions = groupService.getGroupDescription(host, subGroupNames);
for (int i = 0; i < subGroupNames.size(); i++) {
GroupInfo groupInfo = new GroupInfo();
groupInfo.setGroupName(subGroupNames.get(i));
groupInfo.setDeviceCount(deviceCounts.get(i));
groupInfo.setDescription(descriptions.get(i));
groupInfoList.add(groupInfo);
}
return BaseVO.success("Get successfully", groupInfoList);
groupInfoVO.setGroupInfoList(groupInfoList);
groupInfoVO.setGroupCount(size);
return BaseVO.success("Get successfully", groupInfoVO);
}

@GetMapping("/storageGroups")
Expand All @@ -130,8 +162,6 @@ public BaseVO<List<StorageGroupVO>> getAllStorageGroups(
String host = connection.getHost();
for (String groupName : groupNames) {
StorageGroupVO storageGroupVO = new StorageGroupVO();
Integer id = groupService.getGroupId(host, groupName);
storageGroupVO.setGroupId(id);
storageGroupVO.setGroupName(groupName);
storageGroupVOList.add(storageGroupVO);
}
Expand Down Expand Up @@ -161,7 +191,6 @@ public BaseVO saveStorageGroup(
Connection connection = connectionService.getById(serverId);
Long ttl = groupDTO.getTtl();
String ttlUnit = groupDTO.getTtlUnit();
checkTtl(ttl, ttlUnit);
Integer groupId = groupDTO.getGroupId();
groupDTO.setGroupName(groupName);

Expand All @@ -175,6 +204,7 @@ public BaseVO saveStorageGroup(
groupService.updateStorageGroupInfo(connection, groupDTO);
}
if (ttl != null && ttlUnit != null) {
checkTtl(ttl, ttlUnit);
if (ttl >= 0) {
Long times = switchTime(ttlUnit);
iotDBService.saveGroupTtl(connection, groupName, ttl * times);
Expand Down Expand Up @@ -323,12 +353,19 @@ public BaseVO<List<NodeTreeVO>> getDevicesNodeTreeByGroup(
public BaseVO<NodeTreeVO> getDevicesTreeByGroup(
@PathVariable("serverId") Integer serverId,
@PathVariable("groupName") String groupName,
@RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
@RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum,
HttpServletRequest request)
throws BaseException {
checkParameter(groupName);
check(request, serverId);
Connection connection = connectionService.getById(serverId);
NodeTreeVO deviceList = iotDBService.getDeviceList(connection, groupName);
NodeTreeVO deviceList = iotDBService.getDeviceList(connection, groupName, pageSize, pageNum);
if (deviceList == null) {
deviceList = new NodeTreeVO(groupName);
}
deviceList.setPageNum(pageNum);
deviceList.setPageSize(pageSize);
return BaseVO.success("Get successfully", deviceList);
}

Expand Down Expand Up @@ -430,8 +467,8 @@ public BaseVO<MeasuremtnInfoVO> getMeasurementsByDeviceName(
@PathVariable("serverId") Integer serverId,
@PathVariable("groupName") String groupName,
@PathVariable("deviceName") String deviceName,
@RequestParam("pageSize") Integer pageSize,
@RequestParam("pageNum") Integer pageNum,
@RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
@RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum,
@RequestParam(value = "keyword", required = false) String keyword,
HttpServletRequest request)
throws BaseException {
Expand All @@ -444,17 +481,26 @@ public BaseVO<MeasuremtnInfoVO> getMeasurementsByDeviceName(
List<MeasurementVO> measurementVOList = new ArrayList<>();
String host = connection.getHost();
if (measurementDTOList != null) {
List<String> timeseriesList = new ArrayList<>();
for (MeasurementDTO measurementDTO : measurementDTOList) {
timeseriesList.add(measurementDTO.getTimeseries());
}
List<String> batchNewValue =
iotDBService.getBatchLastMeasurementValue(connection, timeseriesList);
List<String> batchDataCount =
iotDBService.getBatchDataCount(connection, deviceName, timeseriesList);
int index = 0;
for (MeasurementDTO measurementDTO : measurementDTOList) {
MeasurementVO measurementVO = new MeasurementVO();
BeanUtils.copyProperties(measurementDTO, measurementVO);
String description =
measurementService.getDescription(host, measurementDTO.getTimeseries());
String newValue =
iotDBService.getLastMeasurementValue(connection, measurementDTO.getTimeseries());
Integer dataCount =
iotDBService.getOneDataCount(connection, deviceName, measurementDTO.getTimeseries());
measurementVO.setDataCount(dataCount);
measurementVO.setNewValue(newValue);
if (batchNewValue.size() != 0) {
measurementVO.setNewValue(batchNewValue.get(index));
}
if (batchDataCount.size() != 0) {
measurementVO.setDataCount(Integer.parseInt(batchDataCount.get(index)));
}
measurementVO.setDescription(description);
ObjectMapper mapper = new ObjectMapper();
List<List<String>> tags = new ArrayList<>();
Expand Down Expand Up @@ -488,6 +534,7 @@ public BaseVO<MeasuremtnInfoVO> getMeasurementsByDeviceName(
throw new BaseException(ErrorCode.GET_MSM_FAIL, ErrorCode.GET_MSM_FAIL_MSG);
}
measurementVOList.add(measurementVO);
index++;
}
}
MeasuremtnInfoVO measuremtnInfoVO = new MeasuremtnInfoVO();
Expand Down Expand Up @@ -1121,9 +1168,7 @@ private void check(HttpServletRequest request, Integer serverId) throws BaseExce

private void checkParameter(String groupName) throws BaseException {
String checkName = StringUtils.removeStart(groupName, "root").toLowerCase();
if (!groupName.matches("^root\\.[^ ]+$")
|| checkName.contains(".root.")
|| checkName.matches("^[^ ]*\\.root$")) {
if (groupName.contains(".root.") || groupName.contains(".root")) {
throw new BaseException(ErrorCode.NO_SUP_CONTAIN_ROOT, ErrorCode.NO_SUP_CONTAIN_ROOT_MSG);
}
if (checkName.contains(".as.")
Expand Down Expand Up @@ -1229,6 +1274,9 @@ private String getTTL(Long time) {
}

private void checkTtl(Long ttl, String unit) throws BaseException {
if (ttl == null || unit == null) {
return;
}
if (Long.MAX_VALUE / switchTime(unit) < ttl) {
throw new BaseException(ErrorCode.TTL_OVER, ErrorCode.TTL_OVER_MSG);
}
Expand Down
Loading