Skip to content

Commit

Permalink
#63: test setup
Browse files Browse the repository at this point in the history
  • Loading branch information
ypujante committed Jun 12, 2011
1 parent 138745b commit ff2defc
Show file tree
Hide file tree
Showing 14 changed files with 219 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<SystemModel> models = SystemModel.filter(expectedModel, currentModel);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Object> args = new HashMap<String, Object>();
args.put("transitions", Agent.DEFAULT_TRANSITIONS);
DEFAULT_STATE_MACHINE = new StateMachineImpl(args);
}

private final SystemEntry _expectedEntry;
private final SystemEntry _currentEntry;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,18 @@

package org.linkedin.glu.orchestration.engine.delta;

import org.linkedin.glu.provisioner.core.model.SystemModel;

import java.util.Set;

/**
* @author yan@pongasoft.com
*/
public interface SystemModelDelta
{
SystemModel getExpectedSystemModel();
SystemModel getCurrentSystemModel();

Set<String> getKeys();
SystemEntryDelta findEntryDelta(String key);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -27,11 +29,31 @@ public class SystemModelDeltaImpl implements SystemModelDelta
{
private final Map<String, SystemEntryDelta> _deltas = new HashMap<String, SystemEntryDelta>();

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<String, SystemEntryDelta> getDeltas()
{
return _deltas;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Object> toMetadata();

void toMetadata(Map<String, Object> metadata);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Object> metadata)
{
super.toMetadata(metadata);
metadata.put("agent", _agent);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

package org.linkedin.glu.orchestration.engine.planner;

import java.util.LinkedHashMap;
import java.util.Map;

/**
* @author yan@pongasoft.com
*/
Expand All @@ -35,4 +38,18 @@ public String getDescription()
{
return _description;
}

@Override
public Map<String, Object> toMetadata()
{
LinkedHashMap<String, Object> metadata = new LinkedHashMap<String, Object>();
toMetadata(metadata);
return metadata;
}

@Override
public void toMetadata(Map<String, Object> metadata)
{
metadata.put("description", _description);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package org.linkedin.glu.orchestration.engine.planner;

import java.net.URI;
import java.util.Map;

/**
Expand All @@ -29,16 +28,23 @@ 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;
}

public String getMountPoint()
{
return _mountPoint;
}

@Override
public void toMetadata(Map<String, Object> metadata)
{
super.toMetadata(metadata);
metadata.put("mountPoint", _mountPoint);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package org.linkedin.glu.orchestration.engine.planner;

import java.util.Map;

/**
* @author yan@pongasoft.com
*/
Expand All @@ -28,4 +30,17 @@ public NoOpActionDescriptor(String description)
{
super(description);
}

@Override
public void toMetadata(Map<String, Object> metadata)
{
super.toMetadata(metadata);
metadata.put("action", "noop");
}

@Override
public String toString()
{
return "noop";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -25,7 +26,5 @@
*/
public interface Planner
{
Plan<ActionDescriptor> computeDeploymentPlan(IStep.Type type,
SystemModel expectedModel,
SystemModel currentModel);
Plan<ActionDescriptor> computeDeploymentPlan(IStep.Type type, SystemModelDelta systemModelDelta);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -38,8 +35,6 @@
*/
public class PlannerImpl implements Planner
{
private DeltaMgr _deltaMgr;

/**
* Constructor
*/
Expand All @@ -49,14 +44,11 @@ public PlannerImpl()

@Override
public Plan<ActionDescriptor> 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<ActionDescriptor> builder = new PlanBuilder<ActionDescriptor>();

ICompositeStepBuilder<ActionDescriptor> stepBuilder = builder.addCompositeSteps(type);
Expand All @@ -69,17 +61,6 @@ public Plan<ActionDescriptor> 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<ActionDescriptor> stepBuilder,
SystemEntryDelta entryDelta)
{
Expand Down Expand Up @@ -140,11 +121,11 @@ protected void addLifecycleStep(ICompositeStepBuilder<ActionDescriptor> 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);
Expand Down Expand Up @@ -177,7 +158,7 @@ protected void addTransitionStep(ICompositeStepBuilder<ActionDescriptor> stepBui
URI agentURI = null;

ScriptTransitionActionDescriptor actionDescriptor =
new ScriptTransitionActionDescriptor(agentURI,
new ScriptTransitionActionDescriptor(entryDelta.getAgent(),
entryDelta.getMountPoint(),
action,
endState,
Expand All @@ -188,17 +169,11 @@ protected void addTransitionStep(ICompositeStepBuilder<ActionDescriptor> stepBui
}

protected void addLeafStep(ICompositeStepBuilder<ActionDescriptor> stepBuilder,
SystemEntryDelta entryDelta, ActionDescriptor actionDescriptor)
SystemEntryDelta entryDelta,
ActionDescriptor actionDescriptor)
{
stepBuilder.addLeafStep(new LeafStep<ActionDescriptor>(null,
computeMetadata(entryDelta),
actionDescriptor.toMetadata(),
actionDescriptor));
}

protected Map<String, Object> computeMetadata(SystemEntryDelta entryDelta)
{
Map<String, Object> metadata = new HashMap<String, Object>();
metadata.put("agent", entryDelta.getAgent());
return metadata;
}
}
Loading

0 comments on commit ff2defc

Please sign in to comment.