Java Code Examples for org.apache.kylin.cube.model.CubeDesc#getCopyOf()

The following examples show how to use org.apache.kylin.cube.model.CubeDesc#getCopyOf() . 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: TableSchemaUpdater.java    From kylin with Apache License 2.0 6 votes vote down vote up
public static CubeDesc dealWithMappingForCubeDesc(CubeDesc other, Map<String, TableSchemaUpdateMapping> mappings) {
    CubeDesc copy = CubeDesc.getCopyOf(other);
    copy.setLastModified(other.getLastModified());

    // mapping for cube-level snapshot tables
    if (other.getSnapshotTableDescList() != null && !other.getSnapshotTableDescList().isEmpty()) {
        List<SnapshotTableDesc> snapshotTableDescListCopy = Lists
                .newArrayListWithExpectedSize(other.getSnapshotTableDescList().size());
        for (SnapshotTableDesc snapshotDesc : other.getSnapshotTableDescList()) {
            TableSchemaUpdateMapping mapping = getTableSchemaUpdateMapping(mappings, snapshotDesc.getTableName());
            if (mapping != null && mapping.isTableIdentityChanged()) {
                snapshotDesc = SnapshotTableDesc.getCopyOf(snapshotDesc);
                snapshotDesc.setTableName(mapping.getTableIdentity(snapshotDesc.getTableName()));
            }
            snapshotTableDescListCopy.add(snapshotDesc);
        }
        copy.setSnapshotTableDescList(snapshotTableDescListCopy);
    }

    return copy;
}
 
Example 2
Source File: CubeDescTest.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetCopyOf() throws Exception {
    CubeDesc desc = CubeDescManager.getInstance(getTestConfig()).getCubeDesc(CUBE_WITH_SLR_DESC);
    CubeDesc copyDesc = CubeDesc.getCopyOf(desc);

    // uuid is different, set to equals for json comparison
    copyDesc.setUuid(desc.getUuid());
    copyDesc.setLastModified(desc.getLastModified());

    String descStr = JsonUtil.writeValueAsIndentString(desc);
    String copyStr = JsonUtil.writeValueAsIndentString(copyDesc);

    assertEquals(descStr, copyStr);
}
 
Example 3
Source File: CubeDescTest.java    From kylin with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetCopyOf() throws Exception {
    CubeDesc desc = CubeDescManager.getInstance(getTestConfig()).getCubeDesc(CUBE_WITH_SLR_DESC);
    CubeDesc copyDesc = CubeDesc.getCopyOf(desc);

    // uuid is different, set to equals for json comparison
    copyDesc.setUuid(desc.getUuid());
    copyDesc.setLastModified(desc.getLastModified());

    String descStr = JsonUtil.writeValueAsIndentString(desc);
    String copyStr = JsonUtil.writeValueAsIndentString(copyDesc);

    assertEquals(descStr, copyStr);
}
 
