/// <summary>
        /// Initializes a new instance of the <see cref="BackupConfiguration"/> class with
        /// the specified values.
        /// </summary>
        /// <param name="instanceId">The database instance ID. This is obtained from <see cref="DatabaseInstance.Id">DatabaseInstance.Id</see>.</param>
        /// <param name="name">The name of the backup.</param>
        /// <param name="description">The optional description of the backup.</param>
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="instanceId"/> is <see langword="null"/>.
        /// <para>-or-</para>
        /// <para>If <paramref name="name"/> is <see langword="null"/>.</para>
        /// </exception>
        /// <exception cref="ArgumentException">If <paramref name="name"/> is empty.</exception>
        public BackupConfiguration(DatabaseInstanceId instanceId, string name, string description)
        {
            if (instanceId == null)
                throw new ArgumentNullException("instanceId");
            if (name == null)
                throw new ArgumentNullException("name");
            if (string.IsNullOrEmpty(name))
                throw new ArgumentException("name cannot be empty");

            _instanceId = instanceId;
            _name = name;
            _description = description;
        }
        /// <summary>
        /// Gets a collection of all database instances.
        /// </summary>
        /// <remarks>
        /// <note>
        /// This is a <see href="http://docs.rackspace.com/cdb/api/v1.0/cdb-devguide/content/pagination.html">paginated collection</see>.
        /// </note>
        /// </remarks>
        /// <param name="service">The database service instance.</param>
        /// <param name="marker">The database instance ID of the last <see cref="DatabaseInstance"/> in the previous page of results. This parameter is used for <see href="http://docs.rackspace.com/cdb/api/v1.0/cdb-devguide/content/pagination.html">pagination</see>. If the value is <see langword="null"/>, the list starts at the beginning.</param>
        /// <param name="limit">The maximum number of <see cref="DatabaseInstance"/> objects to return in a single page of results. This parameter is used for <see href="http://docs.rackspace.com/cdb/api/v1.0/cdb-devguide/content/pagination.html">pagination</see>. If the value is <see langword="null"/>, a provider-specific default value is used.</param>
        /// <returns>
        /// A collection of <see cref="DatabaseInstance"/> objects describing the database instances.
        /// </returns>
        /// <exception cref="ArgumentNullException">If <paramref name="service"/> is <see langword="null"/>.</exception>
        /// <exception cref="ArgumentOutOfRangeException">If <paramref name="limit"/> is less than or equal to 0.</exception>
        /// <exception cref="WebException">If the REST request does not return successfully.</exception>
        /// <seealso href="http://docs.rackspace.com/cdb/api/v1.0/cdb-devguide/content/GET_getInstance__version___accountId__instances_.html">List All Database Instances (Rackspace Cloud Databases Developer Guide - API v1.0)</seealso>
        /// <seealso href="http://docs.rackspace.com/cdb/api/v1.0/cdb-devguide/content/pagination.html">Pagination (Rackspace Cloud Databases Developer Guide - API v1.0)</seealso>
        public static ReadOnlyCollectionPage<DatabaseInstance> ListDatabaseInstances(this IDatabaseService service, DatabaseInstanceId marker, int? limit)
        {
            if (service == null)
                throw new ArgumentNullException("service");

            try
            {
                return service.ListDatabaseInstancesAsync(marker, limit, CancellationToken.None).Result;
            }
            catch (AggregateException ex)
            {
                ReadOnlyCollection<Exception> innerExceptions = ex.Flatten().InnerExceptions;
                if (innerExceptions.Count == 1)
                    throw innerExceptions[0];

                throw;
            }
        }
