public void USqlBuildTest()
        {
            using (var context = MockContext.Start(this.GetType()))
            {
                commonData         = new CommonTestFixture(context);
                commonData.HostUrl =
                    commonData.DataLakeAnalyticsManagementHelper.TryCreateDataLakeAnalyticsAccount(
                        commonData.ResourceGroupName,
                        commonData.Location,
                        commonData.DataLakeStoreAccountName,
                        commonData.SecondDataLakeAnalyticsAccountName
                        );

                // Wait 5 minutes for the account setup
                TestUtilities.Wait(300000);

                var clientToUse = this.GetDataLakeAnalyticsJobManagementClient(context);

                // Compile a usql job, which requires a jobId in the job object
                // Submit a usql job to the account
                var jobToBuild = new BuildJobParameters
                {
                    Name       = "azure sdk data lake analytics job",
                    Type       = JobType.USql,
                    Properties = new CreateUSqlJobProperties
                    {
                        Script = "DROP DATABASE IF EXISTS testdb; CREATE DATABASE testdb;"
                    }
                };

                // Just compile the usql job, which requires a jobId in the job object
                var compileResponse =
                    clientToUse.Job.Build(
                        commonData.SecondDataLakeAnalyticsAccountName,
                        jobToBuild
                        );

                Assert.NotNull(compileResponse);

                // Now compile a broken usql job and verify diagnostics report an error
                jobToBuild.Properties.Script = "DROP DATABASE IF EXIST FOO; CREATE DATABASE FOO;";
                compileResponse =
                    clientToUse.Job.Build(
                        commonData.SecondDataLakeAnalyticsAccountName,
                        jobToBuild
                        );

                Assert.NotNull(compileResponse);
                Assert.Equal(1, ((USqlJobProperties)compileResponse.Properties).Diagnostics.Count);
                Assert.Equal(SeverityTypes.Error, ((USqlJobProperties)compileResponse.Properties).Diagnostics[0].Severity);
                Assert.Equal(18, ((USqlJobProperties)compileResponse.Properties).Diagnostics[0].ColumnNumber);
                Assert.Equal(22, ((USqlJobProperties)compileResponse.Properties).Diagnostics[0].End);
                Assert.Equal(17, ((USqlJobProperties)compileResponse.Properties).Diagnostics[0].Start);
                Assert.Equal(1, ((USqlJobProperties)compileResponse.Properties).Diagnostics[0].LineNumber);
                Assert.Contains("E_CSC_USER_SYNTAXERROR", ((USqlJobProperties)compileResponse.Properties).Diagnostics[0].Message);
            }
        }
예제 #2
0
        public void GetCatalogItemsTest()
        {
            // this test currently tests for Database, table TVF, view, types and procedure
            using (var context = MockContext.Start(this.GetType().FullName))
            {
                commonData         = new CommonTestFixture(context);
                commonData.HostUrl =
                    commonData.DataLakeAnalyticsManagementHelper.TryCreateDataLakeAnalyticsAccount(commonData.ResourceGroupName,
                                                                                                   commonData.Location, commonData.DataLakeStoreAccountName, commonData.SecondDataLakeAnalyticsAccountName);
                TestUtilities.Wait(120000); // Sleep for two minutes to give the account a chance to provision the queue
                commonData.DataLakeAnalyticsManagementHelper.CreateCatalog(commonData.ResourceGroupName,
                                                                           commonData.SecondDataLakeAnalyticsAccountName, commonData.DatabaseName, commonData.TableName, commonData.TvfName, commonData.ViewName, commonData.ProcName);
                using (var clientToUse = commonData.GetDataLakeAnalyticsCatalogManagementClient(context))
                {
                    var dbListResponse = clientToUse.Catalog.ListDatabases(
                        commonData.SecondDataLakeAnalyticsAccountName);

                    Assert.True(dbListResponse.Count() >= 1);

                    // look for the DB we created
                    Assert.True(dbListResponse.Any(db => db.Name.Equals(commonData.DatabaseName)));

                    // Get the specific Database as well
                    var dbGetResponse = clientToUse.Catalog.GetDatabase(commonData.SecondDataLakeAnalyticsAccountName, commonData.DatabaseName);

                    Assert.Equal(commonData.DatabaseName, dbGetResponse.Name);

                    // Get the table list
                    var tableListResponse = clientToUse.Catalog.ListTables(
                        commonData.SecondDataLakeAnalyticsAccountName,
                        commonData.DatabaseName, CommonTestFixture.SchemaName);

                    Assert.True(tableListResponse.Count() >= 1);

                    // look for the table we created
                    Assert.True(tableListResponse.Any(table => table.Name.Equals(commonData.TableName)));

                    // Get the specific table as well
                    var tableGetResponse = clientToUse.Catalog.GetTable(
                        commonData.SecondDataLakeAnalyticsAccountName,
                        commonData.DatabaseName, CommonTestFixture.SchemaName, commonData.TableName);

                    Assert.Equal(commonData.TableName, tableGetResponse.Name);

                    // Get the TVF list
                    var tvfListResponse = clientToUse.Catalog.ListTableValuedFunctions(
                        commonData.SecondDataLakeAnalyticsAccountName,
                        commonData.DatabaseName, CommonTestFixture.SchemaName);

                    Assert.True(tvfListResponse.Count() >= 1);

                    // look for the tvf we created
                    Assert.True(tvfListResponse.Any(tvf => tvf.Name.Equals(commonData.TvfName)));

                    // Get the specific TVF as well
                    var tvfGetResponse = clientToUse.Catalog.GetTableValuedFunction(
                        commonData.SecondDataLakeAnalyticsAccountName,
                        commonData.DatabaseName, CommonTestFixture.SchemaName, commonData.TvfName);

                    Assert.Equal(commonData.TvfName, tvfGetResponse.Name);

                    // Get the View list
                    var viewListResponse = clientToUse.Catalog.ListViews(
                        commonData.SecondDataLakeAnalyticsAccountName,
                        commonData.DatabaseName, CommonTestFixture.SchemaName);

                    Assert.True(viewListResponse.Count() >= 1);

                    // look for the view we created
                    Assert.True(viewListResponse.Any(view => view.Name.Equals(commonData.ViewName)));

                    // Get the specific view as well
                    var viewGetResponse = clientToUse.Catalog.GetView(
                        commonData.SecondDataLakeAnalyticsAccountName,
                        commonData.DatabaseName, CommonTestFixture.SchemaName, commonData.ViewName);

                    Assert.Equal(commonData.ViewName, viewGetResponse.Name);

                    // Get the Procedure list
                    var procListResponse = clientToUse.Catalog.ListProcedures(
                        commonData.SecondDataLakeAnalyticsAccountName,
                        commonData.DatabaseName, CommonTestFixture.SchemaName);

                    Assert.True(procListResponse.Count() >= 1);

                    // look for the procedure we created
                    Assert.True(procListResponse.Any(proc => proc.Name.Equals(commonData.ProcName)));

                    // Get the specific procedure as well
                    var procGetResponse = clientToUse.Catalog.GetProcedure(
                        commonData.SecondDataLakeAnalyticsAccountName,
                        commonData.DatabaseName, CommonTestFixture.SchemaName, commonData.ProcName);

                    Assert.Equal(commonData.ProcName, procGetResponse.Name);

                    // Get the Partition list
                    var partitionList = clientToUse.Catalog.ListTablePartitions(
                        commonData.SecondDataLakeAnalyticsAccountName,
                        commonData.DatabaseName, CommonTestFixture.SchemaName, commonData.TableName);

                    Assert.True(partitionList.Count() >= 1);

                    var specificPartition = partitionList.First();

                    // Get the specific partition as well
                    var partitionGetResponse = clientToUse.Catalog.GetTablePartition(
                        commonData.SecondDataLakeAnalyticsAccountName,
                        commonData.DatabaseName, CommonTestFixture.SchemaName, commonData.TableName, specificPartition.Name);

                    Assert.Equal(specificPartition.Name, partitionGetResponse.Name);

                    // Get all the types
                    var typeGetResponse = clientToUse.Catalog.ListTypes(
                        commonData.SecondDataLakeAnalyticsAccountName,
                        commonData.DatabaseName, CommonTestFixture.SchemaName);


                    Assert.NotNull(typeGetResponse);
                    Assert.NotEmpty(typeGetResponse);

                    // Get all the types that are not complex
                    typeGetResponse = clientToUse.Catalog.ListTypes(
                        commonData.SecondDataLakeAnalyticsAccountName,
                        commonData.DatabaseName, CommonTestFixture.SchemaName, new Microsoft.Rest.Azure.OData.ODataQuery <USqlType> {
                        Filter = "isComplexType eq false"
                    });


                    Assert.NotNull(typeGetResponse);
                    Assert.NotEmpty(typeGetResponse);
                    Assert.False(typeGetResponse.Any(type => type.IsComplexType.Value));
                }
            }
        }