Example 4
Source File: ExtendCubeToHybridCLI.java    From kylin-on-parquet-v2 with Apache License 2.0 4 votes vote down vote up
public void createFromCube(String projectName, String cubeName, String partitionDateStr) throws Exception {
    logger.info("Create hybrid for cube[" + cubeName + "], project[" + projectName + "], partition_date[" + partitionDateStr + "].");

    CubeInstance cubeInstance = cubeManager.getCube(cubeName);
    if (!validateCubeInstance(cubeInstance)) {
        return;
    }

    CubeDesc cubeDesc = cubeDescManager.getCubeDesc(cubeInstance.getDescName());
    DataModelDesc dataModelDesc = metadataManager.getDataModelDesc(cubeDesc.getModelName());
    if (StringUtils.isEmpty(dataModelDesc.getPartitionDesc().getPartitionDateColumn())) {
        logger.error("No incremental cube, no need to extend.");
        return;
    }

    String owner = cubeInstance.getOwner();
    long partitionDate = partitionDateStr != null ? DateFormat.stringToMillis(partitionDateStr) : 0;

    // get new name for old cube and cube_desc
    String newCubeDescName = renameCube(cubeDesc.getName());
    String newCubeInstanceName = renameCube(cubeInstance.getName());
    while (cubeDescManager.getCubeDesc(newCubeDescName) != null)
        newCubeDescName = renameCube(newCubeDescName);
    while (cubeManager.getCube(newCubeInstanceName) != null)
        newCubeInstanceName = renameCube(newCubeInstanceName);

    // create new cube_instance for old segments
    CubeInstance newCubeInstance = CubeInstance.getCopyOf(cubeInstance);
    newCubeInstance.setName(newCubeInstanceName);
    newCubeInstance.setDescName(newCubeDescName);
    newCubeInstance.updateRandomUuid();
    Iterator<CubeSegment> segmentIterator = newCubeInstance.getSegments().iterator();
    CubeSegment currentSeg = null;
    while (segmentIterator.hasNext()) {
        currentSeg = segmentIterator.next();
        if (partitionDateStr != null && (currentSeg.getTSRange().start.v >= partitionDate || currentSeg.getTSRange().end.v > partitionDate)) {
            segmentIterator.remove();
            logger.info("CubeSegment[" + currentSeg + "] was removed.");
        }
    }
    if (currentSeg != null && partitionDateStr != null && partitionDate != currentSeg.getTSRange().end.v) {
        logger.error("PartitionDate must be end date of one segment.");
        return;
    }
    if (currentSeg != null && partitionDateStr == null)
        partitionDate = currentSeg.getTSRange().end.v;

    cubeManager.createCube(newCubeInstance, projectName, owner);
    logger.info("CubeInstance was saved at: " + newCubeInstance.getResourcePath());

    // create new cube for old segments
    CubeDesc newCubeDesc = CubeDesc.getCopyOf(cubeDesc);
    newCubeDesc.setName(newCubeDescName);
    newCubeDesc.updateRandomUuid();
    newCubeDesc.init(kylinConfig);
    newCubeDesc.setPartitionDateEnd(partitionDate);
    newCubeDesc.calculateSignature();
    cubeDescManager.createCubeDesc(newCubeDesc);
    logger.info("CubeDesc was saved at: " + newCubeDesc.getResourcePath());

    // update old cube_desc to new-version metadata
    cubeDesc.setPartitionDateStart(partitionDate);
    cubeDesc.setEngineType(IEngineAware.ID_MR_V2);
    cubeDesc.setStorageType(IStorageAware.ID_SHARDED_HBASE);
    cubeDesc.calculateSignature();
    cubeDescManager.updateCubeDesc(cubeDesc);
    logger.info("CubeDesc was saved at: " + cubeDesc.getResourcePath());

    // clear segments for old cube
    cubeInstance.setSegments(new Segments());
    cubeInstance.setStatus(RealizationStatusEnum.DISABLED);
    store.checkAndPutResource(cubeInstance.getResourcePath(), cubeInstance, CubeManager.CUBE_SERIALIZER);
    logger.info("CubeInstance was saved at: " + cubeInstance.getResourcePath());

    // create hybrid model for these two cubes
    List<RealizationEntry> realizationEntries = Lists.newArrayListWithCapacity(2);
    realizationEntries.add(RealizationEntry.create(RealizationType.CUBE, cubeInstance.getName()));
    realizationEntries.add(RealizationEntry.create(RealizationType.CUBE, newCubeInstance.getName()));
    HybridInstance hybridInstance = HybridInstance.create(kylinConfig, renameHybrid(cubeInstance.getName()), realizationEntries);
    store.checkAndPutResource(hybridInstance.getResourcePath(), hybridInstance, HybridManager.HYBRID_SERIALIZER);
    ProjectManager.getInstance(kylinConfig).moveRealizationToProject(RealizationType.HYBRID, hybridInstance.getName(), projectName, owner);
    logger.info("HybridInstance was saved at: " + hybridInstance.getResourcePath());

    // copy Acl from old cube to new cube
    copyAcl(cubeInstance.getId(), newCubeInstance.getId(), projectName);
    logger.info("Acl copied from [" + cubeName + "] to [" + newCubeInstanceName + "].");
}
 
