Java Code Examples for org.apache.kylin.metadata.project.ProjectInstance#getRealizationEntries()

The following examples show how to use org.apache.kylin.metadata.project.ProjectInstance#getRealizationEntries() . 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: DeployCoprocessorCLI.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
private static List<String> filterByProjects(List<String> allTableNames, List<String> projectNames) {
    ProjectManager projectManager = ProjectManager.getInstance(KylinConfig.getInstanceFromEnv());
    CubeManager cubeManager = CubeManager.getInstance(KylinConfig.getInstanceFromEnv());

    List<String> result = Lists.newArrayList();
    for (String p : projectNames) {
        p = p.trim();
        if (p.endsWith(",")) {
            p = p.substring(0, p.length() - 1);
        }

        ProjectInstance projectInstance = projectManager.getProject(p);
        List<RealizationEntry> cubeList = projectInstance.getRealizationEntries(RealizationType.CUBE);
        for (RealizationEntry cube : cubeList) {
            CubeInstance cubeInstance = cubeManager.getCube(cube.getRealization());
            for (CubeSegment segment : cubeInstance.getSegments()) {
                String tableName = segment.getStorageLocationIdentifier();
                if (allTableNames.contains(tableName)) {
                    result.add(tableName);
                }
            }
        }
    }
    return result;
}
 
Example 2
Source File: CubeService.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
public List<CubeInstance> listAllCubes(String projectName) {
    ProjectManager projectManager = getProjectManager();
    ProjectInstance project = projectManager.getProject(projectName);
    if (project == null) {
        return Collections.emptyList();
    }
    ArrayList<CubeInstance> result = new ArrayList<CubeInstance>();
    for (RealizationEntry projectDataModel : project.getRealizationEntries()) {
        if (projectDataModel.getType() == RealizationType.CUBE) {
            CubeInstance cube = getCubeManager().getCube(projectDataModel.getRealization());
            if (cube != null)
                result.add(cube);
            else
                logger.error("Cube instance " + projectDataModel.getRealization() + " is failed to load");
        }
    }
    return result;
}
 
Example 3
Source File: CubeService.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
protected boolean isCubeInProject(String projectName, CubeInstance target) {
    ProjectManager projectManager = getProjectManager();
    ProjectInstance project = projectManager.getProject(projectName);
    if (project == null) {
        return false;
    }
    for (RealizationEntry projectDataModel : project.getRealizationEntries()) {
        if (projectDataModel.getType() == RealizationType.CUBE) {
            CubeInstance cube = getCubeManager().getCube(projectDataModel.getRealization());
            if (cube == null) {
                logger.error("Project " + projectName + " contains realization " + projectDataModel.getRealization()
                        + " which is not found by CubeManager");
                continue;
            }
            if (cube.equals(target)) {
                return true;
            }
        }
    }
    return false;
}
 
Example 4
Source File: DeployCoprocessorCLI.java    From kylin with Apache License 2.0 6 votes vote down vote up
private static List<String> filterByProjects(List<String> allTableNames, List<String> projectNames) {
    ProjectManager projectManager = ProjectManager.getInstance(KylinConfig.getInstanceFromEnv());
    CubeManager cubeManager = CubeManager.getInstance(KylinConfig.getInstanceFromEnv());

    List<String> result = Lists.newArrayList();
    for (String p : projectNames) {
        p = p.trim();
        if (p.endsWith(",")) {
            p = p.substring(0, p.length() - 1);
        }

        ProjectInstance projectInstance = projectManager.getProject(p);
        List<RealizationEntry> cubeList = projectInstance.getRealizationEntries(RealizationType.CUBE);
        for (RealizationEntry cube : cubeList) {
            CubeInstance cubeInstance = cubeManager.getCube(cube.getRealization());
            for (CubeSegment segment : cubeInstance.getSegments()) {
                String tableName = segment.getStorageLocationIdentifier();
                if (allTableNames.contains(tableName)) {
                    result.add(tableName);
                }
            }
        }
    }
    return result;
}
 
