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;
}
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
}
}
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();
}
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);
}
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();
}
Aggregations