示例#1
0
        public JobInformationBasicEx CreateJob(JobCreateParameters parameters)
        {
            FixupCreateJobParameters(parameters);

            var usql_prop_parameters = new CreateUSqlJobProperties(parameters.ScriptText);
            var cj       = new CreateJobParameters(JobType.USql, usql_prop_parameters, parameters.JobName);
            var job_info = this.RestClients.JobsClient.Job.Create(this.Account.Name, parameters.JobId, cj);

            var j = new JobInformationBasicEx(job_info, this.Account);

            return(j);
        }
        public override void ExecuteCmdlet()
        {
            if (AnalyticsUnits < 1)
            {
                WriteWarning(Resources.InvalidAnalyticsUnits);
            }

            // Error handling for not passing or passing both script and script path
            if ((string.IsNullOrEmpty(Script) && string.IsNullOrEmpty(ScriptPath)) ||
                (!string.IsNullOrEmpty(Script) && !string.IsNullOrEmpty(ScriptPath)))
            {
                throw new CloudException(Resources.AmbiguousScriptParameter);
            }

            // Get the script
            if (string.IsNullOrEmpty(Script))
            {
                var powerShellDestinationPath = SessionState.Path.GetUnresolvedProviderPathFromPSPath(ScriptPath);
                if (!File.Exists(powerShellDestinationPath))
                {
                    throw new CloudException(string.Format(Resources.ScriptFilePathDoesNotExist,
                                                           powerShellDestinationPath));
                }

                Script = File.ReadAllText(powerShellDestinationPath);
            }

            // Check for script parameters
            if (ScriptParameter != null)
            {
                StringBuilder paramBuilder = new StringBuilder();
                string        paramVar     = null;
                string        paramValue   = null;
                Type          paramType    = null;

                // Build the parameter string in order to prepend it to the script
                foreach (DictionaryEntry param in ScriptParameter)
                {
                    if (param.Value == null)
                    {
                        throw new CloudException(string.Format(Resources.ScriptParameterValueIsNull,
                                                               param.Key.ToString()));
                    }

                    paramVar   = param.Key.ToString();
                    paramValue = param.Value.ToString();
                    paramType  = param.Value.GetType();

                    if (paramType.Equals(typeof(byte)))
                    {
                        paramBuilder.Append(string.Format("DECLARE @{0} byte = {1};\n",
                                                          paramVar,
                                                          paramValue));
                    }
                    else if (paramType.Equals(typeof(sbyte)))
                    {
                        paramBuilder.Append(string.Format("DECLARE @{0} sbyte = {1};\n",
                                                          paramVar,
                                                          paramValue));
                    }
                    else if (paramType.Equals(typeof(int)))
                    {
                        paramBuilder.Append(string.Format("DECLARE @{0} int = {1};\n",
                                                          paramVar,
                                                          paramValue));
                    }
                    else if (paramType.Equals(typeof(uint)))
                    {
                        paramBuilder.Append(string.Format("DECLARE @{0} uint = {1};\n",
                                                          paramVar,
                                                          paramValue));
                    }
                    else if (paramType.Equals(typeof(long)))
                    {
                        paramBuilder.Append(string.Format("DECLARE @{0} long = {1};\n",
                                                          paramVar,
                                                          paramValue));
                    }
                    else if (paramType.Equals(typeof(ulong)))
                    {
                        paramBuilder.Append(string.Format("DECLARE @{0} ulong = {1};\n",
                                                          paramVar,
                                                          paramValue));
                    }
                    else if (paramType.Equals(typeof(float)))
                    {
                        paramBuilder.Append(string.Format("DECLARE @{0} float = {1};\n",
                                                          paramVar,
                                                          paramValue));
                    }
                    else if (paramType.Equals(typeof(double)))
                    {
                        paramBuilder.Append(string.Format("DECLARE @{0} double = {1};\n",
                                                          paramVar,
                                                          paramValue));
                    }
                    else if (paramType.Equals(typeof(decimal)))
                    {
                        paramBuilder.Append(string.Format("DECLARE @{0} decimal = {1};\n",
                                                          paramVar,
                                                          paramValue));
                    }
                    else if (paramType.Equals(typeof(short)))
                    {
                        paramBuilder.Append(string.Format("DECLARE @{0} short = {1};\n",
                                                          paramVar,
                                                          paramValue));
                    }
                    else if (paramType.Equals(typeof(ushort)))
                    {
                        paramBuilder.Append(string.Format("DECLARE @{0} ushort = {1};\n",
                                                          paramVar,
                                                          paramValue));
                    }
                    else if (paramType.Equals(typeof(char)))
                    {
                        paramBuilder.Append(string.Format("DECLARE @{0} char = '{1}';\n",
                                                          paramVar,
                                                          paramValue));
                    }
                    else if (paramType.Equals(typeof(string)))
                    {
                        paramBuilder.Append(string.Format("DECLARE @{0} string = \"{1}\";\n",
                                                          paramVar,
                                                          paramValue));
                    }
                    else if (paramType.Equals(typeof(DateTime)))
                    {
                        DateTime datetime = (DateTime)param.Value;

                        paramBuilder.Append(string.Format("DECLARE @{0} DateTime = new DateTime({1}, {2}, {3}, {4}, {5}, {6}, {7});\n",
                                                          paramVar,
                                                          datetime.Year,
                                                          datetime.Month,
                                                          datetime.Day,
                                                          datetime.Hour,
                                                          datetime.Minute,
                                                          datetime.Second,
                                                          datetime.Millisecond));
                    }
                    else if (paramType.Equals(typeof(bool)))
                    {
                        if ((bool)param.Value)
                        {
                            paramBuilder.Append(string.Format("DECLARE @{0} bool = true;\n", paramVar));
                        }
                        else
                        {
                            paramBuilder.Append(string.Format("DECLARE @{0} bool = false;\n", paramVar));
                        }
                    }
                    else if (paramType.Equals(typeof(Guid)))
                    {
                        paramBuilder.Append(string.Format("DECLARE @{0} Guid = new Guid(\"{1}\");\n",
                                                          paramVar,
                                                          paramValue));
                    }
                    else if (paramType.Equals(typeof(byte[])))
                    {
                        StringBuilder byteArrayBuilder = new StringBuilder(string.Format("DECLARE @{0} byte[] = new byte[] {{", paramVar));
                        byte[]        byteArray        = (byte[])param.Value;

                        if (byteArray.Length > 0)
                        {
                            foreach (byte b in byteArray)
                            {
                                byteArrayBuilder.Append(string.Format("\n  {0},", b.ToString()));
                            }

                            byteArrayBuilder.Append("\n};\n");
                        }
                        else
                        {
                            byteArrayBuilder.Append(" };\n");
                        }

                        paramBuilder.Append(byteArrayBuilder.ToString());
                    }
                    else
                    {
                        throw new CloudException(string.Format(Resources.InvalidScriptParameterType,
                                                               paramType.ToString()));
                    }
                }

                Script = Script.Insert(0, paramBuilder.ToString());
            }

            JobType             jobType;
            CreateJobProperties properties;

            if (USql)
            {
                jobType = JobType.USql;
                var sqlIpProperties = new CreateUSqlJobProperties
                {
                    Script = Script
                };

                if (!string.IsNullOrEmpty(CompileMode))
                {
                    CompileMode toUse;
                    if (Enum.TryParse(CompileMode, out toUse))
                    {
                        sqlIpProperties.CompileMode = toUse;
                    }
                }

                if (!string.IsNullOrEmpty(Runtime))
                {
                    sqlIpProperties.RuntimeVersion = Runtime;
                }

                properties = sqlIpProperties;
            }
            else
            {
                throw new CloudException(Resources.InvalidJobType);
            }

            if (CompileOnly)
            {
                var buildJobParameters = new BuildJobParameters
                {
                    Type       = jobType,
                    Name       = Name,
                    Properties = properties
                };

                WriteObject(DataLakeAnalyticsClient.BuildJob(Account, buildJobParameters));
            }
            else
            {
                var jobId = DataLakeAnalyticsClient.JobIdQueue.Count == 0 ? Guid.NewGuid() : DataLakeAnalyticsClient.JobIdQueue.Dequeue();

                var createJobParameters = new CreateJobParameters
                {
                    Type = jobType,
                    Name = Name,
                    DegreeOfParallelism = AnalyticsUnits,
                    Priority            = Priority,
                    Properties          = properties,
                };

                if (ParameterSetName.Equals(USqlJobParameterSetNameAndRecurrence) ||
                    ParameterSetName.Equals(USqlJobParameterSetNameAndPipeline) ||
                    ParameterSetName.Equals(USqlJobWithScriptPathAndRecurrence) ||
                    ParameterSetName.Equals(USqlJobWithScriptPathAndPipeline))
                {
                    createJobParameters.Related = new JobRelationshipProperties
                    {
                        RecurrenceId   = RecurrenceId,
                        RecurrenceName = RecurrenceName
                    };

                    if (ParameterSetName.Equals(USqlJobParameterSetNameAndPipeline) ||
                        ParameterSetName.Equals(USqlJobWithScriptPathAndPipeline))
                    {
                        createJobParameters.Related.PipelineId   = PipelineId;
                        createJobParameters.Related.PipelineName = PipelineName;
                        createJobParameters.Related.PipelineUri  = PipelineUri;
                        createJobParameters.Related.RunId        = RunId;
                    }
                }

                WriteObject(DataLakeAnalyticsClient.SubmitJob(Account, jobId, createJobParameters));
            }
        }