Example 5
Source File: CubeService.java    From kylin with Apache License 2.0 6 votes vote down vote up
public List<CubeInstance> listAllCubes(String projectName) {
    ProjectManager projectManager = getProjectManager();
    ProjectInstance project = projectManager.getProject(projectName);
    if (project == null) {
        return Collections.emptyList();
    }
    ArrayList<CubeInstance> result = new ArrayList<CubeInstance>();
    for (RealizationEntry projectDataModel : project.getRealizationEntries()) {
        if (projectDataModel.getType() == RealizationType.CUBE) {
            CubeInstance cube = getCubeManager().getCube(projectDataModel.getRealization());
            if (cube != null)
                result.add(cube);
            else
                logger.error("Cube instance " + projectDataModel.getRealization() + " is failed to load");
        }
    }
    return result;
}
 
Example 6
Source File: CubeService.java    From kylin with Apache License 2.0 6 votes vote down vote up
protected boolean isCubeInProject(String projectName, CubeInstance target) {
    ProjectManager projectManager = getProjectManager();
    ProjectInstance project = projectManager.getProject(projectName);
    if (project == null) {
        return false;
    }
    for (RealizationEntry projectDataModel : project.getRealizationEntries()) {
        if (projectDataModel.getType() == RealizationType.CUBE) {
            CubeInstance cube = getCubeManager().getCube(projectDataModel.getRealization());
            if (cube == null) {
                logger.error("Project " + projectName + " contains realization " + projectDataModel.getRealization()
                        + " which is not found by CubeManager");
                continue;
            }
            if (cube.equals(target)) {
                return true;
            }
        }
    }
    return false;
}
 
Example 7
Source File: HBaseUsageExtractor.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
@Override
protected void executeExtract(OptionsHelper optionsHelper, File exportDir) throws Exception {
    if (cachedHMasterUrl == null) {
        return;
    }
    kylinConfig = KylinConfig.getInstanceFromEnv();
    cubeManager = CubeManager.getInstance(kylinConfig);
    realizationRegistry = RealizationRegistry.getInstance(kylinConfig);
    projectManager = ProjectManager.getInstance(kylinConfig);

    if (optionsHelper.hasOption(OPTION_PROJECT)) {
        String projectNames = optionsHelper.getOptionValue(OPTION_PROJECT);
        for (String projectName : StringUtil.splitByComma(projectNames)) {
            ProjectInstance projectInstance = projectManager.getProject(projectName);
            if (projectInstance == null) {
                throw new IllegalArgumentException("Project " + projectName + " does not exist");
            }
            List<RealizationEntry> realizationEntries = projectInstance.getRealizationEntries();
            for (RealizationEntry realizationEntry : realizationEntries) {
                retrieveResourcePath(getRealization(realizationEntry));
            }
        }
    } else if (optionsHelper.hasOption(OPTION_CUBE)) {
        String cubeNames = optionsHelper.getOptionValue(OPTION_CUBE);
        for (String cubeName : StringUtil.splitByComma(cubeNames)) {
            IRealization realization = cubeManager.getRealization(cubeName);
            if (realization != null) {
                retrieveResourcePath(realization);
            } else {
                throw new IllegalArgumentException("No cube found with name of " + cubeName);
            }
        }
    }

    extractCommonInfo(exportDir, kylinConfig);
    extractHTables(exportDir);
}
 
Example 8
Source File: CubeMetaExtractor.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
private void requireProject(ProjectInstance projectInstance) throws IOException {
    addRequired(projectInstance.getResourcePath());
    List<RealizationEntry> realizationEntries = projectInstance.getRealizationEntries();
    for (RealizationEntry realizationEntry : realizationEntries) {
        retrieveResourcePath(getRealization(realizationEntry));
    }
    List<DataModelDesc> modelDescs = metadataManager.getModels(projectInstance.getName());
    for (DataModelDesc modelDesc : modelDescs) {
        addRequired(DataModelDesc.concatResourcePath(modelDesc.getName()));
    }
    addOptional(badQueryHistoryManager.getBadQueriesForProject(projectInstance.getName()).getResourcePath());
}
 