예제 #3
0
        public void SecretAndCredentialCRUDTest()
        {
            // NOTE: This is deprecated and will be removed in a future release
            using (var context = MockContext.Start(this.GetType().FullName))
            {
                commonData         = new CommonTestFixture(context);
                commonData.HostUrl =
                    commonData.DataLakeAnalyticsManagementHelper.TryCreateDataLakeAnalyticsAccount(commonData.ResourceGroupName,
                                                                                                   commonData.Location, commonData.DataLakeStoreAccountName, commonData.SecondDataLakeAnalyticsAccountName);
                TestUtilities.Wait(120000); // Sleep for two minutes to give the account a chance to provision the queue
                commonData.DataLakeAnalyticsManagementHelper.CreateCatalog(commonData.ResourceGroupName,
                                                                           commonData.SecondDataLakeAnalyticsAccountName, commonData.DatabaseName, commonData.TableName, commonData.TvfName, commonData.ViewName, commonData.ProcName);
                using (var clientToUse = commonData.GetDataLakeAnalyticsCatalogManagementClient(context))
                {
                    using (var jobClient = commonData.GetDataLakeAnalyticsJobManagementClient(context))
                    {
                        // create the secret
                        var secretCreateResponse = clientToUse.Catalog.CreateSecret(
                            commonData.SecondDataLakeAnalyticsAccountName,
                            commonData.DatabaseName, commonData.SecretName,
                            new DataLakeAnalyticsCatalogSecretCreateOrUpdateParameters
                        {
                            Password = commonData.SecretPwd,
                            Uri      = "https://adlasecrettest.contoso.com:443"
                        });

                        // Attempt to create the secret again, which should throw
                        Assert.Throws <CloudException>(
                            () => clientToUse.Catalog.CreateSecret(
                                commonData.SecondDataLakeAnalyticsAccountName,
                                commonData.DatabaseName, commonData.SecretName,
                                new DataLakeAnalyticsCatalogSecretCreateOrUpdateParameters
                        {
                            Password = commonData.SecretPwd,
                            Uri      = "https://adlasecrettest.contoso.com:443"
                        }));

                        // create another secret
                        var secondSecretName = commonData.SecretName + "dup";
                        clientToUse.Catalog.CreateSecret(
                            commonData.SecondDataLakeAnalyticsAccountName,
                            commonData.DatabaseName, secondSecretName,
                            new DataLakeAnalyticsCatalogSecretCreateOrUpdateParameters
                        {
                            Password = commonData.SecretPwd,
                            Uri      = "https://adlasecrettest.contoso.com:443"
                        });
                        // Get the secret and ensure the response contains a date.
                        var secretGetResponse = clientToUse.Catalog.GetSecret(
                            commonData.SecondDataLakeAnalyticsAccountName,
                            commonData.DatabaseName, commonData.SecretName);

                        Assert.NotNull(secretGetResponse);
                        Assert.NotNull(secretGetResponse.CreationTime);

                        // Create a credential with the secret
                        var credentialCreationScript =
                            string.Format(
                                @"USE {0}; CREATE CREDENTIAL {1} WITH USER_NAME = ""scope@rkm4grspxa"", IDENTITY = ""{2}"";",
                                commonData.DatabaseName, commonData.CredentialName, commonData.SecretName);
                        commonData.DataLakeAnalyticsManagementHelper.RunJobToCompletion(jobClient,
                                                                                        commonData.SecondDataLakeAnalyticsAccountName, TestUtilities.GenerateGuid(),
                                                                                        credentialCreationScript);

                        // Get the Credential list
                        var credListResponse = clientToUse.Catalog.ListCredentials(
                            commonData.SecondDataLakeAnalyticsAccountName,
                            commonData.DatabaseName);
                        Assert.True(credListResponse.Count() >= 1);

                        // look for the credential we created
                        Assert.True(credListResponse.Any(cred => cred.Name.Equals(commonData.CredentialName)));

                        // Get the specific credential as well
                        var credGetResponse = clientToUse.Catalog.GetCredential(
                            commonData.SecondDataLakeAnalyticsAccountName,
                            commonData.DatabaseName, commonData.CredentialName);
                        Assert.Equal(commonData.CredentialName, credGetResponse.Name);

                        // Drop the credential (to enable secret deletion)
                        var credentialDropScript =
                            string.Format(
                                @"USE {0}; DROP CREDENTIAL {1};", commonData.DatabaseName, commonData.CredentialName);
                        commonData.DataLakeAnalyticsManagementHelper.RunJobToCompletion(jobClient,
                                                                                        commonData.SecondDataLakeAnalyticsAccountName, TestUtilities.GenerateGuid(),
                                                                                        credentialDropScript);

                        // Delete the secret
                        clientToUse.Catalog.DeleteSecret(
                            commonData.SecondDataLakeAnalyticsAccountName,
                            commonData.DatabaseName, commonData.SecretName);

                        // Try to get the secret which should throw
                        Assert.Throws <CloudException>(() => clientToUse.Catalog.GetSecret(
                                                           commonData.SecondDataLakeAnalyticsAccountName,
                                                           commonData.DatabaseName, commonData.SecretName));

                        // Delete all secrets
                        clientToUse.Catalog.DeleteAllSecrets(
                            commonData.SecondDataLakeAnalyticsAccountName,
                            commonData.DatabaseName);

                        // Try to get the second secret, which should throw.
                        // Try to get the secret which should throw
                        Assert.Throws <CloudException>(() => clientToUse.Catalog.GetSecret(
                                                           commonData.SecondDataLakeAnalyticsAccountName,
                                                           commonData.DatabaseName, secondSecretName));
                    }
                }
            }
        }
        public void USqlSubmitGetListCancelTest()
        {
            using (var context = MockContext.Start(this.GetType()))
            {
                commonData         = new CommonTestFixture(context);
                commonData.HostUrl =
                    commonData.DataLakeAnalyticsManagementHelper.TryCreateDataLakeAnalyticsAccount(
                        commonData.ResourceGroupName,
                        commonData.Location,
                        commonData.DataLakeStoreAccountName,
                        commonData.SecondDataLakeAnalyticsAccountName
                        );

                // Wait 5 minutes for the account setup
                TestUtilities.Wait(300000);

                var clientToUse = this.GetDataLakeAnalyticsJobManagementClient(context);

                Guid jobId    = TestUtilities.GenerateGuid();
                Guid secondId = TestUtilities.GenerateGuid();

                // Job relationship information
                var recurrenceId   = TestUtilities.GenerateGuid();
                var recurrenceName = TestUtilities.GenerateName("recurrence");

                var runId01 = TestUtilities.GenerateGuid();
                var runId02 = TestUtilities.GenerateGuid();

                var pipelineId   = TestUtilities.GenerateGuid();
                var pipelineName = TestUtilities.GenerateName("jobPipeline");
                var pipelineUri  = string.Format("https://{0}.contoso.com/myJob", TestUtilities.GenerateName("pipelineuri"));

                // Submit a usql job to the account
                var jobToSubmit = new CreateJobParameters
                {
                    Name = "azure sdk data lake analytics job",
                    Type = JobType.USql,
                    DegreeOfParallelism = 2,
                    Properties          = new CreateUSqlJobProperties
                    {
                        RuntimeVersion = "default",
                        Script         = "DROP DATABASE IF EXISTS testdb; CREATE DATABASE testdb;"
                    },
                    Related = new JobRelationshipProperties
                    {
                        PipelineId     = pipelineId,
                        PipelineName   = pipelineName,
                        PipelineUri    = pipelineUri,
                        RecurrenceId   = recurrenceId,
                        RecurrenceName = recurrenceName,
                        RunId          = runId01
                    }
                };

                // Check to make sure the usql job doesn't already exist
                Assert.False(
                    clientToUse.Job.Exists(
                        commonData.SecondDataLakeAnalyticsAccountName,
                        jobId
                        )
                    );

                // Submit the usql job
                var jobCreateResponse =
                    clientToUse.Job.Create(
                        commonData.SecondDataLakeAnalyticsAccountName,
                        jobId,
                        jobToSubmit
                        );

                Assert.NotNull(jobCreateResponse);

                // Check to make sure the usql job does exist now
                Assert.True(
                    clientToUse.Job.Exists(
                        commonData.SecondDataLakeAnalyticsAccountName,
                        jobId
                        )
                    );

                // Cancel the usql job
                clientToUse.Job.Cancel(
                    commonData.SecondDataLakeAnalyticsAccountName,
                    jobCreateResponse.JobId.GetValueOrDefault()
                    );

                // Get the usql job and ensure that it says it was cancelled
                var getCancelledJobResponse =
                    clientToUse.Job.Get(
                        commonData.SecondDataLakeAnalyticsAccountName,
                        jobCreateResponse.JobId.GetValueOrDefault()
                        );

                Assert.Equal(JobResult.Cancelled, getCancelledJobResponse.Result);
                Assert.NotNull(getCancelledJobResponse.ErrorMessage);
                Assert.NotEmpty(getCancelledJobResponse.ErrorMessage);

                // Resubmit the usql job
                // First update the runId to a new run
                jobToSubmit.Related.RunId = runId02;
                jobCreateResponse         =
                    clientToUse.Job.Create(
                        commonData.SecondDataLakeAnalyticsAccountName,
                        secondId,
                        jobToSubmit
                        );

                Assert.NotNull(jobCreateResponse);

                // Poll the usql job until it finishes
                var getJobResponse =
                    clientToUse.Job.Get(
                        commonData.SecondDataLakeAnalyticsAccountName,
                        jobCreateResponse.JobId.GetValueOrDefault()
                        );

                Assert.NotNull(getJobResponse);

                int maxWaitInSeconds = 180; // 3 minutes should be long enough
                int curWaitInSeconds = 0;
                while (getJobResponse.State != JobState.Ended && curWaitInSeconds < maxWaitInSeconds)
                {
                    // Wait 5 seconds before polling again
                    TestUtilities.Wait(5000);
                    curWaitInSeconds += 5;
                    getJobResponse    =
                        clientToUse.Job.Get(
                            commonData.SecondDataLakeAnalyticsAccountName,
                            jobCreateResponse.JobId.GetValueOrDefault()
                            );

                    Assert.NotNull(getJobResponse);
                }

                Assert.True(curWaitInSeconds <= maxWaitInSeconds);

                // Verify the usql job completes successfully
                Assert.True(
                    getJobResponse.State == JobState.Ended && getJobResponse.Result == JobResult.Succeeded,
                    string.Format(
                        "Job: {0} did not return success. Current job state: {1}. Actual result: {2}. Error (if any): {3}",
                        getJobResponse.JobId,
                        getJobResponse.State,
                        getJobResponse.Result,
                        getJobResponse.ErrorMessage
                        )
                    );

                // Validate usql job relationship info
                Assert.Equal(runId02, getJobResponse.Related.RunId);
                Assert.Equal(pipelineId, getJobResponse.Related.PipelineId);
                Assert.Equal(pipelineName, getJobResponse.Related.PipelineName);
                Assert.Equal(recurrenceName, getJobResponse.Related.RecurrenceName);
                Assert.Equal(recurrenceId, getJobResponse.Related.RecurrenceId);
                Assert.Equal(pipelineUri, getJobResponse.Related.PipelineUri);

                // Get the list of usql jobs and check that the submitted job exists
                var listJobResponse =
                    clientToUse.Job.List(
                        commonData.SecondDataLakeAnalyticsAccountName
                        );

                Assert.NotNull(listJobResponse);
                Assert.Contains(listJobResponse, job => job.JobId == getJobResponse.JobId);

                // Validate usql job relationship retrieval (get/list pipeline and get/list recurrence)
                var getPipeline =
                    clientToUse.Pipeline.Get(
                        commonData.SecondDataLakeAnalyticsAccountName,
                        pipelineId
                        );

                Assert.Equal(pipelineId, getPipeline.PipelineId);
                Assert.Equal(pipelineName, getPipeline.PipelineName);
                Assert.Equal(pipelineUri, getPipeline.PipelineUri);
                Assert.True(getPipeline.Runs.Count() >= 2);

                var listPipeline =
                    clientToUse.Pipeline.List(
                        commonData.SecondDataLakeAnalyticsAccountName
                        );

                Assert.Single(listPipeline);
                Assert.Contains(listPipeline, pipeline => pipeline.PipelineId == pipelineId);

                // Recurrence get/list
                var getRecurrence =
                    clientToUse.Recurrence.Get(
                        commonData.SecondDataLakeAnalyticsAccountName,
                        recurrenceId
                        );

                Assert.Equal(recurrenceId, getRecurrence.RecurrenceId);
                Assert.Equal(recurrenceName, getRecurrence.RecurrenceName);

                var listRecurrence =
                    clientToUse.Recurrence.List(
                        commonData.SecondDataLakeAnalyticsAccountName
                        );

                Assert.Single(listRecurrence);
                Assert.Contains(listRecurrence, recurrence => recurrence.RecurrenceId == recurrenceId);

                // TODO: re-enable this after the next prod push
                // List the usql jobs with only the jobId property filled
                // listJobResponse = clientToUse.Job.List(commonData.SecondDataLakeAnalyticsAccountName, select: "jobId");

                // Assert.NotNull(listJobResponse);
                // Assert.True(listJobResponse.Any(job => job.JobId == getJobResponse.JobId));
            }
        }
예제 #5
0
        public void FirewallCRUDTest()
        {
            using (var context = MockContext.Start(this.GetType()))
            {
                commonData = new CommonTestFixture(context);
                var clientToUse = this.GetDataLakeAnalyticsAccountManagementClient(context);

                // Create a an account with trusted ID provider and firewall rules.
                var firewallStart     = "127.0.0.1";
                var firewallEnd       = "127.0.0.2";
                var firewallRuleName1 = TestUtilities.GenerateName("firerule1");
                var adlaAcocunt       = TestUtilities.GenerateName("adla01");

                // Create a test account
                var responseCreate =
                    clientToUse.Accounts.Create(
                        commonData.ResourceGroupName,
                        adlaAcocunt,
                        parameters: new CreateDataLakeAnalyticsAccountParameters
                {
                    Location = commonData.Location,
                    DefaultDataLakeStoreAccount = commonData.DataLakeStoreAccountName,
                    DataLakeStoreAccounts       = new List <AddDataLakeStoreWithAccountParameters>
                    {
                        new AddDataLakeStoreWithAccountParameters
                        {
                            Name   = commonData.DataLakeStoreAccountName,
                            Suffix = commonData.DataLakeStoreAccountSuffix
                        }
                    },
                    FirewallState         = FirewallState.Enabled,
                    FirewallAllowAzureIps = FirewallAllowAzureIpsState.Enabled,
                    FirewallRules         = new List <CreateFirewallRuleWithAccountParameters>
                    {
                        new CreateFirewallRuleWithAccountParameters
                        {
                            Name           = firewallRuleName1,
                            StartIpAddress = firewallStart,
                            EndIpAddress   = firewallEnd,
                        }
                    },
                }
                        );

                Assert.Equal(DataLakeAnalyticsAccountStatus.Succeeded, responseCreate.ProvisioningState);

                // Get the account and ensure that all the values are properly set.
                var responseGet =
                    clientToUse.Accounts.Get(
                        commonData.ResourceGroupName,
                        adlaAcocunt
                        );

                // Validate the account creation process
                Assert.Equal(DataLakeAnalyticsAccountStatus.Succeeded, responseGet.ProvisioningState);
                Assert.NotNull(responseCreate.Id);
                Assert.NotNull(responseGet.Id);
                Assert.Contains(adlaAcocunt, responseGet.Id);
                Assert.Equal(commonData.Location, responseGet.Location);
                Assert.Equal(adlaAcocunt, responseGet.Name);
                Assert.Equal("Microsoft.DataLakeAnalytics/accounts", responseGet.Type);

                // Validate firewall state
                Assert.Equal(FirewallState.Enabled, responseGet.FirewallState);
                Assert.True(responseGet.FirewallRules.Count() == 1);
                Assert.Equal(firewallStart, responseGet.FirewallRules[0].StartIpAddress);
                Assert.Equal(firewallEnd, responseGet.FirewallRules[0].EndIpAddress);
                Assert.Equal(firewallRuleName1, responseGet.FirewallRules[0].Name);
                Assert.Equal(FirewallAllowAzureIpsState.Enabled, responseGet.FirewallAllowAzureIps);

                // Test getting the specific firewall rules
                var firewallRule =
                    clientToUse.FirewallRules.Get(
                        commonData.ResourceGroupName,
                        adlaAcocunt,
                        firewallRuleName1
                        );

                Assert.Equal(firewallStart, firewallRule.StartIpAddress);
                Assert.Equal(firewallEnd, firewallRule.EndIpAddress);
                Assert.Equal(firewallRuleName1, firewallRule.Name);

                var updatedFirewallStart = "192.168.0.0";
                var updatedFirewallEnd   = "192.168.0.1";

                // Update the firewall rule to change the start/end ip addresses
                firewallRule =
                    clientToUse.FirewallRules.CreateOrUpdate(
                        commonData.ResourceGroupName,
                        adlaAcocunt,
                        firewallRuleName1,
                        parameters: new CreateOrUpdateFirewallRuleParameters
                {
                    StartIpAddress = updatedFirewallStart,
                    EndIpAddress   = updatedFirewallEnd,
                }
                        );

                Assert.Equal(updatedFirewallStart, firewallRule.StartIpAddress);
                Assert.Equal(updatedFirewallEnd, firewallRule.EndIpAddress);
                Assert.Equal(firewallRuleName1, firewallRule.Name);

                // Just update the firewall rule start IP
                firewallRule =
                    clientToUse.FirewallRules.Update(
                        commonData.ResourceGroupName,
                        adlaAcocunt,
                        firewallRuleName1,
                        parameters: new UpdateFirewallRuleParameters
                {
                    StartIpAddress = firewallStart
                }
                        );

                Assert.Equal(firewallStart, firewallRule.StartIpAddress);
                Assert.Equal(updatedFirewallEnd, firewallRule.EndIpAddress);
                Assert.Equal(firewallRuleName1, firewallRule.Name);

                // Remove the firewall rule and verify it is gone.
                clientToUse.FirewallRules.Delete(
                    commonData.ResourceGroupName,
                    adlaAcocunt,
                    firewallRuleName1
                    );

                try
                {
                    firewallRule =
                        clientToUse.FirewallRules.Get(
                            commonData.ResourceGroupName,
                            adlaAcocunt,
                            firewallRuleName1
                            );

                    Assert.True(false, "Attempting to retrieve a deleted firewall rule did not throw.");
                }
                catch (CloudException e)
                {
                    Assert.Equal(HttpStatusCode.NotFound, e.Response.StatusCode);
                }
            }
        }
