Exemplo n.º 1
0
        private ClusterCreateParameters CreateClusterToValidateScriptActions(string resourceGroup, string dnsName, HDInsightManagementClient client)
        {
            var clusterCreateParams = GetClusterSpecHelpers.GetCustomCreateParametersIaas();

            client.Clusters.Create(resourceGroup, dnsName, clusterCreateParams);

            HDInsightManagementTestUtilities.WaitForClusterToMoveToRunning(resourceGroup, dnsName, client);

            // upload only in record mode
            if (HDInsightManagementTestUtilities.IsRecordMode())
            {
                //upload failing script to the cluster  default storage account
                var defaultStorageAccount = clusterCreateParams.DefaultStorageInfo as AzureStorageInfo;
                var storageAccountName    = defaultStorageAccount.StorageAccountName.Split('.')[0];
                var creds = new StorageCredentials(storageAccountName, defaultStorageAccount.StorageAccountKey);

                var storageAccount = new CloudStorageAccount(creds, true);
                var blobClient     = storageAccount.CreateCloudBlobClient();
                var container      = blobClient.GetContainerReference(FailingScriptLocationContainer);
                container.CreateIfNotExists();
                var blockBlob = container.GetBlockBlobReference("failingscriptaction.sh");

                using (var fileStream = System.IO.File.OpenRead(@"TestData/FailingScriptAction.sh"))
                {
                    blockBlob.UploadFromStream(fileStream);
                }
            }

            return(clusterCreateParams);
        }
Exemplo n.º 2
0
        public void TestScriptActionsOnRunningCluster()
        {
            var handler = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };

            using (var context = UndoContext.Current)
            {
                context.Start();

                var client = HDInsightManagementTestUtilities.GetHDInsightManagementClient(handler);
                var resourceManagementClient = HDInsightManagementTestUtilities.GetResourceManagementClient(handler);

                var resourceGroup = HDInsightManagementTestUtilities.CreateResourceGroup(resourceManagementClient);

                // need to use static name, so tests work in playback mode
                var dnsName = "hdiscriptaction733a2822-b098-443f-95b8-2e35f261a5c2";

                try
                {
                    // need to use static name , so tests work in playback mode
                    string scriptName = "script6de8a1ea-4";

                    var clusterCreateParams = CreateClusterToValidateScriptActions(resourceGroup, dnsName, client);

                    var executeScriptActionParamsPersisted = GetExecuteScriptActionParams(true, scriptName, InstallGiraph);

                    var response = client.Clusters.ExecuteScriptActions(resourceGroup, dnsName, executeScriptActionParamsPersisted);

                    Assert.Equal(AsyncOperationState.Succeeded, response.State);

                    var scriptActionsList = client.Clusters.ListPersistedScripts(resourceGroup, dnsName);

                    // validate that scripts are persisted
                    Assert.Equal(1, scriptActionsList.PersistedScriptActions.Count);
                    Assert.Equal(scriptActionsList.PersistedScriptActions[0].Name, executeScriptActionParamsPersisted.ScriptActions[0].Name);
                    Assert.Equal(scriptActionsList.PersistedScriptActions[0].Uri, executeScriptActionParamsPersisted.ScriptActions[0].Uri);
                    Assert.Equal(scriptActionsList.PersistedScriptActions[0].Roles.Count, executeScriptActionParamsPersisted.ScriptActions[0].Roles.Count);

                    Assert.True(scriptActionsList.PersistedScriptActions[0].ApplicationName == null);

                    // DELETE a script action
                    client.Clusters.DeletePersistedScript(resourceGroup, dnsName, scriptActionsList.PersistedScriptActions[0].Name);

                    //Do a get after delete, to validate that scripts have been deleted
                    scriptActionsList = client.Clusters.ListPersistedScripts(resourceGroup, dnsName);

                    Assert.Equal(0, scriptActionsList.PersistedScriptActions.Count);

                    var listHistoryResponse = client.Clusters.ListScriptExecutionHistory(resourceGroup, dnsName);

                    ValidateHistoryDetail(listHistoryResponse.RuntimeScriptActionDetail[0], false, scriptName);

                    // Get execution details of a single execution
                    var executionDetailedResponse = client.Clusters.GetScriptExecutionDetail(resourceGroup, dnsName, listHistoryResponse.RuntimeScriptActionDetail[0].ScriptExecutionId);

                    //validate a single execution detail with debug information
                    ValidateHistoryDetail(executionDetailedResponse.RuntimeScriptActionDetail, true, scriptName);

                    // Run Ad hoc execution
                    var executeScriptActionParamsAdHoc = GetExecuteScriptActionParams(false, "script" + Guid.NewGuid().ToString().Substring(0, 10), InstallGiraph);

                    var adHocExecutionResponse = client.Clusters.ExecuteScriptActions(resourceGroup, dnsName, executeScriptActionParamsAdHoc);

                    Assert.Equal(AsyncOperationState.Succeeded, adHocExecutionResponse.State);

                    var historyResponse = client.Clusters.ListScriptExecutionHistory(resourceGroup, dnsName);

                    //promote a script from ad hoc execution
                    var promoteResponse = client.Clusters.PromoteScript(resourceGroup, dnsName, historyResponse.RuntimeScriptActionDetail[0].ScriptExecutionId);

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

                    string failingScriptUri = "http://bing.com";

                    //this is set only for RECORD mode, playback this uri doesnt matter
                    if (HDInsightManagementTestUtilities.IsRecordMode())
                    {
                        failingScriptUri = string.Format(FailingScriptLocationFormat, clusterCreateParams.DefaultStorageInfo.StorageAccountName, FailingScriptLocationContainer);
                    }

                    var executeScriptActionParams = GetExecuteScriptActionParams(true, scriptName, failingScriptUri);

                    var result = client.Clusters.ExecuteScriptActions(resourceGroup, dnsName, executeScriptActionParams);
                    Assert.Equal(result.StatusCode, HttpStatusCode.OK);
                    Assert.Equal(result.State, AsyncOperationState.Failed);
                    Assert.Equal(result.ErrorInfo.Message, "ScriptExecutionFailed");

                    var scriptActionParams = GetExecuteScriptActionParams(true, "script" + Guid.NewGuid().ToString().Substring(0, 10), InstallGiraph);

                    var result2 = client.Clusters.ExecuteScriptActions(resourceGroup, dnsName, scriptActionParams.ScriptActions, true);

                    Assert.Equal(result2.StatusCode, HttpStatusCode.OK);
                    Assert.Equal(result2.State, AsyncOperationState.Succeeded);
                }
                finally
                {
                    //cleanup
                    client.Clusters.Delete(resourceGroup, dnsName);
                }
            }
        }