KYLIN-216 Update draft
Project: http://git-wip-us.apache.org/repos/asf/kylin/repo Commit: http://git-wip-us.apache.org/repos/asf/kylin/commit/25a53673 Tree: http://git-wip-us.apache.org/repos/asf/kylin/tree/25a53673 Diff: http://git-wip-us.apache.org/repos/asf/kylin/diff/25a53673 Branch: refs/heads/master Commit: 25a536734fc46ad71cceae24289733e90d214793 Parents: b6b71e8 Author: Luwei-Chen <chenlu...@apache.org> Authored: Mon Jun 5 11:41:22 2017 +0800 Committer: liyang-gmt8 <liy...@apache.org> Committed: Mon Jun 5 13:16:15 2017 +0800 ---------------------------------------------------------------------- .../java/org/apache/kylin/cube/CubeManager.java | 104 ++++++++++++------- .../rest/controller2/CubeControllerV2.java | 16 --- .../apache/kylin/rest/service/CubeService.java | 78 +++++++++----- 3 files changed, 121 insertions(+), 77 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/kylin/blob/25a53673/core-cube/src/main/java/org/apache/kylin/cube/CubeManager.java ---------------------------------------------------------------------- diff --git a/core-cube/src/main/java/org/apache/kylin/cube/CubeManager.java b/core-cube/src/main/java/org/apache/kylin/cube/CubeManager.java index 8546f76..32e2316 100644 --- a/core-cube/src/main/java/org/apache/kylin/cube/CubeManager.java +++ b/core-cube/src/main/java/org/apache/kylin/cube/CubeManager.java @@ -109,7 +109,8 @@ public class CubeManager implements IRealizationProvider { if (CACHE.size() > 1) { logger.warn("More than one singleton exist"); for (KylinConfig kylinConfig : CACHE.keySet()) { - logger.warn("type: " + kylinConfig.getClass() + " reference: " + System.identityHashCode(kylinConfig.base())); + logger.warn("type: " + kylinConfig.getClass() + " reference: " + + System.identityHashCode(kylinConfig.base())); } } return r; @@ -160,7 +161,8 @@ public class CubeManager implements IRealizationProvider { } @Override - public void onEntityChange(Broadcaster broadcaster, String entity, Event event, String cacheKey) throws IOException { + public void onEntityChange(Broadcaster broadcaster, String entity, Event event, String cacheKey) + throws IOException { String cubeName = cacheKey; if (event == Event.DROP) @@ -168,7 +170,8 @@ public class CubeManager implements IRealizationProvider { else reloadCubeLocal(cubeName); - for (ProjectInstance prj : ProjectManager.getInstance(config).findProjects(RealizationType.CUBE, cubeName)) { + for (ProjectInstance prj : ProjectManager.getInstance(config).findProjects(RealizationType.CUBE, + cubeName)) { broadcaster.notifyProjectDataUpdate(prj.getName()); } } @@ -214,19 +217,22 @@ public class CubeManager implements IRealizationProvider { return result; } - public DictionaryInfo buildDictionary(CubeSegment cubeSeg, TblColRef col, IReadableTable inpTable) throws IOException { + public DictionaryInfo buildDictionary(CubeSegment cubeSeg, TblColRef col, IReadableTable inpTable) + throws IOException { CubeDesc cubeDesc = cubeSeg.getCubeDesc(); if (!cubeDesc.getAllColumnsNeedDictionaryBuilt().contains(col)) return null; String builderClass = cubeDesc.getDictionaryBuilderClass(col); - DictionaryInfo dictInfo = getDictionaryManager().buildDictionary(cubeDesc.getModel(), col, inpTable, builderClass); + DictionaryInfo dictInfo = getDictionaryManager().buildDictionary(cubeDesc.getModel(), col, inpTable, + builderClass); saveDictionaryInfo(cubeSeg, col, dictInfo); return dictInfo; } - public DictionaryInfo saveDictionary(CubeSegment cubeSeg, TblColRef col, IReadableTable inpTable, Dictionary<String> dict) throws IOException { + public DictionaryInfo saveDictionary(CubeSegment cubeSeg, TblColRef col, IReadableTable inpTable, + Dictionary<String> dict) throws IOException { CubeDesc cubeDesc = cubeSeg.getCubeDesc(); if (!cubeDesc.getAllColumnsNeedDictionaryBuilt().contains(col)) return null; @@ -263,7 +269,8 @@ public class CubeManager implements IRealizationProvider { info = dictMgr.getDictionaryInfo(dictResPath); if (info == null) - throw new IllegalStateException("No dictionary found by " + dictResPath + ", invalid cube state; cube segment" + cubeSeg + ", col " + col); + throw new IllegalStateException("No dictionary found by " + dictResPath + + ", invalid cube state; cube segment" + cubeSeg + ", col " + col); } catch (IOException e) { throw new IllegalStateException("Failed to get dictionary for cube segment" + cubeSeg + ", col" + col, e); } @@ -318,7 +325,8 @@ public class CubeManager implements IRealizationProvider { } // sync on update - public CubeInstance createCube(String cubeName, String projectName, CubeDesc desc, String owner) throws IOException { + public CubeInstance createCube(String cubeName, String projectName, CubeDesc desc, String owner) + throws IOException { logger.info("Creating cube '" + projectName + "-->" + cubeName + "' from desc '" + desc.getName() + "'"); // save cube resource @@ -326,9 +334,7 @@ public class CubeManager implements IRealizationProvider { cube.setOwner(owner); updateCubeWithRetry(new CubeUpdate(cube), 0); - if (!desc.isDraft()) { - ProjectManager.getInstance(config).moveRealizationToProject(RealizationType.CUBE, cubeName, projectName, owner); - } + ProjectManager.getInstance(config).moveRealizationToProject(RealizationType.CUBE, cubeName, projectName, owner); if (listener != null) listener.afterCubeCreate(cube); @@ -343,7 +349,8 @@ public class CubeManager implements IRealizationProvider { cube.setOwner(owner); updateCubeWithRetry(new CubeUpdate(cube), 0); - ProjectManager.getInstance(config).moveRealizationToProject(RealizationType.CUBE, cube.getName(), projectName, owner); + ProjectManager.getInstance(config).moveRealizationToProject(RealizationType.CUBE, cube.getName(), projectName, + owner); if (listener != null) listener.afterCubeCreate(cube); @@ -458,12 +465,16 @@ public class CubeManager implements IRealizationProvider { } public CubeSegment appendSegment(CubeInstance cube, SourcePartition sourcePartition) throws IOException { - return appendSegment(cube, sourcePartition.getStartDate(), sourcePartition.getEndDate(), sourcePartition.getStartOffset(), sourcePartition.getEndOffset(), sourcePartition.getSourcePartitionOffsetStart(), sourcePartition.getSourcePartitionOffsetEnd()); + return appendSegment(cube, sourcePartition.getStartDate(), sourcePartition.getEndDate(), + sourcePartition.getStartOffset(), sourcePartition.getEndOffset(), + sourcePartition.getSourcePartitionOffsetStart(), sourcePartition.getSourcePartitionOffsetEnd()); } - CubeSegment appendSegment(CubeInstance cube, long startDate, long endDate, long startOffset, long endOffset, Map<Integer, Long> sourcePartitionOffsetStart, Map<Integer, Long> sourcePartitionOffsetEnd) throws IOException { + CubeSegment appendSegment(CubeInstance cube, long startDate, long endDate, long startOffset, long endOffset, + Map<Integer, Long> sourcePartitionOffsetStart, Map<Integer, Long> sourcePartitionOffsetEnd) + throws IOException { checkBuildingSegment(cube); - + // fix start/end a bit if (cube.getModel().getPartitionDesc().isPartitioned()) { // if missing start, set it to where last time ends @@ -489,19 +500,22 @@ public class CubeManager implements IRealizationProvider { return newSegment; } - public CubeSegment refreshSegment(CubeInstance cube, long startDate, long endDate, long startOffset, long endOffset) throws IOException { + public CubeSegment refreshSegment(CubeInstance cube, long startDate, long endDate, long startOffset, long endOffset) + throws IOException { checkBuildingSegment(cube); CubeSegment newSegment = newSegment(cube, startDate, endDate, startOffset, endOffset); Pair<Boolean, Boolean> pair = CubeValidator.fitInSegments(cube.getSegments(), newSegment); if (pair.getFirst() == false || pair.getSecond() == false) - throw new IllegalArgumentException("The new refreshing segment " + newSegment + " does not match any existing segment in cube " + cube); + throw new IllegalArgumentException("The new refreshing segment " + newSegment + + " does not match any existing segment in cube " + cube); if (startOffset > 0 || endOffset > 0) { CubeSegment toRefreshSeg = null; for (CubeSegment cubeSegment : cube.getSegments()) { - if (cubeSegment.getSourceOffsetStart() == startOffset && cubeSegment.getSourceOffsetEnd() == endOffset) { + if (cubeSegment.getSourceOffsetStart() == startOffset + && cubeSegment.getSourceOffsetEnd() == endOffset) { toRefreshSeg = cubeSegment; break; } @@ -522,7 +536,8 @@ public class CubeManager implements IRealizationProvider { return newSegment; } - public CubeSegment mergeSegments(CubeInstance cube, long startDate, long endDate, long startOffset, long endOffset, boolean force) throws IOException { + public CubeSegment mergeSegments(CubeInstance cube, long startDate, long endDate, long startOffset, long endOffset, + boolean force) throws IOException { if (cube.getSegments().isEmpty()) throw new IllegalArgumentException("Cube " + cube + " has no segments"); if (startDate >= endDate && startOffset >= endOffset) @@ -536,9 +551,11 @@ public class CubeManager implements IRealizationProvider { if (isOffsetsOn) { // offset cube, merge by date range? if (startOffset == endOffset) { - Pair<CubeSegment, CubeSegment> pair = cube.getSegments(SegmentStatusEnum.READY).findMergeOffsetsByDateRange(startDate, endDate, Long.MAX_VALUE); + Pair<CubeSegment, CubeSegment> pair = cube.getSegments(SegmentStatusEnum.READY) + .findMergeOffsetsByDateRange(startDate, endDate, Long.MAX_VALUE); if (pair == null) - throw new IllegalArgumentException("Find no segments to merge by date range " + startDate + "-" + endDate + " for cube " + cube); + throw new IllegalArgumentException("Find no segments to merge by date range " + startDate + "-" + + endDate + " for cube " + cube); startOffset = pair.getFirst().getSourceOffsetStart(); endOffset = pair.getSecond().getSourceOffsetEnd(); } @@ -558,7 +575,9 @@ public class CubeManager implements IRealizationProvider { List<CubeSegment> mergingSegments = cube.getMergingSegments(newSegment); if (mergingSegments.size() <= 1) - throw new IllegalArgumentException("Range " + newSegment.getSourceOffsetStart() + "-" + newSegment.getSourceOffsetEnd() + " must contain at least 2 segments, but there is " + mergingSegments.size()); + throw new IllegalArgumentException( + "Range " + newSegment.getSourceOffsetStart() + "-" + newSegment.getSourceOffsetEnd() + + " must contain at least 2 segments, but there is " + mergingSegments.size()); CubeSegment first = mergingSegments.get(0); CubeSegment last = mergingSegments.get(mergingSegments.size() - 1); @@ -583,7 +602,9 @@ public class CubeManager implements IRealizationProvider { } if (emptySegment.size() > 0) { - throw new IllegalArgumentException("Empty cube segment found, couldn't merge unless 'forceMergeEmptySegment' set to true: " + emptySegment); + throw new IllegalArgumentException( + "Empty cube segment found, couldn't merge unless 'forceMergeEmptySegment' set to true: " + + emptySegment); } } @@ -622,13 +643,15 @@ public class CubeManager implements IRealizationProvider { private void checkBuildingSegment(CubeInstance cube) { int maxBuldingSeg = cube.getConfig().getMaxBuildingSegments(); if (cube.getBuildingSegments().size() >= maxBuldingSeg) { - throw new IllegalStateException("There is already " + cube.getBuildingSegments().size() + " building segment; "); + throw new IllegalStateException( + "There is already " + cube.getBuildingSegments().size() + " building segment; "); } } private void checkCubeIsPartitioned(CubeInstance cube) { if (cube.getDescriptor().getModel().getPartitionDesc().isPartitioned() == false) { - throw new IllegalStateException("there is no partition date column specified, only full build is supported"); + throw new IllegalStateException( + "there is no partition date column specified, only full build is supported"); } } @@ -652,14 +675,16 @@ public class CubeManager implements IRealizationProvider { String[] pkCols = join.getPrimaryKey(); String snapshotResPath = cubeSegment.getSnapshotResPath(tableName); if (snapshotResPath == null) - throw new IllegalStateException("No snaphot for table '" + tableName + "' found on cube segment" + cubeSegment.getCubeInstance().getName() + "/" + cubeSegment); + throw new IllegalStateException("No snaphot for table '" + tableName + "' found on cube segment" + + cubeSegment.getCubeInstance().getName() + "/" + cubeSegment); try { SnapshotTable snapshot = getSnapshotManager().getSnapshotTable(snapshotResPath); TableDesc tableDesc = getMetadataManager().getTableDesc(tableName); return new LookupStringTable(tableDesc, pkCols, snapshot); } catch (IOException e) { - throw new IllegalStateException("Failed to load lookup table " + tableName + " from snapshot " + snapshotResPath, e); + throw new IllegalStateException( + "Failed to load lookup table " + tableName + " from snapshot " + snapshotResPath, e); } } @@ -703,7 +728,8 @@ public class CubeManager implements IRealizationProvider { public void promoteNewlyBuiltSegments(CubeInstance cube, CubeSegment newSegment) throws IOException { if (StringUtils.isBlank(newSegment.getStorageLocationIdentifier())) - throw new IllegalStateException("For cube " + cube + ", segment " + newSegment + " missing StorageLocationIdentifier"); + throw new IllegalStateException( + "For cube " + cube + ", segment " + newSegment + " missing StorageLocationIdentifier"); if (StringUtils.isBlank(newSegment.getLastBuildJobID())) throw new IllegalStateException("For cube " + cube + ", segment " + newSegment + " missing LastBuildJobID"); @@ -715,7 +741,8 @@ public class CubeManager implements IRealizationProvider { List<CubeSegment> tobe = cube.calculateToBeSegments(newSegment); if (tobe.contains(newSegment) == false) - throw new IllegalStateException("For cube " + cube + ", segment " + newSegment + " is expected but not in the tobe " + tobe); + throw new IllegalStateException( + "For cube " + cube + ", segment " + newSegment + " is expected but not in the tobe " + tobe); newSegment.setStatus(SegmentStatusEnum.READY); @@ -728,7 +755,8 @@ public class CubeManager implements IRealizationProvider { logger.info("Promoting cube " + cube + ", new segment " + newSegment + ", to remove segments " + toRemoveSegs); CubeUpdate cubeBuilder = new CubeUpdate(cube); - cubeBuilder.setToRemoveSegs(toRemoveSegs.toArray(new CubeSegment[toRemoveSegs.size()])).setToUpdateSegs(newSegment).setStatus(RealizationStatusEnum.READY); + cubeBuilder.setToRemoveSegs(toRemoveSegs.toArray(new CubeSegment[toRemoveSegs.size()])) + .setToUpdateSegs(newSegment).setStatus(RealizationStatusEnum.READY); updateCube(cubeBuilder); } @@ -736,7 +764,8 @@ public class CubeManager implements IRealizationProvider { List<CubeSegment> tobe = cube.calculateToBeSegments(newSegments); List<CubeSegment> newList = Arrays.asList(newSegments); if (tobe.containsAll(newList) == false) { - throw new IllegalStateException("For cube " + cube + ", the new segments " + newList + " do not fit in its current " + cube.getSegments() + "; the resulted tobe is " + tobe); + throw new IllegalStateException("For cube " + cube + ", the new segments " + newList + + " do not fit in its current " + cube.getSegments() + "; the resulted tobe is " + tobe); } } @@ -778,7 +807,9 @@ public class CubeManager implements IRealizationProvider { CubeDesc cubeDesc = CubeDescManager.getInstance(config).getCubeDesc(cube.getDescName()); checkNotNull(cubeDesc, "cube descriptor '%s' (for cube '%s') not found", cube.getDescName(), cubeName); if (!isSpecialTestCube(cubeName)) - checkState(cubeDesc.getName().equals(cubeName), "cube name '%s' must be same as descriptor name '%s', but it is not", cubeName, cubeDesc.getName()); + checkState(cubeDesc.getName().equals(cubeName), + "cube name '%s' must be same as descriptor name '%s', but it is not", cubeName, + cubeDesc.getName()); if (!cubeDesc.getError().isEmpty()) { cube.setStatus(RealizationStatusEnum.DESCBROKEN); @@ -809,7 +840,8 @@ public class CubeManager implements IRealizationProvider { private boolean isSpecialTestCube(String cubeName) { return cubeName.equals("kylin_sales_cube") // - || config.isDevEnv() && (cubeName.startsWith("test_kylin_cube") || cubeName.startsWith("test_streaming")); + || config.isDevEnv() + && (cubeName.startsWith("test_kylin_cube") || cubeName.startsWith("test_streaming")); } private MetadataManager getMetadataManager() { @@ -906,7 +938,8 @@ public class CubeManager implements IRealizationProvider { hole.setDateRangeStart(first.getDateRangeEnd()); hole.setDateRangeEnd(second.getDateRangeStart()); } - hole.setName(CubeSegment.makeSegmentName(hole.getDateRangeStart(), hole.getDateRangeEnd(), hole.getSourceOffsetStart(), hole.getSourceOffsetEnd())); + hole.setName(CubeSegment.makeSegmentName(hole.getDateRangeStart(), hole.getDateRangeEnd(), + hole.getSourceOffsetStart(), hole.getSourceOffsetEnd())); holes.add(hole); } } @@ -924,7 +957,8 @@ public class CubeManager implements IRealizationProvider { List<DictionaryDesc> dictionaryDescList = cubeDesc.getDictionaries(); if (dictionaryDescList != null) { for (DictionaryDesc dictionaryDesc : dictionaryDescList) { - if (dictionaryDesc.getBuilderClass() != null && dictionaryDesc.getBuilderClass().equalsIgnoreCase(GLOBAL_DICTIONNARY_CLASS)) { + if (dictionaryDesc.getBuilderClass() != null + && dictionaryDesc.getBuilderClass().equalsIgnoreCase(GLOBAL_DICTIONNARY_CLASS)) { for (int i = 0; i < factDictCols.size(); i++) { if (factDictCols.get(i).equals(dictionaryDesc.getColumnRef())) { uhcIndex[i] = 1; http://git-wip-us.apache.org/repos/asf/kylin/blob/25a53673/server-base/src/main/java/org/apache/kylin/rest/controller2/CubeControllerV2.java ---------------------------------------------------------------------- diff --git a/server-base/src/main/java/org/apache/kylin/rest/controller2/CubeControllerV2.java b/server-base/src/main/java/org/apache/kylin/rest/controller2/CubeControllerV2.java index 2edfe7d..aac00ec 100644 --- a/server-base/src/main/java/org/apache/kylin/rest/controller2/CubeControllerV2.java +++ b/server-base/src/main/java/org/apache/kylin/rest/controller2/CubeControllerV2.java @@ -488,22 +488,6 @@ public class CubeControllerV2 extends BasicController { return new EnvelopeResponse(ResponseCode.CODE_SUCCESS, cubeService.enableCube(cube), ""); } - @RequestMapping(value = "/{cubeName}", method = { RequestMethod.DELETE }, produces = { - "application/vnd.apache.kylin-v2+json" }) - @ResponseBody - public void deleteCubeV2(@PathVariable String cubeName) throws IOException { - Message msg = MsgPicker.getMsg(); - - CubeInstance cube = cubeService.getCubeManager().getCube(cubeName); - if (null == cube) { - throw new BadRequestException(String.format(msg.getCUBE_NOT_FOUND(), cubeName)); - } - - //drop Cube - cubeService.deleteCube(cube); - - } - /** * get Hbase Info * http://git-wip-us.apache.org/repos/asf/kylin/blob/25a53673/server-base/src/main/java/org/apache/kylin/rest/service/CubeService.java ---------------------------------------------------------------------- diff --git a/server-base/src/main/java/org/apache/kylin/rest/service/CubeService.java b/server-base/src/main/java/org/apache/kylin/rest/service/CubeService.java index 3c0bbc6..ebce61b 100644 --- a/server-base/src/main/java/org/apache/kylin/rest/service/CubeService.java +++ b/server-base/src/main/java/org/apache/kylin/rest/service/CubeService.java @@ -110,7 +110,8 @@ public class CubeService extends BasicService { if (modelName != null) { for (CubeInstance cubeInstance : cubeInstances) { - boolean isCubeMatch = cubeInstance.getDescriptor().getModelName().toLowerCase().equals(modelName.toLowerCase()); + boolean isCubeMatch = cubeInstance.getDescriptor().getModelName().toLowerCase() + .equals(modelName.toLowerCase()); if (isCubeMatch) { filterModelCubes.add(cubeInstance); } @@ -121,7 +122,8 @@ public class CubeService extends BasicService { List<CubeInstance> filterCubes = new ArrayList<CubeInstance>(); for (CubeInstance cubeInstance : filterModelCubes) { - boolean isCubeMatch = (null == cubeName) || cubeInstance.getName().toLowerCase().contains(cubeName.toLowerCase()); + boolean isCubeMatch = (null == cubeName) + || cubeInstance.getName().toLowerCase().contains(cubeName.toLowerCase()); if (isCubeMatch) { filterCubes.add(cubeInstance); @@ -131,7 +133,8 @@ public class CubeService extends BasicService { return filterCubes; } - @PreAuthorize(Constant.ACCESS_HAS_ROLE_ADMIN + " or hasPermission(#cube, 'ADMINISTRATION') or hasPermission(#cube, 'MANAGEMENT')") + @PreAuthorize(Constant.ACCESS_HAS_ROLE_ADMIN + + " or hasPermission(#cube, 'ADMINISTRATION') or hasPermission(#cube, 'MANAGEMENT')") public CubeInstance updateCubeCost(CubeInstance cube, int cost) throws IOException { if (cube.getCost() == cost) { @@ -222,7 +225,8 @@ public class CubeService extends BasicService { 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"); + logger.error("Project " + projectName + " contains realization " + projectDataModel.getRealization() + + " which is not found by CubeManager"); continue; } if (cube.equals(target)) { @@ -233,11 +237,14 @@ public class CubeService extends BasicService { return false; } - @PreAuthorize(Constant.ACCESS_HAS_ROLE_ADMIN + " or hasPermission(#cube, 'ADMINISTRATION') or hasPermission(#cube, 'MANAGEMENT')") - public CubeDesc updateCubeAndDesc(CubeInstance cube, CubeDesc desc, String newProjectName, boolean forceUpdate) throws IOException { + @PreAuthorize(Constant.ACCESS_HAS_ROLE_ADMIN + + " or hasPermission(#cube, 'ADMINISTRATION') or hasPermission(#cube, 'MANAGEMENT')") + public CubeDesc updateCubeAndDesc(CubeInstance cube, CubeDesc desc, String newProjectName, boolean forceUpdate) + throws IOException { Message msg = MsgPicker.getMsg(); - final List<CubingJob> cubingJobs = jobService.listAllCubingJobs(cube.getName(), null, EnumSet.of(ExecutableState.READY, ExecutableState.RUNNING)); + final List<CubingJob> cubingJobs = jobService.listAllCubingJobs(cube.getName(), null, + EnumSet.of(ExecutableState.READY, ExecutableState.RUNNING)); if (!cubingJobs.isEmpty()) { throw new BadRequestException(String.format(msg.getDISCARD_JOB_FIRST(), cube.getName())); } @@ -251,11 +258,15 @@ public class CubeService extends BasicService { if (!desc.isDraft()) { int cuboidCount = CuboidCLI.simulateCuboidGeneration(updatedCubeDesc, false); logger.info("Updated cube " + cube.getName() + " has " + cuboidCount + " cuboids"); + } + + ProjectManager projectManager = getProjectManager(); + if (!isCubeInProject(newProjectName, cube)) { + String owner = SecurityContextHolder.getContext().getAuthentication().getName(); + ProjectInstance newProject = projectManager.moveRealizationToProject(RealizationType.CUBE, cube.getName(), + newProjectName, owner); - ProjectManager projectManager = getProjectManager(); - if (!isCubeInProject(newProjectName, cube)) { - String owner = SecurityContextHolder.getContext().getAuthentication().getName(); - ProjectInstance newProject = projectManager.moveRealizationToProject(RealizationType.CUBE, cube.getName(), newProjectName, owner); + if (!desc.isDraft()) { accessService.inherit(cube, newProject); } } @@ -263,11 +274,13 @@ public class CubeService extends BasicService { return updatedCubeDesc; } - @PreAuthorize(Constant.ACCESS_HAS_ROLE_ADMIN + " or hasPermission(#cube, 'ADMINISTRATION') or hasPermission(#cube, 'MANAGEMENT')") + @PreAuthorize(Constant.ACCESS_HAS_ROLE_ADMIN + + " or hasPermission(#cube, 'ADMINISTRATION') or hasPermission(#cube, 'MANAGEMENT')") public void deleteCube(CubeInstance cube) throws IOException { Message msg = MsgPicker.getMsg(); - final List<CubingJob> cubingJobs = jobService.listAllCubingJobs(cube.getName(), null, EnumSet.of(ExecutableState.READY, ExecutableState.RUNNING, ExecutableState.ERROR)); + final List<CubingJob> cubingJobs = jobService.listAllCubingJobs(cube.getName(), null, + EnumSet.of(ExecutableState.READY, ExecutableState.RUNNING, ExecutableState.ERROR)); if (!cubingJobs.isEmpty()) { throw new BadRequestException(String.format(msg.getDISCARD_JOB_FIRST(), cube.getName())); } @@ -292,7 +305,8 @@ public class CubeService extends BasicService { * @throws IOException * @throws JobException */ - @PreAuthorize(Constant.ACCESS_HAS_ROLE_ADMIN + " or hasPermission(#cube, 'ADMINISTRATION') or hasPermission(#cube, 'OPERATION') or hasPermission(#cube, 'MANAGEMENT')") + @PreAuthorize(Constant.ACCESS_HAS_ROLE_ADMIN + + " or hasPermission(#cube, 'ADMINISTRATION') or hasPermission(#cube, 'OPERATION') or hasPermission(#cube, 'MANAGEMENT')") public CubeInstance purgeCube(CubeInstance cube) throws IOException { Message msg = MsgPicker.getMsg(); @@ -314,7 +328,8 @@ public class CubeService extends BasicService { * @throws IOException * @throws JobException */ - @PreAuthorize(Constant.ACCESS_HAS_ROLE_ADMIN + " or hasPermission(#cube, 'ADMINISTRATION') or hasPermission(#cube, 'OPERATION') or hasPermission(#cube, 'MANAGEMENT')") + @PreAuthorize(Constant.ACCESS_HAS_ROLE_ADMIN + + " or hasPermission(#cube, 'ADMINISTRATION') or hasPermission(#cube, 'OPERATION') or hasPermission(#cube, 'MANAGEMENT')") public CubeInstance disableCube(CubeInstance cube) throws IOException { Message msg = MsgPicker.getMsg(); @@ -343,7 +358,8 @@ public class CubeService extends BasicService { * @return * @throws IOException */ - @PreAuthorize(Constant.ACCESS_HAS_ROLE_ADMIN + " or hasPermission(#cube, 'ADMINISTRATION') or hasPermission(#cube, 'OPERATION') or hasPermission(#cube, 'MANAGEMENT')") + @PreAuthorize(Constant.ACCESS_HAS_ROLE_ADMIN + + " or hasPermission(#cube, 'ADMINISTRATION') or hasPermission(#cube, 'OPERATION') or hasPermission(#cube, 'MANAGEMENT')") public CubeInstance enableCube(CubeInstance cube) throws IOException { Message msg = MsgPicker.getMsg(); @@ -358,12 +374,14 @@ public class CubeService extends BasicService { throw new BadRequestException(String.format(msg.getNO_READY_SEGMENT(), cubeName)); } - final List<CubingJob> cubingJobs = jobService.listAllCubingJobs(cube.getName(), null, EnumSet.of(ExecutableState.READY, ExecutableState.RUNNING)); + final List<CubingJob> cubingJobs = jobService.listAllCubingJobs(cube.getName(), null, + EnumSet.of(ExecutableState.READY, ExecutableState.RUNNING)); if (!cubingJobs.isEmpty()) { throw new BadRequestException(msg.getENABLE_WITH_RUNNING_JOB()); } if (!cube.getDescriptor().checkSignature()) { - throw new BadRequestException(String.format(msg.getINCONSISTENT_CUBE_DESC_SIGNATURE(), cube.getDescriptor())); + throw new BadRequestException( + String.format(msg.getINCONSISTENT_CUBE_DESC_SIGNATURE(), cube.getDescriptor())); } try { @@ -393,7 +411,8 @@ public class CubeService extends BasicService { } } - metrics.increase("aveStorage", (metrics.get("totalCubes") == 0) ? 0 : metrics.get("totalStorage") / metrics.get("totalCubes")); + metrics.increase("aveStorage", + (metrics.get("totalCubes") == 0) ? 0 : metrics.get("totalStorage") / metrics.get("totalCubes")); return metrics; } @@ -428,26 +447,31 @@ public class CubeService extends BasicService { return hr; } - @PreAuthorize(Constant.ACCESS_HAS_ROLE_ADMIN + " or hasPermission(#cube, 'ADMINISTRATION') or hasPermission(#cube, 'OPERATION') or hasPermission(#cube, 'MANAGEMENT')") + @PreAuthorize(Constant.ACCESS_HAS_ROLE_ADMIN + + " or hasPermission(#cube, 'ADMINISTRATION') or hasPermission(#cube, 'OPERATION') or hasPermission(#cube, 'MANAGEMENT')") public void updateCubeNotifyList(CubeInstance cube, List<String> notifyList) throws IOException { CubeDesc desc = cube.getDescriptor(); desc.setNotifyList(notifyList); getCubeDescManager().updateCubeDesc(desc); } - @PreAuthorize(Constant.ACCESS_HAS_ROLE_ADMIN + " or hasPermission(#cube, 'ADMINISTRATION') or hasPermission(#cube, 'OPERATION') or hasPermission(#cube, 'MANAGEMENT')") - public CubeInstance rebuildLookupSnapshot(CubeInstance cube, String segmentName, String lookupTable) throws IOException { + @PreAuthorize(Constant.ACCESS_HAS_ROLE_ADMIN + + " or hasPermission(#cube, 'ADMINISTRATION') or hasPermission(#cube, 'OPERATION') or hasPermission(#cube, 'MANAGEMENT')") + public CubeInstance rebuildLookupSnapshot(CubeInstance cube, String segmentName, String lookupTable) + throws IOException { CubeSegment seg = cube.getSegment(segmentName, SegmentStatusEnum.READY); getCubeManager().buildSnapshotTable(seg, lookupTable); return cube; } - @PreAuthorize(Constant.ACCESS_HAS_ROLE_ADMIN + " or hasPermission(#cube, 'ADMINISTRATION') or hasPermission(#cube, 'OPERATION') or hasPermission(#cube, 'MANAGEMENT')") + @PreAuthorize(Constant.ACCESS_HAS_ROLE_ADMIN + + " or hasPermission(#cube, 'ADMINISTRATION') or hasPermission(#cube, 'OPERATION') or hasPermission(#cube, 'MANAGEMENT')") public CubeInstance deleteSegment(CubeInstance cube, String segmentName) throws IOException { Message msg = MsgPicker.getMsg(); - if (!segmentName.equals(cube.getSegments().get(0).getName()) && !segmentName.equals(cube.getSegments().get(cube.getSegments().size() - 1).getName())) { + if (!segmentName.equals(cube.getSegments().get(0).getName()) + && !segmentName.equals(cube.getSegments().get(cube.getSegments().size() - 1).getName())) { throw new BadRequestException(String.format(msg.getDELETE_NOT_FIRST_LAST_SEG(), segmentName)); } CubeSegment toDelete = null; @@ -497,7 +521,8 @@ public class CubeService extends BasicService { public void updateOnNewSegmentReady(String cubeName) { final KylinConfig kylinConfig = KylinConfig.getInstanceFromEnv(); String serverMode = kylinConfig.getServerMode(); - if (Constant.SERVER_MODE_JOB.equals(serverMode.toLowerCase()) || Constant.SERVER_MODE_ALL.equals(serverMode.toLowerCase())) { + if (Constant.SERVER_MODE_JOB.equals(serverMode.toLowerCase()) + || Constant.SERVER_MODE_ALL.equals(serverMode.toLowerCase())) { CubeInstance cube = getCubeManager().getCube(cubeName); if (cube != null) { CubeSegment seg = cube.getLatestBuiltSegment(); @@ -555,7 +580,8 @@ public class CubeService extends BasicService { cube = getCubeManager().getCube(cubeName); Pair<Long, Long> offsets = getCubeManager().autoMergeCubeSegments(cube); if (offsets != null) { - CubeSegment newSeg = getCubeManager().mergeSegments(cube, 0, 0, offsets.getFirst(), offsets.getSecond(), true); + CubeSegment newSeg = getCubeManager().mergeSegments(cube, 0, 0, offsets.getFirst(), + offsets.getSecond(), true); logger.debug("Will submit merge job on " + newSeg); DefaultChainedExecutable job = EngineFactory.createBatchMergeJob(newSeg, "SYSTEM"); getExecutableManager().addJob(job);