HDFS-12313. Ozone: SCM: move container/pipeline StateMachine to the right package. Contributed by Xiaoyu Yao.
This commit is contained in:
parent
ad1d8197fc
commit
795ba1b3b7
@ -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.
|
||||
**/
|
@ -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.
|
@ -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 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);
|
||||
}
|
||||
}
|
@ -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.
|
||||
**/
|
@ -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);
|
Loading…
Reference in New Issue
Block a user