public CloudWorkflow(string computeName = "csharpcompute-2021-02-17-1", string profile = "default", int maxAttempts = 20, int sleepTime = 60000)
        {
            // Loads data from ~/.rai/config (rai cloud configuration)
            IniData ini = Config.LoadDotRaiConfig();

            this.MaxAttempts = maxAttempts;
            this.SleepTime   = sleepTime;
            this.ComputeName = computeName;

            this.MngtConn = new ManagementConnection(
                creds: RAICredentials.FromFile(profile: profile),
                scheme: "https",
                host: Config.RaiGetHost(ini, profile),
                port: 443,
                verifySSL: false
                );

            this.MngtConn.DebugLevel = 1;

            this.CloudConn = new CloudConnection(
                dbname: computeName,
                managementConn: this.MngtConn,
                computeName: computeName
                );

            this.CloudConn.DebugLevel = 1;
        }
Example #2
0
        /// <summary>
        /// Creates a new DbaWmConnectionParameter based on an input-name
        /// </summary>
        /// <param name="ComputerName">The name of the computer the connection is stored for.</param>
        public DbaCmConnectionParameter(string ComputerName)
        {
            InputObject = ComputerName;
            if (!Utility.Validation.IsValidComputerTarget(ComputerName))
            {
                Success = false;
                return;
            }


            bool test = false;

            try { test = ConnectionHost.Connections[ComputerName.ToLower()] != null; }
            catch { }

            if (test)
            {
                Connection = ConnectionHost.Connections[ComputerName.ToLower()];
            }

            else
            {
                Connection = new ManagementConnection(ComputerName.ToLower());
                ConnectionHost.Connections[Connection.ComputerName] = Connection;
            }

            Success = true;
        }
Example #3
0
        private void BootstrapEmbeddedEventStore()
        {
            Server = global::EventStore.ClientAPI.Embedded.EmbeddedVNodeBuilder
                     .AsSingleNode()
                     .RunInMemory()
                     .RunProjections(global::EventStore.Common.Options.ProjectionType.All)
                     .OnDefaultEndpoints()
                     .StartStandardProjections()
                     .AddExternalHttpPrefix("http://*:2113/")
                     .Build();

            var startedEvent = new ManualResetEventSlim(false);

            Server.MainBus.Subscribe(
                new global::EventStore.Core.Bus.AdHocHandler <global::EventStore.Core.Messages.UserManagementMessage.UserManagementServiceInitialized>(m => startedEvent.Set()));

            Server.Start();

            if (!startedEvent.Wait(60000))
            {
                throw new TimeoutException("Embedded Event Store has not started in 60 seconds.");
            }

            var connectionSettings = global::EventStore.ClientAPI.ConnectionSettings
                                     .Create()
                                     .SetDefaultUserCredentials(new global::EventStore.ClientAPI.SystemData.UserCredentials("admin", "changeit"))
                                     .Build();

            ManagementConnection = global::EventStore.ClientAPI.Embedded.EmbeddedEventStoreConnection.Create(Server, connectionSettings);
            ManagementConnection.ConnectAsync().GetAwaiter().GetResult();
        }
        private async Task ThenTheStoredEventStreamIsNamedByAggregateRootIdWithEvelynPrefix()
        {
            var expectedStreamName = $"evelyn-{_aggregateId}";
            var result             = await ManagementConnection.ReadStreamEventsForwardAsync(expectedStreamName, 0, 2000, false);

            result.Events.Should().HaveCount(EventsAddedToStore.Count);
        }
Example #5
0
        /// <summary>
        /// Creates a new DbaWmConnectionParameter based on an already existing connection object.
        /// </summary>
        /// <param name="Connection">The connection to accept</param>
        public DbaCmConnectionParameter(ManagementConnection Connection)
        {
            InputObject = Connection;

            this.Connection = Connection;

            Success = true;
        }
        private ComputeInfoProtocol GetComputeByName(ManagementConnection connection, string computeName)
        {
            var filters = new RAIComputeFilters(null, name: new List <string> {
                computeName, "random"
            }, null, null);
            var computes = connection.ListComputes(filters);

            return(computes.FirstOrDefault());
        }
