您當前的位置:首頁 > 詩詞

Deadline Web API適配Houdini18.5 py3版

作者:由 CGAI即時演繹 發表于 詩詞時間:2021-01-10

Deadline本身機制是透過各DCC軟體自身的後臺命令去執行渲染或者解算。如果要從外部提交任務到Deadline需要透過Deadline提供的Web Sevice進行資料互動。但是官方只提供了Python2版本的API並沒有提供Python3版的。為了能在Houdini18。5 python3版裡直接提交任務到Deadline,這裡對其介面API稍微改了一下。(當然,如果熟悉Deadline的job資料,直接使用 GET,POST,DELETE,PUT這四種方式與Web Service進行資料互動也是可以的,這樣不僅能無視python版本還能支援其他語言)

啟動WebService

任意一臺安裝Deadline Client的機器上,在安裝目錄裡可以找到deadlinewebservice。exe。以管理員身份執行後可以在該機器上開啟一個Deadline Web Service。該Serivce的作用其實就是一箇中間資料轉發小服務,它能接收從其他機器傳來的命令資料,之後對Deadline倉庫與資料進行互動,最後將操作結果返回。為了統一管理,一般我們會將Deadline Web Serivce放在倉庫統一的伺服器裡。

然後其他機器上要連線到Web Service就需要連線它所在的IP與埠。

Deadline Web API適配Houdini18.5 py3版

幾處指令碼修改

Repository中指令碼修改

找到Deadline倉庫安裝目錄下的Houdini外掛,比如:xxx/DeadlineRepository10/plugins/Houdini

1.Houdini.param新增Houdini18.5的配置

如果要使用HQueue,需要同樣配置[Houdini18_5_SimTracker]

Houdini18_5_Hython_Executable

Label

=

Houdini

18。5

Hython

Executable

Category

=

Render

Executables

CategoryOrder

=

0

Type

=

multilinemultifilename

Index

=

3

Default

=

C

\

Program

Files

\

Side

Effects

Software

\

Houdini

18。5

448

\

bin

\

Hython

exe

/

Applications

/

Houdini

/

Houdini18

5。448

/

Frameworks

/

Houdini

framework

/

Versions

/

18。5

448

/

Resources

/

bin

/

hython

/

opt

/

hfs18

5

/

bin

/

hython

Description

=

The

path

to

the

hython

executable

It

can

be

found

in

the

Houdini

bin

folder

Description

=

The

path

to

the

hython

executable

It

can

be

found

in

the

Houdini

bin

folder

2.Houdini.py的RenderExecutable()函數里.新增version版本執行檔案返回值。

我這裡使用self。GetConfigEntry返回報錯,所以直接返回houdiniExeList,其實就是Exe的配置路徑

def

RenderExecutable

self

):

version

=

self

GetPluginInfoEntryWithDefault

“Version”

“16。0”

replace

“。”

“_”

build

=

self

GetPluginInfoEntryWithDefault

“Build”

“none”

lower

()

if

version

startswith

‘18_5’

):

houdiniExeList

=

r

‘C:\Program Files\Side Effects Software\Houdini 18。5。449\bin\Hython。exe;/Applications/Houdini/Houdini18。5。449/Frameworks/Houdini。framework/Versions/18。5。449/Resources/bin/hython;/opt/hfs18。5/bin/hython’

else

houdiniExeList

=

self

GetConfigEntry

“Houdini”

+

version

+

“_Hython_Executable”

。。。

Deadline API指令碼更改

也就是Deadline提供的Standalone Web Service介面python包。在倉庫安裝目錄的api/python資料夾下的Deadline,比如: xxx/DeadlineRepository10/api/python/Deadline。最好把這個資料夾複製到你Houdini中心管理的地方統一載入。

1.找到DeadlineUtility.py將 basestring 替換為 str

def

ArrayToCommaSeparatedString

iterable

):

# if isinstance( iterable, basestring ):

if

isinstance

iterable

str

):

return

iterable

if

iterable

is

None

return

“”

return

“,”

join

str

x

for

x

in

iterable

2.找到DeadlineSend.py 登出掉所以python2的url請求方式,改為python3的requests方式。

從這裡可以看出,與Web Serive互動其實就是Http請求機制。其中send函式主要處理GET,DELETE請求,psend函式主要處理PUT,POST請求。

import

socket

# import httplib

import

json

# import urllib2

import

traceback

import

requests

def

send

address

