|
21 | 21 | import org.apache.inlong.manager.common.enums.ErrorCodeEnum;
|
22 | 22 | import org.apache.inlong.manager.common.enums.TenantUserTypeEnum;
|
23 | 23 | import org.apache.inlong.manager.common.exceptions.BusinessException;
|
| 24 | +import org.apache.inlong.manager.common.util.CommonBeanUtils; |
24 | 25 | import org.apache.inlong.manager.common.util.Preconditions;
|
25 | 26 | import org.apache.inlong.manager.dao.entity.DataNodeEntity;
|
26 | 27 | import org.apache.inlong.manager.dao.mapper.DataNodeEntityMapper;
|
@@ -184,68 +185,35 @@ public List<DataNodeInfo> list(DataNodePageRequest request, UserInfo opInfo) {
|
184 | 185 | @Transactional(rollbackFor = Throwable.class)
|
185 | 186 | public Boolean update(DataNodeRequest request, String operator) {
|
186 | 187 | LOGGER.info("begin to update data node by id: {}", request);
|
187 |
| - // check whether record existed |
| 188 | + // check whether the record existed |
188 | 189 | DataNodeEntity curEntity = dataNodeMapper.selectById(request.getId());
|
189 | 190 | if (curEntity == null) {
|
190 | 191 | throw new BusinessException(ErrorCodeEnum.RECORD_NOT_FOUND,
|
191 | 192 | String.format("data node record not found by id=%d", request.getId()));
|
192 | 193 | }
|
193 | 194 | userService.checkUser(curEntity.getInCharges(), operator,
|
194 | 195 | "Current user does not have permission to update data node info");
|
| 196 | + |
195 | 197 | // check whether modify unmodifiable parameters
|
196 | 198 | chkUnmodifiableParams(curEntity, request);
|
197 |
| - // Check whether the data node name exists with the same name and type |
198 |
| - if (request.getName() != null) { |
199 |
| - if (StringUtils.isBlank(request.getName())) { |
200 |
| - throw new BusinessException(ErrorCodeEnum.INVALID_PARAMETER, |
201 |
| - "the name changed of data node is blank!"); |
202 |
| - } |
203 |
| - DataNodeEntity existEntity = |
204 |
| - dataNodeMapper.selectByUniqueKey(request.getName(), request.getType()); |
205 |
| - if (existEntity != null && !existEntity.getId().equals(request.getId())) { |
206 |
| - throw new BusinessException(ErrorCodeEnum.RECORD_DUPLICATE, |
207 |
| - String.format("data node already exist for name=%s, type=%s, required id=%s, exist id=%s", |
208 |
| - request.getName(), request.getType(), request.getId(), existEntity.getId())); |
209 |
| - } |
210 |
| - } |
| 199 | + |
| 200 | + // after the update operation, `curEntity` will be updated to the latest info by the MyBatis cache mechanism, |
| 201 | + // so we need to get an `oldEntity` by copying `curEntity` before the update operation. |
| 202 | + DataNodeEntity oldEntity = CommonBeanUtils.copyProperties(curEntity, DataNodeEntity::new); |
211 | 203 | DataNodeOperator dataNodeOperator = operatorFactory.getInstance(request.getType());
|
212 | 204 | dataNodeOperator.updateOpt(request, operator);
|
213 |
| - dataNodeOperator.updateRelatedStreamSource(request, curEntity, operator); |
| 205 | + |
| 206 | + // update the related stream sources if the request and old entity ha |
| 207 | + dataNodeOperator.updateRelatedStreamSource(request, oldEntity, operator); |
214 | 208 | LOGGER.info("success to update data node={}", request);
|
215 | 209 | return true;
|
216 | 210 | }
|
217 | 211 |
|
218 | 212 | @Override
|
219 | 213 | @Transactional(rollbackFor = Throwable.class)
|
220 | 214 | public Boolean update(DataNodeRequest request, UserInfo opInfo) {
|
221 |
| - // check the record existed |
222 |
| - DataNodeEntity curEntity = dataNodeMapper.selectById(request.getId()); |
223 |
| - if (curEntity == null) { |
224 |
| - throw new BusinessException(ErrorCodeEnum.RECORD_NOT_FOUND, |
225 |
| - String.format("data node record not found by id=%d", request.getId())); |
226 |
| - } |
227 |
| - userService.checkUser(curEntity.getInCharges(), opInfo.getName(), |
228 |
| - "Current user does not have permission to update data node info"); |
229 |
| - // check whether modify unmodifiable parameters |
230 |
| - chkUnmodifiableParams(curEntity, request); |
231 |
| - // Check whether the data node name exists with the same name and type |
232 |
| - if (request.getName() != null) { |
233 |
| - if (StringUtils.isBlank(request.getName())) { |
234 |
| - throw new BusinessException(ErrorCodeEnum.INVALID_PARAMETER, |
235 |
| - "the name changed of data node is blank!"); |
236 |
| - } |
237 |
| - DataNodeEntity existEntity = |
238 |
| - dataNodeMapper.selectByUniqueKey(request.getName(), request.getType()); |
239 |
| - if (existEntity != null && !existEntity.getId().equals(request.getId())) { |
240 |
| - throw new BusinessException(ErrorCodeEnum.RECORD_DUPLICATE, |
241 |
| - String.format("data node already exist for name=%s, type=%s, required id=%s, exist id=%s", |
242 |
| - request.getName(), request.getType(), request.getId(), existEntity.getId())); |
243 |
| - } |
244 |
| - } |
245 |
| - DataNodeOperator dataNodeOperator = operatorFactory.getInstance(request.getType()); |
246 |
| - dataNodeOperator.updateOpt(request, opInfo.getName()); |
247 |
| - dataNodeOperator.updateRelatedStreamSource(request, curEntity, opInfo.getName()); |
248 |
| - return true; |
| 215 | + String operator = opInfo.getName(); |
| 216 | + return this.update(request, operator); |
249 | 217 | }
|
250 | 218 |
|
251 | 219 | @Override
|
|
0 commit comments