use of org.apache.inlong.manager.dao.entity.StreamSourceEntity in project incubator-inlong by apache.
the class AbstractStreamSourceOperation method deleteOpt.
@Override
public void deleteOpt(SourceRequest request, String operator) {
Integer id = request.getId();
StreamSourceEntity existEntity = sourceMapper.selectByPrimaryKey(id);
SourceState curState = SourceState.forCode(existEntity.getStatus());
SourceState nextState = SourceState.TO_BE_ISSUED_DELETE;
if (!SourceState.isAllowedTransition(curState, nextState)) {
throw new RuntimeException(String.format("Source=%s is not allowed to delete", existEntity));
}
StreamSourceEntity curEntity = CommonBeanUtils.copyProperties(request, StreamSourceEntity::new);
curEntity.setModifyTime(new Date());
curEntity.setPreviousStatus(curState.getCode());
curEntity.setStatus(nextState.getCode());
curEntity.setIsDeleted(id);
sourceMapper.updateByPrimaryKeySelective(curEntity);
}
use of org.apache.inlong.manager.dao.entity.StreamSourceEntity in project incubator-inlong by apache.
the class AbstractStreamSourceOperation method restartOpt.
@Override
public void restartOpt(SourceRequest request, String operator) {
StreamSourceEntity snapshot = sourceMapper.selectByPrimaryKey(request.getId());
SourceState curState = SourceState.forCode(snapshot.getStatus());
SourceState nextState = SourceState.TO_BE_ISSUED_ACTIVE;
if (!SourceState.isAllowedTransition(curState, nextState)) {
throw new RuntimeException(String.format("Source=%s is not allowed to restart", snapshot));
}
StreamSourceEntity curEntity = CommonBeanUtils.copyProperties(request, StreamSourceEntity::new);
curEntity.setModifyTime(new Date());
curEntity.setPreviousStatus(curState.getCode());
curEntity.setStatus(nextState.getCode());
sourceMapper.updateByPrimaryKeySelective(curEntity);
}
use of org.apache.inlong.manager.dao.entity.StreamSourceEntity in project incubator-inlong by apache.
the class AbstractStreamSourceOperation method updateOpt.
@Override
public void updateOpt(SourceRequest request, String operator) {
StreamSourceEntity entity = sourceMapper.selectByPrimaryKey(request.getId());
Preconditions.checkNotNull(entity, ErrorCodeEnum.SOURCE_INFO_NOT_FOUND.getMessage());
if (!SourceState.ALLOWED_UPDATE.contains(entity.getStatus())) {
throw new RuntimeException(String.format("Source=%s is not allowed to update, " + "please stop / frozen / delete it firstly", entity));
}
// Setting updated parameters of stream source entity.
setTargetEntity(request, entity);
entity.setModifier(operator);
entity.setModifyTime(new Date());
sourceMapper.updateByPrimaryKeySelective(entity);
LOGGER.info("success to update source of type={}", request.getSourceType());
}
use of org.apache.inlong.manager.dao.entity.StreamSourceEntity in project incubator-inlong by apache.
the class SourceSnapshotOperation method getTaskIpAndStatusMap.
/**
* Get all tasks in a temporary state, and set up an ip-id-status map,
* the temporary state is greater than or equal to 200.
*
* @see org.apache.inlong.manager.common.enums.SourceState
*/
private ConcurrentHashMap<String, ConcurrentHashMap<Integer, Integer>> getTaskIpAndStatusMap() {
ConcurrentHashMap<String, ConcurrentHashMap<Integer, Integer>> ipTaskMap = new ConcurrentHashMap<>(16);
List<StreamSourceEntity> sourceList = sourceMapper.selectTempStatusSource();
for (StreamSourceEntity entity : sourceList) {
String ip = entity.getAgentIp();
ConcurrentHashMap<Integer, Integer> tmpMap = ipTaskMap.getOrDefault(ip, new ConcurrentHashMap<>());
tmpMap.put(entity.getId(), entity.getStatus());
ipTaskMap.put(ip, tmpMap);
}
return ipTaskMap;
}
use of org.apache.inlong.manager.dao.entity.StreamSourceEntity in project incubator-inlong by apache.
the class StreamSourceServiceImpl method logicDeleteAll.
@Override
@Transactional(rollbackFor = Throwable.class)
public boolean logicDeleteAll(String groupId, String streamId, String operator) {
LOGGER.info("begin to logic delete all source info by groupId={}, streamId={}", groupId, streamId);
Preconditions.checkNotNull(groupId, Constant.GROUP_ID_IS_EMPTY);
Preconditions.checkNotNull(streamId, Constant.STREAM_ID_IS_EMPTY);
// Check if it can be deleted
InlongGroupEntity groupEntity = commonOperateService.checkGroupStatus(groupId, operator);
Integer nextStatus;
if (GroupState.CONFIG_SUCCESSFUL.getCode().equals(groupEntity.getStatus())) {
nextStatus = SourceState.TO_BE_ISSUED_DELETE.getCode();
} else {
nextStatus = SourceState.SOURCE_DISABLE.getCode();
}
Date now = new Date();
List<StreamSourceEntity> entityList = sourceMapper.selectByRelatedId(groupId, streamId);
if (CollectionUtils.isNotEmpty(entityList)) {
for (StreamSourceEntity entity : entityList) {
Integer id = entity.getId();
entity.setPreviousStatus(entity.getStatus());
entity.setStatus(nextStatus);
entity.setIsDeleted(id);
entity.setModifier(operator);
entity.setModifyTime(now);
sourceMapper.updateByPrimaryKeySelective(entity);
}
}
LOGGER.info("success to logic delete all source by groupId={}, streamId={}", groupId, streamId);
return true;
}
Aggregations