timmylicheng commented on a change in pull request #1019:
URL: https://github.com/apache/hadoop-ozone/pull/1019#discussion_r436437739



##########
File path: 
hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/pipeline/TestPipelineManagerImpl.java
##########
@@ -0,0 +1,466 @@
+/**
+ * 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.hadoop.hdds.scm.pipeline;
+
+import com.google.common.base.Supplier;
+import org.apache.hadoop.fs.FileUtil;
+import org.apache.hadoop.hdds.HddsConfigKeys;
+import org.apache.hadoop.hdds.conf.OzoneConfiguration;
+import org.apache.hadoop.hdds.protocol.DatanodeDetails;
+import org.apache.hadoop.hdds.protocol.proto.HddsProtos;
+import org.apache.hadoop.hdds.scm.TestUtils;
+import org.apache.hadoop.hdds.scm.container.ContainerID;
+import org.apache.hadoop.hdds.scm.container.MockNodeManager;
+import org.apache.hadoop.hdds.scm.container.TestContainerManagerImpl;
+import org.apache.hadoop.hdds.scm.exceptions.SCMException;
+import org.apache.hadoop.hdds.scm.ha.MockSCMHAManager;
+import org.apache.hadoop.hdds.scm.metadata.SCMDBDefinition;
+import org.apache.hadoop.hdds.scm.safemode.SCMSafeModeManager;
+import org.apache.hadoop.hdds.scm.server.SCMDatanodeHeartbeatDispatcher;
+import org.apache.hadoop.hdds.server.events.EventQueue;
+import org.apache.hadoop.hdds.utils.db.DBStore;
+import org.apache.hadoop.hdds.utils.db.DBStoreBuilder;
+import org.apache.hadoop.metrics2.MetricsRecordBuilder;
+import org.apache.hadoop.ozone.container.common.SCMTestUtils;
+import org.apache.hadoop.test.GenericTestUtils;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.UUID;
+import java.util.concurrent.TimeUnit;
+
+import static 
org.apache.hadoop.hdds.scm.ScmConfigKeys.OZONE_DATANODE_PIPELINE_LIMIT;
+import static 
org.apache.hadoop.hdds.scm.ScmConfigKeys.OZONE_DATANODE_PIPELINE_LIMIT_DEFAULT;
+import static 
org.apache.hadoop.hdds.scm.ScmConfigKeys.OZONE_SCM_PIPELINE_ALLOCATED_TIMEOUT;
+import static 
org.apache.hadoop.hdds.scm.pipeline.Pipeline.PipelineState.ALLOCATED;
+import static org.apache.hadoop.test.MetricsAsserts.getLongCounter;
+import static org.apache.hadoop.test.MetricsAsserts.getMetrics;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+/**
+ * Tests for PipelineManagerImpl.
+ */
+public class TestPipelineManagerImpl {
+  private static OzoneConfiguration conf;
+  private static File testDir;
+  private DBStore dbStore;
+  private static MockNodeManager nodeManager;
+  private static int maxPipelineCount;
+  private static EventQueue eventQueue;
+
+  @Before
+  public void init() throws Exception {
+    conf = SCMTestUtils.getConf();
+    testDir = GenericTestUtils.getTestDir(
+        TestContainerManagerImpl.class.getSimpleName() + UUID.randomUUID());
+    conf.set(HddsConfigKeys.OZONE_METADATA_DIRS, testDir.getAbsolutePath());
+    dbStore = DBStoreBuilder.createDBStore(conf, new SCMDBDefinition());
+    nodeManager = new MockNodeManager(true, 20);
+    eventQueue = new EventQueue();
+    maxPipelineCount = nodeManager.getNodeCount(HddsProtos.NodeState.HEALTHY) *
+        conf.getInt(OZONE_DATANODE_PIPELINE_LIMIT,
+            OZONE_DATANODE_PIPELINE_LIMIT_DEFAULT) /
+        HddsProtos.ReplicationFactor.THREE.getNumber();
+  }
+
+  @After
+  public void cleanup() throws Exception {
+    if (dbStore != null) {
+      dbStore.close();
+    }
+    FileUtil.fullyDelete(testDir);
+  }
+
+  private PipelineManagerV2Impl createPipelineManager()
+      throws IOException {
+    return PipelineManagerV2Impl.newPipelineManager(
+        conf, MockSCMHAManager.getInstance(),
+        nodeManager,
+        SCMDBDefinition.PIPELINES.getTable(dbStore), eventQueue);
+  }
+
+  @Test
+  public void testCreatePipeline() throws Exception {
+    List<Pipeline> pipelines = new ArrayList<>();

Review comment:
       Updated.

##########
File path: 
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/pipeline/PipelineManagerV2Impl.java
##########
@@ -299,8 +299,9 @@ public void openPipeline(PipelineID pipelineId) throws 
IOException {
       }
       if (pipeline.getPipelineState() == Pipeline.PipelineState.ALLOCATED) {
         LOG.info("Pipeline {} moved to OPEN state", pipeline);
-        stateManager.updatePipelineState(pipelineId.getProtobuf(),
-            HddsProtos.PipelineState.PIPELINE_OPEN);
+        HddsProtos.Pipeline pipelineProto = stateManager.updatePipelineState(
+            pipelineId.getProtobuf(), HddsProtos.PipelineState.PIPELINE_OPEN);
+        pipeline = Pipeline.getFromProtobuf(pipelineProto);

Review comment:
       Updated.

##########
File path: 
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/pipeline/StateManager.java
##########
@@ -58,7 +58,7 @@ void removePipeline(HddsProtos.PipelineID pipelineIDProto)
    * @throws IOException
    */
   @Replicate
-  void updatePipelineState(HddsProtos.PipelineID pipelineIDProto,
+  HddsProtos.Pipeline updatePipelineState(HddsProtos.PipelineID 
pipelineIDProto,

Review comment:
       Updated.




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: ozone-issues-unsubscr...@hadoop.apache.org
For additional commands, e-mail: ozone-issues-h...@hadoop.apache.org

Reply via email to