Example 5
Source File: ExtendCubeToHybridCLI.java    From kylin-on-parquet-v2 with Apache License 2.0 4 votes vote down vote up
public void createFromCube(String projectName, String cubeName, String partitionDateStr) throws Exception {
    logger.info("Create hybrid for cube[" + cubeName + "], project[" + projectName + "], partition_date[" + partitionDateStr + "].");

    CubeInstance cubeInstance = cubeManager.getCube(cubeName);
    if (!validateCubeInstance(cubeInstance)) {
        return;
    }

    CubeDesc cubeDesc = cubeDescManager.getCubeDesc(cubeInstance.getDescName());
    DataModelDesc dataModelDesc = metadataManager.getDataModelDesc(cubeDesc.getModelName());
    if (StringUtils.isEmpty(dataModelDesc.getPartitionDesc().getPartitionDateColumn())) {
        logger.error("No incremental cube, no need to extend.");
        return;
    }

    String owner = cubeInstance.getOwner();
    long partitionDate = partitionDateStr != null ? DateFormat.stringToMillis(partitionDateStr) : 0;

    // get new name for old cube and cube_desc
    String newCubeDescName = renameCube(cubeDesc.getName());
    String newCubeInstanceName = renameCube(cubeInstance.getName());
    while (cubeDescManager.getCubeDesc(newCubeDescName) != null)
        newCubeDescName = renameCube(newCubeDescName);
    while (cubeManager.getCube(newCubeInstanceName) != null)
        newCubeInstanceName = renameCube(newCubeInstanceName);

    // create new cube_instance for old segments
    CubeInstance newCubeInstance = CubeInstance.getCopyOf(cubeInstance);
    newCubeInstance.setName(newCubeInstanceName);
    newCubeInstance.setDescName(newCubeDescName);
    newCubeInstance.updateRandomUuid();
    Iterator<CubeSegment> segmentIterator = newCubeInstance.getSegments().iterator();
    CubeSegment currentSeg = null;
    while (segmentIterator.hasNext()) {
        currentSeg = segmentIterator.next();
        if (partitionDateStr != null && (currentSeg.getTSRange().start.v >= partitionDate || currentSeg.getTSRange().end.v > partitionDate)) {
            segmentIterator.remove();
            logger.info("CubeSegment[" + currentSeg + "] was removed.");
        }
    }
    if (partitionDateStr != null && partitionDate != currentSeg.getTSRange().end.v) {
        logger.error("PartitionDate must be end date of one segment.");
        return;
    }
    if (currentSeg != null && partitionDateStr == null)
        partitionDate = currentSeg.getTSRange().end.v;

    cubeManager.createCube(newCubeInstance, projectName, owner);
    logger.info("CubeInstance was saved at: " + newCubeInstance.getResourcePath());

    // create new cube for old segments
    CubeDesc newCubeDesc = CubeDesc.getCopyOf(cubeDesc);
    newCubeDesc.setName(newCubeDescName);
    newCubeDesc.updateRandomUuid();
    newCubeDesc.init(kylinConfig);
    newCubeDesc.setPartitionDateEnd(partitionDate);
    newCubeDesc.calculateSignature();
    cubeDescManager.createCubeDesc(newCubeDesc);
    logger.info("CubeDesc was saved at: " + newCubeDesc.getResourcePath());

    // update old cube_desc to new-version metadata
    cubeDesc.setPartitionDateStart(partitionDate);
    cubeDesc.setEngineType(IEngineAware.ID_MR_V2);
    cubeDesc.setStorageType(IStorageAware.ID_SHARDED_HBASE);
    cubeDesc.calculateSignature();
    cubeDescManager.updateCubeDesc(cubeDesc);
    logger.info("CubeDesc was saved at: " + cubeDesc.getResourcePath());

    // clear segments for old cube
    cubeInstance.setSegments(new Segments<CubeSegment>());
    cubeInstance.setStatus(RealizationStatusEnum.DISABLED);
    store.checkAndPutResource(cubeInstance.getResourcePath(), cubeInstance, CubeManager.CUBE_SERIALIZER);
    logger.info("CubeInstance was saved at: " + cubeInstance.getResourcePath());

    // create hybrid model for these two cubes
    List<RealizationEntry> realizationEntries = Lists.newArrayListWithCapacity(2);
    realizationEntries.add(RealizationEntry.create(RealizationType.CUBE, cubeInstance.getName()));
    realizationEntries.add(RealizationEntry.create(RealizationType.CUBE, newCubeInstance.getName()));
    HybridInstance hybridInstance = HybridInstance.create(kylinConfig, renameHybrid(cubeInstance.getName()), realizationEntries);
    store.checkAndPutResource(hybridInstance.getResourcePath(), hybridInstance, HybridManager.HYBRID_SERIALIZER);
    ProjectManager.getInstance(kylinConfig).moveRealizationToProject(RealizationType.HYBRID, hybridInstance.getName(), projectName, owner);
    logger.info("HybridInstance was saved at: " + hybridInstance.getResourcePath());

    // copy Acl from old cube to new cube
    copyAcl(cubeInstance.getId(), newCubeInstance.getId(), projectName);
    logger.info("Acl copied from [" + cubeName + "] to [" + newCubeInstanceName + "].");
}
 
