http://git-wip-us.apache.org/repos/asf/kylin/blob/73a78dbe/server-base/src/main/java/org/apache/kylin/rest/model/TableMeta.java ---------------------------------------------------------------------- diff --git a/server-base/src/main/java/org/apache/kylin/rest/model/TableMeta.java b/server-base/src/main/java/org/apache/kylin/rest/model/TableMeta.java index 9a48851..47002b5 100644 --- a/server-base/src/main/java/org/apache/kylin/rest/model/TableMeta.java +++ b/server-base/src/main/java/org/apache/kylin/rest/model/TableMeta.java @@ -27,16 +27,16 @@ import java.util.List; public class TableMeta implements Serializable { private static final long serialVersionUID = 1L; - private String TABLE_CAT; - private String TABLE_SCHEM; - private String TABLE_NAME; - private String TABLE_TYPE; - private String REMARKS; - private String TYPE_CAT; - private String TYPE_SCHEM; - private String TYPE_NAME; - private String SELF_REFERENCING_COL_NAME; - private String REF_GENERATION; + protected String TABLE_CAT; + protected String TABLE_SCHEM; + protected String TABLE_NAME; + protected String TABLE_TYPE; + protected String REMARKS; + protected String TYPE_CAT; + protected String TYPE_SCHEM; + protected String TYPE_NAME; + protected String SELF_REFERENCING_COL_NAME; + protected String REF_GENERATION; private List<ColumnMeta> columns = new ArrayList<ColumnMeta>(); public TableMeta() {
http://git-wip-us.apache.org/repos/asf/kylin/blob/73a78dbe/server-base/src/main/java/org/apache/kylin/rest/model/TableMetaWithType.java ---------------------------------------------------------------------- diff --git a/server-base/src/main/java/org/apache/kylin/rest/model/TableMetaWithType.java b/server-base/src/main/java/org/apache/kylin/rest/model/TableMetaWithType.java new file mode 100644 index 0000000..55198fe --- /dev/null +++ b/server-base/src/main/java/org/apache/kylin/rest/model/TableMetaWithType.java @@ -0,0 +1,57 @@ +/* + * 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.model; + +import java.io.Serializable; +import java.util.HashSet; + +/** + * Created by luwei on 17-4-26. + */ +public class TableMetaWithType extends TableMeta { + public static enum tableTypeEnum implements Serializable { + + LOOKUP, FACT + + } + + private HashSet<tableTypeEnum> TYPE; + + public TableMetaWithType(String tABLE_CAT, String tABLE_SCHEM, String tABLE_NAME, String tABLE_TYPE, String rEMARKS, String tYPE_CAT, String tYPE_SCHEM, String tYPE_NAME, String sELF_REFERENCING_COL_NAME, String rEF_GENERATION) { + TABLE_CAT = tABLE_CAT; + TABLE_SCHEM = tABLE_SCHEM; + TABLE_NAME = tABLE_NAME; + TABLE_TYPE = tABLE_TYPE; + REMARKS = rEMARKS; + TYPE_CAT = tYPE_CAT; + TYPE_SCHEM = tYPE_SCHEM; + TYPE_NAME = tYPE_NAME; + SELF_REFERENCING_COL_NAME = sELF_REFERENCING_COL_NAME; + REF_GENERATION = rEF_GENERATION; + TYPE = new HashSet<tableTypeEnum>(); + } + + public HashSet<tableTypeEnum> getTYPE() { + return TYPE; + } + + public void setTYPE(HashSet<tableTypeEnum> TYPE) { + this.TYPE = TYPE; + } +} http://git-wip-us.apache.org/repos/asf/kylin/blob/73a78dbe/server-base/src/main/java/org/apache/kylin/rest/msg/CnMessage.java ---------------------------------------------------------------------- diff --git a/server-base/src/main/java/org/apache/kylin/rest/msg/CnMessage.java b/server-base/src/main/java/org/apache/kylin/rest/msg/CnMessage.java new file mode 100644 index 0000000..53cbaba --- /dev/null +++ b/server-base/src/main/java/org/apache/kylin/rest/msg/CnMessage.java @@ -0,0 +1,38 @@ +/* + * 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.msg; + +/** + * Created by luwei on 17-4-12. + */ +public class CnMessage extends Message{ + + private static CnMessage instance = null; + + protected CnMessage() { + + } + + public static CnMessage getInstance() { + if (instance == null) { + instance = new CnMessage(); + } + return instance; + } +} http://git-wip-us.apache.org/repos/asf/kylin/blob/73a78dbe/server-base/src/main/java/org/apache/kylin/rest/msg/Message.java ---------------------------------------------------------------------- diff --git a/server-base/src/main/java/org/apache/kylin/rest/msg/Message.java b/server-base/src/main/java/org/apache/kylin/rest/msg/Message.java new file mode 100644 index 0000000..1ad29e6 --- /dev/null +++ b/server-base/src/main/java/org/apache/kylin/rest/msg/Message.java @@ -0,0 +1,588 @@ +/* + * 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.msg; + +/** + * Created by luwei on 17-4-12. + */ +public class Message { + + private static Message instance = null; + + protected Message() { + + } + + public static Message getInstance() { + if (instance == null) { + instance = new Message(); + } + return instance; + } + + // Cube + private final String CUBE_NOT_FOUND = "Cannot find cube '%s'."; + private final String SEG_NOT_FOUND = "Cannot find segment '%s'."; + private final String KAFKA_DEP_NOT_FOUND = "Could not find Kafka dependency."; + private final String BUILD_DRAFT_CUBE = "Could not build draft cube."; + private final String BUILD_BROKEN_CUBE = "Broken cube '%s' can't be built."; + private final String INCONSISTENT_CUBE_DESC_SIGNATURE = "Inconsistent cube desc signature for '%s', if it's right after an upgrade, please try 'Edit CubeDesc' to delete the 'signature' field. Or use 'bin/metastore.sh refresh-cube-signature' to batch refresh all cubes' signatures, then reload metadata to take effect."; + private final String DELETE_NOT_FIRST_LAST_SEG = "Cannot delete segment '%s' as it is neither the first nor the last segment."; + private final String DELETE_NOT_READY_SEG = "Cannot delete segment '%s' as its status is not READY. Discard the on-going job for it."; + private final String INVALID_BUILD_TYPE = "Invalid build type: '%s'."; + private final String NO_ACL_ENTRY = "There should have been an Acl entry for ObjectIdentity '%s'."; + private final String ACL_INFO_NOT_FOUND = "Unable to find ACL information for object identity '%s'."; + private final String ACL_DOMAIN_NOT_FOUND = "Acl domain object required."; + private final String PARENT_ACL_NOT_FOUND = "Parent acl required."; + private final String DISABLE_NOT_READY_CUBE= "Only ready cube can be disabled, status of '%s' is %s."; + private final String PURGE_NOT_DISABLED_CUBE = "Only disabled cube can be purged, status of '%s' is %s."; + private final String CLONE_BROKEN_CUBE = "Broken cube '%s' can't be cloned."; + private final String INVALID_CUBE_NAME = "Invalid Cube name '%s', only letters, numbers and underline supported."; + private final String CUBE_ALREADY_EXIST = "The cube named '%s' already exists."; + private final String CUBE_DESC_ALREADY_EXIST = "The cube desc named '%s' already exists."; + private final String BROKEN_CUBE_DESC = "Broken cube desc named '%s'."; + private final String ENABLE_NOT_DISABLED_CUBE= "Only disabled cube can be enabled, status of '%s' is %s."; + private final String NO_READY_SEGMENT = "Cube '%s' doesn't contain any READY segment."; + private final String ENABLE_WITH_RUNNING_JOB= "Enable is not allowed with a running job."; + private final String DISCARD_JOB_FIRST = "The cube '%s' has running or failed job, please discard it and try again."; + private final String IDENTITY_EXIST_CHILDREN = "Children exists for '%s'."; + private final String INVALID_CUBE_DEFINITION = "The cube definition is invalid."; + private final String EMPTY_CUBE_NAME = "Cube name should not be empty."; + private final String USE_DRAFT_MODEL = "Cannot use draft model '%s'."; + private final String UNEXPECTED_CUBE_DESC_STATUS = "CubeDesc status should not be %s."; + private final String EXPECTED_CUBE_DESC_STATUS = "CubeDesc status should be %s."; + private final String CUBE_DESC_RENAME = "Cube Desc renaming is not allowed: desc.getName(): '%s', cubeRequest.getCubeName(): '%s'."; + private final String INCONSISTENT_CUBE_DESC = "CubeDesc '%s' is inconsistent with existing. Try purge that cube first or avoid updating key cube desc fields."; + private final String UPDATE_CUBE_NO_RIGHT = "You don't have right to update this cube."; + private final String NOT_STREAMING_CUBE = "Cube '%s' is not a Streaming Cube."; + private final String NO_DRAFT_CUBE_TO_UPDATE = "Cube '%s' has no draft to update."; + private final String NON_DRAFT_CUBE_ALREADY_EXIST = "A non-draft cube with name '%s' already exists."; + private final String CUBE_RENAME = "Cube renaming is not allowed."; + private final String ORIGIN_CUBE_NOT_FOUND = "Origin cube not found."; + + // Model + private final String INVALID_MODEL_DEFINITION = "The data model definition is invalid."; + private final String EMPTY_MODEL_NAME = "Model name should not be empty."; + private final String INVALID_MODEL_NAME = "Invalid Model name '%s', only letters, numbers and underline supported."; + private final String UNEXPECTED_MODEL_STATUS = "Model status should not be %s."; + private final String EXPECTED_MODEL_STATUS = "Model status should be %s."; + private final String DUPLICATE_MODEL_NAME = "Model name '%s' is duplicated, could not be created."; + private final String DROP_REFERENCED_MODEL = "Model is referenced by Cube '%s' , could not dropped"; + private final String UPDATE_MODEL_KEY_FIELD = "Dimensions and measures in use and existing join tree cannot be modified."; + private final String BROKEN_MODEL_DESC = "Broken model desc named '%s'."; + private final String MODEL_NOT_FOUND = "Data Model with name '%s' not found."; + private final String EMPTY_PROJECT_NAME = "Project name should not be empty."; + private final String EMPTY_NEW_MODEL_NAME = "New model name should not be empty"; + private final String UPDATE_MODEL_NO_RIGHT = "You don't have right to update this model."; + private final String NO_DRAFT_MODEL_TO_UPDATE = "Model '%s' has no draft to update."; + private final String NON_DRAFT_MODEL_ALREADY_EXIST = "A non-draft model with name '%s' already exists."; + private final String MODEL_RENAME = "Model renaming is not allowed."; + private final String ORIGIN_MODEL_NOT_FOUND = "Origin model not found."; + + // Job + private final String ILLEGAL_TIME_FILTER = "Illegal timeFilter for job history: %s."; + private final String ILLEGAL_EXECUTABLE_STATE = "Illegal status: %s."; + private final String INVALID_JOB_STATE = "Invalid state: %s."; + private final String ILLEGAL_JOB_TYPE = "Illegal job type, id: %s."; + private final String INVALID_JOB_STEP_STATE = "Invalid state: %s."; + + // Acl + private final String USER_NOT_EXIST = "User '%s' does not exist. Please make sure the user has logged in before"; + + // Project + private final String INVALID_PROJECT_NAME = "Invalid Project name '%s', only letters, numbers and underline supported."; + private final String PROJECT_ALREADY_EXIST = "The project named '%s' already exists."; + private final String PROJECT_NOT_FOUND = "Cannot find project '%s'."; + + // Table + private final String HIVE_TABLE_NOT_FOUND = "Cannot find Hive table '%s'. "; + private final String TABLE_DESC_NOT_FOUND = "Cannot find table descriptor '%s'."; + private final String TABLE_IN_USE_BY_MODEL = "Table is already in use by models '%s'."; + + // Cube Desc + private final String CUBE_DESC_NOT_FOUND = "Cannot find cube desc '%s'."; + + // Streaming + private final String INVALID_TABLE_DESC_DEFINITION = "The TableDesc definition is invalid."; + private final String INVALID_STREAMING_CONFIG_DEFINITION = "The StreamingConfig definition is invalid."; + private final String INVALID_KAFKA_CONFIG_DEFINITION = "The KafkaConfig definition is invalid."; + private final String ADD_STREAMING_TABLE_FAIL = "Failed to add streaming table."; + private final String EMPTY_STREAMING_CONFIG_NAME = "StreamingConfig name should not be empty."; + private final String STREAMING_CONFIG_ALREADY_EXIST = "The streamingConfig named '%s' already exists."; + private final String SAVE_STREAMING_CONFIG_FAIL = "Failed to save StreamingConfig."; + private final String KAFKA_CONFIG_ALREADY_EXIST = "The kafkaConfig named '%s' already exists."; + private final String CREATE_KAFKA_CONFIG_FAIL = "StreamingConfig is created, but failed to create KafkaConfig."; + private final String SAVE_KAFKA_CONFIG_FAIL = "Failed to save KafkaConfig."; + private final String ROLLBACK_STREAMING_CONFIG_FAIL = "Action failed and failed to rollback the created streaming config."; + private final String ROLLBACK_KAFKA_CONFIG_FAIL = "Action failed and failed to rollback the created kafka config."; + private final String UPDATE_STREAMING_CONFIG_NO_RIGHT = "You don't have right to update this StreamingConfig."; + private final String UPDATE_KAFKA_CONFIG_NO_RIGHT = "You don't have right to update this KafkaConfig."; + private final String STREAMING_CONFIG_NOT_FOUND = "StreamingConfig with name '%s' not found."; + + // Query + private final String QUERY_NOT_ALLOWED = "Query is not allowed in '%s' mode."; + private final String NOT_SUPPORTED_SQL = "Not Supported SQL."; + private final String TABLE_META_INCONSISTENT = "Table metadata inconsistent with JDBC meta."; + private final String COLUMN_META_INCONSISTENT = "Column metadata inconsistent with JDBC meta."; + + // Access + private final String ACL_PERMISSION_REQUIRED = "Acl permission required."; + private final String SID_REQUIRED = "Sid required."; + private final String REVOKE_ADMIN_PERMISSION = "Can't revoke admin permission of owner."; + private final String ACE_ID_REQUIRED = "Ace id required."; + + // Admin + private final String GET_ENV_CONFIG_FAIL = "Failed to get Kylin env Config."; + + // User + private final String AUTH_INFO_NOT_FOUND = "Can not find authentication information."; + private final String USER_NOT_FOUND = "User '%s' not found."; + + // Diagnosis + private final String DIAG_NOT_FOUND = "diag.sh not found at %s."; + private final String GENERATE_DIAG_PACKAGE_FAIL = "Failed to generate diagnosis package."; + private final String DIAG_PACKAGE_NOT_AVAILABLE = "Diagnosis package is not available in directory: %s."; + private final String DIAG_PACKAGE_NOT_FOUND = "Diagnosis package not found in directory: %s."; + + // Encoding + private final String VALID_ENCODING_NOT_AVAILABLE = "can't provide valid encodings for datatype: %s."; + + // ExternalFilter + private final String FILTER_ALREADY_EXIST = "The filter named '%s' already exists."; + private final String FILTER_NOT_FOUND = "The filter named '%s' does not exist."; + + + + public String getCUBE_NOT_FOUND() { + return CUBE_NOT_FOUND; + } + + public String getSEG_NOT_FOUND() { + return SEG_NOT_FOUND; + } + + public String getKAFKA_DEP_NOT_FOUND() { + return KAFKA_DEP_NOT_FOUND; + } + + public String getBUILD_DRAFT_CUBE() { + return BUILD_DRAFT_CUBE; + } + + public String getBUILD_BROKEN_CUBE() { + return BUILD_BROKEN_CUBE; + } + + public String getINCONSISTENT_CUBE_DESC_SIGNATURE() { + return INCONSISTENT_CUBE_DESC_SIGNATURE; + } + + public String getDELETE_NOT_FIRST_LAST_SEG() { + return DELETE_NOT_FIRST_LAST_SEG; + } + + public String getDELETE_NOT_READY_SEG() { + return DELETE_NOT_READY_SEG; + } + + public String getINVALID_BUILD_TYPE() { + return INVALID_BUILD_TYPE; + } + + public String getNO_ACL_ENTRY() { + return NO_ACL_ENTRY; + } + + public String getACL_INFO_NOT_FOUND() { + return ACL_INFO_NOT_FOUND; + } + + public String getACL_DOMAIN_NOT_FOUND() { + return ACL_DOMAIN_NOT_FOUND; + } + + public String getPARENT_ACL_NOT_FOUND() { + return PARENT_ACL_NOT_FOUND; + } + + public String getDISABLE_NOT_READY_CUBE() { + return DISABLE_NOT_READY_CUBE; + } + + public String getPURGE_NOT_DISABLED_CUBE() { + return PURGE_NOT_DISABLED_CUBE; + } + + public String getCLONE_BROKEN_CUBE() { + return CLONE_BROKEN_CUBE; + } + + public String getINVALID_CUBE_NAME() { + return INVALID_CUBE_NAME; + } + + public String getCUBE_ALREADY_EXIST() { + return CUBE_ALREADY_EXIST; + } + + public String getCUBE_DESC_ALREADY_EXIST() { + return CUBE_DESC_ALREADY_EXIST; + } + + public String getBROKEN_CUBE_DESC() { + return BROKEN_CUBE_DESC; + } + + public String getENABLE_NOT_DISABLED_CUBE() { + return ENABLE_NOT_DISABLED_CUBE; + } + + public String getNO_READY_SEGMENT() { + return NO_READY_SEGMENT; + } + + public String getENABLE_WITH_RUNNING_JOB() { + return ENABLE_WITH_RUNNING_JOB; + } + + public String getDISCARD_JOB_FIRST() { + return DISCARD_JOB_FIRST; + } + + public String getIDENTITY_EXIST_CHILDREN() { + return IDENTITY_EXIST_CHILDREN; + } + + public String getINVALID_CUBE_DEFINITION() { + return INVALID_CUBE_DEFINITION; + } + + public String getEMPTY_CUBE_NAME() { + return EMPTY_CUBE_NAME; + } + + public String getUSE_DRAFT_MODEL() { + return USE_DRAFT_MODEL; + } + + public String getUNEXPECTED_CUBE_DESC_STATUS() { + return UNEXPECTED_CUBE_DESC_STATUS; + } + + public String getEXPECTED_CUBE_DESC_STATUS() { + return EXPECTED_CUBE_DESC_STATUS; + } + + public String getCUBE_DESC_RENAME() { + return CUBE_DESC_RENAME; + } + + public String getINCONSISTENT_CUBE_DESC() { + return INCONSISTENT_CUBE_DESC; + } + + public String getUPDATE_CUBE_NO_RIGHT() { + return UPDATE_CUBE_NO_RIGHT; + } + + public String getNOT_STREAMING_CUBE() { + return NOT_STREAMING_CUBE; + } + + public String getNO_DRAFT_CUBE_TO_UPDATE() { + return NO_DRAFT_CUBE_TO_UPDATE; + } + + public String getNON_DRAFT_CUBE_ALREADY_EXIST() { + return NON_DRAFT_CUBE_ALREADY_EXIST; + } + + public String getCUBE_RENAME() { + return CUBE_RENAME; + } + + public String getORIGIN_CUBE_NOT_FOUND() { + return ORIGIN_CUBE_NOT_FOUND; + } + + + public String getINVALID_MODEL_DEFINITION() { + return INVALID_MODEL_DEFINITION; + } + + public String getEMPTY_MODEL_NAME() { + return EMPTY_MODEL_NAME; + } + + public String getINVALID_MODEL_NAME() { + return INVALID_MODEL_NAME; + } + + public String getUNEXPECTED_MODEL_STATUS() { + return UNEXPECTED_MODEL_STATUS; + } + + public String getEXPECTED_MODEL_STATUS() { + return EXPECTED_MODEL_STATUS; + } + + public String getDUPLICATE_MODEL_NAME() { + return DUPLICATE_MODEL_NAME; + } + + public String getDROP_REFERENCED_MODEL() { + return DROP_REFERENCED_MODEL; + } + + public String getUPDATE_MODEL_KEY_FIELD() { + return UPDATE_MODEL_KEY_FIELD; + } + + public String getBROKEN_MODEL_DESC() { + return BROKEN_MODEL_DESC; + } + + public String getMODEL_NOT_FOUND() { + return MODEL_NOT_FOUND; + } + + public String getEMPTY_PROJECT_NAME() { + return EMPTY_PROJECT_NAME; + } + + public String getEMPTY_NEW_MODEL_NAME() { + return EMPTY_NEW_MODEL_NAME; + } + + public String getUPDATE_MODEL_NO_RIGHT() { + return UPDATE_MODEL_NO_RIGHT; + } + + public String getNO_DRAFT_MODEL_TO_UPDATE() { + return NO_DRAFT_MODEL_TO_UPDATE; + } + + public String getNON_DRAFT_MODEL_ALREADY_EXIST() { + return NON_DRAFT_MODEL_ALREADY_EXIST; + } + + public String getMODEL_RENAME() { + return MODEL_RENAME; + } + + public String getORIGIN_MODEL_NOT_FOUND() { + return ORIGIN_MODEL_NOT_FOUND; + } + + + public String getILLEGAL_TIME_FILTER() { + return ILLEGAL_TIME_FILTER; + } + + public String getILLEGAL_EXECUTABLE_STATE() { + return ILLEGAL_EXECUTABLE_STATE; + } + + public String getINVALID_JOB_STATE() { + return INVALID_JOB_STATE; + } + + public String getILLEGAL_JOB_TYPE() { + return ILLEGAL_JOB_TYPE; + } + + public String getINVALID_JOB_STEP_STATE() { + return INVALID_JOB_STEP_STATE; + } + + + public String getUSER_NOT_EXIST() { + return USER_NOT_EXIST; + } + + + public String getINVALID_PROJECT_NAME() { + return INVALID_PROJECT_NAME; + } + + public String getPROJECT_ALREADY_EXIST() { + return PROJECT_ALREADY_EXIST; + } + + public String getPROJECT_NOT_FOUND() { + return PROJECT_NOT_FOUND; + } + + + public String getHIVE_TABLE_NOT_FOUND() { + return HIVE_TABLE_NOT_FOUND; + } + + public String getTABLE_DESC_NOT_FOUND() { + return TABLE_DESC_NOT_FOUND; + } + + public String getTABLE_IN_USE_BY_MODEL() { + return TABLE_IN_USE_BY_MODEL; + } + + public String getCUBE_DESC_NOT_FOUND() { + return CUBE_DESC_NOT_FOUND; + } + + + public String getINVALID_TABLE_DESC_DEFINITION() { + return INVALID_TABLE_DESC_DEFINITION; + } + + public String getINVALID_STREAMING_CONFIG_DEFINITION() { + return INVALID_STREAMING_CONFIG_DEFINITION; + } + + public String getINVALID_KAFKA_CONFIG_DEFINITION() { + return INVALID_KAFKA_CONFIG_DEFINITION; + } + + public String getADD_STREAMING_TABLE_FAIL() { + return ADD_STREAMING_TABLE_FAIL; + } + + public String getEMPTY_STREAMING_CONFIG_NAME() { + return EMPTY_STREAMING_CONFIG_NAME; + } + + public String getSTREAMING_CONFIG_ALREADY_EXIST() { + return STREAMING_CONFIG_ALREADY_EXIST; + } + + public String getSAVE_STREAMING_CONFIG_FAIL() { + return SAVE_STREAMING_CONFIG_FAIL; + } + + public String getKAFKA_CONFIG_ALREADY_EXIST() { + return KAFKA_CONFIG_ALREADY_EXIST; + } + + public String getCREATE_KAFKA_CONFIG_FAIL() { + return CREATE_KAFKA_CONFIG_FAIL; + } + + public String getSAVE_KAFKA_CONFIG_FAIL() { + return SAVE_KAFKA_CONFIG_FAIL; + } + + public String getROLLBACK_STREAMING_CONFIG_FAIL() { + return ROLLBACK_STREAMING_CONFIG_FAIL; + } + + public String getROLLBACK_KAFKA_CONFIG_FAIL() { + return ROLLBACK_KAFKA_CONFIG_FAIL; + } + + public String getUPDATE_STREAMING_CONFIG_NO_RIGHT() { + return UPDATE_STREAMING_CONFIG_NO_RIGHT; + } + + public String getUPDATE_KAFKA_CONFIG_NO_RIGHT() { + return UPDATE_KAFKA_CONFIG_NO_RIGHT; + } + + public String getSTREAMING_CONFIG_NOT_FOUND() { + return STREAMING_CONFIG_NOT_FOUND; + } + + + public String getQUERY_NOT_ALLOWED() { + return QUERY_NOT_ALLOWED; + } + + public String getNOT_SUPPORTED_SQL() { + return NOT_SUPPORTED_SQL; + } + + public String getTABLE_META_INCONSISTENT() { + return TABLE_META_INCONSISTENT; + } + + public String getCOLUMN_META_INCONSISTENT() { + return COLUMN_META_INCONSISTENT; + } + + + public String getACL_PERMISSION_REQUIRED() { + return ACL_PERMISSION_REQUIRED; + } + + public String getSID_REQUIRED() { + return SID_REQUIRED; + } + + public String getREVOKE_ADMIN_PERMISSION() { + return REVOKE_ADMIN_PERMISSION; + } + + public String getACE_ID_REQUIRED() { + return ACE_ID_REQUIRED; + } + + + public String getGET_ENV_CONFIG_FAIL() { + return GET_ENV_CONFIG_FAIL; + } + + + public String getAUTH_INFO_NOT_FOUND() { + return AUTH_INFO_NOT_FOUND; + } + + public String getUSER_NOT_FOUND() { + return USER_NOT_FOUND; + } + + + public String getDIAG_NOT_FOUND() { + return DIAG_NOT_FOUND; + } + + public String getGENERATE_DIAG_PACKAGE_FAIL() { + return GENERATE_DIAG_PACKAGE_FAIL; + } + + public String getDIAG_PACKAGE_NOT_AVAILABLE() { + return DIAG_PACKAGE_NOT_AVAILABLE; + } + + public String getDIAG_PACKAGE_NOT_FOUND() { + return DIAG_PACKAGE_NOT_FOUND; + } + + + public String getVALID_ENCODING_NOT_AVAILABLE() { + return VALID_ENCODING_NOT_AVAILABLE; + } + + + public String getFILTER_ALREADY_EXIST() { + return FILTER_ALREADY_EXIST; + } + + public String getFILTER_NOT_FOUND() { + return FILTER_NOT_FOUND; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/kylin/blob/73a78dbe/server-base/src/main/java/org/apache/kylin/rest/msg/MsgPicker.java ---------------------------------------------------------------------- diff --git a/server-base/src/main/java/org/apache/kylin/rest/msg/MsgPicker.java b/server-base/src/main/java/org/apache/kylin/rest/msg/MsgPicker.java new file mode 100644 index 0000000..b9418ff --- /dev/null +++ b/server-base/src/main/java/org/apache/kylin/rest/msg/MsgPicker.java @@ -0,0 +1,42 @@ +/* + * 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.msg; + +/** + * Created by luwei on 17-4-12. + */ +public class MsgPicker { + private static ThreadLocal<Message> msg = new ThreadLocal<Message>(); + + public static void setMsg(String lang) { + if (lang.equals("cn")) + msg.set(CnMessage.getInstance()); + else + msg.set(Message.getInstance()); + } + + public static Message getMsg() { + Message ret = msg.get(); + if (ret == null) { // use English by default + ret = Message.getInstance(); + msg.set(Message.getInstance()); + } + return ret; + } +} http://git-wip-us.apache.org/repos/asf/kylin/blob/73a78dbe/server-base/src/main/java/org/apache/kylin/rest/request/HiveTableRequestV2.java ---------------------------------------------------------------------- diff --git a/server-base/src/main/java/org/apache/kylin/rest/request/HiveTableRequestV2.java b/server-base/src/main/java/org/apache/kylin/rest/request/HiveTableRequestV2.java new file mode 100644 index 0000000..f043d15 --- /dev/null +++ b/server-base/src/main/java/org/apache/kylin/rest/request/HiveTableRequestV2.java @@ -0,0 +1,59 @@ +/* + * 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; + +/** + * Created by luwei on 17-4-25. + */ +public class HiveTableRequestV2 { + + public HiveTableRequestV2() { + + } + + private String[] tables; + + private String project; + + private boolean needProfile = true; + + + public String[] getTables() { + return tables; + } + + public String getProject() { + return project; + } + + public boolean isNeedProfile() { + return needProfile; + } + + public void setTables(String[] tables) { + this.tables = tables; + } + + public void setProject(String project) { + this.project = project; + } + + public void setNeedProfile(boolean needProfile) { + this.needProfile = needProfile; + } +} http://git-wip-us.apache.org/repos/asf/kylin/blob/73a78dbe/server-base/src/main/java/org/apache/kylin/rest/response/CubeInstanceResponse.java ---------------------------------------------------------------------- diff --git a/server-base/src/main/java/org/apache/kylin/rest/response/CubeInstanceResponse.java b/server-base/src/main/java/org/apache/kylin/rest/response/CubeInstanceResponse.java new file mode 100644 index 0000000..66878a4 --- /dev/null +++ b/server-base/src/main/java/org/apache/kylin/rest/response/CubeInstanceResponse.java @@ -0,0 +1,72 @@ +/* + * 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 com.fasterxml.jackson.annotation.JsonProperty; +import org.apache.kylin.cube.CubeInstance; + +/** + * Created by luwei on 17-4-17. + */ +public class CubeInstanceResponse extends CubeInstance{ + + public void setProject(String project) { + this.project = project; + } + + public void setModel(String model) { + this.model = model; + } + + public void setIs_streaming(boolean is_streaming) { + this.is_streaming = is_streaming; + } + + public void setPartitionDateColumn(String partitionDateColumn) { + this.partitionDateColumn = partitionDateColumn; + } + + public void setPartitionDateStart(long partitionDateStart) { + this.partitionDateStart = partitionDateStart; + } + + @JsonProperty("project") + private String project; + @JsonProperty("model") + private String model; + @JsonProperty("is_streaming") + private boolean is_streaming; + @JsonProperty("partitionDateColumn") + private String partitionDateColumn; + @JsonProperty("partitionDateStart") + private long partitionDateStart; + + public CubeInstanceResponse(CubeInstance cubeInstance) { + setUuid(cubeInstance.getUuid()); + setLastModified(cubeInstance.getLastModified()); + setVersion(cubeInstance.getVersion()); + setName(cubeInstance.getName()); + setOwner(cubeInstance.getOwner()); + setDescName(cubeInstance.getDescName()); + setCost(cubeInstance.getCost()); + setStatus(cubeInstance.getStatus()); + setSegments(cubeInstance.getSegments()); + setCreateTimeUTC(cubeInstance.getCreateTimeUTC()); + } +} http://git-wip-us.apache.org/repos/asf/kylin/blob/73a78dbe/server-base/src/main/java/org/apache/kylin/rest/response/DataModelDescResponse.java ---------------------------------------------------------------------- diff --git a/server-base/src/main/java/org/apache/kylin/rest/response/DataModelDescResponse.java b/server-base/src/main/java/org/apache/kylin/rest/response/DataModelDescResponse.java new file mode 100644 index 0000000..9fd0076 --- /dev/null +++ b/server-base/src/main/java/org/apache/kylin/rest/response/DataModelDescResponse.java @@ -0,0 +1,62 @@ +/* + * 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 com.fasterxml.jackson.annotation.JsonAutoDetect; +import com.fasterxml.jackson.annotation.JsonProperty; +import org.apache.kylin.metadata.model.DataModelDesc; +import org.apache.kylin.metadata.model.PartitionDesc; + +/** + * Created by luwei on 17-4-19. + */ + +@SuppressWarnings("serial") +@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.NONE, getterVisibility = JsonAutoDetect.Visibility.NONE, isGetterVisibility = JsonAutoDetect.Visibility.NONE, setterVisibility = JsonAutoDetect.Visibility.NONE) +public class DataModelDescResponse extends DataModelDesc { + public void setProject(String project) { + this.project = project; + } + + public DataModelDescResponse() { + + } + + @JsonProperty("project") + private String project; + + public DataModelDescResponse(DataModelDesc dataModelDesc) { + setUuid(dataModelDesc.getUuid()); + setLastModified(dataModelDesc.getLastModified()); + setVersion(dataModelDesc.getVersion()); + setName(dataModelDesc.getName()); + setOwner(dataModelDesc.getOwner()); + setStatus(dataModelDesc.getStatus()); + setDescription(dataModelDesc.getDescription()); + setRootFactTableName(dataModelDesc.getRootFactTableName()); + setJoinTables(dataModelDesc.getJoinTables()); + setDimensions(dataModelDesc.getDimensions()); + setMetrics(dataModelDesc.getMetrics()); + setFilterCondition(dataModelDesc.getFilterCondition()); + if (dataModelDesc.getPartitionDesc() != null) + setPartitionDesc(PartitionDesc.getCopyOf(dataModelDesc.getPartitionDesc())); + setCapacity(dataModelDesc.getCapacity()); + setComputedColumnDescs(dataModelDesc.getComputedColumnDescs()); + } +} http://git-wip-us.apache.org/repos/asf/kylin/blob/73a78dbe/server-base/src/main/java/org/apache/kylin/rest/response/HBaseResponse.java ---------------------------------------------------------------------- diff --git a/server-base/src/main/java/org/apache/kylin/rest/response/HBaseResponse.java b/server-base/src/main/java/org/apache/kylin/rest/response/HBaseResponse.java index f68c096..6d17a53 100644 --- a/server-base/src/main/java/org/apache/kylin/rest/response/HBaseResponse.java +++ b/server-base/src/main/java/org/apache/kylin/rest/response/HBaseResponse.java @@ -23,6 +23,7 @@ import java.io.Serializable; public class HBaseResponse implements Serializable { private static final long serialVersionUID = 7263557115683263492L; private String segmentName; + private String segmentUUID; private String segmentStatus; private String tableName; private long tableSize; @@ -119,6 +120,14 @@ public class HBaseResponse implements Serializable { this.segmentName = segmentName; } + public String getSegmentUUID() { + return segmentUUID; + } + + public void setSegmentUUID(String segmentUUID) { + this.segmentUUID = segmentUUID; + } + public String getSegmentStatus() { return segmentStatus; } http://git-wip-us.apache.org/repos/asf/kylin/blob/73a78dbe/server-base/src/main/java/org/apache/kylin/rest/response/ResponseCode.java ---------------------------------------------------------------------- diff --git a/server-base/src/main/java/org/apache/kylin/rest/response/ResponseCode.java b/server-base/src/main/java/org/apache/kylin/rest/response/ResponseCode.java index 8c3860a..013644c 100644 --- a/server-base/src/main/java/org/apache/kylin/rest/response/ResponseCode.java +++ b/server-base/src/main/java/org/apache/kylin/rest/response/ResponseCode.java @@ -27,4 +27,4 @@ package org.apache.kylin.rest.response; public class ResponseCode { public final static String CODE_SUCCESS = "000"; public final static String CODE_UNDEFINED = "999"; -} +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/kylin/blob/73a78dbe/server-base/src/main/java/org/apache/kylin/rest/security/KylinAuthenticationProvider.java ---------------------------------------------------------------------- diff --git a/server-base/src/main/java/org/apache/kylin/rest/security/KylinAuthenticationProvider.java b/server-base/src/main/java/org/apache/kylin/rest/security/KylinAuthenticationProvider.java index d0dd06a..4935a14 100644 --- a/server-base/src/main/java/org/apache/kylin/rest/security/KylinAuthenticationProvider.java +++ b/server-base/src/main/java/org/apache/kylin/rest/security/KylinAuthenticationProvider.java @@ -26,6 +26,7 @@ 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.authentication.AuthenticationProvider; import org.springframework.security.core.Authentication; import org.springframework.security.core.AuthenticationException; @@ -47,6 +48,7 @@ public class KylinAuthenticationProvider implements AuthenticationProvider { private static final Logger logger = LoggerFactory.getLogger(KylinAuthenticationProvider.class); @Autowired + @Qualifier("userService") UserService userService; @Autowired http://git-wip-us.apache.org/repos/asf/kylin/blob/73a78dbe/server-base/src/main/java/org/apache/kylin/rest/security/LdapProvider.java ---------------------------------------------------------------------- diff --git a/server-base/src/main/java/org/apache/kylin/rest/security/LdapProvider.java b/server-base/src/main/java/org/apache/kylin/rest/security/LdapProvider.java index 2c5fe50..c76301b 100644 --- a/server-base/src/main/java/org/apache/kylin/rest/security/LdapProvider.java +++ b/server-base/src/main/java/org/apache/kylin/rest/security/LdapProvider.java @@ -26,6 +26,7 @@ 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.AuthenticationException; import org.springframework.security.core.context.SecurityContextHolder; @@ -49,6 +50,7 @@ public class LdapProvider extends LdapAuthenticationProvider { private static final Logger logger = LoggerFactory.getLogger(LdapProvider.class); @Autowired + @Qualifier("userService") UserService userService; @Autowired http://git-wip-us.apache.org/repos/asf/kylin/blob/73a78dbe/server-base/src/main/java/org/apache/kylin/rest/service/AccessService.java ---------------------------------------------------------------------- diff --git a/server-base/src/main/java/org/apache/kylin/rest/service/AccessService.java b/server-base/src/main/java/org/apache/kylin/rest/service/AccessService.java index 9561fbd..9ae372a 100644 --- a/server-base/src/main/java/org/apache/kylin/rest/service/AccessService.java +++ b/server-base/src/main/java/org/apache/kylin/rest/service/AccessService.java @@ -25,10 +25,14 @@ import java.util.List; import org.apache.kylin.common.persistence.AclEntity; import org.apache.kylin.common.persistence.RootPersistentEntity; import org.apache.kylin.rest.constant.Constant; +import org.apache.kylin.rest.exception.BadRequestException; import org.apache.kylin.rest.exception.ForbiddenException; +import org.apache.kylin.rest.msg.Message; +import org.apache.kylin.rest.msg.MsgPicker; import org.apache.kylin.rest.response.AccessEntryResponse; import org.apache.kylin.rest.security.AclEntityFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.acls.domain.BasePermission; import org.springframework.security.acls.domain.GrantedAuthoritySid; @@ -46,7 +50,6 @@ import org.springframework.security.core.Authentication; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; -import org.springframework.util.Assert; /** * @author xduo @@ -56,9 +59,11 @@ import org.springframework.util.Assert; public class AccessService { @Autowired + @Qualifier("aclService") private AclService aclService; @Autowired + @Qualifier("userService") UserService userService; // ~ Methods to manage acl life circle of domain objects ~ @@ -87,9 +92,14 @@ public class AccessService { @Transactional @PreAuthorize(Constant.ACCESS_HAS_ROLE_ADMIN + " or hasPermission(#ae, 'ADMINISTRATION')") public Acl grant(AclEntity ae, Permission permission, Sid sid) { - Assert.notNull(ae, "Acl domain object required"); - Assert.notNull(permission, "Acl permission required"); - Assert.notNull(sid, "Sid required"); + Message msg = MsgPicker.getMsg(); + + if (ae == null) + throw new BadRequestException(msg.getACL_DOMAIN_NOT_FOUND()); + if (permission == null) + throw new BadRequestException(msg.getACL_PERMISSION_REQUIRED()); + if (sid == null) + throw new BadRequestException(msg.getSID_REQUIRED()); ObjectIdentity objectIdentity = new ObjectIdentityImpl(ae.getClass(), ae.getId()); MutableAcl acl = null; @@ -124,9 +134,14 @@ public class AccessService { @Transactional @PreAuthorize(Constant.ACCESS_HAS_ROLE_ADMIN + " or hasPermission(#ae, 'ADMINISTRATION')") public Acl update(AclEntity ae, Long accessEntryId, Permission newPermission) { - Assert.notNull(ae, "Acl domain object required"); - Assert.notNull(accessEntryId, "Ace id required"); - Assert.notNull(newPermission, "Acl permission required"); + Message msg = MsgPicker.getMsg(); + + if (ae == null) + throw new BadRequestException(msg.getACL_DOMAIN_NOT_FOUND()); + if (accessEntryId == null) + throw new BadRequestException(msg.getACE_ID_REQUIRED()); + if (newPermission == null) + throw new BadRequestException(msg.getACL_PERMISSION_REQUIRED()); ObjectIdentity objectIdentity = new ObjectIdentityImpl(ae.getClass(), ae.getId()); MutableAcl acl = (MutableAcl) aclService.readAclById(objectIdentity); @@ -157,8 +172,12 @@ public class AccessService { @Transactional @PreAuthorize(Constant.ACCESS_HAS_ROLE_ADMIN + " or hasPermission(#ae, 'ADMINISTRATION')") public Acl revoke(AclEntity ae, Long accessEntryId) { - Assert.notNull(ae, "Acl domain object required"); - Assert.notNull(accessEntryId, "Ace id required"); + Message msg = MsgPicker.getMsg(); + + if (ae == null) + throw new BadRequestException(msg.getACL_DOMAIN_NOT_FOUND()); + if (accessEntryId == null) + throw new BadRequestException(msg.getACE_ID_REQUIRED()); ObjectIdentity objectIdentity = new ObjectIdentityImpl(ae.getClass(), ae.getId()); MutableAcl acl = (MutableAcl) aclService.readAclById(objectIdentity); @@ -188,8 +207,14 @@ public class AccessService { @Transactional public void inherit(AclEntity ae, AclEntity parentAe) { - Assert.notNull(ae, "Acl domain object required"); - Assert.notNull(parentAe, "Parent acl required"); + Message msg = MsgPicker.getMsg(); + + if (ae == null) { + throw new BadRequestException(msg.getACL_DOMAIN_NOT_FOUND()); + } + if (parentAe == null) { + throw new BadRequestException(msg.getPARENT_ACL_NOT_FOUND()); + } ObjectIdentity objectIdentity = new ObjectIdentityImpl(ae.getClass(), ae.getId()); MutableAcl acl = null; @@ -219,7 +244,11 @@ public class AccessService { @Transactional @PreAuthorize(Constant.ACCESS_HAS_ROLE_ADMIN + " or hasPermission(#ae, 'ADMINISTRATION')") public void clean(AclEntity ae, boolean deleteChildren) { - Assert.notNull(ae, "Acl domain object required"); + Message msg = MsgPicker.getMsg(); + + if (ae == null) { + throw new BadRequestException(msg.getACL_DOMAIN_NOT_FOUND()); + } // For those may have null uuid, like DataModel, won't delete Acl. if (ae.getId() == null) @@ -285,14 +314,16 @@ public class AccessService { /** * Protect admin permission granted to acl owner. - * + * * @param acl * @param indexOfAce */ private void secureOwner(MutableAcl acl, int indexOfAce) { + Message msg = MsgPicker.getMsg(); + // Can't revoke admin permission from domain object owner if (acl.getOwner().equals(acl.getEntries().get(indexOfAce).getSid()) && BasePermission.ADMINISTRATION.equals(acl.getEntries().get(indexOfAce).getPermission())) { - throw new ForbiddenException("Can't revoke admin permission of owner."); + throw new ForbiddenException(msg.getREVOKE_ADMIN_PERMISSION()); } } } http://git-wip-us.apache.org/repos/asf/kylin/blob/73a78dbe/server-base/src/main/java/org/apache/kylin/rest/service/AclService.java ---------------------------------------------------------------------- diff --git a/server-base/src/main/java/org/apache/kylin/rest/service/AclService.java b/server-base/src/main/java/org/apache/kylin/rest/service/AclService.java index dcfc867..6292c00 100644 --- a/server-base/src/main/java/org/apache/kylin/rest/service/AclService.java +++ b/server-base/src/main/java/org/apache/kylin/rest/service/AclService.java @@ -33,9 +33,14 @@ import org.apache.kylin.common.persistence.ResourceStore; import org.apache.kylin.common.persistence.RootPersistentEntity; import org.apache.kylin.common.persistence.Serializer; import org.apache.kylin.common.util.JsonUtil; +import org.apache.kylin.rest.exception.BadRequestException; +import org.apache.kylin.rest.exception.InternalErrorException; +import org.apache.kylin.rest.msg.Message; +import org.apache.kylin.rest.msg.MsgPicker; 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.acls.domain.AccessControlEntryImpl; import org.springframework.security.acls.domain.AclAuthorizationStrategy; import org.springframework.security.acls.domain.AclImpl; @@ -56,10 +61,8 @@ import org.springframework.security.acls.model.PermissionGrantingStrategy; import org.springframework.security.acls.model.Sid; import org.springframework.security.core.Authentication; import org.springframework.security.core.context.SecurityContextHolder; -import org.springframework.security.core.userdetails.UsernameNotFoundException; import org.springframework.security.util.FieldUtils; import org.springframework.stereotype.Component; -import org.springframework.util.Assert; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; @@ -91,18 +94,17 @@ public class AclService implements MutableAclService { protected ResourceStore aclStore; @Autowired + @Qualifier("userService") protected UserService userService; public AclService() throws IOException { fieldAces.setAccessible(true); fieldAcl.setAccessible(true); aclStore = ResourceStore.getStore(KylinConfig.getInstanceFromEnv()); - logger.debug("Acl service2 create"); } @Override public List<ObjectIdentity> findChildren(ObjectIdentity parentIdentity) { - logger.debug("invoke method : findChildren"); List<ObjectIdentity> oids = new ArrayList<ObjectIdentity>(); try { List<AclRecord> allAclRecords = aclStore.getAllResources(String.valueOf(DIR_PREFIX), AclRecord.class, AclRecordSerializer.getInstance()); @@ -115,7 +117,7 @@ public class AclService implements MutableAclService { } return oids; } catch (IOException e) { - throw new RuntimeException(e.getMessage(), e); + throw new InternalErrorException(e); } } @@ -127,8 +129,11 @@ public class AclService implements MutableAclService { @Override public Acl readAclById(ObjectIdentity object, List<Sid> sids) throws NotFoundException { + Message msg = MsgPicker.getMsg(); Map<ObjectIdentity, Acl> aclsMap = readAclsById(Arrays.asList(object), sids); - Assert.isTrue(aclsMap.containsKey(object), "There should have been an Acl entry for ObjectIdentity " + object); + if (!aclsMap.containsKey(object)) { + throw new BadRequestException(String.format(msg.getNO_ACL_ENTRY(), object)); + } return aclsMap.get(object); } @@ -139,7 +144,7 @@ public class AclService implements MutableAclService { @Override public Map<ObjectIdentity, Acl> readAclsById(List<ObjectIdentity> oids, List<Sid> sids) throws NotFoundException { - logger.debug("invoke method : readAclsById"); + Message msg = MsgPicker.getMsg(); Map<ObjectIdentity, Acl> aclMaps = new HashMap<ObjectIdentity, Acl>(); try { for (ObjectIdentity oid : oids) { @@ -161,18 +166,17 @@ public class AclService implements MutableAclService { aclMaps.put(oid, acl); } else { - throw new NotFoundException("Unable to find ACL information for object identity '" + oid + "'"); + throw new NotFoundException(String.format(msg.getACL_INFO_NOT_FOUND(), oid)); } } return aclMaps; } catch (IOException e) { - throw new NotFoundException(e.getMessage(), e); + throw new InternalErrorException(e); } } @Override public MutableAcl createAcl(ObjectIdentity objectIdentity) throws AlreadyExistsException { - logger.debug("invoke method : createAcl"); Acl acl = null; try { @@ -190,18 +194,18 @@ public class AclService implements MutableAclService { aclStore.putResource(getQueryKeyById(String.valueOf(objectIdentity.getIdentifier())), record, 0, AclRecordSerializer.getInstance()); logger.debug("ACL of " + objectIdentity + " created successfully."); } catch (IOException e) { - throw new RuntimeException(e.getMessage(), e); + throw new InternalErrorException(e); } return (MutableAcl) readAclById(objectIdentity); } @Override public void deleteAcl(ObjectIdentity objectIdentity, boolean deleteChildren) throws ChildrenExistException { + Message msg = MsgPicker.getMsg(); try { - logger.debug("invoke method : deleteAcl"); List<ObjectIdentity> children = findChildren(objectIdentity); if (!deleteChildren && children.size() > 0) { - throw new ChildrenExistException("Children exists for " + objectIdentity); + throw new BadRequestException(String.format(msg.getIDENTITY_EXIST_CHILDREN(), objectIdentity)); } for (ObjectIdentity oid : children) { deleteAcl(oid, deleteChildren); @@ -209,14 +213,14 @@ public class AclService implements MutableAclService { aclStore.deleteResource(getQueryKeyById(String.valueOf(objectIdentity.getIdentifier()))); logger.debug("ACL of " + objectIdentity + " deleted successfully."); } catch (IOException e) { - throw new RuntimeException(e.getMessage(), e); + throw new InternalErrorException(e); } } @Override public MutableAcl updateAcl(MutableAcl mutableAcl) throws NotFoundException { + Message msg = MsgPicker.getMsg(); try { - logger.debug("invoke method : updateAcl"); readAclById(mutableAcl.getObjectIdentity()); } catch (NotFoundException e) { throw e; @@ -226,7 +230,6 @@ public class AclService implements MutableAclService { String id = getQueryKeyById(String.valueOf(mutableAcl.getObjectIdentity().getIdentifier())); AclRecord record = aclStore.getResource(id, AclRecord.class, AclRecordSerializer.getInstance()); aclStore.deleteResource(id); - //logger.debug("Exist? {}", aclStore.exists(id)); if (mutableAcl.getParentAcl() != null) { record.setParentDomainObjectInfo(new DomainObjectInfo(mutableAcl.getParentAcl().getObjectIdentity())); } @@ -240,9 +243,8 @@ public class AclService implements MutableAclService { if (ace.getSid() instanceof PrincipalSid) { PrincipalSid psid = (PrincipalSid) ace.getSid(); String userName = psid.getPrincipal(); - logger.debug("ACE SID name: " + userName); if (!userService.userExists(userName)) - throw new UsernameNotFoundException("User " + userName + " does not exist. Please make sure the user has logged in before"); + throw new BadRequestException(String.format(msg.getUSER_NOT_EXIST(), userName)); } AceInfo aceInfo = new AceInfo(ace); allAceInfo.put(String.valueOf(aceInfo.getSidInfo().getSid()), aceInfo); @@ -250,12 +252,12 @@ public class AclService implements MutableAclService { aclStore.putResource(id, record, 0, AclRecordSerializer.getInstance()); logger.debug("ACL of " + mutableAcl.getObjectIdentity() + " updated successfully."); } catch (IOException e) { - throw new RuntimeException(e.getMessage(), e); + throw new InternalErrorException(e); } return (MutableAcl) readAclById(mutableAcl.getObjectIdentity()); } - private void genAces(List<Sid> sids, AclRecord record, AclImpl acl) throws JsonParseException, JsonMappingException, IOException { + protected void genAces(List<Sid> sids, AclRecord record, AclImpl acl) throws JsonParseException, JsonMappingException, IOException { List<AceInfo> aceInfos = new ArrayList<AceInfo>(); Map<String, AceInfo> allAceInfos = record.getAllAceInfo(); if (allAceInfos != null) { @@ -306,12 +308,6 @@ public class AclService implements MutableAclService { return DIR_PREFIX + id; } - private boolean equal(ObjectIdentity o1, ObjectIdentity o2) { - if (o1.getIdentifier().equals(o2.getIdentifier()) && o1.getType().equals(o2.getType())) - return true; - return false; - } - protected static class AclRecordSerializer implements Serializer<AclRecord> { private static final AclRecordSerializer serializer = new AclRecordSerializer(); @@ -339,6 +335,7 @@ public class AclService implements MutableAclService { } +@SuppressWarnings("serial") class AclRecord extends RootPersistentEntity { @JsonProperty() http://git-wip-us.apache.org/repos/asf/kylin/blob/73a78dbe/server-base/src/main/java/org/apache/kylin/rest/service/AdminService.java ---------------------------------------------------------------------- diff --git a/server-base/src/main/java/org/apache/kylin/rest/service/AdminService.java b/server-base/src/main/java/org/apache/kylin/rest/service/AdminService.java index 695c0d5..f9bb7e6 100644 --- a/server-base/src/main/java/org/apache/kylin/rest/service/AdminService.java +++ b/server-base/src/main/java/org/apache/kylin/rest/service/AdminService.java @@ -29,7 +29,6 @@ import org.apache.commons.configuration.PropertiesConfiguration; import org.apache.kylin.common.KylinConfig; import org.apache.kylin.common.util.OrderedProperties; import org.apache.kylin.rest.constant.Constant; -import org.apache.kylin.rest.exception.InternalErrorException; import org.apache.kylin.rest.job.StorageCleanupJob; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -45,70 +44,54 @@ public class AdminService extends BasicService { /** * Get Java Env info as string - * - * @return */ @PreAuthorize(Constant.ACCESS_HAS_ROLE_ADMIN) - public String getEnv() { + public String getEnv() throws ConfigurationException { PropertiesConfiguration tempConfig = new PropertiesConfiguration(); OrderedProperties orderedProperties = new OrderedProperties(new TreeMap<String, String>()); // Add Java Env - try { - String content = ""; - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - // env - Map<String, String> env = System.getenv(); + String content = ""; + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + // env + Map<String, String> env = System.getenv(); - for (Map.Entry<String, String> entry : env.entrySet()) { - orderedProperties.setProperty(entry.getKey(), entry.getValue()); - } - - // properties - Properties properties = System.getProperties(); + for (Map.Entry<String, String> entry : env.entrySet()) { + orderedProperties.setProperty(entry.getKey(), entry.getValue()); + } - for (Map.Entry<Object, Object> entry : properties.entrySet()) { - orderedProperties.setProperty((String) entry.getKey(), (String) entry.getValue()); - } + // properties + Properties properties = System.getProperties(); - for (Map.Entry<String, String> entry : orderedProperties.entrySet()) { - tempConfig.addProperty(entry.getKey(), entry.getValue()); - } + for (Map.Entry<Object, Object> entry : properties.entrySet()) { + orderedProperties.setProperty((String) entry.getKey(), (String) entry.getValue()); + } - // do save - tempConfig.save(baos); - content = baos.toString(); - return content; - } catch (ConfigurationException e) { - throw new InternalErrorException("Failed to get Kylin env Config", e); + for (Map.Entry<String, String> entry : orderedProperties.entrySet()) { + tempConfig.addProperty(entry.getKey(), entry.getValue()); } + + // do save + tempConfig.save(baos); + content = baos.toString(); + return content; } /** * Get Java config info as String - * - * @return */ // @PreAuthorize(Constant.ACCESS_HAS_ROLE_ADMIN) // this is a critical security issue, see KYLIN-1664 - public String getConfigAsString() { + public String getConfigAsString() throws IOException { logger.debug("Get Kylin Runtime Config"); - try { - return KylinConfig.getInstanceFromEnv().getConfigAsString(); - } catch (IOException e) { - throw new InternalErrorException("Failed to get Kylin Runtime Config", e); - } + return KylinConfig.getInstanceFromEnv().getConfigAsString(); } @PreAuthorize(Constant.ACCESS_HAS_ROLE_ADMIN) public void cleanupStorage() { StorageCleanupJob job = new StorageCleanupJob(); String[] args = new String[] { "-delete", "true" }; - try { - job.execute(args); - } catch (Exception e) { - throw new InternalErrorException(e.getMessage(), e); - } + job.execute(args); } } http://git-wip-us.apache.org/repos/asf/kylin/blob/73a78dbe/server-base/src/main/java/org/apache/kylin/rest/service/CacheService.java ---------------------------------------------------------------------- diff --git a/server-base/src/main/java/org/apache/kylin/rest/service/CacheService.java b/server-base/src/main/java/org/apache/kylin/rest/service/CacheService.java index fc82bfe..6f5e9f8 100644 --- a/server-base/src/main/java/org/apache/kylin/rest/service/CacheService.java +++ b/server-base/src/main/java/org/apache/kylin/rest/service/CacheService.java @@ -18,10 +18,7 @@ package org.apache.kylin.rest.service; -import java.io.IOException; - -import javax.sql.DataSource; - +import net.sf.ehcache.CacheManager; import org.apache.commons.lang3.StringUtils; import org.apache.kylin.metadata.cachesync.Broadcaster; import org.apache.kylin.metadata.cachesync.Broadcaster.Event; @@ -30,9 +27,11 @@ import org.apache.kylin.query.QueryDataSource; 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.Component; -import net.sf.ehcache.CacheManager; +import javax.sql.DataSource; +import java.io.IOException; /** */ @@ -44,6 +43,7 @@ public class CacheService extends BasicService { private static QueryDataSource queryDataSource = new QueryDataSource(); @Autowired + @Qualifier("cubeMgmtService") private CubeService cubeService; @Autowired http://git-wip-us.apache.org/repos/asf/kylin/blob/73a78dbe/server-base/src/main/java/org/apache/kylin/rest/service/CubeService.java ---------------------------------------------------------------------- diff --git a/server-base/src/main/java/org/apache/kylin/rest/service/CubeService.java b/server-base/src/main/java/org/apache/kylin/rest/service/CubeService.java index a6310d1..744d170 100644 --- a/server-base/src/main/java/org/apache/kylin/rest/service/CubeService.java +++ b/server-base/src/main/java/org/apache/kylin/rest/service/CubeService.java @@ -18,15 +18,7 @@ package org.apache.kylin.rest.service; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Date; -import java.util.EnumSet; -import java.util.List; -import java.util.Map; -import java.util.WeakHashMap; - +import com.google.common.collect.Lists; import org.apache.hadoop.hbase.client.Connection; import org.apache.kylin.common.KylinConfig; import org.apache.kylin.common.util.Pair; @@ -58,12 +50,20 @@ import org.apache.kylin.storage.hbase.util.HBaseRegionSizeCalculator; 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.prepost.PostFilter; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.stereotype.Component; -import com.google.common.collect.Lists; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Date; +import java.util.EnumSet; +import java.util.List; +import java.util.Map; +import java.util.WeakHashMap; /** * Stateless & lightweight service facade of cube management functions. @@ -79,9 +79,11 @@ public class CubeService extends BasicService { private WeakHashMap<String, HBaseResponse> htableInfoCache = new WeakHashMap<>(); @Autowired + @Qualifier("accessService") private AccessService accessService; @Autowired + @Qualifier("jobService") private JobService jobService; @PostFilter(Constant.ACCESS_POST_FILTER_READ) @@ -158,12 +160,14 @@ public class CubeService extends BasicService { throw new InternalErrorException(createdDesc.getError().get(0)); } - try { - int cuboidCount = CuboidCLI.simulateCuboidGeneration(createdDesc, false); - logger.info("New cube " + cubeName + " has " + cuboidCount + " cuboids"); - } catch (Exception e) { - getCubeDescManager().removeCubeDesc(createdDesc); - throw new InternalErrorException("Failed to deal with the request.", e); + if (desc.getStatus() == null) { + try { + int cuboidCount = CuboidCLI.simulateCuboidGeneration(createdDesc, false); + logger.info("New cube " + cubeName + " has " + cuboidCount + " cuboids"); + } catch (Exception e) { + getCubeDescManager().removeCubeDesc(createdDesc); + throw new InternalErrorException("Failed to deal with the request.", e); + } } createdCube = getCubeManager().createCube(cubeName, projectName, createdDesc, owner); @@ -194,7 +198,7 @@ public class CubeService extends BasicService { return result; } - private boolean isCubeInProject(String projectName, CubeInstance target) { + protected boolean isCubeInProject(String projectName, CubeInstance target) { ProjectManager projectManager = getProjectManager(); ProjectInstance project = projectManager.getProject(projectName); if (project == null) { @@ -230,8 +234,10 @@ public class CubeService extends BasicService { } CubeDesc updatedCubeDesc = getCubeDescManager().updateCubeDesc(desc); - int cuboidCount = CuboidCLI.simulateCuboidGeneration(updatedCubeDesc, false); - logger.info("Updated cube " + cube.getName() + " has " + cuboidCount + " cuboids"); + if (desc.getStatus() == null) { + int cuboidCount = CuboidCLI.simulateCuboidGeneration(updatedCubeDesc, false); + logger.info("Updated cube " + cube.getName() + " has " + cuboidCount + " cuboids"); + } ProjectManager projectManager = getProjectManager(); if (!isCubeInProject(newProjectName, cube)) { @@ -457,7 +463,7 @@ public class CubeService extends BasicService { return CubeManager.getInstance(getConfig()).updateCube(update); } - private void releaseAllJobs(CubeInstance cube) { + protected void releaseAllJobs(CubeInstance cube) { final List<CubingJob> cubingJobs = jobService.listAllCubingJobs(cube.getName(), null); for (CubingJob cubingJob : cubingJobs) { final ExecutableState status = cubingJob.getStatus(); @@ -555,4 +561,13 @@ public class CubeService extends BasicService { } } + public boolean checkNameAvailability(String cubeName) { + List<CubeInstance> cubes = listAllCubes(cubeName, null, null); + for (CubeInstance cube : cubes) { + if (cube.getName().equals(cubeName)) + return false; + } + return true; + } + }