public Flow(
            Endpoint c,
            Endpoint h,
            string inputRecord,
            string[] inputTokens,
            int inputTokensLastHeaderIndex,
            OktofsRateController rateController)
        {
            if (c == null && h == null)
                throw new ArgumentOutOfRangeException(String.Format("Flow: both endpoints cannot be null."));

            this.flowId = newFlowId++;
            this.vmName = (c != null ? c.SidOrAccount.ToLower() : h.SidOrAccount.ToLower());
            this.hypervName = (c != null ? c.FilterServer.ToLower() : h.HyperVserver.ToLower());
            this.shareName = (c != null ? c.ShareOrVolume.ToLower() : null);
            this.storageServerName = (h != null ? h.FilterServer.ToLower() : null);
            this.volumeName = (h != null ? h.ShareOrVolume.ToLower() : null);
            this.endpointC = c;
            this.endpointH = h;
            this.inputRecord = inputRecord;
            this.inputTokens = inputTokens;
            this.inputTokensLastHeaderIndex = inputTokensLastHeaderIndex;

            if (String.IsNullOrEmpty(vmName) || String.IsNullOrWhiteSpace(vmName))
                throw new ArgumentOutOfRangeException(String.Format("Invalid arg vmName={0}", vmName));
            if (String.IsNullOrEmpty(hypervName) || String.IsNullOrWhiteSpace(hypervName))
                throw new ArgumentOutOfRangeException(String.Format("Invalid arg hypervName={0}", hypervName));
            if (endpointC != null && (String.IsNullOrEmpty(shareName) || String.IsNullOrWhiteSpace(shareName)))
                throw new ArgumentOutOfRangeException(String.Format("Invalid arg shareName={0}", shareName));
            if (endpointH != null && (String.IsNullOrEmpty(storageServerName) || String.IsNullOrWhiteSpace(storageServerName)))
                throw new ArgumentOutOfRangeException(String.Format("Invalid arg storageServerName={0}", storageServerName));
            if (endpointH != null && (String.IsNullOrEmpty(volumeName) || String.IsNullOrWhiteSpace(volumeName)))
                throw new ArgumentOutOfRangeException(String.Format("Invalid arg volumeName={0}", volumeName));
            if (inputTokensLastHeaderIndex < 4)
                throw new ArgumentOutOfRangeException(String.Format("Invalid arg inputTokensLastHeaderIndex too small {0}", inputTokensLastHeaderIndex));
        }
        /// <summary>
        /// Parses config file and returns list of Enpoints.
        /// </summary>
        /// <param name="fileName">Name of input file.</param>
        /// <param name="validTags">Acceptable input record types.</param>
        /// <returns>List containing one Endpoint for each input record.</returns>
        public List<Endpoint> ParseConfigFile(string fileName, string[] validTags)
        {
            List<Endpoint> listEndpoints = null;
            StreamReader streamIn = new StreamReader(fileName);
            string inputRecord;
            string[] separators = new string[] { " ", "\t" };

            ValidateState(RateControllerState.Init, "ParseConfigFile");
            while ((inputRecord = streamIn.ReadLine()) != null)
            {
                string[] inputTokens = inputRecord.Split(separators, StringSplitOptions.RemoveEmptyEntries);
                if (inputTokens.Length == 0)
                    continue;
                else if (inputTokens[0].StartsWith(@"#") || inputTokens[0].StartsWith(@"//"))
                    continue;
                else if (inputTokens[0].ToLower().Equals(Parameters.VOLNAME_ALIAS_REC_HEADER))
                    continue;
                else if (inputTokens.Length > 4 &&
                    IsValidTag(inputTokens[0], validTags) &&
                    !inputTokens[0].StartsWith("-") &&
                    (inputTokens[0].ToLower().Contains("-vm-share-vol") ||
                     inputTokens[0].ToLower().Contains("-vm-file-vol")))
                {
                    //
                    // Parse records.
                    // Each such record generates a Flow containing one or more queue : e.g. one at C and one at H.
                    //
                    string tag = inputTokens[0].ToLower();
                    string StageIds = tag.Substring(0, tag.IndexOf("-"));
                    bool isOktofsC = StageIds.Contains("c");
                    bool isOktofsH = StageIds.Contains("h");
                    bool isIoFlowD = StageIds.Contains("d");

                    Endpoint endpointC = null;
                    Endpoint endpointH = null;
                    if (listEndpoints == null)
                        listEndpoints = new List<Endpoint>();
                    string vmName = inputTokens[1];
                    string hypervName = inputTokens[2];
                    string shareName = inputTokens[3];
                    string volName = inputTokens[4];
                    // Windows keeps breaking our conf files by changing the volume names at H.
                    // Provide an optional alias func based on share name to avoid admin chaos.
                    volName = GetVolumeNameFromShareName(shareName, volName);

                    if (!StageIds.Replace("c", "").Replace("h", "").Replace("d", "").Equals(""))
                    {
                        streamIn.Close();
                        streamIn = null;
                        throw new ApplicationException(String.Format("input rec illegal prefix {0}", tag));
                    }
                    if (vmName.Length > Parameters.OKTO_VM_NAME_MAX_CHARS)
                    {
                        streamIn.Close();
                        streamIn = null;
                        throw new ApplicationException(String.Format("VmName too long {0}", vmName));
                    }
                    if (shareName.Length > Parameters.OKTO_SHARE_NAME_MAX_CHARS)
                    {
                        streamIn.Close();
                        streamIn = null;
                        throw new ApplicationException(String.Format("ShareName too long {0}", shareName));
                    }
                    if (volName.Length > Parameters.OKTO_SHARE_NAME_MAX_CHARS)
                    {
                        streamIn.Close();
                        streamIn = null;
                        throw new ApplicationException(String.Format("VolumeName too long {0}", volName));
                    }

                    string storageServer = GetHostNameFromShareName(shareName);
                    const int LastHeaderIndex = 4; // Index of last std header field in "ch-vm-share-vol" record.

                    if (isOktofsC || isIoFlowD)
                    {
                        endpointC = new Endpoint(tag, hypervName, hypervName, vmName, shareName, NextEndpointKey++);
                        listEndpoints.Add(endpointC);
                    }
                    if (isOktofsH)
                    {
                        endpointH = new Endpoint(tag, storageServer, hypervName, vmName, volName, NextEndpointKey++);
                        listEndpoints.Add(endpointH);
                    }
                    Flow flow = new Flow(endpointC, endpointH, inputRecord, inputTokens, LastHeaderIndex, this);
                    if (ListFlows == null)
                        ListFlows = new List<Flow>();
                    ListFlows.Add(flow);

                }
                else if (IsValidTag(inputTokens[0], validTags))
                {
                    // Silently ignore tags that we don't understand if caller said they are valid.
                }
                else
                {
                    string msg = String.Format("Illegal config file line: {0}", inputRecord);
                    streamIn.Close();
                    streamIn = null;
                    throw new ApplicationException(msg);
                }
            }
            streamIn.Close();
            //
            // Plumb index values into ordered list of Endpoints.
            //
            if (listEndpoints != null)
                for (int i = 0; i < listEndpoints.Count; i++)
                    listEndpoints[i].SetIndex(i);

            return listEndpoints;
        }
 public static Endpoint[] ArrayEndpoints(SortedList<UInt64, Endpoint> listEndpoints)
 {
     Endpoint[] arrayEndpoints = new Endpoint[listEndpoints.Count];
     int i = 0;
     foreach (Endpoint endpoint in listEndpoints.Values)
         arrayEndpoints[i++] = endpoint;
     return arrayEndpoints;
 }
Exemple #4
0
        private OktoQueue queue = null; // Queue attached to this entry.

        #endregion Fields

        #region Constructors

        internal RAP(
            Endpoint locEndpointDetails,
            Endpoint remEndpointDetails)
        {
            this.locEndpointDetails = locEndpointDetails;
        }