예제 #6
0
        public void CreateGetUpdateDeleteTest()
        {
            using (var context = MockContext.Start(this.GetType().FullName))
            {
                commonData = new CommonTestFixture(context, true);
                var clientToUse = this.GetDataLakeAnalyticsAccountManagementClient(context);

                // ensure the account doesn't exist
                Assert.False(clientToUse.Account.Exists(commonData.ResourceGroupName, commonData.DataLakeAnalyticsAccountName));

                // Create a test account
                var responseCreate =
                    clientToUse.Account.Create(commonData.ResourceGroupName, commonData.DataLakeAnalyticsAccountName,
                                               parameters: new DataLakeAnalyticsAccount
                {
                    Name       = commonData.DataLakeAnalyticsAccountName,
                    Location   = commonData.Location,
                    Properties = new DataLakeAnalyticsAccountProperties
                    {
                        DefaultDataLakeStoreAccount = commonData.DataLakeStoreAccountName,
                        DataLakeStoreAccounts       = new List <DataLakeStoreAccountInfo>
                        {
                            new DataLakeStoreAccountInfo
                            {
                                Name       = commonData.DataLakeStoreAccountName,
                                Properties = new DataLakeStoreAccountInfoProperties
                                {
                                    Suffix = commonData.DataLakeStoreAccountSuffix
                                }
                            }
                        }
                    },
                    Tags = new Dictionary <string, string>
                    {
                        { "testkey", "testvalue" }
                    }
                });

                // verify the account exists
                Assert.True(clientToUse.Account.Exists(commonData.ResourceGroupName, commonData.DataLakeAnalyticsAccountName));

                // get the account and ensure that all the values are properly set.
                var responseGet = clientToUse.Account.Get(commonData.ResourceGroupName, commonData.DataLakeAnalyticsAccountName);

                // validate the account creation process
                Assert.True(responseGet.Properties.ProvisioningState == DataLakeAnalyticsAccountStatus.Creating || responseGet.Properties.ProvisioningState == DataLakeAnalyticsAccountStatus.Succeeded);
                Assert.NotNull(responseCreate.Id);
                Assert.NotNull(responseGet.Id);
                Assert.Contains(commonData.DataLakeAnalyticsAccountName, responseGet.Id);
                Assert.Equal(commonData.Location, responseGet.Location);
                Assert.Equal(commonData.DataLakeAnalyticsAccountName, responseGet.Name);
                Assert.Equal("Microsoft.DataLakeAnalytics/accounts", responseGet.Type);

                Assert.True(responseGet.Properties.DataLakeStoreAccounts.Count == 1);
                Assert.True(responseGet.Properties.DataLakeStoreAccounts.ToList()[0].Name.Equals(commonData.DataLakeStoreAccountName));

                // wait for provisioning state to be Succeeded
                // we will wait a maximum of 15 minutes for this to happen and then report failures
                int timeToWaitInMinutes = 15;
                int minutesWaited       = 0;
                while (responseGet.Properties.ProvisioningState != DataLakeAnalyticsAccountStatus.Succeeded && responseGet.Properties.ProvisioningState != DataLakeAnalyticsAccountStatus.Failed && minutesWaited <= timeToWaitInMinutes)
                {
                    TestUtilities.Wait(60000); // Wait for one minute and then go again.
                    minutesWaited++;
                    responseGet = clientToUse.Account.Get(commonData.ResourceGroupName, commonData.DataLakeAnalyticsAccountName);
                }

                // Confirm that the account creation did succeed
                Assert.True(responseGet.Properties.ProvisioningState == DataLakeAnalyticsAccountStatus.Succeeded);

                // Update the account and confirm the updates make it in.
                var newAccount = responseGet;
                var firstStorageAccountName = newAccount.Properties.DataLakeStoreAccounts.ToList()[0].Name;
                newAccount.Tags = new Dictionary <string, string>
                {
                    { "updatedKey", "updatedValue" }
                };

                // need to null out deep properties to prevent an error
                newAccount.Properties.DataLakeStoreAccounts = null;
                newAccount.Properties.StorageAccounts       = null;

                var updateResponse = clientToUse.Account.Update(commonData.ResourceGroupName, commonData.DataLakeAnalyticsAccountName, newAccount);

                Assert.Equal(DataLakeAnalyticsAccountStatus.Succeeded, updateResponse.Properties.ProvisioningState);

                // get the account and ensure that all the values are properly set.
                var updateResponseGet = clientToUse.Account.Get(commonData.ResourceGroupName, commonData.DataLakeAnalyticsAccountName);

                Assert.NotNull(updateResponse.Id);
                Assert.Contains(responseGet.Id, updateResponseGet.Id);
                Assert.Equal(responseGet.Location, updateResponseGet.Location);
                Assert.Equal(newAccount.Name, updateResponseGet.Name);
                Assert.Equal(responseGet.Type, updateResponseGet.Type);

                // verify the new tags. NOTE: sequence equal is not ideal if we have more than 1 tag, since the ordering can change.
                Assert.True(updateResponseGet.Tags.SequenceEqual(newAccount.Tags));
                Assert.True(updateResponseGet.Properties.DataLakeStoreAccounts.Count == 1);
                Assert.True(updateResponseGet.Properties.DataLakeStoreAccounts.ToList()[0].Name.Equals(firstStorageAccountName));

                // Create another account and ensure that list account returns both
                responseGet = clientToUse.Account.Get(commonData.ResourceGroupName, commonData.DataLakeAnalyticsAccountName);
                var accountToChange = responseGet;
                accountToChange.Name = accountToChange.Name + "secondacct";

                clientToUse.Account.Create(commonData.ResourceGroupName, accountToChange.Name, accountToChange);

                var listResponse = clientToUse.Account.List();

                // Assert that there are at least two accounts in the list
                Assert.True(listResponse.Count() > 1);

                // now list with the resource group
                listResponse = clientToUse.Account.ListByResourceGroup(commonData.ResourceGroupName);

                // Assert that there are at least two accounts in the list
                Assert.True(listResponse.Count() > 1);

                // Add, list and remove a data source to the first account
                // validate the data source doesn't exist first
                Assert.False(clientToUse.Account.DataLakeStoreAccountExists(commonData.ResourceGroupName, commonData.DataLakeAnalyticsAccountName, commonData.SecondDataLakeStoreAccountName));
                clientToUse.Account.AddDataLakeStoreAccount(commonData.ResourceGroupName,
                                                            commonData.DataLakeAnalyticsAccountName, commonData.SecondDataLakeStoreAccountName, new AddDataLakeStoreParameters {
                    Properties = new DataLakeStoreAccountInfoProperties {
                        Suffix = commonData.DataLakeStoreAccountSuffix
                    }
                });

                // verify that the store account does exist now
                Assert.True(clientToUse.Account.DataLakeStoreAccountExists(commonData.ResourceGroupName, commonData.DataLakeAnalyticsAccountName, commonData.SecondDataLakeStoreAccountName));

                // Get the data sources and confirm there are 2
                var getDataSourceResponse =
                    clientToUse.Account.ListDataLakeStoreAccounts(commonData.ResourceGroupName,
                                                                  commonData.DataLakeAnalyticsAccountName, null);

                Assert.Equal(2, getDataSourceResponse.Count());

                // get the specific data source
                var getSingleDataSourceResponse =
                    clientToUse.Account.GetDataLakeStoreAccount(commonData.ResourceGroupName,
                                                                commonData.DataLakeAnalyticsAccountName, commonData.SecondDataLakeStoreAccountName);

                Assert.Equal(commonData.SecondDataLakeStoreAccountName, getSingleDataSourceResponse.Name);
                Assert.Equal(commonData.SecondDataLakeStoreAccountSuffix, getSingleDataSourceResponse.Properties.Suffix);

                // Remove the data source we added
                clientToUse.Account.DeleteDataLakeStoreAccount(commonData.ResourceGroupName,
                                                               commonData.DataLakeAnalyticsAccountName, commonData.SecondDataLakeStoreAccountName);

                // Confirm that there is now only one data source.
                getDataSourceResponse =
                    clientToUse.Account.ListDataLakeStoreAccounts(commonData.ResourceGroupName,
                                                                  commonData.DataLakeAnalyticsAccountName, null);

                Assert.Equal(1, getDataSourceResponse.Count());

                // Add, list and remove an azure blob source to the first account
                // verify the blob doesn't exist
                Assert.False(clientToUse.Account.StorageAccountExists(commonData.ResourceGroupName, commonData.DataLakeAnalyticsAccountName, commonData.StorageAccountName));
                clientToUse.Account.AddStorageAccount(commonData.ResourceGroupName,
                                                      commonData.DataLakeAnalyticsAccountName, commonData.StorageAccountName, new AddStorageAccountParameters {
                    Properties = new StorageAccountProperties
                    {
                        Suffix    = commonData.StorageAccountSuffix,
                        AccessKey = commonData.StorageAccountAccessKey
                    }
                });

                // verify the blob exists now
                Assert.True(clientToUse.Account.StorageAccountExists(commonData.ResourceGroupName, commonData.DataLakeAnalyticsAccountName, commonData.StorageAccountName));

                // Get the data sources and confirm there is 1
                var getDataSourceBlobResponse =
                    clientToUse.Account.ListStorageAccounts(commonData.ResourceGroupName,
                                                            commonData.DataLakeAnalyticsAccountName, null);

                Assert.Equal(1, getDataSourceBlobResponse.Count());

                // Get the specific data source we added and confirm that it has the same properties
                var getSingleDataSourceBlobResponse =
                    clientToUse.Account.GetStorageAccount(commonData.ResourceGroupName,
                                                          commonData.DataLakeAnalyticsAccountName, commonData.StorageAccountName);

                Assert.Equal(commonData.StorageAccountName, getSingleDataSourceBlobResponse.Name);
                Assert.True(string.IsNullOrEmpty(getSingleDataSourceBlobResponse.Properties.AccessKey));
                Assert.Equal(commonData.StorageAccountSuffix, getSingleDataSourceBlobResponse.Properties.Suffix);

                // Remove the data source we added
                clientToUse.Account.DeleteStorageAccount(commonData.ResourceGroupName,
                                                         commonData.DataLakeAnalyticsAccountName, commonData.StorageAccountName);

                // Confirm that there no azure data sources.
                getDataSourceBlobResponse =
                    clientToUse.Account.ListStorageAccounts(commonData.ResourceGroupName,
                                                            commonData.DataLakeAnalyticsAccountName, null);

                Assert.Equal(0, getDataSourceBlobResponse.Count());

                // Delete the account and confirm that it is deleted.
                clientToUse.Account.Delete(commonData.ResourceGroupName, newAccount.Name);

                // delete the account again and make sure it continues to result in a succesful code.
                clientToUse.Account.Delete(commonData.ResourceGroupName, newAccount.Name);

                // delete the account with its old name, which should also succeed.
                clientToUse.Account.Delete(commonData.ResourceGroupName, commonData.DataLakeAnalyticsAccountName);

                // delete the second account that was created to ensure that we properly clean up after ourselves.
                clientToUse.Account.Delete(commonData.ResourceGroupName, accountToChange.Name);
            }
        }