Example 9
Source File: HBaseUsageExtractor.java    From kylin with Apache License 2.0 5 votes vote down vote up
@Override
protected void executeExtract(OptionsHelper optionsHelper, File exportDir) throws Exception {
    if (cachedHMasterUrl == null) {
        return;
    }
    kylinConfig = KylinConfig.getInstanceFromEnv();
    cubeManager = CubeManager.getInstance(kylinConfig);
    realizationRegistry = RealizationRegistry.getInstance(kylinConfig);
    projectManager = ProjectManager.getInstance(kylinConfig);

    if (optionsHelper.hasOption(OPTION_PROJECT)) {
        String projectNames = optionsHelper.getOptionValue(OPTION_PROJECT);
        for (String projectName : StringUtil.splitByComma(projectNames)) {
            ProjectInstance projectInstance = projectManager.getProject(projectName);
            if (projectInstance == null) {
                throw new IllegalArgumentException("Project " + projectName + " does not exist");
            }
            List<RealizationEntry> realizationEntries = projectInstance.getRealizationEntries();
            for (RealizationEntry realizationEntry : realizationEntries) {
                retrieveResourcePath(getRealization(realizationEntry));
            }
        }
    } else if (optionsHelper.hasOption(OPTION_CUBE)) {
        String cubeNames = optionsHelper.getOptionValue(OPTION_CUBE);
        for (String cubeName : StringUtil.splitByComma(cubeNames)) {
            IRealization realization = cubeManager.getRealization(cubeName);
            if (realization != null) {
                retrieveResourcePath(realization);
            } else {
                throw new IllegalArgumentException("No cube found with name of " + cubeName);
            }
        }
    }

    extractCommonInfo(exportDir, kylinConfig);
    extractHTables(exportDir);
}
 
Example 10
Source File: CubeMetaExtractor.java    From kylin with Apache License 2.0 5 votes vote down vote up
private void requireProject(ProjectInstance projectInstance) throws IOException {
    addRequired(projectInstance.getResourcePath());
    List<RealizationEntry> realizationEntries = projectInstance.getRealizationEntries();
    for (RealizationEntry realizationEntry : realizationEntries) {
        retrieveResourcePath(getRealization(realizationEntry));
    }
    List<DataModelDesc> modelDescs = metadataManager.getModels(projectInstance.getName());
    for (DataModelDesc modelDesc : modelDescs) {
        addRequired(DataModelDesc.concatResourcePath(modelDesc.getName()));
    }
    addOptional(badQueryHistoryManager.getBadQueriesForProject(projectInstance.getName()).getResourcePath());
}
 
