Skip to content

Commit

Permalink
#228: added reconfigure plan
Browse files Browse the repository at this point in the history
- now rest api supports automatically all planAction defined
  • Loading branch information
ypujante committed Aug 14, 2013
1 parent 3299861 commit 6bed3f0
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 40 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (c) 2010-2010 LinkedIn, Inc
* Portions Copyright (c) 2011-2012 Yan Pujante
* Portions Copyright (c) 2011-2013 Yan Pujante
*
* Licensed 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
Expand All @@ -17,6 +17,7 @@

package org.linkedin.glu.console.controllers

import org.linkedin.glu.grails.utils.ConsoleConfig
import org.linkedin.glu.groovy.utils.collections.GluGroovyCollectionUtils
import org.linkedin.glu.provisioner.plan.api.IStepFilter
import org.linkedin.glu.orchestration.engine.deployment.DeploymentService
Expand Down Expand Up @@ -47,18 +48,28 @@ public class PlanController extends ControllerBase
* Default plans
*/
def static DEFAULT_PLANS = [
[planType: "deploy"],
[planType: "bounce"],
[planType: "redeploy"],
[planType: "undeploy"],
[planAction: "deploy", planType: "deploy"],
[planAction: "bounce", planType: "bounce"],
[planAction: "bounce", planType: "redeploy"],
[planAction: "undeploy", planType: "undeploy"],
[
planAction: "reconfigure",
planType: "transition",
displayName: "Reconfigure",
states: ["installed", "running"],
expectedEntryStates: ["running", "stopped", "installed"],
currentEntryStates: ["running", "stopped"]
],
[
planAction: "start",
planType: "transition",
displayName: "Start",
state: "running",
expectedEntryStates: ["running"],
currentEntryStates: ["stopped"]
],
[
planAction: "stop",
planType: "transition",
displayName: "Stop",
state: "stopped",
Expand All @@ -68,6 +79,7 @@ public class PlanController extends ControllerBase
]

Clock clock = SystemClock.instance()
ConsoleConfig consoleConfig
DeploymentService deploymentService
PlannerService plannerService
AgentsService agentsService
Expand Down Expand Up @@ -390,39 +402,14 @@ public class PlanController extends ControllerBase

if(params.planAction)
{
switch(params.planAction)
args = processPlanAction(params, args)

if(!args)
{
case 'start':
args.state = 'running'
args.planType = 'transition'
break;

case 'deploy':
args.planType = 'deploy'
break;

case 'stop':
args.state = 'stopped'
args.planType = 'transition'
break;

case 'undeploy':
args.planType = 'undeploy'
break;

case 'bounce':
args.planType = 'bounce'
break;

case 'redeploy':
args.planType = 'redeploy'
break;

default:
response.sendError(HttpServletResponse.SC_BAD_REQUEST,
"invalid action: ${params.planAction}")
render ''
return
response.sendError(HttpServletResponse.SC_BAD_REQUEST,
"invalid action: ${params.planAction}")
render ''
return
}
}
else
Expand Down Expand Up @@ -471,6 +458,36 @@ public class PlanController extends ControllerBase
}
}

private def processPlanAction(def params, def args)
{
def res = processPlanAction(params, args, consoleConfig.defaults.plans)
if(!res)
res = processPlanAction(params, args, DEFAULT_PLANS)
return res
}

private def processPlanAction(def params, def args, def plansDefinition)
{
if(plansDefinition)
{
def planDefinition =
plansDefinition.find { planDefinition -> planDefinition.planAction == params.planAction }

if(planDefinition)
{
args.planType = planDefinition.planType

['state', 'states', 'expectedEntryStates', 'currentEntryStates'].each { p ->
args[p] = params[p] ?: planDefinition[p]
}

return args
}
}

return null
}

/**
* View a plan
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2011 Yan Pujante
* Copyright (c) 2011-2013 Yan Pujante
*
* Licensed 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
Expand Down Expand Up @@ -226,7 +226,7 @@ class PlannerServiceImpl implements PlannerService
currentEntrySystemFilter)
}

doComputeDeploymentPlans(params, metadata, [params.state], filter)
doComputeDeploymentPlans(params, metadata, params.states ?: [params.state], filter)
}

/**
Expand Down
2 changes: 1 addition & 1 deletion project-spec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
spec = [
name: 'glu',
group: 'org.pongasoft',
version: '5.1.0',
version: '5.2.0',

versions: [
jdk: '1.7',
Expand Down

0 comments on commit 6bed3f0

Please sign in to comment.