Search in sources :

Example 6 with StreamSourceEntity

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

the class StreamSourceServiceImpl method restart.

@Override
public boolean restart(Integer id, String sourceType, String operator) {
    LOGGER.info("begin to restart source by id={}, sourceType={}", id, sourceType);
    Preconditions.checkNotNull(id, Constant.ID_IS_EMPTY);
    StreamSourceEntity entity = sourceMapper.selectByPrimaryKey(id);
    Preconditions.checkNotNull(entity, ErrorCodeEnum.SOURCE_INFO_NOT_FOUND.getMessage());
    commonOperateService.checkGroupStatus(entity.getInlongGroupId(), operator);
    StreamSourceOperation operation = operationFactory.getInstance(SourceType.forType(sourceType));
    SourceRequest sourceRequest = new SourceRequest();
    CommonBeanUtils.copyProperties(entity, sourceRequest, true);
    operation.restartOpt(sourceRequest, operator);
    LOGGER.info("success to restart source info:{}", entity);
    return true;
}
Also used : SourceRequest(org.apache.inlong.manager.common.pojo.source.SourceRequest) StreamSourceEntity(org.apache.inlong.manager.dao.entity.StreamSourceEntity)

Example 7 with StreamSourceEntity

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

the class AgentServiceImpl method updateTaskStatus.

/**
 * Update the task status by the request
 */
private void updateTaskStatus(TaskRequest request) {
    if (CollectionUtils.isEmpty(request.getCommandInfo())) {
        LOGGER.warn("task result was empty, just return");
        return;
    }
    for (CommandEntity command : request.getCommandInfo()) {
        Integer taskId = command.getTaskId();
        StreamSourceEntity current = sourceMapper.selectByPrimaryKey(taskId);
        if (current == null) {
            continue;
        }
        LocalDateTime localDateTime = LocalDateTime.parse(command.getDeliveryTime(), TIME_FORMATTER);
        Instant instant = localDateTime.atZone(ZoneId.systemDefault()).toInstant();
        if (current.getModifyTime().getTime() - instant.toEpochMilli() > maxModifyTime) {
            LOGGER.warn("task {} receive result delay more than {} ms, skip it", taskId, maxModifyTime);
            continue;
        }
        int result = command.getCommandResult();
        int previousStatus = current.getStatus();
        int nextStatus = SourceState.SOURCE_NORMAL.getCode();
        // Change the status from 30x to normal / disable / frozen
        if (previousStatus / MODULUS_100 == ISSUED_STATUS) {
            if (Constants.RESULT_SUCCESS == result) {
                if (SourceState.TEMP_TO_NORMAL.contains(previousStatus)) {
                    nextStatus = SourceState.SOURCE_NORMAL.getCode();
                } else if (SourceState.BEEN_ISSUED_DELETE.getCode() == previousStatus) {
                    nextStatus = SourceState.SOURCE_DISABLE.getCode();
                } else if (SourceState.BEEN_ISSUED_FROZEN.getCode() == previousStatus) {
                    nextStatus = SourceState.SOURCE_FROZEN.getCode();
                }
            } else if (Constants.RESULT_FAIL == result) {
                nextStatus = SourceState.SOURCE_FAILED.getCode();
            }
            sourceMapper.updateStatus(taskId, nextStatus);
        }
    // Other tasks with status 20x will change to 30x in next getTaskResult method
    }
}
Also used : LocalDateTime(java.time.LocalDateTime) Instant(java.time.Instant) StreamSourceEntity(org.apache.inlong.manager.dao.entity.StreamSourceEntity) CommandEntity(org.apache.inlong.common.db.CommandEntity)

Example 8 with StreamSourceEntity

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

the class AgentServiceImpl method getTaskResult.

/**
 * Get task result by the request
 */
@Transactional(isolation = Isolation.REPEATABLE_READ)
TaskResult getTaskResult(TaskRequest request) {
    // Query the tasks that needed to add or active - without agentIp and uuid
    List<Integer> addedStatusList = Arrays.asList(SourceState.TO_BE_ISSUED_ADD.getCode(), SourceState.TO_BE_ISSUED_ACTIVE.getCode());
    List<StreamSourceEntity> addList = sourceMapper.selectByStatusForUpdate(addedStatusList);
    // Query other tasks by agentIp and uuid - not included status with TO_BE_ISSUED_ADD and TO_BE_ISSUED_ACTIVE
    List<Integer> statusList = Arrays.asList(SourceState.TO_BE_ISSUED_DELETE.getCode(), SourceState.TO_BE_ISSUED_RETRY.getCode(), SourceState.TO_BE_ISSUED_BACKTRACK.getCode(), SourceState.TO_BE_ISSUED_FROZEN.getCode(), SourceState.TO_BE_ISSUED_CHECK.getCode(), SourceState.TO_BE_ISSUED_REDO_METRIC.getCode(), SourceState.TO_BE_ISSUED_MAKEUP.getCode());
    String agentIp = request.getAgentIp();
    String uuid = request.getUuid();
    List<StreamSourceEntity> entityList = sourceMapper.selectByStatusAndIp(statusList, agentIp, uuid);
    entityList.addAll(addList);
    List<DataConfig> dataConfigs = Lists.newArrayList();
    for (StreamSourceEntity entity : entityList) {
        // Change 20x to 30x
        int id = entity.getId();
        int status = entity.getStatus();
        int op = status % MODULUS_100;
        if (status / MODULUS_100 == UNISSUED_STATUS) {
            sourceMapper.updateStatus(id, ISSUED_STATUS * MODULUS_100 + op);
        } else {
            LOGGER.info("skip task status not in 20x, id={}", id);
            continue;
        }
        DataConfig dataConfig = getDataConfig(entity, op);
        dataConfigs.add(dataConfig);
    }
    // Query pending special commands
    List<CmdConfig> cmdConfigs = getAgentCmdConfigs(request);
    // Update agentIp and uuid for the added and active tasks
    for (StreamSourceEntity entity : addList) {
        sourceMapper.updateIpAndUuid(entity.getId(), agentIp, uuid);
    }
    return TaskResult.builder().dataConfigs(dataConfigs).cmdConfigs(cmdConfigs).build();
}
Also used : CmdConfig(org.apache.inlong.common.pojo.agent.CmdConfig) DataConfig(org.apache.inlong.common.pojo.agent.DataConfig) StreamSourceEntity(org.apache.inlong.manager.dao.entity.StreamSourceEntity) Transactional(org.springframework.transaction.annotation.Transactional)

Example 9 with StreamSourceEntity

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

the class AbstractStreamSourceOperation method stopOpt.

@Override
public void stopOpt(SourceRequest request, String operator) {
    StreamSourceEntity snapshot = sourceMapper.selectByPrimaryKey(request.getId());
    SourceState curState = SourceState.forCode(snapshot.getStatus());
    SourceState nextState = SourceState.TO_BE_ISSUED_FROZEN;
    if (!SourceState.isAllowedTransition(curState, nextState)) {
        throw new RuntimeException(String.format("Source=%s is not allowed to stop", 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 10 with StreamSourceEntity

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

the class AbstractStreamSourceOperation method saveOpt.

@Override
public Integer saveOpt(SourceRequest request, Integer groupStatus, String operator) {
    StreamSourceEntity entity = CommonBeanUtils.copyProperties(request, StreamSourceEntity::new);
    if (GroupState.forCode(groupStatus).equals(GroupState.CONFIG_SUCCESSFUL)) {
        entity.setStatus(SourceState.TO_BE_ISSUED_ADD.getCode());
    } else {
        entity.setStatus(SourceState.SOURCE_NEW.getCode());
    }
    entity.setIsDeleted(Constant.UN_DELETED);
    entity.setCreator(operator);
    entity.setModifier(operator);
    Date now = new Date();
    entity.setCreateTime(now);
    entity.setModifyTime(now);
    // get the ext params
    setTargetEntity(request, entity);
    sourceMapper.insert(entity);
    return entity.getId();
}
Also used : StreamSourceEntity(org.apache.inlong.manager.dao.entity.StreamSourceEntity) Date(java.util.Date)

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