Skip to content

Commit

Permalink
pongasoft#63: cleanup to use new code
Browse files Browse the repository at this point in the history
  • Loading branch information
ypujante committed Jun 12, 2011
1 parent 921baa2 commit 093b1a9
Show file tree
Hide file tree
Showing 78 changed files with 862 additions and 8,337 deletions.
1 change: 0 additions & 1 deletion console/org.linkedin.glu.console-webapp/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ dependencies {
compile project(':agent:org.linkedin.glu.agent-api')
compile project(':agent:org.linkedin.glu.agent-rest-client')
compile project(':agent:org.linkedin.glu.agent-tracker')
compile project(':provisioner:org.linkedin.glu.provisioner-agent')
compile project(':orchestration:org.linkedin.glu.orchestration-engine')
compile spec.external.linkedinUtilsGroovy
compile spec.external.linkedinZookeeperImpl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@
<property name="agentURIProvider" ref="_agentsServiceImpl"/>
</bean>

<bean id="agentPlanner" class="org.linkedin.glu.provisioner.impl.planner.AgentPlanner"/>

<bean id="configurableFactory" class="org.linkedin.glu.agent.rest.client.ConfigurableFactoryImpl"/>

<bean id="consoleConfig" class="org.linkedin.glu.grails.utils.ConsoleConfig"/>
Expand Down Expand Up @@ -143,7 +141,6 @@
<bean id="_agentsServiceImpl"
class="org.linkedin.glu.orchestration.engine.agents.AgentsServiceImpl">
<property name="agentFactory" ref="agentFactory"/>
<property name="agentPlanner" ref="agentPlanner"/>
<property name="trackerService" ref="trackerService"/>
<property name="authorizationService" ref="authorizationService"/>
</bean>
Expand All @@ -169,17 +166,24 @@
<property name="auditLogService" ref="auditLogService"/>
</bean>

<!-- *********************** -->
<!-- plannerService -->
<!-- *********************** -->
<bean id="plannerService"
class="org.linkedin.glu.orchestration.engine.planner.PlannerServiceImpl">
<property name="agentsService" ref="agentsService"/>
<property name="deltaMgr" ref="deltaMgr"/>
<property name="planner" ref="planner"/>
<property name="fabricService" ref="fabricService"/>
</bean>

<!-- *********************** -->
<!-- deploymentService -->
<!-- *********************** -->
<bean id="_deploymentServiceImpl"
class="org.linkedin.glu.orchestration.engine.deployment.DeploymentServiceImpl">
<property name="agentsService" ref="agentsService"/>
<property name="authorizationService" ref="authorizationService"/>
<property name="deployer" ref="deployer"/>
<property name="deltaMgr" ref="deltaMgr"/>
<property name="planner" ref="planner"/>
<property name="fabricService" ref="fabricService"/>
<property name="deploymentStorage">
<bean class="org.linkedin.glu.console.provisioner.services.storage.DeploymentStorageImpl"/>
</property>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,22 @@
package org.linkedin.glu.console.controllers

import org.linkedin.glu.orchestration.engine.agents.AgentsService
import org.linkedin.glu.orchestration.engine.deployment.DeploymentService
import org.linkedin.glu.provisioner.plan.api.IStep
import org.linkedin.glu.agent.tracker.MountPointInfo
import org.linkedin.glu.orchestration.engine.fabric.Fabric
import java.security.AccessControlException
import org.linkedin.glu.orchestration.engine.agents.NoSuchAgentException
import org.linkedin.glu.provisioner.plan.api.IStep.Type
import org.linkedin.glu.provisioner.core.model.SystemModel
import org.linkedin.glu.orchestration.engine.planner.PlannerService

/**
* @author ypujante@linkedin.com
*/
class AgentsController extends ControllerBase
{
AgentsService agentsService
DeploymentService deploymentService
PlannerService plannerService

def beforeInterceptor = {
// we make sure that the fabric is always set before executing any action
Expand Down Expand Up @@ -70,15 +70,14 @@ class AgentsController extends ControllerBase
params.fabric = request.fabric
params.type = Type.PARALLEL

def plans =
deploymentService.computeAgentsUpgradePlan(params,
[name: "Agent upgrade to version ${params.version}".toString()])
def plan =
plannerService.computeAgentsUpgradePlan(params,
[name: "Agent upgrade to version ${params.version}".toString()])

if(plans)
if(plan)
{
session.delta = plans
println plans[0].toXml()
redirect(controller: 'plan', action: 'view', id: plans[0].id)
session.delta = [plan]
redirect(controller: 'plan', action: 'view', id: plan.id)
}
else
{
Expand All @@ -95,13 +94,12 @@ class AgentsController extends ControllerBase
params.system = request.system
params.type = Type.PARALLEL

def plans = deploymentService.computeAgentsCleanupUpgradePlan(params, null)
def plan = plannerService.computeAgentsCleanupUpgradePlan(params, null)

if(plans)
if(plan)
{
session.delta = plans
println plans[0].toXml()
redirect(controller: 'plan', action: 'view', id: plans[0].id)
session.delta = [plan]
redirect(controller: 'plan', action: 'view', id: plan.id)
}
else
{
Expand Down Expand Up @@ -138,9 +136,9 @@ class AgentsController extends ControllerBase
params.name = "${type.capitalize()}: ${title}".toString()

def plans =
deploymentService."compute${type.capitalize()}Plans"(params,
[type: type,
agent: params.id])
plannerService."compute${type.capitalize()}Plans"(params,
[type: type,
agent: params.id])
if(plans)
session.delta.addAll(plans)

Expand Down Expand Up @@ -257,7 +255,7 @@ class AgentsController extends ControllerBase
params.state = 'running'
params.name = params.name ?: 'Start'
redirectToActionPlan('start') { p, metadata ->
deploymentService.computeTransitionPlans(p, metadata)
plannerService.computeTransitionPlans(p, metadata)
}
}

Expand All @@ -267,7 +265,7 @@ class AgentsController extends ControllerBase
params.state = 'stopped'
params.name = params.name ?: 'Stop'
redirectToActionPlan('stop') { p, metadata ->
deploymentService.computeTransitionPlans(p, metadata)
plannerService.computeTransitionPlans(p, metadata)
}
}

Expand All @@ -276,7 +274,7 @@ class AgentsController extends ControllerBase
def bounce = {
params.name = params.name ?: 'Bounce'
redirectToActionPlan('bounce') { p, metadata ->
deploymentService.computeBouncePlans(p, metadata)
plannerService.computeBouncePlans(p, metadata)
}
}

Expand All @@ -285,7 +283,7 @@ class AgentsController extends ControllerBase
def undeploy = {
params.name = params.name ?: 'Undeploy'
redirectToActionPlan('undeploy') { p, metadata ->
deploymentService.computeUndeployPlans(p, metadata)
plannerService.computeUndeployPlans(p, metadata)
}
}

Expand All @@ -294,7 +292,7 @@ class AgentsController extends ControllerBase
def redeploy = {
params.name = params.name ?: 'Redeploy'
redirectToActionPlan('redeploy') { p, metadata ->
deploymentService.computeRedeployPlans(p, metadata)
plannerService.computeRedeployPlans(p, metadata)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package org.linkedin.glu.console.controllers

import org.linkedin.glu.grails.utils.ConsoleConfig
import org.linkedin.glu.orchestration.engine.delta.DeltaService
import org.linkedin.groovy.util.json.JsonUtils

/**
* @author ypujante@linkedin.com
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,21 @@ import org.linkedin.glu.provisioner.plan.api.Plan
import org.linkedin.glu.provisioner.plan.api.IStepExecution
import org.linkedin.glu.provisioner.plan.api.IPlanExecution
import org.linkedin.glu.console.domain.DbDeployment
import org.linkedin.glu.provisioner.core.action.ActionDescriptor
import org.linkedin.glu.provisioner.plan.api.LeafStep
import org.linkedin.glu.orchestration.engine.agents.AgentsService
import javax.servlet.http.HttpServletResponse
import org.linkedin.util.clock.Clock
import org.linkedin.util.clock.SystemClock
import org.linkedin.glu.orchestration.engine.deployment.CurrentDeployment
import org.linkedin.glu.orchestration.engine.planner.PlannerService
import org.linkedin.glu.orchestration.engine.action.descriptor.NoOpActionDescriptor

/**
* @author ypujante@linkedin.com */
public class PlanController extends ControllerBase
{
Clock clock = SystemClock.instance()
DeploymentService deploymentService
PlannerService plannerService
AgentsService agentsService

def beforeInterceptor = {
Expand Down Expand Up @@ -290,31 +291,43 @@ public class PlanController extends ControllerBase
args.fabric = request.fabric
args.name = params.systemFilter ?: 'all'

try
{
args.type = IStep.Type.valueOf((params.order ?: 'sequential').toUpperCase())
}
catch (IllegalArgumentException e)
{
render e.message
response.sendError(HttpServletResponse.SC_BAD_REQUEST)
return
}

Plan plan

def metadata = [origin: 'rest', action: params.planAction, filter: args.name]

switch(params.planAction)
{
case 'start':
case 'deploy':
plan = deploymentService.computeDeploymentPlan(args)
plan = plannerService.computeDeployPlan(args, metadata)
break;

case 'stop':
args.state = ['stopped']
plan = deploymentService.computeTransitionPlan(args) { true }
plan = plannerService.computeTransitionPlan(args, metadata)
break;

case 'undeploy':
plan = deploymentService.computeUndeployPlans(args) { true }
plan = plannerService.computeUndeployPlan(args, metadata)
break;

case 'bounce':
plan = deploymentService.computeBouncePlans(args) { true }
plan = plannerService.computeBouncePlan(args, metadata)
break;

case 'redeploy':
plan = deploymentService.computeRedeployPlans(args) { true }
plan = plannerService.computeRedeployPlan(args, metadata)
break;

default:
Expand All @@ -323,28 +336,9 @@ public class PlanController extends ControllerBase
return
}

def type

try
{
type = IStep.Type.valueOf((params.order ?: 'sequential').toUpperCase())
}
catch (IllegalArgumentException e)
{
render e.message
response.sendError(HttpServletResponse.SC_BAD_REQUEST)
return
}

plan?.name = null // force the generation of a new name
plan =
deploymentService.groupByInstance(plan,
type,
[origin: 'rest', action: params.planAction, filter: args.name])

if(plan?.hasLeafSteps())
{
if(plan.leafSteps.findAll { it.action?.actionName == 'noop' }.size() == plan.leafStepsCount)
if(plan.leafSteps.findAll { it.action instanceof NoOpActionDescriptor }.size() == plan.leafStepsCount)
{
response.setStatus(HttpServletResponse.SC_NO_CONTENT,
'no plan created (only pending transitions)')
Expand Down Expand Up @@ -452,100 +446,6 @@ public class PlanController extends ControllerBase
response.sendError HttpServletResponse.SC_NOT_FOUND
}
}

private Plan createStartAllPlan()
{
def args = [:]
args.system = request.system
args.fabric = request.fabric
return deploymentService.computeDeploymentPlan(args)
}

private Plan createStartAllPlan(IStep.Type type)
{
Plan plan = createStartAllPlan()
deploymentService.groupByInstance(plan, type, [instance: '*'])
}

private Plan createStopAllPlan()
{
def args = [:]
args.system = request.system
args.fabric = request.fabric
return deploymentService.computeUndeployPlans(args) { true }
}

private Plan createStopAllPlan(IStep.Type type)
{
Plan plan = createStopAllPlan()
deploymentService.groupByInstance(plan, type, [instance: '-*'])
}

private Plan createPlan(Plan startAllPlan, Plan stopAllPlan, String line)
{
IStep.Type planType = IStep.Type.SEQUENTIAL

if(line.startsWith('//'))
{
planType = IStep.Type.PARALLEL
line = line[2..-1]
}

def planBuilder = startAllPlan.createEmptyPlanBuilder()
planBuilder.name = line
def stepsBuilder = planBuilder.addSequentialSteps()
stepsBuilder.name = planBuilder.name

def entries = line.split(',')
entries.each { entry ->
def kv = entry.split('=')
def type = kv[0].trim()
def value = kv[1].trim()

def plan
if(value.startsWith('-'))
{
value = value[1..-1]
plan = stopAllPlan
}
else
{
if(value.startsWith('+'))
value = value[1..-1]
plan = startAllPlan
}

def steps = plan.leafSteps.findAll { LeafStep<ActionDescriptor> step ->
def adp = step.action.descriptorProperties

switch(type)
{
case 'host':
return adp.hostname == value

case 'appname':
return step.action.actionParams?.metadata?.container?.name == value

case 'instance':
def instance = "${adp.hostname}:${adp.mountPoint}".toString()
return instance == value

case 'cluster':
return step.action.actionParams?.metadata?.cluster == value

default:
return false
}
}

steps.each { LeafStep<ActionDescriptor> step ->
stepsBuilder.addLeafStep(step)
}
}

def plan = planBuilder.toPlan()
deploymentService.groupByInstance(plan, planType, [:])
}
}

/**
Expand Down
Loading

0 comments on commit 093b1a9

Please sign in to comment.