message

requestType

useAuth

=

False

username

=

“”

password

=

“”

):

“”“

Used for sending requests that do not require message body, like GET and DELETE。

Params: address of the webservice (string)。

message to the webservice (string)。

request type for the message (string, GET or DELETE)。

”“”

try

if

not

address

startswith

“http://”

):

address

=

“http://”

+

address

url

=

address

+

message

response

=

requests

request

requestType

url

data

=

response

text

data

=

data

replace

\n

‘ ’

# except urllib2。HTTPError as err:

except

Exception

as

err

data

=

traceback

format_exc

()

if

response

==

401

data

=

“Error: HTTP Status Code 401。 Authentication with the Web Service failed。 Please ensure that the authentication credentials are set, are correct, and that authentication mode is enabled。”

# else:

# data = err。read()

try

data

=

json

loads

data

except

pass

return

data

def

pSend

address

message

requestType

body

useAuth

=

False

username

=

“”

password

=

“”

):

“”“

Used for sending requests that require a message body, like PUT and POST。

Params: address of the webservice (string)。

message to the webservice (string)。

request type for the message (string, PUT or POST)。

message body for the request (string, JSON object)。

”“”

response

=

“”

try

if

not

address

startswith

“http://”

):

address

=

“http://”

+

address

url

=

address

+

message

except

Exception

as

err

data

=

traceback

format_exc

()

if

response

==

401

data

=

“Error: HTTP Status Code 401。 Authentication with the Web Service failed。 Please ensure that the authentication credentials are set, are correct, and that authentication mode is enabled。”

# else:

# data = err。read()

try

data

=

json

loads

data

except

pass

return

data

Houdini18。5 py3版提交案例

import

os

import

hou

import

getpass

import

DeadlineConnect

as

Connect

connectionObject

=

Connect

DeadlineCon

‘192。168。1。xx’

8082

file_path

=

hou

hipFile

name

()

version

=

hou

applicationVersionString

()

hip_name

=

os

path

sliptext

hou

hipFile

basename