예제 #7
0
        public void AccountCRUDTest()
        {
            using (var context = MockContext.Start(this.GetType()))
            {
                commonData = new CommonTestFixture(context, true);
                var clientToUse = this.GetDataLakeAnalyticsAccountManagementClient(context);

                // Ensure that the account doesn't exist and that the account name is available
                Assert.False(
                    clientToUse.Accounts.Exists(
                        commonData.ResourceGroupName,
                        commonData.DataLakeAnalyticsAccountName
                        )
                    );

                var checkNameParam = new CheckNameAvailabilityParameters
                {
                    Name = commonData.DataLakeAnalyticsAccountName
                };

                var responseNameCheck =
                    clientToUse.Accounts.CheckNameAvailability(
                        commonData.Location.Replace(" ", ""),
                        checkNameParam
                        );

                Assert.True(responseNameCheck.NameAvailable);

                // Create a test account
                var responseCreate =
                    clientToUse.Accounts.Create(
                        commonData.ResourceGroupName,
                        commonData.DataLakeAnalyticsAccountName,
                        parameters: new CreateDataLakeAnalyticsAccountParameters
                {
                    Location = commonData.Location,
                    Tags     = new Dictionary <string, string>
                    {
                        { "testkey", "testvalue" }
                    },
                    DefaultDataLakeStoreAccount = commonData.DataLakeStoreAccountName,
                    DataLakeStoreAccounts       = new List <AddDataLakeStoreWithAccountParameters>
                    {
                        new AddDataLakeStoreWithAccountParameters
                        {
                            Name   = commonData.DataLakeStoreAccountName,
                            Suffix = commonData.DataLakeStoreAccountSuffix
                        }
                    },
                    NewTier = TierType.Commitment100AUHours
                }
                        );

                // Verify that the account exists and that the account name is no longer available
                Assert.True(
                    clientToUse.Accounts.Exists(
                        commonData.ResourceGroupName,
                        commonData.DataLakeAnalyticsAccountName
                        )
                    );

                responseNameCheck =
                    clientToUse.Accounts.CheckNameAvailability(
                        commonData.Location.Replace(" ", ""),
                        checkNameParam
                        );

                Assert.False(responseNameCheck.NameAvailable);

                // Get the account and ensure that all the values are properly set.
                var responseGet =
                    clientToUse.Accounts.Get(
                        commonData.ResourceGroupName,
                        commonData.DataLakeAnalyticsAccountName
                        );

                // Validate the account creation process
                Assert.True(responseGet.ProvisioningState == DataLakeAnalyticsAccountStatus.Creating || responseGet.ProvisioningState == DataLakeAnalyticsAccountStatus.Succeeded);
                Assert.NotNull(responseCreate.Id);
                Assert.NotNull(responseGet.Id);
                Assert.Contains(commonData.DataLakeAnalyticsAccountName, responseGet.Id);
                Assert.Equal(commonData.Location, responseGet.Location);
                Assert.Equal(commonData.DataLakeAnalyticsAccountName, responseGet.Name);
                Assert.Equal("Microsoft.DataLakeAnalytics/accounts", responseGet.Type);
                Assert.True(responseGet.DataLakeStoreAccounts.Count == 1);
                Assert.Equal(responseGet.DataLakeStoreAccounts.ToList()[0].Name, commonData.DataLakeStoreAccountName);

                // Wait for provisioning state to be Succeeded
                // We will wait a maximum of 15 minutes for this to happen and then report failures
                int timeToWaitInMinutes = 15;
                int minutesWaited       = 0;
                while (responseGet.ProvisioningState != DataLakeAnalyticsAccountStatus.Succeeded &&
                       responseGet.ProvisioningState != DataLakeAnalyticsAccountStatus.Failed &&
                       minutesWaited <= timeToWaitInMinutes)
                {
                    TestUtilities.Wait(60000); // Wait for one minute and then go again.
                    minutesWaited++;
                    responseGet =
                        clientToUse.Accounts.Get(
                            commonData.ResourceGroupName,
                            commonData.DataLakeAnalyticsAccountName
                            );
                }

                // Confirm that the account creation did succeed
                Assert.True(responseGet.ProvisioningState == DataLakeAnalyticsAccountStatus.Succeeded);
                Assert.Equal(TierType.Commitment100AUHours, responseGet.CurrentTier);
                Assert.Equal(TierType.Commitment100AUHours, responseGet.NewTier);

                // Update the account and confirm that the updates make it in.
                var responseUpdate =
                    clientToUse.Accounts.Update(
                        commonData.ResourceGroupName,
                        commonData.DataLakeAnalyticsAccountName,
                        parameters: new UpdateDataLakeAnalyticsAccountParameters
                {
                    Tags = new Dictionary <string, string>
                    {
                        { "updatedKey", "updatedValue" }
                    },
                    NewTier = TierType.Consumption
                }
                        );

                Assert.Equal(DataLakeAnalyticsAccountStatus.Succeeded, responseUpdate.ProvisioningState);

                // Get the account and ensure that all the values are properly set.
                var responseUpdateGet =
                    clientToUse.Accounts.Get(
                        commonData.ResourceGroupName,
                        commonData.DataLakeAnalyticsAccountName
                        );

                Assert.NotNull(responseUpdate.Id);
                Assert.Contains(responseGet.Id, responseUpdateGet.Id);
                Assert.Equal(responseGet.Location, responseUpdateGet.Location);
                Assert.Equal(responseGet.Name, responseUpdateGet.Name);
                Assert.Equal(responseGet.Type, responseUpdateGet.Type);

                // Verify the new tags and tier
                Assert.True(responseUpdateGet.Tags.Count == 1);
                Assert.True(responseUpdateGet.Tags.ContainsKey("updatedKey"));
                Assert.True(responseUpdateGet.Tags.Values.Contains("updatedValue"));
                Assert.Equal(TierType.Commitment100AUHours, responseUpdateGet.CurrentTier);
                Assert.Equal(TierType.Consumption, responseUpdateGet.NewTier);

                // Create another account and ensure that list account returns both
                clientToUse.Accounts.Create(
                    commonData.ResourceGroupName,
                    commonData.DataLakeAnalyticsAccountName + "secondacct",
                    new CreateDataLakeAnalyticsAccountParameters
                {
                    Location = commonData.Location,
                    DefaultDataLakeStoreAccount = commonData.DataLakeStoreAccountName,
                    DataLakeStoreAccounts       = new List <AddDataLakeStoreWithAccountParameters>
                    {
                        new AddDataLakeStoreWithAccountParameters
                        {
                            Name   = commonData.DataLakeStoreAccountName,
                            Suffix = commonData.DataLakeStoreAccountSuffix
                        }
                    },
                }
                    );

                var listResponse = clientToUse.Accounts.List();

                // Assert that there are at least two accounts in the list
                Assert.True(listResponse.Count() > 1);

                // Now list with the resource group
                listResponse = clientToUse.Accounts.ListByResourceGroup(commonData.ResourceGroupName);

                // Assert that there are at least two accounts in the list
                Assert.True(listResponse.Count() > 1);

                // Add, list and remove a data source to the first account
                // Validate the data source doesn't exist first
                Assert.False(
                    clientToUse.Accounts.DataLakeStoreAccountExists(
                        commonData.ResourceGroupName,
                        commonData.DataLakeAnalyticsAccountName,
                        commonData.SecondDataLakeStoreAccountName
                        )
                    );

                clientToUse.DataLakeStoreAccounts.Add(
                    commonData.ResourceGroupName,
                    commonData.DataLakeAnalyticsAccountName,
                    commonData.SecondDataLakeStoreAccountName,
                    new AddDataLakeStoreParameters
                {
                    Suffix = commonData.DataLakeStoreAccountSuffix
                }
                    );

                // Verify that the store account does exist now
                Assert.True(
                    clientToUse.Accounts.DataLakeStoreAccountExists(
                        commonData.ResourceGroupName,
                        commonData.DataLakeAnalyticsAccountName,
                        commonData.SecondDataLakeStoreAccountName
                        )
                    );

                // Get the data sources and confirm there are 2
                var getDataSourceResponse =
                    clientToUse.DataLakeStoreAccounts.ListByAccount(
                        commonData.ResourceGroupName,
                        commonData.DataLakeAnalyticsAccountName
                        );

                Assert.Equal(2, getDataSourceResponse.Count());

                // Get the specific data source
                var getSingleDataSourceResponse =
                    clientToUse.DataLakeStoreAccounts.Get(
                        commonData.ResourceGroupName,
                        commonData.DataLakeAnalyticsAccountName,
                        commonData.SecondDataLakeStoreAccountName
                        );

                Assert.Equal(commonData.SecondDataLakeStoreAccountName, getSingleDataSourceResponse.Name);
                Assert.Equal(commonData.SecondDataLakeStoreAccountSuffix, getSingleDataSourceResponse.Suffix);

                // Remove the data source we added
                clientToUse.DataLakeStoreAccounts.Delete(
                    commonData.ResourceGroupName,
                    commonData.DataLakeAnalyticsAccountName,
                    commonData.SecondDataLakeStoreAccountName
                    );

                // Confirm that there is now only one data source.
                getDataSourceResponse =
                    clientToUse.DataLakeStoreAccounts.ListByAccount(
                        commonData.ResourceGroupName,
                        commonData.DataLakeAnalyticsAccountName
                        );

                Assert.True(getDataSourceResponse.Count() == 1);

                // Add, list and remove an azure blob source to the first account
                // Verify the blob doesn't exist
                Assert.False(
                    clientToUse.Accounts.StorageAccountExists(
                        commonData.ResourceGroupName,
                        commonData.DataLakeAnalyticsAccountName,
                        commonData.StorageAccountName
                        )
                    );

                clientToUse.StorageAccounts.Add(
                    commonData.ResourceGroupName,
                    commonData.DataLakeAnalyticsAccountName,
                    commonData.StorageAccountName,
                    new AddStorageAccountParameters
                {
                    Suffix    = commonData.StorageAccountSuffix,
                    AccessKey = commonData.StorageAccountAccessKey
                }
                    );

                // Verify the blob exists now
                Assert.True(
                    clientToUse.Accounts.StorageAccountExists(
                        commonData.ResourceGroupName,
                        commonData.DataLakeAnalyticsAccountName,
                        commonData.StorageAccountName
                        )
                    );

                // Get the data sources and confirm there is 1
                var getDataSourceBlobResponse =
                    clientToUse.StorageAccounts.ListByAccount(
                        commonData.ResourceGroupName,
                        commonData.DataLakeAnalyticsAccountName
                        );

                Assert.True(getDataSourceBlobResponse.Count() == 1);

                // Get the specific data source we added and confirm that it has the same properties
                var getSingleDataSourceBlobResponse =
                    clientToUse.StorageAccounts.Get(
                        commonData.ResourceGroupName,
                        commonData.DataLakeAnalyticsAccountName,
                        commonData.StorageAccountName
                        );

                Assert.Equal(commonData.StorageAccountName, getSingleDataSourceBlobResponse.Name);
                Assert.Equal(commonData.StorageAccountSuffix, getSingleDataSourceBlobResponse.Suffix);

                // Remove the data source we added
                clientToUse.StorageAccounts.Delete(
                    commonData.ResourceGroupName,
                    commonData.DataLakeAnalyticsAccountName,
                    commonData.StorageAccountName
                    );

                // Confirm that there no azure data sources.
                getDataSourceBlobResponse =
                    clientToUse.StorageAccounts.ListByAccount(
                        commonData.ResourceGroupName,
                        commonData.DataLakeAnalyticsAccountName
                        );

                Assert.True(getDataSourceBlobResponse.Count() == 0);

                // Check that Locations_GetCapability and Operations_List are functional
                var responseGetCapability =
                    clientToUse.Locations.GetCapability(
                        commonData.Location.Replace(" ", "")
                        );

                Assert.NotNull(responseGetCapability);

                var responseListOps = clientToUse.Operations.List();

                Assert.NotNull(responseListOps);

                // Delete the account and confirm that it is deleted.
                clientToUse.Accounts.Delete(
                    commonData.ResourceGroupName,
                    commonData.DataLakeAnalyticsAccountName + "secondacct"
                    );

                // Delete the account again and make sure it continues to result in a successful code.
                clientToUse.Accounts.Delete(
                    commonData.ResourceGroupName,
                    commonData.DataLakeAnalyticsAccountName + "secondacct"
                    );

                // Delete the account with its old name, which should also succeed.
                clientToUse.Accounts.Delete(
                    commonData.ResourceGroupName,
                    commonData.DataLakeAnalyticsAccountName
                    );
            }
        }
