[ https://issues.apache.org/jira/browse/KYLIN-3418?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16558166#comment-16558166 ]
ASF GitHub Bot commented on KYLIN-3418: --------------------------------------- shaofengshi closed pull request #174: KYLIN-3418 Adjust hybrid API URL: https://github.com/apache/kylin/pull/174 This is a PR merged from a forked repository. As GitHub hides the original diff on merge, it is displayed below for the sake of provenance: As this is a foreign pull request (from a fork), the diff is supplied below (as it won't show otherwise due to GitHub magic): diff --git a/core-storage/src/main/java/org/apache/kylin/storage/hybrid/HybridInstance.java b/core-storage/src/main/java/org/apache/kylin/storage/hybrid/HybridInstance.java index 286af5f360..5bb4450b34 100644 --- a/core-storage/src/main/java/org/apache/kylin/storage/hybrid/HybridInstance.java +++ b/core-storage/src/main/java/org/apache/kylin/storage/hybrid/HybridInstance.java @@ -26,6 +26,8 @@ import org.apache.kylin.common.KylinConfig; import org.apache.kylin.common.persistence.ResourceStore; import org.apache.kylin.common.persistence.RootPersistentEntity; +import org.apache.kylin.cube.CubeInstance; +import org.apache.kylin.cube.CubeManager; import org.apache.kylin.metadata.model.ColumnDesc; import org.apache.kylin.metadata.model.DataModelDesc; import org.apache.kylin.metadata.model.MeasureDesc; @@ -62,7 +64,7 @@ public static HybridInstance create(KylinConfig config, String name, List<Realiz return hybridInstance; } - + // ============================================================================ @JsonIgnore @@ -90,7 +92,7 @@ public static HybridInstance create(KylinConfig config, String name, List<Realiz public String resourceName() { return name; } - + public List<RealizationEntry> getRealizationEntries() { return realizationEntries; } @@ -222,8 +224,15 @@ public RealizationType getType() { @Override public DataModelDesc getModel() { - if (this.getLatestRealization() != null) + if (this.getLatestRealization() != null) { return this.getLatestRealization().getModel(); + } + // all included cubes are disabled + if (this.getRealizationEntries() != null && this.getRealizationEntries().size() > 0) { + String cubeName = this.getRealizationEntries().get(0).getRealization(); + CubeInstance cubeInstance = CubeManager.getInstance(config).getCube(cubeName); + return cubeInstance.getModel(); + } return null; } diff --git a/server-base/src/main/java/org/apache/kylin/rest/controller/HybridController.java b/server-base/src/main/java/org/apache/kylin/rest/controller/HybridController.java index f23f26c7df..c139b8dba8 100644 --- a/server-base/src/main/java/org/apache/kylin/rest/controller/HybridController.java +++ b/server-base/src/main/java/org/apache/kylin/rest/controller/HybridController.java @@ -19,8 +19,12 @@ package org.apache.kylin.rest.controller; import java.util.Collection; +import java.util.List; +import com.google.common.collect.Lists; +import org.apache.kylin.metadata.model.DataModelDesc; import org.apache.kylin.rest.request.HybridRequest; +import org.apache.kylin.rest.response.HybridRespone; import org.apache.kylin.rest.service.HybridService; import org.apache.kylin.storage.hybrid.HybridInstance; import org.springframework.beans.factory.annotation.Autowired; @@ -41,45 +45,58 @@ @RequestMapping(value = "", method = RequestMethod.POST, produces = { "application/json" }) @ResponseBody - public HybridInstance create(@RequestBody HybridRequest request) { + public HybridRespone create(@RequestBody HybridRequest request) { checkRequiredArg("hybrid", request.getHybrid()); checkRequiredArg("project", request.getProject()); checkRequiredArg("model", request.getModel()); checkRequiredArg("cubes", request.getCubes()); - HybridInstance instance = hybridService.createHybridCube(request.getHybrid(), request.getProject(), request.getModel(), request.getCubes()); - return instance; + HybridInstance hybridInstance = hybridService.createHybridInstance(request.getHybrid(), request.getProject(), request.getModel(), + request.getCubes()); + return hybridInstance2response(hybridInstance); } @RequestMapping(value = "", method = RequestMethod.PUT, produces = { "application/json" }) @ResponseBody - public HybridInstance update(@RequestBody HybridRequest request) { + public HybridRespone update(@RequestBody HybridRequest request) { checkRequiredArg("hybrid", request.getHybrid()); checkRequiredArg("project", request.getProject()); checkRequiredArg("model", request.getModel()); checkRequiredArg("cubes", request.getCubes()); - HybridInstance instance = hybridService.updateHybridCube(request.getHybrid(), request.getProject(), request.getModel(), request.getCubes()); - return instance; + HybridInstance hybridInstance = hybridService.updateHybridInstance(request.getHybrid(), request.getProject(), request.getModel(), + request.getCubes()); + return hybridInstance2response(hybridInstance); } @RequestMapping(value = "", method = RequestMethod.DELETE, produces = { "application/json" }) @ResponseBody - public void delete(@RequestBody HybridRequest request) { - checkRequiredArg("hybrid", request.getHybrid()); - checkRequiredArg("project", request.getProject()); - checkRequiredArg("model", request.getModel()); - hybridService.deleteHybridCube(request.getHybrid(), request.getProject(), request.getModel()); + public void delete(String hybrid, String project) { + checkRequiredArg("hybrid", hybrid); + checkRequiredArg("project", project); + hybridService.deleteHybridInstance(hybrid, project); } @RequestMapping(value = "", method = RequestMethod.GET, produces = { "application/json" }) @ResponseBody - public Collection<HybridInstance> list(@RequestParam(required = false) String project, @RequestParam(required = false) String model) { - return hybridService.listHybrids(project, model); + public Collection<HybridRespone> list(@RequestParam(required = false) String project, @RequestParam(required = false) String model) { + List<HybridInstance> hybridInstances = hybridService.listHybrids(project, model); + List<HybridRespone> hybridRespones = Lists.newArrayListWithCapacity(hybridInstances.size()); + + for (HybridInstance hybridInstance : hybridInstances) { + hybridRespones.add(hybridInstance2response(hybridInstance)); + } + + return hybridRespones; } @RequestMapping(value = "{hybrid}", method = RequestMethod.GET, produces = { "application/json" }) @ResponseBody - public HybridInstance get(@PathVariable String hybrid) { - return hybridService.getHybridInstance(hybrid); + public HybridRespone get(@PathVariable String hybrid) { + HybridInstance hybridInstance = hybridService.getHybridInstance(hybrid); + return hybridInstance2response(hybridInstance); } + private HybridRespone hybridInstance2response(HybridInstance hybridInstance){ + DataModelDesc modelDesc = hybridInstance.getModel(); + return new HybridRespone(modelDesc == null ? HybridRespone.NO_PROJECT : modelDesc.getProject(), modelDesc == null ? HybridRespone.NO_MODEL : modelDesc.getName(), hybridInstance); + } } diff --git a/server-base/src/main/java/org/apache/kylin/rest/job/HybridCubeCLI.java b/server-base/src/main/java/org/apache/kylin/rest/job/HybridCubeCLI.java index 1c8a46acb9..48e7f40973 100644 --- a/server-base/src/main/java/org/apache/kylin/rest/job/HybridCubeCLI.java +++ b/server-base/src/main/java/org/apache/kylin/rest/job/HybridCubeCLI.java @@ -59,9 +59,9 @@ private static final Option OPTION_HYBRID_NAME = OptionBuilder.withArgName("name").hasArg().isRequired(true).withDescription("HybridCube name").create("name"); - private static final Option OPTION_PROJECT = OptionBuilder.withArgName("project").hasArg().isRequired(true).withDescription("the target project for the hybrid cube").create("project"); + private static final Option OPTION_PROJECT = OptionBuilder.withArgName("project").hasArg().isRequired(false).withDescription("the target project for the hybrid cube").create("project"); - private static final Option OPTION_MODEL = OptionBuilder.withArgName("model").hasArg().isRequired(true).withDescription("the target model for the hybrid cube").create("model"); + private static final Option OPTION_MODEL = OptionBuilder.withArgName("model").hasArg().isRequired(false).withDescription("the target model for the hybrid cube").create("model"); private static final Option OPTION_CUBES = OptionBuilder.withArgName("cubes").hasArg().isRequired(false).withDescription("the cubes used in HybridCube, seperated by comma, empty if to delete HybridCube").create("cubes"); @@ -110,6 +110,17 @@ protected void execute(OptionsHelper optionsHelper) throws Exception { String cubeNamesStr = optionsHelper.getOptionValue(OPTION_CUBES); boolean checkCubeSize = optionsHelper.hasOption(OPTION_CHECK) ? Boolean.valueOf(optionsHelper.getOptionValue(OPTION_CHECK)) : true; + HybridInstance hybridInstance = hybridManager.getHybridInstance(hybridName); + + if ("delete".equals(action)) { + if (hybridInstance == null) { + throw new IllegalArgumentException("The Hybrid Cube doesn't exist, could not delete: " + hybridName); + } + // Delete the Hybrid + delete(hybridInstance); + return; + } + String[] cubeNames = new String[] {}; if (cubeNamesStr != null) cubeNames = cubeNamesStr.split(","); @@ -117,7 +128,7 @@ protected void execute(OptionsHelper optionsHelper) throws Exception { DataModelDesc modelDesc = metadataManager.getDataModelDesc(modelName); if (modelDesc == null) { - throw new RuntimeException("Could not find model: " + modelName); + throw new IllegalArgumentException("Could not find model: " + modelName); } List<RealizationEntry> realizationEntries = new ArrayList<RealizationEntry>(); @@ -126,7 +137,7 @@ protected void execute(OptionsHelper optionsHelper) throws Exception { continue; CubeInstance cube = cubeManager.getCube(cubeName); if (cube == null) { - throw new RuntimeException("Could not find cube: " + cubeName); + throw new IllegalArgumentException("Could not find cube: " + cubeName); } if (owner == null) { owner = cube.getOwner(); @@ -134,27 +145,19 @@ protected void execute(OptionsHelper optionsHelper) throws Exception { realizationEntries.add(RealizationEntry.create(RealizationType.CUBE, cube.getName())); } - HybridInstance hybridInstance = hybridManager.getHybridInstance(hybridName); if ("create".equals(action)) { if (hybridInstance != null) { - throw new RuntimeException("The Hybrid Cube does exist, could not create: " + hybridName); + throw new IllegalArgumentException("The Hybrid Cube does exist, could not create: " + hybridName); } //Create new Hybrid create(hybridName, realizationEntries, projectName, owner); } else if ("update".equals(action)) { if (hybridInstance == null) { - throw new RuntimeException("The Hybrid Cube doesn't exist, could not update: " + hybridName); + throw new IllegalArgumentException("The Hybrid Cube doesn't exist, could not update: " + hybridName); } // Update the Hybrid update(hybridInstance, realizationEntries, projectName, owner, checkCubeSize); - } else if ("delete".equals(action)) { - if (hybridInstance == null) { - throw new RuntimeException("The Hybrid Cube doesn't exist, could not delete: " + hybridName); - } - // Delete the Hybrid - delete(hybridInstance); } - } private HybridInstance create(String hybridName, List<RealizationEntry> realizationEntries, String projectName, String owner) throws IOException { @@ -186,13 +189,13 @@ private void delete(HybridInstance hybridInstance) throws IOException { private void checkSegmentOffset(List<RealizationEntry> realizationEntries) { if (realizationEntries == null || realizationEntries.size() == 0) - throw new RuntimeException("No realization found"); + throw new IllegalArgumentException("No realization found"); if (realizationEntries.size() == 1) - throw new RuntimeException("Hybrid needs at least 2 cubes"); + throw new IllegalArgumentException("Hybrid needs at least 2 cubes"); long lastOffset = -1; for (RealizationEntry entry : realizationEntries) { if (entry.getType() != RealizationType.CUBE) { - throw new RuntimeException("Wrong realization type: " + entry.getType() + ", only cube supported. "); + throw new IllegalArgumentException("Wrong realization type: " + entry.getType() + ", only cube supported. "); } CubeInstance cubeInstance = cubeManager.getCube(entry.getRealization()); @@ -203,7 +206,7 @@ private void checkSegmentOffset(List<RealizationEntry> realizationEntries) { lastOffset = (Long) segment.getSegRange().end.v; } else { if (lastOffset > (Long) segment.getSegRange().start.v) { - throw new RuntimeException("Segments has overlap, could not hybrid. Last Segment End: " + lastOffset + ", Next Segment Start: " + segment.getSegRange().start.v); + throw new IllegalArgumentException("Segments has overlap, could not hybrid. Last Segment End: " + lastOffset + ", Next Segment Start: " + segment.getSegRange().start.v); } lastOffset = (Long) segment.getSegRange().end.v; } diff --git a/server-base/src/main/java/org/apache/kylin/rest/response/HybridRespone.java b/server-base/src/main/java/org/apache/kylin/rest/response/HybridRespone.java new file mode 100644 index 0000000000..745d4b1f90 --- /dev/null +++ b/server-base/src/main/java/org/apache/kylin/rest/response/HybridRespone.java @@ -0,0 +1,61 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.kylin.rest.response; + +import org.apache.kylin.storage.hybrid.HybridInstance; + +public class HybridRespone { + + public static final String NO_PROJECT = "NO_PROJECT"; + public static final String NO_MODEL = "NO_MODEL"; + + private String projectName; + private String modelName; + private HybridInstance hybridInstance; + + public HybridRespone(String projectName, String modelName, HybridInstance hybridInstance) { + this.projectName = projectName; + this.modelName = modelName; + this.hybridInstance = hybridInstance; + } + + public String getProjectName() { + return projectName; + } + + public void setProjectName(String projectName) { + this.projectName = projectName; + } + + public String getModelName() { + return modelName; + } + + public void setModelName(String modelName) { + this.modelName = modelName; + } + + public HybridInstance getHybridInstance() { + return hybridInstance; + } + + public void setHybridInstance(HybridInstance hybridInstance) { + this.hybridInstance = hybridInstance; + } +} diff --git a/server-base/src/main/java/org/apache/kylin/rest/service/HybridService.java b/server-base/src/main/java/org/apache/kylin/rest/service/HybridService.java index 1b48082853..9de59419d8 100644 --- a/server-base/src/main/java/org/apache/kylin/rest/service/HybridService.java +++ b/server-base/src/main/java/org/apache/kylin/rest/service/HybridService.java @@ -43,7 +43,7 @@ @Autowired private AclEvaluate aclEvaluate; - public HybridInstance createHybridCube(String hybridName, String projectName, String modelName, + public HybridInstance createHybridInstance(String hybridName, String projectName, String modelName, String[] cubeNames) { aclEvaluate.checkProjectWritePermission(projectName); List<String> args = new ArrayList<String>(); @@ -66,7 +66,7 @@ public HybridInstance createHybridCube(String hybridName, String projectName, St return getHybridInstance(hybridName); } - public HybridInstance updateHybridCube(String hybridName, String projectName, String modelName, + public HybridInstance updateHybridInstance(String hybridName, String projectName, String modelName, String[] cubeNames) { aclEvaluate.checkProjectWritePermission(projectName); List<String> args = new ArrayList<String>(); @@ -112,15 +112,11 @@ public void updateHybridCubeNoCheck(String hybridName, String projectName, Strin } } - public void deleteHybridCube(String hybridName, String projectName, String modelName) { + public void deleteHybridInstance(String hybridName, String projectName) { aclEvaluate.checkProjectWritePermission(projectName); List<String> args = new ArrayList<String>(); args.add("-name"); args.add(hybridName); - args.add("-project"); - args.add(projectName); - args.add("-model"); - args.add(modelName); args.add("-action"); args.add("delete"); try { ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org > User interface for hybrid model > ------------------------------- > > Key: KYLIN-3418 > URL: https://issues.apache.org/jira/browse/KYLIN-3418 > Project: Kylin > Issue Type: Improvement > Components: Web > Reporter: Shaofeng SHI > Assignee: Roger > Priority: Major > Fix For: v2.5.0 > > > Hybrid model is useful for model change. While now there is no entry for it > from GUI, this makes many users don't see such feature. -- This message was sent by Atlassian JIRA (v7.6.3#76005)