Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(33)

Side by Side Diff: appengine/swarming/message_conversion.py

Issue 1910713002: swarming: add support for cipd on the server side (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/luci-py@master
Patch Set: nits Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 # Copyright 2015 The LUCI Authors. All rights reserved. 1 # Copyright 2015 The LUCI Authors. All rights reserved.
2 # Use of this source code is governed by the Apache v2.0 license that can be 2 # Use of this source code is governed by the Apache v2.0 license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """This module facilitates conversion from dictionaries to ProtoRPC messages. 5 """This module facilitates conversion from dictionaries to ProtoRPC messages.
6 6
7 Given a dictionary whose keys' names and values' types comport with the 7 Given a dictionary whose keys' names and values' types comport with the
8 fields defined for a protorpc.messages.Message subclass, this module tries to 8 fields defined for a protorpc.messages.Message subclass, this module tries to
9 generate a Message instance that corresponds to the provided dictionary. The 9 generate a Message instance that corresponds to the provided dictionary. The
10 "normal" use case is for ndb.Models which need to be represented as a 10 "normal" use case is for ndb.Models which need to be represented as a
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 if props.commands: 111 if props.commands:
112 cmd = props.commands[0] 112 cmd = props.commands[0]
113 elif props.command: 113 elif props.command:
114 cmd = props.command 114 cmd = props.command
115 properties = _ndb_to_rpc( 115 properties = _ndb_to_rpc(
116 swarming_rpcs.TaskProperties, 116 swarming_rpcs.TaskProperties,
117 props, 117 props,
118 command=cmd, 118 command=cmd,
119 dimensions=_string_pairs_from_dict(props.dimensions), 119 dimensions=_string_pairs_from_dict(props.dimensions),
120 env=_string_pairs_from_dict(props.env), 120 env=_string_pairs_from_dict(props.env),
121 inputs_ref=inputs_ref) 121 inputs_ref=inputs_ref,
122 packages=[
123 _ndb_to_rpc(swarming_rpcs.CipdPackage, p) for p in props.packages
124 ])
122 125
123 return _ndb_to_rpc( 126 return _ndb_to_rpc(
124 swarming_rpcs.TaskRequest, 127 swarming_rpcs.TaskRequest,
125 entity, 128 entity,
126 authenticated=entity.authenticated.to_bytes(), 129 authenticated=entity.authenticated.to_bytes(),
127 properties=properties) 130 properties=properties)
128 131
129 132
130 def new_task_request_from_rpc(msg, now): 133 def new_task_request_from_rpc(msg, now):
131 """"Returns a task_request.TaskRequest from a swarming_rpcs.NewTaskRequest.""" 134 """"Returns a task_request.TaskRequest from a swarming_rpcs.NewTaskRequest."""
132 assert msg.__class__ is swarming_rpcs.NewTaskRequest 135 assert msg.__class__ is swarming_rpcs.NewTaskRequest
133 props = msg.properties 136 props = msg.properties
134 if not props: 137 if not props:
135 raise ValueError('properties is required') 138 raise ValueError('properties is required')
136 inputs_ref = None 139 inputs_ref = None
137 if props.inputs_ref: 140 if props.inputs_ref:
138 inputs_ref = _rpc_to_ndb(task_request.FilesRef, props.inputs_ref) 141 inputs_ref = _rpc_to_ndb(task_request.FilesRef, props.inputs_ref)
139 properties = _rpc_to_ndb( 142 properties = _rpc_to_ndb(
140 task_request.TaskProperties, 143 task_request.TaskProperties,
141 props, 144 props,
142 # Passing command=None is supported at API level but not at NDB level. 145 # Passing command=None is supported at API level but not at NDB level.
143 command=props.command or [], 146 command=props.command or [],
144 # Legacy, ignored. 147 # Legacy, ignored.
145 commands=None, 148 commands=None,
146 dimensions={i.key: i.value for i in props.dimensions}, 149 dimensions={i.key: i.value for i in props.dimensions},
147 env={i.key: i.value for i in props.env}, 150 env={i.key: i.value for i in props.env},
148 inputs_ref=inputs_ref) 151 inputs_ref=inputs_ref,
152 packages=[
153 _rpc_to_ndb(task_request.CipdPackage, p) for p in props.packages
154 ])
149 155
150 return _rpc_to_ndb( 156 return _rpc_to_ndb(
151 task_request.TaskRequest, 157 task_request.TaskRequest,
152 msg, 158 msg,
153 created_ts=now, 159 created_ts=now,
154 expiration_ts=now+datetime.timedelta(seconds=msg.expiration_secs), 160 expiration_ts=now+datetime.timedelta(seconds=msg.expiration_secs),
155 # It is set in task_request.make_request(). 161 # It is set in task_request.make_request().
156 authenticated=None, 162 authenticated=None,
157 properties=properties) 163 properties=properties)
158 164
(...skipping 28 matching lines...) Expand all
187 kwargs['costs_usd'].append(entity.cost_usd) 193 kwargs['costs_usd'].append(entity.cost_usd)
188 kwargs['properties_hash'] = None 194 kwargs['properties_hash'] = None
189 kwargs['tags'] = [] 195 kwargs['tags'] = []
190 kwargs['user'] = None 196 kwargs['user'] = None
191 else: 197 else:
192 assert entity.__class__ is task_result.TaskResultSummary, entity 198 assert entity.__class__ is task_result.TaskResultSummary, entity
193 kwargs['properties_hash'] = ( 199 kwargs['properties_hash'] = (
194 entity.properties_hash.encode('hex') 200 entity.properties_hash.encode('hex')
195 if entity.properties_hash else None) 201 if entity.properties_hash else None)
196 return _ndb_to_rpc(swarming_rpcs.TaskResult, entity, **kwargs) 202 return _ndb_to_rpc(swarming_rpcs.TaskResult, entity, **kwargs)
OLDNEW
« no previous file with comments | « appengine/swarming/handlers_endpoints_test.py ('k') | appengine/swarming/server/task_request.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698