Example 6
Source File: CubeController.java    From kylin-on-parquet-v2 with Apache License 2.0 4 votes vote down vote up
@RequestMapping(value = "/{cubeName}/clone", method = { RequestMethod.PUT }, produces = { "application/json" })
@ResponseBody
public CubeInstance cloneCube(@PathVariable String cubeName, @RequestBody CubeRequest cubeRequest) {
    String newCubeName = cubeRequest.getCubeName();
    String projectName = cubeRequest.getProject();

    checkCubeExists(cubeName);
    CubeInstance cube = cubeService.getCubeManager().getCube(cubeName);
    if (cube.getStatus() == RealizationStatusEnum.DESCBROKEN) {
        throw new BadRequestException("Broken cube can't be cloned");
    }
    if (!ValidateUtil.isAlphanumericUnderscore(newCubeName)) {
        throw new BadRequestException("Invalid Cube name, only letters, numbers and underscore supported.");
    }

    ProjectInstance project = cubeService.getProjectManager().getProject(projectName);
    if (project == null) {
        throw new NotFoundException("Project " + projectName + " doesn't exist");
    }
    // KYLIN-1925, forbid cloning cross projects
    if (!project.getName().equals(cube.getProject())) {
        throw new BadRequestException("Cloning cubes across projects is not supported.");
    }

    CubeDesc cubeDesc = cube.getDescriptor();
    CubeDesc newCubeDesc = CubeDesc.getCopyOf(cubeDesc);

    newCubeDesc.setName(newCubeName);

    CubeInstance newCube;
    try {
        newCube = cubeService.createCubeAndDesc(project, newCubeDesc);

        //reload to avoid shallow clone
        cubeService.getCubeDescManager().reloadCubeDescLocal(newCubeName);
    } catch (IOException e) {
        throw new InternalErrorException("Failed to clone cube ", e);
    }

    return newCube;

}
 
