public void Setup()
 {
     _fixture            = new Fixture();
     _provider           = new Mock <IMinilockProvider>();
     _clusterInformation = _fixture.Create <ClusterInformation>();
     _sut = new MinilockClusterStatusTracker(_provider.Object, _clusterInformation);
 }
        public void It_Should_Throw_ArgumentNullException_When_HostName_Is_Null()
        {
            //Arrange
            var clusterName = _fixture.Create <string>();
            var hostName    = string.Empty;

            //Act
            Assert.Throws <ArgumentNullException>(() => _sut = new ClusterInformation(clusterName, hostName))
            .ParamName.Should().Be("hostName");
        }
Esempio n. 3
0
 public override int GetHashCode()
 {
     unchecked
     {
         int hashCode = (Url != null ? Url.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (ClusterInformation != null ? ClusterInformation.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (Credentials != null ? Credentials.GetHashCode() : 0);
         return(hashCode);
     }
 }
Esempio n. 4
0
        public void FixtureSetUp()
        {
            ClientSideTypeDescription clientTypeDescription = ClientSideTypeDescription.RegisterType(typeof(TradeLike));

            var sd = new ServerDescriptionResponse {
                KnownTypesByFullName = { { clientTypeDescription.FullTypeName, clientTypeDescription.AsTypeDescription } }
            };

            _serverDescription = new ClusterInformation(new[] { sd });
        }
        public void It_Should_Assign_ClusterInformation_When_Initialized_Successfully()
        {
            //Arrange
            var clusterName = _fixture.Create <string>();
            var hostName    = _fixture.Create <string>();

            //Act
            _sut = new ClusterInformation(clusterName, hostName);

            //Assert
            _sut.ClusterName.Should().Be(clusterName);
            _sut.HostName.Should().Be(hostName);
        }
Esempio n. 6
0
 //Dispose method
 public void Dispose()
 {
     if (GlassCollection != null)
     {
         GlassCollection.Clear();
     }
     if (BfeedCollection != null)
     {
         BfeedCollection.Clear();
     }
     if (AuditCollection != null)
     {
         AuditCollection.Clear();
     }
     if (WineCollection != null)
     {
         WineCollection.Clear();
     }
     if (BreastCancerCollection != null)
     {
         BreastCancerCollection.Clear();
     }
     if (IrisCollection != null)
     {
         IrisCollection.Clear();
     }
     if (TitanicCollection != null)
     {
         TitanicCollection.Clear();
     }
     if (RecommendedGroceries != null)
     {
         RecommendedGroceries.Clear();
     }
     if (ClusterInformation != null)
     {
         ClusterInformation.Clear();
     }
     if (PMML != null)
     {
         PMML = null;
     }
     if (RCode != null)
     {
         RCode = null;
     }
     if (CSharpCode != null)
     {
         CSharpCode = null;
     }
 }
        public void Given_ClusterInformation_It_Should_Create_Cluster_StatusTracker()
        {
            //Arrange

            var clusterName        = _fixture.Create <string>();
            var hostName           = _fixture.Create <string>();
            var clusterInformation = new ClusterInformation(clusterName, hostName);

            //Act
            var result = _sut.CreateStatusTracker(clusterInformation);

            //Assert
            result.Should().NotBeNull();
            result.ClusterInformation.Should().BeEquivalentTo(clusterInformation);
            result.ClusterInformation.Should().NotBeSameAs(clusterInformation);
        }
 public ReplicationDocumentWithClusterInformation()
 {
     ClusterInformation = new ClusterInformation(false, false);
     ClusterCommitIndex = -1;
     Term = -1;
 }
Esempio n. 9
0
 /// <summary>
 /// Load the cluster info together with the http call information.
 /// </summary>
 /// <param name="checkSuccessful"></param>
 /// <param name="statusCode"></param>
 /// <param name="clusterInformation"></param>
 public ClusterHealthStatus(bool checkSuccessful, HttpStatusCode statusCode, ClusterInformation clusterInformation)
 {
     CheckSuccessful    = checkSuccessful;
     StatusCode         = statusCode;
     ClusterInformation = clusterInformation;
 }
Esempio n. 10
0
 public OperationMetadata(OperationMetadata operationMetadata)
 {
     Url                = operationMetadata.Url;
     Credentials        = new OperationCredentials(operationMetadata.Credentials.ApiKey, operationMetadata.Credentials.Credentials);
     ClusterInformation = new ClusterInformation(operationMetadata.ClusterInformation.IsInCluster, operationMetadata.ClusterInformation.IsLeader);
 }
Esempio n. 11
0
 public OperationMetadata(string url, OperationCredentials credentials, ClusterInformation clusterInformation)
 {
     Url                = url;
     Credentials        = credentials != null ? new OperationCredentials(credentials.ApiKey, credentials.Credentials) : new OperationCredentials(null, null);
     ClusterInformation = clusterInformation != null ? new ClusterInformation(clusterInformation.IsInCluster, clusterInformation.IsLeader) : ClusterInformation.NotInCluster;
 }
Esempio n. 12
0
        static void Main(string[] args)
        {
            // by default conect to the local server
            string server = "localhost";

            if (args.Length > 0)
            {
                server = args[0];
            }


            // default port
            int port = 4848;

            if (args.Length > 1)
            {
                if (int.TryParse(args[1], out var customPort))
                {
                    port = customPort;
                }
            }



            var          channel = new TcpClientChannel(new TcpClientPool(1, 1, server, port));
            ICacheClient client  = new CacheClient {
                Channel = channel
            };


            Logger.CommandLogger = new ConsoleLogger();

            Logger.Write("connecting to server {0} on port {1}", server, port);

            try
            {
                ClusterInformation serverDesc = null;

                try
                {
                    serverDesc = client.GetClusterInformation();
                }
                catch (Exception)
                {
                    Logger.WriteEror("Not connected to server: Only CONNECT and HELP commands are available");
                }


                //Profiler.Logger = new ProfileOutput(Console.Out);
                CommandLineParser parser = new CommandLineParser(serverDesc);
                Logger.Write("Type HELP for command list. Advanced autocompletion is also available");

                ConsoleExt.SetLine(">>");

                var running             = true;
                var cyclingAutoComplete = new CyclingAutoComplete {
                    KnownTypes = serverDesc?.Schema.ToList()
                };
                while (running)
                {
                    var result = ConsoleExt.ReadKey();
                    switch (result.Key)
                    {
                    case ConsoleKey.Enter:
                        var line = result.LineBeforeKeyPress.Line;
                        line = line.TrimStart('>');
                        var cmd = parser.Parse(line);
                        if (cmd.Success)
                        {
                            if (cmd.CmdType != CommandType.Exit)
                            {
                                var title = Console.Title;
                                Console.Title = " WORKING...";
                                client        = cmd.TryExecute(client);
                                Console.Title = title;

                                // table definitions may have changed by command execution (connect, import, recreate)
                                // or by external action

                                try
                                {
                                    serverDesc = client.GetClusterInformation();
                                    // if the connection changed reinitialize the autocomplete with the new schema
                                    cyclingAutoComplete = new CyclingAutoComplete {
                                        KnownTypes = serverDesc?.Schema.ToList()
                                    };
                                    parser = new CommandLineParser(serverDesc);
                                }
                                catch (Exception)
                                {
                                    Logger.WriteEror("Not connected to server: Only CONNECT and HELP commands are available");
                                }
                            }
                            else
                            {
                                running = false;
                            }
                        }
                        else
                        {
                            Logger.WriteEror("invalid command");
                        }

                        ConsoleExt.SetLine(">>");

                        break;

                    case ConsoleKey.Tab:
                        var shiftPressed     = (result.Modifiers & ConsoleModifiers.Shift) != 0;
                        var cyclingDirection = shiftPressed ? CyclingDirections.Backward : CyclingDirections.Forward;
                        line = result.LineBeforeKeyPress.LineBeforeCursor.TrimStart('>');

                        var autoCompletedLine =
                            cyclingAutoComplete.AutoComplete(line, cyclingDirection);

                        ConsoleExt.SetLine(">>" + autoCompletedLine);
                        break;
                    }
                }

                Logger.Flush();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Esempio n. 13
0
 public CommandLineParser(ClusterInformation desc)
 {
     _knownTypes = desc?.Schema.ToDictionary(t => t.FullTypeName);
 }
Esempio n. 14
0
 protected bool Equals(ClusterInformation other)
 {
     return(IsInCluster.Equals(other.IsInCluster) &&
            IsLeader.Equals(other.IsLeader) &&
            WithClusterFailoverHeader.Equals(other.WithClusterFailoverHeader));
 }
        //*************************************************************************
        //  Method: ReadClusterTable()
        //
        /// <summary>
        /// Reads the cluster table.
        /// </summary>
        ///
        /// <param name="oClusterTable">
        /// The cluster table.
        /// </param>
        ///
        /// <param name="oReadWorkbookContext">
        /// Provides access to objects needed for converting an Excel workbook to a
        /// NodeXL graph.
        /// </param>
        ///
        /// <returns>
        /// A dictionary.  The key is the cluster name and the value is a
        /// ClusterInformation object for the cluster.
        /// </returns>
        //*************************************************************************
        protected Dictionary<String, ClusterInformation> ReadClusterTable(
            ListObject oClusterTable,
            ReadWorkbookContext oReadWorkbookContext
            )
        {
            Debug.Assert(oClusterTable != null);
            Debug.Assert(oReadWorkbookContext != null);
            AssertValid();

            Dictionary<String, ClusterInformation> oClusterNameDictionary =
            new Dictionary<String, ClusterInformation>();

            ColorConverter2 oColorConverter2 =
            oReadWorkbookContext.ColorConverter2;

            ExcelTableReader oExcelTableReader =
            new ExcelTableReader(oClusterTable);

            foreach ( ExcelTableReader.ExcelTableRow oRow in
            oExcelTableReader.GetRows() )
            {
            // Get the cluster information.

            String sClusterName;
            Color oVertexColor;
            VertexShape eVertexShape;

            if (
                !oRow.TryGetNonEmptyStringFromCell(
                    ClusterTableColumnNames.Name, out sClusterName)
                ||
                !TryGetColor(oRow, ClusterTableColumnNames.VertexColor,
                    oColorConverter2, out oVertexColor)
                ||
                !TryGetVertexShape(oRow, ClusterTableColumnNames.VertexShape,
                    out eVertexShape)
                )
            {
                continue;
            }

            // Add the cluster information to the dictionary.

            ClusterInformation oClusterInformation =
                new ClusterInformation();

            oClusterInformation.VertexColor = oVertexColor;
            oClusterInformation.VertexShape = eVertexShape;

            try
            {
                oClusterNameDictionary.Add(
                    sClusterName, oClusterInformation);
            }
            catch (ArgumentException)
            {
                Range oInvalidCell = oRow.GetRangeForCell(
                    ClusterTableColumnNames.Name);

                OnWorkbookFormatError( String.Format(

                    "The cell {0} contains a duplicate cluster name.  There"
                    + " can't be two rows with the same cluster name."
                    ,
                    ExcelUtil.GetRangeAddress(oInvalidCell)
                    ),

                    oInvalidCell
                );
            }
            }

            return (oClusterNameDictionary);
        }
Esempio n. 16
0
        public OperationMetadata(string url, string username = null, string password = null, string domain = null, string apiKey = null, ClusterInformation clusterInformation = null)
        {
            Url = url;

            ICredentials credentials = null;

            if (!string.IsNullOrEmpty(username))
            {
                credentials = new NetworkCredential(username, password ?? string.Empty, domain ?? string.Empty);
            }

            Credentials        = new OperationCredentials(apiKey, credentials);
            ClusterInformation = clusterInformation != null ? new ClusterInformation(clusterInformation.IsInCluster, clusterInformation.IsLeader) : ClusterInformation.NotInCluster;
        }
        private static OperationMetadata ConvertReplicationDestinationToOperationMetadata(ReplicationDestination destination, ClusterInformation clusterInformation)
        {
            var url = string.IsNullOrEmpty(destination.ClientVisibleUrl) ? destination.Url : destination.ClientVisibleUrl;

            if (string.IsNullOrEmpty(url) || destination.CanBeFailover() == false)
            {
                return(null);
            }

            if (string.IsNullOrEmpty(destination.Database))
            {
                return(new OperationMetadata(url, destination.Username, destination.Password, destination.Domain, destination.ApiKey, clusterInformation));
            }

            return(new OperationMetadata(MultiDatabase.GetRootDatabaseUrl(url).ForDatabase(destination.Database), destination.Username, destination.Password, destination.Domain, destination.ApiKey, clusterInformation));
        }
Esempio n. 18
0
        ReadClusterTable
        (
            ListObject oClusterTable,
            ReadWorkbookContext oReadWorkbookContext
        )
        {
            Debug.Assert(oClusterTable != null);
            Debug.Assert(oReadWorkbookContext != null);
            AssertValid();

            Dictionary <String, ClusterInformation> oClusterNameDictionary =
                new Dictionary <String, ClusterInformation>();

            ColorConverter2 oColorConverter2 =
                oReadWorkbookContext.ColorConverter2;

            ExcelTableReader oExcelTableReader =
                new ExcelTableReader(oClusterTable);

            foreach (ExcelTableReader.ExcelTableRow oRow in
                     oExcelTableReader.GetRows())
            {
                // Get the cluster information.

                String      sClusterName;
                Color       oVertexColor;
                VertexShape eVertexShape;

                if (
                    !oRow.TryGetNonEmptyStringFromCell(
                        ClusterTableColumnNames.Name, out sClusterName)
                    ||
                    !TryGetColor(oRow, ClusterTableColumnNames.VertexColor,
                                 oColorConverter2, out oVertexColor)
                    ||
                    !TryGetVertexShape(oRow, ClusterTableColumnNames.VertexShape,
                                       out eVertexShape)
                    )
                {
                    continue;
                }

                // Add the cluster information to the dictionary.

                ClusterInformation oClusterInformation =
                    new ClusterInformation();

                oClusterInformation.VertexColor = oVertexColor;
                oClusterInformation.VertexShape = eVertexShape;

                try
                {
                    oClusterNameDictionary.Add(
                        sClusterName, oClusterInformation);
                }
                catch (ArgumentException)
                {
                    Range oInvalidCell = oRow.GetRangeForCell(
                        ClusterTableColumnNames.Name);

                    OnWorkbookFormatError(String.Format(

                                              "The cell {0} contains a duplicate cluster name.  There"
                                              + " can't be two rows with the same cluster name."
                                              ,
                                              ExcelUtil.GetRangeAddress(oInvalidCell)
                                              ),

                                          oInvalidCell
                                          );
                }
            }

            return(oClusterNameDictionary);
        }