示例#3
0
        public override void ExecuteCmdlet()
        {
            if (DegreeOfParallelism < 1)
            {
                WriteWarning(Resources.InvalidDegreeOfParallelism);
            }

            // error handling for not passing or passing both script and script path
            if ((string.IsNullOrEmpty(Script) && string.IsNullOrEmpty(ScriptPath)) ||
                (!string.IsNullOrEmpty(Script) && !string.IsNullOrEmpty(ScriptPath)))
            {
                throw new CloudException(Resources.AmbiguousScriptParameter);
            }

            // get the script
            if (string.IsNullOrEmpty(Script))
            {
                var powerShellDestinationPath = SessionState.Path.GetUnresolvedProviderPathFromPSPath(ScriptPath);
                if (!File.Exists(powerShellDestinationPath))
                {
                    throw new CloudException(string.Format(Resources.ScriptFilePathDoesNotExist,
                                                           powerShellDestinationPath));
                }

                Script = File.ReadAllText(powerShellDestinationPath);
            }

            JobType             jobType;
            CreateJobProperties properties;

            if (USql)
            {
                jobType = JobType.USql;
                var sqlIpProperties = new CreateUSqlJobProperties
                {
                    Script = Script
                };

                if (!string.IsNullOrEmpty(CompileMode))
                {
                    CompileMode toUse;
                    if (Enum.TryParse(CompileMode, out toUse))
                    {
                        sqlIpProperties.CompileMode = toUse;
                    }
                }

                if (!string.IsNullOrEmpty(Runtime))
                {
                    sqlIpProperties.RuntimeVersion = Runtime;
                }

                properties = sqlIpProperties;
            }
            else
            {
                throw new CloudException(Resources.InvalidJobType);
            }

            if (CompileOnly)
            {
                var buildJobParameters = new BuildJobParameters
                {
                    Type       = jobType,
                    Name       = Name,
                    Properties = properties
                };

                WriteObject(DataLakeAnalyticsClient.BuildJob(Account, buildJobParameters));
            }
            else
            {
                var jobId = DataLakeAnalyticsClient.JobIdQueue.Count == 0 ? Guid.NewGuid() : DataLakeAnalyticsClient.JobIdQueue.Dequeue();

                var createJobParameters = new CreateJobParameters
                {
                    Type = jobType,
                    Name = Name,
                    DegreeOfParallelism = DegreeOfParallelism,
                    Priority            = Priority,
                    Properties          = properties,
                };

                if (ParameterSetName.Equals(USqlJobParameterSetNameAndRecurrence) ||
                    ParameterSetName.Equals(USqlJobParameterSetNameAndPipeline) ||
                    ParameterSetName.Equals(USqlJobWithScriptPathAndRecurrence) ||
                    ParameterSetName.Equals(USqlJobWithScriptPathAndPipeline))
                {
                    createJobParameters.Related = new JobRelationshipProperties
                    {
                        RecurrenceId   = RecurrenceId,
                        RecurrenceName = RecurrenceName
                    };

                    if (ParameterSetName.Equals(USqlJobParameterSetNameAndPipeline) ||
                        ParameterSetName.Equals(USqlJobWithScriptPathAndPipeline))
                    {
                        createJobParameters.Related.PipelineId   = PipelineId;
                        createJobParameters.Related.PipelineName = PipelineName;
                        createJobParameters.Related.PipelineUri  = PipelineUri;
                        createJobParameters.Related.RunId        = RunId;
                    }
                }

                WriteObject(DataLakeAnalyticsClient.SubmitJob(Account, jobId, createJobParameters));
            }
        }