Example 7
Source File: ExtendCubeToHybridCLI.java    From kylin with Apache License 2.0 4 votes vote down vote up
public void createFromCube(String projectName, String cubeName, String partitionDateStr) throws Exception {
    logger.info("Create hybrid for cube[" + cubeName + "], project[" + projectName + "], partition_date[" + partitionDateStr + "].");

    CubeInstance cubeInstance = cubeManager.getCube(cubeName);
    if (!validateCubeInstance(cubeInstance)) {
        return;
    }

    CubeDesc cubeDesc = cubeDescManager.getCubeDesc(cubeInstance.getDescName());
    DataModelDesc dataModelDesc = metadataManager.getDataModelDesc(cubeDesc.getModelName());
    if (StringUtils.isEmpty(dataModelDesc.getPartitionDesc().getPartitionDateColumn())) {
        logger.error("No incremental cube, no need to extend.");
        return;
    }

    String owner = cubeInstance.getOwner();
    long partitionDate = partitionDateStr != null ? DateFormat.stringToMillis(partitionDateStr) : 0;

    // get new name for old cube and cube_desc
    String newCubeDescName = renameCube(cubeDesc.getName());
    String newCubeInstanceName = renameCube(cubeInstance.getName());
    while (cubeDescManager.getCubeDesc(newCubeDescName) != null)
        newCubeDescName = renameCube(newCubeDescName);
    while (cubeManager.getCube(newCubeInstanceName) != null)
        newCubeInstanceName = renameCube(newCubeInstanceName);

    // create new cube_instance for old segments
    CubeInstance newCubeInstance = CubeInstance.getCopyOf(cubeInstance);
    newCubeInstance.setName(newCubeInstanceName);
    newCubeInstance.setDescName(newCubeDescName);
    newCubeInstance.updateRandomUuid();
    Iterator<CubeSegment> segmentIterator = newCubeInstance.getSegments().iterator();
    CubeSegment currentSeg = null;
    while (segmentIterator.hasNext()) {
        currentSeg = segmentIterator.next();
        if (partitionDateStr != null && (currentSeg.getTSRange().start.v >= partitionDate || currentSeg.getTSRange().end.v > partitionDate)) {
            segmentIterator.remove();
            logger.info("CubeSegment[" + currentSeg + "] was removed.");
        }
    }
    if (currentSeg != null && partitionDateStr != null && partitionDate != currentSeg.getTSRange().end.v) {
        logger.error("PartitionDate must be end date of one segment.");
        return;
    }
    if (currentSeg != null && partitionDateStr == null)
        partitionDate = currentSeg.getTSRange().end.v;

    cubeManager.createCube(newCubeInstance, projectName, owner);
    logger.info("CubeInstance was saved at: " + newCubeInstance.getResourcePath());

    // create new cube for old segments
    CubeDesc newCubeDesc = CubeDesc.getCopyOf(cubeDesc);
    newCubeDesc.setName(newCubeDescName);
    newCubeDesc.updateRandomUuid();
    newCubeDesc.init(kylinConfig);
    newCubeDesc.setPartitionDateEnd(partitionDate);
    newCubeDesc.calculateSignature();
    cubeDescManager.createCubeDesc(newCubeDesc);
    logger.info("CubeDesc was saved at: " + newCubeDesc.getResourcePath());

    // update old cube_desc to new-version metadata
    cubeDesc.setPartitionDateStart(partitionDate);
    cubeDesc.setEngineType(IEngineAware.ID_MR_V2);
    cubeDesc.setStorageType(IStorageAware.ID_SHARDED_HBASE);
    cubeDesc.calculateSignature();
    cubeDescManager.updateCubeDesc(cubeDesc);
    logger.info("CubeDesc was saved at: " + cubeDesc.getResourcePath());

    // clear segments for old cube
    cubeInstance.setSegments(new Segments());
    cubeInstance.setStatus(RealizationStatusEnum.DISABLED);
    store.checkAndPutResource(cubeInstance.getResourcePath(), cubeInstance, CubeManager.CUBE_SERIALIZER);
    logger.info("CubeInstance was saved at: " + cubeInstance.getResourcePath());

    // create hybrid model for these two cubes
    List<RealizationEntry> realizationEntries = Lists.newArrayListWithCapacity(2);
    realizationEntries.add(RealizationEntry.create(RealizationType.CUBE, cubeInstance.getName()));
    realizationEntries.add(RealizationEntry.create(RealizationType.CUBE, newCubeInstance.getName()));
    HybridInstance hybridInstance = HybridInstance.create(kylinConfig, renameHybrid(cubeInstance.getName()), realizationEntries);
    store.checkAndPutResource(hybridInstance.getResourcePath(), hybridInstance, HybridManager.HYBRID_SERIALIZER);
    ProjectManager.getInstance(kylinConfig).moveRealizationToProject(RealizationType.HYBRID, hybridInstance.getName(), projectName, owner);
    logger.info("HybridInstance was saved at: " + hybridInstance.getResourcePath());

    // copy Acl from old cube to new cube
    copyAcl(cubeInstance.getId(), newCubeInstance.getId(), projectName);
    logger.info("Acl copied from [" + cubeName + "] to [" + newCubeInstanceName + "].");
}
 
