GetHiveJob() public method

public GetHiveJob ( ) : Microsoft.Azure.Commands.HDInsight.Models.AzureHDInsightHiveJobDefinition
return Microsoft.Azure.Commands.HDInsight.Models.AzureHDInsightHiveJobDefinition
Ejemplo n.º 1
0
        public override void ExecuteCmdlet()
        {
            //get variables from session
            var clusterConnection = SessionState.PSVariable.Get(UseAzureHDInsightClusterCommand.ClusterEndpoint).Value.ToString();
            var clusterCred       =
                (PSCredential)SessionState.PSVariable.Get(UseAzureHDInsightClusterCommand.ClusterCred).Value;
            var resourceGroup =
                SessionState.PSVariable.Get(UseAzureHDInsightClusterCommand.CurrentResourceGroup).Value.ToString();

            _clusterName = clusterConnection;
            _credential  = new BasicAuthenticationCloudCredentials
            {
                Username = clusterCred.UserName,
                Password = clusterCred.Password.ConvertToString()
            };

            if (clusterConnection == null || clusterCred == null)
            {
                throw new NullReferenceException(
                          string.Format(
                              "The cluster or resource group specified is null. Please use the Use-AzureHDInsightCluster command to connect to a cluster."));
            }

            //get hive job
            var hivejob = hiveJobDefinitionCommand.GetHiveJob();

            //start hive job
            WriteObject("Submitting hive query...");
            var startJobCommand = new StartAzureHDInsightJobCommand
            {
                ClusterName       = clusterConnection,
                ResourceGroupName = resourceGroup,
                JobDefinition     = hivejob,
                ClusterCredential = clusterCred
            };

            var jobCreationResult = startJobCommand.SubmitJob();
            var jobid             = jobCreationResult.JobSubmissionJsonResponse.Id;

            WriteObject(string.Format("Submitted Hive query with jobDetails Id : {0}", jobid));

            //wait for job to complete
            WriteProgress(new ProgressRecord(0, "Waiting for job to complete", "In Progress"));
            var waitJobCommand = new WaitAzureHDInsightJobCommand
            {
                ClusterCredential = clusterCred,
                ResourceGroupName = resourceGroup,
                ClusterName       = clusterConnection,
                JobId             = jobid
            };

            var    job = waitJobCommand.WaitJob();
            string output;

            if (job.ExitValue == 0)
            {
                //get job output
                var getOutputCommand = new GetAzureHDInsightJobOutputCommand
                {
                    ClusterCredential         = clusterCred,
                    ResourceGroupName         = resourceGroup,
                    ClusterName               = clusterConnection,
                    DefaultContainer          = DefaultContainer,
                    DefaultStorageAccountName = DefaultStorageAccountName,
                    DefaultStorageAccountKey  = DefaultStorageAccountKey,
                    JobId = jobid
                };

                output = getOutputCommand.GetJobOutput();
            }
            else
            {
                //get job error
                output = Convert(HDInsightJobClient.GetJobError(jobid, DefaultStorageAccountName, DefaultStorageAccountKey,
                                                                DefaultContainer));
            }
            WriteObject(output);
        }