Example #7
0
        private void TearDownEmbeddedEventStore()
        {
            ManagementConnection?.Close();

            if (!Server.Stop(TimeSpan.FromSeconds(30), true, true))
            {
                throw new Exception("Failed to stop embedded eventstore server");
            }
        }
Example #8
0
        /// <summary>
        /// Tries to convert a generic input object into a true input.
        /// </summary>
        /// <param name="Input">Any damn object in the world</param>
        public DbaCmConnectionParameter(object Input)
        {
            InputObject = Input;
            PSObject tempInput = new PSObject(Input);
            string   typeName  = "";

            try { typeName = tempInput.TypeNames[0].ToLower(); }
            catch
            {
                Success = false;
                return;
            }

            switch (typeName)
            {
            case "Sqlcollaborative.Dbatools.connection.managementconnection":
                try
                {
                    ManagementConnection con = new ManagementConnection();
                    con.ComputerName = (string)tempInput.Properties["ComputerName"].Value;

                    con.CimRM                  = (ManagementConnectionProtocolState)tempInput.Properties["CimRM"].Value;
                    con.LastCimRM              = (DateTime)tempInput.Properties["LastCimRM"].Value;
                    con.CimDCOM                = (ManagementConnectionProtocolState)tempInput.Properties["CimDCOM"].Value;
                    con.LastCimDCOM            = (DateTime)tempInput.Properties["LastCimDCOM"].Value;
                    con.Wmi                    = (ManagementConnectionProtocolState)tempInput.Properties["Wmi"].Value;
                    con.LastWmi                = (DateTime)tempInput.Properties["LastWmi"].Value;
                    con.PowerShellRemoting     = (ManagementConnectionProtocolState)tempInput.Properties["PowerShellRemoting"].Value;
                    con.LastPowerShellRemoting = (DateTime)tempInput.Properties["LastPowerShellRemoting"].Value;

                    con.Credentials = (PSCredential)tempInput.Properties["Credentials"].Value;
                    con.OverrideExplicitCredential = (bool)tempInput.Properties["OverrideExplicitCredential"].Value;
                    con.KnownBadCredentials        = (List <PSCredential>)tempInput.Properties["KnownBadCredentials"].Value;
                    con.WindowsCredentialsAreBad   = (bool)tempInput.Properties["WindowsCredentialsAreBad"].Value;
                    con.UseWindowsCredentials      = (bool)tempInput.Properties["UseWindowsCredentials"].Value;

                    con.DisableBadCredentialCache     = (bool)tempInput.Properties["DisableBadCredentialCache"].Value;
                    con.DisableCimPersistence         = (bool)tempInput.Properties["DisableCimPersistence"].Value;
                    con.DisableCredentialAutoRegister = (bool)tempInput.Properties["DisableCredentialAutoRegister"].Value;
                    con.EnableCredentialFailover      = (bool)tempInput.Properties["EnableCredentialFailover"].Value;
                }
                catch
                {
                    Success = false;
                }
                break;

            default:
                Success = false;
                break;
            }
        }
        /*
         * Helpers
         *
         */

        private bool WaitForCompute(ManagementConnection connection, string computeName)
        {
            for (var i = 0; i < this.MaxAttempts; i++)
            {
                var compute = GetComputeByName(connection, computeName);
                Console.WriteLine($"==> Compute {computeName} state: {compute.State}");
                if ("PROVISIONED".Equals(compute.State))
                {
                    return(true);
                }
                Thread.Sleep(this.SleepTime);
            }
            return(false);
        }
        private async Task <global::EventStore.ClientAPI.StreamEventsSlice> GetProjectAggregateRootStream(Guid id)
        {
            var expectedStreamName = $"evelyn-{_aggregateId}";

            return(await ManagementConnection.ReadStreamEventsForwardAsync(expectedStreamName, 0, 2000, false));
        }