예제 #8
0
        public void ComputePolicyCRUDTest()
        {
            using (var context = MockContext.Start(this.GetType()))
            {
                commonData = new CommonTestFixture(context, true);
                var clientToUse         = this.GetDataLakeAnalyticsAccountManagementClient(context);
                var userPolicyObjectId  = new Guid("8ce05900-7a9e-4895-b3f0-0fbcee507803");
                var userPolicyName      = TestUtilities.GenerateName("adlapolicy1");
                var groupPolicyObjectId = new Guid("0583cfd7-60f5-43f0-9597-68b85591fc69");
                var groupPolicyName     = TestUtilities.GenerateName("adlapolicy2");
                var adlaAccountName     = TestUtilities.GenerateName("adlaacct1");

                // Ensure the account doesn't exist
                Assert.False(
                    clientToUse.Accounts.Exists(
                        commonData.ResourceGroupName,
                        adlaAccountName
                        )
                    );

                // Create a test account
                var responseCreate =
                    clientToUse.Accounts.Create(
                        commonData.ResourceGroupName,
                        adlaAccountName,
                        parameters: new CreateDataLakeAnalyticsAccountParameters
                {
                    Location = commonData.Location,
                    DefaultDataLakeStoreAccount = commonData.DataLakeStoreAccountName,
                    DataLakeStoreAccounts       = new List <AddDataLakeStoreWithAccountParameters>
                    {
                        new AddDataLakeStoreWithAccountParameters
                        {
                            Name   = commonData.DataLakeStoreAccountName,
                            Suffix = commonData.DataLakeStoreAccountSuffix
                        }
                    },
                    NewTier         = TierType.Commitment100AUHours,
                    ComputePolicies = new List <CreateComputePolicyWithAccountParameters>
                    {
                        new CreateComputePolicyWithAccountParameters
                        {
                            Name       = userPolicyName,
                            ObjectId   = userPolicyObjectId,
                            ObjectType = AADObjectType.User,
                            MaxDegreeOfParallelismPerJob = 1,
                            MinPriorityPerJob            = 1,
                        }
                    }
                }
                        );

                // Get the account and ensure that all the values are properly set.
                var responseGet =
                    clientToUse.Accounts.Get(
                        commonData.ResourceGroupName,
                        adlaAccountName
                        );

                // Validate compute policies are set on creation.
                Assert.True(responseGet.ComputePolicies.Count == 1);
                Assert.Equal(responseGet.ComputePolicies.ToList()[0].Name, userPolicyName);

                // Validate compute policy CRUD
                // Add another account
                var computePolicy =
                    clientToUse.ComputePolicies.CreateOrUpdate(
                        commonData.ResourceGroupName,
                        adlaAccountName,
                        groupPolicyName,
                        new CreateOrUpdateComputePolicyParameters
                {
                    ObjectId   = groupPolicyObjectId,
                    ObjectType = AADObjectType.Group,
                    MaxDegreeOfParallelismPerJob = 1,
                    MinPriorityPerJob            = 1,
                }
                        );

                Assert.Equal(1, computePolicy.MaxDegreeOfParallelismPerJob);
                Assert.Equal(1, computePolicy.MinPriorityPerJob);
                Assert.Equal(groupPolicyObjectId, computePolicy.ObjectId);
                Assert.Equal(AADObjectType.Group, computePolicy.ObjectType);

                // Get the compute policy
                computePolicy =
                    clientToUse.ComputePolicies.Get(
                        commonData.ResourceGroupName,
                        adlaAccountName,
                        groupPolicyName
                        );

                Assert.Equal(1, computePolicy.MaxDegreeOfParallelismPerJob);
                Assert.Equal(1, computePolicy.MinPriorityPerJob);
                Assert.Equal(groupPolicyObjectId, computePolicy.ObjectId);
                Assert.Equal(AADObjectType.Group, computePolicy.ObjectType);

                // List all policies
                var policyList =
                    clientToUse.ComputePolicies.ListByAccount(
                        commonData.ResourceGroupName,
                        adlaAccountName
                        );

                Assert.Equal(2, policyList.Count());

                // Remove the new policy
                clientToUse.ComputePolicies.Delete(
                    commonData.ResourceGroupName,
                    adlaAccountName,
                    groupPolicyName
                    );

                policyList =
                    clientToUse.ComputePolicies.ListByAccount(
                        commonData.ResourceGroupName,
                        adlaAccountName
                        );

                Assert.True(policyList.Count() == 1);

                // Delete the account
                clientToUse.Accounts.Delete(commonData.ResourceGroupName, adlaAccountName);
            }
        }
        public void CreateGetUpdateDeleteTest()
        {
            TestUtilities.StartTest();
            try
            {
                UndoContext.Current.Start();
                CommonTestFixture commonData = new CommonTestFixture();
                var clientToUse = this.GetDataLakeAnalyticsManagementClient();

                // Create a test account
                AzureAsyncOperationResponse responseCreate =
                    clientToUse.DataLakeAnalyticsAccount.Create(commonData.ResourceGroupName,
                        parameters: new DataLakeAnalyticsAccountCreateOrUpdateParameters
                        {
                            DataLakeAnalyticsAccount = new DataLakeAnalyticsAccount
                            {
                                Name = commonData.DataLakeAnalyticsAccountName,
                                Location = commonData.Location,
                                Properties = new DataLakeAnalyticsAccountProperties
                                {
                                    DefaultDataLakeStoreAccount = commonData.DataLakeStoreAccountName,
                                    DataLakeStoreAccounts = new List<DataLakeStoreAccount>
                                    {
                                        new DataLakeStoreAccount
                                        {
                                            Name = commonData.DataLakeStoreAccountName,
                                            Properties = new DataLakeStoreAccountProperties
                                            {
                                                Suffix = commonData.DataLakeStoreAccountSuffix
                                            }
                                        }
                                    }
                                },
                                Tags = new Dictionary<string, string>
                                {
                                    { "testkey","testvalue" }
                                }
                            }
                        });

                Assert.Equal(HttpStatusCode.OK, responseCreate.StatusCode);

                // get the account and ensure that all the values are properly set.
                var responseGet = clientToUse.DataLakeAnalyticsAccount.Get(commonData.ResourceGroupName, commonData.DataLakeAnalyticsAccountName);

                // validate the account creation process
                Assert.True(responseGet.DataLakeAnalyticsAccount.Properties.ProvisioningState == DataLakeAnalyticsAccountStatus.Creating || responseGet.DataLakeAnalyticsAccount.Properties.ProvisioningState == DataLakeAnalyticsAccountStatus.Succeeded);
                Assert.NotNull(responseCreate.RequestId);
                Assert.NotNull(responseGet.RequestId);
                Assert.Contains(commonData.DataLakeAnalyticsAccountName, responseGet.DataLakeAnalyticsAccount.Id);
                Assert.Equal(commonData.Location, responseGet.DataLakeAnalyticsAccount.Location);
                Assert.Equal(commonData.DataLakeAnalyticsAccountName, responseGet.DataLakeAnalyticsAccount.Name);
                Assert.Equal("Microsoft.DataLakeAnalytics/accounts", responseGet.DataLakeAnalyticsAccount.Type);

                Assert.True(responseGet.DataLakeAnalyticsAccount.Properties.DataLakeStoreAccounts.Count == 1);
                Assert.True(responseGet.DataLakeAnalyticsAccount.Properties.DataLakeStoreAccounts.ToList()[0].Name.Equals(commonData.DataLakeStoreAccountName));

                // wait for provisioning state to be Succeeded
                // we will wait a maximum of 15 minutes for this to happen and then report failures
                int timeToWaitInMinutes = 15;
                int minutesWaited = 0;
                while (responseGet.DataLakeAnalyticsAccount.Properties.ProvisioningState != DataLakeAnalyticsAccountStatus.Succeeded && responseGet.DataLakeAnalyticsAccount.Properties.ProvisioningState != DataLakeAnalyticsAccountStatus.Failed && minutesWaited <= timeToWaitInMinutes)
                {
                    TestUtilities.Wait(60000); // Wait for one minute and then go again.
                    minutesWaited++;
                    responseGet = clientToUse.DataLakeAnalyticsAccount.Get(commonData.ResourceGroupName, commonData.DataLakeAnalyticsAccountName);
                }

                // Confirm that the account creation did succeed
                Assert.True(responseGet.DataLakeAnalyticsAccount.Properties.ProvisioningState == DataLakeAnalyticsAccountStatus.Succeeded);

                // Update the account and confirm the updates make it in.
                var newAccount = responseGet.DataLakeAnalyticsAccount;
                var firstStorageAccountName = newAccount.Properties.DataLakeStoreAccounts.ToList()[0].Name;
                newAccount.Tags = new Dictionary<string, string>
                {
                    {"updatedKey", "updatedValue"}
                };

                // need to null out deep properties to prevent an error
                newAccount.Properties.DataLakeStoreAccounts = null;
                newAccount.Properties.StorageAccounts = null;

                var updateResponse = clientToUse.DataLakeAnalyticsAccount.Update(commonData.ResourceGroupName, new DataLakeAnalyticsAccountCreateOrUpdateParameters
                    {
                        DataLakeAnalyticsAccount = newAccount,
                    });

                Assert.Equal(HttpStatusCode.OK, updateResponse.StatusCode);
                Assert.Equal(updateResponse.Status, OperationStatus.Succeeded);

                // get the account and ensure that all the values are properly set.
                var updateResponseGet = clientToUse.DataLakeAnalyticsAccount.Get(commonData.ResourceGroupName, commonData.DataLakeAnalyticsAccountName);

                Assert.NotNull(updateResponse.RequestId);
                Assert.Contains(responseGet.DataLakeAnalyticsAccount.Id, updateResponseGet.DataLakeAnalyticsAccount.Id);
                Assert.Equal(responseGet.DataLakeAnalyticsAccount.Location, updateResponseGet.DataLakeAnalyticsAccount.Location);
                Assert.Equal(newAccount.Name, updateResponseGet.DataLakeAnalyticsAccount.Name);
                Assert.Equal(responseGet.DataLakeAnalyticsAccount.Type, updateResponseGet.DataLakeAnalyticsAccount.Type);

                // verify the new tags. NOTE: sequence equal is not ideal if we have more than 1 tag, since the ordering can change.
                Assert.True(updateResponseGet.DataLakeAnalyticsAccount.Tags.SequenceEqual(newAccount.Tags));
                Assert.True(updateResponseGet.DataLakeAnalyticsAccount.Properties.DataLakeStoreAccounts.Count == 1);
                Assert.True(updateResponseGet.DataLakeAnalyticsAccount.Properties.DataLakeStoreAccounts.ToList()[0].Name.Equals(firstStorageAccountName));

                // Create another account and ensure that list account returns both
                var accountToChange = responseGet.DataLakeAnalyticsAccount;
                accountToChange.Name = accountToChange.Name + "secondacct";
                var parameters = new DataLakeAnalyticsAccountCreateOrUpdateParameters
                {
                    DataLakeAnalyticsAccount = accountToChange
                };

                clientToUse.DataLakeAnalyticsAccount.Create(commonData.ResourceGroupName, parameters);

                DataLakeAnalyticsAccountListResponse listResponse = clientToUse.DataLakeAnalyticsAccount.List(commonData.ResourceGroupName, null);

                // Assert that there are at least two accounts in the list
                Assert.True(listResponse.Value.Count > 1);

                // Add, list and remove a data source to the first account
                var addDataSourceResponse =
                    clientToUse.DataLakeAnalyticsAccount.AddDataLakeStoreAccount(commonData.ResourceGroupName,
                        commonData.DataLakeAnalyticsAccountName, commonData.SecondDataLakeStoreAccountName,
                        new AddDataLakeStoreParameters
                        {
                            Properties =
                                new DataLakeStoreAccountProperties {Suffix = commonData.DataLakeStoreAccountSuffix}
                        });

                Assert.Equal(HttpStatusCode.OK, addDataSourceResponse.StatusCode);

                // Get the data sources and confirm there are 2
                var getDataSourceResponse =
                    clientToUse.DataLakeAnalyticsAccount.ListDataLakeStoreAccounts(commonData.ResourceGroupName,
                        commonData.DataLakeAnalyticsAccountName, null);

                Assert.Equal(HttpStatusCode.OK, getDataSourceResponse.StatusCode);
                Assert.Equal(2, getDataSourceResponse.Value.Count);

                // get the specific data source
                var getSingleDataSourceResponse =
                    clientToUse.DataLakeAnalyticsAccount.GetDataLakeStoreAccount(commonData.ResourceGroupName,
                        commonData.DataLakeAnalyticsAccountName, commonData.SecondDataLakeStoreAccountName);

                Assert.Equal(HttpStatusCode.OK, getSingleDataSourceResponse.StatusCode);
                Assert.Equal(commonData.SecondDataLakeStoreAccountName, getSingleDataSourceResponse.DataLakeStoreAccount.Name);
                Assert.Equal(commonData.SecondDataLakeStoreAccountSuffix, getSingleDataSourceResponse.DataLakeStoreAccount.Properties.Suffix);

                // Remove the data source we added
                var removeDataSourceResponse =
                    clientToUse.DataLakeAnalyticsAccount.DeleteDataLakeStoreAccount(commonData.ResourceGroupName,
                        commonData.DataLakeAnalyticsAccountName, commonData.SecondDataLakeStoreAccountName);

                Assert.Equal(HttpStatusCode.OK, removeDataSourceResponse.StatusCode);

                // Confirm that there is now only one data source.
                getDataSourceResponse =
                    clientToUse.DataLakeAnalyticsAccount.ListDataLakeStoreAccounts(commonData.ResourceGroupName,
                        commonData.DataLakeAnalyticsAccountName, null);

                Assert.Equal(HttpStatusCode.OK, getDataSourceResponse.StatusCode);
                Assert.Equal(1, getDataSourceResponse.Value.Count);

                // Add, list and remove an azure blob source to the first account
                var addDataSourceBlobResponse =
                    clientToUse.DataLakeAnalyticsAccount.AddStorageAccount(commonData.ResourceGroupName,
                        commonData.DataLakeAnalyticsAccountName, commonData.StorageAccountName,
                        new AddStorageAccountParameters
                        {
                            Properties =
                                new StorageAccountProperties
                                {
                                    Suffix = commonData.StorageAccountSuffix,
                                    AccessKey = commonData.StorageAccountAccessKey
                                }
                        });

                Assert.Equal(HttpStatusCode.OK, addDataSourceBlobResponse.StatusCode);

                // Get the data sources and confirm there is 1
                var getDataSourceBlobResponse =
                    clientToUse.DataLakeAnalyticsAccount.ListStorageAccounts(commonData.ResourceGroupName,
                        commonData.DataLakeAnalyticsAccountName, null);

                Assert.Equal(HttpStatusCode.OK, getDataSourceBlobResponse.StatusCode);
                Assert.Equal(1, getDataSourceBlobResponse.Value.Count);

                // Get the specific data source we added and confirm that it has the same properties
                var getSingleDataSourceBlobResponse =
                    clientToUse.DataLakeAnalyticsAccount.GetStorageAccount(commonData.ResourceGroupName,
                        commonData.DataLakeAnalyticsAccountName, commonData.StorageAccountName);

                Assert.Equal(HttpStatusCode.OK, getSingleDataSourceBlobResponse.StatusCode);
                Assert.Equal(commonData.StorageAccountName, getSingleDataSourceBlobResponse.StorageAccount.Name);
                Assert.True(string.IsNullOrEmpty(getSingleDataSourceBlobResponse.StorageAccount.Properties.AccessKey));
                Assert.Equal(commonData.StorageAccountSuffix, getSingleDataSourceBlobResponse.StorageAccount.Properties.Suffix);

                // Remove the data source we added
                var removeDataSourceBlobResponse =
                    clientToUse.DataLakeAnalyticsAccount.DeleteStorageAccount(commonData.ResourceGroupName,
                        commonData.DataLakeAnalyticsAccountName, commonData.StorageAccountName);

                Assert.Equal(HttpStatusCode.OK, removeDataSourceBlobResponse.StatusCode);

                // Confirm that there no azure data sources.
                getDataSourceBlobResponse =
                    clientToUse.DataLakeAnalyticsAccount.ListStorageAccounts(commonData.ResourceGroupName,
                        commonData.DataLakeAnalyticsAccountName, null);

                Assert.Equal(HttpStatusCode.OK, getDataSourceResponse.StatusCode);
                Assert.Equal(0, getDataSourceBlobResponse.Value.Count);

                // Delete the account and confirm that it is deleted.
                AzureOperationResponse deleteResponse = clientToUse.DataLakeAnalyticsAccount.Delete(commonData.ResourceGroupName, newAccount.Name);

                // define the list of accepted status codes when deleting an account.
                List<HttpStatusCode> acceptedStatusCodes = new List<HttpStatusCode>
            {
                HttpStatusCode.OK,
                HttpStatusCode.Accepted,
                HttpStatusCode.NotFound,
                HttpStatusCode.NoContent
            };

                Assert.Contains<HttpStatusCode>(deleteResponse.StatusCode, acceptedStatusCodes);
                Assert.NotNull(deleteResponse.RequestId);

                // delete the account again and make sure it continues to result in a succesful code.
                deleteResponse = clientToUse.DataLakeAnalyticsAccount.Delete(commonData.ResourceGroupName, newAccount.Name);
                Assert.Contains<HttpStatusCode>(deleteResponse.StatusCode, acceptedStatusCodes);

                // delete the account with its old name, which should also succeed.
                deleteResponse = clientToUse.DataLakeAnalyticsAccount.Delete(commonData.ResourceGroupName, commonData.DataLakeAnalyticsAccountName);
                Assert.Contains<HttpStatusCode>(deleteResponse.StatusCode, acceptedStatusCodes);

                // delete the second account that was created to ensure that we properly clean up after ourselves.
                deleteResponse = clientToUse.DataLakeAnalyticsAccount.Delete(commonData.ResourceGroupName, accountToChange.Name);
                Assert.Contains<HttpStatusCode>(deleteResponse.StatusCode, acceptedStatusCodes);
            }
            finally
            {
                // we don't catch any exceptions, those should all be bubbled up.
                UndoContext.Current.UndoAll();
                TestUtilities.EndTest();
            }
        }
        public void CreateGetUpdateDeleteTest()
        {
            TestUtilities.StartTest();
            try
            {
                UndoContext.Current.Start();
                CommonTestFixture commonData = new CommonTestFixture();
                var clientToUse = this.GetDataLakeAnalyticsManagementClient();

                // Create a test account
                AzureAsyncOperationResponse responseCreate =
                    clientToUse.DataLakeAnalyticsAccount.Create(commonData.ResourceGroupName,
                                                                parameters: new DataLakeAnalyticsAccountCreateOrUpdateParameters
                {
                    DataLakeAnalyticsAccount = new DataLakeAnalyticsAccount
                    {
                        Name       = commonData.DataLakeAnalyticsAccountName,
                        Location   = commonData.Location,
                        Properties = new DataLakeAnalyticsAccountProperties
                        {
                            DefaultDataLakeStoreAccount = commonData.DataLakeStoreAccountName,
                            DataLakeStoreAccounts       = new List <DataLakeStoreAccount>
                            {
                                new DataLakeStoreAccount
                                {
                                    Name       = commonData.DataLakeStoreAccountName,
                                    Properties = new DataLakeStoreAccountProperties
                                    {
                                        Suffix = commonData.DataLakeStoreAccountSuffix
                                    }
                                }
                            }
                        },
                        Tags = new Dictionary <string, string>
                        {
                            { "testkey", "testvalue" }
                        }
                    }
                });

                Assert.Equal(HttpStatusCode.OK, responseCreate.StatusCode);

                // get the account and ensure that all the values are properly set.
                var responseGet = clientToUse.DataLakeAnalyticsAccount.Get(commonData.ResourceGroupName, commonData.DataLakeAnalyticsAccountName);

                // validate the account creation process
                Assert.True(responseGet.DataLakeAnalyticsAccount.Properties.ProvisioningState == DataLakeAnalyticsAccountStatus.Creating || responseGet.DataLakeAnalyticsAccount.Properties.ProvisioningState == DataLakeAnalyticsAccountStatus.Succeeded);
                Assert.NotNull(responseCreate.RequestId);
                Assert.NotNull(responseGet.RequestId);
                Assert.Contains(commonData.DataLakeAnalyticsAccountName, responseGet.DataLakeAnalyticsAccount.Id);
                Assert.Equal(commonData.Location, responseGet.DataLakeAnalyticsAccount.Location);
                Assert.Equal(commonData.DataLakeAnalyticsAccountName, responseGet.DataLakeAnalyticsAccount.Name);
                Assert.Equal("Microsoft.DataLakeAnalytics/accounts", responseGet.DataLakeAnalyticsAccount.Type);

                Assert.True(responseGet.DataLakeAnalyticsAccount.Properties.DataLakeStoreAccounts.Count == 1);
                Assert.True(responseGet.DataLakeAnalyticsAccount.Properties.DataLakeStoreAccounts.ToList()[0].Name.Equals(commonData.DataLakeStoreAccountName));

                // wait for provisioning state to be Succeeded
                // we will wait a maximum of 15 minutes for this to happen and then report failures
                int timeToWaitInMinutes = 15;
                int minutesWaited       = 0;
                while (responseGet.DataLakeAnalyticsAccount.Properties.ProvisioningState != DataLakeAnalyticsAccountStatus.Succeeded && responseGet.DataLakeAnalyticsAccount.Properties.ProvisioningState != DataLakeAnalyticsAccountStatus.Failed && minutesWaited <= timeToWaitInMinutes)
                {
                    TestUtilities.Wait(60000); // Wait for one minute and then go again.
                    minutesWaited++;
                    responseGet = clientToUse.DataLakeAnalyticsAccount.Get(commonData.ResourceGroupName, commonData.DataLakeAnalyticsAccountName);
                }

                // Confirm that the account creation did succeed
                Assert.True(responseGet.DataLakeAnalyticsAccount.Properties.ProvisioningState == DataLakeAnalyticsAccountStatus.Succeeded);

                // Update the account and confirm the updates make it in.
                var newAccount = responseGet.DataLakeAnalyticsAccount;
                var firstStorageAccountName = newAccount.Properties.DataLakeStoreAccounts.ToList()[0].Name;
                newAccount.Tags = new Dictionary <string, string>
                {
                    { "updatedKey", "updatedValue" }
                };

                // need to null out deep properties to prevent an error
                newAccount.Properties.DataLakeStoreAccounts = null;
                newAccount.Properties.StorageAccounts       = null;

                var updateResponse = clientToUse.DataLakeAnalyticsAccount.Update(commonData.ResourceGroupName, new DataLakeAnalyticsAccountCreateOrUpdateParameters
                {
                    DataLakeAnalyticsAccount = newAccount,
                });

                Assert.Equal(HttpStatusCode.OK, updateResponse.StatusCode);
                Assert.Equal(updateResponse.Status, OperationStatus.Succeeded);

                // get the account and ensure that all the values are properly set.
                var updateResponseGet = clientToUse.DataLakeAnalyticsAccount.Get(commonData.ResourceGroupName, commonData.DataLakeAnalyticsAccountName);

                Assert.NotNull(updateResponse.RequestId);
                Assert.Contains(responseGet.DataLakeAnalyticsAccount.Id, updateResponseGet.DataLakeAnalyticsAccount.Id);
                Assert.Equal(responseGet.DataLakeAnalyticsAccount.Location, updateResponseGet.DataLakeAnalyticsAccount.Location);
                Assert.Equal(newAccount.Name, updateResponseGet.DataLakeAnalyticsAccount.Name);
                Assert.Equal(responseGet.DataLakeAnalyticsAccount.Type, updateResponseGet.DataLakeAnalyticsAccount.Type);

                // verify the new tags. NOTE: sequence equal is not ideal if we have more than 1 tag, since the ordering can change.
                Assert.True(updateResponseGet.DataLakeAnalyticsAccount.Tags.SequenceEqual(newAccount.Tags));
                Assert.True(updateResponseGet.DataLakeAnalyticsAccount.Properties.DataLakeStoreAccounts.Count == 1);
                Assert.True(updateResponseGet.DataLakeAnalyticsAccount.Properties.DataLakeStoreAccounts.ToList()[0].Name.Equals(firstStorageAccountName));

                // Create another account and ensure that list account returns both
                var accountToChange = responseGet.DataLakeAnalyticsAccount;
                accountToChange.Name = accountToChange.Name + "secondacct";
                var parameters = new DataLakeAnalyticsAccountCreateOrUpdateParameters
                {
                    DataLakeAnalyticsAccount = accountToChange
                };

                clientToUse.DataLakeAnalyticsAccount.Create(commonData.ResourceGroupName, parameters);

                DataLakeAnalyticsAccountListResponse listResponse = clientToUse.DataLakeAnalyticsAccount.List(commonData.ResourceGroupName, null);

                // Assert that there are at least two accounts in the list
                Assert.True(listResponse.Value.Count > 1);

                // Add, list and remove a data source to the first account
                var addDataSourceResponse =
                    clientToUse.DataLakeAnalyticsAccount.AddDataLakeStoreAccount(commonData.ResourceGroupName,
                                                                                 commonData.DataLakeAnalyticsAccountName, commonData.SecondDataLakeStoreAccountName,
                                                                                 new AddDataLakeStoreParameters
                {
                    Properties =
                        new DataLakeStoreAccountProperties {
                        Suffix = commonData.DataLakeStoreAccountSuffix
                    }
                });

                Assert.Equal(HttpStatusCode.OK, addDataSourceResponse.StatusCode);

                // Get the data sources and confirm there are 2
                var getDataSourceResponse =
                    clientToUse.DataLakeAnalyticsAccount.ListDataLakeStoreAccounts(commonData.ResourceGroupName,
                                                                                   commonData.DataLakeAnalyticsAccountName, null);

                Assert.Equal(HttpStatusCode.OK, getDataSourceResponse.StatusCode);
                Assert.Equal(2, getDataSourceResponse.Value.Count);

                // get the specific data source
                var getSingleDataSourceResponse =
                    clientToUse.DataLakeAnalyticsAccount.GetDataLakeStoreAccount(commonData.ResourceGroupName,
                                                                                 commonData.DataLakeAnalyticsAccountName, commonData.SecondDataLakeStoreAccountName);

                Assert.Equal(HttpStatusCode.OK, getSingleDataSourceResponse.StatusCode);
                Assert.Equal(commonData.SecondDataLakeStoreAccountName, getSingleDataSourceResponse.DataLakeStoreAccount.Name);
                Assert.Equal(commonData.SecondDataLakeStoreAccountSuffix, getSingleDataSourceResponse.DataLakeStoreAccount.Properties.Suffix);

                // Remove the data source we added
                var removeDataSourceResponse =
                    clientToUse.DataLakeAnalyticsAccount.DeleteDataLakeStoreAccount(commonData.ResourceGroupName,
                                                                                    commonData.DataLakeAnalyticsAccountName, commonData.SecondDataLakeStoreAccountName);

                Assert.Equal(HttpStatusCode.OK, removeDataSourceResponse.StatusCode);

                // Confirm that there is now only one data source.
                getDataSourceResponse =
                    clientToUse.DataLakeAnalyticsAccount.ListDataLakeStoreAccounts(commonData.ResourceGroupName,
                                                                                   commonData.DataLakeAnalyticsAccountName, null);

                Assert.Equal(HttpStatusCode.OK, getDataSourceResponse.StatusCode);
                Assert.Equal(1, getDataSourceResponse.Value.Count);

                // Add, list and remove an azure blob source to the first account
                var addDataSourceBlobResponse =
                    clientToUse.DataLakeAnalyticsAccount.AddStorageAccount(commonData.ResourceGroupName,
                                                                           commonData.DataLakeAnalyticsAccountName, commonData.StorageAccountName,
                                                                           new AddStorageAccountParameters
                {
                    Properties =
                        new StorageAccountProperties
                    {
                        Suffix    = commonData.StorageAccountSuffix,
                        AccessKey = commonData.StorageAccountAccessKey
                    }
                });

                Assert.Equal(HttpStatusCode.OK, addDataSourceBlobResponse.StatusCode);

                // Get the data sources and confirm there is 1
                var getDataSourceBlobResponse =
                    clientToUse.DataLakeAnalyticsAccount.ListStorageAccounts(commonData.ResourceGroupName,
                                                                             commonData.DataLakeAnalyticsAccountName, null);

                Assert.Equal(HttpStatusCode.OK, getDataSourceBlobResponse.StatusCode);
                Assert.Equal(1, getDataSourceBlobResponse.Value.Count);

                // Get the specific data source we added and confirm that it has the same properties
                var getSingleDataSourceBlobResponse =
                    clientToUse.DataLakeAnalyticsAccount.GetStorageAccount(commonData.ResourceGroupName,
                                                                           commonData.DataLakeAnalyticsAccountName, commonData.StorageAccountName);

                Assert.Equal(HttpStatusCode.OK, getSingleDataSourceBlobResponse.StatusCode);
                Assert.Equal(commonData.StorageAccountName, getSingleDataSourceBlobResponse.StorageAccount.Name);
                Assert.True(string.IsNullOrEmpty(getSingleDataSourceBlobResponse.StorageAccount.Properties.AccessKey));
                Assert.Equal(commonData.StorageAccountSuffix, getSingleDataSourceBlobResponse.StorageAccount.Properties.Suffix);

                // Remove the data source we added
                var removeDataSourceBlobResponse =
                    clientToUse.DataLakeAnalyticsAccount.DeleteStorageAccount(commonData.ResourceGroupName,
                                                                              commonData.DataLakeAnalyticsAccountName, commonData.StorageAccountName);

                Assert.Equal(HttpStatusCode.OK, removeDataSourceBlobResponse.StatusCode);

                // Confirm that there no azure data sources.
                getDataSourceBlobResponse =
                    clientToUse.DataLakeAnalyticsAccount.ListStorageAccounts(commonData.ResourceGroupName,
                                                                             commonData.DataLakeAnalyticsAccountName, null);

                Assert.Equal(HttpStatusCode.OK, getDataSourceResponse.StatusCode);
                Assert.Equal(0, getDataSourceBlobResponse.Value.Count);

                // Delete the account and confirm that it is deleted.
                AzureOperationResponse deleteResponse = clientToUse.DataLakeAnalyticsAccount.Delete(commonData.ResourceGroupName, newAccount.Name);

                // define the list of accepted status codes when deleting an account.
                List <HttpStatusCode> acceptedStatusCodes = new List <HttpStatusCode>
                {
                    HttpStatusCode.OK,
                    HttpStatusCode.Accepted,
                    HttpStatusCode.NotFound,
                    HttpStatusCode.NoContent
                };

                Assert.Contains <HttpStatusCode>(deleteResponse.StatusCode, acceptedStatusCodes);
                Assert.NotNull(deleteResponse.RequestId);

                // delete the account again and make sure it continues to result in a succesful code.
                deleteResponse = clientToUse.DataLakeAnalyticsAccount.Delete(commonData.ResourceGroupName, newAccount.Name);
                Assert.Contains <HttpStatusCode>(deleteResponse.StatusCode, acceptedStatusCodes);

                // delete the account with its old name, which should also succeed.
                deleteResponse = clientToUse.DataLakeAnalyticsAccount.Delete(commonData.ResourceGroupName, commonData.DataLakeAnalyticsAccountName);
                Assert.Contains <HttpStatusCode>(deleteResponse.StatusCode, acceptedStatusCodes);

                // delete the second account that was created to ensure that we properly clean up after ourselves.
                deleteResponse = clientToUse.DataLakeAnalyticsAccount.Delete(commonData.ResourceGroupName, accountToChange.Name);
                Assert.Contains <HttpStatusCode>(deleteResponse.StatusCode, acceptedStatusCodes);
            }
            finally
            {
                // we don't catch any exceptions, those should all be bubbled up.
                UndoContext.Current.UndoAll();
                TestUtilities.EndTest();
            }
        }
