Java Code Examples for org.apache.kylin.cube.CubeInstance#getBuildingSegments()

The following examples show how to use org.apache.kylin.cube.CubeInstance#getBuildingSegments() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JobService.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
private void checkAllowOptimization(CubeInstance cube, Set<Long> cuboidsRecommend) {
    Segments<CubeSegment> buildingSegments = cube.getBuildingSegments();
    if (buildingSegments.size() > 0) {
        throw new BadRequestException("The cube " + cube.getName() + " has building segments " + buildingSegments
                + ". It's not allowed for optimization");
    }
    long baseCuboid = cube.getCuboidScheduler().getBaseCuboidId();
    if (!cuboidsRecommend.contains(baseCuboid)) {
        throw new BadRequestException("The recommend cuboids should contain the base cuboid " + baseCuboid);
    }
    Set<Long> currentCuboidSet = cube.getCuboidScheduler().getAllCuboidIds();
    if (currentCuboidSet.equals(cuboidsRecommend)) {
        throw new BadRequestException(
                "The recommend cuboids are the same as the current cuboids. It's no need to do optimization.");
    }
}
 
Example 2
Source File: JobService.java    From kylin with Apache License 2.0 6 votes vote down vote up
private void checkAllowOptimization(CubeInstance cube, Set<Long> cuboidsRecommend) {
    Segments<CubeSegment> buildingSegments = cube.getBuildingSegments();
    if (buildingSegments.size() > 0) {
        throw new BadRequestException("The cube " + cube.getName() + " has building segments " + buildingSegments
                + ". It's not allowed for optimization");
    }
    long baseCuboid = cube.getCuboidScheduler().getBaseCuboidId();
    if (!cuboidsRecommend.contains(baseCuboid)) {
        throw new BadRequestException("The recommend cuboids should contain the base cuboid " + baseCuboid);
    }
    Set<Long> currentCuboidSet = cube.getCuboidScheduler().getAllCuboidIds();
    if (currentCuboidSet.equals(cuboidsRecommend)) {
        throw new BadRequestException(
                "The recommend cuboids are the same as the current cuboids. It's no need to do optimization.");
    }
}
 
Example 3
Source File: CubeService.java    From kylin-on-parquet-v2 with Apache License 2.0 4 votes vote down vote up
/**
 * Update a cube status from ready to disabled.
 *
 * @return
 * @throws IOException
 * @throws JobException
 */
public CubeInstance disableCube(CubeInstance cube) throws IOException {
    aclEvaluate.checkProjectWritePermission(cube);
    Message msg = MsgPicker.getMsg();

    String cubeName = cube.getName();

    RealizationStatusEnum ostatus = cube.getStatus();
    if (null != ostatus && !RealizationStatusEnum.READY.equals(ostatus)) {
        throw new BadRequestException(
                String.format(Locale.ROOT, msg.getDISABLE_NOT_READY_CUBE(), cubeName, ostatus));
    }

    boolean isStreamingCube = cube.getDescriptor().isStreamingCube();

    boolean cubeStatusUpdated = false;
    try {
        CubeInstance cubeInstance = getCubeManager().updateCubeStatus(cube, RealizationStatusEnum.DISABLED);
        cubeStatusUpdated = true;
        // for streaming cube.
        if (isStreamingCube) {
            //drop not ready segments
            CubeSegment[] buildingSegments = new CubeSegment[cubeInstance.getBuildingSegments().size()];
            Segments segments = cubeInstance.getBuildingSegments();
            if (!CollectionUtils.isEmpty(segments)) {
                for (int i = 0; i < segments.size(); i++) {
                    buildingSegments[i] = (CubeSegment) segments.get(i);
                }
                getCubeManager().dropOptmizingSegments(cubeInstance, buildingSegments);
            }
            //unAssign cube
            getStreamingCoordinator().unAssignCube(cubeName);

            //discard jobs
            releaseAllJobs(cubeInstance);

        }
        return cubeInstance;
    } catch (Exception e) {
        cube.setStatus(ostatus);
        // roll back if cube status updated
        if (cubeStatusUpdated) {
            logger.info("roll back cube status to:{}", ostatus);
            getCubeManager().updateCubeStatus(cube, ostatus);
        }
        throw e;
    }
}
 
Example 4
Source File: CubeService.java    From kylin with Apache License 2.0 4 votes vote down vote up
/**
 * Update a cube status from ready to disabled.
 *
 * @return
 * @throws IOException
 * @throws JobException
 */
public CubeInstance disableCube(CubeInstance cube) throws IOException {
    aclEvaluate.checkProjectWritePermission(cube);
    Message msg = MsgPicker.getMsg();

    String cubeName = cube.getName();

    RealizationStatusEnum ostatus = cube.getStatus();
    if (null != ostatus && !RealizationStatusEnum.READY.equals(ostatus)) {
        throw new BadRequestException(
                String.format(Locale.ROOT, msg.getDISABLE_NOT_READY_CUBE(), cubeName, ostatus));
    }

    boolean isStreamingCube = cube.getDescriptor().isStreamingCube();

    boolean cubeStatusUpdated = false;
    try {
        CubeInstance cubeInstance = getCubeManager().updateCubeStatus(cube, RealizationStatusEnum.DISABLED);
        cubeStatusUpdated = true;
        // for streaming cube.
        if (isStreamingCube) {
            //drop not ready segments
            CubeSegment[] buildingSegments = new CubeSegment[cubeInstance.getBuildingSegments().size()];
            Segments segments = cubeInstance.getBuildingSegments();
            if (!CollectionUtils.isEmpty(segments)) {
                for (int i = 0; i < segments.size(); i++) {
                    buildingSegments[i] = (CubeSegment) segments.get(i);
                }
                getCubeManager().dropOptmizingSegments(cubeInstance, buildingSegments);
            }
            //unAssign cube
            getStreamingCoordinator().unAssignCube(cubeName);

            //discard jobs
            releaseAllJobs(cubeInstance);

        }
        return cubeInstance;
    } catch (Exception e) {
        cube.setStatus(ostatus);
        // roll back if cube status updated
        if (cubeStatusUpdated) {
            logger.info("roll back cube status to:{}", ostatus);
            getCubeManager().updateCubeStatus(cube, ostatus);
        }
        throw e;
    }
}