())[

0

user_name

=

getpass

getuser

()

pool

=

‘none’

pri

=

100

chunk

=

10

node

=

hou

node

‘obj/geo1/filecache1’

node_name

=

node

name

()

f1

=

node

parm

‘f1’

eval

()

f2

=

node

parm

‘f2’

eval

()

#設定job屬性

props

=

{}

props

‘Name’

=

hip_name

+

‘_’

+

node_name

props

‘UserName’

=

user_name

props

‘Frames’

=

{}

-

{}

format

f1

f2

props

‘Plugin’

=

‘Houdini’

props

‘Pool’

=

pool

props

‘Pri’

=

pri

props

‘ChunkSize’

=

chunk

#外掛屬性

plug

=

{

“OutputDriver”

node

path

()

+

‘/render’

“SceneFile”

file_path

“Version”

version

}

job

=

connectionObject

Jobs

SubmitJob

props

plug

JOB資料內容

job資訊本身是一個大json。 Deadline對Job資料的具體值進行對應的操作。

job的keys有:

‘Props’

‘ComFra’

‘IsSub’

‘Purged’

‘Mach’

‘Date’

‘DateStart’

‘DateComp’

‘Plug’

‘OutDir’

‘OutFile’

‘TileFile’

‘Main’

‘MainStart’

‘MainEnd’

‘Tile’

‘TileFrame’

‘TileCount’

‘TileX’

‘TileY’

‘Stat’

‘Aux’

‘Bad’

‘CompletedChunks’

‘QueuedChunks’

‘SuspendedChunks’

‘RenderingChunks’

‘FailedChunks’

‘PendingChunks’

‘SnglTskPrg’

‘Errs’

‘DataSize’

‘_id’

‘ExtraElements’

常用屬性說明

Props

屬性

Stat

狀態

值為int

在使用api的時候可以傳入字串

其中對於的int值如下

Unknown

0

Active

1

Suspended

2

Completed

3

Failed

4

Pending

6

_id

job

id

其中最重要的是Props屬性,它的內容有:

‘Name’

‘Batch’

‘User’

‘Region’

‘Cmmt’

‘Dept’

‘Frames’

‘Chunk’

‘Tasks’

‘Grp’

‘Pool’

‘SecPool’

‘Pri’

‘ReqAss’

‘ScrDep’

‘Conc’

‘ConcLimt’

‘AuxSync’

‘Int’

‘IntPer’

‘RemTmT’

‘Seq’

‘Reload’

‘NoEvnt’

‘OnComp’

‘Protect’

‘PathMap’

‘AutoTime’

‘TimeScrpt’

‘MinTime’

‘MaxTime’

‘Timeout’

‘FrameTimeout’

‘StartTime’

‘InitializePluginTime’

‘Dep’

‘DepFrame’

‘DepFrameStart’

‘DepFrameEnd’

‘DepComp’

‘DepDel’

‘DepFail’

‘DepPer’

‘NoBad’

‘OverAutoClean’

‘OverClean’

‘OverCleanDays’

‘OverCleanType’

‘JobFailOvr’

‘JobFailErr’

‘TskFailOvr’

‘TskFailErr’

‘SndWarn’

‘NotOvr’

‘SndEmail’

‘SndPopup’

‘NotEmail’

‘NotUser’

‘NotNote’

‘Limits’

‘ListedSlaves’

‘White’

‘MachLmt’

‘MachLmtProg’

‘PrJobScrp’

‘PoJobScrp’

‘PrTskScrp’

‘PoTskScrp’

‘Schd’

‘SchdDays’

‘SchdDate’

‘SchdStop’

‘MonStart’

‘MonStop’

‘TueStart’

‘TueStop’

‘WedStart’

‘WedStop’

‘ThuStart’

‘ThuStop’

‘FriStart’

‘FriStop’

‘SatStart’

‘SatStop’

‘SunStart’

‘SunStop’

‘PlugInfo’

‘Env’

‘EnvOnly’

‘PlugDir’

‘EventDir’

‘OptIns’

‘EventOI’

‘AWSPortalAssets’

‘AWSPortalAssetFileWhitelist’

‘Ex0’

‘Ex1’

‘Ex2’

‘Ex3’

‘Ex4’

‘Ex5’

‘Ex6’

‘Ex7’

‘Ex8’

‘Ex9’

‘ExDic’

‘OvrTaskEINames’

‘TaskEx0’

‘TaskEx1’

‘TaskEx2’

‘TaskEx3’

‘TaskEx4’

‘TaskEx5’

‘TaskEx6’

‘TaskEx7’

‘TaskEx8’

‘TaskEx9’

常見屬性說明

Name

任務名稱

User

電腦賬戶名稱

比如

Administrator

laozhang

Frames

幀數範圍

結構

‘1-2’

Chunk

1

每臺機器載入一次工程的執行長度

如果設定為1

那麼每次載入工程後

渲染一幀然後關閉工程

下次繼續載入

機器少建議開大

Tasks

執行的任務數量

就是點選一個job後

右邊顯示任務數

Grp

機器組

Pool

機器池

Pri

優先順序

Dep

依賴關係

[{

u

‘ResumeOnPercentageValue’

0。0

u

‘OverrideFrameOffsets’

False

u

‘EndOffset’

0

u

‘OverrideResumeOn’

False

u

‘ResumeOnFailed’

False

u

‘JobID’

u

‘5ff7c49d14a13a26f4b9f893’

u

‘IgnoreFrameOffsets’

False

u

‘ResumeOnDeleted’

False

u

‘StartOffset’

0

u

‘ResumeOnComplete’

True

u

‘ResumeOnPercentageCompleted’

False

u

‘Notes’

u

‘’

}]

一些真正被Deadline輸入識別的屬性

Deadline有個不嚴謹的地方就是,從Deadline API返回的job資料屬性名其與傳入的屬性名稱不一致。

建議在User-Manual-> Manual Job Submission下可檢視job傳入屬性名稱

這裡說2個常用的。

Frames Per Tasks: 每任務長度

在返回的job屬性裡是Chunk欄位

而需要傳入的是ChunkSize

呼叫的API是Jobs。SetJobFrameRange(self, id, frameList, chunkSize):

body

=

json

dumps

({

“Command”

“setjobframerange”

“JobID”

id

“FrameList”

frameList

“ChunkSize”

chunkSize

})

return

self

connectionProperties

__put__

“/api/jobs”

body

JobDependencies: 依賴job

所謂依賴關係,就是當A依賴B時,只有B渲染或解算完後才會執行A。

在返回的job中屬性是Dep:[] 一個列表

而需要傳入的名稱是JobDependencies,值為父依賴的job id

props

‘JobDependencies’

=

dependent_job_id

標簽: deadline  job  data  houdini  Web