Skip to content

Instantly share code, notes, and snippets.

@akki
Last active June 2, 2020 08:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akki/1d80c97463198275b3abe39350688bda to your computer and use it in GitHub Desktop.
Save akki/1d80c97463198275b3abe39350688bda to your computer and use it in GitHub Desktop.
Helix OnlineOffline state model
package my.package;
import org.apache.helix.HelixDefinedState;
import org.apache.helix.model.StateModelDefinition;
public final class OnlineOfflineStateModel {
public static final String name = "OnlineOffline";
public enum States {
ONLINE,
OFFLINE
}
/**
* Build OnlineOffline state model definition
*/
public static StateModelDefinition build() {
StateModelDefinition.Builder builder = new StateModelDefinition.Builder(name);
// add states
builder.addState(States.ONLINE.name(), 1);
builder.addState(States.OFFLINE.name(), 2);
for (HelixDefinedState state : HelixDefinedState.values()) {
builder.addState(state.name());
}
// Set the initial state when the node starts
builder.initialState(States.OFFLINE.name());
// Add transitions between the states.
builder.addTransition(States.ONLINE.name(), States.OFFLINE.name());
builder.addTransition(States.OFFLINE.name(), States.ONLINE.name());
builder.addTransition(States.OFFLINE.name(), HelixDefinedState.DROPPED.name());
// bounds
builder.upperBound(States.ONLINE.name(), 1);
builder.dynamicUpperBound(States.ONLINE.name(), "R");
return builder.build();
}
}
############################################
# INITIAL STATE #
############################################
get /helixClustername/IDEALSTATES/ResourceName
{
"id" : "ResourceName",
"simpleFields" : {
"IDEAL_STATE_MODE" : "CUSTOMIZED",
"MAX_PARTITIONS_PER_INSTANCE" : "6",
"NUM_PARTITIONS" : "6",
"REBALANCE_MODE" : "CUSTOMIZED",
"REPLICAS" : "1",
"STATE_MODEL_DEF_REF" : "OnlineOffline",
"STATE_MODEL_FACTORY_NAME" : "DEFAULT"
},
"mapFields" : {
"0" : {
"hadin-worker-1001" : "ONLINE"
},
"1" : {
"hadin-worker-1001" : "ONLINE"
},
"2" : {
"hadin-worker-1001" : "ONLINE"
},
"3" : {
"hadin-worker-1001" : "ONLINE"
},
"4" : {
"hadin-worker-1001" : "ONLINE"
},
"5" : {
"hadin-worker-1001" : "ONLINE"
}
},
"listFields" : { }
}
############################################
# AFTER ADDING A NODE #
############################################
get /helixClustername/EXTERNALVIEW/ResourceName
{
"id" : "ResourceName",
"simpleFields" : {
"BUCKET_SIZE" : "0",
"IDEAL_STATE_MODE" : "CUSTOMIZED",
"MAX_PARTITIONS_PER_INSTANCE" : "6",
"NUM_PARTITIONS" : "6",
"REBALANCE_MODE" : "CUSTOMIZED",
"REPLICAS" : "1",
"STATE_MODEL_DEF_REF" : "OnlineOffline",
"STATE_MODEL_FACTORY_NAME" : "DEFAULT"
},
"mapFields" : {
"0" : {
"hadin-worker-1002" : "ONLINE",
"hadin-worker-1001" : "ONLINE"
},
"1" : {
"hadin-worker-1001" : "ONLINE"
},
"2" : {
"hadin-worker-1001" : "ONLINE"
},
"3" : {
"hadin-worker-1002" : "ONLINE",
"hadin-worker-1001" : "ONLINE"
},
"4" : {
"hadin-worker-1001" : "ONLINE"
},
"5" : {
"hadin-worker-1002" : "ONLINE",
"hadin-worker-1001" : "ONLINE"
}
},
"listFields" : { }
}
get /helixClustername/IDEALSTATES/ResourceName
{
"id" : "ResourceName",
"simpleFields" : {
"IDEAL_STATE_MODE" : "CUSTOMIZED",
"MAX_PARTITIONS_PER_INSTANCE" : "6",
"NUM_PARTITIONS" : "6",
"REBALANCE_MODE" : "CUSTOMIZED",
"REPLICAS" : "1",
"STATE_MODEL_DEF_REF" : "OnlineOffline",
"STATE_MODEL_FACTORY_NAME" : "DEFAULT"
},
"mapFields" : {
"0" : {
"hadin-worker-1002" : "ONLINE"
},
"1" : {
"hadin-worker-1001" : "ONLINE"
},
"2" : {
"hadin-worker-1001" : "ONLINE"
},
"3" : {
"hadin-worker-1002" : "ONLINE"
},
"4" : {
"hadin-worker-1001" : "ONLINE"
},
"5" : {
"hadin-worker-1002" : "ONLINE"
}
},
"listFields" : { }
}
get /helixClustername/EXTERNALVIEW/ResourceName
{
"id" : "ResourceName",
"simpleFields" : {
"BUCKET_SIZE" : "0",
"IDEAL_STATE_MODE" : "AUTO",
"MAX_PARTITIONS_PER_INSTANCE" : "6",
"NUM_PARTITIONS" : "6",
"REBALANCE_MODE" : "SEMI_AUTO",
"REPLICAS" : "1",
"STATE_MODEL_DEF_REF" : "OnlineOffline",
"STATE_MODEL_FACTORY_NAME" : "DEFAULT"
},
"mapFields" : {
"0" : {
"hadin-worker-1002" : "ONLINE",
"hadin-worker-1001" : "ONLINE"
},
"1" : {
"hadin-worker-1001" : "ONLINE"
},
"2" : {
"hadin-worker-1001" : "ONLINE"
},
"3" : {
"hadin-worker-1002" : "ONLINE",
"hadin-worker-1001" : "ONLINE"
},
"4" : {
"hadin-worker-1002" : "ONLINE",
"hadin-worker-1001" : "ONLINE"
},
"5" : {
"hadin-worker-1001" : "ONLINE"
}
},
"listFields" : { }
}
get /helixClustername/IDEALSTATES/ResourceName
{
"id" : "ResourceName",
"simpleFields" : {
"IDEAL_STATE_MODE" : "AUTO",
"MAX_PARTITIONS_PER_INSTANCE" : "6",
"NUM_PARTITIONS" : "6",
"REBALANCE_MODE" : "SEMI_AUTO",
"REPLICAS" : "1",
"STATE_MODEL_DEF_REF" : "OnlineOffline",
"STATE_MODEL_FACTORY_NAME" : "DEFAULT"
},
"mapFields" : { },
"listFields" : {
"0" : [ "hadin-worker-1002" ],
"1" : [ "hadin-worker-1001" ],
"2" : [ "hadin-worker-1001" ],
"3" : [ "hadin-worker-1002" ],
"4" : [ "hadin-worker-1002" ],
"5" : [ "hadin-worker-1001" ]
}
}
get /helixClustername/EXTERNALVIEW/ResourceName
{
"id" : "ResourceName",
"simpleFields" : {
"BUCKET_SIZE" : "0",
"IDEAL_STATE_MODE" : "CUSTOMIZED",
"MAX_PARTITIONS_PER_INSTANCE" : "6",
"NUM_PARTITIONS" : "6",
"REBALANCE_MODE" : "CUSTOMIZED",
"REPLICAS" : "1",
"STATE_MODEL_DEF_REF" : "OnlineOffline",
"STATE_MODEL_FACTORY_NAME" : "DEFAULT"
},
"mapFields" : {
"0" : {
"hadin-worker-1002" : "ONLINE",
"hadin-worker-1001" : "ONLINE"
},
"1" : {
"hadin-worker-1001" : "ONLINE"
},
"2" : {
"hadin-worker-1001" : "ONLINE"
},
"3" : {
"hadin-worker-1002" : "ONLINE",
"hadin-worker-1001" : "ONLINE"
},
"4" : {
"hadin-worker-1001" : "ONLINE"
},
"5" : {
"hadin-worker-1002" : "ONLINE",
"hadin-worker-1001" : "ONLINE"
}
},
"listFields" : { }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment