Browse Source

HDFS-12313. Ozone: SCM: move container/pipeline StateMachine to the right package. Contributed by Xiaoyu Yao.

Xiaoyu Yao 7 years ago
parent
commit
795ba1b3b7

+ 21 - 0
hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/ozone/common/package-info.java

@@ -0,0 +1,21 @@
+/**
+ * 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.ozone.common;
+/**
+  ozone common shared by SCM, KSM, etc.
+ **/

+ 1 - 1
hadoop-hdfs-client/src/main/java/org/apache/hadoop/scm/container/common/helpers/StateMachine/InvalidStateTransitionException.java → hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/ozone/common/statemachine/InvalidStateTransitionException.java

@@ -16,7 +16,7 @@
  *  limitations under the License.
  */
 
-package org.apache.hadoop.scm.container.common.helpers.StateMachine;
+package org.apache.hadoop.ozone.common.statemachine;
 
 /**
  * Class wraps invalid state transition exception.

+ 4 - 5
hadoop-hdfs-client/src/main/java/org/apache/hadoop/scm/container/common/helpers/StateMachine/StateMachine.java → hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/ozone/common/statemachine/StateMachine.java

@@ -16,12 +16,12 @@
  *  limitations under the License.
  */
 
-package org.apache.hadoop.scm.container.common.helpers.StateMachine;
+package org.apache.hadoop.ozone.common.statemachine;
 
 import com.google.common.base.Supplier;
-import com.google.common.cache.Cache;
 import com.google.common.cache.CacheBuilder;
 import com.google.common.cache.CacheLoader;
+import com.google.common.cache.LoadingCache;
 
 import java.util.HashMap;
 import java.util.Map;
@@ -36,7 +36,7 @@ public class StateMachine<STATE extends Enum<?>, EVENT extends Enum<?>> {
   private STATE initialState;
   private Set<STATE> finalStates;
 
-  private final Cache<EVENT, Map<STATE, STATE>> transitions =
+  private final LoadingCache<EVENT, Map<STATE, STATE>> transitions =
       CacheBuilder.newBuilder().build(
           CacheLoader.from((Supplier<Map<STATE, STATE>>) () -> new HashMap()));
 
@@ -62,8 +62,7 @@ public class StateMachine<STATE extends Enum<?>, EVENT extends Enum<?>> {
     return target;
   }
 
-  public void addTransition(STATE from, STATE to, EVENT e)
-      throws InvalidStateTransitionException {
+  public void addTransition(STATE from, STATE to, EVENT e) {
     transitions.getUnchecked(e).put(from, to);
   }
 }

+ 21 - 0
hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/ozone/common/statemachine/package-info.java

@@ -0,0 +1,21 @@
+/**
+ * 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.ozone.common.statemachine;
+/**
+ state machine template class for ozone.
+ **/

+ 19 - 10
hadoop-hdfs-client/src/test/java/org/apache/hadoop/scm/TestStateMachine.java → hadoop-hdfs-project/hadoop-hdfs-client/src/test/java/org/apache/hadoop/ozone/common/TestStateMachine.java

@@ -15,11 +15,11 @@
  * the License.
  */
 
-package org.apache.hadoop.scm;
+package org.apache.hadoop.ozone.common;
 
 import org.apache.commons.collections.SetUtils;
-import org.apache.hadoop.scm.container.common.helpers.StateMachine.InvalidStateTransitionException;
-import org.apache.hadoop.scm.container.common.helpers.StateMachine.StateMachine;
+import org.apache.hadoop.ozone.common.statemachine.InvalidStateTransitionException;
+import org.apache.hadoop.ozone.common.statemachine.StateMachine;
 import org.junit.Assert;
 import org.junit.Rule;
 import org.junit.Test;
@@ -28,17 +28,26 @@ import org.junit.rules.ExpectedException;
 import java.util.HashSet;
 import java.util.Set;
 
-import static org.apache.hadoop.scm.TestStateMachine.STATES.INIT;
-import static org.apache.hadoop.scm.TestStateMachine.STATES.CREATING;
-import static org.apache.hadoop.scm.TestStateMachine.STATES.OPERATIONAL;
-import static org.apache.hadoop.scm.TestStateMachine.STATES.CLOSED;
-import static org.apache.hadoop.scm.TestStateMachine.STATES.CLEANUP;
-import static org.apache.hadoop.scm.TestStateMachine.STATES.FINAL;
+import static org.apache.hadoop.ozone.common.TestStateMachine.STATES.INIT;
+import static org.apache.hadoop.ozone.common.TestStateMachine.STATES.CREATING;
+import static org.apache.hadoop.ozone.common.TestStateMachine.STATES.OPERATIONAL;
+import static org.apache.hadoop.ozone.common.TestStateMachine.STATES.CLOSED;
+import static org.apache.hadoop.ozone.common.TestStateMachine.STATES.CLEANUP;
+import static org.apache.hadoop.ozone.common.TestStateMachine.STATES.FINAL;
 
+/**
+ * This class is to test ozone common state machine.
+ */
 public class TestStateMachine {
 
+  /**
+   * STATES used by the test state machine.
+   */
   public enum STATES {INIT, CREATING, OPERATIONAL, CLOSED, CLEANUP, FINAL};
 
+  /**
+   * EVENTS used by the test state machine.
+   */
   public enum EVENTS {ALLOCATE, CREATE, UPDATE, CLOSE, DELETE, TIMEOUT};
 
   @Rule
@@ -75,7 +84,7 @@ public class TestStateMachine {
         CLEANUP, stateMachine.getNextState(CREATING, EVENTS.TIMEOUT));
     Assert.assertEquals("STATE should be CLOSED after being closed",
         CLOSED, stateMachine.getNextState(OPERATIONAL, EVENTS.CLOSE));
-    
+
     // Negative cases: invalid transition
     expectException();
     stateMachine.getNextState(OPERATIONAL, EVENTS.CREATE);