예제 #11
0
        public void CredentialCRUDTest()
        {
            using (var context = MockContext.Start(this.GetType().FullName))
            {
                commonData         = new CommonTestFixture(context);
                commonData.HostUrl =
                    commonData.DataLakeAnalyticsManagementHelper.TryCreateDataLakeAnalyticsAccount(
                        commonData.ResourceGroupName,
                        commonData.Location,
                        commonData.DataLakeStoreAccountName,
                        commonData.SecondDataLakeAnalyticsAccountName
                        );

                // Wait 5 minutes for the account setup
                TestUtilities.Wait(300000);

                commonData.DataLakeAnalyticsManagementHelper.CreateCatalog(
                    commonData.ResourceGroupName,
                    commonData.SecondDataLakeAnalyticsAccountName,
                    commonData.DatabaseName,
                    commonData.TableName,
                    commonData.TvfName,
                    commonData.ViewName,
                    commonData.ProcName
                    );

                using (var clientToUse = commonData.GetDataLakeAnalyticsCatalogManagementClient(context))
                {
                    // Create the credential
                    clientToUse.Catalog.CreateCredential(
                        commonData.SecondDataLakeAnalyticsAccountName,
                        commonData.DatabaseName,
                        commonData.SecretName,
                        new DataLakeAnalyticsCatalogCredentialCreateParameters
                    {
                        UserId   = TestUtilities.GenerateGuid("fakeUserId01").ToString(),
                        Password = commonData.SecretPwd,
                        Uri      = "https://adlasecrettest.contoso.com:443",
                    }
                        );

                    // Attempt to create the secret again, which should throw
                    Assert.Throws <CloudException>(
                        () =>
                        clientToUse.Catalog.CreateCredential(
                            commonData.SecondDataLakeAnalyticsAccountName,
                            commonData.DatabaseName,
                            commonData.SecretName,
                            new DataLakeAnalyticsCatalogCredentialCreateParameters
                    {
                        UserId   = TestUtilities.GenerateGuid("fakeUserId02").ToString(),
                        Password = commonData.SecretPwd,
                        Uri      = "https://adlasecrettest.contoso.com:443",
                    }
                            )
                        );

                    // Create another credential
                    var secondSecretName = commonData.SecretName + "dup";
                    clientToUse.Catalog.CreateCredential(
                        commonData.SecondDataLakeAnalyticsAccountName,
                        commonData.DatabaseName,
                        secondSecretName,
                        new DataLakeAnalyticsCatalogCredentialCreateParameters
                    {
                        UserId   = TestUtilities.GenerateGuid("fakeUserId03").ToString(),
                        Password = commonData.SecretPwd,
                        Uri      = "https://adlasecrettest.contoso.com:443",
                    }
                        );

                    // Get the credential and ensure the response contains a date.
                    var secretGetResponse =
                        clientToUse.Catalog.GetCredential(
                            commonData.SecondDataLakeAnalyticsAccountName,
                            commonData.DatabaseName, commonData.SecretName);

                    Assert.NotNull(secretGetResponse);
                    Assert.NotNull(secretGetResponse.Name);

                    // Get the Credential list
                    var credListResponse = clientToUse.Catalog.ListCredentials(
                        commonData.SecondDataLakeAnalyticsAccountName,
                        commonData.DatabaseName);

                    Assert.True(credListResponse.Count() >= 1);

                    // Look for the credential we created
                    Assert.Contains(credListResponse, cred => cred.Name.Equals(commonData.SecretName));

                    // Get the specific credential as well
                    var credGetResponse = clientToUse.Catalog.GetCredential(
                        commonData.SecondDataLakeAnalyticsAccountName,
                        commonData.DatabaseName, commonData.SecretName);
                    Assert.Equal(commonData.SecretName, credGetResponse.Name);

                    // Delete the credential
                    clientToUse.Catalog.DeleteCredential(
                        commonData.SecondDataLakeAnalyticsAccountName,
                        commonData.DatabaseName, commonData.SecretName,
                        new DataLakeAnalyticsCatalogCredentialDeleteParameters(commonData.SecretPwd));

                    // Try to get the credential which should throw
                    Assert.Throws <CloudException>(() => clientToUse.Catalog.GetCredential(
                                                       commonData.SecondDataLakeAnalyticsAccountName,
                                                       commonData.DatabaseName, commonData.SecretName));

                    // Re-create and delete the credential using cascade = true, which should still succeed.
                    clientToUse.Catalog.CreateCredential(
                        commonData.SecondDataLakeAnalyticsAccountName,
                        commonData.DatabaseName, commonData.SecretName,
                        new DataLakeAnalyticsCatalogCredentialCreateParameters
                    {
                        Password = commonData.SecretPwd,
                        Uri      = "https://adlasecrettest.contoso.com:443",
                        UserId   = TestUtilities.GenerateGuid("fakeUserId01").ToString()
                    });

                    clientToUse.Catalog.DeleteCredential(
                        commonData.SecondDataLakeAnalyticsAccountName,
                        commonData.DatabaseName, commonData.SecretName,
                        new DataLakeAnalyticsCatalogCredentialDeleteParameters(commonData.SecretPwd), cascade: true);

                    // Try to get the credential which should throw
                    Assert.Throws <CloudException>(() => clientToUse.Catalog.GetCredential(
                                                       commonData.SecondDataLakeAnalyticsAccountName,
                                                       commonData.DatabaseName, commonData.SecretName));

                    // TODO: once support is available for delete all credentials add tests here for that.
                }
            }
        }
