private AzureHDInsightHiveJobDefinition UploadFileToStorage(
            AzureHDInsightHiveJobDefinition jobDefinition, AzureHDInsightClusterConnection currentConnection)
        {
            currentConnection.Cluster.DefaultStorageAccount.ArgumentNotNull("DefaultStorageAccount");
            WabStorageAccountConfiguration storageAccount = currentConnection.Cluster.DefaultStorageAccount.ToWabStorageAccountConfiguration();
            var storageHandler = ServiceLocator.Instance.Locate<IAzureHDInsightStorageHandlerFactory>().Create(storageAccount);
            string hiveQueryFilePath = string.Format(
                CultureInfo.InvariantCulture,
                HiveQueryFileStoragePath,
                currentConnection.Cluster.DefaultStorageAccount.StorageAccountName,
                currentConnection.Cluster.DefaultStorageAccount.StorageContainerName,
                currentConnection.Cluster.HttpUserName,
                Guid.NewGuid().ToString("N"));
            using (Stream hiveQueryFileStream = this.GetStreamForText(jobDefinition.Query))
            {
                var hiveQueryFileUri = new Uri(hiveQueryFilePath, UriKind.RelativeOrAbsolute);
                storageHandler.UploadFile(hiveQueryFileUri, hiveQueryFileStream);
                jobDefinition.Query = string.Empty;
                jobDefinition.File = storageHandler.GetStoragePath(hiveQueryFileUri).OriginalString;
            }

            return jobDefinition;
        }
 protected virtual async Task WriteJobSuccess(AzureHDInsightJob completedJob, AzureHDInsightClusterConnection currentConnection)
 {
     completedJob.ArgumentNotNull("completedJob");
     currentConnection.ArgumentNotNull("currentConnection");
     this.WriteOutput("Hive query completed Successfully");
     this.WriteOutput(Environment.NewLine);
     this.ValidateNotCanceled();
     var getJobOutputCommand = ServiceLocator.Instance.Locate<IAzureHDInsightCommandFactory>().CreateGetJobOutput();
     this.SetClient(getJobOutputCommand);
     getJobOutputCommand.JobId = completedJob.JobId;
     getJobOutputCommand.Logger = this.Logger;
     getJobOutputCommand.CurrentSubscription = this.CurrentSubscription;
     getJobOutputCommand.Cluster = currentConnection.Cluster.Name;
     this.ValidateNotCanceled();
     await getJobOutputCommand.EndProcessing();
     var outputStream = getJobOutputCommand.Output.First();
     string content = new StreamReader(outputStream).ReadToEnd();
     this.WriteOutput(content);
 }
 protected virtual async Task<AzureHDInsightJob> WaitForCompletion(
     AzureHDInsightJob startedJob, AzureHDInsightClusterConnection currentConnection)
 {
     startedJob.ArgumentNotNull("startedJob");
     currentConnection.ArgumentNotNull("currentConnection");
     this.ValidateNotCanceled();
     var waitJobCommand = ServiceLocator.Instance.Locate<IAzureHDInsightCommandFactory>().CreateWaitJobs();
     waitJobCommand.JobStatusEvent += this.ClientOnJobStatus;
     this.SetClient(waitJobCommand);
     waitJobCommand.Job = startedJob;
     waitJobCommand.Logger = this.Logger;
     waitJobCommand.WaitTimeoutInSeconds = WaitAnHourInSeconds;
     waitJobCommand.CurrentSubscription = this.CurrentSubscription;
     this.ValidateNotCanceled();
     await waitJobCommand.ProcessRecord();
     return waitJobCommand.Output.Last();
 }
 protected virtual async Task<AzureHDInsightJob> StartJob(
     AzureHDInsightJobDefinition jobDefinition, AzureHDInsightClusterConnection currentConnection)
 {
     jobDefinition.ArgumentNotNull("jobDefinition");
     currentConnection.ArgumentNotNull("currentCluster");
     this.ValidateNotCanceled();
     var startJobCommand = ServiceLocator.Instance.Locate<IAzureHDInsightCommandFactory>().CreateStartJob();
     this.SetClient(startJobCommand);
     startJobCommand.Cluster = currentConnection.Cluster.Name;
     startJobCommand.Logger = this.Logger;
     startJobCommand.CurrentSubscription = this.CurrentSubscription;
     startJobCommand.JobDefinition = jobDefinition;
     this.ValidateNotCanceled();
     await startJobCommand.EndProcessing();
     return startJobCommand.Output.Last();
 }
 public void SetCurrentCluster(AzureHDInsightClusterConnection cluster)
 {
     this.currentCluster = cluster;
 }
 public void SetCurrentCluster(AzureHDInsightClusterConnection cluster)
 {
     this.sessionState.PSVariable.Set(CurrentClusterVariableName, cluster);
 }