/// <summary>
 /// Executes script actions on specified HDInsight Running cluster.
 /// </summary>
 /// <param name='resourceGroupName'>
 /// Required. The name of the resource group.
 /// </param>
 /// <param name='clusterName'>
 /// Required. The name of the cluster.
 /// </param>
 /// <param name='scriptActions'>
 /// Required. The list of script actions that needs to be executed.
 /// </param>      
 /// <param name='persistOnSuccess'>
 /// Required. Flag indicating if the script needs to be persisted.
 /// </param>
 /// <param name='cancellationToken'>
 /// Cancellation token.
 /// </param>
 /// <returns>
 /// The cluster long running operation response.
 /// </returns>
 public async Task<OperationResource> ExecuteScriptActionsAsync(string resourceGroupName, string clusterName, IList<RuntimeScriptAction> scriptActions,
     bool persistOnSuccess, CancellationToken cancellationToken)
 {
     try
     {
         var executeScriptActionsParams = new ExecuteScriptActionParameters { ScriptActions = scriptActions, PersistOnSuccess = persistOnSuccess };
         return await ExecuteScriptActionsAsync(resourceGroupName, clusterName, executeScriptActionsParams, cancellationToken);
     }
     catch (Exception ex)
     {
         throw new CloudException(ex.Message);
     }
 }
        public override void ExecuteCmdlet()
        {
            if (ResourceGroupName == null)
            {
                ResourceGroupName = GetResourceGroupByAccountName(ClusterName);
            }

            var scriptAction = new RuntimeScriptAction
            {
                Name = Name,
                Parameters = Parameters,
                Roles = NodeTypes.Select(n => n.ToString()).ToList(),
                Uri = Uri,
                ApplicationName = ApplicationName
            };

            var scriptActions = new List<RuntimeScriptAction> { scriptAction };

            var executeScriptActionParameters = new ExecuteScriptActionParameters
            {
                ScriptActions = scriptActions,
                PersistOnSuccess = PersistOnSuccess.IsPresent
            };

            var operationResource = HDInsightManagementClient.ExecuteScriptActions(ResourceGroupName, ClusterName, executeScriptActionParameters);
            WriteObject(new AzureHDInsightRuntimeScriptActionOperationResource(scriptAction, operationResource));
        }
        private ExecuteScriptActionParameters GetExecuteScriptActionParams(bool persistOnSuccess, string scriptName, string scriptUri)
        {
            var scriptActions = new List<RuntimeScriptAction>();

            scriptActions.Add(new RuntimeScriptAction
            {
                Name = scriptName,
                Uri = new System.Uri(scriptUri),          
                Roles = new List<string>() { "headnode", "workernode" }
            }
            );

            var scriptActionParams = new ExecuteScriptActionParameters
            {
                ScriptActions = scriptActions,
                PersistOnSuccess = persistOnSuccess
            };

            return scriptActionParams;
        }
 /// <summary>
 /// Executes script actions on the specified HDInsight cluster.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Management.HDInsight.IClusterOperations.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Required. The name of the resource group.
 /// </param>
 /// <param name='clusterName'>
 /// Required. The name of the cluster.
 /// </param>
 /// <param name='executeScriptActionParameters'>
 /// Required. The parameters for executing script actions.
 /// </param>
 /// <returns>
 /// The azure async operation response.
 /// </returns>
 public static Task<OperationResource> ExecuteScriptActionsAsync(this IClusterOperations operations, string resourceGroupName, string clusterName, ExecuteScriptActionParameters executeScriptActionParameters)
 {
     return operations.ExecuteScriptActionsAsync(resourceGroupName, clusterName, executeScriptActionParameters, CancellationToken.None);
 }
 /// <summary>
 /// Executes script actions on the specified HDInsight cluster.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Management.HDInsight.IClusterOperations.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Required. The name of the resource group.
 /// </param>
 /// <param name='clusterName'>
 /// Required. The name of the cluster.
 /// </param>
 /// <param name='executeScriptActionParameters'>
 /// Required. The parameters for executing script actions.
 /// </param>
 /// <returns>
 /// The azure async operation response.
 /// </returns>
 public static OperationResource ExecuteScriptActions(this IClusterOperations operations, string resourceGroupName, string clusterName, ExecuteScriptActionParameters executeScriptActionParameters)
 {
     return Task.Factory.StartNew((object s) => 
     {
         return ((IClusterOperations)s).ExecuteScriptActionsAsync(resourceGroupName, clusterName, executeScriptActionParameters);
     }
     , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
 }
 public virtual OperationResource ExecuteScriptActions(string resourceGroupName, string clusterName, ExecuteScriptActionParameters executeScriptActionParameters)
 {
     return HdInsightManagementClient.Clusters.ExecuteScriptActions(resourceGroupName, clusterName, executeScriptActionParameters);
 }