You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by hi...@apache.org on 2012/09/05 00:02:39 UTC
svn commit: r1380914 - in /incubator/ambari/branches/AMBARI-666: ./
ambari-server/src/main/java/org/apache/ambari/server/
ambari-server/src/main/java/org/apache/ambari/server/fsm/
ambari-server/src/main/java/org/apache/ambari/server/state/ ambari-serve...
Author: hitesh
Date: Tue Sep 4 22:02:37 2012
New Revision: 1380914
URL: http://svn.apache.org/viewvc?rev=1380914&view=rev
Log:
AMBARI-695. More basic class restructuring for new design. (Contributed by hitesh)
Added:
incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/
incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigVersion.java (with props)
incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/fsm/
incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/fsm/InvalidStateTransitonException.java (with props)
incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/fsm/MultipleArcTransition.java (with props)
incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/fsm/SingleArcTransition.java (with props)
incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/fsm/StateMachine.java (with props)
incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/fsm/StateMachineFactory.java (with props)
incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/
incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/AgentVersion.java (with props)
incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/DiskInfo.java (with props)
incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/Job.java (with props)
incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/JobEvent.java (with props)
incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/JobEventType.java (with props)
incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/JobId.java (with props)
incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/JobImpl.java (with props)
incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/JobState.java (with props)
incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/Node.java (with props)
incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/NodeEvent.java (with props)
incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/NodeEventType.java (with props)
incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/NodeHealthStatus.java (with props)
incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/NodeImpl.java (with props)
incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/NodeState.java (with props)
incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/ServiceComponentNode.java (with props)
incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/ServiceComponentNodeEvent.java (with props)
incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/ServiceComponentNodeEventType.java (with props)
incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/ServiceComponentNodeImpl.java (with props)
incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/ServiceComponentNodeState.java (with props)
Removed:
incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/AgentVersion.java
incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/Cluster.java
incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/Config.java
incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/ConfigVersion.java
incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/DiskInfo.java
incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/Job.java
incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/JobId.java
incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/JobState.java
incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/Node.java
incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/NodeHealthStatus.java
incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/NodeState.java
incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/Service.java
incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/ServiceComponent.java
incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/ServiceComponentNode.java
incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/ServiceComponentNodeState.java
incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/ServiceComponentType.java
incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/ServiceType.java
incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/fsm/InvalidStateTransitonException.java
incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/fsm/JobEvent.java
incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/fsm/JobEventType.java
incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/fsm/JobFSM.java
incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/fsm/JobFSMImpl.java
incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/fsm/MultipleArcTransition.java
incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/fsm/NodeEvent.java
incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/fsm/NodeEventType.java
incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/fsm/NodeFSM.java
incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/fsm/NodeFSMImpl.java
incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/fsm/ServiceComponentNodeEvent.java
incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/fsm/ServiceComponentNodeEventType.java
incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/fsm/ServiceComponentNodeFSM.java
incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/fsm/ServiceComponentNodeFSMImpl.java
incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/fsm/SingleArcTransition.java
incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/fsm/StateMachine.java
incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/fsm/StateMachineFactory.java
Modified:
incubator/ambari/branches/AMBARI-666/AMBARI-666-CHANGES.txt
Modified: incubator/ambari/branches/AMBARI-666/AMBARI-666-CHANGES.txt
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/AMBARI-666-CHANGES.txt?rev=1380914&r1=1380913&r2=1380914&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/AMBARI-666-CHANGES.txt (original)
+++ incubator/ambari/branches/AMBARI-666/AMBARI-666-CHANGES.txt Tue Sep 4 22:02:37 2012
@@ -12,6 +12,8 @@ AMBARI-666 branch (unreleased changes)
NEW FEATURES
+ AMBARI-695. More basic class restructuring for new design. (hitesh)
+
AMBARI-694. Class to encapsulate stage. (jitendra)
AMBARI-691. More basic classes for new design. (hitesh)
Added: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigVersion.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigVersion.java?rev=1380914&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigVersion.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigVersion.java Tue Sep 4 22:02:37 2012
@@ -0,0 +1,5 @@
+package org.apache.ambari.server.state;
+
+public interface ConfigVersion {
+
+}
Propchange: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigVersion.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/fsm/InvalidStateTransitonException.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/fsm/InvalidStateTransitonException.java?rev=1380914&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/fsm/InvalidStateTransitonException.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/fsm/InvalidStateTransitonException.java Tue Sep 4 22:02:37 2012
@@ -0,0 +1,41 @@
+/**
+* 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.ambari.server.state.fsm;
+
+// TODO
+public class InvalidStateTransitonException extends Exception {
+
+ private Enum<?> currentState;
+ private Enum<?> event;
+
+ public InvalidStateTransitonException(Enum<?> currentState, Enum<?> event) {
+ super("Invalid event: " + event + " at " + currentState);
+ this.currentState = currentState;
+ this.event = event;
+ }
+
+ public Enum<?> getCurrentState() {
+ return currentState;
+ }
+
+ public Enum<?> getEvent() {
+ return event;
+ }
+
+}
Propchange: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/fsm/InvalidStateTransitonException.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/fsm/MultipleArcTransition.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/fsm/MultipleArcTransition.java?rev=1380914&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/fsm/MultipleArcTransition.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/fsm/MultipleArcTransition.java Tue Sep 4 22:02:37 2012
@@ -0,0 +1,39 @@
+/**
+* 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.ambari.server.state.fsm;
+
+/**
+ * Hook for Transition.
+ * Post state is decided by Transition hook. Post state must be one of the
+ * valid post states registered in StateMachine.
+ */
+public interface MultipleArcTransition
+ <OPERAND, EVENT, STATE extends Enum<STATE>> {
+
+ /**
+ * Transition hook.
+ * @return the postState. Post state must be one of the
+ * valid post states registered in StateMachine.
+ * @param operand the entity attached to the FSM, whose internal
+ * state may change.
+ * @param event causal event
+ */
+ public STATE transition(OPERAND operand, EVENT event);
+
+}
Propchange: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/fsm/MultipleArcTransition.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/fsm/SingleArcTransition.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/fsm/SingleArcTransition.java?rev=1380914&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/fsm/SingleArcTransition.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/fsm/SingleArcTransition.java Tue Sep 4 22:02:37 2012
@@ -0,0 +1,35 @@
+/**
+* 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.ambari.server.state.fsm;
+
+/**
+ * Hook for Transition. This lead to state machine to move to
+ * the post state as registered in the state machine.
+ */
+public interface SingleArcTransition<OPERAND, EVENT> {
+ /**
+ * Transition hook.
+ *
+ * @param operand the entity attached to the FSM, whose internal
+ * state may change.
+ * @param event causal event
+ */
+ public void transition(OPERAND operand, EVENT event);
+
+}
Propchange: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/fsm/SingleArcTransition.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/fsm/StateMachine.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/fsm/StateMachine.java?rev=1380914&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/fsm/StateMachine.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/fsm/StateMachine.java Tue Sep 4 22:02:37 2012
@@ -0,0 +1,27 @@
+/**
+* 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.ambari.server.state.fsm;
+
+public interface StateMachine
+ <STATE extends Enum<STATE>,
+ EVENTTYPE extends Enum<EVENTTYPE>, EVENT> {
+ public STATE getCurrentState();
+ public STATE doTransition(EVENTTYPE eventType, EVENT event)
+ throws InvalidStateTransitonException;
+}
Propchange: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/fsm/StateMachine.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/fsm/StateMachineFactory.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/fsm/StateMachineFactory.java?rev=1380914&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/fsm/StateMachineFactory.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/fsm/StateMachineFactory.java Tue Sep 4 22:02:37 2012
@@ -0,0 +1,480 @@
+/**
+* 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.ambari.server.state.fsm;
+
+import java.util.EnumMap;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+import java.util.Stack;
+
+/**
+ * State machine topology.
+ * This object is semantically immutable. If you have a
+ * StateMachineFactory there's no operation in the API that changes
+ * its semantic properties.
+ *
+ * @param <OPERAND> The object type on which this state machine operates.
+ * @param <STATE> The state of the entity.
+ * @param <EVENTTYPE> The external eventType to be handled.
+ * @param <EVENT> The event object.
+ *
+ */
+final public class StateMachineFactory
+ <OPERAND, STATE extends Enum<STATE>,
+ EVENTTYPE extends Enum<EVENTTYPE>, EVENT> {
+
+ private final TransitionsListNode transitionsListNode;
+
+ private Map<STATE, Map<EVENTTYPE,
+ Transition<OPERAND, STATE, EVENTTYPE, EVENT>>> stateMachineTable;
+
+ private STATE defaultInitialState;
+
+ private final boolean optimized;
+
+ /**
+ * Constructor
+ *
+ * This is the only constructor in the API.
+ *
+ */
+ public StateMachineFactory(STATE defaultInitialState) {
+ this.transitionsListNode = null;
+ this.defaultInitialState = defaultInitialState;
+ this.optimized = false;
+ this.stateMachineTable = null;
+ }
+
+ private StateMachineFactory
+ (StateMachineFactory<OPERAND, STATE, EVENTTYPE, EVENT> that,
+ ApplicableTransition t) {
+ this.defaultInitialState = that.defaultInitialState;
+ this.transitionsListNode
+ = new TransitionsListNode(t, that.transitionsListNode);
+ this.optimized = false;
+ this.stateMachineTable = null;
+ }
+
+ private StateMachineFactory
+ (StateMachineFactory<OPERAND, STATE, EVENTTYPE, EVENT> that,
+ boolean optimized) {
+ this.defaultInitialState = that.defaultInitialState;
+ this.transitionsListNode = that.transitionsListNode;
+ this.optimized = optimized;
+ if (optimized) {
+ makeStateMachineTable();
+ } else {
+ stateMachineTable = null;
+ }
+ }
+
+ private interface ApplicableTransition
+ <OPERAND, STATE extends Enum<STATE>,
+ EVENTTYPE extends Enum<EVENTTYPE>, EVENT> {
+ void apply(StateMachineFactory<OPERAND, STATE, EVENTTYPE, EVENT> subject);
+ }
+
+ private class TransitionsListNode {
+ final ApplicableTransition transition;
+ final TransitionsListNode next;
+
+ TransitionsListNode
+ (ApplicableTransition transition, TransitionsListNode next) {
+ this.transition = transition;
+ this.next = next;
+ }
+ }
+
+ static private class ApplicableSingleOrMultipleTransition
+ <OPERAND, STATE extends Enum<STATE>,
+ EVENTTYPE extends Enum<EVENTTYPE>, EVENT>
+ implements ApplicableTransition<OPERAND, STATE, EVENTTYPE, EVENT> {
+ final STATE preState;
+ final EVENTTYPE eventType;
+ final Transition<OPERAND, STATE, EVENTTYPE, EVENT> transition;
+
+ ApplicableSingleOrMultipleTransition
+ (STATE preState, EVENTTYPE eventType,
+ Transition<OPERAND, STATE, EVENTTYPE, EVENT> transition) {
+ this.preState = preState;
+ this.eventType = eventType;
+ this.transition = transition;
+ }
+
+ @Override
+ public void apply
+ (StateMachineFactory<OPERAND, STATE, EVENTTYPE, EVENT> subject) {
+ Map<EVENTTYPE, Transition<OPERAND, STATE, EVENTTYPE, EVENT>> transitionMap
+ = subject.stateMachineTable.get(preState);
+ if (transitionMap == null) {
+ // I use HashMap here because I would expect most EVENTTYPE's to not
+ // apply out of a particular state, so FSM sizes would be
+ // quadratic if I use EnumMap's here as I do at the top level.
+ transitionMap = new HashMap<EVENTTYPE,
+ Transition<OPERAND, STATE, EVENTTYPE, EVENT>>();
+ subject.stateMachineTable.put(preState, transitionMap);
+ }
+ transitionMap.put(eventType, transition);
+ }
+ }
+
+ /**
+ * @return a NEW StateMachineFactory just like {@code this} with the current
+ * transition added as a new legal transition. This overload
+ * has no hook object.
+ *
+ * Note that the returned StateMachineFactory is a distinct
+ * object.
+ *
+ * This method is part of the API.
+ *
+ * @param preState pre-transition state
+ * @param postState post-transition state
+ * @param eventType stimulus for the transition
+ */
+ public StateMachineFactory
+ <OPERAND, STATE, EVENTTYPE, EVENT>
+ addTransition(STATE preState, STATE postState, EVENTTYPE eventType) {
+ return addTransition(preState, postState, eventType, null);
+ }
+
+ /**
+ * @return a NEW StateMachineFactory just like {@code this} with the current
+ * transition added as a new legal transition. This overload
+ * has no hook object.
+ *
+ *
+ * Note that the returned StateMachineFactory is a distinct
+ * object.
+ *
+ * This method is part of the API.
+ *
+ * @param preState pre-transition state
+ * @param postState post-transition state
+ * @param eventTypes List of stimuli for the transitions
+ */
+ public StateMachineFactory<OPERAND, STATE, EVENTTYPE, EVENT> addTransition(
+ STATE preState, STATE postState, Set<EVENTTYPE> eventTypes) {
+ return addTransition(preState, postState, eventTypes, null);
+ }
+
+ /**
+ * @return a NEW StateMachineFactory just like {@code this} with the current
+ * transition added as a new legal transition
+ *
+ * Note that the returned StateMachineFactory is a distinct
+ * object.
+ *
+ * This method is part of the API.
+ *
+ * @param preState pre-transition state
+ * @param postState post-transition state
+ * @param eventTypes List of stimuli for the transitions
+ * @param hook transition hook
+ */
+ public StateMachineFactory<OPERAND, STATE, EVENTTYPE, EVENT> addTransition(
+ STATE preState, STATE postState, Set<EVENTTYPE> eventTypes,
+ SingleArcTransition<OPERAND, EVENT> hook) {
+ StateMachineFactory<OPERAND, STATE, EVENTTYPE, EVENT> factory = null;
+ for (EVENTTYPE event : eventTypes) {
+ if (factory == null) {
+ factory = addTransition(preState, postState, event, hook);
+ } else {
+ factory = factory.addTransition(preState, postState, event, hook);
+ }
+ }
+ return factory;
+ }
+
+ /**
+ * @return a NEW StateMachineFactory just like {@code this} with the current
+ * transition added as a new legal transition
+ *
+ * Note that the returned StateMachineFactory is a distinct object.
+ *
+ * This method is part of the API.
+ *
+ * @param preState pre-transition state
+ * @param postState post-transition state
+ * @param eventType stimulus for the transition
+ * @param hook transition hook
+ */
+ public StateMachineFactory
+ <OPERAND, STATE, EVENTTYPE, EVENT>
+ addTransition(STATE preState, STATE postState,
+ EVENTTYPE eventType,
+ SingleArcTransition<OPERAND, EVENT> hook){
+ return new StateMachineFactory
+ (this, new ApplicableSingleOrMultipleTransition
+ (preState, eventType, new SingleInternalArc(postState, hook)));
+ }
+
+ /**
+ * @return a NEW StateMachineFactory just like {@code this} with the current
+ * transition added as a new legal transition
+ *
+ * Note that the returned StateMachineFactory is a distinct object.
+ *
+ * This method is part of the API.
+ *
+ * @param preState pre-transition state
+ * @param postStates valid post-transition states
+ * @param eventType stimulus for the transition
+ * @param hook transition hook
+ */
+ public StateMachineFactory
+ <OPERAND, STATE, EVENTTYPE, EVENT>
+ addTransition(STATE preState, Set<STATE> postStates,
+ EVENTTYPE eventType,
+ MultipleArcTransition<OPERAND, EVENT, STATE> hook){
+ return new StateMachineFactory
+ (this,
+ new ApplicableSingleOrMultipleTransition
+ (preState, eventType, new MultipleInternalArc(postStates, hook)));
+ }
+
+ /**
+ * @return a StateMachineFactory just like {@code this}, except that if
+ * you won't need any synchronization to build a state machine
+ *
+ * Note that the returned StateMachineFactory is a distinct object.
+ *
+ * This method is part of the API.
+ *
+ * The only way you could distinguish the returned
+ * StateMachineFactory from {@code this} would be by
+ * measuring the performance of the derived
+ * {@code StateMachine} you can get from it.
+ *
+ * Calling this is optional. It doesn't change the semantics of the factory,
+ * if you call it then when you use the factory there is no synchronization.
+ */
+ public StateMachineFactory
+ <OPERAND, STATE, EVENTTYPE, EVENT>
+ installTopology() {
+ return new StateMachineFactory(this, true);
+ }
+
+ /**
+ * Effect a transition due to the effecting stimulus.
+ * @param state current state
+ * @param eventType trigger to initiate the transition
+ * @param cause causal eventType context
+ * @return transitioned state
+ */
+ private STATE doTransition
+ (OPERAND operand, STATE oldState, EVENTTYPE eventType, EVENT event)
+ throws InvalidStateTransitonException {
+ // We can assume that stateMachineTable is non-null because we call
+ // maybeMakeStateMachineTable() when we build an InnerStateMachine ,
+ // and this code only gets called from inside a working InnerStateMachine .
+ Map<EVENTTYPE, Transition<OPERAND, STATE, EVENTTYPE, EVENT>> transitionMap
+ = stateMachineTable.get(oldState);
+ if (transitionMap != null) {
+ Transition<OPERAND, STATE, EVENTTYPE, EVENT> transition
+ = transitionMap.get(eventType);
+ if (transition != null) {
+ return transition.doTransition(operand, oldState, event, eventType);
+ }
+ }
+ throw new InvalidStateTransitonException(oldState, eventType);
+ }
+
+ private synchronized void maybeMakeStateMachineTable() {
+ if (stateMachineTable == null) {
+ makeStateMachineTable();
+ }
+ }
+
+ private void makeStateMachineTable() {
+ Stack<ApplicableTransition> stack = new Stack<ApplicableTransition>();
+
+ Map<STATE, Map<EVENTTYPE, Transition<OPERAND, STATE, EVENTTYPE, EVENT>>>
+ prototype = new HashMap<STATE, Map<EVENTTYPE, Transition<OPERAND, STATE, EVENTTYPE, EVENT>>>();
+
+ prototype.put(defaultInitialState, null);
+
+ // I use EnumMap here because it'll be faster and denser. I would
+ // expect most of the states to have at least one transition.
+ stateMachineTable
+ = new EnumMap<STATE, Map<EVENTTYPE,
+ Transition<OPERAND, STATE, EVENTTYPE, EVENT>>>(prototype);
+
+ for (TransitionsListNode cursor = transitionsListNode;
+ cursor != null;
+ cursor = cursor.next) {
+ stack.push(cursor.transition);
+ }
+
+ while (!stack.isEmpty()) {
+ stack.pop().apply(this);
+ }
+ }
+
+ private interface Transition<OPERAND, STATE extends Enum<STATE>,
+ EVENTTYPE extends Enum<EVENTTYPE>, EVENT> {
+ STATE doTransition(OPERAND operand, STATE oldState,
+ EVENT event, EVENTTYPE eventType)
+ throws InvalidStateTransitonException;
+ }
+
+ private class SingleInternalArc
+ implements Transition<OPERAND, STATE, EVENTTYPE, EVENT> {
+
+ private STATE postState;
+ private SingleArcTransition<OPERAND, EVENT> hook; // transition hook
+
+ SingleInternalArc(STATE postState,
+ SingleArcTransition<OPERAND, EVENT> hook) {
+ this.postState = postState;
+ this.hook = hook;
+ }
+
+ @Override
+ public STATE doTransition(OPERAND operand, STATE oldState,
+ EVENT event, EVENTTYPE eventType) {
+ if (hook != null) {
+ hook.transition(operand, event);
+ }
+ return postState;
+ }
+ }
+
+ private class MultipleInternalArc
+ implements Transition<OPERAND, STATE, EVENTTYPE, EVENT>{
+
+ // Fields
+ private Set<STATE> validPostStates;
+ private MultipleArcTransition<OPERAND, EVENT, STATE> hook; // transition hook
+
+ MultipleInternalArc(Set<STATE> postStates,
+ MultipleArcTransition<OPERAND, EVENT, STATE> hook) {
+ this.validPostStates = postStates;
+ this.hook = hook;
+ }
+
+ @Override
+ public STATE doTransition(OPERAND operand, STATE oldState,
+ EVENT event, EVENTTYPE eventType)
+ throws InvalidStateTransitonException {
+ STATE postState = hook.transition(operand, event);
+
+ if (!validPostStates.contains(postState)) {
+ throw new InvalidStateTransitonException(oldState, eventType);
+ }
+ return postState;
+ }
+ }
+
+ /*
+ * @return a {@link StateMachine} that starts in
+ * {@code initialState} and whose {@link Transition} s are
+ * applied to {@code operand} .
+ *
+ * This is part of the API.
+ *
+ * @param operand the object upon which the returned
+ * {@link StateMachine} will operate.
+ * @param initialState the state in which the returned
+ * {@link StateMachine} will start.
+ *
+ */
+ public StateMachine<STATE, EVENTTYPE, EVENT>
+ make(OPERAND operand, STATE initialState) {
+ return new InternalStateMachine(operand, initialState);
+ }
+
+ /*
+ * @return a {@link StateMachine} that starts in the default initial
+ * state and whose {@link Transition} s are applied to
+ * {@code operand} .
+ *
+ * This is part of the API.
+ *
+ * @param operand the object upon which the returned
+ * {@link StateMachine} will operate.
+ *
+ */
+ public StateMachine<STATE, EVENTTYPE, EVENT> make(OPERAND operand) {
+ return new InternalStateMachine(operand, defaultInitialState);
+ }
+
+ private class InternalStateMachine
+ implements StateMachine<STATE, EVENTTYPE, EVENT> {
+ private final OPERAND operand;
+ private STATE currentState;
+
+ InternalStateMachine(OPERAND operand, STATE initialState) {
+ this.operand = operand;
+ this.currentState = initialState;
+ if (!optimized) {
+ maybeMakeStateMachineTable();
+ }
+ }
+
+ @Override
+ public synchronized STATE getCurrentState() {
+ return currentState;
+ }
+
+ @Override
+ public synchronized STATE doTransition(EVENTTYPE eventType, EVENT event)
+ throws InvalidStateTransitonException {
+ currentState = StateMachineFactory.this.doTransition
+ (operand, currentState, eventType, event);
+ return currentState;
+ }
+ }
+
+ /*
+ * Generate a graph represents the state graph of this StateMachine
+ * @param name graph name
+ * @return Graph object generated
+ public Graph generateStateGraph(String name) {
+ maybeMakeStateMachineTable();
+ Graph g = new Graph(name);
+ for (STATE startState : stateMachineTable.keySet()) {
+ Map<EVENTTYPE, Transition<OPERAND, STATE, EVENTTYPE, EVENT>> transitions
+ = stateMachineTable.get(startState);
+ for (Entry<EVENTTYPE, Transition<OPERAND, STATE, EVENTTYPE, EVENT>> entry :
+ transitions.entrySet()) {
+ Transition<OPERAND, STATE, EVENTTYPE, EVENT> transition = entry.getValue();
+ if (transition instanceof StateMachineFactory.SingleInternalArc) {
+ StateMachineFactory.SingleInternalArc sa
+ = (StateMachineFactory.SingleInternalArc) transition;
+ Graph.Node fromNode = g.getNode(startState.toString());
+ Graph.Node toNode = g.getNode(sa.postState.toString());
+ fromNode.addEdge(toNode, entry.getKey().toString());
+ } else if (transition instanceof StateMachineFactory.MultipleInternalArc) {
+ StateMachineFactory.MultipleInternalArc ma
+ = (StateMachineFactory.MultipleInternalArc) transition;
+ Iterator<STATE> iter = ma.validPostStates.iterator();
+ while (iter.hasNext()) {
+ Graph.Node fromNode = g.getNode(startState.toString());
+ Graph.Node toNode = g.getNode(iter.next().toString());
+ fromNode.addEdge(toNode, entry.getKey().toString());
+ }
+ }
+ }
+ }
+ return g;
+ }
+ */
+}
Propchange: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/fsm/StateMachineFactory.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/AgentVersion.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/AgentVersion.java?rev=1380914&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/AgentVersion.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/AgentVersion.java Tue Sep 4 22:02:37 2012
@@ -0,0 +1,6 @@
+package org.apache.ambari.server.state.live;
+
+// TODO
+public class AgentVersion {
+
+}
Propchange: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/AgentVersion.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/DiskInfo.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/DiskInfo.java?rev=1380914&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/DiskInfo.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/DiskInfo.java Tue Sep 4 22:02:37 2012
@@ -0,0 +1,35 @@
+package org.apache.ambari.server.state.live;
+
+/**
+ * Information about a mounted disk on a given node
+ */
+public class DiskInfo {
+
+ /**
+ * Name of device
+ * For example: /dev/sda, /dev/sdb, etc
+ */
+ String device;
+
+ /**
+ * Filesystem Type
+ * For example: ext3, tmpfs, swap, etc
+ */
+ String fsType;
+
+ /**
+ * Path at which the device is mounted on
+ */
+ String mountPath;
+
+ /**
+ * Capacity of the disk in bytes
+ */
+ long totalCapacityBytes;
+
+ /**
+ * Current capacity in bytes
+ */
+ long currentCapacityBytes;
+
+}
Propchange: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/DiskInfo.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/Job.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/Job.java?rev=1380914&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/Job.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/Job.java Tue Sep 4 22:02:37 2012
@@ -0,0 +1,37 @@
+package org.apache.ambari.server.state.live;
+
+import org.apache.ambari.server.state.fsm.InvalidStateTransitonException;
+
+public interface Job {
+
+ /**
+ * Get the Job ID for the action
+ * @return JobId
+ */
+ public JobId getId();
+
+ // TODO requires some form of JobType to ensure only one running
+ // action per action type
+ // There may be gotchas such as de-commissioning should be allowed to happen
+ // on more than one node at a time
+
+ /**
+ * Get the current state of the Job
+ * @return JobState
+ */
+ public JobState getState();
+
+ /**
+ * Set the State of the Job
+ * @param state JobState
+ */
+ public void setState(JobState state);
+
+ /**
+ * Send a JobEvent to the Job's StateMachine
+ * @param event JobEvent
+ * @throws InvalidStateTransitonException
+ */
+ public void handleEvent(JobEvent event)
+ throws InvalidStateTransitonException;
+}
Propchange: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/Job.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/JobEvent.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/JobEvent.java?rev=1380914&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/JobEvent.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/JobEvent.java Tue Sep 4 22:02:37 2012
@@ -0,0 +1,13 @@
+package org.apache.ambari.server.state.live;
+
+import org.apache.ambari.server.fsm.event.AbstractEvent;
+
+public class JobEvent extends AbstractEvent<JobEventType> {
+
+ // TODO
+ // this should have some action identifier
+ public JobEvent(JobEventType type) {
+ super(type);
+ // TODO Auto-generated constructor stub
+ }
+}
Propchange: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/JobEvent.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/JobEventType.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/JobEventType.java?rev=1380914&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/JobEventType.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/JobEventType.java Tue Sep 4 22:02:37 2012
@@ -0,0 +1,20 @@
+package org.apache.ambari.server.state.live;
+
+public enum JobEventType {
+ /**
+ * Initial state for the job when triggered.
+ */
+ JOB_INIT,
+ /**
+ * Job still in progress.
+ */
+ JOB_IN_PROGRESS,
+ /**
+ * Job completed successfully.
+ */
+ JOB_COMPLETED,
+ /**
+ * Job failed to complete successfully.
+ */
+ JOB_FAILED
+}
Propchange: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/JobEventType.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/JobId.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/JobId.java?rev=1380914&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/JobId.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/JobId.java Tue Sep 4 22:02:37 2012
@@ -0,0 +1,6 @@
+package org.apache.ambari.server.state.live;
+
+// TODO
+public class JobId {
+
+}
Propchange: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/JobId.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/JobImpl.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/JobImpl.java?rev=1380914&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/JobImpl.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/JobImpl.java Tue Sep 4 22:02:37 2012
@@ -0,0 +1,65 @@
+package org.apache.ambari.server.state.live;
+
+import org.apache.ambari.server.state.fsm.InvalidStateTransitonException;
+import org.apache.ambari.server.state.fsm.StateMachine;
+import org.apache.ambari.server.state.fsm.StateMachineFactory;
+
+public class JobImpl implements Job {
+
+ private static final StateMachineFactory
+ <JobImpl, JobState, JobEventType, JobEvent>
+ stateMachineFactory
+ = new StateMachineFactory<JobImpl, JobState,
+ JobEventType, JobEvent>
+ (JobState.INIT)
+
+ // define the state machine of a Job
+
+ .addTransition(JobState.INIT, JobState.IN_PROGRESS,
+ JobEventType.JOB_IN_PROGRESS)
+ .addTransition(JobState.IN_PROGRESS, JobState.IN_PROGRESS,
+ JobEventType.JOB_IN_PROGRESS)
+ .addTransition(JobState.IN_PROGRESS, JobState.COMPLETED,
+ JobEventType.JOB_COMPLETED)
+ .addTransition(JobState.IN_PROGRESS, JobState.FAILED,
+ JobEventType.JOB_FAILED)
+ .addTransition(JobState.COMPLETED, JobState.INIT,
+ JobEventType.JOB_INIT)
+ .addTransition(JobState.FAILED, JobState.INIT,
+ JobEventType.JOB_INIT)
+ .installTopology();
+
+ private final StateMachine<JobState, JobEventType, JobEvent>
+ stateMachine;
+
+ public JobImpl() {
+ super();
+ this.stateMachine = stateMachineFactory.make(this);
+ }
+
+ @Override
+ public JobState getState() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public void setState(JobState state) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void handleEvent(JobEvent event)
+ throws InvalidStateTransitonException {
+ // TODO
+ stateMachine.doTransition(event.getType(), event);
+ }
+
+ @Override
+ public JobId getId() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
Propchange: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/JobImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/JobState.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/JobState.java?rev=1380914&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/JobState.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/JobState.java Tue Sep 4 22:02:37 2012
@@ -0,0 +1,21 @@
+package org.apache.ambari.server.state.live;
+
+public enum JobState {
+ /**
+ * Initial state for the Job.
+ * When a new action is triggered or set in motion.
+ */
+ INIT,
+ /**
+ * State when the job is triggered on the cluster,
+ */
+ IN_PROGRESS,
+ /**
+ * State of successful completion
+ */
+ COMPLETED,
+ /**
+ * Job failed to complete successfully
+ */
+ FAILED
+}
Propchange: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/JobState.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/Node.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/Node.java?rev=1380914&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/Node.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/Node.java Tue Sep 4 22:02:37 2012
@@ -0,0 +1,224 @@
+package org.apache.ambari.server.state.live;
+
+import java.util.List;
+import java.util.Map;
+
+import org.apache.ambari.server.state.fsm.InvalidStateTransitonException;
+
+public interface Node {
+
+ /**
+ * @return the hostName
+ */
+ public String getHostName();
+
+ /**
+ * @param hostName the hostName to set
+ */
+ public void setHostName(String hostName);
+
+ /**
+ * IPv4 assigned to the Node
+ * @return the ip or null if no IPv4 interface
+ */
+ public String getIPv4();
+
+ /**
+ * @param ip the ip to set
+ */
+ public void setIPv4(String ip);
+
+ /**
+ * IPv6 assigned to the Node
+ * @return the ip or null if no IPv6 interface
+ */
+ public String getIPv6();
+
+ /**
+ * @param ip the ip to set
+ */
+ public void setIPv6(String ip);
+
+ /**
+ * @return the cpuCount
+ */
+ public int getCpuCount();
+
+ /**
+ * @param cpuCount the cpuCount to set
+ */
+ public void setCpuCount(int cpuCount);
+
+ /**
+ * Get the Amount of physical memory for the Node.
+ * @return the totalMemBytes
+ */
+ public int getTotalMemBytes();
+
+ /**
+ * Set the Amount of physical memory for the Node.
+ * @param totalMemBytes the totalMemBytes to set
+ */
+ public void setTotalMemBytes(int totalMemBytes);
+
+ /**
+ * Get the Amount of available memory for the Node.
+ * In most cases, available should be same as total unless
+ * the agent on the node is configured to not use all
+ * available memory
+ * @return the availableMemBytes
+ */
+ public int getAvailableMemBytes();
+
+ /**
+ * Set the Amount of available memory for the Node.
+ * @param availableMemBytes the availableMemBytes to set
+ */
+ public void setAvailableMemBytes(int availableMemBytes);
+
+ /**
+ * Get the OS Architecture.
+ * i386, x86_64, etc.
+ * @return the osArch
+ */
+ public String getOsArch();
+
+ /**
+ * @param osArch the osArch to set
+ */
+ public void setOsArch(String osArch);
+
+ /**
+ * Get the General OS information.
+ * uname -a, /etc/*-release dump
+ * @return the osInfo
+ */
+ public String getOsInfo();
+
+ /**
+ * @param osInfo the osInfo to set
+ */
+ public void setOsInfo(String osInfo);
+
+ /**
+ * Get the OS Type: RHEL5/RHEL6/CentOS5/...
+ * Defined and match-able OS type
+ * @return the osType
+ */
+ public String getOsType();
+
+ /**
+ * @param osType the osType to set
+ */
+ public void setOsType(String osType);
+
+ /**
+ * Get information on disks available on the node.
+ * @return the disksInfo
+ */
+ public List<DiskInfo> getDisksInfo();
+
+ /**
+ * @param disksInfo the disksInfo to set
+ */
+ public void setDisksInfo(List<DiskInfo> disksInfo);
+
+ /**
+ * @return the healthStatus
+ */
+ public NodeHealthStatus getHealthStatus();
+
+ /**
+ * @param healthStatus the healthStatus to set
+ */
+ public void setHealthStatus(NodeHealthStatus healthStatus);
+
+ /**
+ * Get additional host attributes
+ * For example, public/hostname/IP for AWS
+ * @return the hostAttributes
+ */
+ public Map<String, String> getHostAttributes();
+
+ /**
+ * @param hostAttributes the hostAttributes to set
+ */
+ public void setHostAttributes(Map<String, String> hostAttributes);
+ /**
+ * @return the rackInfo
+ */
+ public String getRackInfo();
+
+ /**
+ * @param rackInfo the rackInfo to set
+ */
+ public void setRackInfo(String rackInfo);
+
+ /**
+ * Last time the node registered with the Ambari Server
+ * ( Unix timestamp )
+ * @return the lastRegistrationTime
+ */
+ public int getLastRegistrationTime();
+
+ /**
+ * @param lastRegistrationTime the lastRegistrationTime to set
+ */
+ public void setLastRegistrationTime(int lastRegistrationTime);
+
+ /**
+ * Last time the Ambari Server received a heartbeat from the Node
+ * ( Unix timestamp )
+ * @return the lastHeartbeatTime
+ */
+ public int getLastHeartbeatTime();
+
+ /**
+ * @param lastHeartbeatTime the lastHeartbeatTime to set
+ */
+ public void setLastHeartbeatTime(int lastHeartbeatTime);
+
+ /**
+ * Version of the Ambari Agent running on the node
+ * @return the agentVersion
+ */
+ public AgentVersion getAgentVersion();
+
+ /**
+ * @param agentVersion the agentVersion to set
+ */
+ public void setAgentVersion(AgentVersion agentVersion);
+
+ /**
+ * Get the current state of the Node
+ * @return NodeState
+ */
+ public NodeState getNodeState();
+
+ /**
+ * Get the list of Jobs that are currently being tracked at the
+ * Node level
+ * @return List of Jobs
+ */
+ public List<Job> getJobs();
+
+ /**
+ * Get Node State
+ * @return NodeState
+ */
+ public NodeState getState();
+
+ /**
+ * Set the State of the Node
+ * @param state Node State
+ */
+ public void setState(NodeState state);
+
+ /**
+ * Send an event to the Node's StateMachine
+ * @param event NodeEvent
+ * @throws InvalidStateTransitonException
+ */
+ public void handleEvent(NodeEvent event)
+ throws InvalidStateTransitonException;
+}
Propchange: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/Node.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/NodeEvent.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/NodeEvent.java?rev=1380914&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/NodeEvent.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/NodeEvent.java Tue Sep 4 22:02:37 2012
@@ -0,0 +1,14 @@
+package org.apache.ambari.server.state.live;
+
+import org.apache.ambari.server.fsm.event.AbstractEvent;
+
+public class NodeEvent extends AbstractEvent<NodeEventType> {
+
+ // TODO
+ // this should have some node identifier
+ public NodeEvent(NodeEventType type) {
+ super(type);
+ // TODO Auto-generated constructor stub
+ }
+
+}
Propchange: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/NodeEvent.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/NodeEventType.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/NodeEventType.java?rev=1380914&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/NodeEventType.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/NodeEventType.java Tue Sep 4 22:02:37 2012
@@ -0,0 +1,24 @@
+package org.apache.ambari.server.state.live;
+
+public enum NodeEventType {
+ /**
+ * Event to denote when a registration request is received from a Node
+ */
+ NODE_REGISTRATION_REQUEST,
+ /**
+ * Node authenticated/verified.
+ */
+ NODE_VERIFIED,
+ /**
+ * A healthy heartbeat event received from the Node.
+ */
+ NODE_HEARTBEAT_HEALTHY,
+ /**
+ * No heartbeat received from the Node within the defined expiry interval.
+ */
+ NODE_HEARTBEAT_TIMED_OUT,
+ /**
+ * A non-healthy heartbeat event received from the Node.
+ */
+ NODE_HEARTBEAT_UNHEALTHY
+}
Propchange: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/NodeEventType.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/NodeHealthStatus.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/NodeHealthStatus.java?rev=1380914&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/NodeHealthStatus.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/NodeHealthStatus.java Tue Sep 4 22:02:37 2012
@@ -0,0 +1,5 @@
+package org.apache.ambari.server.state.live;
+
+public interface NodeHealthStatus {
+
+}
Propchange: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/NodeHealthStatus.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/NodeImpl.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/NodeImpl.java?rev=1380914&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/NodeImpl.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/NodeImpl.java Tue Sep 4 22:02:37 2012
@@ -0,0 +1,291 @@
+package org.apache.ambari.server.state.live;
+
+import java.util.List;
+import java.util.Map;
+
+import org.apache.ambari.server.state.fsm.InvalidStateTransitonException;
+import org.apache.ambari.server.state.fsm.SingleArcTransition;
+import org.apache.ambari.server.state.fsm.StateMachine;
+import org.apache.ambari.server.state.fsm.StateMachineFactory;
+
+public class NodeImpl implements Node {
+
+ private static final StateMachineFactory
+ <NodeImpl, NodeState, NodeEventType, NodeEvent>
+ stateMachineFactory
+ = new StateMachineFactory<NodeImpl, NodeState, NodeEventType, NodeEvent>
+ (NodeState.INIT)
+
+ // define the state machine of a Node
+
+ .addTransition(NodeState.INIT, NodeState.WAITING_FOR_VERIFICATION,
+ NodeEventType.NODE_REGISTRATION_REQUEST)
+
+ .addTransition(NodeState.WAITING_FOR_VERIFICATION, NodeState.HEALTHY,
+ NodeEventType.NODE_VERIFIED, new NodeVerifiedTransition())
+
+ // TODO - should be able to combine multiple into a single multi-arc
+ // transition
+ .addTransition(NodeState.HEALTHY, NodeState.HEALTHY,
+ NodeEventType.NODE_HEARTBEAT_HEALTHY)
+ .addTransition(NodeState.HEALTHY, NodeState.HEARTBEAT_LOST,
+ NodeEventType.NODE_HEARTBEAT_TIMED_OUT)
+ .addTransition(NodeState.HEALTHY, NodeState.UNHEALTHY,
+ NodeEventType.NODE_HEARTBEAT_UNHEALTHY)
+
+ .addTransition(NodeState.UNHEALTHY, NodeState.HEALTHY,
+ NodeEventType.NODE_HEARTBEAT_HEALTHY)
+ .addTransition(NodeState.UNHEALTHY, NodeState.UNHEALTHY,
+ NodeEventType.NODE_HEARTBEAT_UNHEALTHY)
+ .addTransition(NodeState.UNHEALTHY, NodeState.HEARTBEAT_LOST,
+ NodeEventType.NODE_HEARTBEAT_TIMED_OUT)
+
+ .addTransition(NodeState.HEARTBEAT_LOST, NodeState.HEALTHY,
+ NodeEventType.NODE_HEARTBEAT_HEALTHY)
+ .addTransition(NodeState.HEARTBEAT_LOST, NodeState.UNHEALTHY,
+ NodeEventType.NODE_HEARTBEAT_UNHEALTHY)
+ .addTransition(NodeState.HEARTBEAT_LOST, NodeState.HEARTBEAT_LOST,
+ NodeEventType.NODE_HEARTBEAT_TIMED_OUT)
+ .installTopology();
+
+ private final StateMachine<NodeState, NodeEventType, NodeEvent> stateMachine;
+
+ public NodeImpl() {
+ super();
+ this.stateMachine = stateMachineFactory.make(this);
+ }
+
+ static class NodeVerifiedTransition
+ implements SingleArcTransition<NodeImpl, NodeEvent> {
+
+ @Override
+ public void transition(NodeImpl node, NodeEvent event) {
+ // TODO Auto-generated method stub
+ }
+
+ }
+
+ @Override
+ public NodeState getState() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public void setState(NodeState state) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void handleEvent(NodeEvent event)
+ throws InvalidStateTransitonException {
+ // TODO Auto-generated method stub
+ stateMachine.doTransition(event.getType(), event);
+ }
+
+ @Override
+ public String getHostName() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public void setHostName(String hostName) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public String getIPv4() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public void setIPv4(String ip) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public String getIPv6() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public void setIPv6(String ip) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public int getCpuCount() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ @Override
+ public void setCpuCount(int cpuCount) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public int getTotalMemBytes() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ @Override
+ public void setTotalMemBytes(int totalMemBytes) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public int getAvailableMemBytes() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ @Override
+ public void setAvailableMemBytes(int availableMemBytes) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public String getOsArch() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public void setOsArch(String osArch) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public String getOsInfo() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public void setOsInfo(String osInfo) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public String getOsType() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public void setOsType(String osType) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public List<DiskInfo> getDisksInfo() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public void setDisksInfo(List<DiskInfo> disksInfo) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public NodeHealthStatus getHealthStatus() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public void setHealthStatus(NodeHealthStatus healthStatus) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public Map<String, String> getHostAttributes() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public void setHostAttributes(Map<String, String> hostAttributes) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public String getRackInfo() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public void setRackInfo(String rackInfo) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public int getLastRegistrationTime() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ @Override
+ public void setLastRegistrationTime(int lastRegistrationTime) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public int getLastHeartbeatTime() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ @Override
+ public void setLastHeartbeatTime(int lastHeartbeatTime) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public AgentVersion getAgentVersion() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public void setAgentVersion(AgentVersion agentVersion) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public NodeState getNodeState() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public List<Job> getJobs() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
Propchange: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/NodeImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/NodeState.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/NodeState.java?rev=1380914&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/NodeState.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/NodeState.java Tue Sep 4 22:02:37 2012
@@ -0,0 +1,28 @@
+package org.apache.ambari.server.state.live;
+
+public enum NodeState {
+ /**
+ * New node state
+ */
+ INIT,
+ /**
+ * State when a registration request is received from the Node but
+ * the node has not been verified/authenticated.
+ */
+ WAITING_FOR_VERIFICATION,
+ /**
+ * State when the server is receiving heartbeats regularly from the Node
+ * and the state of the Node is healthy
+ */
+ HEALTHY,
+ /**
+ * State when the server has not received a heartbeat from the Node in the
+ * configured heartbeat expiry window.
+ */
+ HEARTBEAT_LOST,
+ /**
+ * Node is in unhealthy state as reported either by the Node itself or via
+ * any other additional means ( monitoring layer )
+ */
+ UNHEALTHY
+}
Propchange: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/NodeState.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/ServiceComponentNode.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/ServiceComponentNode.java?rev=1380914&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/ServiceComponentNode.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/ServiceComponentNode.java Tue Sep 4 22:02:37 2012
@@ -0,0 +1,58 @@
+package org.apache.ambari.server.state.live;
+
+import java.util.List;
+
+import org.apache.ambari.server.state.ConfigVersion;
+import org.apache.ambari.server.state.fsm.InvalidStateTransitonException;
+
+
+public interface ServiceComponentNode {
+
+ /**
+ * Get the ServiceComponent this object maps to
+ * @return Name of the ServiceComponent
+ */
+ public String getServiceComponentName();
+
+ /**
+ * Get the Node this object maps to
+ * @return Node's hostname
+ */
+ public String getNodeName();
+
+
+ /**
+ * Get the Config Version
+ * @return ConfigVersion
+ */
+ public ConfigVersion getConfigVersion();
+
+ /**
+ * Get the list of Jobs that are currently being tracked at the
+ * ServiceComponentNode level
+ * @return List of Jobs
+ */
+ public List<Job> getJobs();
+
+
+ /**
+ * Get ServiceComponent-Node State
+ * @return ServiceComponentNodeState
+ */
+ public ServiceComponentNodeState getState();
+
+ /**
+ * Set the State for this ServiceComponent-Node
+ * @param state ServiceComponentNodeState to set to
+ */
+ public void setState(ServiceComponentNodeState state);
+
+ /**
+ * Send a ServiceComponentNodeState event to the StateMachine
+ * @param event Event to handle
+ * @throws InvalidStateTransitonException
+ */
+ public void handleEvent(ServiceComponentNodeEvent event)
+ throws InvalidStateTransitonException;
+
+}
Propchange: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/ServiceComponentNode.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/ServiceComponentNodeEvent.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/ServiceComponentNodeEvent.java?rev=1380914&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/ServiceComponentNodeEvent.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/ServiceComponentNodeEvent.java Tue Sep 4 22:02:37 2012
@@ -0,0 +1,13 @@
+package org.apache.ambari.server.state.live;
+
+import org.apache.ambari.server.fsm.event.AbstractEvent;
+
+public class ServiceComponentNodeEvent
+ extends AbstractEvent<ServiceComponentNodeEventType> {
+
+ public ServiceComponentNodeEvent(ServiceComponentNodeEventType type) {
+ super(type);
+ // TODO Auto-generated constructor stub
+ }
+
+}
Propchange: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/ServiceComponentNodeEvent.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/ServiceComponentNodeEventType.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/ServiceComponentNodeEventType.java?rev=1380914&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/ServiceComponentNodeEventType.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/ServiceComponentNodeEventType.java Tue Sep 4 22:02:37 2012
@@ -0,0 +1,40 @@
+package org.apache.ambari.server.state.live;
+
+public enum ServiceComponentNodeEventType {
+ /**
+ * Operation in progress
+ */
+ NODE_SVCCOMP_OP_IN_PROGRESS,
+ /**
+ * Operation succeeded
+ */
+ NODE_SVCCOMP_OP_SUCCEEDED,
+ /**
+ * Operation failed.
+ */
+ NODE_SVCCOMP_OP_FAILED,
+ /**
+ * Re-starting a failed operation.
+ */
+ NODE_SVCCOMP_OP_RESTART,
+ /**
+ * Triggering an install.
+ */
+ NODE_SVCCOMP_INSTALL,
+ /**
+ * Triggering a start.
+ */
+ NODE_SVCCOMP_START,
+ /**
+ * Triggering a stop.
+ */
+ NODE_SVCCOMP_STOP,
+ /**
+ * Triggering an uninstall.
+ */
+ NODE_SVCCOMP_UNINSTALL,
+ /**
+ * Triggering a wipe-out ( restore to clean state ).
+ */
+ NODE_SVCCOMP_WIPEOUT
+}
Propchange: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/ServiceComponentNodeEventType.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/ServiceComponentNodeImpl.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/ServiceComponentNodeImpl.java?rev=1380914&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/ServiceComponentNodeImpl.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/ServiceComponentNodeImpl.java Tue Sep 4 22:02:37 2012
@@ -0,0 +1,222 @@
+package org.apache.ambari.server.state.live;
+
+import java.util.List;
+
+import org.apache.ambari.server.state.ConfigVersion;
+import org.apache.ambari.server.state.fsm.InvalidStateTransitonException;
+import org.apache.ambari.server.state.fsm.StateMachine;
+import org.apache.ambari.server.state.fsm.StateMachineFactory;
+
+public class ServiceComponentNodeImpl implements ServiceComponentNode {
+
+ private static final StateMachineFactory
+ <ServiceComponentNodeImpl, ServiceComponentNodeState,
+ ServiceComponentNodeEventType, ServiceComponentNodeEvent>
+ daemonStateMachineFactory
+ = new StateMachineFactory<ServiceComponentNodeImpl,
+ ServiceComponentNodeState, ServiceComponentNodeEventType,
+ ServiceComponentNodeEvent>
+ (ServiceComponentNodeState.INIT)
+
+ // define the state machine of a NodeServiceComponent
+
+ .addTransition(ServiceComponentNodeState.INIT,
+ ServiceComponentNodeState.INSTALLING,
+ ServiceComponentNodeEventType.NODE_SVCCOMP_INSTALL)
+
+ .addTransition(ServiceComponentNodeState.INSTALLING,
+ ServiceComponentNodeState.INSTALLED,
+ ServiceComponentNodeEventType.NODE_SVCCOMP_OP_SUCCEEDED)
+ .addTransition(ServiceComponentNodeState.INSTALLING,
+ ServiceComponentNodeState.INSTALLING,
+ ServiceComponentNodeEventType.NODE_SVCCOMP_OP_IN_PROGRESS)
+ .addTransition(ServiceComponentNodeState.INSTALLING,
+ ServiceComponentNodeState.INSTALL_FAILED,
+ ServiceComponentNodeEventType.NODE_SVCCOMP_OP_FAILED)
+
+ .addTransition(ServiceComponentNodeState.INSTALL_FAILED,
+ ServiceComponentNodeState.INSTALLING,
+ ServiceComponentNodeEventType.NODE_SVCCOMP_OP_RESTART)
+
+ .addTransition(ServiceComponentNodeState.INSTALLED,
+ ServiceComponentNodeState.STARTING,
+ ServiceComponentNodeEventType.NODE_SVCCOMP_START)
+ .addTransition(ServiceComponentNodeState.INSTALLED,
+ ServiceComponentNodeState.UNINSTALLING,
+ ServiceComponentNodeEventType.NODE_SVCCOMP_UNINSTALL)
+ .addTransition(ServiceComponentNodeState.INSTALLED,
+ ServiceComponentNodeState.INSTALLING,
+ ServiceComponentNodeEventType.NODE_SVCCOMP_INSTALL)
+
+ .addTransition(ServiceComponentNodeState.STARTING,
+ ServiceComponentNodeState.STARTING,
+ ServiceComponentNodeEventType.NODE_SVCCOMP_OP_IN_PROGRESS)
+ .addTransition(ServiceComponentNodeState.STARTING,
+ ServiceComponentNodeState.STARTED,
+ ServiceComponentNodeEventType.NODE_SVCCOMP_OP_SUCCEEDED)
+ .addTransition(ServiceComponentNodeState.STARTING,
+ ServiceComponentNodeState.START_FAILED,
+ ServiceComponentNodeEventType.NODE_SVCCOMP_OP_FAILED)
+
+ .addTransition(ServiceComponentNodeState.START_FAILED,
+ ServiceComponentNodeState.STARTING,
+ ServiceComponentNodeEventType.NODE_SVCCOMP_OP_RESTART)
+
+ .addTransition(ServiceComponentNodeState.STARTED,
+ ServiceComponentNodeState.STOPPING,
+ ServiceComponentNodeEventType.NODE_SVCCOMP_STOP)
+
+ .addTransition(ServiceComponentNodeState.STOPPING,
+ ServiceComponentNodeState.STOPPING,
+ ServiceComponentNodeEventType.NODE_SVCCOMP_OP_IN_PROGRESS)
+ .addTransition(ServiceComponentNodeState.STOPPING,
+ ServiceComponentNodeState.INSTALLED,
+ ServiceComponentNodeEventType.NODE_SVCCOMP_OP_SUCCEEDED)
+ .addTransition(ServiceComponentNodeState.STOPPING,
+ ServiceComponentNodeState.STOP_FAILED,
+ ServiceComponentNodeEventType.NODE_SVCCOMP_OP_FAILED)
+
+ .addTransition(ServiceComponentNodeState.STOP_FAILED,
+ ServiceComponentNodeState.STOPPING,
+ ServiceComponentNodeEventType.NODE_SVCCOMP_OP_RESTART)
+
+ .addTransition(ServiceComponentNodeState.UNINSTALLING,
+ ServiceComponentNodeState.UNINSTALLING,
+ ServiceComponentNodeEventType.NODE_SVCCOMP_OP_IN_PROGRESS)
+ .addTransition(ServiceComponentNodeState.UNINSTALLING,
+ ServiceComponentNodeState.UNINSTALLED,
+ ServiceComponentNodeEventType.NODE_SVCCOMP_OP_SUCCEEDED)
+ .addTransition(ServiceComponentNodeState.UNINSTALLING,
+ ServiceComponentNodeState.UNINSTALL_FAILED,
+ ServiceComponentNodeEventType.NODE_SVCCOMP_OP_FAILED)
+
+ .addTransition(ServiceComponentNodeState.UNINSTALL_FAILED,
+ ServiceComponentNodeState.UNINSTALLING,
+ ServiceComponentNodeEventType.NODE_SVCCOMP_OP_RESTART)
+
+ .addTransition(ServiceComponentNodeState.UNINSTALLED,
+ ServiceComponentNodeState.INSTALLING,
+ ServiceComponentNodeEventType.NODE_SVCCOMP_INSTALL)
+
+ .addTransition(ServiceComponentNodeState.UNINSTALLED,
+ ServiceComponentNodeState.INIT,
+ ServiceComponentNodeEventType.NODE_SVCCOMP_WIPEOUT)
+
+ .installTopology();
+
+ private static final StateMachineFactory
+ <ServiceComponentNodeImpl, ServiceComponentNodeState,
+ ServiceComponentNodeEventType, ServiceComponentNodeEvent>
+ clientStateMachineFactory
+ = new StateMachineFactory<ServiceComponentNodeImpl,
+ ServiceComponentNodeState, ServiceComponentNodeEventType,
+ ServiceComponentNodeEvent>
+ (ServiceComponentNodeState.INIT)
+
+ // define the state machine of a NodeServiceComponent
+
+ .addTransition(ServiceComponentNodeState.INIT,
+ ServiceComponentNodeState.INSTALLING,
+ ServiceComponentNodeEventType.NODE_SVCCOMP_INSTALL)
+
+ .addTransition(ServiceComponentNodeState.INSTALLING,
+ ServiceComponentNodeState.INSTALLED,
+ ServiceComponentNodeEventType.NODE_SVCCOMP_OP_SUCCEEDED)
+ .addTransition(ServiceComponentNodeState.INSTALLING,
+ ServiceComponentNodeState.INSTALLING,
+ ServiceComponentNodeEventType.NODE_SVCCOMP_OP_IN_PROGRESS)
+ .addTransition(ServiceComponentNodeState.INSTALLING,
+ ServiceComponentNodeState.INSTALL_FAILED,
+ ServiceComponentNodeEventType.NODE_SVCCOMP_OP_FAILED)
+
+ .addTransition(ServiceComponentNodeState.INSTALL_FAILED,
+ ServiceComponentNodeState.INSTALLING,
+ ServiceComponentNodeEventType.NODE_SVCCOMP_OP_RESTART)
+
+ .addTransition(ServiceComponentNodeState.INSTALLED,
+ ServiceComponentNodeState.UNINSTALLING,
+ ServiceComponentNodeEventType.NODE_SVCCOMP_UNINSTALL)
+ .addTransition(ServiceComponentNodeState.INSTALLED,
+ ServiceComponentNodeState.INSTALLING,
+ ServiceComponentNodeEventType.NODE_SVCCOMP_INSTALL)
+
+ .addTransition(ServiceComponentNodeState.UNINSTALLING,
+ ServiceComponentNodeState.UNINSTALLING,
+ ServiceComponentNodeEventType.NODE_SVCCOMP_OP_IN_PROGRESS)
+ .addTransition(ServiceComponentNodeState.UNINSTALLING,
+ ServiceComponentNodeState.UNINSTALLED,
+ ServiceComponentNodeEventType.NODE_SVCCOMP_OP_SUCCEEDED)
+ .addTransition(ServiceComponentNodeState.UNINSTALLING,
+ ServiceComponentNodeState.UNINSTALL_FAILED,
+ ServiceComponentNodeEventType.NODE_SVCCOMP_OP_FAILED)
+
+ .addTransition(ServiceComponentNodeState.UNINSTALL_FAILED,
+ ServiceComponentNodeState.UNINSTALLING,
+ ServiceComponentNodeEventType.NODE_SVCCOMP_OP_RESTART)
+
+ .addTransition(ServiceComponentNodeState.UNINSTALLED,
+ ServiceComponentNodeState.INSTALLING,
+ ServiceComponentNodeEventType.NODE_SVCCOMP_INSTALL)
+
+ .addTransition(ServiceComponentNodeState.UNINSTALLED,
+ ServiceComponentNodeState.INIT,
+ ServiceComponentNodeEventType.NODE_SVCCOMP_WIPEOUT)
+
+ .installTopology();
+
+
+ private final StateMachine<ServiceComponentNodeState,
+ ServiceComponentNodeEventType, ServiceComponentNodeEvent> stateMachine;
+
+ public ServiceComponentNodeImpl(boolean isClient) {
+ super();
+ if (isClient) {
+ this.stateMachine = clientStateMachineFactory.make(this);
+ } else {
+ this.stateMachine = daemonStateMachineFactory.make(this);
+ }
+ }
+
+ @Override
+ public ServiceComponentNodeState getState() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public void setState(ServiceComponentNodeState state) {
+ // TODO Auto-generated method stub
+ }
+
+ @Override
+ public void handleEvent(ServiceComponentNodeEvent event)
+ throws InvalidStateTransitonException {
+ // TODO
+ stateMachine.doTransition(event.getType(), event);
+ }
+
+ @Override
+ public ConfigVersion getConfigVersion() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public List<Job> getJobs() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public String getServiceComponentName() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public String getNodeName() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
Propchange: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/ServiceComponentNodeImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/ServiceComponentNodeState.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/ServiceComponentNodeState.java?rev=1380914&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/ServiceComponentNodeState.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/ServiceComponentNodeState.java Tue Sep 4 22:02:37 2012
@@ -0,0 +1,52 @@
+package org.apache.ambari.server.state.live;
+
+public enum ServiceComponentNodeState {
+ /**
+ * Initial/Clean state
+ */
+ INIT,
+ /**
+ * In the process of installing.
+ */
+ INSTALLING,
+ /**
+ * Install failed
+ */
+ INSTALL_FAILED,
+ /**
+ * State when install completed successfully
+ */
+ INSTALLED,
+ /**
+ * In the process of starting.
+ */
+ STARTING,
+ /**
+ * Start failed.
+ */
+ START_FAILED,
+ /**
+ * State when start completed successfully.
+ */
+ STARTED,
+ /**
+ * In the process of stopping.
+ */
+ STOPPING,
+ /**
+ * Stop failed
+ */
+ STOP_FAILED,
+ /**
+ * In the process of uninstalling.
+ */
+ UNINSTALLING,
+ /**
+ * Uninstall failed.
+ */
+ UNINSTALL_FAILED,
+ /**
+ * State when uninstall completed successfully.
+ */
+ UNINSTALLED
+}
Propchange: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/ServiceComponentNodeState.java
------------------------------------------------------------------------------
svn:eol-style = native