diff --git a/orchestration/org.linkedin.glu.orchestration-engine/src/main/java/org/linkedin/glu/orchestration/engine/delta/DeltaMgrImpl.java b/orchestration/org.linkedin.glu.orchestration-engine/src/main/java/org/linkedin/glu/orchestration/engine/delta/DeltaMgrImpl.java index 7821f255..f6d63a05 100644 --- a/orchestration/org.linkedin.glu.orchestration-engine/src/main/java/org/linkedin/glu/orchestration/engine/delta/DeltaMgrImpl.java +++ b/orchestration/org.linkedin.glu.orchestration-engine/src/main/java/org/linkedin/glu/orchestration/engine/delta/DeltaMgrImpl.java @@ -71,7 +71,7 @@ public SystemModelDelta computeDelta(SystemModel expectedModel, SystemModel curr if(expectedModel == null || currentModel == null) return null; - SystemModelDeltaImpl systemModelDelta = new SystemModelDeltaImpl(); + SystemModelDeltaImpl systemModelDelta = new SystemModelDeltaImpl(expectedModel, currentModel); List models = SystemModel.filter(expectedModel, currentModel); @@ -106,9 +106,6 @@ private SystemEntryDelta computeSystemEntryDelta(SystemEntry expectedEntry, { SystemEntryDeltaImpl sed = new SystemEntryDeltaImpl(expectedEntry, currentEntry); - if(expectedEntry == null || currentEntry == null) - return sed; - // processing version mismatch processVersionMismatch(sed); @@ -156,7 +153,7 @@ protected boolean isKeyIncludedInVersionMismatch(String key) res = res || key.startsWith("initParameters."); - res = res && !_excludedInVersionMismatch.contains(key); + res = res && (_excludedInVersionMismatch == null || !_excludedInVersionMismatch.contains(key)); return res; } diff --git a/orchestration/org.linkedin.glu.orchestration-engine/src/main/java/org/linkedin/glu/orchestration/engine/delta/SystemEntryDeltaImpl.java b/orchestration/org.linkedin.glu.orchestration-engine/src/main/java/org/linkedin/glu/orchestration/engine/delta/SystemEntryDeltaImpl.java index 8021de67..277fe2ff 100644 --- a/orchestration/org.linkedin.glu.orchestration-engine/src/main/java/org/linkedin/glu/orchestration/engine/delta/SystemEntryDeltaImpl.java +++ b/orchestration/org.linkedin.glu.orchestration-engine/src/main/java/org/linkedin/glu/orchestration/engine/delta/SystemEntryDeltaImpl.java @@ -31,8 +31,14 @@ */ public class SystemEntryDeltaImpl implements SystemEntryDelta { - public static final StateMachine DEFAULT_STATE_MACHINE = - new StateMachineImpl(Agent.DEFAULT_TRANSITIONS); + public static final StateMachine DEFAULT_STATE_MACHINE; + + static + { + Map args = new HashMap(); + args.put("transitions", Agent.DEFAULT_TRANSITIONS); + DEFAULT_STATE_MACHINE = new StateMachineImpl(args); + } private final SystemEntry _expectedEntry; private final SystemEntry _currentEntry; diff --git a/orchestration/org.linkedin.glu.orchestration-engine/src/main/java/org/linkedin/glu/orchestration/engine/delta/SystemModelDelta.java b/orchestration/org.linkedin.glu.orchestration-engine/src/main/java/org/linkedin/glu/orchestration/engine/delta/SystemModelDelta.java index 8eededf8..490ff0f4 100644 --- a/orchestration/org.linkedin.glu.orchestration-engine/src/main/java/org/linkedin/glu/orchestration/engine/delta/SystemModelDelta.java +++ b/orchestration/org.linkedin.glu.orchestration-engine/src/main/java/org/linkedin/glu/orchestration/engine/delta/SystemModelDelta.java @@ -16,6 +16,8 @@ package org.linkedin.glu.orchestration.engine.delta; +import org.linkedin.glu.provisioner.core.model.SystemModel; + import java.util.Set; /** @@ -23,6 +25,9 @@ */ public interface SystemModelDelta { + SystemModel getExpectedSystemModel(); + SystemModel getCurrentSystemModel(); + Set getKeys(); SystemEntryDelta findEntryDelta(String key); diff --git a/orchestration/org.linkedin.glu.orchestration-engine/src/main/java/org/linkedin/glu/orchestration/engine/delta/SystemModelDeltaImpl.java b/orchestration/org.linkedin.glu.orchestration-engine/src/main/java/org/linkedin/glu/orchestration/engine/delta/SystemModelDeltaImpl.java index 25e475cf..7ced1c10 100644 --- a/orchestration/org.linkedin.glu.orchestration-engine/src/main/java/org/linkedin/glu/orchestration/engine/delta/SystemModelDeltaImpl.java +++ b/orchestration/org.linkedin.glu.orchestration-engine/src/main/java/org/linkedin/glu/orchestration/engine/delta/SystemModelDeltaImpl.java @@ -16,6 +16,8 @@ package org.linkedin.glu.orchestration.engine.delta; +import org.linkedin.glu.provisioner.core.model.SystemModel; + import java.util.HashMap; import java.util.Map; import java.util.Set; @@ -27,11 +29,31 @@ public class SystemModelDeltaImpl implements SystemModelDelta { private final Map _deltas = new HashMap(); + private final SystemModel _expectedSystemModel; + private final SystemModel _currentSystemModel; + /** * Constructor */ - public SystemModelDeltaImpl() + public SystemModelDeltaImpl(SystemModel expectedSystemModel, SystemModel currentSystemModel) + { + _expectedSystemModel = expectedSystemModel; + _currentSystemModel = currentSystemModel; + } + + public SystemModel getExpectedSystemModel() + { + return _expectedSystemModel; + } + + public SystemModel getCurrentSystemModel() + { + return _currentSystemModel; + } + + public Map getDeltas() { + return _deltas; } @Override diff --git a/orchestration/org.linkedin.glu.orchestration-engine/src/main/java/org/linkedin/glu/orchestration/engine/planner/ActionDescriptor.java b/orchestration/org.linkedin.glu.orchestration-engine/src/main/java/org/linkedin/glu/orchestration/engine/planner/ActionDescriptor.java index f7ff8dfc..27562659 100644 --- a/orchestration/org.linkedin.glu.orchestration-engine/src/main/java/org/linkedin/glu/orchestration/engine/planner/ActionDescriptor.java +++ b/orchestration/org.linkedin.glu.orchestration-engine/src/main/java/org/linkedin/glu/orchestration/engine/planner/ActionDescriptor.java @@ -16,10 +16,16 @@ package org.linkedin.glu.orchestration.engine.planner; +import java.util.Map; + /** * @author yan@pongasoft.com */ public interface ActionDescriptor { String getDescription(); + + Map toMetadata(); + + void toMetadata(Map metadata); } \ No newline at end of file diff --git a/orchestration/org.linkedin.glu.orchestration-engine/src/main/java/org/linkedin/glu/orchestration/engine/planner/AgentActionDescriptor.java b/orchestration/org.linkedin.glu.orchestration-engine/src/main/java/org/linkedin/glu/orchestration/engine/planner/AgentActionDescriptor.java index 64dcf1d0..8a159f04 100644 --- a/orchestration/org.linkedin.glu.orchestration-engine/src/main/java/org/linkedin/glu/orchestration/engine/planner/AgentActionDescriptor.java +++ b/orchestration/org.linkedin.glu.orchestration-engine/src/main/java/org/linkedin/glu/orchestration/engine/planner/AgentActionDescriptor.java @@ -16,27 +16,34 @@ package org.linkedin.glu.orchestration.engine.planner; -import java.net.URI; +import java.util.Map; /** * @author yan@pongasoft.com */ public class AgentActionDescriptor extends BaseActionDescriptor { - private final URI _agentURI; + private final String _agent; /** * Constructor */ - public AgentActionDescriptor(URI agentURI, + public AgentActionDescriptor(String agent, String description) { super(description); - _agentURI = agentURI; + _agent = agent; } - public URI getAgentURI() + public String getAgent() { - return _agentURI; + return _agent; + } + + @Override + public void toMetadata(Map metadata) + { + super.toMetadata(metadata); + metadata.put("agent", _agent); } } diff --git a/orchestration/org.linkedin.glu.orchestration-engine/src/main/java/org/linkedin/glu/orchestration/engine/planner/BaseActionDescriptor.java b/orchestration/org.linkedin.glu.orchestration-engine/src/main/java/org/linkedin/glu/orchestration/engine/planner/BaseActionDescriptor.java index edb71d4b..cd99d76c 100644 --- a/orchestration/org.linkedin.glu.orchestration-engine/src/main/java/org/linkedin/glu/orchestration/engine/planner/BaseActionDescriptor.java +++ b/orchestration/org.linkedin.glu.orchestration-engine/src/main/java/org/linkedin/glu/orchestration/engine/planner/BaseActionDescriptor.java @@ -16,6 +16,9 @@ package org.linkedin.glu.orchestration.engine.planner; +import java.util.LinkedHashMap; +import java.util.Map; + /** * @author yan@pongasoft.com */ @@ -35,4 +38,18 @@ public String getDescription() { return _description; } + + @Override + public Map toMetadata() + { + LinkedHashMap metadata = new LinkedHashMap(); + toMetadata(metadata); + return metadata; + } + + @Override + public void toMetadata(Map metadata) + { + metadata.put("description", _description); + } } diff --git a/orchestration/org.linkedin.glu.orchestration-engine/src/main/java/org/linkedin/glu/orchestration/engine/planner/MountPointActionDescriptor.java b/orchestration/org.linkedin.glu.orchestration-engine/src/main/java/org/linkedin/glu/orchestration/engine/planner/MountPointActionDescriptor.java index 27696ed5..14143b55 100644 --- a/orchestration/org.linkedin.glu.orchestration-engine/src/main/java/org/linkedin/glu/orchestration/engine/planner/MountPointActionDescriptor.java +++ b/orchestration/org.linkedin.glu.orchestration-engine/src/main/java/org/linkedin/glu/orchestration/engine/planner/MountPointActionDescriptor.java @@ -16,7 +16,6 @@ package org.linkedin.glu.orchestration.engine.planner; -import java.net.URI; import java.util.Map; /** @@ -29,11 +28,11 @@ public class MountPointActionDescriptor extends AgentActionDescriptor /** * Constructor */ - public MountPointActionDescriptor(URI agentURI, + public MountPointActionDescriptor(String agent, String mountPoint, String description) { - super(agentURI, description); + super(agent, description); _mountPoint = mountPoint; } @@ -41,4 +40,11 @@ public String getMountPoint() { return _mountPoint; } + + @Override + public void toMetadata(Map metadata) + { + super.toMetadata(metadata); + metadata.put("mountPoint", _mountPoint); + } } diff --git a/orchestration/org.linkedin.glu.orchestration-engine/src/main/java/org/linkedin/glu/orchestration/engine/planner/NoOpActionDescriptor.java b/orchestration/org.linkedin.glu.orchestration-engine/src/main/java/org/linkedin/glu/orchestration/engine/planner/NoOpActionDescriptor.java index 06b2f8cf..f0af8d03 100644 --- a/orchestration/org.linkedin.glu.orchestration-engine/src/main/java/org/linkedin/glu/orchestration/engine/planner/NoOpActionDescriptor.java +++ b/orchestration/org.linkedin.glu.orchestration-engine/src/main/java/org/linkedin/glu/orchestration/engine/planner/NoOpActionDescriptor.java @@ -16,6 +16,8 @@ package org.linkedin.glu.orchestration.engine.planner; +import java.util.Map; + /** * @author yan@pongasoft.com */ @@ -28,4 +30,17 @@ public NoOpActionDescriptor(String description) { super(description); } + + @Override + public void toMetadata(Map metadata) + { + super.toMetadata(metadata); + metadata.put("action", "noop"); + } + + @Override + public String toString() + { + return "noop"; + } } diff --git a/orchestration/org.linkedin.glu.orchestration-engine/src/main/java/org/linkedin/glu/orchestration/engine/planner/Planner.java b/orchestration/org.linkedin.glu.orchestration-engine/src/main/java/org/linkedin/glu/orchestration/engine/planner/Planner.java index ef97c063..3675ce42 100644 --- a/orchestration/org.linkedin.glu.orchestration-engine/src/main/java/org/linkedin/glu/orchestration/engine/planner/Planner.java +++ b/orchestration/org.linkedin.glu.orchestration-engine/src/main/java/org/linkedin/glu/orchestration/engine/planner/Planner.java @@ -16,6 +16,7 @@ package org.linkedin.glu.orchestration.engine.planner; +import org.linkedin.glu.orchestration.engine.delta.SystemModelDelta; import org.linkedin.glu.provisioner.core.model.SystemModel; import org.linkedin.glu.provisioner.plan.api.IStep; import org.linkedin.glu.provisioner.plan.api.Plan; @@ -25,7 +26,5 @@ */ public interface Planner { - Plan computeDeploymentPlan(IStep.Type type, - SystemModel expectedModel, - SystemModel currentModel); + Plan computeDeploymentPlan(IStep.Type type, SystemModelDelta systemModelDelta); } \ No newline at end of file diff --git a/orchestration/org.linkedin.glu.orchestration-engine/src/main/java/org/linkedin/glu/orchestration/engine/planner/PlannerImpl.java b/orchestration/org.linkedin.glu.orchestration-engine/src/main/java/org/linkedin/glu/orchestration/engine/planner/PlannerImpl.java index bf568b31..9d45fc74 100644 --- a/orchestration/org.linkedin.glu.orchestration-engine/src/main/java/org/linkedin/glu/orchestration/engine/planner/PlannerImpl.java +++ b/orchestration/org.linkedin.glu.orchestration-engine/src/main/java/org/linkedin/glu/orchestration/engine/planner/PlannerImpl.java @@ -16,17 +16,14 @@ package org.linkedin.glu.orchestration.engine.planner; -import org.linkedin.glu.orchestration.engine.delta.DeltaMgr; import org.linkedin.glu.orchestration.engine.delta.SystemEntryDelta; import org.linkedin.glu.orchestration.engine.delta.SystemModelDelta; -import org.linkedin.glu.provisioner.core.model.SystemModel; import org.linkedin.glu.provisioner.plan.api.ICompositeStepBuilder; import org.linkedin.glu.provisioner.plan.api.IStep; import org.linkedin.glu.provisioner.plan.api.LeafStep; import org.linkedin.glu.provisioner.plan.api.Plan; import org.linkedin.glu.provisioner.plan.api.PlanBuilder; import org.linkedin.groovy.util.state.StateMachine; -import org.linkedin.util.annotations.Initializer; import java.net.URI; import java.util.Collection; @@ -38,8 +35,6 @@ */ public class PlannerImpl implements Planner { - private DeltaMgr _deltaMgr; - /** * Constructor */ @@ -49,14 +44,11 @@ public PlannerImpl() @Override public Plan computeDeploymentPlan(IStep.Type type, - SystemModel expectedModel, - SystemModel currentModel) + SystemModelDelta systemModelDelta) { - SystemModelDelta systemModelDelta = _deltaMgr.computeDelta(expectedModel, currentModel); - - if(systemModelDelta == null || !systemModelDelta.hasDelta()) + if(systemModelDelta == null) return null; - + PlanBuilder builder = new PlanBuilder(); ICompositeStepBuilder stepBuilder = builder.addCompositeSteps(type); @@ -69,17 +61,6 @@ public Plan computeDeploymentPlan(IStep.Type type, return builder.toPlan(); } - public DeltaMgr getDeltaMgr() - { - return _deltaMgr; - } - - @Initializer(required = true) - public void setDeltaMgr(DeltaMgr deltaMgr) - { - _deltaMgr = deltaMgr; - } - protected void processEntryDelta(ICompositeStepBuilder stepBuilder, SystemEntryDelta entryDelta) { @@ -140,11 +121,11 @@ protected void addLifecycleStep(ICompositeStepBuilder stepBuil URI agentURI = null; ScriptLifecycleActionDescriptor actionDescriptor = - new ScriptLifecycleActionDescriptor(agentURI, + new ScriptLifecycleActionDescriptor(entryDelta.getAgent(), entryDelta.getMountPoint(), scriptLifecycle, scriptLifecycle == ScriptLifecycle.INSTALL_SCRIPT ? - (Map) entryDelta.getCurrentEntry().getInitParameters() : null, + (Map) entryDelta.getExpectedEntry().getInitParameters() : null, "TODO script lifecycle: " + scriptLifecycle); addLeafStep(stepBuilder, entryDelta, actionDescriptor); @@ -177,7 +158,7 @@ protected void addTransitionStep(ICompositeStepBuilder stepBui URI agentURI = null; ScriptTransitionActionDescriptor actionDescriptor = - new ScriptTransitionActionDescriptor(agentURI, + new ScriptTransitionActionDescriptor(entryDelta.getAgent(), entryDelta.getMountPoint(), action, endState, @@ -188,17 +169,11 @@ protected void addTransitionStep(ICompositeStepBuilder stepBui } protected void addLeafStep(ICompositeStepBuilder stepBuilder, - SystemEntryDelta entryDelta, ActionDescriptor actionDescriptor) + SystemEntryDelta entryDelta, + ActionDescriptor actionDescriptor) { stepBuilder.addLeafStep(new LeafStep(null, - computeMetadata(entryDelta), + actionDescriptor.toMetadata(), actionDescriptor)); } - - protected Map computeMetadata(SystemEntryDelta entryDelta) - { - Map metadata = new HashMap(); - metadata.put("agent", entryDelta.getAgent()); - return metadata; - } } diff --git a/orchestration/org.linkedin.glu.orchestration-engine/src/main/java/org/linkedin/glu/orchestration/engine/planner/ScriptLifecycleActionDescriptor.java b/orchestration/org.linkedin.glu.orchestration-engine/src/main/java/org/linkedin/glu/orchestration/engine/planner/ScriptLifecycleActionDescriptor.java index 684b62b6..0265924b 100644 --- a/orchestration/org.linkedin.glu.orchestration-engine/src/main/java/org/linkedin/glu/orchestration/engine/planner/ScriptLifecycleActionDescriptor.java +++ b/orchestration/org.linkedin.glu.orchestration-engine/src/main/java/org/linkedin/glu/orchestration/engine/planner/ScriptLifecycleActionDescriptor.java @@ -16,7 +16,6 @@ package org.linkedin.glu.orchestration.engine.planner; -import java.net.URI; import java.util.Map; /** @@ -31,13 +30,13 @@ public class ScriptLifecycleActionDescriptor extends MountPointActionDescriptor /** * Constructor */ - public ScriptLifecycleActionDescriptor(URI agentURI, + public ScriptLifecycleActionDescriptor(String agent, String mountPoint, ScriptLifecycle scriptLifecycle, Map initParameters, String description) { - super(agentURI, mountPoint, description); + super(agent, mountPoint, description); _scriptLifecycle = scriptLifecycle; _initParameters = initParameters; } @@ -51,4 +50,11 @@ public Map getInitParameters() { return _initParameters; } + + @Override + public void toMetadata(Map metadata) + { + super.toMetadata(metadata); + metadata.put("scriptLifecycle", _scriptLifecycle.toString().toLowerCase()); + } } diff --git a/orchestration/org.linkedin.glu.orchestration-engine/src/main/java/org/linkedin/glu/orchestration/engine/planner/ScriptTransitionActionDescriptor.java b/orchestration/org.linkedin.glu.orchestration-engine/src/main/java/org/linkedin/glu/orchestration/engine/planner/ScriptTransitionActionDescriptor.java index 7cd4abb4..72eeb133 100644 --- a/orchestration/org.linkedin.glu.orchestration-engine/src/main/java/org/linkedin/glu/orchestration/engine/planner/ScriptTransitionActionDescriptor.java +++ b/orchestration/org.linkedin.glu.orchestration-engine/src/main/java/org/linkedin/glu/orchestration/engine/planner/ScriptTransitionActionDescriptor.java @@ -16,7 +16,6 @@ package org.linkedin.glu.orchestration.engine.planner; -import java.net.URI; import java.util.Map; /** @@ -31,14 +30,14 @@ public class ScriptTransitionActionDescriptor extends MountPointActionDescriptor /** * Constructor */ - public ScriptTransitionActionDescriptor(URI agentURI, + public ScriptTransitionActionDescriptor(String agent, String mountPoint, String action, String endState, Map actionArgs, String description) { - super(agentURI, mountPoint, description); + super(agent, mountPoint, description); _action = action; _endState = endState; _actionArgs = actionArgs; @@ -58,4 +57,10 @@ public Map getActionArgs() { return _actionArgs; } -} + @Override + public void toMetadata(Map metadata) + { + super.toMetadata(metadata); + metadata.put("scriptTransition", _action); + } + } diff --git a/orchestration/org.linkedin.glu.orchestration-engine/src/test/groovy/test/orchestration/engine/planner/TestPlannerImpl.groovy b/orchestration/org.linkedin.glu.orchestration-engine/src/test/groovy/test/orchestration/engine/planner/TestPlannerImpl.groovy new file mode 100644 index 00000000..495573db --- /dev/null +++ b/orchestration/org.linkedin.glu.orchestration-engine/src/test/groovy/test/orchestration/engine/planner/TestPlannerImpl.groovy @@ -0,0 +1,92 @@ +/* + * 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 test.orchestration.engine.planner + +import org.linkedin.glu.orchestration.engine.planner.PlannerImpl +import org.linkedin.glu.provisioner.plan.api.IStep.Type +import org.linkedin.glu.provisioner.core.model.SystemModel +import org.linkedin.glu.provisioner.core.model.SystemEntry +import org.linkedin.glu.provisioner.plan.api.Plan +import org.linkedin.glu.orchestration.engine.planner.ActionDescriptor +import org.linkedin.glu.orchestration.engine.delta.SystemModelDelta +import org.linkedin.glu.orchestration.engine.delta.DeltaMgr +import org.linkedin.glu.orchestration.engine.delta.DeltaMgrImpl + +/** + * @author yan@pongasoft.com */ +public class TestPlannerImpl extends GroovyTestCase +{ + def PlannerImpl planner = new PlannerImpl() + def DeltaMgr deltaMgr = new DeltaMgrImpl() + + public void testDeploymentPlanNoDelta() + { + assertNull(planner.computeDeploymentPlan(Type.SEQUENTIAL, null)) + + Plan plan = plan(Type.SEQUENTIAL, + delta(m([agent: 'a1', mountPoint: 'm1', script: 's1']), + m([agent: 'a1', mountPoint: 'm1', script: 's1']))) + + println plan.toXml() + } + + /** + * When delta means deploy (not in current) + */ + public void testDeploymentPlanDeploy() + { + Plan plan = plan(Type.SEQUENTIAL, + delta(m([agent: 'a1', mountPoint: 'm1', script: 's1']), + m())) + + println plan.toXml() + } + + /** + * When delta means undeploy (not in expected) + */ + public void testDeploymentPlanUnDeploy() + { + Plan plan = plan(Type.SEQUENTIAL, + delta(m(), + m([agent: 'a1', mountPoint: 'm1', script: 's1']))) + + println plan.toXml() + } + + private SystemModel m(Map... entries) + { + SystemModel model = new SystemModel(fabric: "f1") + + + entries.each { + model.addEntry(SystemEntry.fromExternalRepresentation(it)) + } + + return model + } + + private SystemModelDelta delta(SystemModel expected, SystemModel current) + { + deltaMgr.computeDelta(expected, current) + } + + private Plan plan(Type type, SystemModelDelta delta) + { + planner.computeDeploymentPlan(type, delta) + } +} \ No newline at end of file