Example 8
Source File: ExtendCubeToHybridCLI.java    From kylin with Apache License 2.0 4 votes vote down vote up
public void createFromCube(String projectName, String cubeName, String partitionDateStr) throws Exception {
    logger.info("Create hybrid for cube[" + cubeName + "], project[" + projectName + "], partition_date[" + partitionDateStr + "].");

    CubeInstance cubeInstance = cubeManager.getCube(cubeName);
    if (!validateCubeInstance(cubeInstance)) {
        return;
    }

    CubeDesc cubeDesc = cubeDescManager.getCubeDesc(cubeInstance.getDescName());
    DataModelDesc dataModelDesc = metadataManager.getDataModelDesc(cubeDesc.getModelName());
    if (StringUtils.isEmpty(dataModelDesc.getPartitionDesc().getPartitionDateColumn())) {
        logger.error("No incremental cube, no need to extend.");
        return;
    }

    String owner = cubeInstance.getOwner();
    long partitionDate = partitionDateStr != null ? DateFormat.stringToMillis(partitionDateStr) : 0;

    // get new name for old cube and cube_desc
    String newCubeDescName = renameCube(cubeDesc.getName());
    String newCubeInstanceName = renameCube(cubeInstance.getName());
    while (cubeDescManager.getCubeDesc(newCubeDescName) != null)
        newCubeDescName = renameCube(newCubeDescName);
    while (cubeManager.getCube(newCubeInstanceName) != null)
        newCubeInstanceName = renameCube(newCubeInstanceName);

    // create new cube_instance for old segments
    CubeInstance newCubeInstance = CubeInstance.getCopyOf(cubeInstance);
    newCubeInstance.setName(newCubeInstanceName);
    newCubeInstance.setDescName(newCubeDescName);
    newCubeInstance.updateRandomUuid();
    Iterator<CubeSegment> segmentIterator = newCubeInstance.getSegments().iterator();
    CubeSegment currentSeg = null;
    while (segmentIterator.hasNext()) {
        currentSeg = segmentIterator.next();
        if (partitionDateStr != null && (currentSeg.getTSRange().start.v >= partitionDate || currentSeg.getTSRange().end.v > partitionDate)) {
            segmentIterator.remove();
            logger.info("CubeSegment[" + currentSeg + "] was removed.");
        }
    }
    if (partitionDateStr != null && partitionDate != currentSeg.getTSRange().end.v) {
        logger.error("PartitionDate must be end date of one segment.");
        return;
    }
    if (currentSeg != null && partitionDateStr == null)
        partitionDate = currentSeg.getTSRange().end.v;

    cubeManager.createCube(newCubeInstance, projectName, owner);
    logger.info("CubeInstance was saved at: " + newCubeInstance.getResourcePath());

    // create new cube for old segments
    CubeDesc newCubeDesc = CubeDesc.getCopyOf(cubeDesc);
    newCubeDesc.setName(newCubeDescName);
    newCubeDesc.updateRandomUuid();
    newCubeDesc.init(kylinConfig);
    newCubeDesc.setPartitionDateEnd(partitionDate);
    newCubeDesc.calculateSignature();
    cubeDescManager.createCubeDesc(newCubeDesc);
    logger.info("CubeDesc was saved at: " + newCubeDesc.getResourcePath());

    // update old cube_desc to new-version metadata
    cubeDesc.setPartitionDateStart(partitionDate);
    cubeDesc.setEngineType(IEngineAware.ID_MR_V2);
    cubeDesc.setStorageType(IStorageAware.ID_SHARDED_HBASE);
    cubeDesc.calculateSignature();
    cubeDescManager.updateCubeDesc(cubeDesc);
    logger.info("CubeDesc was saved at: " + cubeDesc.getResourcePath());

    // clear segments for old cube
    cubeInstance.setSegments(new Segments<CubeSegment>());
    cubeInstance.setStatus(RealizationStatusEnum.DISABLED);
    store.checkAndPutResource(cubeInstance.getResourcePath(), cubeInstance, CubeManager.CUBE_SERIALIZER);
    logger.info("CubeInstance was saved at: " + cubeInstance.getResourcePath());

    // create hybrid model for these two cubes
    List<RealizationEntry> realizationEntries = Lists.newArrayListWithCapacity(2);
    realizationEntries.add(RealizationEntry.create(RealizationType.CUBE, cubeInstance.getName()));
    realizationEntries.add(RealizationEntry.create(RealizationType.CUBE, newCubeInstance.getName()));
    HybridInstance hybridInstance = HybridInstance.create(kylinConfig, renameHybrid(cubeInstance.getName()), realizationEntries);
    store.checkAndPutResource(hybridInstance.getResourcePath(), hybridInstance, HybridManager.HYBRID_SERIALIZER);
    ProjectManager.getInstance(kylinConfig).moveRealizationToProject(RealizationType.HYBRID, hybridInstance.getName(), projectName, owner);
    logger.info("HybridInstance was saved at: " + hybridInstance.getResourcePath());

    // copy Acl from old cube to new cube
    copyAcl(cubeInstance.getId(), newCubeInstance.getId(), projectName);
    logger.info("Acl copied from [" + cubeName + "] to [" + newCubeInstanceName + "].");
}
 