예제 #12
0
        public void GetCatalogItemsTest()
        {
            // This test currently tests for Database, table TVF, view, types and procedure, and ACLs
            using (var context = MockContext.Start(this.GetType().FullName))
            {
                commonData         = new CommonTestFixture(context);
                commonData.HostUrl =
                    commonData.DataLakeAnalyticsManagementHelper.TryCreateDataLakeAnalyticsAccount(
                        commonData.ResourceGroupName,
                        commonData.Location,
                        commonData.DataLakeStoreAccountName,
                        commonData.SecondDataLakeAnalyticsAccountName
                        );

                // Wait 5 minutes for the account setup
                TestUtilities.Wait(300000);

                commonData.DataLakeAnalyticsManagementHelper.CreateCatalog(
                    commonData.ResourceGroupName,
                    commonData.SecondDataLakeAnalyticsAccountName,
                    commonData.DatabaseName,
                    commonData.TableName,
                    commonData.TvfName,
                    commonData.ViewName,
                    commonData.ProcName);

                using (var clientToUse = commonData.GetDataLakeAnalyticsCatalogManagementClient(context))
                {
                    var dbListResponse =
                        clientToUse.Catalog.ListDatabases(
                            commonData.SecondDataLakeAnalyticsAccountName
                            );

                    Assert.True(dbListResponse.Count() >= 1);

                    // Look for the db we created
                    Assert.Contains(dbListResponse, db => db.Name.Equals(commonData.DatabaseName));

                    // Get the specific Database as well
                    var dbGetResponse =
                        clientToUse.Catalog.GetDatabase(
                            commonData.SecondDataLakeAnalyticsAccountName,
                            commonData.DatabaseName
                            );

                    Assert.Equal(commonData.DatabaseName, dbGetResponse.Name);

                    // Get the table list
                    var tableListResponse =
                        clientToUse.Catalog.ListTables(
                            commonData.SecondDataLakeAnalyticsAccountName,
                            commonData.DatabaseName,
                            CommonTestFixture.SchemaName
                            );

                    Assert.True(tableListResponse.Count() >= 1);
                    Assert.True(tableListResponse.ElementAt(0).ColumnList != null && tableListResponse.ElementAt(0).ColumnList.Count() > 0);

                    // Look for the table we created
                    Assert.Contains(tableListResponse, table => table.Name.Equals(commonData.TableName));

                    // Get the table list with only basic info
                    tableListResponse =
                        clientToUse.Catalog.ListTables(
                            commonData.SecondDataLakeAnalyticsAccountName,
                            commonData.DatabaseName,
                            CommonTestFixture.SchemaName,
                            basic: true
                            );

                    Assert.True(tableListResponse.Count() >= 1);
                    Assert.True(tableListResponse.ElementAt(0).ColumnList == null || tableListResponse.ElementAt(0).ColumnList.Count() == 0);

                    // Get the table list in just the db
                    tableListResponse =
                        clientToUse.Catalog.ListTablesByDatabase(
                            commonData.SecondDataLakeAnalyticsAccountName,
                            commonData.DatabaseName
                            );

                    Assert.True(tableListResponse.Count() >= 1);
                    Assert.True(tableListResponse.ElementAt(0).ColumnList != null && tableListResponse.ElementAt(0).ColumnList.Count > 0);

                    // Look for the table we created
                    Assert.Contains(tableListResponse, table => table.Name.Equals(commonData.TableName));

                    // Get the table list in the db with only basic info
                    tableListResponse =
                        clientToUse.Catalog.ListTablesByDatabase(
                            commonData.SecondDataLakeAnalyticsAccountName,
                            commonData.DatabaseName,
                            basic: true
                            );

                    Assert.True(tableListResponse.Count() >= 1);
                    Assert.True(tableListResponse.ElementAt(0).ColumnList == null || tableListResponse.ElementAt(0).ColumnList.Count() == 0);

                    // Get preview of the specific table
                    var tablePreviewGetResponse =
                        clientToUse.Catalog.PreviewTable(
                            commonData.SecondDataLakeAnalyticsAccountName,
                            commonData.DatabaseName,
                            CommonTestFixture.SchemaName,
                            commonData.TableName
                            );

                    Assert.True(tablePreviewGetResponse.TotalRowCount > 0);
                    Assert.True(tablePreviewGetResponse.TotalColumnCount > 0);
                    Assert.True(tablePreviewGetResponse.Rows != null && tablePreviewGetResponse.Rows.Count() > 0);
                    Assert.True(tablePreviewGetResponse.Schema != null && tablePreviewGetResponse.Schema.Count() > 0);
                    Assert.NotNull(tablePreviewGetResponse.Schema[0].Name);
                    Assert.NotNull(tablePreviewGetResponse.Schema[0].Type);

                    // Get the specific table as well
                    var tableGetResponse =
                        clientToUse.Catalog.GetTable(
                            commonData.SecondDataLakeAnalyticsAccountName,
                            commonData.DatabaseName,
                            CommonTestFixture.SchemaName,
                            commonData.TableName
                            );

                    Assert.Equal(commonData.TableName, tableGetResponse.Name);

                    // Get the tvf list
                    var tvfListResponse =
                        clientToUse.Catalog.ListTableValuedFunctions(
                            commonData.SecondDataLakeAnalyticsAccountName,
                            commonData.DatabaseName,
                            CommonTestFixture.SchemaName
                            );

                    Assert.True(tvfListResponse.Count() >= 1);

                    // Look for the tvf we created
                    Assert.Contains(tvfListResponse, tvf => tvf.Name.Equals(commonData.TvfName));

                    // Get tvf list in the database
                    tvfListResponse =
                        clientToUse.Catalog.ListTableValuedFunctionsByDatabase(
                            commonData.SecondDataLakeAnalyticsAccountName,
                            commonData.DatabaseName
                            );

                    Assert.True(tvfListResponse.Count() >= 1);

                    // look for the tvf we created
                    Assert.Contains(tvfListResponse, tvf => tvf.Name.Equals(commonData.TvfName));

                    // Get the specific tvf as well
                    var tvfGetResponse =
                        clientToUse.Catalog.GetTableValuedFunction(
                            commonData.SecondDataLakeAnalyticsAccountName,
                            commonData.DatabaseName,
                            CommonTestFixture.SchemaName,
                            commonData.TvfName
                            );

                    Assert.Equal(commonData.TvfName, tvfGetResponse.Name);

                    // Get the view list
                    var viewListResponse =
                        clientToUse.Catalog.ListViews(
                            commonData.SecondDataLakeAnalyticsAccountName,
                            commonData.DatabaseName,
                            CommonTestFixture.SchemaName
                            );

                    Assert.True(viewListResponse.Count() >= 1);

                    // Look for the view we created
                    Assert.Contains(viewListResponse, view => view.Name.Equals(commonData.ViewName));

                    // Get the view list from just the database
                    viewListResponse =
                        clientToUse.Catalog.ListViewsByDatabase(
                            commonData.SecondDataLakeAnalyticsAccountName,
                            commonData.DatabaseName
                            );

                    Assert.True(viewListResponse.Count() >= 1);

                    // Look for the view we created
                    Assert.Contains(viewListResponse, view => view.Name.Equals(commonData.ViewName));

                    // Get the specific view as well
                    var viewGetResponse =
                        clientToUse.Catalog.GetView(
                            commonData.SecondDataLakeAnalyticsAccountName,
                            commonData.DatabaseName,
                            CommonTestFixture.SchemaName,
                            commonData.ViewName
                            );

                    Assert.Equal(commonData.ViewName, viewGetResponse.Name);

                    // Get the procedure list
                    var procListResponse =
                        clientToUse.Catalog.ListProcedures(
                            commonData.SecondDataLakeAnalyticsAccountName,
                            commonData.DatabaseName,
                            CommonTestFixture.SchemaName
                            );

                    Assert.True(procListResponse.Count() >= 1);

                    // Look for the procedure we created
                    Assert.Contains(procListResponse, proc => proc.Name.Equals(commonData.ProcName));

                    // Get the specific procedure as well
                    var procGetResponse =
                        clientToUse.Catalog.GetProcedure(
                            commonData.SecondDataLakeAnalyticsAccountName,
                            commonData.DatabaseName,
                            CommonTestFixture.SchemaName,
                            commonData.ProcName
                            );

                    Assert.Equal(commonData.ProcName, procGetResponse.Name);

                    // Get the partition list
                    var partitionList =
                        clientToUse.Catalog.ListTablePartitions(
                            commonData.SecondDataLakeAnalyticsAccountName,
                            commonData.DatabaseName,
                            CommonTestFixture.SchemaName,
                            commonData.TableName
                            );

                    Assert.True(partitionList.Count() >= 1);

                    var specificPartition = partitionList.First();

                    // Get preview of the specific partition
                    var partitionPreviewGetResponse =
                        clientToUse.Catalog.PreviewTablePartition(
                            commonData.SecondDataLakeAnalyticsAccountName,
                            commonData.DatabaseName,
                            CommonTestFixture.SchemaName,
                            commonData.TableName,
                            specificPartition.Name
                            );

                    Assert.True(partitionPreviewGetResponse.TotalRowCount > 0);
                    Assert.True(partitionPreviewGetResponse.TotalColumnCount > 0);
                    Assert.True(partitionPreviewGetResponse.Rows != null && partitionPreviewGetResponse.Rows.Count() > 0);
                    Assert.True(partitionPreviewGetResponse.Schema != null && partitionPreviewGetResponse.Schema.Count() > 0);
                    Assert.NotNull(tablePreviewGetResponse.Schema[0].Name);
                    Assert.NotNull(tablePreviewGetResponse.Schema[0].Type);

                    // Get the specific partition as well
                    var partitionGetResponse =
                        clientToUse.Catalog.GetTablePartition(
                            commonData.SecondDataLakeAnalyticsAccountName,
                            commonData.DatabaseName,
                            CommonTestFixture.SchemaName,
                            commonData.TableName,
                            specificPartition.Name
                            );

                    Assert.Equal(specificPartition.Name, partitionGetResponse.Name);

                    // Get the fragment list
                    var fragmentList =
                        clientToUse.Catalog.ListTableFragments(
                            commonData.SecondDataLakeAnalyticsAccountName,
                            commonData.DatabaseName,
                            CommonTestFixture.SchemaName,
                            commonData.TableName
                            );

                    Assert.NotNull(fragmentList);
                    Assert.NotEmpty(fragmentList);

                    // Get all the types
                    var typeGetResponse =
                        clientToUse.Catalog.ListTypes(
                            commonData.SecondDataLakeAnalyticsAccountName,
                            commonData.DatabaseName,
                            CommonTestFixture.SchemaName
                            );

                    Assert.NotNull(typeGetResponse);
                    Assert.NotEmpty(typeGetResponse);

                    // Get all the types that are not complex
                    typeGetResponse =
                        clientToUse.Catalog.ListTypes(
                            commonData.SecondDataLakeAnalyticsAccountName,
                            commonData.DatabaseName,
                            CommonTestFixture.SchemaName,
                            new Microsoft.Rest.Azure.OData.ODataQuery <USqlType> {
                        Filter = "isComplexType eq false"
                    }
                            );

                    Assert.NotNull(typeGetResponse);
                    Assert.NotEmpty(typeGetResponse);
                    Assert.DoesNotContain(typeGetResponse, type => type.IsComplexType.Value);

                    // Prepare to grant/revoke ACLs
                    var principalId   = TestUtilities.GenerateGuid();
                    var grantAclParam = new AclCreateOrUpdateParameters
                    {
                        AceType     = AclType.User,
                        PrincipalId = principalId,
                        Permission  = PermissionType.Use
                    };
                    var revokeAclParam = new AclDeleteParameters
                    {
                        AceType     = AclType.User,
                        PrincipalId = principalId
                    };

                    // Get the initial number of ACLs by db
                    var aclByDbListResponse =
                        clientToUse.Catalog.ListAclsByDatabase(
                            commonData.SecondDataLakeAnalyticsAccountName,
                            commonData.DatabaseName
                            );
                    var aclByDbCount = aclByDbListResponse.Count();

                    // Get the initial number of ACLs by catalog
                    var aclListResponse =
                        clientToUse.Catalog.ListAcls(
                            commonData.SecondDataLakeAnalyticsAccountName
                            );
                    var aclCount = aclListResponse.Count();

                    // Grant ACL to the db
                    clientToUse.Catalog.GrantAclToDatabase(
                        commonData.SecondDataLakeAnalyticsAccountName,
                        commonData.DatabaseName,
                        grantAclParam
                        );
                    aclByDbListResponse =
                        clientToUse.Catalog.ListAclsByDatabase(
                            commonData.SecondDataLakeAnalyticsAccountName,
                            commonData.DatabaseName
                            );
                    var acl = aclByDbListResponse.Last();

                    // Confirm the ACL's information
                    Assert.Equal(aclByDbCount + 1, aclByDbListResponse.Count());
                    Assert.Equal(AclType.User, acl.AceType);
                    Assert.Equal(principalId, acl.PrincipalId);
                    Assert.Equal(PermissionType.Use, acl.Permission);

                    // Revoke ACL from the db
                    clientToUse.Catalog.RevokeAclFromDatabase(
                        commonData.SecondDataLakeAnalyticsAccountName,
                        commonData.DatabaseName,
                        revokeAclParam
                        );
                    aclByDbListResponse =
                        clientToUse.Catalog.ListAclsByDatabase(
                            commonData.SecondDataLakeAnalyticsAccountName,
                            commonData.DatabaseName
                            );

                    Assert.Equal(aclByDbCount, aclByDbListResponse.Count());

                    // Grant ACL to the catalog
                    clientToUse.Catalog.GrantAcl(
                        commonData.SecondDataLakeAnalyticsAccountName,
                        grantAclParam
                        );
                    aclListResponse =
                        clientToUse.Catalog.ListAcls(
                            commonData.SecondDataLakeAnalyticsAccountName
                            );
                    acl = aclListResponse.Last();

                    // Confirm the ACL's information
                    Assert.Equal(aclCount + 1, aclListResponse.Count());
                    Assert.Equal(AclType.User, acl.AceType);
                    Assert.Equal(principalId, acl.PrincipalId);
                    Assert.Equal(PermissionType.Use, acl.Permission);

                    // Revoke ACL from the catalog
                    clientToUse.Catalog.RevokeAcl(
                        commonData.SecondDataLakeAnalyticsAccountName,
                        revokeAclParam
                        );
                    aclListResponse =
                        clientToUse.Catalog.ListAcls(
                            commonData.SecondDataLakeAnalyticsAccountName
                            );

                    Assert.Equal(aclCount, aclListResponse.Count());
                }
            }
        }
