Search in sources :

Example 1 with StreamSourceEntity

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);
}
Also used : SourceState(org.apache.inlong.manager.common.enums.SourceState) StreamSourceEntity(org.apache.inlong.manager.dao.entity.StreamSourceEntity) Date(java.util.Date)

Example 2 with StreamSourceEntity

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);
}
Also used : SourceState(org.apache.inlong.manager.common.enums.SourceState) StreamSourceEntity(org.apache.inlong.manager.dao.entity.StreamSourceEntity) Date(java.util.Date)

Example 3 with StreamSourceEntity

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());
}
Also used : StreamSourceEntity(org.apache.inlong.manager.dao.entity.StreamSourceEntity) Date(java.util.Date)

Example 4 with StreamSourceEntity

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;
}
Also used : StreamSourceEntity(org.apache.inlong.manager.dao.entity.StreamSourceEntity) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 5 with StreamSourceEntity

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;
}
Also used : InlongGroupEntity(org.apache.inlong.manager.dao.entity.InlongGroupEntity) StreamSourceEntity(org.apache.inlong.manager.dao.entity.StreamSourceEntity) Date(java.util.Date) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

StreamSourceEntity (org.apache.inlong.manager.dao.entity.StreamSourceEntity)14 Date (java.util.Date)7 SourceState (org.apache.inlong.manager.common.enums.SourceState)4 SourceRequest (org.apache.inlong.manager.common.pojo.source.SourceRequest)4 Transactional (org.springframework.transaction.annotation.Transactional)4 InlongGroupEntity (org.apache.inlong.manager.dao.entity.InlongGroupEntity)2 Page (com.github.pagehelper.Page)1 PageHelper (com.github.pagehelper.PageHelper)1 PageInfo (com.github.pagehelper.PageInfo)1 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1 Instant (java.time.Instant)1 LocalDateTime (java.time.LocalDateTime)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 List (java.util.List)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 CollectionUtils (org.apache.commons.collections.CollectionUtils)1 StringUtils (org.apache.commons.lang3.StringUtils)1