czy006 commented on code in PR #3072:
URL: https://github.com/apache/amoro/pull/3072#discussion_r1732790233


##########
amoro-ams/amoro-ams-server/src/test/java/org/apache/amoro/server/manager/TestKubernetesOptimizerContainer.java:
##########
@@ -0,0 +1,201 @@
+/*
+ * 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.amoro.server.manager;
+
+import io.fabric8.kubernetes.api.model.LocalObjectReference;
+import io.fabric8.kubernetes.api.model.LocalObjectReferenceBuilder;
+import io.fabric8.kubernetes.api.model.PodTemplate;
+import io.fabric8.kubernetes.api.model.Quantity;
+import io.fabric8.kubernetes.api.model.apps.Deployment;
+import org.apache.amoro.api.OptimizerProperties;
+import org.apache.amoro.api.resource.Resource;
+import org.apache.amoro.api.resource.ResourceType;
+import org.apache.amoro.server.AmoroManagementConf;
+import org.apache.amoro.shade.guava32.com.google.common.base.Preconditions;
+import org.apache.amoro.shade.guava32.com.google.common.collect.Maps;
+import org.apache.amoro.shade.jackson2.com.fasterxml.jackson.databind.JsonNode;
+import 
org.apache.amoro.shade.jackson2.com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.amoro.utils.JacksonUtil;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.yaml.snakeyaml.Yaml;
+
+import java.io.IOException;
+import java.net.URL;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+public class TestKubernetesOptimizerContainer {
+  private KubernetesOptimizerContainer kubernetesOptimizerContainer;
+  private Map<String, String> containerProperties;
+  private Map<String, String> groupProperties;
+  public static final String MEMORY_PROPERTY = "memory";
+  public static final String CPU_FACTOR_PROPERTY = "cpu.factor";
+  public static final String IMAGE = "image";
+  public static final String PULL_POLICY = "pullPolicy";
+  public static final String PULL_SECRETS = "imagePullSecrets";
+
+  @Before
+  public void setup() throws IOException {
+    // generating configuration files
+    kubernetesOptimizerContainer = new KubernetesOptimizerContainer();
+    groupProperties = Maps.newHashMap();
+    containerProperties = Maps.newHashMap();
+
+    containerProperties.put(OptimizerProperties.AMS_HOME, "/home/ams");
+    containerProperties.put(OptimizerProperties.AMS_OPTIMIZER_URI, 
"thrift://127.0.0.1:1261");
+
+    URL resource = getClass().getClassLoader().getResource("config.yaml");
+
+    JsonNode yamlConfig =
+        JacksonUtil.fromObjects(
+            new 
Yaml().loadAs(Files.newInputStream(Paths.get(resource.getPath())), Map.class));
+    JsonNode containers = yamlConfig.get(AmoroManagementConf.CONTAINER_LIST);
+    for (JsonNode container : containers) {
+      if (container.get("name").asText().equals("KubernetesContainer")) {
+        ObjectMapper mapper = new ObjectMapper();
+        
containerProperties.putAll(mapper.convertValue(container.get("properties"), 
Map.class));
+      }
+    }
+    groupProperties.putAll(this.containerProperties);
+  }
+
+  private static String checkAndGetProperty(Map<String, String> properties, 
String key) {
+    Preconditions.checkState(
+        properties != null && properties.containsKey(key), "Cannot find %s in 
properties", key);
+    return properties.get(key);
+  }
+
+  @Test
+  public void testBuildPodTemplateFromLocal() {
+    PodTemplate podTemplate =
+        kubernetesOptimizerContainer.initPodTemplateFromLocal(groupProperties);
+
+    Assert.assertEquals(1, 
podTemplate.getTemplate().getSpec().getContainers().size());
+    // read the image version from the podTemplate config and assert it
+    Assert.assertEquals(
+        "apache/amoro:0.6", 
podTemplate.getTemplate().getSpec().getContainers().get(0).getImage());
+  }
+
+  @Test
+  public void testBuildPodTemplateConfig() {
+    // before parameter merging
+    PodTemplate podTemplate =
+        kubernetesOptimizerContainer.initPodTemplateFromLocal(groupProperties);
+
+    // after parameter merging

Review Comment:
   Comments can be merged



##########
amoro-ams/amoro-ams-server/src/test/java/org/apache/amoro/server/manager/TestKubernetesOptimizerContainer.java:
##########
@@ -0,0 +1,201 @@
+/*
+ * 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.amoro.server.manager;
+
+import io.fabric8.kubernetes.api.model.LocalObjectReference;
+import io.fabric8.kubernetes.api.model.LocalObjectReferenceBuilder;
+import io.fabric8.kubernetes.api.model.PodTemplate;
+import io.fabric8.kubernetes.api.model.Quantity;
+import io.fabric8.kubernetes.api.model.apps.Deployment;
+import org.apache.amoro.api.OptimizerProperties;
+import org.apache.amoro.api.resource.Resource;
+import org.apache.amoro.api.resource.ResourceType;
+import org.apache.amoro.server.AmoroManagementConf;
+import org.apache.amoro.shade.guava32.com.google.common.base.Preconditions;
+import org.apache.amoro.shade.guava32.com.google.common.collect.Maps;
+import org.apache.amoro.shade.jackson2.com.fasterxml.jackson.databind.JsonNode;
+import 
org.apache.amoro.shade.jackson2.com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.amoro.utils.JacksonUtil;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.yaml.snakeyaml.Yaml;
+
+import java.io.IOException;
+import java.net.URL;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+public class TestKubernetesOptimizerContainer {
+  private KubernetesOptimizerContainer kubernetesOptimizerContainer;
+  private Map<String, String> containerProperties;
+  private Map<String, String> groupProperties;
+  public static final String MEMORY_PROPERTY = "memory";
+  public static final String CPU_FACTOR_PROPERTY = "cpu.factor";
+  public static final String IMAGE = "image";
+  public static final String PULL_POLICY = "pullPolicy";
+  public static final String PULL_SECRETS = "imagePullSecrets";
+
+  @Before
+  public void setup() throws IOException {
+    // generating configuration files
+    kubernetesOptimizerContainer = new KubernetesOptimizerContainer();
+    groupProperties = Maps.newHashMap();
+    containerProperties = Maps.newHashMap();
+
+    containerProperties.put(OptimizerProperties.AMS_HOME, "/home/ams");
+    containerProperties.put(OptimizerProperties.AMS_OPTIMIZER_URI, 
"thrift://127.0.0.1:1261");
+
+    URL resource = getClass().getClassLoader().getResource("config.yaml");
+
+    JsonNode yamlConfig =
+        JacksonUtil.fromObjects(
+            new 
Yaml().loadAs(Files.newInputStream(Paths.get(resource.getPath())), Map.class));
+    JsonNode containers = yamlConfig.get(AmoroManagementConf.CONTAINER_LIST);
+    for (JsonNode container : containers) {
+      if (container.get("name").asText().equals("KubernetesContainer")) {
+        ObjectMapper mapper = new ObjectMapper();
+        
containerProperties.putAll(mapper.convertValue(container.get("properties"), 
Map.class));
+      }
+    }
+    groupProperties.putAll(this.containerProperties);
+  }
+
+  private static String checkAndGetProperty(Map<String, String> properties, 
String key) {
+    Preconditions.checkState(
+        properties != null && properties.containsKey(key), "Cannot find %s in 
properties", key);
+    return properties.get(key);
+  }
+
+  @Test
+  public void testBuildPodTemplateFromLocal() {
+    PodTemplate podTemplate =
+        kubernetesOptimizerContainer.initPodTemplateFromLocal(groupProperties);
+
+    Assert.assertEquals(1, 
podTemplate.getTemplate().getSpec().getContainers().size());
+    // read the image version from the podTemplate config and assert it
+    Assert.assertEquals(
+        "apache/amoro:0.6", 
podTemplate.getTemplate().getSpec().getContainers().get(0).getImage());
+  }
+
+  @Test
+  public void testBuildPodTemplateConfig() {
+    // before parameter merging
+    PodTemplate podTemplate =
+        kubernetesOptimizerContainer.initPodTemplateFromLocal(groupProperties);
+
+    // after parameter merging
+
+    // generating frontend parameter
+    ResourceType resourceType = ResourceType.OPTIMIZER;
+    Map<String, String> properties = Maps.newHashMap();
+    properties.put("memory", "1024");
+    Resource resource =
+        new Resource.Builder("KubernetesContainer", "k8s", resourceType)
+            .setMemoryMb(0)

Review Comment:
   Resource Properties doesn't in resource.getProperties(),must be set it



##########
amoro-ams/amoro-ams-server/src/test/java/org/apache/amoro/server/manager/TestKubernetesOptimizerContainer.java:
##########
@@ -0,0 +1,201 @@
+/*
+ * 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.amoro.server.manager;
+
+import io.fabric8.kubernetes.api.model.LocalObjectReference;
+import io.fabric8.kubernetes.api.model.LocalObjectReferenceBuilder;
+import io.fabric8.kubernetes.api.model.PodTemplate;
+import io.fabric8.kubernetes.api.model.Quantity;
+import io.fabric8.kubernetes.api.model.apps.Deployment;
+import org.apache.amoro.api.OptimizerProperties;
+import org.apache.amoro.api.resource.Resource;
+import org.apache.amoro.api.resource.ResourceType;
+import org.apache.amoro.server.AmoroManagementConf;
+import org.apache.amoro.shade.guava32.com.google.common.base.Preconditions;
+import org.apache.amoro.shade.guava32.com.google.common.collect.Maps;
+import org.apache.amoro.shade.jackson2.com.fasterxml.jackson.databind.JsonNode;
+import 
org.apache.amoro.shade.jackson2.com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.amoro.utils.JacksonUtil;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.yaml.snakeyaml.Yaml;
+
+import java.io.IOException;
+import java.net.URL;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+public class TestKubernetesOptimizerContainer {
+  private KubernetesOptimizerContainer kubernetesOptimizerContainer;
+  private Map<String, String> containerProperties;
+  private Map<String, String> groupProperties;
+  public static final String MEMORY_PROPERTY = "memory";
+  public static final String CPU_FACTOR_PROPERTY = "cpu.factor";
+  public static final String IMAGE = "image";
+  public static final String PULL_POLICY = "pullPolicy";
+  public static final String PULL_SECRETS = "imagePullSecrets";
+
+  @Before
+  public void setup() throws IOException {
+    // generating configuration files
+    kubernetesOptimizerContainer = new KubernetesOptimizerContainer();
+    groupProperties = Maps.newHashMap();
+    containerProperties = Maps.newHashMap();
+
+    containerProperties.put(OptimizerProperties.AMS_HOME, "/home/ams");
+    containerProperties.put(OptimizerProperties.AMS_OPTIMIZER_URI, 
"thrift://127.0.0.1:1261");
+
+    URL resource = getClass().getClassLoader().getResource("config.yaml");
+
+    JsonNode yamlConfig =
+        JacksonUtil.fromObjects(
+            new 
Yaml().loadAs(Files.newInputStream(Paths.get(resource.getPath())), Map.class));
+    JsonNode containers = yamlConfig.get(AmoroManagementConf.CONTAINER_LIST);
+    for (JsonNode container : containers) {
+      if (container.get("name").asText().equals("KubernetesContainer")) {
+        ObjectMapper mapper = new ObjectMapper();
+        
containerProperties.putAll(mapper.convertValue(container.get("properties"), 
Map.class));
+      }
+    }
+    groupProperties.putAll(this.containerProperties);
+  }
+
+  private static String checkAndGetProperty(Map<String, String> properties, 
String key) {
+    Preconditions.checkState(
+        properties != null && properties.containsKey(key), "Cannot find %s in 
properties", key);
+    return properties.get(key);
+  }
+
+  @Test
+  public void testBuildPodTemplateFromLocal() {
+    PodTemplate podTemplate =
+        kubernetesOptimizerContainer.initPodTemplateFromLocal(groupProperties);
+
+    Assert.assertEquals(1, 
podTemplate.getTemplate().getSpec().getContainers().size());
+    // read the image version from the podTemplate config and assert it
+    Assert.assertEquals(
+        "apache/amoro:0.6", 
podTemplate.getTemplate().getSpec().getContainers().get(0).getImage());
+  }
+
+  @Test
+  public void testBuildPodTemplateConfig() {
+    // before parameter merging
+    PodTemplate podTemplate =
+        kubernetesOptimizerContainer.initPodTemplateFromLocal(groupProperties);
+
+    // after parameter merging
+
+    // generating frontend parameter
+    ResourceType resourceType = ResourceType.OPTIMIZER;
+    Map<String, String> properties = Maps.newHashMap();
+    properties.put("memory", "1024");
+    Resource resource =
+        new Resource.Builder("KubernetesContainer", "k8s", resourceType)
+            .setMemoryMb(0)
+            .setThreadCount(1)
+            .setProperties(properties)
+            .build();
+    groupProperties.putAll(resource.getProperties());
+
+    // generate pod start args
+    long memoryPerThread = Long.parseLong(checkAndGetProperty(groupProperties, 
MEMORY_PROPERTY));
+    long memory = memoryPerThread * resource.getThreadCount();
+    String startUpArgs =
+        String.format(
+            "/entrypoint.sh optimizer %s %s",
+            memory, 
kubernetesOptimizerContainer.buildOptimizerStartupArgsString(resource));

Review Comment:
   this is the merge lastest memory



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to