Search in sources :

Example 1 with SourceFileDetailEntity

use of org.apache.inlong.manager.dao.entity.SourceFileDetailEntity in project incubator-inlong by apache.

the class AgentServiceImpl method dealCommandResult.

@Deprecated
private void dealCommandResult(FileAgentCommandInfo info) {
    if (CollectionUtils.isEmpty(info.getCommandInfo())) {
        LOGGER.warn("command info is empty, just return");
        return;
    }
    for (CommandInfoBean command : info.getCommandInfo()) {
        SourceFileDetailEntity current = fileDetailMapper.selectByPrimaryKey(command.getTaskId());
        if (current == null) {
            continue;
        }
        int op = command.getOp();
        if (op == 2 || op == 6 || op == 8) {
            // Channel results issued by special orders
            DataSourceCmdConfigEntity cmd = new DataSourceCmdConfigEntity();
            if (command.getId() > 0) {
                // Modify the data result status of special commands
                cmd.setId(command.getId());
                cmd.setBsend(true);
                cmd.setModifyTime(new Date());
                cmd.setResultInfo(String.valueOf(command.getCommandResult()));
                sourceCmdConfigMapper.updateByPrimaryKeySelective(cmd);
            }
        } else {
            // Modify the result status of the data collection task
            if (current.getModifyTime().getTime() - command.getDeliveryTime().getTime() > 1000 * 5) {
                LOGGER.warn(" task id {} receive heartbeat time delay more than 5's, skip it!", command.getTaskId());
                continue;
            }
            int result = command.getCommandResult();
            int nextStatus = EntityStatus.AGENT_NORMAL.getCode();
            int previousStatus = current.getStatus();
            if (previousStatus / 100 == 2) {
                // Modify 30x -> 10x
                if (result == 0) {
                    // Processed successfully
                    if (previousStatus == EntityStatus.AGENT_ADD.getCode()) {
                        nextStatus = EntityStatus.AGENT_NORMAL.getCode();
                    } else if (previousStatus == EntityStatus.AGENT_DELETE.getCode()) {
                        nextStatus = EntityStatus.AGENT_DISABLE.getCode();
                    }
                } else if (result == 1) {
                    // Processing failed
                    nextStatus = EntityStatus.AGENT_FAILURE.getCode();
                }
                SourceFileDetailEntity update = new SourceFileDetailEntity();
                update.setId(command.getTaskId());
                update.setStatus(nextStatus);
                update.setPreviousStatus(previousStatus);
                fileDetailMapper.updateByPrimaryKeySelective(update);
            }
        }
    }
}
Also used : DataSourceCmdConfigEntity(org.apache.inlong.manager.dao.entity.DataSourceCmdConfigEntity) CommandInfoBean(org.apache.inlong.manager.common.pojo.agent.FileAgentCommandInfo.CommandInfoBean) SourceFileDetailEntity(org.apache.inlong.manager.dao.entity.SourceFileDetailEntity) Date(java.util.Date)

Example 2 with SourceFileDetailEntity

use of org.apache.inlong.manager.dao.entity.SourceFileDetailEntity in project incubator-inlong by apache.

the class SourceFileServiceImpl method saveDetail.

@Override
public Integer saveDetail(SourceFileDetailInfo detailInfo, String operator) {
    LOGGER.info("begin to save file data source detail={}", detailInfo);
    Preconditions.checkNotNull(detailInfo, "file data source detail is empty");
    Preconditions.checkNotNull(detailInfo.getInlongGroupId(), Constant.GROUP_ID_IS_EMPTY);
    Preconditions.checkNotNull(detailInfo.getInlongStreamId(), Constant.STREAM_ID_IS_EMPTY);
    // Check if it can be added
    InlongGroupEntity inlongGroupEntity = this.checkGroupIsTempStatus(detailInfo.getInlongGroupId());
    // If there are data sources under the same groupId, streamId, ip, username, the addition fails
    String groupId = detailInfo.getInlongGroupId();
    String streamId = detailInfo.getInlongStreamId();
    String ip = detailInfo.getIp();
    String username = detailInfo.getUsername();
    Integer count = fileDetailMapper.selectDetailExist(groupId, streamId, ip, username);
    if (count > 0) {
        LOGGER.error("file data source already exists: groupId=" + groupId + ", streamId=" + streamId + ", ip=" + ip + ", username=" + username);
        throw new BusinessException(ErrorCodeEnum.SOURCE_DUPLICATE);
    }
    detailInfo.setStatus(EntityStatus.AGENT_ADD.getCode());
    SourceFileDetailEntity detailEntity = CommonBeanUtils.copyProperties(detailInfo, SourceFileDetailEntity::new);
    detailEntity.setCreator(operator);
    detailEntity.setModifier(operator);
    Date now = new Date();
    detailEntity.setCreateTime(now);
    detailEntity.setModifyTime(now);
    fileDetailMapper.insertSelective(detailEntity);
    LOGGER.info("success to save file data source detail");
    return detailEntity.getId();
}
Also used : InlongGroupEntity(org.apache.inlong.manager.dao.entity.InlongGroupEntity) BusinessException(org.apache.inlong.manager.common.exceptions.BusinessException) SourceFileDetailEntity(org.apache.inlong.manager.dao.entity.SourceFileDetailEntity) Date(java.util.Date)

Example 3 with SourceFileDetailEntity

use of org.apache.inlong.manager.dao.entity.SourceFileDetailEntity in project incubator-inlong by apache.

the class SourceFileServiceImpl method logicDeleteBasic.

