You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kylin.apache.org by sh...@apache.org on 2018/07/26 10:57:57 UTC
[kylin] branch master updated: KYLIN-3418 Adjust hybrid API
This is an automated email from the ASF dual-hosted git repository.
shaofengshi pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kylin.git
The following commit(s) were added to refs/heads/master by this push:
new 88a242f KYLIN-3418 Adjust hybrid API
88a242f is described below
commit 88a242f514a9ea9ae44f5b22a213dcd3a0aefb0b
Author: chao long <wa...@qq.com>
AuthorDate: Thu Jul 26 11:45:00 2018 +0800
KYLIN-3418 Adjust hybrid API
---
.../kylin/storage/hybrid/HybridInstance.java | 15 ++++--
.../kylin/rest/controller/HybridController.java | 47 +++++++++++------
.../org/apache/kylin/rest/job/HybridCubeCLI.java | 39 +++++++-------
.../apache/kylin/rest/response/HybridRespone.java | 61 ++++++++++++++++++++++
.../apache/kylin/rest/service/HybridService.java | 10 ++--
5 files changed, 129 insertions(+), 43 deletions(-)
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 286af5f..5bb4450 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 java.util.Set;
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 class HybridInstance extends RootPersistentEntity implements IRealization
return hybridInstance;
}
-
+
// ============================================================================
@JsonIgnore
@@ -90,7 +92,7 @@ public class HybridInstance extends RootPersistentEntity implements IRealization
public String resourceName() {
return name;
}
-
+
public List<RealizationEntry> getRealizationEntries() {
return realizationEntries;
}
@@ -222,8 +224,15 @@ public class HybridInstance extends RootPersistentEntity implements IRealization
@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 f23f26c..c139b8d 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 @@ public class HybridController extends BasicController {
@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 1c8a46a..48e7f40 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 @@ public class HybridCubeCLI extends AbstractApplication {
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 @@ public class HybridCubeCLI extends AbstractApplication {
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 @@ public class HybridCubeCLI extends AbstractApplication {
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 @@ public class HybridCubeCLI extends AbstractApplication {
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 @@ public class HybridCubeCLI extends AbstractApplication {
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 @@ public class HybridCubeCLI extends AbstractApplication {
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 @@ public class HybridCubeCLI extends AbstractApplication {
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 0000000..745d4b1
--- /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 1b48082..9de5941 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 @@ public class HybridService extends BasicService {
@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 class HybridService extends BasicService {
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 class HybridService extends BasicService {
}
}
- 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 {