Example 11
Source File: CubeService.java    From kylin-on-parquet-v2 with Apache License 2.0 4 votes vote down vote up
public void deleteCube(CubeInstance cube) throws IOException {
    aclEvaluate.checkProjectWritePermission(cube);
    Message msg = MsgPicker.getMsg();

    final List<CubingJob> cubingJobs = jobService.listJobsByRealizationName(cube.getName(), null,
            EnumSet.of(ExecutableState.READY, ExecutableState.RUNNING, ExecutableState.ERROR));
    if (!cubingJobs.isEmpty()) {
        throw new BadRequestException(String.format(Locale.ROOT, msg.getDISCARD_JOB_FIRST(), cube.getName()));
    }

    try {
        this.releaseAllJobs(cube);
    } catch (Exception e) {
        logger.error("error when releasing all jobs", e);
        //ignore the exception
    }

    // remove from hybrid definition
    ProjectInstance projectInstance = cube.getProjectInstance();
    List<RealizationEntry> hybridRealizationEntries = projectInstance.getRealizationEntries(RealizationType.HYBRID);

    if (hybridRealizationEntries != null) {
        for (RealizationEntry entry : hybridRealizationEntries) {
            HybridInstance instance = getHybridManager().getHybridInstance(entry.getRealization());
            List<RealizationEntry> cubeRealizationEntries = instance.getRealizationEntries();

            boolean needUpdateHybrid = false;
            for (RealizationEntry cubeRealizationEntry : cubeRealizationEntries) {
                if (cube.getName().equals(cubeRealizationEntry.getRealization())) {
                    needUpdateHybrid = true;
                    cubeRealizationEntries.remove(cubeRealizationEntry);
                    break;
                }
            }

            if (needUpdateHybrid) {
                String[] cubeNames = new String[cubeRealizationEntries.size()];
                for (int i = 0; i < cubeRealizationEntries.size(); i++) {
                    cubeNames[i] = cubeRealizationEntries.get(i).getRealization();
                }
                hybridService.updateHybridCubeNoCheck(instance.getName(), projectInstance.getName(),
                        cube.getModel().getName(), cubeNames);
            }
        }
    }

    List<CubeSegment> toRemoveSegs = cube.getSegments();

    int cubeNum = getCubeManager().getCubesByDesc(cube.getDescriptor().getName()).size();
    getCubeManager().dropCube(cube.getName(), cubeNum == 1);//only delete cube desc when no other cube is using it

    cleanSegmentStorage(toRemoveSegs);
}
 
Example 12
Source File: CubeService.java    From kylin with Apache License 2.0 4 votes vote down vote up
public void deleteCube(CubeInstance cube) throws IOException {
    aclEvaluate.checkProjectWritePermission(cube);
    Message msg = MsgPicker.getMsg();

    final List<CubingJob> cubingJobs = jobService.listJobsByRealizationName(cube.getName(), null,
            EnumSet.of(ExecutableState.READY, ExecutableState.RUNNING, ExecutableState.ERROR));
    if (!cubingJobs.isEmpty()) {
        throw new BadRequestException(String.format(Locale.ROOT, msg.getDISCARD_JOB_FIRST(), cube.getName()));
    }

    try {
        this.releaseAllJobs(cube);
    } catch (Exception e) {
        logger.error("error when releasing all jobs", e);
        //ignore the exception
    }

    // remove from hybrid definition
    ProjectInstance projectInstance = cube.getProjectInstance();
    List<RealizationEntry> hybridRealizationEntries = projectInstance.getRealizationEntries(RealizationType.HYBRID);

    if (hybridRealizationEntries != null) {
        for (RealizationEntry entry : hybridRealizationEntries) {
            HybridInstance instance = getHybridManager().getHybridInstance(entry.getRealization());
            List<RealizationEntry> cubeRealizationEntries = instance.getRealizationEntries();

            boolean needUpdateHybrid = false;
            for (RealizationEntry cubeRealizationEntry : cubeRealizationEntries) {
                if (cube.getName().equals(cubeRealizationEntry.getRealization())) {
                    needUpdateHybrid = true;
                    cubeRealizationEntries.remove(cubeRealizationEntry);
                    break;
                }
            }

            if (needUpdateHybrid) {
                String[] cubeNames = new String[cubeRealizationEntries.size()];
                for (int i = 0; i < cubeRealizationEntries.size(); i++) {
                    cubeNames[i] = cubeRealizationEntries.get(i).getRealization();
                }
                hybridService.updateHybridCubeNoCheck(instance.getName(), projectInstance.getName(),
                        cube.getModel().getName(), cubeNames);
            }
        }
    }

    List<CubeSegment> toRemoveSegs = cube.getSegments();

    int cubeNum = getCubeManager().getCubesByDesc(cube.getDescriptor().getName()).size();
    getCubeManager().dropCube(cube.getName(), cubeNum == 1);//only delete cube desc when no other cube is using it

    cleanSegmentStorage(toRemoveSegs);
}