def encode(self, entity: Entity, property_names: Optional[List[str]]): entity_dict = { "entity": { "key": { "partitionId": { "projectId": entity.key.project if entity and entity.key else None, }, "path": entity.key.path if entity and entity.key else None, }, "properties": [], }, "URLSafeKey": entity._serialized_key if hasattr(entity, "_serialized_key") else None } for prop_name in entity.keys(): value_type, value = self._property_encode(entity.get(prop_name)) entity_dict['entity']['properties'].append( { "property_name": prop_name, "value_type": value_type, "value": value, "index": prop_name in property_names if property_names else None, }, ) return entity_dict
def entity_to_node_req(entity: datastore.Entity) -> NodeReq: return NodeReq( operation_id=entity.key.name, cluster_id=entity["cluster_id"], status=entity["status"], node_class=entity["node_class"], sequence=entity["sequence"], job_id=entity.get("job_id"), instance_name=entity["instance_name"], )