public CloudManagerLocal(List <CloudMakefile> leaderCloudMakefiles, CloudMakefile localCloudMakefile, string name, List <List <string> > leaders, List <string> reserveLeaders, int nreplicas, int timeout, Vsync.Group vsyncGroup, string debugFilename, string monitorDebugFilename) { _vsyncAddress = VsyncSystem.GetMyAddress().ToStringVerboseFormat(); _name = name; _curDirectory = Directory.GetCurrentDirectory(); _procs = new Dictionary <string, ProcessInfo> (); _procsLock = new object(); _leaders = leaders; _reserveLeaders = reserveLeaders; _nreplicas = nreplicas; _leaderCloudMakefiles = leaderCloudMakefiles; _localCloudMakefile = localCloudMakefile; _queue = new List <Tuple <MessageType, List <string> > > (); _queueLock = new object(); _debugFilename = debugFilename; _cloudMakeMonitor = new CloudMakeMonitor(this, monitorDebugFilename, timeout); Thread cloudMakeMonitorThread = new Thread(delegate() { _cloudMakeMonitor.Run(vsyncGroup); }); cloudMakeMonitorThread.Start(); }
public DependencyStructure(CloudMakefile cloudMakefile, string debugFilename) { CloudManager.WriteLine(debugFilename, "CloudMakefile: " + cloudMakefile.ToString()); _cloudMakefile = cloudMakefile; _entries = new List <string> (); _policies = cloudMakefile.GetPolicies(); _inputs = new List <List <int> > (); _outputs = new List <List <int> > (); for (int i = 0; i < _policies.Count; i++) { _inputs.Add(new List <int> ()); _outputs.Add(new List <int> ()); } _reverseInputs = new List <List <int> > (); _reverseOutputs = new List <List <int> > (); _entryTokens = new HashSet <int> (); _policyTokens = new HashSet <int> (); _order = cloudMakefile.GetOrder(); _configFiles = new HashSet <string> (); _modifiedConfigFiles = new HashSet <string> (); _cloudMakeConfigFiles = new HashSet <string> (); _modifiedCloudMakeConfigFiles = new HashSet <string> (); _debugFilename = debugFilename; }
public CloudMakefile(CloudMakefile cloudMakefile) { List <HashSet <int> > inputs = cloudMakefile.GetInputs(); List <HashSet <int> > outputs = cloudMakefile.GetOutputs(); List <HashSet <int> > reverseInputs = cloudMakefile.GetReverseInputs(); List <HashSet <int> > reverseOutputs = cloudMakefile.GetReverseOutputs(); List <HashSet <int> > order = cloudMakefile.GetOrder(); _inputs = new List <HashSet <int> > (); for (int i = 0; i < inputs.Count; i++) { _inputs.Add(new HashSet <int> (inputs [i])); } _outputs = new List <HashSet <int> > (); for (int i = 0; i < outputs.Count; i++) { _outputs.Add(new HashSet <int> (outputs [i])); } _reverseInputs = new List <HashSet <int> > (); for (int i = 0; i < reverseInputs.Count; i++) { _reverseInputs.Add(new HashSet <int> (reverseInputs [i])); } _reverseOutputs = new List <HashSet <int> > (); for (int i = 0; i < reverseOutputs.Count; i++) { _reverseOutputs.Add(new HashSet <int> (reverseOutputs [i])); } _dfas = new List <DFA> (cloudMakefile.GetDFAs()); _policies = new List <string> (cloudMakefile.GetPolicies()); _order = new List <HashSet <int> > (); for (int i = 0; i < order.Count; i++) { _order.Add(new HashSet <int> (order [i])); } }
static private void ParseTreeNode(Node node, List <Entry> entryList) { List <Node> children = null; HashSet <char> alphabet = null; NFA curNFA = null; State state1, state2, chkState1, chkState2; switch (node.GetNodeType()) { case Node.Type.TENTRY: children = node.GetChildren(); if (children [0].GetNodeType() != Node.Type.TDIRPATH) { throw new CloudMakefile.ParseException("A TDIRPATH node is expected as the first node of a " + "TENTRY node."); } if (children [1].GetNodeType() != Node.Type.TNAME) { throw new CloudMakefile.ParseException("A TNAME node is expected as the second node of a TENTRY " + "node."); } if (children [2].GetNodeType() != Node.Type.TXMLPATH) { throw new CloudMakefile.ParseException("A TXMLPATH node is expected as the third node of a " + "TENTRY node."); } ParseTreeNode(children [0], entryList); ParseTreeNode(children [1], entryList); curNFA = EnsureLastNFA(entryList); state1 = curNFA.GetFinalState(); state2 = curNFA.AddState(); curNFA.AddTransition(state1, '.', state2); state1 = state2; state2 = curNFA.AddState(); curNFA.AddTransition(state1, 'x', state2); state1 = state2; state2 = curNFA.AddState(); curNFA.AddTransition(state1, 'm', state2); state1 = state2; state2 = curNFA.AddState(); curNFA.AddTransition(state1, 'l', state2); curNFA.SetFinalState(state2); ParseTreeNode(children [2], entryList); break; case Node.Type.TEVENT: children = node.GetChildren(); if (children [0].GetNodeType() != Node.Type.TDIRPATH) { throw new CloudMakefile.ParseException("A TDIRPATH node is expected as the first node of a " + "TEVENT node."); } if (children [1].GetNodeType() != Node.Type.TNAME) { throw new CloudMakefile.ParseException("A TNAME node is expected as the second node of a TEVENT " + "node."); } ParseTreeNode(children [0], entryList); ParseTreeNode(children [1], entryList); break; case Node.Type.TDIRPATH: children = node.GetChildren(); foreach (Node child in children) { if (child.GetNodeType() != Node.Type.TNAME) { throw new CloudMakefile.ParseException("A TNAME node is expected as the child node of a " + "TDIRPATH node."); } ParseTreeNode(child, entryList); curNFA = EnsureLastNFA(entryList); state1 = curNFA.GetFinalState(); state2 = curNFA.AddState(); curNFA.AddTransition(state1, Path.DirectorySeparatorChar, state2); curNFA.SetFinalState(state2); } break; case Node.Type.TXMLPATH: Node lastNode = new Node("ASTERISK(ATOM(SEQUENCE(CHOICE(RANGE(CHAR(A),CHAR(Z)),RANGE(CHAR(a)," + "CHAR(z)),RANGE(CHAR(0),CHAR(9)),CHAR(@),CHAR(_)))))"); children = node.GetChildren(); foreach (Node child in children) { if (child.GetNodeType() != Node.Type.TNAME) { throw new CloudMakefile.ParseException("A TNAME node is expected as the child node of a " + "TXMLPATH node."); } curNFA = EnsureLastNFA(entryList); state1 = curNFA.GetFinalState(); state2 = curNFA.AddState(); curNFA.AddTransition(state1, '{', state2); curNFA.SetFinalState(state2); ParseTreeNode(child, entryList); curNFA = EnsureLastNFA(entryList); state1 = curNFA.GetFinalState(); state2 = curNFA.AddState(); curNFA.AddTransition(state1, '}', state2); curNFA.SetFinalState(state2); } curNFA = EnsureLastNFA(entryList); chkState1 = curNFA.GetFinalState(); state1 = chkState1; state2 = curNFA.AddState(); curNFA.AddTransition(state1, '{', state2); curNFA.SetFinalState(state2); ParseTreeNode(lastNode, entryList); state1 = curNFA.GetFinalState(); state2 = curNFA.AddState(); chkState2 = state2; curNFA.AddTransition(state1, '}', state2); curNFA.SetFinalState(state2); curNFA.AddTransition(chkState1, Char.MinValue, chkState2); curNFA.AddTransition(chkState2, Char.MinValue, chkState1); break; case Node.Type.TNAME: children = node.GetChildren(); foreach (Node child in children) { if (child.GetNodeType() == Node.Type.TSEQUENCE) { ParseTreeNode(child, entryList); } else if (child.GetNodeType() == Node.Type.TVAR) { ParseTreeNode(child, entryList); } else { throw new CloudMakefile.ParseException("A TSEQUENCE or TVAR node is expected as the child " + "node of a TNAME node."); } } break; case Node.Type.TSEQUENCE: children = node.GetChildren(); foreach (Node child in children) { if ((child.GetNodeType() != Node.Type.TASTERISK) && (child.GetNodeType() != Node.Type.TPLUS) && (child.GetNodeType() != Node.Type.TQUESTIONMARK) && (child.GetNodeType() != Node.Type.TCHAR) && (child.GetNodeType() != Node.Type.TCHOICE) && (child.GetNodeType() != Node.Type.TNO_CHOICE) && (child.GetNodeType() != Node.Type.TUNION) && (child.GetNodeType() != Node.Type.TATOM)) { throw new CloudMakefile.ParseException("An appropriate node is expected as the child node " + "of a TSEQUENCE node."); } ParseTreeNode(child, entryList); } break; case Node.Type.TATOM: children = node.GetChildren(); if (children [0].GetNodeType() != Node.Type.TSEQUENCE) { throw new CloudMakefile.ParseException("A TSEQUENCE node is expected as the first node of a " + "TATOM node."); } ParseTreeNode(children [0], entryList); break; case Node.Type.TASTERISK: children = node.GetChildren(); if ((children [0].GetNodeType() != Node.Type.TCHAR) && (children [0].GetNodeType() != Node.Type.TCHOICE) && (children [0].GetNodeType() != Node.Type.TNO_CHOICE) && (children [0].GetNodeType() != Node.Type.TUNION) && (children [0].GetNodeType() != Node.Type.TATOM)) { throw new CloudMakefile.ParseException("An appropriate node is expected as the child node of a " + "TASTERISK node."); } curNFA = EnsureLastNFA(entryList); chkState1 = curNFA.GetFinalState(); ParseTreeNode(children [0], entryList); chkState2 = curNFA.GetFinalState(); curNFA.AddTransition(chkState1, Char.MinValue, chkState2); curNFA.AddTransition(chkState2, Char.MinValue, chkState1); break; case Node.Type.TPLUS: children = node.GetChildren(); if ((children [0].GetNodeType() != Node.Type.TCHAR) && (children [0].GetNodeType() != Node.Type.TCHOICE) && (children [0].GetNodeType() != Node.Type.TNO_CHOICE) && (children [0].GetNodeType() != Node.Type.TUNION) && (children [0].GetNodeType() != Node.Type.TATOM)) { throw new CloudMakefile.ParseException("An appropriate node is expected as the child node of a " + "TPLUS node."); } curNFA = EnsureLastNFA(entryList); chkState1 = curNFA.GetFinalState(); ParseTreeNode(children [0], entryList); chkState2 = curNFA.GetFinalState(); curNFA.AddTransition(chkState2, Char.MinValue, chkState1); break; case Node.Type.TQUESTIONMARK: children = node.GetChildren(); if ((children [0].GetNodeType() != Node.Type.TCHAR) && (children [0].GetNodeType() != Node.Type.TCHOICE) && (children [0].GetNodeType() != Node.Type.TNO_CHOICE) && (children [0].GetNodeType() != Node.Type.TUNION) && (children [0].GetNodeType() != Node.Type.TATOM)) { throw new CloudMakefile.ParseException("An appropriate node is expected as the child node of a " + "TQUESTIONMARK node."); } curNFA = EnsureLastNFA(entryList); chkState1 = curNFA.GetFinalState(); ParseTreeNode(children [0], entryList); chkState2 = curNFA.GetFinalState(); curNFA.AddTransition(chkState1, Char.MinValue, chkState2); break; case Node.Type.TCHOICE: alphabet = new HashSet <char> (); children = node.GetChildren(); foreach (Node child in children) { if ((child.GetNodeType() != Node.Type.TCHAR) && (child.GetNodeType() != Node.Type.TRANGE)) { throw new CloudMakefile.ParseException("A TCHAR and a TRANGE node is expected as the child " + "node of a TCHOICE node."); } if (child.GetNodeType() == Node.Type.TRANGE) { Tuple <char, char> range = child.GetRange(); for (char c = range.Item1; c <= range.Item2; c++) { alphabet.Add(c); } } else { alphabet.Add(child.GetChar()); } } curNFA = EnsureLastNFA(entryList); state1 = curNFA.GetFinalState(); state2 = curNFA.AddState(); foreach (char c in alphabet) { curNFA.AddTransition(state1, c, state2); } curNFA.SetFinalState(state2); break; case Node.Type.TNO_CHOICE: alphabet = new HashSet <char> (); for (char c = 'A'; c <= 'Z'; c++) { alphabet.Add(c); } for (char c = 'a'; c <= 'z'; c++) { alphabet.Add(c); } for (char c = '0'; c <= '9'; c++) { alphabet.Add(c); } alphabet.Add('_'); alphabet.Add('@'); children = node.GetChildren(); foreach (Node child in children) { if (child.GetNodeType() == Node.Type.TRANGE) { Tuple <char, char> range = child.GetRange(); for (char c = range.Item1; c <= range.Item2; c++) { alphabet.Remove(c); } } else { alphabet.Remove(child.GetChar()); } } state1 = curNFA.GetFinalState(); state2 = curNFA.AddState(); curNFA = EnsureLastNFA(entryList); foreach (char c in alphabet) { curNFA.AddTransition(state1, c, state2); } curNFA.SetFinalState(state2); break; case Node.Type.TUNION: children = node.GetChildren(); if (children [0].GetNodeType() != Node.Type.TSEQUENCE) { throw new CloudMakefile.ParseException("A TSEQUENCE node is expected as the first node of a " + "TUNION node."); } if (children [1].GetNodeType() != Node.Type.TSEQUENCE) { throw new CloudMakefile.ParseException("A TSEQUENCE node is expected as the second node of a " + "TUNION node."); } curNFA = EnsureLastNFA(entryList); state1 = curNFA.GetFinalState(); ParseTreeNode(children [0], entryList); chkState1 = curNFA.GetFinalState(); curNFA.SetFinalState(state1); ParseTreeNode(children [1], entryList); chkState2 = curNFA.GetFinalState(); state2 = curNFA.AddState(); curNFA.AddTransition(chkState1, Char.MinValue, state2); curNFA.AddTransition(chkState2, Char.MinValue, state2); curNFA.SetFinalState(state2); break; case Node.Type.TVAR: string varName = CloudMakefile.ParseString(node); entryList.Add(new Entry(varName)); break; case Node.Type.TCHAR: char character = node.GetChar(); curNFA = EnsureLastNFA(entryList); state1 = curNFA.GetFinalState(); state2 = curNFA.AddState(); curNFA.AddTransition(state1, character, state2); curNFA.SetFinalState(state2); break; default: throw new CloudMakefile.ParseException("Unhandled node type: " + node.GetNodeType().ToString()); } }
public CloudMakefile(CloudMakefile cloudMakefile, List <int> selectedPolicies) : this() { List <HashSet <int> > inputs = cloudMakefile.GetInputs(); List <HashSet <int> > outputs = cloudMakefile.GetOutputs(); List <DFA> dfas = cloudMakefile.GetDFAs(); List <string> policies = cloudMakefile.GetPolicies(); List <HashSet <int> > order = cloudMakefile.GetOrder(); Dictionary <int, int> dfaTransform = new Dictionary <int, int> (); int dfaCount = 0; int newDfaIndex; int count = -1; for (int newPolicyIndex = 0; newPolicyIndex < selectedPolicies.Count; newPolicyIndex++) { int oldPolicyIndex = selectedPolicies [newPolicyIndex]; _inputs.Add(new HashSet <int> ()); _outputs.Add(new HashSet <int> ()); foreach (int oldDfaIndex in inputs[oldPolicyIndex]) { if (!dfaTransform.ContainsKey(oldDfaIndex)) { dfaTransform [oldDfaIndex] = dfaCount; _dfas.Add(dfas [oldDfaIndex]); dfaCount++; _reverseInputs.Add(new HashSet <int> ()); _reverseOutputs.Add(new HashSet <int> ()); } newDfaIndex = dfaTransform [oldDfaIndex]; _inputs [newPolicyIndex].Add(newDfaIndex); _reverseInputs [newDfaIndex].Add(newPolicyIndex); } foreach (int oldDfaIndex in outputs[oldPolicyIndex]) { if (!dfaTransform.ContainsKey(oldDfaIndex)) { dfaTransform [oldDfaIndex] = dfaCount; _dfas.Add(dfas [oldDfaIndex]); dfaCount++; _reverseInputs.Add(new HashSet <int> ()); _reverseOutputs.Add(new HashSet <int> ()); } newDfaIndex = dfaTransform [oldDfaIndex]; _outputs [newPolicyIndex].Add(newDfaIndex); _reverseOutputs [newDfaIndex].Add(newPolicyIndex); } _policies.Add(policies [oldPolicyIndex]); } for (int i = 0; i < order.Count; i++) { bool created = false; foreach (int oldPolicyIndex in order[i]) { if (selectedPolicies.Contains(oldPolicyIndex)) { if (!created) { _order.Add(new HashSet <int> ()); created = true; count += 1; } _order [count].Add(selectedPolicies.IndexOf(oldPolicyIndex)); } } } }
static public List <CloudMakefile> SplitCloudMakefile(CloudMakefile initialCloudMakefile) { List <CloudMakefile> res = new List <CloudMakefile> (); List <List <int> > selectedPolicies = new List <List <int> > (); List <int> unexploredPolicies = new List <int> (); List <int> unexploredDfas = new List <int> (); List <int> unsearchedPolicies = new List <int> (); List <int> unsearchedDfas = new List <int> (); List <HashSet <int> > inputs = initialCloudMakefile.GetInputs(); List <HashSet <int> > outputs = initialCloudMakefile.GetOutputs(); List <HashSet <int> > reverseInputs = initialCloudMakefile.GetReverseInputs(); List <HashSet <int> > reverseOutputs = initialCloudMakefile.GetReverseOutputs(); int count = 0; bool explorePolicy; // Fill the unsearched fields. for (int i = 0; i < initialCloudMakefile.GetPolicies().Count; i++) { unsearchedPolicies.Add(i); } for (int i = 0; i < initialCloudMakefile.GetDFAs().Count; i++) { unsearchedDfas.Add(i); } // Divide CloudMakefile to independent pieces. while (unsearchedPolicies.Count != 0) { // Console.Out.WriteLine ("Unsearched Policies"); // for (int i = 0; i < unsearchedPolicies.Count; i++) // Console.Out.WriteLine (unsearchedPolicies [i].ToString ()); // Console.Out.WriteLine ("Unsearched DFAs"); // for (int i = 0; i < unsearchedDfas.Count; i++) // Console.Out.WriteLine (unsearchedDfas [i].ToString ()); unexploredPolicies.Add(unsearchedPolicies [0]); unsearchedPolicies.RemoveAt(0); explorePolicy = true; selectedPolicies.Add(new List <int> ()); while ((unexploredPolicies.Count != 0) || (unexploredDfas.Count != 0)) { if (explorePolicy) { while (unexploredPolicies.Count != 0) { int policyIndex = unexploredPolicies [0]; /* * Console.Out.WriteLine ("Selected Policy: " + policyIndex); * Console.Out.WriteLine ("Inputs:" + String.Join (" ", inputs [policyIndex])); * Console.Out.WriteLine ("Outputs:" + String.Join (" ", outputs [policyIndex])); */ foreach (int dfaIndex in inputs[policyIndex]) { if (unsearchedDfas.Contains(dfaIndex)) { unexploredDfas.Add(dfaIndex); unsearchedDfas.Remove(dfaIndex); } } foreach (int dfaIndex in outputs[policyIndex]) { if (unsearchedDfas.Contains(dfaIndex)) { unexploredDfas.Add(dfaIndex); unsearchedDfas.Remove(dfaIndex); } } unexploredPolicies.RemoveAt(0); selectedPolicies [count].Add(policyIndex); } } else { while (unexploredDfas.Count != 0) { int dfaIndex = unexploredDfas [0]; /* * Console.Out.WriteLine ("Selected Index: " + dfaIndex); * Console.Out.WriteLine ("Reverse Inputs:" + String.Join (" ", reverseInputs [dfaIndex])); * Console.Out.WriteLine ("Reverse Outputs:" + String.Join (" ", reverseOutputs [dfaIndex])); */ foreach (int policyIndex in reverseInputs[dfaIndex]) { if (unsearchedPolicies.Contains(policyIndex)) { unexploredPolicies.Add(policyIndex); unsearchedPolicies.Remove(policyIndex); } } foreach (int policyIndex in reverseOutputs[dfaIndex]) { if (unsearchedPolicies.Contains(policyIndex)) { unexploredPolicies.Add(policyIndex); unsearchedPolicies.Remove(policyIndex); } } unexploredDfas.RemoveAt(0); } } explorePolicy = !explorePolicy; } count++; } // Print Selected Policies. /*for (int i = 0; i < selectedPolicies.Count; i++) { * Console.Out.Write ("[ "); * selectedPolicies [i].Sort (); * for (int j = 0; j < selectedPolicies[i].Count; j++) * Console.Out.Write (selectedPolicies [i] [j].ToString () + " "); * Console.Out.WriteLine ("]"); * }*/ // Create the CloudMakefiles. for (int i = 0; i < selectedPolicies.Count; i++) { res.Add(new CloudMakefile(initialCloudMakefile, selectedPolicies [i])); } return(res); }