SubmitJob() public method

public SubmitJob ( ) : Microsoft.Azure.Management.HDInsight.Job.Models.JobSubmissionResponse
return Microsoft.Azure.Management.HDInsight.Job.Models.JobSubmissionResponse
示例#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);
        }
        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();

            _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-AzureRmHDInsightCluster 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,
                HttpCredential = 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
            {
                HttpCredential = clusterCred,
                ResourceGroupName = resourceGroup,
                ClusterName = clusterConnection,
                JobId = jobid
            };

            var job = waitJobCommand.WaitJob();

            _clusterName = clusterConnection.Substring(0, clusterConnection.IndexOf('.'));

            var getOutputCommand = new GetAzureHDInsightJobOutputCommand
            {
                HttpCredential = clusterCred,
                ResourceGroupName = resourceGroup,
                ClusterName = clusterConnection,
                DefaultContainer = DefaultContainer,
                DefaultStorageAccountName = DefaultStorageAccountName,
                DefaultStorageAccountKey = DefaultStorageAccountKey,
                JobId = jobid
            };

            var storageAccess = getOutputCommand.GetDefaultStorageAccess(resourceGroup, _clusterName);

            string output;
            if (job.ExitValue == 0)
            {
                //get job output
                output = getOutputCommand.GetJobOutput(storageAccess);
            }
            else
            {
                //get job error
                output = getOutputCommand.GetJobError(storageAccess);
            }

            WriteObject(output);
        }