コード例 #1
0
 /// <summary>
 /// Exports a Azure SQL Database to bacpac. To determine the status of
 /// the operation call GetImportExportOperationStatus.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Management.Sql.IImportExportOperations.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Required. The name of the Resource Group to which the Azure SQL
 /// Server belongs.
 /// </param>
 /// <param name='serverName'>
 /// Required. The name of the Azure SQL Server on which the database is
 /// hosted.
 /// </param>
 /// <param name='databaseName'>
 /// Required. The name of the Azure SQL Database to export.
 /// </param>
 /// <param name='parameters'>
 /// Required. The required parameters for exporting a database.
 /// </param>
 /// <returns>
 /// Response Azure Sql Import/Export operations.
 /// </returns>
 public static ImportExportResponse Export(this IImportExportOperations operations, string resourceGroupName, string serverName, string databaseName, ExportRequestParameters parameters)
 {
     return Task.Factory.StartNew((object s) =>
     {
         return ((IImportExportOperations)s).ExportAsync(resourceGroupName, serverName, databaseName, parameters);
     }
     , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
 }
コード例 #2
0
        /// <summary>
        /// Creates a new export request
        /// </summary>
        /// <param name="exportRequest">Export request parameters</param>
        /// <returns>Operation response including the OperationStatusLink to get the operation status</returns>
        public AzureSqlDatabaseImportExportBaseModel Export(AzureSqlDatabaseImportExportBaseModel exportRequest)
        {
            ExportRequestParameters parameters = new ExportRequestParameters()
            {
                AdministratorLogin = exportRequest.AdministratorLogin,
                AdministratorLoginPassword = AzureSqlServerAdapter.Decrypt(exportRequest.AdministratorLoginPassword),
                StorageKey = exportRequest.StorageKey,
                StorageKeyType = exportRequest.StorageKeyType.ToString(),
                StorageUri = exportRequest.StorageUri
            };

            if (exportRequest.AuthenticationType != AuthenticationType.None)
            {
                parameters.AuthenticationType = exportRequest.AuthenticationType.ToString().ToLowerInvariant();
            }

            ImportExportResponse response = Communicator.Export(exportRequest.ResourceGroupName, exportRequest.ServerName,
                exportRequest.DatabaseName, parameters, Util.GenerateTracingId());
            return CreateImportExportResponse(response, exportRequest);
        }
コード例 #3
0
 /// <summary>
 /// Creates new export request
 /// </summary>
 public Management.Sql.Models.ImportExportResponse Export(string resourceGroupName, string serverName, string databaseName, ExportRequestParameters parameters, string clientRequestId)
 {
     return GetCurrentSqlClient(clientRequestId).ImportExport.Export(resourceGroupName, serverName, databaseName, parameters);
 }
コード例 #4
0
 /// <summary>
 /// Exports a Azure SQL Database to bacpac. To determine the status of
 /// the operation call GetImportExportOperationStatus.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Management.Sql.IImportExportOperations.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Required. The name of the Resource Group to which the Azure SQL
 /// Server belongs.
 /// </param>
 /// <param name='serverName'>
 /// Required. The name of the Azure SQL Server on which the database is
 /// hosted.
 /// </param>
 /// <param name='databaseName'>
 /// Required. The name of the Azure SQL Database to export.
 /// </param>
 /// <param name='parameters'>
 /// Required. The required parameters for exporting a database.
 /// </param>
 /// <returns>
 /// Response Azure Sql Import/Export operations.
 /// </returns>
 public static Task<ImportExportResponse> ExportAsync(this IImportExportOperations operations, string resourceGroupName, string serverName, string databaseName, ExportRequestParameters parameters)
 {
     return operations.ExportAsync(resourceGroupName, serverName, databaseName, parameters, CancellationToken.None);
 }
コード例 #5
0
        private void ValidateImportExport(bool createServer = true, bool createDatabase = true, bool createFirewallRule = true, 
            string operationName = "Export", bool missingFields = false, HttpStatusCode expectedStatueCode = HttpStatusCode.Accepted)
        {
            var handler = new BasicDelegatingHandler();

            // Management Clients
            var sqlClient = Sql2ScenarioHelper.GetSqlClient(handler);
            var resClient = Sql2ScenarioHelper.GetResourceClient(handler);

            // Variables for server create
            string serverName = TestUtilities.GenerateName("csm-sql-ie");
            string resGroupName = TestUtilities.GenerateName("csm-rg-servercrud");
            string serverLocation = "North Europe";
            string adminLogin = "******";
            string adminPass = "******";
            string version = "12.0";

            // Variables for database create
            string databaseName = TestUtilities.GenerateName("csm-sql-db_ie");
            string databaseEdition = "Standard";
            long databaseMaxSize = 5L*1024L*1024L*1024L; // 5 GB
            Guid dbSloS1 = new Guid("1b1ebd4d-d903-4baa-97f9-4ea675f5e928"); // S1
            string serviceObjectiveName = "S1";

            // Create firewall test.
            string firewallRuleName = TestUtilities.GenerateName("sql-fwrule");
            string startIp1 = "0.0.0.0";
            string endIp1 = "255.255.255.255";

            string storageKey = "StorageKey";
            string storageKeyType = "StorageAccessKey";
            string exportBacpacLink = string.Format(CultureInfo.InvariantCulture, "http://test.blob.core.windows.net/databases/{0}.bacpac", databaseName);
            string importBacpacLink = "http://test.blob.core.windows.net/databases/test.bacpac";

            string testMode = Environment.GetEnvironmentVariable("AZURE_TEST_MODE");
            if(testMode == "Record")
            {
                string importBacpacBaseUrl = Environment.GetEnvironmentVariable("TEST_EXPORT_BACPAC");
                storageKey = Environment.GetEnvironmentVariable("TEST_STORAGE_KEY");
                exportBacpacLink = string.Format(CultureInfo.InvariantCulture, "{0}/{1}.bacpac", importBacpacBaseUrl, databaseName);
                importBacpacLink = Environment.GetEnvironmentVariable("TEST_IMPORT_BACPAC");

                Assert.False(string.IsNullOrWhiteSpace(storageKey), "Environment variable TEST_EXPORT_BACPAC has not been set");
                Assert.False(string.IsNullOrWhiteSpace(importBacpacBaseUrl), "Environment variable TEST_EXPORT_BACPAC has not been set");
                Assert.False(string.IsNullOrWhiteSpace(importBacpacLink), "Environment variable TEST_IMPORT_BACPAC has not been set");
            }

            // Create the resource group.
            resClient.ResourceGroups.CreateOrUpdate(resGroupName, new ResourceGroup()
            {
                Location = serverLocation,
            });

            try
            {
                //////////////////////////////////////////////////////////////////////
                // Create server
                if (createServer)
                {
                    var createResponse = sqlClient.Servers.CreateOrUpdate(resGroupName, serverName, new ServerCreateOrUpdateParameters()
                    {
                        Location = serverLocation,
                        Properties = new ServerCreateOrUpdateProperties()
                        {
                            AdministratorLogin = adminLogin,
                            AdministratorLoginPassword = adminPass,
                            Version = version,
                        }
                    });
                    TestUtilities.ValidateOperationResponse(createResponse, HttpStatusCode.Created);
                }
                //////////////////////////////////////////////////////////////////////
                // Create database
                if (createServer && createDatabase)
                {
                    var createDbResponse = sqlClient.Databases.CreateOrUpdate(resGroupName, serverName, databaseName, new DatabaseCreateOrUpdateParameters()
                    {
                        Location = serverLocation,
                        Properties = new DatabaseCreateOrUpdateProperties()
                        {
                            Edition = databaseEdition,
                            MaxSizeBytes = databaseMaxSize,
                            RequestedServiceObjectiveId = dbSloS1
                        },
                    });

                    TestUtilities.ValidateOperationResponse(createDbResponse, HttpStatusCode.Created);
                }
                //////////////////////////////////////////////////////////////////////
                // Create firewall rule
                if (createServer && createFirewallRule)
                {
                    var firewallCreate = sqlClient.FirewallRules.CreateOrUpdate(resGroupName, serverName, firewallRuleName, new FirewallRuleCreateOrUpdateParameters()
                    {
                        Properties = new FirewallRuleCreateOrUpdateProperties()
                        {
                            StartIpAddress = startIp1,
                            EndIpAddress = endIp1,
                        }
                    });
                    TestUtilities.ValidateOperationResponse(firewallCreate, HttpStatusCode.Created);
                }
                //////////////////////////////////////////////////////////////////////
                //Import Export
                try
                {
                    ImportExportResponse importExportResponse = null;
                    if (operationName == ExportOperationName)
                    {
                        ExportRequestParameters parameters = new ExportRequestParameters()
                        {
                            AdministratorLogin = adminLogin,
                            AdministratorLoginPassword = adminPass
                        };
                        if (!missingFields)
                        {
                            parameters.StorageKey = storageKey;
                            parameters.StorageKeyType = storageKeyType;
                            parameters.StorageUri = new Uri(exportBacpacLink);
                        }

                        importExportResponse = sqlClient.ImportExport.Export(resGroupName, serverName, databaseName, parameters);
                    }
                    else if (operationName == ImportOperationName)
                    {

                        ImportRequestParameters parameters = new ImportRequestParameters()
                        {
                            AdministratorLogin = adminLogin,
                            AdministratorLoginPassword = adminPass,
                            StorageKey = storageKey,
                            StorageKeyType = storageKeyType,
                            StorageUri = new Uri(importBacpacLink),
                            DatabaseName = databaseName
                        };

                        if (!missingFields)
                        {
                            parameters.DatabaseMaxSize = databaseMaxSize;
                            parameters.Edition = databaseEdition;
                            parameters.ServiceObjectiveName = serviceObjectiveName;
                        }

                        importExportResponse = sqlClient.ImportExport.Import(resGroupName, serverName, parameters);
                    }
                    else if (operationName == ImportExistingDbOperationName)
                    {

                        ImportExtensionRequestParameteres parameters = new ImportExtensionRequestParameteres()
                        {
                            Properties = new ImportExtensionProperties
                            {
                                AdministratorLogin = adminLogin,
                                AdministratorLoginPassword = adminPass,
                                StorageKey = storageKey,
                                StorageKeyType = storageKeyType,
                                StorageUri = new Uri(importBacpacLink)
                            }
                        };

                        importExportResponse = sqlClient.ImportExport.ImportToExistingDatabase(resGroupName, serverName, databaseName, parameters);
                    }

                    if(expectedStatueCode == HttpStatusCode.Accepted)
                    {
                        Assert.Equal(importExportResponse.Status, OperationStatus.InProgress);
                        ImportExportOperationStatusResponse statusResponse = sqlClient.ImportExport.GetImportExportOperationStatus(importExportResponse.OperationStatusLink);
                        while(statusResponse.Status == Microsoft.Azure.OperationStatus.InProgress)
                        {
                            statusResponse = sqlClient.ImportExport.GetImportExportOperationStatus(importExportResponse.OperationStatusLink);
                            if (statusResponse.Status == Microsoft.Azure.OperationStatus.InProgress)
                            {
                                ValidateImportExportOperationStatusResponseProperties(statusResponse);
                            }
                        }

                        Assert.Equal(statusResponse.Status, OperationStatus.Succeeded);
                        ValidateImportExportOperationStatusResponseProperties(statusResponse.Properties);
                    }

                    TestUtilities.ValidateOperationResponse(importExportResponse, expectedStatueCode);

                }
                catch (CloudException exception)
                {
                    Assert.Equal(exception.Response.StatusCode, expectedStatueCode);
                }
                if (operationName == ImportOperationName && !createDatabase && !missingFields)
                {
                    DatabaseGetResponse databaseGetResponse = sqlClient.Databases.Get(resGroupName, serverName, databaseName);
                    TestUtilities.ValidateOperationResponse(databaseGetResponse);
                }
            }
            finally
            {
                // Clean up the resource group.
                resClient.ResourceGroups.Delete(resGroupName);
            }
        }