def discover(self, request, context): logger.info("discovering.") pprint(request) descriptor_set = FileDescriptorSet() for entity in self.event_sourced_entities + self.action_protocol_entities: logger.info(f"entity: {entity.name()}") for descriptor in entity.file_descriptors: logger.info(f"discovering {descriptor.name}") logger.info(f"SD: {entity.service_descriptor.full_name}") from_string = FileDescriptorProto.FromString( descriptor.serialized_pb) descriptor_set.file.append(from_string) descriptor_set.file.append( FileDescriptorProto.FromString(Default().FindFileByName( "google/protobuf/empty.proto").serialized_pb)) descriptor_set.file.append( FileDescriptorProto.FromString(Default().FindFileByName( "cloudstate/entity_key.proto").serialized_pb)) descriptor_set.file.append( FileDescriptorProto.FromString(Default().FindFileByName( "cloudstate/eventing.proto").serialized_pb)) descriptor_set.file.append( FileDescriptorProto.FromString(Default().FindFileByName( "google/protobuf/descriptor.proto").serialized_pb)) descriptor_set.file.append( FileDescriptorProto.FromString(Default().FindFileByName( "google/api/annotations.proto").serialized_pb)) descriptor_set.file.append( FileDescriptorProto.FromString(Default().FindFileByName( "google/api/http.proto").serialized_pb)) descriptor_set.file.append( FileDescriptorProto.FromString(Default().FindFileByName( "google/api/httpbody.proto").serialized_pb)) descriptor_set.file.append( FileDescriptorProto.FromString(Default().FindFileByName( "google/protobuf/any.proto").serialized_pb)) spec = entity_pb2.EntitySpec( service_info=entity_pb2.ServiceInfo( service_name="", service_version="0.1.0", service_runtime="Python " + platform.python_version() + " [" + platform.python_implementation() + " " + platform.python_compiler() + "]", support_library_name="cloudstate-python-support", support_library_version="0.1.0", ), entities=[ entity_pb2.Entity( entity_type=entity.entity_type(), service_name=entity.service_descriptor.full_name, persistence_id=entity.persistence_id, ) for entity in self.event_sourced_entities + self.action_protocol_entities ], proto=descriptor_set.SerializeToString(), ) return spec
def discover(self, request, context): pprint(request) descriptor_set = FileDescriptorSet() for entity in self.event_sourced_entities: for descriptor in entity.file_descriptors: descriptor_set.file.append(FileDescriptorProto.FromString(descriptor.serialized_pb)) descriptor_set.file.append( FileDescriptorProto.FromString(Default().FindFileByName('google/protobuf/empty.proto').serialized_pb) ) descriptor_set.file.append( FileDescriptorProto.FromString(Default().FindFileByName('cloudstate/entity_key.proto').serialized_pb) ) descriptor_set.file.append( FileDescriptorProto.FromString(Default().FindFileByName('google/protobuf/descriptor.proto').serialized_pb) ) descriptor_set.file.append( FileDescriptorProto.FromString(Default().FindFileByName('google/api/annotations.proto').serialized_pb) ) descriptor_set.file.append( FileDescriptorProto.FromString(Default().FindFileByName('google/api/http.proto').serialized_pb) ) spec = entity_pb2.EntitySpec( service_info=entity_pb2.ServiceInfo( service_version='0.1.0', service_runtime='Python ' + platform.python_version() + ' [' + platform.python_implementation() + ' ' + platform.python_compiler() + ']', support_library_name='cloudstate-python-support', support_library_version='0.1.0' ), entities=[ entity_pb2.Entity( entity_type=entity.entity_type(), service_name=entity.service_descriptor.full_name, persistence_id=entity.persistence_id, ) for entity in self.event_sourced_entities], proto=descriptor_set.SerializeToString() ) return spec
def _createDescriptorFile(self): set_proto = FileDescriptorSet() file_proto = set_proto.file.add(name='types.proto', package='tensorflow', syntax='proto3') enum_proto = file_proto.enum_type.add(name='DataType') enum_proto.value.add(name='DT_DOUBLE', number=0) enum_proto.value.add(name='DT_BOOL', number=1) file_proto = set_proto.file.add(name='test_example.proto', package='tensorflow.contrib.proto', dependency=['types.proto']) message_proto = file_proto.message_type.add(name='TestCase') message_proto.field.add( name='values', number=1, type=FieldDescriptorProto.TYPE_MESSAGE, type_name='.tensorflow.contrib.proto.TestValue', label=FieldDescriptorProto.LABEL_REPEATED) message_proto.field.add(name='shapes', number=2, type=FieldDescriptorProto.TYPE_INT32, label=FieldDescriptorProto.LABEL_REPEATED) message_proto.field.add(name='sizes', number=3, type=FieldDescriptorProto.TYPE_INT32, label=FieldDescriptorProto.LABEL_REPEATED) message_proto.field.add( name='fields', number=4, type=FieldDescriptorProto.TYPE_MESSAGE, type_name='.tensorflow.contrib.proto.FieldSpec', label=FieldDescriptorProto.LABEL_REPEATED) message_proto = file_proto.message_type.add(name='TestValue') message_proto.field.add(name='double_value', number=1, type=FieldDescriptorProto.TYPE_DOUBLE, label=FieldDescriptorProto.LABEL_REPEATED) message_proto.field.add(name='bool_value', number=2, type=FieldDescriptorProto.TYPE_BOOL, label=FieldDescriptorProto.LABEL_REPEATED) message_proto = file_proto.message_type.add(name='FieldSpec') message_proto.field.add(name='name', number=1, type=FieldDescriptorProto.TYPE_STRING, label=FieldDescriptorProto.LABEL_OPTIONAL) message_proto.field.add(name='dtype', number=2, type=FieldDescriptorProto.TYPE_ENUM, type_name='.tensorflow.DataType', label=FieldDescriptorProto.LABEL_OPTIONAL) message_proto.field.add( name='value', number=3, type=FieldDescriptorProto.TYPE_MESSAGE, type_name='.tensorflow.contrib.proto.TestValue', label=FieldDescriptorProto.LABEL_OPTIONAL) fn = os.path.join(self.get_temp_dir(), 'descriptor.pb') with open(fn, 'wb') as f: f.write(set_proto.SerializeToString()) return fn