This is an automated email from the ASF dual-hosted git repository.

xxyu pushed a commit to branch kylin5
in repository https://gitbox.apache.org/repos/asf/kylin.git

commit 43c2fba01f7414f832679a3a401b0ed863abf97e
Author: lixiang <447399...@qq.com>
AuthorDate: Thu Apr 13 18:54:04 2023 +0800

    KYLIN-5606 minor fix (#30283)
---
 .../controller/open/OpenIndexPlanController.java   | 19 ++++++--
 .../open/OpenIndexPlanControllerTest.java          | 57 +++++++++++++++++++---
 .../rest/response/OpenAddAggGroupResponse.java     | 37 ++++++++++++++
 3 files changed, 104 insertions(+), 9 deletions(-)

diff --git 
a/src/metadata-server/src/main/java/org/apache/kylin/rest/controller/open/OpenIndexPlanController.java
 
b/src/metadata-server/src/main/java/org/apache/kylin/rest/controller/open/OpenIndexPlanController.java
index 432528b511..d032bd14fb 100644
--- 
a/src/metadata-server/src/main/java/org/apache/kylin/rest/controller/open/OpenIndexPlanController.java
+++ 
b/src/metadata-server/src/main/java/org/apache/kylin/rest/controller/open/OpenIndexPlanController.java
@@ -31,6 +31,7 @@ import 
org.apache.kylin.rest.request.OpenUpdateRuleBasedCuboidRequest;
 import org.apache.kylin.rest.request.UpdateRuleBasedCuboidRequest;
 import org.apache.kylin.rest.response.DiffRuleBasedIndexResponse;
 import org.apache.kylin.rest.response.EnvelopeResponse;
+import org.apache.kylin.rest.response.OpenAddAggGroupResponse;
 import org.apache.kylin.rest.service.FusionIndexService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Qualifier;
@@ -47,6 +48,8 @@ public class OpenIndexPlanController extends NBasicController 
{
 
     private static final String MODEL_ALIAS = "model";
 
+    private static final String AGGREGATION_GROUPS = "aggregation_groups";
+
     @Autowired
     @Qualifier("fusionIndexService")
     private FusionIndexService fusionIndexService;
@@ -55,10 +58,10 @@ public class OpenIndexPlanController extends 
NBasicController {
     NIndexPlanController indexPlanController;
 
     @PutMapping(value = "/agg_groups")
-    public EnvelopeResponse<DiffRuleBasedIndexResponse> updateRule(
-            @RequestBody OpenUpdateRuleBasedCuboidRequest request) {
+    public EnvelopeResponse<OpenAddAggGroupResponse> updateRule(@RequestBody 
OpenUpdateRuleBasedCuboidRequest request) {
         String projectName = checkProjectName(request.getProject());
         checkRequiredArg(MODEL_ALIAS, request.getModelAlias());
+        checkListRequiredArg(AGGREGATION_GROUPS, 
request.getAggregationGroups());
         request.setProject(projectName);
         val modelManager = 
NDataModelManager.getInstance(KylinConfig.getInstanceFromEnv(), projectName);
         NDataModel model = 
modelManager.getDataModelDescByAlias(request.getModelAlias());
@@ -69,6 +72,16 @@ public class OpenIndexPlanController extends 
NBasicController {
         EnvelopeResponse<DiffRuleBasedIndexResponse> response = 
indexPlanController
                 .calculateDiffRuleBasedIndex(internalRequest);
         indexPlanController.updateRule(internalRequest);
-        return response;
+        return convertResponse(response);
+    }
+
+    private EnvelopeResponse<OpenAddAggGroupResponse> convertResponse(
+            EnvelopeResponse<DiffRuleBasedIndexResponse> internal) {
+        if (internal != null && internal.getData() != null) {
+            val response = new 
OpenAddAggGroupResponse(internal.getData().getDecreaseLayouts(),
+                    internal.getData().getIncreaseLayouts(), 
internal.getData().getRollbackLayouts());
+            return new EnvelopeResponse<>(KylinException.CODE_SUCCESS, 
response, "");
+        }
+        return new EnvelopeResponse<>(KylinException.CODE_SUCCESS, null, "");
     }
 }
diff --git 
a/src/metadata-server/src/test/java/org/apache/kylin/rest/controller/open/OpenIndexPlanControllerTest.java
 
b/src/metadata-server/src/test/java/org/apache/kylin/rest/controller/open/OpenIndexPlanControllerTest.java
index 529a491c92..6fba06521e 100644
--- 
a/src/metadata-server/src/test/java/org/apache/kylin/rest/controller/open/OpenIndexPlanControllerTest.java
+++ 
b/src/metadata-server/src/test/java/org/apache/kylin/rest/controller/open/OpenIndexPlanControllerTest.java
@@ -21,8 +21,11 @@ package org.apache.kylin.rest.controller.open;
 import static 
org.apache.kylin.common.constant.HttpConstant.HTTP_VND_APACHE_KYLIN_V4_PUBLIC_JSON;
 
 import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.List;
 
 import org.apache.kylin.common.KylinConfig;
+import org.apache.kylin.common.exception.KylinException;
 import org.apache.kylin.common.util.JsonUtil;
 import org.apache.kylin.common.util.NLocalFileMetadataTestCase;
 import org.apache.kylin.guava30.shaded.common.collect.Lists;
@@ -32,8 +35,11 @@ import org.apache.kylin.rest.constant.Constant;
 import org.apache.kylin.rest.controller.NIndexPlanController;
 import org.apache.kylin.rest.request.OpenUpdateRuleBasedCuboidRequest;
 import org.apache.kylin.rest.request.UpdateRuleBasedCuboidRequest;
+import org.apache.kylin.rest.response.DiffRuleBasedIndexResponse;
+import org.apache.kylin.rest.response.EnvelopeResponse;
 import org.apache.kylin.rest.service.FusionIndexService;
 import org.junit.After;
+import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 import org.mockito.InjectMocks;
@@ -45,6 +51,7 @@ import 
org.springframework.security.authentication.TestingAuthenticationToken;
 import org.springframework.security.core.Authentication;
 import org.springframework.security.core.context.SecurityContextHolder;
 import org.springframework.test.web.servlet.MockMvc;
+import org.springframework.test.web.servlet.MvcResult;
 import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
 import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
 import org.springframework.test.web.servlet.setup.MockMvcBuilders;
@@ -60,7 +67,7 @@ public class OpenIndexPlanControllerTest extends 
NLocalFileMetadataTestCase {
     private FusionIndexService fusionIndexService;
 
     @Mock
-    private NIndexPlanController nIndexPlanController;
+    private NIndexPlanController indexPlanController;
 
     private MockMvc mockMvc;
 
@@ -85,10 +92,13 @@ public class OpenIndexPlanControllerTest extends 
NLocalFileMetadataTestCase {
     public void testCreateAggGroups() throws Exception {
         val request = UpdateRuleBasedCuboidRequest.builder().project("default")
                 
.modelId("89af4ee2-2cdb-4b07-b39e-4c29856309aa").aggregationGroups(Lists.newArrayList()).build();
-
         OpenUpdateRuleBasedCuboidRequest openRequest = new 
OpenUpdateRuleBasedCuboidRequest();
         openRequest.setModelAlias("nmodel_basic");
         openRequest.setProject("default");
+        List<OpenUpdateRuleBasedCuboidRequest.OpenAggGroupRequest> 
aggregationGroups = new ArrayList<>();
+        val aggregationGroup = new 
OpenUpdateRuleBasedCuboidRequest.OpenAggGroupRequest();
+        aggregationGroups.add(aggregationGroup);
+        openRequest.setAggregationGroups(aggregationGroups);
         val modelManager = 
NDataModelManager.getInstance(KylinConfig.getInstanceFromEnv(), 
request.getProject());
         NDataModel model = 
modelManager.getDataModelDescByAlias(openRequest.getModelAlias());
 
@@ -98,17 +108,52 @@ public class OpenIndexPlanControllerTest extends 
NLocalFileMetadataTestCase {
                 
.accept(MediaType.parseMediaType(HTTP_VND_APACHE_KYLIN_V4_PUBLIC_JSON)))
                 .andExpect(MockMvcResultMatchers.status().isOk());
         Mockito.verify(openIndexPlanController).updateRule(openRequest);
+
+        DiffRuleBasedIndexResponse tmp = new 
DiffRuleBasedIndexResponse("test", 1, 2, 0);
+        EnvelopeResponse<DiffRuleBasedIndexResponse> internalResponse = new 
EnvelopeResponse<>(KylinException.CODE_SUCCESS, tmp, "");
+        
Mockito.when(indexPlanController.calculateDiffRuleBasedIndex(request)).thenReturn(internalResponse);
+        
mockMvc.perform(MockMvcRequestBuilders.put("/api/index_plans/agg_groups")
+                
.contentType(MediaType.APPLICATION_JSON).content(JsonUtil.writeValueAsString(openRequest))
+                
.accept(MediaType.parseMediaType(HTTP_VND_APACHE_KYLIN_V4_PUBLIC_JSON)))
+                .andExpect(MockMvcResultMatchers.status().isOk());
     }
 
     @Test
     public void testCreateAggGroupsNotExistModel() throws Exception {
+        val request = UpdateRuleBasedCuboidRequest.builder().project("default")
+                
.modelId("89af4ee2-2cdb-4b07-b39e-4c29856309aa").aggregationGroups(Lists.newArrayList()).build();
         OpenUpdateRuleBasedCuboidRequest openRequest = new 
OpenUpdateRuleBasedCuboidRequest();
         openRequest.setModelAlias("model_not_exist");
         openRequest.setProject("default");
-        
mockMvc.perform(MockMvcRequestBuilders.put("/api/index_plans/agg_groups")
-                
.contentType(MediaType.APPLICATION_JSON).content(JsonUtil.writeValueAsString(openRequest))
-                
.accept(MediaType.parseMediaType(HTTP_VND_APACHE_KYLIN_V4_PUBLIC_JSON)))
-                .andExpect(MockMvcResultMatchers.status().is5xxServerError());
+        val modelManager = 
NDataModelManager.getInstance(KylinConfig.getInstanceFromEnv(), 
request.getProject());
+        NDataModel model = 
modelManager.getDataModelDescByAlias(openRequest.getModelAlias());
+        List<OpenUpdateRuleBasedCuboidRequest.OpenAggGroupRequest> 
aggregationGroups = new ArrayList<>();
+        val aggregationGroup = new 
OpenUpdateRuleBasedCuboidRequest.OpenAggGroupRequest();
+        aggregationGroups.add(aggregationGroup);
+        openRequest.setAggregationGroups(aggregationGroups);
+
+        Mockito.when(fusionIndexService.convertOpenToInternal(openRequest, 
model)).thenReturn(request);
+        MvcResult mvcResult = mockMvc
+                
.perform(MockMvcRequestBuilders.put("/api/index_plans/agg_groups")
+                        
.contentType(MediaType.APPLICATION_JSON).content(JsonUtil.writeValueAsString(openRequest))
+                        
.accept(MediaType.parseMediaType(HTTP_VND_APACHE_KYLIN_V4_PUBLIC_JSON)))
+                
.andExpect(MockMvcResultMatchers.status().is5xxServerError()).andReturn();
+        Assert.assertTrue(
+                mvcResult.getResponse().getContentAsString().contains("Can't 
find model. Please check and try again"));
+        Mockito.verify(openIndexPlanController).updateRule(openRequest);
+    }
+
+    @Test
+    public void testCreateAggGroupsNotExistAggregationGroups() throws 
Exception {
+        OpenUpdateRuleBasedCuboidRequest openRequest = new 
OpenUpdateRuleBasedCuboidRequest();
+        openRequest.setModelAlias("nmodel_basic");
+        openRequest.setProject("default");
+        MvcResult mvcResult = mockMvc
+                
.perform(MockMvcRequestBuilders.put("/api/index_plans/agg_groups")
+                        
.contentType(MediaType.APPLICATION_JSON).content(JsonUtil.writeValueAsString(openRequest))
+                        
.accept(MediaType.parseMediaType(HTTP_VND_APACHE_KYLIN_V4_PUBLIC_JSON)))
+                
.andExpect(MockMvcResultMatchers.status().is5xxServerError()).andReturn();
+        
Assert.assertTrue(mvcResult.getResponse().getContentAsString().contains("KE-010043201"));
         Mockito.verify(openIndexPlanController).updateRule(openRequest);
     }
 }
diff --git 
a/src/modeling-service/src/main/java/org/apache/kylin/rest/response/OpenAddAggGroupResponse.java
 
b/src/modeling-service/src/main/java/org/apache/kylin/rest/response/OpenAddAggGroupResponse.java
new file mode 100644
index 0000000000..a658485057
--- /dev/null
+++ 
b/src/modeling-service/src/main/java/org/apache/kylin/rest/response/OpenAddAggGroupResponse.java
@@ -0,0 +1,37 @@
+/*
+ * 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 lombok.AllArgsConstructor;
+import lombok.Data;
+
+@Data
+@AllArgsConstructor
+public class OpenAddAggGroupResponse {
+
+    @JsonProperty("removed_layouts_size")
+    private Integer removedLayoutsSize;
+
+    @JsonProperty("added_layouts_size")
+    private Integer addedLayoutsSize;
+
+    @JsonProperty("recovered_layouts_size")
+    private Integer recoveredLayoutsSize;
+}

Reply via email to