Exemple #3
0
        public async Task <DatabaseInstance> RegisterAsync(RegisterDatabaseInstanceRequest request)
        {
            Ensure.NotNull(request, nameof(request));

            var instanceId = await DatabaseInstanceId.NextAsync(db.Context, request.DatabaseId);

            var instance = new DatabaseInstance(
                id: instanceId,
                clusterId: request.ClusterId,
                flags: request.Flags,
                priority: request.Priority,
                resource: request.Resource
                );

            await db.DatabaseInstances.InsertAsync(instance);

            return(instance);
        }
        protected async Task <ReadOnlyCollection <Database> > ListAllDatabasesAsync(IDatabaseService provider, DatabaseInstanceId instanceId, int?blockSize, CancellationToken cancellationToken, net.openstack.Core.IProgress <ReadOnlyCollectionPage <Database> > progress = null)
        {
            if (provider == null)
            {
                throw new ArgumentNullException("provider");
            }
            if (instanceId == null)
            {
                throw new ArgumentNullException("instanceId");
            }
            if (blockSize <= 0)
            {
                throw new ArgumentOutOfRangeException("blockSize");
            }

            return(await(await provider.ListDatabasesAsync(instanceId, null, blockSize, cancellationToken)).GetAllPagesAsync(cancellationToken, progress));
        }
        /// <summary>
        /// Get a collection of all backups for a particular database instance.
        /// </summary>
        /// <param name="service">The database service instance.</param>
        /// <param name="instanceId">The database instance ID. This is obtained from <see cref="DatabaseInstance.Id">DatabaseInstance.Id</see>.</param>
        /// <returns>
        /// A collection of <see cref="Backup"/> objects describing the backups for the database instance
        /// identified by <paramref name="instanceId"/>.
        /// </returns>
        /// <exception cref="ArgumentNullException">If <paramref name="service"/> is <see langword="null"/>.</exception>
        /// <exception cref="ArgumentNullException">If <paramref name="instanceId"/> is <see langword="null"/>.</exception>
        /// <exception cref="WebException">If the REST request does not return successfully.</exception>
        /// <seealso href="http://docs.rackspace.com/cdb/api/v1.0/cdb-devguide/content/GET_getBackups__version___accountId__backups_.html">List Backups (Rackspace Cloud Databases Developer Guide - API v1.0)</seealso>
        public static ReadOnlyCollection<Backup> ListBackupsForInstance(this IDatabaseService service, DatabaseInstanceId instanceId)
        {
            if (service == null)
                throw new ArgumentNullException("service");

            try
            {
                return service.ListBackupsForInstanceAsync(instanceId, CancellationToken.None).Result;
            }
            catch (AggregateException ex)
            {
                ReadOnlyCollection<Exception> innerExceptions = ex.Flatten().InnerExceptions;
                if (innerExceptions.Count == 1)
                    throw innerExceptions[0];

                throw;
            }
        }
        /// <summary>
        /// Revoke access to a database for a particular user.
        /// </summary>
        /// <param name="service">The database service instance.</param>
        /// <param name="instanceId">The database instance ID. This is obtained from <see cref="DatabaseInstance.Id">DatabaseInstance.Id</see>.</param>
        /// <param name="databaseName">The database name. This is obtained from <see cref="Database.Name">Database.Name</see>.</param>
        /// <param name="userName">A <see cref="UserName"/> object identifying the database user. This is obtained from <see cref="UserConfiguration.UserName">UserConfiguration.UserName</see>.</param>
        /// <exception cref="ArgumentNullException">If <paramref name="service"/> is <see langword="null"/>.</exception>
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="instanceId"/> is <see langword="null"/>.
        /// <para>-or-</para>
        /// <para>If <paramref name="databaseName"/> is <see langword="null"/>.</para>
        /// <para>-or-</para>
        /// <para>If <paramref name="userName"/> is <see langword="null"/>.</para>
        /// </exception>
        /// <exception cref="WebException">If the REST request does not return successfully.</exception>
        /// <seealso href="http://docs.rackspace.com/cdb/api/v1.0/cdb-devguide/content/DELETE_revokeUserAccess__version___accountId__instances__instanceId__users__name__databases__databaseName__.html">Revoke User Access (Rackspace Cloud Databases Developer Guide - API v1.0)</seealso>
        public static void RevokeUserAccess(this IDatabaseService service, DatabaseInstanceId instanceId, DatabaseName databaseName, UserName userName)
        {
            if (service == null)
                throw new ArgumentNullException("service");

            try
            {
                service.RevokeUserAccessAsync(instanceId, databaseName, userName, CancellationToken.None).Wait();
            }
            catch (AggregateException ex)
            {
                ReadOnlyCollection<Exception> innerExceptions = ex.Flatten().InnerExceptions;
                if (innerExceptions.Count == 1)
                    throw innerExceptions[0];

                throw;
            }
        }
        /// <summary>
        /// Get a database user by ID.
        /// </summary>
        /// <param name="service">The database service instance.</param>
        /// <param name="instanceId">The database instance ID. This is obtained from <see cref="DatabaseInstance.Id">DatabaseInstance.Id</see>.</param>
        /// <param name="userName">A <see cref="UserName"/> object identifying the database user. This is obtained from <see cref="UserConfiguration.UserName">UserConfiguration.UserName</see>.</param>
        /// <returns>
        /// A <see cref="DatabaseUser"/> object describing the user.
        /// </returns>
        /// <exception cref="ArgumentNullException">If <paramref name="service"/> is <see langword="null"/>.</exception>
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="instanceId"/> is <see langword="null"/>.
        /// <para>-or-</para>
        /// <para>If <paramref name="userName"/> is <see langword="null"/>.</para>
        /// </exception>
        /// <exception cref="WebException">If the REST request does not return successfully.</exception>
        /// <seealso href="http://docs.rackspace.com/cdb/api/v1.0/cdb-devguide/content/GET_listUser__version___accountId__instances__instanceId__users__name__.html">List User (Rackspace Cloud Databases Developer Guide - API v1.0)</seealso>
        public static DatabaseUser GetUser(this IDatabaseService service, DatabaseInstanceId instanceId, UserName userName)
        {
            if (service == null)
                throw new ArgumentNullException("service");

            try
            {
                return service.GetUserAsync(instanceId, userName, CancellationToken.None).Result;
            }
            catch (AggregateException ex)
            {
                ReadOnlyCollection<Exception> innerExceptions = ex.Flatten().InnerExceptions;
                if (innerExceptions.Count == 1)
                    throw innerExceptions[0];

                throw;
            }
        }
        /// <summary>
        /// Set the password for a database user.
        /// </summary>
        /// <param name="service">The database service instance.</param>
        /// <param name="instanceId">The database instance ID. This is obtained from <see cref="DatabaseInstance.Id">DatabaseInstance.Id</see>.</param>
        /// <param name="userName">A <see cref="UserName"/> object identifying the database user. This is obtained from <see cref="UserConfiguration.UserName">UserConfiguration.UserName</see>.</param>
        /// <param name="password">The new password for the user.</param>
        /// <exception cref="ArgumentNullException">If <paramref name="service"/> is <see langword="null"/>.</exception>
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="instanceId"/> is <see langword="null"/>.
        /// <para>-or-</para>
        /// <para>If <paramref name="userName"/> is <see langword="null"/>.</para>
        /// <para>-or-</para>
        /// <para>If <paramref name="password"/> is <see langword="null"/>.</para>
        /// </exception>
        /// <exception cref="ArgumentException">If <paramref name="password"/> is empty.</exception>
        /// <exception cref="WebException">If the REST request does not return successfully.</exception>
        /// <seealso href="http://docs.rackspace.com/cdb/api/v1.0/cdb-devguide/content/PUT_changePass__version___accountId__instances__instanceId__users_.html">Change User(s) Password (Rackspace Cloud Databases Developer Guide - API v1.0)</seealso>
        public static void SetUserPassword(this IDatabaseService service, DatabaseInstanceId instanceId, UserName userName, string password)
        {
            if (service == null)
                throw new ArgumentNullException("service");

            try
            {
                service.SetUserPasswordAsync(instanceId, userName, password, CancellationToken.None).Wait();
            }
            catch (AggregateException ex)
            {
                ReadOnlyCollection<Exception> innerExceptions = ex.Flatten().InnerExceptions;
                if (innerExceptions.Count == 1)
                    throw innerExceptions[0];

                throw;
            }
        }
        /// <summary>
        /// Create a new user in a database instance.
        /// </summary>
        /// <param name="service">The database service instance.</param>
        /// <param name="instanceId">The database instance ID. This is obtained from <see cref="DatabaseInstance.Id">DatabaseInstance.Id</see>.</param>
        /// <param name="configuration">A <see cref="UserConfiguration"/> object describing the configuration of the new user.</param>
        /// <exception cref="ArgumentNullException">If <paramref name="service"/> is <see langword="null"/>.</exception>
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="instanceId"/> is <see langword="null"/>.
        /// <para>-or-</para>
        /// <para>If <paramref name="configuration"/> is <see langword="null"/>.</para>
        /// </exception>
        /// <exception cref="WebException">If the REST request does not return successfully.</exception>
        /// <seealso href="http://docs.rackspace.com/cdb/api/v1.0/cdb-devguide/content/POST_createUser__version___accountId__instances__instanceId__users_.html">Create User (Rackspace Cloud Databases Developer Guide - API v1.0)</seealso>
        public static void CreateUser(this IDatabaseService service, DatabaseInstanceId instanceId, UserConfiguration configuration)
        {
            if (service == null)
                throw new ArgumentNullException("service");

            try
            {
                service.CreateUserAsync(instanceId, configuration, CancellationToken.None).Wait();
            }
            catch (AggregateException ex)
            {
                ReadOnlyCollection<Exception> innerExceptions = ex.Flatten().InnerExceptions;
                if (innerExceptions.Count == 1)
                    throw innerExceptions[0];

                throw;
            }
        }
        /// <summary>
        /// Resize the volume attached to the database instance.
        /// </summary>
        /// <remarks>
        /// The provider may limit database volume resize operations to <em>increasing</em> the volume size.
        /// </remarks>
        /// <param name="service">The database service instance.</param>
        /// <param name="instanceId">The database instance ID. This is obtained from <see cref="DatabaseInstance.Id">DatabaseInstance.Id</see>.</param>
        /// <param name="volumeSize">The new volume size for the database instance.</param>
        /// <exception cref="ArgumentNullException">If <paramref name="service"/> is <see langword="null"/>.</exception>
        /// <exception cref="ArgumentNullException">If <paramref name="instanceId"/> is <see langword="null"/>.</exception>
        /// <exception cref="ArgumentOutOfRangeException">If <paramref name="volumeSize"/> is less than or equal to 0.</exception>
        /// <exception cref="WebException">If the REST request does not return successfully.</exception>
        /// <seealso href="http://docs.rackspace.com/cdb/api/v1.0/cdb-devguide/content/POST_resizeVolume__version___accountId__instances__instanceId__action_.html">Resize the Instance Volume (Rackspace Cloud Databases Developer Guide - API v1.0)</seealso>
        public static void ResizeDatabaseInstanceVolume(this IDatabaseService service, DatabaseInstanceId instanceId, int volumeSize)
        {
            if (service == null)
                throw new ArgumentNullException("service");

            try
            {
                service.ResizeDatabaseInstanceVolumeAsync(instanceId, volumeSize, AsyncCompletionOption.RequestSubmitted, CancellationToken.None, null).Wait();
            }
            catch (AggregateException ex)
            {
                ReadOnlyCollection<Exception> innerExceptions = ex.Flatten().InnerExceptions;
                if (innerExceptions.Count == 1)
                    throw innerExceptions[0];

                throw;
            }
        }
        /// <summary>
        /// Checks whether or not root access has been enabled for a database instance.
        /// </summary>
        /// <param name="service">The database service instance.</param>
        /// <param name="instanceId">The database instance ID. This is obtained from <see cref="DatabaseInstance.Id">DatabaseInstance.Id</see>.</param>
        /// <returns>
        /// <see langword="true"/> if root access is enabled for the database instance; otherwise, <see langword="false"/>.
        /// </returns>
        /// <exception cref="ArgumentNullException">If <paramref name="service"/> is <see langword="null"/>.</exception>
        /// <exception cref="ArgumentNullException">If <paramref name="instanceId"/> is <see langword="null"/>.</exception>
        /// <exception cref="WebException">If the REST request does not return successfully.</exception>
        /// <seealso href="http://docs.rackspace.com/cdb/api/v1.0/cdb-devguide/content/GET_isRootEnabled__version___accountId__instances__instanceId__root_.html">List Root-Enabled Status (Rackspace Cloud Databases Developer Guide - API v1.0)</seealso>
        public static bool? CheckRootEnabledStatus(this IDatabaseService service, DatabaseInstanceId instanceId)
        {
            if (service == null)
                throw new ArgumentNullException("service");

            try
            {
                return service.CheckRootEnabledStatusAsync(instanceId, CancellationToken.None).Result;
            }
            catch (AggregateException ex)
            {
                ReadOnlyCollection<Exception> innerExceptions = ex.Flatten().InnerExceptions;
                if (innerExceptions.Count == 1)
                    throw innerExceptions[0];

                throw;
            }
        }