@Transactional(rollbackFor = Throwable.class)
@Override
public boolean logicDeleteBasic(Integer id, String operator) {
    LOGGER.info("begin to delete file data source basic, id={}", id);
    Preconditions.checkNotNull(id, "file data source basic's id is null");
    SourceFileBasicEntity entity = fileBasicMapper.selectByPrimaryKey(id);
    if (entity == null) {
        LOGGER.error("file data source basic not found by id={}, delete failed", id);
        throw new BusinessException(ErrorCodeEnum.SOURCE_BASIC_NOT_FOUND);
    }
    String groupId = entity.getInlongGroupId();
    String streamId = entity.getInlongStreamId();
    // Check if it can be deleted
    this.checkGroupIsTempStatus(groupId);
    // If there are related data source details, it is not allowed to delete
    List<SourceFileDetailEntity> detailEntities = fileDetailMapper.selectByIdentifier(groupId, streamId);
    if (CollectionUtils.isNotEmpty(detailEntities)) {
        LOGGER.error("the data source basic have [{}] details, delete failed", detailEntities.size());
        throw new BusinessException(ErrorCodeEnum.SOURCE_BASIC_DELETE_HAS_DETAIL);
    }
    entity.setIsDeleted(1);
    entity.setModifier(operator);
    int resultCount = fileBasicMapper.updateByPrimaryKey(entity);
    LOGGER.info("success to delete file data source basic");
    return resultCount >= 0;
}
Also used : SourceFileBasicEntity(org.apache.inlong.manager.dao.entity.SourceFileBasicEntity) BusinessException(org.apache.inlong.manager.common.exceptions.BusinessException) SourceFileDetailEntity(org.apache.inlong.manager.dao.entity.SourceFileDetailEntity) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with SourceFileDetailEntity

use of org.apache.inlong.manager.dao.entity.SourceFileDetailEntity in project incubator-inlong by apache.

the class SourceFileServiceImpl method logicDeleteDetail.

@Transactional(rollbackFor = Throwable.class)
@Override
public boolean logicDeleteDetail(Integer id, String operator) {
    LOGGER.info("begin to delete file data source detail, id={}", id);
    Preconditions.checkNotNull(id, "file data source detail's id is null");
    SourceFileDetailEntity entity = fileDetailMapper.selectByPrimaryKey(id);
    if (entity == null) {
        LOGGER.error("file data source detail not found by id={}", id);
        throw new BusinessException(ErrorCodeEnum.SOURCE_DETAIL_NOT_FOUND);
    }
    // Check if it can be deleted
    InlongGroupEntity bizEntity = this.checkGroupIsTempStatus(entity.getInlongGroupId());
    // After the approval is passed, the status needs to be modified to delete to be issued: 204
    if (EntityStatus.GROUP_CONFIG_SUCCESSFUL.getCode().equals(bizEntity.getStatus())) {
        entity.setPreviousStatus(entity.getStatus());
        entity.setStatus(EntityStatus.AGENT_DELETE.getCode());
    } else {
        entity.setPreviousStatus(entity.getStatus());
        entity.setStatus(EntityStatus.AGENT_DISABLE.getCode());
    }
    entity.setIsDeleted(EntityStatus.IS_DELETED.getCode());
    entity.setModifier(operator);
    int resultCount = fileDetailMapper.updateByPrimaryKey(entity);
    LOGGER.info("success to delete file data source detail");
    return resultCount >= 0;
}
Also used : BusinessException(org.apache.inlong.manager.common.exceptions.BusinessException) InlongGroupEntity(org.apache.inlong.manager.dao.entity.InlongGroupEntity) SourceFileDetailEntity(org.apache.inlong.manager.dao.entity.SourceFileDetailEntity) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with SourceFileDetailEntity

use of org.apache.inlong.manager.dao.entity.SourceFileDetailEntity in project incubator-inlong by apache.

the class SourceFileServiceImpl method getDetailById.

@Override
public SourceFileDetailInfo getDetailById(Integer id) {
    LOGGER.info("begin to get file data source detail by id={}", id);
    Preconditions.checkNotNull(id, "file data source detail's id is null");
    SourceFileDetailEntity entity = fileDetailMapper.selectByPrimaryKey(id);
    if (entity == null) {
        LOGGER.error("file data source detail not found by id={}", id);
        throw new BusinessException(ErrorCodeEnum.SOURCE_DETAIL_NOT_FOUND);
    }
    SourceFileDetailInfo detailInfo = CommonBeanUtils.copyProperties(entity, SourceFileDetailInfo::new);
    LOGGER.info("success to get file data source detail");
    return detailInfo;
}
Also used : BusinessException(org.apache.inlong.manager.common.exceptions.BusinessException) SourceFileDetailEntity(org.apache.inlong.manager.dao.entity.SourceFileDetailEntity) SourceFileDetailInfo(org.apache.inlong.manager.common.pojo.source.SourceFileDetailInfo)

Aggregations

SourceFileDetailEntity (org.apache.inlong.manager.dao.entity.SourceFileDetailEntity)6 BusinessException (org.apache.inlong.manager.common.exceptions.BusinessException)5 Date (java.util.Date)3 Transactional (org.springframework.transaction.annotation.Transactional)3 InlongGroupEntity (org.apache.inlong.manager.dao.entity.InlongGroupEntity)2 CommandInfoBean (org.apache.inlong.manager.common.pojo.agent.FileAgentCommandInfo.CommandInfoBean)1 SourceFileDetailInfo (org.apache.inlong.manager.common.pojo.source.SourceFileDetailInfo)1 DataSourceCmdConfigEntity (org.apache.inlong.manager.dao.entity.DataSourceCmdConfigEntity)1 SourceFileBasicEntity (org.apache.inlong.manager.dao.entity.SourceFileBasicEntity)1