You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kylin.apache.org by li...@apache.org on 2017/09/15 14:42:37 UTC
[17/48] kylin git commit: KYLIN-2854 Remove duplicated controllers
http://git-wip-us.apache.org/repos/asf/kylin/blob/92306639/server-base/src/main/java/org/apache/kylin/rest/controller2/ModelControllerV2.java
----------------------------------------------------------------------
diff --git a/server-base/src/main/java/org/apache/kylin/rest/controller2/ModelControllerV2.java b/server-base/src/main/java/org/apache/kylin/rest/controller2/ModelControllerV2.java
deleted file mode 100644
index 12cd717..0000000
--- a/server-base/src/main/java/org/apache/kylin/rest/controller2/ModelControllerV2.java
+++ /dev/null
@@ -1,335 +0,0 @@
-/*
- * 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.controller2;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.apache.commons.lang.StringUtils;
-import org.apache.kylin.common.KylinConfig;
-import org.apache.kylin.common.util.JsonUtil;
-import org.apache.kylin.cube.CubeInstance;
-import org.apache.kylin.metadata.MetadataManager;
-import org.apache.kylin.metadata.draft.Draft;
-import org.apache.kylin.metadata.draft.DraftManager;
-import org.apache.kylin.metadata.model.DataModelDesc;
-import org.apache.kylin.metadata.model.TblColRef;
-import org.apache.kylin.metadata.project.ProjectInstance;
-import org.apache.kylin.rest.controller.BasicController;
-import org.apache.kylin.rest.exception.BadRequestException;
-import org.apache.kylin.rest.msg.Message;
-import org.apache.kylin.rest.msg.MsgPicker;
-import org.apache.kylin.rest.request.ModelRequest;
-import org.apache.kylin.rest.response.DataModelDescResponse;
-import org.apache.kylin.rest.response.EnvelopeResponse;
-import org.apache.kylin.rest.response.GeneralResponse;
-import org.apache.kylin.rest.response.ResponseCode;
-import org.apache.kylin.rest.service.CacheService;
-import org.apache.kylin.rest.service.ModelService;
-import org.apache.kylin.rest.service.ProjectService;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Qualifier;
-import org.springframework.stereotype.Controller;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.ResponseBody;
-
-import com.fasterxml.jackson.core.JsonParseException;
-import com.fasterxml.jackson.databind.JsonMappingException;
-import com.google.common.base.Preconditions;
-import com.google.common.collect.Sets;
-
-/**
- * ModelController is defined as Restful API entrance for UI.
- *
- * @author jiazhong
- */
-@Controller
-@RequestMapping(value = "/models")
-public class ModelControllerV2 extends BasicController {
- private static final Logger logger = LoggerFactory.getLogger(ModelControllerV2.class);
-
- public static final char[] VALID_MODELNAME = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890_"
- .toCharArray();
-
- @Autowired
- @Qualifier("modelMgmtService")
- private ModelService modelService;
-
- @Autowired
- @Qualifier("projectService")
- private ProjectService projectService;
-
- @Autowired
- @Qualifier("cacheService")
- private CacheService cacheService;
-
- @RequestMapping(value = "", method = { RequestMethod.GET }, produces = { "application/vnd.apache.kylin-v2+json" })
- @ResponseBody
- public EnvelopeResponse getModelsPaging(@RequestParam(value = "modelName", required = false) String modelName,
- @RequestParam(value = "exactMatch", required = false, defaultValue = "true") boolean exactMatch,
- @RequestParam(value = "projectName", required = false) String projectName,
- @RequestParam(value = "pageOffset", required = false, defaultValue = "0") Integer pageOffset,
- @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize)
- throws IOException {
-
- List<DataModelDescResponse> response = new ArrayList<DataModelDescResponse>();
-
- // official models
- for (DataModelDesc m : modelService.listAllModels(modelName, projectName, exactMatch)) {
- Preconditions.checkState(!m.isDraft());
-
- DataModelDescResponse r = new DataModelDescResponse(m);
- r.setProject(projectService.getProjectOfModel(m.getName()));
- response.add(r);
- }
-
- // draft models
- for (Draft d : modelService.listModelDrafts(modelName, projectName)) {
- DataModelDesc m = (DataModelDesc) d.getEntity();
- Preconditions.checkState(m.isDraft());
-
- if (contains(response, m.getName()) == false) {
- DataModelDescResponse r = new DataModelDescResponse(m);
- r.setProject(d.getProject());
- response.add(r);
- }
- }
-
- int offset = pageOffset * pageSize;
- int limit = pageSize;
- int size = response.size();
-
- if (size <= offset) {
- offset = size;
- limit = 0;
- }
-
- if ((size - offset) < limit) {
- limit = size - offset;
- }
- HashMap<String, Object> data = new HashMap<String, Object>();
- data.put("models", response.subList(offset, offset + limit));
- data.put("size", size);
-
- return new EnvelopeResponse(ResponseCode.CODE_SUCCESS, data, "");
- }
-
- private boolean contains(List<DataModelDescResponse> response, String name) {
- for (DataModelDescResponse m : response) {
- if (m.getName().equals(name))
- return true;
- }
- return false;
- }
-
- @RequestMapping(value = "", method = { RequestMethod.PUT }, produces = { "application/vnd.apache.kylin-v2+json" })
- @ResponseBody
- public EnvelopeResponse updateModelDescV2(@RequestBody ModelRequest modelRequest) throws IOException {
- DraftManager draftMgr = modelService.getDraftManager();
-
- DataModelDesc modelDesc = deserializeDataModelDescV2(modelRequest);
- modelService.primaryCheck(modelDesc);
-
- String project = (null == modelRequest.getProject()) ? ProjectInstance.DEFAULT_PROJECT_NAME
- : modelRequest.getProject();
-
- // don't use checkpoint/rollback, the following update is the only change that must succeed
-
- // save/update model
- modelDesc = modelService.updateModelToResourceStore(modelDesc, project);
-
- // remove any previous draft
- draftMgr.delete(modelDesc.getUuid());
-
- String descData = JsonUtil.writeValueAsIndentString(modelDesc);
- GeneralResponse data = new GeneralResponse();
- data.setProperty("uuid", modelDesc.getUuid());
- data.setProperty("modelDescData", descData);
-
- return new EnvelopeResponse(ResponseCode.CODE_SUCCESS, data, "");
- }
-
- @RequestMapping(value = "/validness", method = { RequestMethod.POST }, produces = {
- "application/vnd.apache.kylin-v2+json" })
- @ResponseBody
- public EnvelopeResponse checkModel(@RequestBody ModelRequest modelRequest) throws IOException {
- Preconditions.checkNotNull(modelRequest.getProject());
- Preconditions.checkNotNull(modelRequest.getModelDescData());
-
- DataModelDesc modelDesc = deserializeDataModelDescV2(modelRequest);
- modelService.primaryCheck(modelDesc);
- modelService.checkCCExpression(modelDesc, modelRequest.getProject());
-
- return new EnvelopeResponse(ResponseCode.CODE_SUCCESS, null, "");
- }
-
- @RequestMapping(value = "/draft", method = { RequestMethod.PUT }, produces = {
- "application/vnd.apache.kylin-v2+json" })
- @ResponseBody
- public EnvelopeResponse updateModelDescDraftV2(@RequestBody ModelRequest modelRequest) throws IOException {
- DraftManager draftMgr = modelService.getDraftManager();
-
- DataModelDesc modelDesc = deserializeDataModelDescV2(modelRequest);
- modelService.primaryCheck(modelDesc);
-
- String project = (null == modelRequest.getProject()) ? ProjectInstance.DEFAULT_PROJECT_NAME
- : modelRequest.getProject();
-
- if (modelDesc.getUuid() == null)
- modelDesc.updateRandomUuid();
- modelDesc.setDraft(true);
-
- draftMgr.save(project, modelDesc.getUuid(), modelDesc);
-
- String descData = JsonUtil.writeValueAsIndentString(modelDesc);
- GeneralResponse data = new GeneralResponse();
- data.setProperty("uuid", modelDesc.getUuid());
- data.setProperty("modelDescData", descData);
-
- return new EnvelopeResponse(ResponseCode.CODE_SUCCESS, data, "");
- }
-
- @RequestMapping(value = "/{projectName}/{modelName}", method = { RequestMethod.DELETE }, produces = {
- "application/vnd.apache.kylin-v2+json" })
- @ResponseBody
- public void deleteModelV2(@PathVariable String projectName, @PathVariable String modelName) throws IOException {
- Message msg = MsgPicker.getMsg();
-
- DataModelDesc model = modelService.getModel(modelName, projectName);
- Draft draft = modelService.getModelDraft(modelName, projectName);
- if (null == model && null == draft)
- throw new BadRequestException(String.format(msg.getMODEL_NOT_FOUND(), modelName));
-
- if (model != null)
- modelService.dropModel(model);
-
- if (draft != null)
- modelService.getDraftManager().delete(draft.getUuid());
- }
-
- @RequestMapping(value = "/{modelName}/clone", method = { RequestMethod.PUT }, produces = {
- "application/vnd.apache.kylin-v2+json" })
- @ResponseBody
- public EnvelopeResponse cloneModelV2(@PathVariable String modelName, @RequestBody ModelRequest modelRequest)
- throws IOException {
- Message msg = MsgPicker.getMsg();
-
- String project = modelRequest.getProject();
- MetadataManager metaManager = MetadataManager.getInstance(KylinConfig.getInstanceFromEnv());
- DataModelDesc modelDesc = metaManager.getDataModelDesc(modelName);
- String newModelName = modelRequest.getModelName();
-
- if (StringUtils.isEmpty(project)) {
- logger.info("Project name should not be empty.");
- throw new BadRequestException(msg.getEMPTY_PROJECT_NAME());
- }
-
- if (modelDesc == null || StringUtils.isEmpty(modelName)) {
- throw new BadRequestException(msg.getEMPTY_MODEL_NAME());
- }
-
- if (StringUtils.isEmpty(newModelName)) {
- logger.info("New model name is empty.");
- throw new BadRequestException(msg.getEMPTY_NEW_MODEL_NAME());
- }
- if (!StringUtils.containsOnly(newModelName, VALID_MODELNAME)) {
- logger.info("Invalid Model name {}, only letters, numbers and underline supported.", newModelName);
- throw new BadRequestException(String.format(msg.getINVALID_MODEL_NAME(), newModelName));
- }
-
- DataModelDesc newModelDesc = DataModelDesc.getCopyOf(modelDesc);
- newModelDesc.setName(newModelName);
-
- newModelDesc = modelService.createModelDesc(project, newModelDesc);
-
- //reload avoid shallow
- metaManager.reloadDataModelDescAt(DataModelDesc.concatResourcePath(newModelName));
-
- String descData = JsonUtil.writeValueAsIndentString(newModelDesc);
- GeneralResponse data = new GeneralResponse();
- data.setProperty("uuid", newModelDesc.getUuid());
- data.setProperty("modelDescData", descData);
-
- return new EnvelopeResponse(ResponseCode.CODE_SUCCESS, data, "");
- }
-
- private DataModelDesc deserializeDataModelDescV2(ModelRequest modelRequest) throws IOException {
- Message msg = MsgPicker.getMsg();
-
- DataModelDesc desc = null;
- try {
- logger.debug("deserialize MODEL " + modelRequest.getModelDescData());
- desc = JsonUtil.readValue(modelRequest.getModelDescData(), DataModelDesc.class);
- } catch (JsonParseException e) {
- logger.error("The data model definition is not valid.", e);
- throw new BadRequestException(msg.getINVALID_MODEL_DEFINITION());
- } catch (JsonMappingException e) {
- logger.error("The data model definition is not valid.", e);
- throw new BadRequestException(msg.getINVALID_MODEL_DEFINITION());
- }
- return desc;
- }
-
- @RequestMapping(value = "/{modelName}/{projectName}/usedCols", method = RequestMethod.GET, produces = {
- "application/vnd.apache.kylin-v2+json" })
- @ResponseBody
- public EnvelopeResponse getUsedColsV2(@PathVariable String projectName, @PathVariable String modelName) {
-
- Map<String, Set<String>> data = new HashMap<>();
-
- for (Map.Entry<TblColRef, Set<CubeInstance>> entry : modelService.getUsedDimCols(modelName, projectName)
- .entrySet()) {
- populateUsedColResponse(entry.getKey(), entry.getValue(), data);
- }
-
- for (Map.Entry<TblColRef, Set<CubeInstance>> entry : modelService.getUsedNonDimCols(modelName, projectName)
- .entrySet()) {
- populateUsedColResponse(entry.getKey(), entry.getValue(), data);
- }
-
- return new EnvelopeResponse(ResponseCode.CODE_SUCCESS, data, "");
- }
-
- private void populateUsedColResponse(TblColRef tblColRef, Set<CubeInstance> cubeInstances,
- Map<String, Set<String>> ret) {
- String columnIdentity = tblColRef.getIdentity();
- if (!ret.containsKey(columnIdentity)) {
- ret.put(columnIdentity, Sets.<String> newHashSet());
- }
-
- for (CubeInstance cubeInstance : cubeInstances) {
- ret.get(columnIdentity).add(cubeInstance.getCanonicalName());
- }
- }
-
- public void setModelService(ModelService modelService) {
- this.modelService = modelService;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/kylin/blob/92306639/server-base/src/main/java/org/apache/kylin/rest/controller2/ModelDescControllerV2.java
----------------------------------------------------------------------
diff --git a/server-base/src/main/java/org/apache/kylin/rest/controller2/ModelDescControllerV2.java b/server-base/src/main/java/org/apache/kylin/rest/controller2/ModelDescControllerV2.java
deleted file mode 100644
index 88089f5..0000000
--- a/server-base/src/main/java/org/apache/kylin/rest/controller2/ModelDescControllerV2.java
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * 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.controller2;
-
-import java.io.IOException;
-import java.util.HashMap;
-
-import org.apache.kylin.common.KylinConfig;
-import org.apache.kylin.metadata.MetadataManager;
-import org.apache.kylin.metadata.draft.Draft;
-import org.apache.kylin.metadata.model.DataModelDesc;
-import org.apache.kylin.rest.controller.BasicController;
-import org.apache.kylin.rest.exception.BadRequestException;
-import org.apache.kylin.rest.msg.Message;
-import org.apache.kylin.rest.msg.MsgPicker;
-import org.apache.kylin.rest.response.DataModelDescResponse;
-import org.apache.kylin.rest.response.EnvelopeResponse;
-import org.apache.kylin.rest.response.ResponseCode;
-import org.apache.kylin.rest.service.ModelService;
-import org.apache.kylin.rest.service.ProjectService;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Qualifier;
-import org.springframework.stereotype.Controller;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.ResponseBody;
-
-import com.google.common.base.Preconditions;
-
-/**
- * @author jiazhong
- *
- */
-@Controller
-@RequestMapping(value = "/model_desc")
-public class ModelDescControllerV2 extends BasicController {
-
- @Autowired
- @Qualifier("modelMgmtService")
- private ModelService modelService;
-
- @Autowired
- @Qualifier("projectService")
- private ProjectService projectService;
-
- /**
- * Get detail information of the "Model ID"
- *
- * @param modelName
- * Model ID
- * @return
- * @throws IOException
- */
- @RequestMapping(value = "/{projectName}/{modelName}", method = { RequestMethod.GET }, produces = {
- "application/vnd.apache.kylin-v2+json" })
- @ResponseBody
- public EnvelopeResponse getModelV2(@PathVariable String projectName, @PathVariable String modelName) throws IOException {
- Message msg = MsgPicker.getMsg();
-
- KylinConfig config = KylinConfig.getInstanceFromEnv();
- MetadataManager metaMgr = MetadataManager.getInstance(config);
-
- DataModelDesc model = modelService.getModel(modelName, projectName);
- Draft draft = modelService.getModelDraft(modelName, projectName);
-
- if (model == null && draft == null)
- throw new BadRequestException(String.format(msg.getMODEL_NOT_FOUND(), modelName));
-
- // figure out project
- String project = null;
- if (model != null) {
- project = projectService.getProjectOfModel(modelName);
- } else {
- project = draft.getProject();
- }
-
- // result
- HashMap<String, DataModelDescResponse> result = new HashMap<String, DataModelDescResponse>();
- if (model != null) {
- Preconditions.checkState(!model.isDraft());
- DataModelDescResponse r = new DataModelDescResponse(model);
- r.setProject(project);
- result.put("model", r);
- }
- if (draft != null) {
- DataModelDesc dm = (DataModelDesc) draft.getEntity();
- Preconditions.checkState(dm.isDraft());
- DataModelDescResponse r = new DataModelDescResponse(dm);
- r.setProject(project);
- result.put("draft", r);
- }
-
- return new EnvelopeResponse(ResponseCode.CODE_SUCCESS, result, "");
- }
-
-}
http://git-wip-us.apache.org/repos/asf/kylin/blob/92306639/server-base/src/main/java/org/apache/kylin/rest/controller2/ProjectControllerV2.java
----------------------------------------------------------------------
diff --git a/server-base/src/main/java/org/apache/kylin/rest/controller2/ProjectControllerV2.java b/server-base/src/main/java/org/apache/kylin/rest/controller2/ProjectControllerV2.java
deleted file mode 100644
index d6ac8f2..0000000
--- a/server-base/src/main/java/org/apache/kylin/rest/controller2/ProjectControllerV2.java
+++ /dev/null
@@ -1,180 +0,0 @@
-/*
- * 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.controller2;
-
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.List;
-
-import org.apache.commons.lang.StringUtils;
-import org.apache.kylin.common.util.JsonUtil;
-import org.apache.kylin.metadata.project.ProjectInstance;
-import org.apache.kylin.rest.controller.BasicController;
-import org.apache.kylin.rest.exception.BadRequestException;
-import org.apache.kylin.rest.msg.Message;
-import org.apache.kylin.rest.msg.MsgPicker;
-import org.apache.kylin.rest.request.ProjectRequest;
-import org.apache.kylin.rest.response.EnvelopeResponse;
-import org.apache.kylin.rest.response.ResponseCode;
-import org.apache.kylin.rest.service.CubeService;
-import org.apache.kylin.rest.service.ModelService;
-import org.apache.kylin.rest.service.ProjectService;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Qualifier;
-import org.springframework.stereotype.Controller;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.ResponseBody;
-
-/**
- * @author xduo
- */
-@Controller
-@RequestMapping(value = "/projects")
-public class ProjectControllerV2 extends BasicController {
- private static final Logger logger = LoggerFactory.getLogger(ProjectControllerV2.class);
-
- private static final char[] VALID_PROJECTNAME = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890_"
- .toCharArray();
-
- @Autowired
- @Qualifier("projectService")
- private ProjectService projectService;
-
- @Autowired
- @Qualifier("cubeMgmtService")
- private CubeService cubeService;
-
- @Autowired
- @Qualifier("modelMgmtService")
- private ModelService modelService;
-
- @RequestMapping(value = "", method = { RequestMethod.GET }, produces = {
- "application/vnd.apache.kylin-v2+json" })
- @ResponseBody
- public EnvelopeResponse getReadableProjectsV2(
- @RequestParam(value = "projectName", required = false) String projectName,
- @RequestParam(value = "pageOffset", required = false, defaultValue = "0") Integer pageOffset,
- @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize) {
-
- HashMap<String, Object> data = new HashMap<String, Object>();
-
- List<ProjectInstance> readableProjects = projectService.getReadableProjects(projectName);
- int offset = pageOffset * pageSize;
- int limit = pageSize;
-
- if (readableProjects.size() <= offset) {
- offset = readableProjects.size();
- limit = 0;
- }
-
- if ((readableProjects.size() - offset) < limit) {
- limit = readableProjects.size() - offset;
- }
- data.put("projects", readableProjects.subList(offset, offset + limit));
- data.put("size", readableProjects.size());
-
- return new EnvelopeResponse(ResponseCode.CODE_SUCCESS, data, "");
- }
-
- @RequestMapping(value = "", method = { RequestMethod.POST }, produces = { "application/vnd.apache.kylin-v2+json" })
- @ResponseBody
- public EnvelopeResponse saveProjectV2(@RequestBody ProjectRequest projectRequest) throws IOException {
- Message msg = MsgPicker.getMsg();
-
- ProjectInstance projectDesc = deserializeProjectDescV2(projectRequest);
-
- if (StringUtils.isEmpty(projectDesc.getName())) {
- throw new BadRequestException(msg.getEMPTY_PROJECT_NAME());
- }
-
- if (!StringUtils.containsOnly(projectDesc.getName(), VALID_PROJECTNAME)) {
- logger.info("Invalid Project name {}, only letters, numbers and underline supported.",
- projectDesc.getName());
- throw new BadRequestException(String.format(msg.getINVALID_PROJECT_NAME(), projectDesc.getName()));
- }
-
- ProjectInstance createdProj = null;
- createdProj = projectService.createProject(projectDesc);
-
- return new EnvelopeResponse(ResponseCode.CODE_SUCCESS, createdProj, "");
- }
-
- @RequestMapping(value = "", method = { RequestMethod.PUT }, produces = { "application/vnd.apache.kylin-v2+json" })
- @ResponseBody
- public EnvelopeResponse updateProjectV2(@RequestBody ProjectRequest projectRequest) throws IOException {
- Message msg = MsgPicker.getMsg();
-
- String formerProjectName = projectRequest.getFormerProjectName();
- if (StringUtils.isEmpty(formerProjectName)) {
- throw new BadRequestException(msg.getEMPTY_PROJECT_NAME());
- }
-
- ProjectInstance projectDesc = deserializeProjectDescV2(projectRequest);
-
- ProjectInstance currentProject = projectService.getProjectManager().getProject(formerProjectName);
- if (currentProject == null) {
- throw new BadRequestException(String.format(msg.getPROJECT_NOT_FOUND(), formerProjectName));
- }
-
- ProjectInstance updatedProj;
- if (projectDesc.getName().equals(currentProject.getName())) {
- updatedProj = projectService.updateProject(projectDesc, currentProject);
- } else {
- if (!isProjectEmpty(formerProjectName)) {
- throw new BadRequestException(msg.getDELETE_PROJECT_NOT_EMPTY());
- }
- // disable project rename
- updatedProj = projectService.renameProject(projectDesc, currentProject);
- }
- return new EnvelopeResponse(ResponseCode.CODE_SUCCESS, updatedProj, "");
- }
-
- private ProjectInstance deserializeProjectDescV2(ProjectRequest projectRequest) throws IOException {
- logger.debug("Saving project " + projectRequest.getProjectDescData());
- ProjectInstance projectDesc = JsonUtil.readValue(projectRequest.getProjectDescData(), ProjectInstance.class);
- return projectDesc;
- }
-
- @RequestMapping(value = "/{projectName}", method = { RequestMethod.DELETE }, produces = {
- "application/vnd.apache.kylin-v2+json" })
- @ResponseBody
- public void deleteProjectV2(@PathVariable String projectName) throws IOException {
- Message msg = MsgPicker.getMsg();
- ProjectInstance project = projectService.getProjectManager().getProject(projectName);
- if (!isProjectEmpty(projectName)) {
- throw new BadRequestException(msg.getDELETE_PROJECT_NOT_EMPTY());
- }
-
- projectService.deleteProject(projectName, project);
- }
-
- private boolean isProjectEmpty(String projectName) throws IOException {
- return cubeService.listAllCubes(projectName).isEmpty()
- && cubeService.listCubeDrafts(null, null, projectName, true).isEmpty()
- && modelService.listAllModels(null, projectName, false).isEmpty()
- && modelService.listModelDrafts(null, projectName).isEmpty();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/kylin/blob/92306639/server-base/src/main/java/org/apache/kylin/rest/controller2/QueryControllerV2.java
----------------------------------------------------------------------
diff --git a/server-base/src/main/java/org/apache/kylin/rest/controller2/QueryControllerV2.java b/server-base/src/main/java/org/apache/kylin/rest/controller2/QueryControllerV2.java
deleted file mode 100644
index 1aa72ba..0000000
--- a/server-base/src/main/java/org/apache/kylin/rest/controller2/QueryControllerV2.java
+++ /dev/null
@@ -1,212 +0,0 @@
-/*
- * 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.controller2;
-
-import java.io.IOException;
-import java.io.OutputStreamWriter;
-import java.io.Writer;
-import java.nio.charset.StandardCharsets;
-import java.sql.SQLException;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import javax.servlet.http.HttpServletResponse;
-
-import org.apache.commons.io.IOUtils;
-import org.apache.kylin.common.debug.BackdoorToggles;
-import org.apache.kylin.metadata.querymeta.SelectedColumnMeta;
-import org.apache.kylin.rest.controller.BasicController;
-import org.apache.kylin.rest.exception.InternalErrorException;
-import org.apache.kylin.rest.model.Query;
-import org.apache.kylin.rest.request.MetaRequest;
-import org.apache.kylin.rest.request.PrepareSqlRequest;
-import org.apache.kylin.rest.request.SQLRequest;
-import org.apache.kylin.rest.request.SaveSqlRequest;
-import org.apache.kylin.rest.response.EnvelopeResponse;
-import org.apache.kylin.rest.response.ResponseCode;
-import org.apache.kylin.rest.response.SQLResponse;
-import org.apache.kylin.rest.service.QueryService;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Qualifier;
-import org.springframework.http.MediaType;
-import org.springframework.security.core.context.SecurityContextHolder;
-import org.springframework.stereotype.Controller;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.ResponseBody;
-import org.supercsv.io.CsvListWriter;
-import org.supercsv.io.ICsvListWriter;
-import org.supercsv.prefs.CsvPreference;
-
-import com.google.common.collect.Maps;
-
-/**
- * Handle query requests.
- *
- * @author xduo
- */
-@Controller
-public class QueryControllerV2 extends BasicController {
-
- @SuppressWarnings("unused")
- private static final Logger logger = LoggerFactory.getLogger(QueryControllerV2.class);
-
- @Autowired
- @Qualifier("queryService")
- private QueryService queryService;
-
- @RequestMapping(value = "/query", method = RequestMethod.POST, produces = {
- "application/vnd.apache.kylin-v2+json" })
- @ResponseBody
- public EnvelopeResponse queryV2(@RequestBody SQLRequest sqlRequest) {
-
- return new EnvelopeResponse(ResponseCode.CODE_SUCCESS, queryService.doQueryWithCache(sqlRequest), "");
- }
-
- // TODO should be just "prepare" a statement, get back expected ResultSetMetaData
-
- @RequestMapping(value = "/query/prestate", method = RequestMethod.POST, produces = {
- "application/vnd.apache.kylin-v2+json" })
- @ResponseBody
- public EnvelopeResponse prepareQueryV2(@RequestBody PrepareSqlRequest sqlRequest) {
- Map<String, String> newToggles = Maps.newHashMap();
- if (sqlRequest.getBackdoorToggles() != null)
- newToggles.putAll(sqlRequest.getBackdoorToggles());
- newToggles.put(BackdoorToggles.DEBUG_TOGGLE_PREPARE_ONLY, "true");
- sqlRequest.setBackdoorToggles(newToggles);
-
- return new EnvelopeResponse(ResponseCode.CODE_SUCCESS, queryService.doQueryWithCache(sqlRequest), "");
- }
-
- @RequestMapping(value = "/saved_queries", method = RequestMethod.POST, produces = {
- "application/vnd.apache.kylin-v2+json" })
- @ResponseBody
- public void saveQueryV2(@RequestBody SaveSqlRequest sqlRequest) throws IOException {
-
- String creator = SecurityContextHolder.getContext().getAuthentication().getName();
- Query newQuery = new Query(sqlRequest.getName(), sqlRequest.getProject(), sqlRequest.getSql(),
- sqlRequest.getDescription());
-
- queryService.saveQuery(creator, newQuery);
- }
-
- @RequestMapping(value = "/saved_queries/{id}", method = RequestMethod.DELETE, produces = {
- "application/vnd.apache.kylin-v2+json" })
- @ResponseBody
- public void removeQueryV2(@PathVariable String id) throws IOException {
-
- String creator = SecurityContextHolder.getContext().getAuthentication().getName();
- queryService.removeQuery(creator, id);
- }
-
- @RequestMapping(value = "/saved_queries", method = RequestMethod.GET, produces = {
- "application/vnd.apache.kylin-v2+json" })
- @ResponseBody
- public EnvelopeResponse getQueriesV2(@RequestParam(value = "project", required = false) String project,
- @RequestParam(value = "pageOffset", required = false, defaultValue = "0") Integer pageOffset,
- @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize)
- throws IOException {
-
- HashMap<String, Object> data = new HashMap<String, Object>();
- String creator = SecurityContextHolder.getContext().getAuthentication().getName();
- List<Query> queries = new ArrayList<Query>();
- for (Query query : queryService.getQueries(creator)) {
- if (project == null || query.getProject().equals(project))
- queries.add(query);
- }
-
- int offset = pageOffset * pageSize;
- int limit = pageSize;
-
- if (queries.size() <= offset) {
- offset = queries.size();
- limit = 0;
- }
-
- if ((queries.size() - offset) < limit) {
- limit = queries.size() - offset;
- }
-
- data.put("queries", queries.subList(offset, offset + limit));
- data.put("size", queries.size());
-
- return new EnvelopeResponse(ResponseCode.CODE_SUCCESS, data, "");
- }
-
- @RequestMapping(value = "/query/format/{format}", method = RequestMethod.POST, produces = {
- "application/vnd.apache.kylin-v2+json" }, consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
- @ResponseBody
- public void downloadQueryResultV2(@PathVariable String format, SQLRequest sqlRequest,
- HttpServletResponse response) throws IOException {
-
- SQLResponse result = queryService.doQueryWithCache(sqlRequest);
-
- SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
- String nowStr = sdf.format(new Date());
- response.setContentType("text/" + format + ";charset=utf-8");
- response.setHeader("Content-Disposition", "attachment; filename=\"" + nowStr + ".result." + format + "\"");
- ICsvListWriter csvWriter = null;
-
- try {
- //Add a BOM for Excel
- Writer writer = new OutputStreamWriter(response.getOutputStream(), StandardCharsets.UTF_8);
- writer.write('\uFEFF');
-
- csvWriter = new CsvListWriter(writer, CsvPreference.STANDARD_PREFERENCE);
- List<String> headerList = new ArrayList<String>();
-
- for (SelectedColumnMeta column : result.getColumnMetas()) {
- headerList.add(column.getLabel());
- }
-
- String[] headers = new String[headerList.size()];
- csvWriter.writeHeader(headerList.toArray(headers));
-
- for (List<String> row : result.getResults()) {
- csvWriter.write(row);
- }
- } catch (IOException e) {
- throw new InternalErrorException(e);
- } finally {
- IOUtils.closeQuietly(csvWriter);
- }
- }
-
- @RequestMapping(value = "/tables_and_columns", method = RequestMethod.GET, produces = {
- "application/vnd.apache.kylin-v2+json" })
- @ResponseBody
- public EnvelopeResponse getMetadataV2(MetaRequest metaRequest) throws SQLException, IOException {
-
- return new EnvelopeResponse(ResponseCode.CODE_SUCCESS, queryService.getMetadataV2(metaRequest.getProject()),
- "");
- }
-
- public void setQueryService(QueryService queryService) {
- this.queryService = queryService;
- }
-}
http://git-wip-us.apache.org/repos/asf/kylin/blob/92306639/server-base/src/main/java/org/apache/kylin/rest/controller2/StreamingControllerV2.java
----------------------------------------------------------------------
diff --git a/server-base/src/main/java/org/apache/kylin/rest/controller2/StreamingControllerV2.java b/server-base/src/main/java/org/apache/kylin/rest/controller2/StreamingControllerV2.java
deleted file mode 100644
index 90f2a45..0000000
--- a/server-base/src/main/java/org/apache/kylin/rest/controller2/StreamingControllerV2.java
+++ /dev/null
@@ -1,297 +0,0 @@
-/*
- * 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.controller2;
-
-import java.io.IOException;
-import java.util.UUID;
-
-import org.apache.commons.lang.StringUtils;
-import org.apache.kylin.common.util.HadoopUtil;
-import org.apache.kylin.common.util.JsonUtil;
-import org.apache.kylin.metadata.model.TableDesc;
-import org.apache.kylin.metadata.streaming.StreamingConfig;
-import org.apache.kylin.rest.controller.BasicController;
-import org.apache.kylin.rest.exception.BadRequestException;
-import org.apache.kylin.rest.exception.ForbiddenException;
-import org.apache.kylin.rest.exception.InternalErrorException;
-import org.apache.kylin.rest.msg.Message;
-import org.apache.kylin.rest.msg.MsgPicker;
-import org.apache.kylin.rest.request.StreamingRequest;
-import org.apache.kylin.rest.response.EnvelopeResponse;
-import org.apache.kylin.rest.response.ResponseCode;
-import org.apache.kylin.rest.service.KafkaConfigService;
-import org.apache.kylin.rest.service.StreamingService;
-import org.apache.kylin.rest.service.TableService;
-import org.apache.kylin.source.kafka.config.KafkaConfig;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Qualifier;
-import org.springframework.security.access.AccessDeniedException;
-import org.springframework.stereotype.Controller;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.ResponseBody;
-
-import com.fasterxml.jackson.core.JsonParseException;
-import com.fasterxml.jackson.databind.JsonMappingException;
-
-/**
- * StreamingController is defined as Restful API entrance for UI.
- *
- * @author jiazhong
- */
-@Controller
-@RequestMapping(value = "/streaming")
-public class StreamingControllerV2 extends BasicController {
- private static final Logger logger = LoggerFactory.getLogger(StreamingControllerV2.class);
-
- @Autowired
- @Qualifier("streamingMgmtService")
- private StreamingService streamingService;
-
- @Autowired
- @Qualifier("kafkaMgmtService")
- private KafkaConfigService kafkaConfigService;
-
- @Autowired
- @Qualifier("tableService")
- private TableService tableService;
-
- @RequestMapping(value = "/getConfig", method = { RequestMethod.GET }, produces = {
- "application/vnd.apache.kylin-v2+json" })
- @ResponseBody
- public EnvelopeResponse getStreamingsV2(@RequestParam(value = "table", required = false) String table,
- @RequestParam(value = "project", required = true) String project,
- @RequestParam(value = "pageOffset", required = false, defaultValue = "0") Integer pageOffset,
- @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize)
- throws IOException {
-
- int offset = pageOffset * pageSize;
- int limit = pageSize;
-
- return new EnvelopeResponse(ResponseCode.CODE_SUCCESS,
- streamingService.getStreamingConfigs(table, project, limit, offset), "");
- }
-
- @RequestMapping(value = "/getKfkConfig", method = { RequestMethod.GET }, produces = {
- "application/vnd.apache.kylin-v2+json" })
- @ResponseBody
- public EnvelopeResponse getKafkaConfigsV2(
- @RequestParam(value = "kafkaConfigName", required = false) String kafkaConfigName,
- @RequestParam(value = "project", required = true) String project,
- @RequestParam(value = "pageOffset", required = false, defaultValue = "0") Integer pageOffset,
- @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize)
- throws IOException {
-
- int offset = pageOffset * pageSize;
- int limit = pageSize;
-
- return new EnvelopeResponse(ResponseCode.CODE_SUCCESS,
- kafkaConfigService.getKafkaConfigs(kafkaConfigName, project, limit, offset), "");
- }
-
- /**
- *
- * create Streaming Schema
- * @throws java.io.IOException
- */
-
- @RequestMapping(value = "", method = { RequestMethod.POST }, produces = { "application/vnd.apache.kylin-v2+json" })
- @ResponseBody
- public void saveStreamingConfigV2(@RequestBody StreamingRequest streamingRequest) throws IOException {
- Message msg = MsgPicker.getMsg();
-
- String project = streamingRequest.getProject();
- TableDesc tableDesc = deserializeTableDescV2(streamingRequest);
- if (null == tableDesc) {
- throw new BadRequestException(msg.getINVALID_TABLE_DESC_DEFINITION());
- }
-
- StreamingConfig streamingConfig = deserializeSchemalDescV2(streamingRequest);
- KafkaConfig kafkaConfig = deserializeKafkaSchemalDescV2(streamingRequest);
-
- boolean saveStreamingSuccess = false, saveKafkaSuccess = false;
-
- try {
- tableService.addStreamingTable(tableDesc, project);
- } catch (IOException e) {
- throw new InternalErrorException(msg.getADD_STREAMING_TABLE_FAIL());
- }
-
- streamingConfig.setName(tableDesc.getIdentity());
- kafkaConfig.setName(tableDesc.getIdentity());
- try {
- if (StringUtils.isEmpty(streamingConfig.getName())) {
- logger.info("StreamingConfig should not be empty.");
- throw new BadRequestException(msg.getEMPTY_STREAMING_CONFIG_NAME());
- }
- try {
- streamingConfig.setUuid(UUID.randomUUID().toString());
- streamingService.createStreamingConfig(streamingConfig, project);
- saveStreamingSuccess = true;
- } catch (IOException e) {
- logger.error("Failed to save StreamingConfig:" + e.getLocalizedMessage(), e);
- throw new InternalErrorException(msg.getSAVE_STREAMING_CONFIG_FAIL());
- }
- try {
- kafkaConfig.setUuid(UUID.randomUUID().toString());
- kafkaConfigService.createKafkaConfig(kafkaConfig, project);
- saveKafkaSuccess = true;
- } catch (IOException e) {
- try {
- streamingService.dropStreamingConfig(streamingConfig, project);
- } catch (IOException e1) {
- throw new InternalErrorException(msg.getCREATE_KAFKA_CONFIG_FAIL());
- }
- logger.error("Failed to save KafkaConfig:" + e.getLocalizedMessage(), e);
- throw new InternalErrorException(msg.getSAVE_KAFKA_CONFIG_FAIL());
- }
- } finally {
- if (saveKafkaSuccess == false || saveStreamingSuccess == false) {
-
- if (saveStreamingSuccess == true) {
- StreamingConfig sConfig = streamingService.getStreamingManager()
- .getStreamingConfig(streamingConfig.getName());
- try {
- streamingService.dropStreamingConfig(sConfig, project);
- } catch (IOException e) {
- throw new InternalErrorException(msg.getROLLBACK_STREAMING_CONFIG_FAIL());
- }
- }
- if (saveKafkaSuccess == true) {
- try {
- KafkaConfig kConfig = kafkaConfigService.getKafkaConfig(kafkaConfig.getName(), project);
- kafkaConfigService.dropKafkaConfig(kConfig, project);
- } catch (IOException e) {
- throw new InternalErrorException(msg.getROLLBACK_KAFKA_CONFIG_FAIL());
- }
- }
- }
-
- }
- }
-
- @RequestMapping(value = "", method = { RequestMethod.PUT }, produces = { "application/vnd.apache.kylin-v2+json" })
- @ResponseBody
- public void updateStreamingConfigV2(@RequestBody StreamingRequest streamingRequest) throws IOException {
- Message msg = MsgPicker.getMsg();
-
- StreamingConfig streamingConfig = deserializeSchemalDescV2(streamingRequest);
- KafkaConfig kafkaConfig = deserializeKafkaSchemalDescV2(streamingRequest);
- String project = streamingRequest.getProject();
-
- if (streamingConfig == null) {
- throw new BadRequestException(msg.getINVALID_STREAMING_CONFIG_DEFINITION());
- }
- try {
- streamingService.updateStreamingConfig(streamingConfig, project);
- } catch (AccessDeniedException accessDeniedException) {
- throw new ForbiddenException(msg.getUPDATE_STREAMING_CONFIG_NO_RIGHT());
- }
-
- try {
- kafkaConfigService.updateKafkaConfig(kafkaConfig, project);
- } catch (AccessDeniedException accessDeniedException) {
- throw new ForbiddenException(msg.getUPDATE_KAFKA_CONFIG_NO_RIGHT());
- }
- }
-
- @RequestMapping(value = "/{project}/{configName}", method = { RequestMethod.DELETE }, produces = {
- "application/vnd.apache.kylin-v2+json" })
- @ResponseBody
- public void deleteConfigV2(@PathVariable String project, @PathVariable String configName) throws IOException {
- Message msg = MsgPicker.getMsg();
-
- StreamingConfig config = streamingService.getStreamingManager().getStreamingConfig(configName);
- KafkaConfig kafkaConfig = kafkaConfigService.getKafkaConfig(configName, project);
- if (null == config) {
- throw new BadRequestException(String.format(msg.getSTREAMING_CONFIG_NOT_FOUND(), configName));
- }
- streamingService.dropStreamingConfig(config, project);
- kafkaConfigService.dropKafkaConfig(kafkaConfig, project);
- }
-
- private TableDesc deserializeTableDescV2(StreamingRequest streamingRequest) throws IOException {
- Message msg = MsgPicker.getMsg();
-
- TableDesc desc = null;
- try {
- logger.debug("Saving TableDesc " + streamingRequest.getTableData());
- desc = JsonUtil.readValue(streamingRequest.getTableData(), TableDesc.class);
- } catch (JsonParseException e) {
- logger.error("The TableDesc definition is invalid.", e);
- throw new BadRequestException(msg.getINVALID_TABLE_DESC_DEFINITION());
- } catch (JsonMappingException e) {
- logger.error("The data TableDesc definition is invalid.", e);
- throw new BadRequestException(msg.getINVALID_TABLE_DESC_DEFINITION());
- }
-
- if (null != desc) {
- String[] dbTable = HadoopUtil.parseHiveTableName(desc.getIdentity());
- desc.setName(dbTable[1]);
- desc.setDatabase(dbTable[0]);
- }
- return desc;
- }
-
- private StreamingConfig deserializeSchemalDescV2(StreamingRequest streamingRequest) throws IOException {
- Message msg = MsgPicker.getMsg();
-
- StreamingConfig desc = null;
- try {
- logger.debug("Saving StreamingConfig " + streamingRequest.getStreamingConfig());
- desc = JsonUtil.readValue(streamingRequest.getStreamingConfig(), StreamingConfig.class);
- } catch (JsonParseException e) {
- logger.error("The StreamingConfig definition is invalid.", e);
- throw new BadRequestException(msg.getINVALID_STREAMING_CONFIG_DEFINITION());
- } catch (JsonMappingException e) {
- logger.error("The data StreamingConfig definition is invalid.", e);
- throw new BadRequestException(msg.getINVALID_STREAMING_CONFIG_DEFINITION());
- }
- return desc;
- }
-
- private KafkaConfig deserializeKafkaSchemalDescV2(StreamingRequest streamingRequest) throws IOException {
- Message msg = MsgPicker.getMsg();
-
- KafkaConfig desc = null;
- try {
- logger.debug("Saving KafkaConfig " + streamingRequest.getKafkaConfig());
- desc = JsonUtil.readValue(streamingRequest.getKafkaConfig(), KafkaConfig.class);
- } catch (JsonParseException e) {
- logger.error("The KafkaConfig definition is invalid.", e);
- throw new BadRequestException(msg.getINVALID_KAFKA_CONFIG_DEFINITION());
- } catch (JsonMappingException e) {
- logger.error("The data KafkaConfig definition is invalid.", e);
- updateRequest(streamingRequest, false, e.getMessage());
- throw new BadRequestException(msg.getINVALID_KAFKA_CONFIG_DEFINITION());
- }
- return desc;
- }
-
- private void updateRequest(StreamingRequest request, boolean success, String message) {
- request.setSuccessful(success);
- request.setMessage(message);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/kylin/blob/92306639/server-base/src/main/java/org/apache/kylin/rest/controller2/TableAclControllerV2.java
----------------------------------------------------------------------
diff --git a/server-base/src/main/java/org/apache/kylin/rest/controller2/TableAclControllerV2.java b/server-base/src/main/java/org/apache/kylin/rest/controller2/TableAclControllerV2.java
deleted file mode 100644
index a72efa2..0000000
--- a/server-base/src/main/java/org/apache/kylin/rest/controller2/TableAclControllerV2.java
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * 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.controller2;
-
-import java.io.IOException;
-import java.util.List;
-
-import org.apache.kylin.rest.controller.BasicController;
-import org.apache.kylin.rest.response.EnvelopeResponse;
-import org.apache.kylin.rest.response.ResponseCode;
-import org.apache.kylin.rest.service.TableACLService;
-import org.apache.kylin.rest.util.ValidateUtil;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Qualifier;
-import org.springframework.stereotype.Controller;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.ResponseBody;
-
-@Controller
-@RequestMapping(value = "/acl")
-public class TableAclControllerV2 extends BasicController {
-
- @Autowired
- @Qualifier("TableAclService")
- private TableACLService tableACLService;
-
- @Autowired
- @Qualifier("validateUtil")
- private ValidateUtil validateUtil;
-
- @RequestMapping(value = "/table/{project}/{table:.+}", method = {RequestMethod.GET}, produces = {"application/vnd.apache.kylin-v2+json"})
- @ResponseBody
- public EnvelopeResponse getTableWhiteListByTable(@PathVariable String project, @PathVariable String table) throws IOException {
- validateUtil.vaildateArgs(project, table);
- project = project.toUpperCase();
- validateUtil.validateTable(project, table);
- List<String> allUsers = validateUtil.getAllUsers();
- List<String> whiteList = tableACLService.getTableWhiteListByTable(project, table, allUsers);
- return new EnvelopeResponse(ResponseCode.CODE_SUCCESS, whiteList, "get table acl");
- }
-
- @RequestMapping(value = "/table/{project}/black/{table:.+}", method = {RequestMethod.GET}, produces = {"application/vnd.apache.kylin-v2+json"})
- @ResponseBody
- public EnvelopeResponse getTableBlackListByTable(@PathVariable String project, @PathVariable String table) throws IOException {
- validateUtil.vaildateArgs(project, table);
- project = project.toUpperCase();
- validateUtil.validateTable(project, table);
- List<String> blackList = tableACLService.getBlockedUserByTable(project, table);
- return new EnvelopeResponse(ResponseCode.CODE_SUCCESS, blackList, "get table acl");
- }
-
- // because the frontend passes user can not visit, so that means put it to the table black list
- @RequestMapping(value = "/table/{project}/{table}/{username}", method = {RequestMethod.DELETE}, produces = {"application/vnd.apache.kylin-v2+json"})
- @ResponseBody
- public EnvelopeResponse putUserToTableBlackList(
- @PathVariable String project,
- @PathVariable String table,
- @PathVariable String username) throws IOException {
- validateUtil.vaildateArgs(project, table, username);
- project = project.toUpperCase();
- validateUtil.validateUser(username);
- validateUtil.validateTable(project, table);
- tableACLService.addToTableBlackList(project, username, table);
- return new EnvelopeResponse(ResponseCode.CODE_SUCCESS, "", "revoke user table query permission and add user to table black list.");
- }
-
- // because the frontend passes user can visit, so that means remove the user from the table black list
- @RequestMapping(value = "/table/{project}/{table}/{username}", method = {RequestMethod.POST}, produces = {"application/vnd.apache.kylin-v2+json"})
- @ResponseBody
- public EnvelopeResponse deleteUserFromTableBlackList(
- @PathVariable String project,
- @PathVariable String table,
- @PathVariable String username) throws IOException {
- validateUtil.vaildateArgs(project, table, username);
- project = project.toUpperCase();
- validateUtil.validateUser(username);
- validateUtil.validateTable(project, table);
- tableACLService.deleteFromTableBlackList(project, username, table);
- return new EnvelopeResponse(ResponseCode.CODE_SUCCESS, "", "grant user table query permission and remove user from table black list.");
- }
-}
http://git-wip-us.apache.org/repos/asf/kylin/blob/92306639/server-base/src/main/java/org/apache/kylin/rest/controller2/TableControllerV2.java
----------------------------------------------------------------------
diff --git a/server-base/src/main/java/org/apache/kylin/rest/controller2/TableControllerV2.java b/server-base/src/main/java/org/apache/kylin/rest/controller2/TableControllerV2.java
deleted file mode 100644
index 39c6c32..0000000
--- a/server-base/src/main/java/org/apache/kylin/rest/controller2/TableControllerV2.java
+++ /dev/null
@@ -1,164 +0,0 @@
-/*
- * 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.controller2;
-
-import java.io.IOException;
-
-import org.apache.kylin.metadata.model.TableDesc;
-import org.apache.kylin.rest.controller.BasicController;
-import org.apache.kylin.rest.exception.BadRequestException;
-import org.apache.kylin.rest.msg.Message;
-import org.apache.kylin.rest.msg.MsgPicker;
-import org.apache.kylin.rest.request.HiveTableRequestV2;
-import org.apache.kylin.rest.response.EnvelopeResponse;
-import org.apache.kylin.rest.response.ResponseCode;
-import org.apache.kylin.rest.service.TableService;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Qualifier;
-import org.springframework.security.core.context.SecurityContextHolder;
-import org.springframework.stereotype.Controller;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.ResponseBody;
-
-/**
- * @author xduo
- */
-@Controller
-@RequestMapping(value = "/tables")
-public class TableControllerV2 extends BasicController {
-
- @SuppressWarnings("unused")
- private static final Logger logger = LoggerFactory.getLogger(TableControllerV2.class);
-
- @Autowired
- @Qualifier("tableService")
- private TableService tableService;
-
- /**
- * Get available table list of the project
- *
- * @return Table metadata array
- * @throws IOException
- */
-
- @RequestMapping(value = "", method = { RequestMethod.GET }, produces = { "application/vnd.apache.kylin-v2+json" })
- @ResponseBody
- public EnvelopeResponse getTableDescV2(@RequestParam(value = "ext", required = false) boolean withExt,
- @RequestParam(value = "project", required = true) String project) throws IOException {
-
- return new EnvelopeResponse(ResponseCode.CODE_SUCCESS, tableService.getTableDescByProject(project, withExt),
- "");
- }
-
- // FIXME prj-table
- /**
- * Get available table list of the input database
- *
- * @return Table metadata array
- * @throws IOException
- */
- @RequestMapping(value = "/{project}/{tableName:.+}", method = { RequestMethod.GET }, produces = {
- "application/vnd.apache.kylin-v2+json" })
- @ResponseBody
- public EnvelopeResponse getTableDescV2(@PathVariable String tableName, @PathVariable String project) {
- Message msg = MsgPicker.getMsg();
-
- TableDesc table = tableService.getTableDescByName(tableName, false, project);
- if (table == null)
- throw new BadRequestException(String.format(msg.getHIVE_TABLE_NOT_FOUND(), tableName));
- return new EnvelopeResponse(ResponseCode.CODE_SUCCESS, table, "");
- }
-
- @RequestMapping(value = "/load", method = { RequestMethod.POST }, produces = {
- "application/vnd.apache.kylin-v2+json" })
- @ResponseBody
- public EnvelopeResponse loadHiveTablesV2(@RequestBody HiveTableRequestV2 requestV2) throws Exception {
-
- return new EnvelopeResponse(ResponseCode.CODE_SUCCESS,
- tableService.loadHiveTables(requestV2.getTables(), requestV2.getProject(), requestV2.isNeedProfile()),
- "");
- }
-
- @RequestMapping(value = "/load", method = { RequestMethod.DELETE }, produces = {
- "application/vnd.apache.kylin-v2+json" })
- @ResponseBody
- public EnvelopeResponse unLoadHiveTablesV2(@RequestBody HiveTableRequestV2 requestV2) throws IOException {
-
- return new EnvelopeResponse(ResponseCode.CODE_SUCCESS,
- tableService.unloadHiveTables(requestV2.getTables(), requestV2.getProject()), "");
- }
-
- // FIXME prj-table
- /**
- * Regenerate table cardinality
- *
- * @return Table metadata array
- * @throws IOException
- */
- @RequestMapping(value = "/cardinality", method = { RequestMethod.POST }, produces = {
- "application/vnd.apache.kylin-v2+json" })
- @ResponseBody
- public void generateCardinalityV2(@RequestBody HiveTableRequestV2 requestV2) throws Exception {
-
- String submitter = SecurityContextHolder.getContext().getAuthentication().getName();
- String[] tables = requestV2.getTables();
- String project = requestV2.getProject();
-
- for (String table : tables) {
- tableService.calculateCardinality(table.toUpperCase(), submitter, project);
- }
- }
-
- /**
- * Show all databases in Hive
- *
- * @return Hive databases list
- * @throws IOException
- */
-
- @RequestMapping(value = "/hive", method = { RequestMethod.GET }, produces = {
- "application/vnd.apache.kylin-v2+json" })
- @ResponseBody
- private EnvelopeResponse showHiveDatabasesV2() throws Exception {
-
- return new EnvelopeResponse(ResponseCode.CODE_SUCCESS, tableService.getHiveDbNames(), "");
- }
-
- /**
- * Show all tables in a Hive database
- *
- * @return Hive table list
- * @throws IOException
- */
-
- @RequestMapping(value = "/hive/{database}", method = { RequestMethod.GET }, produces = {
- "application/vnd.apache.kylin-v2+json" })
- @ResponseBody
- private EnvelopeResponse showHiveTablesV2(@PathVariable String database) throws Exception {
-
- return new EnvelopeResponse(ResponseCode.CODE_SUCCESS, tableService.getHiveTableNames(database), "");
- }
-
-}
http://git-wip-us.apache.org/repos/asf/kylin/blob/92306639/server-base/src/main/java/org/apache/kylin/rest/controller2/UserControllerV2.java
----------------------------------------------------------------------
diff --git a/server-base/src/main/java/org/apache/kylin/rest/controller2/UserControllerV2.java b/server-base/src/main/java/org/apache/kylin/rest/controller2/UserControllerV2.java
deleted file mode 100644
index c0f5c17..0000000
--- a/server-base/src/main/java/org/apache/kylin/rest/controller2/UserControllerV2.java
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * 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.controller2;
-
-import java.io.IOException;
-import java.util.List;
-
-import org.apache.kylin.rest.controller.BasicController;
-import org.apache.kylin.rest.exception.UnauthorizedException;
-import org.apache.kylin.rest.msg.Message;
-import org.apache.kylin.rest.msg.MsgPicker;
-import org.apache.kylin.rest.response.EnvelopeResponse;
-import org.apache.kylin.rest.response.ResponseCode;
-import org.apache.kylin.rest.service.UserService;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Qualifier;
-import org.springframework.security.core.Authentication;
-import org.springframework.security.core.context.SecurityContextHolder;
-import org.springframework.security.core.userdetails.UserDetails;
-import org.springframework.stereotype.Controller;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.ResponseBody;
-
-/**
- * Handle user authentication request to protected kylin rest resources by
- * spring security.
- *
- * @author xduo
- *
- */
-@Controller
-@RequestMapping(value = "/user")
-public class UserControllerV2 extends BasicController {
-
- private static final Logger logger = LoggerFactory.getLogger(UserControllerV2.class);
-
- @Autowired
- @Qualifier("userService")
- UserService userService;
-
- @RequestMapping(value = "/authentication", method = RequestMethod.POST, produces = {
- "application/vnd.apache.kylin-v2+json" })
- @ResponseBody
- public EnvelopeResponse<UserDetails> authenticateV2() {
- EnvelopeResponse response = authenticatedUserV2();
- logger.debug("User login: {}", response.data);
- return response;
- }
-
- @RequestMapping(value = "/authentication", method = RequestMethod.GET, produces = {
- "application/vnd.apache.kylin-v2+json" })
- @ResponseBody
- public EnvelopeResponse<UserDetails> authenticatedUserV2() {
- Message msg = MsgPicker.getMsg();
-
- Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
- UserDetails data = null;
-
- if (authentication == null) {
- logger.debug("authentication is null.");
- throw new UnauthorizedException(msg.getAUTH_INFO_NOT_FOUND());
- }
-
- if (authentication.getPrincipal() instanceof UserDetails) {
- data = (UserDetails) authentication.getPrincipal();
- return new EnvelopeResponse(ResponseCode.CODE_SUCCESS, data, "");
- }
-
- if (authentication.getDetails() instanceof UserDetails) {
- data = (UserDetails) authentication.getDetails();
- return new EnvelopeResponse(ResponseCode.CODE_SUCCESS, data, "");
- }
-
- throw new UnauthorizedException(msg.getAUTH_INFO_NOT_FOUND());
- }
-
- @RequestMapping(value = "/authentication/authorities", method = RequestMethod.GET, produces = {
- "application/vnd.apache.kylin-v2+json" })
- @ResponseBody
- public EnvelopeResponse<List<String>> getAuthoritiesV2() throws IOException {
-
- return new EnvelopeResponse(ResponseCode.CODE_SUCCESS, userService.listUserAuthorities(), "");
- }
-
-}
http://git-wip-us.apache.org/repos/asf/kylin/blob/92306639/server-base/src/main/java/org/apache/kylin/rest/service/ModelService.java
----------------------------------------------------------------------
diff --git a/server-base/src/main/java/org/apache/kylin/rest/service/ModelService.java b/server-base/src/main/java/org/apache/kylin/rest/service/ModelService.java
index 61c8bff..585a4c3 100644
--- a/server-base/src/main/java/org/apache/kylin/rest/service/ModelService.java
+++ b/server-base/src/main/java/org/apache/kylin/rest/service/ModelService.java
@@ -18,8 +18,6 @@
package org.apache.kylin.rest.service;
-import static org.apache.kylin.rest.controller2.ModelControllerV2.VALID_MODELNAME;
-
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
@@ -71,6 +69,9 @@ public class ModelService extends BasicService {
private static final Logger logger = LoggerFactory.getLogger(ModelService.class);
+ public static final char[] VALID_MODELNAME = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890_"
+ .toCharArray();
+
@Autowired
@Qualifier("accessService")
private AccessService accessService;