in backend/src/main/java/org/apache/iotdb/admin/controller/IotDBController.java [183:222]
public BaseVO saveStorageGroup(
@PathVariable("serverId") Integer serverId,
@RequestBody GroupDTO groupDTO,
HttpServletRequest request)
throws BaseException {
String groupName = groupDTO.getGroupName();
checkParameter(groupName);
check(request, serverId);
Connection connection = connectionService.getById(serverId);
Long ttl = groupDTO.getTtl();
String ttlUnit = groupDTO.getTtlUnit();
Integer groupId = groupDTO.getGroupId();
groupDTO.setGroupName(groupName);
List<String> groupNames = iotDBService.getAllStorageGroups(connection);
if (groupId == null) {
if (!groupNames.contains(groupDTO.getGroupName())) {
iotDBService.saveStorageGroup(connection, groupName);
}
groupService.setStorageGroupInfo(connection, groupDTO);
} else {
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);
} else {
throw new BaseException(ErrorCode.TTL_WRONG, ErrorCode.TTL_WRONG_MSG);
}
} else {
if (ttl == null && ttlUnit == null) {
iotDBService.cancelGroupTtl(connection, groupName);
} else {
throw new BaseException(ErrorCode.WRONG_DB_PARAM, ErrorCode.WRONG_DB_PARAM_MSG);
}
}
return BaseVO.success("Upsert successfully", null);
}