diff --git a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/ozone/common/package-info.java b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/ozone/common/package-info.java new file mode 100644 index 0000000000..1e9fd59252 --- /dev/null +++ b/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. + **/ \ No newline at end of file diff --git a/hadoop-hdfs-client/src/main/java/org/apache/hadoop/scm/container/common/helpers/StateMachine/InvalidStateTransitionException.java b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/ozone/common/statemachine/InvalidStateTransitionException.java similarity index 95% rename from hadoop-hdfs-client/src/main/java/org/apache/hadoop/scm/container/common/helpers/StateMachine/InvalidStateTransitionException.java rename to hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/ozone/common/statemachine/InvalidStateTransitionException.java index 1fab16b5cc..9aeff24838 100644 --- a/hadoop-hdfs-client/src/main/java/org/apache/hadoop/scm/container/common/helpers/StateMachine/InvalidStateTransitionException.java +++ b/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. diff --git a/hadoop-hdfs-client/src/main/java/org/apache/hadoop/scm/container/common/helpers/StateMachine/StateMachine.java b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/ozone/common/statemachine/StateMachine.java similarity index 87% rename from hadoop-hdfs-client/src/main/java/org/apache/hadoop/scm/container/common/helpers/StateMachine/StateMachine.java rename to hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/ozone/common/statemachine/StateMachine.java index 1d5436fe1f..bf8cbd596e 100644 --- a/hadoop-hdfs-client/src/main/java/org/apache/hadoop/scm/container/common/helpers/StateMachine/StateMachine.java +++ b/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, EVENT extends Enum> { private STATE initialState; private Set finalStates; - private final Cache> transitions = + private final LoadingCache> transitions = CacheBuilder.newBuilder().build( CacheLoader.from((Supplier>) () -> new HashMap())); @@ -62,8 +62,7 @@ public STATE getNextState(STATE from, EVENT e) 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); } } \ No newline at end of file diff --git a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/ozone/common/statemachine/package-info.java b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/ozone/common/statemachine/package-info.java new file mode 100644 index 0000000000..045409e3ed --- /dev/null +++ b/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. + **/ \ No newline at end of file diff --git a/hadoop-hdfs-client/src/test/java/org/apache/hadoop/scm/TestStateMachine.java b/hadoop-hdfs-project/hadoop-hdfs-client/src/test/java/org/apache/hadoop/ozone/common/TestStateMachine.java similarity index 80% rename from hadoop-hdfs-client/src/test/java/org/apache/hadoop/scm/TestStateMachine.java rename to hadoop-hdfs-project/hadoop-hdfs-client/src/test/java/org/apache/hadoop/ozone/common/TestStateMachine.java index f9e1d5a91c..d4c626e9f5 100644 --- a/hadoop-hdfs-client/src/test/java/org/apache/hadoop/scm/TestStateMachine.java +++ b/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 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 void testStateMachineStates() throws InvalidStateTransitionException { 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);