Commit bbe9758d authored by Iustin Pop's avatar Iustin Pop
Browse files

htools: add target_node member to migrate opcode



… and failover too. Not many changes otherwise except for
serialisation and unittests.
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarGuido Trotter <ultrotter@google.com>
parent 10f055ac
......@@ -1329,7 +1329,7 @@ iMoveToJob nl il idx move =
let inst = Container.find idx il
iname = Instance.name inst
lookNode = Just . Container.nameOf nl
opF = OpCodes.OpInstanceMigrate iname True False True
opF = OpCodes.OpInstanceMigrate iname True False True Nothing
opR n = OpCodes.OpInstanceReplaceDisks iname (lookNode n)
OpCodes.ReplaceNewSecondary [] Nothing
in case move of
......
......@@ -255,9 +255,11 @@ instance Arbitrary OpCodes.OpCode where
liftM5 OpCodes.OpInstanceReplaceDisks arbitrary arbitrary
arbitrary arbitrary arbitrary
"OP_INSTANCE_FAILOVER" ->
liftM2 OpCodes.OpInstanceFailover arbitrary arbitrary
liftM3 OpCodes.OpInstanceFailover arbitrary arbitrary
arbitrary
"OP_INSTANCE_MIGRATE" ->
liftM4 OpCodes.OpInstanceMigrate arbitrary arbitrary arbitrary
liftM5 OpCodes.OpInstanceMigrate arbitrary arbitrary
arbitrary arbitrary
arbitrary
_ -> fail "Wrong opcode")
......
......@@ -63,8 +63,8 @@ instance JSON ReplaceDisksMode where
data OpCode = OpTestDelay Double Bool [String]
| OpInstanceReplaceDisks String (Maybe String) ReplaceDisksMode
[Int] (Maybe String)
| OpInstanceFailover String Bool
| OpInstanceMigrate String Bool Bool Bool
| OpInstanceFailover String Bool (Maybe String)
| OpInstanceMigrate String Bool Bool Bool (Maybe String)
deriving (Show, Read, Eq)
......@@ -72,8 +72,8 @@ data OpCode = OpTestDelay Double Bool [String]
opID :: OpCode -> String
opID (OpTestDelay _ _ _) = "OP_TEST_DELAY"
opID (OpInstanceReplaceDisks _ _ _ _ _) = "OP_INSTANCE_REPLACE_DISKS"
opID (OpInstanceFailover _ _) = "OP_INSTANCE_FAILOVER"
opID (OpInstanceMigrate _ _ _ _) = "OP_INSTANCE_MIGRATE"
opID (OpInstanceFailover {}) = "OP_INSTANCE_FAILOVER"
opID (OpInstanceMigrate {}) = "OP_INSTANCE_MIGRATE"
-- | Loads an OpCode from the JSON serialised form.
loadOpCode :: JSValue -> J.Result OpCode
......@@ -97,13 +97,16 @@ loadOpCode v = do
"OP_INSTANCE_FAILOVER" -> do
inst <- extract "instance_name"
consist <- extract "ignore_consistency"
return $ OpInstanceFailover inst consist
tnode <- maybeFromObj o "target_node"
return $ OpInstanceFailover inst consist tnode
"OP_INSTANCE_MIGRATE" -> do
inst <- extract "instance_name"
live <- extract "live"
cleanup <- extract "cleanup"
allow_failover <- fromObjWithDefault o "allow_failover" False
return $ OpInstanceMigrate inst live cleanup allow_failover
tnode <- maybeFromObj o "target_node"
return $ OpInstanceMigrate inst live cleanup
allow_failover tnode
_ -> J.Error $ "Unknown opcode " ++ op_id
-- | Serialises an opcode to JSON.
......@@ -128,19 +131,25 @@ saveOpCode op@(OpInstanceReplaceDisks inst node mode disks iallocator) =
Nothing -> ol2
in makeObj ol3
saveOpCode op@(OpInstanceFailover inst consist) =
saveOpCode op@(OpInstanceFailover inst consist tnode) =
let ol = [ ("OP_ID", showJSON $ opID op)
, ("instance_name", showJSON inst)
, ("ignore_consistency", showJSON consist) ]
in makeObj ol
ol' = case tnode of
Nothing -> ol
Just node -> ("target_node", showJSON node):ol
in makeObj ol'
saveOpCode op@(OpInstanceMigrate inst live cleanup allow_failover) =
saveOpCode op@(OpInstanceMigrate inst live cleanup allow_failover tnode) =
let ol = [ ("OP_ID", showJSON $ opID op)
, ("instance_name", showJSON inst)
, ("live", showJSON live)
, ("cleanup", showJSON cleanup)
, ("allow_failover", showJSON allow_failover) ]
in makeObj ol
ol' = case tnode of
Nothing -> ol
Just node -> ("target_node", showJSON node):ol
in makeObj ol'
instance JSON OpCode where
readJSON = loadOpCode
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment