Search in sources :

Example 11 with StreamSourceEntity

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

the class AbstractStreamSourceOperation method getById.

@Override
public SourceResponse getById(@NotNull Integer id) {
    StreamSourceEntity entity = sourceMapper.selectByPrimaryKey(id);
    Preconditions.checkNotNull(entity, ErrorCodeEnum.SOURCE_INFO_NOT_FOUND.getMessage());
    String existType = entity.getSourceType();
    Preconditions.checkTrue(getSourceType().equals(existType), String.format(Constant.SOURCE_TYPE_NOT_SAME, getSourceType(), existType));
    return this.getFromEntity(entity, this::getResponse);
}
Also used : StreamSourceEntity(org.apache.inlong.manager.dao.entity.StreamSourceEntity)

Example 12 with StreamSourceEntity

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

the class StreamSourceServiceImpl method listByCondition.

@Override
public PageInfo<? extends SourceListResponse> listByCondition(SourcePageRequest request) {
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("begin to list source page by " + request);
    }
    Preconditions.checkNotNull(request.getInlongGroupId(), Constant.GROUP_ID_IS_EMPTY);
    PageHelper.startPage(request.getPageNum(), request.getPageSize());
    List<StreamSourceEntity> entityPage = sourceMapper.selectByCondition(request);
    // Encapsulate the paging query results into the PageInfo object to obtain related paging information
    Map<SourceType, Page<StreamSourceEntity>> sourceMap = Maps.newHashMap();
    for (StreamSourceEntity streamSource : entityPage) {
        SourceType sourceType = SourceType.forType(streamSource.getSourceType());
        sourceMap.computeIfAbsent(sourceType, k -> new Page<>()).add(streamSource);
    }
    List<SourceListResponse> sourceListResponses = Lists.newArrayList();
    for (Map.Entry<SourceType, Page<StreamSourceEntity>> entry : sourceMap.entrySet()) {
        SourceType sourceType = entry.getKey();
        StreamSourceOperation operation = operationFactory.getInstance(sourceType);
        PageInfo<? extends SourceListResponse> pageInfo = operation.getPageInfo(entry.getValue());
        sourceListResponses.addAll(pageInfo.getList());
    }
    PageInfo<? extends SourceListResponse> pageInfo = PageInfo.of(sourceListResponses);
    LOGGER.debug("success to list source page");
    return pageInfo;
}
Also used : Date(java.util.Date) LoggerFactory(org.slf4j.LoggerFactory) StreamSourceEntityMapper(org.apache.inlong.manager.dao.mapper.StreamSourceEntityMapper) Autowired(org.springframework.beans.factory.annotation.Autowired) StringUtils(org.apache.commons.lang3.StringUtils) SourceType(org.apache.inlong.manager.common.enums.SourceType) ArrayList(java.util.ArrayList) Lists(com.google.common.collect.Lists) Preconditions(org.apache.inlong.manager.common.util.Preconditions) CollectionUtils(org.apache.commons.collections.CollectionUtils) CommonOperateService(org.apache.inlong.manager.service.CommonOperateService) Service(org.springframework.stereotype.Service) Map(java.util.Map) SourceState(org.apache.inlong.manager.common.enums.SourceState) GroupState(org.apache.inlong.manager.common.enums.GroupState) Logger(org.slf4j.Logger) PageHelper(com.github.pagehelper.PageHelper) PageInfo(com.github.pagehelper.PageInfo) SourceRequest(org.apache.inlong.manager.common.pojo.source.SourceRequest) Maps(com.google.common.collect.Maps) SourceResponse(org.apache.inlong.manager.common.pojo.source.SourceResponse) ErrorCodeEnum(org.apache.inlong.manager.common.enums.ErrorCodeEnum) Constant(org.apache.inlong.manager.common.enums.Constant) SourceListResponse(org.apache.inlong.manager.common.pojo.source.SourceListResponse) List(java.util.List) InlongGroupEntity(org.apache.inlong.manager.dao.entity.InlongGroupEntity) Page(com.github.pagehelper.Page) SourcePageRequest(org.apache.inlong.manager.common.pojo.source.SourcePageRequest) StreamSourceEntity(org.apache.inlong.manager.dao.entity.StreamSourceEntity) CommonBeanUtils(org.apache.inlong.manager.common.util.CommonBeanUtils) Collections(java.util.Collections) Transactional(org.springframework.transaction.annotation.Transactional) SourceType(org.apache.inlong.manager.common.enums.SourceType) StreamSourceEntity(org.apache.inlong.manager.dao.entity.StreamSourceEntity) Page(com.github.pagehelper.Page) Map(java.util.Map) SourceListResponse(org.apache.inlong.manager.common.pojo.source.SourceListResponse)

Example 13 with StreamSourceEntity

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

the class StreamSourceServiceImpl method stop.

@Override
public boolean stop(Integer id, String sourceType, String operator) {
    LOGGER.info("begin to stop source by id={}, sourceType={}", id, sourceType);
    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.stopOpt(sourceRequest, operator);
    LOGGER.info("success to stop 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 14 with StreamSourceEntity

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

the class StreamSourceServiceImpl method delete.

@Override
@Transactional(rollbackFor = Throwable.class)
public boolean delete(Integer id, String sourceType, String operator) {
    LOGGER.info("begin to delete 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.deleteOpt(sourceRequest, operator);
    LOGGER.info("success to delete source info:{}", entity);
    return true;
}
Also used : SourceRequest(org.apache.inlong.manager.common.pojo.source.SourceRequest) StreamSourceEntity(org.apache.inlong.manager.dao.entity.StreamSourceEntity) 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