You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kylin.apache.org by zh...@apache.org on 2016/03/25 19:07:32 UTC
kylin git commit: External Filter Rest
Repository: kylin
Updated Branches:
refs/heads/master 068694191 -> 3b2ebd243
External Filter Rest
Project: http://git-wip-us.apache.org/repos/asf/kylin/repo
Commit: http://git-wip-us.apache.org/repos/asf/kylin/commit/3b2ebd24
Tree: http://git-wip-us.apache.org/repos/asf/kylin/tree/3b2ebd24
Diff: http://git-wip-us.apache.org/repos/asf/kylin/diff/3b2ebd24
Branch: refs/heads/master
Commit: 3b2ebd243cfe233ea7b1a80285f4c2110500bbe5
Parents: 0686941
Author: Jason <ji...@163.com>
Authored: Sat Mar 26 02:07:21 2016 +0800
Committer: Jason <ji...@163.com>
Committed: Sat Mar 26 02:07:21 2016 +0800
----------------------------------------------------------------------
.../controller/ExternalFilterController.java | 101 ++++++++++++++++++
.../rest/request/ExternalFilterRequest.java | 65 ++++++++++++
.../kylin/rest/service/ExtFilterService.java | 105 +++++++++++++++++++
3 files changed, 271 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/kylin/blob/3b2ebd24/server/src/main/java/org/apache/kylin/rest/controller/ExternalFilterController.java
----------------------------------------------------------------------
diff --git a/server/src/main/java/org/apache/kylin/rest/controller/ExternalFilterController.java b/server/src/main/java/org/apache/kylin/rest/controller/ExternalFilterController.java
new file mode 100644
index 0000000..b0b7569
--- /dev/null
+++ b/server/src/main/java/org/apache/kylin/rest/controller/ExternalFilterController.java
@@ -0,0 +1,101 @@
+/*
+ * 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.controller;
+
+import org.apache.kylin.common.util.JsonUtil;
+import org.apache.kylin.metadata.model.ExternalFilterDesc;
+import org.apache.kylin.rest.request.ExternalFilterRequest;
+import org.apache.kylin.rest.service.ExtFilterService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.*;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+
+/**
+ * @author jiazhong
+ */
+@Controller
+@RequestMapping(value = "/extFilter")
+public class ExternalFilterController extends BasicController {
+ private static final Logger logger = LoggerFactory.getLogger(ExternalFilterController.class);
+
+ @Autowired
+ private ExtFilterService extFilterService;
+
+
+
+ @RequestMapping(value = "/saveExtFilter", method = { RequestMethod.POST })
+ @ResponseBody
+ public Map<String, String> saveExternalFilter(@RequestBody ExternalFilterRequest request) throws IOException {
+ Map<String, String> result = new HashMap();
+ String filterProject = request.getProject();
+ ExternalFilterDesc desc = JsonUtil.readValue(request.getExtFilter(), ExternalFilterDesc.class);
+ desc.setUuid(UUID.randomUUID().toString());
+ extFilterService.saveExternalFilter(desc);
+ extFilterService.syncExtFilterToProject(new String[]{desc.getName()},filterProject);
+ result.put("success","true");
+ return result;
+ }
+
+ @RequestMapping(value = "/updateExtFilter", method = { RequestMethod.PUT })
+ @ResponseBody
+ public Map<String, String> updateExternalFilter(@RequestBody ExternalFilterRequest request) throws IOException {
+ Map<String, String> result = new HashMap();
+ ExternalFilterDesc desc = JsonUtil.readValue(request.getExtFilter(), ExternalFilterDesc.class);
+ extFilterService.updateExternalFilter(desc);
+ result.put("success","true");
+ return result;
+ }
+
+ @RequestMapping(value = "/{filter}/{project}", method = { RequestMethod.DELETE })
+ @ResponseBody
+ public Map<String, String> unLoadHiveTables(@PathVariable String filter, @PathVariable String project) throws IOException {
+ Map<String, String> result = new HashMap<String, String>();
+ extFilterService.removeExtFilterFromProject(filter,project);
+ extFilterService.removeExternalFilter(filter);
+ result.put("success", "true");
+ return result;
+ }
+
+
+ /**
+ * Get available table list of the input database
+ *
+ * @return Table metadata array
+ * @throws IOException
+ */
+ @RequestMapping(value = "", method = { RequestMethod.GET })
+ @ResponseBody
+ public List<ExternalFilterDesc> getExternalFilters(@RequestParam(value = "project", required = true) String project) throws IOException {
+ List<ExternalFilterDesc> filterDescs;
+ filterDescs = extFilterService.listProjectFilters(project);
+ return filterDescs;
+ }
+
+
+
+
+}
http://git-wip-us.apache.org/repos/asf/kylin/blob/3b2ebd24/server/src/main/java/org/apache/kylin/rest/request/ExternalFilterRequest.java
----------------------------------------------------------------------
diff --git a/server/src/main/java/org/apache/kylin/rest/request/ExternalFilterRequest.java b/server/src/main/java/org/apache/kylin/rest/request/ExternalFilterRequest.java
new file mode 100644
index 0000000..6b4e297
--- /dev/null
+++ b/server/src/main/java/org/apache/kylin/rest/request/ExternalFilterRequest.java
@@ -0,0 +1,65 @@
+/*
+ * 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.request;
+
+public class ExternalFilterRequest {
+
+ private String project;
+
+ private String extFilter;
+
+ private boolean successful;
+
+ private String message;
+
+ public String getProject() {
+ return project;
+ }
+
+ public void setProject(String project) {
+ this.project = project;
+ }
+
+
+ public boolean isSuccessful() {
+ return successful;
+ }
+
+ public String getExtFilter() {
+ return extFilter;
+ }
+
+ public void setExtFilter(String extFilter) {
+ this.extFilter = extFilter;
+ }
+
+ public void setSuccessful(boolean successful) {
+ this.successful = successful;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+
+ public void setMessage(String message) {
+ this.message = message;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/kylin/blob/3b2ebd24/server/src/main/java/org/apache/kylin/rest/service/ExtFilterService.java
----------------------------------------------------------------------
diff --git a/server/src/main/java/org/apache/kylin/rest/service/ExtFilterService.java b/server/src/main/java/org/apache/kylin/rest/service/ExtFilterService.java
new file mode 100644
index 0000000..f41996d
--- /dev/null
+++ b/server/src/main/java/org/apache/kylin/rest/service/ExtFilterService.java
@@ -0,0 +1,105 @@
+/*
+ * 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.service;
+
+
+import com.google.common.collect.Lists;
+import org.apache.kylin.metadata.model.ExternalFilterDesc;
+import org.apache.kylin.metadata.project.ProjectInstance;
+import org.apache.kylin.rest.constant.Constant;
+import org.apache.kylin.rest.exception.InternalErrorException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.stereotype.Component;
+
+import java.io.IOException;
+import java.util.List;
+
+/**
+ * Stateless & lightweight service facade of cube management functions.
+ *
+ * @author jiazhong
+ */
+@Component("extFilterService")
+public class ExtFilterService extends BasicService {
+ private static final Logger logger = LoggerFactory.getLogger(ExtFilterService.class);
+
+
+ @Autowired
+ private AccessService accessService;
+
+
+
+ public List<ExternalFilterDesc> listProjectFilters(String project) throws IOException {
+ List<ExternalFilterDesc> filterDescs = Lists.newArrayList();
+ if(project == null){
+ return filterDescs;
+ }
+ ProjectInstance projectInstance = getProjectManager().getProject(project);
+ for(String filter:projectInstance.getExtFilters()){
+ ExternalFilterDesc filterDesc = getMetadataManager().getExtFilterDesc(filter);
+ if(filterDesc!=null){
+ filterDescs.add(filterDesc);
+ }
+ }
+ return filterDescs;
+ }
+
+ @PreAuthorize(Constant.ACCESS_HAS_ROLE_ADMIN)
+ public void saveExternalFilter(ExternalFilterDesc desc) throws IOException {
+ if(getMetadataManager().getExtFilterDesc(desc.getName()) != null){
+ throw new InternalErrorException("The filter named " + desc.getName() + " already exists");
+ }
+ getMetadataManager().saveExternalFilter(desc);
+ }
+
+ @PreAuthorize(Constant.ACCESS_HAS_ROLE_ADMIN)
+ public void updateExternalFilter(ExternalFilterDesc desc) throws IOException {
+ if(getMetadataManager().getExtFilterDesc(desc.getName()) == null){
+ throw new InternalErrorException("The filter named " + desc.getName() + " does not exists");
+ }
+ getMetadataManager().saveExternalFilter(desc);
+ }
+
+
+ @PreAuthorize(Constant.ACCESS_HAS_ROLE_ADMIN)
+ public void removeExternalFilter(String name) throws IOException {
+ getMetadataManager().removeExternalFilter(name);
+ }
+
+
+
+ @PreAuthorize(Constant.ACCESS_HAS_ROLE_ADMIN)
+ public void syncExtFilterToProject(String[] filters, String project) throws IOException {
+ getProjectManager().addExtFilterToProject(filters, project);
+ }
+
+ @PreAuthorize(Constant.ACCESS_HAS_ROLE_ADMIN)
+ public void removeExtFilterFromProject(String filterName, String projectName) throws IOException {
+ getProjectManager().removeExtFilterFromProject(filterName, projectName);
+ }
+
+ @PreAuthorize(Constant.ACCESS_HAS_ROLE_ADMIN)
+ public List<ExternalFilterDesc> listAllExternalFilters(){
+ return getMetadataManager().listAllExternalFilters();
+ }
+
+}