Наследование: Microsoft.Azure.Commands.HDInsight.Commands.HDInsightCmdletBase
        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);
        }
Пример #2
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();

            _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);
        }