internal static IExperimentRunner CreateExperimentRunner(IExperiment currentExperiment, TraceLab.Core.Workspaces.Workspace workspace, TraceLab.Core.Components.ComponentsLibrary library) { // Allow all nodes to send info to logs - if any targets exist. foreach (TraceLab.Core.Experiments.ExperimentNode node in currentExperiment.Vertices) { var componentNode = node as TraceLab.Core.Experiments.ComponentNode; if (componentNode != null) { foreach (TraceLab.Core.Settings.LogLevelItem item in componentNode.Data.Metadata.LogLevels) { item.IsEnabled = true; } } } RunnableNodeFactory templateGraphNodesFactory = new RunnableNodeFactory(workspace); TraceLab.Core.ExperimentExecution.RunnableExperimentBase template = GraphAdapter.Adapt(currentExperiment, templateGraphNodesFactory, library, workspace.TypeDirectories); var dispatcher = ExperimentRunnerFactory.CreateExperimentRunner(template); return(dispatcher); }
/// <summary> /// Creates the experiment. /// </summary> /// <param name="experiment">The experiment.</param> /// <param name="baseline">The baseline - if baseline is different than null it is going to be written into workspace before executing the experiment /// with the Unitname BASELINE.</param> /// <returns></returns> private IExperimentRunner CreateExperimentRunner(Workspace workspace, ComponentsLibrary library, TraceLabSDK.Types.Contests.TLExperimentResults baseline) { RunnableExperimentBase graph = null; var experimentWorkspaceWrapper = WorkspaceWrapperFactory.CreateExperimentWorkspaceWrapper(workspace, ExperimentInfo.Id); RunnableNodeFactory templateGraphNodesFactory = new RunnableNodeFactory(experimentWorkspaceWrapper); graph = GraphAdapter.Adapt(this, templateGraphNodesFactory, library, experimentWorkspaceWrapper.TypeDirectories); //clear Workspace experimentWorkspaceWrapper.DeleteExperimentUnits(); //if baseline has been provided write it into the workspace before returning the dispatcher if (baseline != null) { experimentWorkspaceWrapper.Store("BASELINE", baseline); } IExperimentRunner dispatcher = ExperimentRunnerFactory.CreateExperimentRunner(graph); dispatcher.NodeExecuting += dispatcher_NodeExecuting; dispatcher.NodeFinished += dispatcher_NodeFinished; dispatcher.NodeHasError += dispatcher_NodeHasError; dispatcher.ExperimentFinished += dispatcher_ExperimentFinished; dispatcher.ExperimentStarted += dispatcher_ExperimentStarted; m_dispatcher = dispatcher; return(dispatcher); }
public void ValidateInputMapping_CorrectFlow_OutputFound2() { IEditableExperiment experiment = ((IEditableExperiment)ExperimentManager.New()); experiment.ExperimentInfo.FilePath = "C:\\somefakelocation\\mockExperiment.teml"; ExperimentNode readerNode = experiment.AddComponentFromDefinition(m_componentReaderMetaDefinition, 5, 5); ExperimentNode writerNode1 = experiment.AddComponentFromDefinition(m_componentWriterMetaDefinition, 15, 15); ExperimentNode writerNode2 = experiment.AddComponentFromDefinition(m_componentWriterMetaDefinition, 25, 25); experiment.AddConnection(experiment.StartNode, writerNode1); experiment.AddConnection(writerNode1, writerNode2); experiment.AddConnection(writerNode2, readerNode); experiment.AddConnection(readerNode, experiment.EndNode); (writerNode1.Data.Metadata as ComponentMetadata).IOSpec.Output["testoutput"].MappedTo = "test1"; (writerNode2.Data.Metadata as ComponentMetadata).IOSpec.Output["testoutput"].MappedTo = "test2"; (readerNode.Data.Metadata as ComponentMetadata).IOSpec.Input["testinput"].MappedTo = "test1"; RunnableNodeFactory templateGraphNodesFactory = new RunnableNodeFactory(AppContext.WorkspaceInstance); RunnableExperimentBase template = GraphAdapter.Adapt(experiment, templateGraphNodesFactory, AppContext.Components, AppContext.WorkspaceInstance.TypeDirectories); Assert.IsFalse(template.IsEmpty); Assert.IsFalse(readerNode.HasError); Assert.IsFalse(writerNode1.HasError); Assert.IsFalse(writerNode2.HasError); Assert.AreEqual(5, template.Nodes.Count); }
public void GraphStructureValidator_NoPathToEnd2() { IEditableExperiment experiment = ((IEditableExperiment)ExperimentManager.New()); experiment.ExperimentInfo.FilePath = "C:\\somefakelocation\\mockExperiment.teml"; ExperimentNode node1 = experiment.AddComponentFromDefinition(m_emptyComponentMetaDefinition, 5, 5); ExperimentNode node2 = experiment.AddComponentFromDefinition(m_emptyComponentMetaDefinition, 15, 15); ExperimentNode node3 = experiment.AddComponentFromDefinition(m_emptyComponentMetaDefinition, 25, 25); experiment.AddConnection(experiment.StartNode, node1); experiment.AddConnection(experiment.StartNode, node3); experiment.AddConnection(node1, node2); experiment.AddConnection(node2, experiment.EndNode); Assert.IsFalse(node1.HasError); Assert.IsFalse(node2.HasError); Assert.IsFalse(node3.HasError); RunnableNodeFactory templateGraphNodesFactory = new RunnableNodeFactory(AppContext.WorkspaceInstance); RunnableExperimentBase template = GraphAdapter.Adapt(experiment, templateGraphNodesFactory, AppContext.Components, AppContext.WorkspaceInstance.TypeDirectories); Assert.IsTrue(template.IsEmpty); Assert.IsTrue(node3.HasError); Assert.AreEqual(node3.ErrorMessage, "Unable to detect path to the END node."); }
public void GraphStructureValidator_NoCircularLinkIfDecision() { Experiment experiment = ExperimentManager.New(); experiment.ExperimentInfo.FilePath = "C:\\somefakelocation\\mockExperiment.teml"; ExperimentNode node1 = experiment.AddComponentFromDefinition(m_emptyComponentMetaDefinition, 5, 5); ExperimentNode node2 = experiment.AddComponentFromDefinition(m_emptyComponentMetaDefinition, 15, 15); var decisionNode = AddDecisionToExperiment(experiment, 10, 10); decisionNode.Data.Metadata = CompileMockDecision(""); experiment.AddConnection(experiment.StartNode, node1); experiment.AddConnection(node1, node2); experiment.AddConnection(node2, decisionNode); experiment.AddConnection(decisionNode, node1); experiment.AddConnection(decisionNode, experiment.EndNode); Assert.IsFalse(node1.HasError); Assert.IsFalse(node2.HasError); Assert.IsFalse(decisionNode.HasError); RunnableNodeFactory templateGraphNodesFactory = new RunnableNodeFactory(AppContext.WorkspaceInstance); RunnableExperimentBase template = GraphAdapter.Adapt(experiment, templateGraphNodesFactory, AppContext.Components, AppContext.WorkspaceInstance.TypeDirectories); Assert.IsFalse(node1.HasError); Assert.IsFalse(node2.HasError); Assert.IsFalse(decisionNode.HasError); Assert.IsFalse(template.IsEmpty); Assert.AreEqual(5, template.Nodes.Count); //check all edges foreach (RunnableNode node in template.Nodes) { if (node is RunnableDecisionNode) { //in this graph decision node has only two outcoming edges Assert.AreEqual(2, node.NextNodes.Count); } else if (node is RunnableEndNode) { //end node has none outcoming edges Assert.AreEqual(0, node.NextNodes.Count); } else { //all other nodes in this graph has only one outcoming edge Assert.AreEqual(1, node.NextNodes.Count); } } }
private static IExperimentRunner CreateExperiment(Experiment experiment, Workspace workspace, ComponentsLibrary library) { RunnableExperimentBase graph = null; ExperimentWorkspaceWrapper experimentWorkspaceWrapper = WorkspaceWrapperFactory.CreateExperimentWorkspaceWrapper(workspace, experiment.ExperimentInfo.Id); RunnableNodeFactory templateGraphNodesFactory = new RunnableNodeFactory(experimentWorkspaceWrapper); graph = GraphAdapter.Adapt(experiment, templateGraphNodesFactory, library, workspace.TypeDirectories); //clear Workspace workspace.DeleteUnits(experiment.ExperimentInfo.Id); IExperimentRunner dispatcher = ExperimentRunnerFactory.CreateExperimentRunner(graph); return(dispatcher); }
public void ValidateInputMapping_NoOutputFound2() { Assert.Fail("Test temporarily broken. The input mapping validator temporarily validates across all components, " + "not only predecessors nodes. Test ignored till the validator feature is going to be revisited."); IEditableExperiment experiment = ((IEditableExperiment)ExperimentManager.New()); experiment.ExperimentInfo.FilePath = "C:\\somefakelocation\\mockExperiment.teml"; ExperimentNode readerNode1 = experiment.AddComponentFromDefinition(m_componentReaderMetaDefinition, 5, 5); ExperimentNode readerNode2 = experiment.AddComponentFromDefinition(m_componentReaderMetaDefinition, 15, 15); ExperimentNode writerNode = experiment.AddComponentFromDefinition(m_componentWriterMetaDefinition, 25, 25); experiment.AddConnection(experiment.StartNode, writerNode); experiment.AddConnection(experiment.StartNode, readerNode1); experiment.AddConnection(writerNode, readerNode2); experiment.AddConnection(readerNode1, experiment.EndNode); experiment.AddConnection(readerNode2, experiment.EndNode); (writerNode.Data.Metadata as ComponentMetadata).IOSpec.Output["testoutput"].MappedTo = "fakemapping"; (readerNode1.Data.Metadata as ComponentMetadata).IOSpec.Input["testinput"].MappedTo = "fakemapping"; (readerNode2.Data.Metadata as ComponentMetadata).IOSpec.Input["testinput"].MappedTo = "fakemapping"; Assert.IsFalse(readerNode1.HasError); Assert.IsFalse(readerNode2.HasError); Assert.IsFalse(writerNode.HasError); RunnableNodeFactory templateGraphNodesFactory = new RunnableNodeFactory(AppContext.WorkspaceInstance); RunnableExperimentBase template = GraphAdapter.Adapt(experiment, templateGraphNodesFactory, AppContext.Components, AppContext.WorkspaceInstance.TypeDirectories); Assert.IsTrue(template.IsEmpty); Assert.IsFalse(readerNode2.HasError); Assert.IsFalse(writerNode.HasError); Assert.IsTrue(readerNode1.HasError); Assert.AreEqual(readerNode1.ErrorMessage, "The component attempts to load 'fakemapping' from the Workspace. However, none of the previous components outputs 'fakemapping' to the Workspace."); }
public void ValidateInputMapping_NoOutputFound() { IEditableExperiment experiment = ((IEditableExperiment)ExperimentManager.New()); experiment.ExperimentInfo.FilePath = "C:\\somefakelocation\\mockExperiment.teml"; ExperimentNode readerNode = experiment.AddComponentFromDefinition(m_componentReaderMetaDefinition, 5, 5); ExperimentNode writerNode = experiment.AddComponentFromDefinition(m_componentWriterMetaDefinition, 5, 5); experiment.AddConnection(experiment.StartNode, writerNode); experiment.AddConnection(writerNode, readerNode); experiment.AddConnection(readerNode, experiment.EndNode); (readerNode.Data.Metadata as ComponentMetadata).IOSpec.Input["testinput"].MappedTo = "fakemapping"; Assert.IsFalse(readerNode.HasError); RunnableNodeFactory templateGraphNodesFactory = new RunnableNodeFactory(AppContext.WorkspaceInstance); RunnableExperimentBase template = GraphAdapter.Adapt(experiment, templateGraphNodesFactory, AppContext.Components, AppContext.WorkspaceInstance.TypeDirectories); Assert.IsTrue(template.IsEmpty); Assert.IsTrue(readerNode.HasError); Assert.AreEqual(readerNode.ErrorMessage, "The component attempts to load 'fakemapping' from the Workspace. However, none of the previous components outputs 'fakemapping' to the Workspace."); }
public void ValidateInputMapping_Decision_CorrectMapping() { Experiment experiment = ExperimentManager.New(); experiment.ExperimentInfo.FilePath = "C:\\somefakelocation\\mockExperiment.teml"; ExperimentNode writerNode = experiment.AddComponentFromDefinition(m_componentWriterMetaDefinition, 15, 15); (writerNode.Data.Metadata as ComponentMetadata).IOSpec.Output["testoutput"].MappedTo = "test"; ExperimentNode readerNode = experiment.AddComponentFromDefinition(m_componentReaderMetaDefinition, 25, 25); (readerNode.Data.Metadata as ComponentMetadata).IOSpec.Input["testinput"].MappedTo = "test"; ExperimentNode incrementerNode = experiment.AddComponentFromDefinition(m_incrementerComponentMetaDefinition, 35, 35); (incrementerNode.Data.Metadata as ComponentMetadata).IOSpec.Input["testinput"].MappedTo = "test"; (incrementerNode.Data.Metadata as ComponentMetadata).IOSpec.Output["testoutput"].MappedTo = "test"; var decisionNode = AddDecisionToExperiment(experiment, 10, 10); //code doesn't really matter in this case, because we don't execute dispatcher string decisionCode = ""; decisionNode.Data.Metadata = CompileMockDecision(decisionCode); experiment.AddConnection(experiment.StartNode, writerNode); experiment.AddConnection(writerNode, readerNode); experiment.AddConnection(readerNode, decisionNode); experiment.AddConnection(decisionNode, incrementerNode); experiment.AddConnection(incrementerNode, readerNode); experiment.AddConnection(decisionNode, experiment.EndNode); Assert.IsFalse(writerNode.HasError); Assert.IsFalse(readerNode.HasError); Assert.IsFalse(incrementerNode.HasError); Assert.IsFalse(decisionNode.HasError); RunnableNodeFactory templateGraphNodesFactory = new RunnableNodeFactory(AppContext.WorkspaceInstance); RunnableExperimentBase template = GraphAdapter.Adapt(experiment, templateGraphNodesFactory, AppContext.Components, AppContext.WorkspaceInstance.TypeDirectories); Assert.IsFalse(writerNode.HasError); Assert.IsFalse(readerNode.HasError); Assert.IsFalse(incrementerNode.HasError); Assert.IsFalse(decisionNode.HasError); Assert.IsFalse(template.IsEmpty); Assert.AreEqual(6, template.Nodes.Count); //check all edges foreach (RunnableNode node in template.Nodes) { if (node is RunnableDecisionNode) { //in this graph decision node has only two outcoming edges Assert.AreEqual(2, node.NextNodes.Count); } else if (node is RunnableEndNode) { //end node has none outcoming edges Assert.AreEqual(0, node.NextNodes.Count); } else { //all other nodes in this graph has only one outcoming edge Assert.AreEqual(1, node.NextNodes.Count); } } }