예제 #13
0
        public void SubmitGetListCancelTest()
        {
            using (var context = MockContext.Start(this.GetType().FullName))
            {
                commonData         = new CommonTestFixture(context);
                commonData.HostUrl =
                    commonData.DataLakeAnalyticsManagementHelper.TryCreateDataLakeAnalyticsAccount(commonData.ResourceGroupName,
                                                                                                   commonData.Location, commonData.DataLakeStoreAccountName, commonData.SecondDataLakeAnalyticsAccountName);

                // TODO: Remove this sleep once defect 5022906 is fixed
                TestUtilities.Wait(120000); // Sleep for two minutes to give the account a chance to provision the queue
                var clientToUse = this.GetDataLakeAnalyticsJobManagementClient(context);

                Guid jobId    = TestUtilities.GenerateGuid();
                var  secondId = TestUtilities.GenerateGuid();
                // Submit a job to the account
                var jobToSubmit = new JobInformation
                {
                    Name = "azure sdk data lake analytics job",
                    DegreeOfParallelism = 2,
                    Type       = JobType.USql,
                    Properties = new USqlJobProperties
                    {
                        // TODO: figure out why this is no longer showing up as a property
                        // Type = JobType.USql,
                        Script = "DROP DATABASE IF EXISTS testdb; CREATE DATABASE testdb;"
                    },
                    JobId = jobId
                };

                // check to make sure the job doesn't already exist
                Assert.False(clientToUse.Job.Exists(commonData.SecondDataLakeAnalyticsAccountName, jobId));
                var jobCreateResponse = clientToUse.Job.Create(commonData.SecondDataLakeAnalyticsAccountName, jobId, jobToSubmit);

                Assert.NotNull(jobCreateResponse);

                // Cancel the job
                clientToUse.Job.Cancel(commonData.SecondDataLakeAnalyticsAccountName, jobCreateResponse.JobId.GetValueOrDefault());

                // check to make sure the job does exist now
                Assert.True(clientToUse.Job.Exists(commonData.SecondDataLakeAnalyticsAccountName, jobId));

                // Get the job and ensure that it says it was cancelled.
                var getCancelledJobResponse = clientToUse.Job.Get(commonData.SecondDataLakeAnalyticsAccountName, jobCreateResponse.JobId.GetValueOrDefault());

                Assert.Equal(JobResult.Cancelled, getCancelledJobResponse.Result);
                Assert.NotNull(getCancelledJobResponse.ErrorMessage);
                Assert.NotEmpty(getCancelledJobResponse.ErrorMessage);

                // Resubmit the job
                jobToSubmit.JobId = secondId;
                jobCreateResponse = clientToUse.Job.Create(commonData.SecondDataLakeAnalyticsAccountName, secondId, jobToSubmit);

                Assert.NotNull(jobCreateResponse);

                // Poll the job until it finishes
                var getJobResponse = clientToUse.Job.Get(commonData.SecondDataLakeAnalyticsAccountName, jobCreateResponse.JobId.GetValueOrDefault());
                Assert.NotNull(getJobResponse);

                int maxWaitInSeconds = 180; // 3 minutes should be long enough
                int curWaitInSeconds = 0;
                while (getJobResponse.State != JobState.Ended && curWaitInSeconds < maxWaitInSeconds)
                {
                    // wait 5 seconds before polling again
                    TestUtilities.Wait(5000);
                    curWaitInSeconds += 5;
                    getJobResponse    = clientToUse.Job.Get(commonData.SecondDataLakeAnalyticsAccountName, jobCreateResponse.JobId.GetValueOrDefault());
                    Assert.NotNull(getJobResponse);
                }

                Assert.True(curWaitInSeconds <= maxWaitInSeconds);

                // Verify the job completes successfully
                Assert.True(
                    getJobResponse.State == JobState.Ended && getJobResponse.Result == JobResult.Succeeded,
                    string.Format("Job: {0} did not return success. Current job state: {1}. Actual result: {2}. Error (if any): {3}",
                                  getJobResponse.JobId, getJobResponse.State, getJobResponse.Result, getJobResponse.ErrorMessage));

                var listJobResponse = clientToUse.Job.List(commonData.SecondDataLakeAnalyticsAccountName, null);
                Assert.NotNull(listJobResponse);

                Assert.True(listJobResponse.Any(job => job.JobId == getJobResponse.JobId));

                // Just compile the job, which requires a jobId in the job object.
                jobToSubmit.JobId = getJobResponse.JobId;
                var compileResponse = clientToUse.Job.Build(commonData.SecondDataLakeAnalyticsAccountName, jobToSubmit);
                Assert.NotNull(compileResponse);

                // now compile a broken job and verify diagnostics report an error
                jobToSubmit.Properties.Script = "DROP DATABASE IF EXIST FOO; CREATE DATABASE FOO;";
                compileResponse = clientToUse.Job.Build(commonData.SecondDataLakeAnalyticsAccountName, jobToSubmit);
                Assert.NotNull(compileResponse);

                Assert.Equal(1, ((USqlJobProperties)compileResponse.Properties).Diagnostics.Count);
                Assert.Equal(SeverityTypes.Error, ((USqlJobProperties)compileResponse.Properties).Diagnostics[0].Severity);
                Assert.Equal(18, ((USqlJobProperties)compileResponse.Properties).Diagnostics[0].ColumnNumber);
                Assert.Equal(22, ((USqlJobProperties)compileResponse.Properties).Diagnostics[0].End);
                Assert.Equal(17, ((USqlJobProperties)compileResponse.Properties).Diagnostics[0].Start);
                Assert.Equal(1, ((USqlJobProperties)compileResponse.Properties).Diagnostics[0].LineNumber);
                Assert.Contains("E_CSC_USER_SYNTAXERROR", ((USqlJobProperties)compileResponse.Properties).Diagnostics[0].Message);

                // list the jobs both with a hand crafted query string and using the parameters
                listJobResponse = clientToUse.Job.List(commonData.SecondDataLakeAnalyticsAccountName, select:  "jobId");
                Assert.NotNull(listJobResponse);

                Assert.True(listJobResponse.Any(job => job.JobId == getJobResponse.JobId));
            }
        }