diff --git a/agent/org.linkedin.glu.agent-api/src/main/groovy/org/linkedin/glu/agent/api/Agent.groovy b/agent/org.linkedin.glu.agent-api/src/main/groovy/org/linkedin/glu/agent/api/Agent.groovy index bedd2efd..6a099777 100644 --- a/agent/org.linkedin.glu.agent-api/src/main/groovy/org/linkedin/glu/agent/api/Agent.groovy +++ b/agent/org.linkedin.glu.agent-api/src/main/groovy/org/linkedin/glu/agent/api/Agent.groovy @@ -33,6 +33,14 @@ public interface Agent running: [[to: 'stopped', action: 'stop']] ] + def static SELF_UPGRADE_TRANSITIONS = + [ + NONE: [[to: 'installed', action: 'install']], + installed: [[to: 'NONE', action: 'uninstall'], [to: 'prepared', action: 'prepare']], + prepared: [[to: 'upgraded', action: 'commit'], [to: 'installed', action: 'rollback']], + upgraded: [[to: 'NONE', action: 'uninstall']] + ] + /******************************************************************** * Software management ********************************************************************/ diff --git a/agent/org.linkedin.glu.agent-impl/src/main/groovy/org/linkedin/glu/agent/impl/script/AutoUpgradeScript.groovy b/agent/org.linkedin.glu.agent-impl/src/main/groovy/org/linkedin/glu/agent/impl/script/AutoUpgradeScript.groovy index 62ba1a38..4fe23d00 100644 --- a/agent/org.linkedin.glu.agent-impl/src/main/groovy/org/linkedin/glu/agent/impl/script/AutoUpgradeScript.groovy +++ b/agent/org.linkedin.glu.agent-impl/src/main/groovy/org/linkedin/glu/agent/impl/script/AutoUpgradeScript.groovy @@ -18,6 +18,7 @@ package org.linkedin.glu.agent.impl.script import org.linkedin.groovy.util.io.fs.FileSystemImpl +import org.linkedin.glu.agent.api.Agent /** * This is the script that will auto upgrade the agent. @@ -36,13 +37,7 @@ import org.linkedin.groovy.util.io.fs.FileSystemImpl */ class AutoUpgradeScript { - def static stateMachine = - [ - NONE: [[to: 'installed', action: 'install']], - installed: [[to: 'NONE', action: 'uninstall'], [to: 'prepared', action: 'prepare']], - prepared: [[to: 'upgraded', action: 'commit'], [to: 'installed', action: 'rollback']], - upgraded: [[to: 'NONE', action: 'uninstall']] - ] + def static stateMachine = Agent.SELF_UPGRADE_TRANSITIONS def currentVersion File agentRootDir diff --git a/agent/org.linkedin.glu.agent-rest-client/src/main/groovy/org/linkedin/glu/agent/rest/client/AgentRestClient.groovy b/agent/org.linkedin.glu.agent-rest-client/src/main/groovy/org/linkedin/glu/agent/rest/client/AgentRestClient.groovy index b1c8566a..7c38c720 100644 --- a/agent/org.linkedin.glu.agent-rest-client/src/main/groovy/org/linkedin/glu/agent/rest/client/AgentRestClient.groovy +++ b/agent/org.linkedin.glu.agent-rest-client/src/main/groovy/org/linkedin/glu/agent/rest/client/AgentRestClient.groovy @@ -443,7 +443,7 @@ class AgentRestClient implements Agent def representation = extractRepresentation(clientResource, clientResource.responseEntity) if(representation instanceof Status) { - throw new AgentException(representation.toString()) + handleRecoverableError(representation) } else { @@ -451,6 +451,14 @@ class AgentRestClient implements Agent } } + protected void handleRecoverableError(Status status) + { + if(status.isRecoverableError()) + throw new RecoverableAgentException(status) + else + throw new AgentException(status.toString()) + } + /** * This method will try to rebuild the full stack trace based on the rest exception recursively. * Handles the case when the client does not know about an exception diff --git a/agent/org.linkedin.glu.agent-rest-client/src/main/groovy/org/linkedin/glu/agent/rest/client/RecoverableAgentException.groovy b/agent/org.linkedin.glu.agent-rest-client/src/main/groovy/org/linkedin/glu/agent/rest/client/RecoverableAgentException.groovy new file mode 100644 index 00000000..2641eb77 --- /dev/null +++ b/agent/org.linkedin.glu.agent-rest-client/src/main/groovy/org/linkedin/glu/agent/rest/client/RecoverableAgentException.groovy @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2011 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 + * 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.linkedin.glu.agent.rest.client + +import org.linkedin.glu.agent.api.AgentException +import org.restlet.data.Status + +/** + * @author yan@pongasoft.com */ +public class RecoverableAgentException extends AgentException +{ + private static final long serialVersionUID = 1L; + + Status status + + RecoverableAgentException(Status status) + { + super(status.toString()) + if(!status.isRecoverableError()) + throw new IllegalArgumentException("${status} is not a recoverable error!") + this.status = status + } +} \ No newline at end of file diff --git a/console/org.linkedin.glu.console-webapp/grails-app/controllers/org/linkedin/glu/console/controllers/AgentsController.groovy b/console/org.linkedin.glu.console-webapp/grails-app/controllers/org/linkedin/glu/console/controllers/AgentsController.groovy index 2fb4fa91..faaa9f7d 100644 --- a/console/org.linkedin.glu.console-webapp/grails-app/controllers/org/linkedin/glu/console/controllers/AgentsController.groovy +++ b/console/org.linkedin.glu.console-webapp/grails-app/controllers/org/linkedin/glu/console/controllers/AgentsController.groovy @@ -24,6 +24,7 @@ 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 /** * @author ypujante@linkedin.com @@ -44,9 +45,7 @@ class AgentsController extends ControllerBase def listVersions = { def agents = agentsService.getAgentInfos(request.fabric) - def versions = agents.values().groupBy { agent -> - agent.agentProperties['org.linkedin.glu.agent.version'] - } + def versions = agents.values().groupBy { it.version } return [versions: versions] } @@ -68,37 +67,46 @@ class AgentsController extends ControllerBase } params.fabric = request.fabric + params.type = Type.PARALLEL - def plan = agentsService.createAgentsUpgradePlan(params) - - session.delta = [plan] + def plans = + deploymentService.computeAgentsUpgradePlan(params, + [name: "Agent upgrade to version ${params.version}".toString()]) - redirect(controller: 'plan', action: 'view', id: plan.id) + if(plans) + { + session.delta = plans + println plans[0].toXml() + redirect(controller: 'plan', action: 'view', id: plans[0].id) + } + else + { + flash.message = "No agent to upgrade" + redirect(action: 'listVersions') + } } /** * cleanup */ def cleanup = { - if(!params.version) + params.name = "Agent upgrade cleanup" + params.system = request.system + params.type = Type.PARALLEL + + def plans = deploymentService.computeAgentsCleanupUpgradePlan(params, null) + + if(plans) { - flash.error = "Missing version" - redirect(action: 'listVersions') - return + session.delta = plans + println plans[0].toXml() + redirect(controller: 'plan', action: 'view', id: plans[0].id) } - - if(params.agents instanceof String) + else { - params.agents = [params.agents] + flash.message = "No agent to cleanup" + redirect(action: 'listVersions') } - - params.fabric = request.fabric - - def plan = agentsService.createAgentsCleanupUpgradePlan(params) - - session.delta = [plan] - - redirect(controller: 'plan', action: 'view', id: plan.id) } /** @@ -117,9 +125,7 @@ class AgentsController extends ControllerBase params.name = title def system = request.system - system = system?.filterBy { - it.agent == params.id - } + system = system?.filterBy("agent='${params.id}'".toString()) request.system = system params.system = system diff --git a/console/org.linkedin.glu.console-webapp/grails-app/views/agents/listVersions.gsp b/console/org.linkedin.glu.console-webapp/grails-app/views/agents/listVersions.gsp index ec7d07fe..c432acfe 100644 --- a/console/org.linkedin.glu.console-webapp/grails-app/views/agents/listVersions.gsp +++ b/console/org.linkedin.glu.console-webapp/grails-app/views/agents/listVersions.gsp @@ -19,7 +19,13 @@
Quick Select: @@ -50,5 +55,10 @@