Example 9
Source File: CubeController.java    From kylin with Apache License 2.0 4 votes vote down vote up
@RequestMapping(value = "/{cubeName}/clone", method = { RequestMethod.PUT }, produces = { "application/json" })
@ResponseBody
public CubeInstance cloneCube(@PathVariable String cubeName, @RequestBody CubeRequest cubeRequest) {
    String newCubeName = cubeRequest.getCubeName();
    String projectName = cubeRequest.getProject();

    checkCubeExists(cubeName);
    CubeInstance cube = cubeService.getCubeManager().getCube(cubeName);
    if (cube.getStatus() == RealizationStatusEnum.DESCBROKEN) {
        throw new BadRequestException("Broken cube can't be cloned");
    }
    if (!ValidateUtil.isAlphanumericUnderscore(newCubeName)) {
        throw new BadRequestException("Invalid Cube name, only letters, numbers and underscore supported.");
    }

    ProjectInstance project = cubeService.getProjectManager().getProject(projectName);
    if (project == null) {
        throw new NotFoundException("Project " + projectName + " doesn't exist");
    }
    // KYLIN-1925, forbid cloning cross projects
    if (!project.getName().equals(cube.getProject())) {
        throw new BadRequestException("Cloning cubes across projects is not supported.");
    }

    CubeDesc cubeDesc = cube.getDescriptor();
    CubeDesc newCubeDesc = CubeDesc.getCopyOf(cubeDesc);

    newCubeDesc.setName(newCubeName);

    CubeInstance newCube;
    try {
        newCube = cubeService.createCubeAndDesc(project, newCubeDesc);

        //reload to avoid shallow clone
        cubeService.getCubeDescManager().reloadCubeDescLocal(newCubeName);
    } catch (IOException e) {
        throw new InternalErrorException("Failed to clone cube ", e);
    }

    return newCube;

}