def __init__(self, service: ServiceDescriptor, *, name: str = None, peer_uid: uuid.UUID = None, manager: ChannelManager = None): """ Arguments: service: Service to start. name: Container name. peer_uid: Peer ID, `None` means that newly generated UUID type 1 should be used. manager: ChannelManager to be used. """ self.outcome: Outcome = Outcome.UNKNOWN self.details: List[str] = [] self.log_context = None self.name: str = service.agent.name if name is None else name self.peer_uid: uuid.UUID = peer_uid self.service: ServiceDescriptor = service self.peer: PeerDescriptor = None self.endpoints: Dict[str, List[ZMQAddress]] = {} self.config: Config = service.config() self.ctrl_addr: ZMQAddress = ZMQAddress(f'inproc://{uuid.uuid1().hex}') self.mngr: ChannelManager = manager self._ext_mngr: bool = manager is not None
def validate(self) -> None: """Extended validation. - `block_size` is positive or -1. """ super().validate() # Blocik size if (self.block_size.value < -1) or (self.block_size.value == 0): raise Error("'block_size' must be positive or -1") # Service description SERVICE_AGENT: AgentDescriptor = \ AgentDescriptor(uid=SERVICE_UID, name="saturnin.binary.reader", version=SERVICE_VERSION, vendor_uid=VENDOR_UID, classification="binary/reader") SERVICE_DESCRIPTOR: ServiceDescriptor = \ ServiceDescriptor(agent=SERVICE_AGENT, api=[], description="Binary data reader microservice", facilities=[], package=pkg_name(__name__), factory=f'{pkg_name(__name__)}.service:BinaryReaderMicro', config=partial(create_config, BinaryReaderConfig, f'{SERVICE_AGENT.name}_service'))
raise Error(f"Unknown MIME parameter '{param}' in pipe format") # Output Pipe format fmt = self.output_pipe_format if fmt.value.mime_type != MIME_TYPE_PROTO: raise Error( f"MIME type '{fmt.value.mime_type}' is not a valid output format" ) if fmt.value.params['type'] != LOG_PROTO: raise Error( f"Unsupported protobuf type '{fmt.value.params['type']}'") # Service description SERVICE_AGENT: AgentDescriptor = \ AgentDescriptor(uid=SERVICE_UID, name='saturnin.firebird.log.parser', version=SERVICE_VERSION, vendor_uid=VENDOR_UID, classification="firebird-log/parser") SERVICE_DESCRIPTOR: ServiceDescriptor = \ ServiceDescriptor(agent=SERVICE_AGENT, api=[], description="Firebird log parser microservice", facilities=[], package=pkg_name(__name__), factory=f'{pkg_name(__name__)}.service:FbLogParserMicro', config=partial(create_config, FbLogParserConfig, f'{SERVICE_AGENT.name}_service'))
MIMEOption('file_format', "File data format specification", required=True, default=MIME('text/plain;charset=utf-8')) def validate(self) -> None: """Extended validation.""" super().validate() if (self.filename.value.lower() in ['stdin', 'stdout', 'stderr'] and self.file_mode.value not in [FileOpenMode.WRITE, FileOpenMode.READ]): raise Error("STD[IN|OUT|ERR] support only READ and WRITE modes") # Service description SERVICE_AGENT: AgentDescriptor = \ AgentDescriptor(uid=SERVICE_UID, name='saturnin.example.textio', version=SERVICE_VERSION, vendor_uid=VENDOR_UID, classification='example/micro') SERVICE_DESCRIPTOR: ServiceDescriptor = \ ServiceDescriptor(agent=SERVICE_AGENT, api=[], description="Sample TEXTIO microservice", facilities=[], package=pkg_name(__name__), factory=f'{pkg_name(__name__)}.service:MicroTextIOSvc', config=partial(create_config, TextIOConfig, f'{SERVICE_AGENT.name}_service'))
defined += 1 if defined != 1: raise Error( "Configuration must contain either 'template' or 'func' option" ) # try: self.func.value except Exception as exc: raise Error("Invalid code definition in 'func' option") from exc # Service description SERVICE_AGENT: AgentDescriptor = \ AgentDescriptor(uid=SERVICE_UID, name="saturnin.proto.printer", version=SERVICE_VERSION, vendor_uid=VENDOR_UID, classification="proto/printer") SERVICE_DESCRIPTOR: ServiceDescriptor = \ ServiceDescriptor(agent=SERVICE_AGENT, api=[], description="Protobuf data printer microservice", facilities=[], package=pkg_name(__name__), factory=f'{pkg_name(__name__)}.service:ProtoPrinterMicro', config=partial(create_config, ProtoPrinterConfig, f'{SERVICE_AGENT.name}_service'))
ROMAN_INTERFACE_UID: UUID = UUID('d0e35134-44af-11e9-b5b8-5404a6a1fd6e') class RomanAPI(ButlerInterface): """Roman Service Request Codes. """ ROMAN = 1 @classmethod def get_uid(cls) -> UUID: return ROMAN_INTERFACE_UID SERVICE_AGENT: AgentDescriptor = \ AgentDescriptor(uid=SERVICE_UID, name='saturnin.example.roman', version=SERVICE_VERSION, vendor_uid=VENDOR_UID, classification='example/service') SERVICE_API = [RomanAPI] SERVICE_DESCRIPTOR: ServiceDescriptor = \ ServiceDescriptor(agent=SERVICE_AGENT, api=SERVICE_API, description="Sample ROMAN service", facilities=[], package=pkg_name(__name__), factory=f'{pkg_name(__name__)}.service:RomanService', config=partial(create_config, ServiceConfig, f'{SERVICE_AGENT.name}_service'))
defined = 0 for opt in (self.regex, self.expr, self.func): if opt.value is not None: defined += 1 if defined != 1: raise Error( "Configuration must contain exactly one filter definition.") # regex if self.regex.value is not None: re.compile(self.regex.value) # Service description SERVICE_AGENT: AgentDescriptor = \ AgentDescriptor(uid=SERVICE_UID, name="saturnin.text.linefilter", version=SERVICE_VERSION, vendor_uid=VENDOR_UID, classification="text/filter") SERVICE_DESCRIPTOR: ServiceDescriptor = \ ServiceDescriptor(agent=SERVICE_AGENT, api=[], description="Text line filter microservice", facilities=[], package=pkg_name(__name__), factory=f'{pkg_name(__name__)}.service:TextLineFilterMicro', config=partial(create_config, TextFilterConfig, f'{SERVICE_AGENT.name}_service'))
- Only 'charset' and 'errors' MIME parameters are alowed for `pipe_format`. """ super().validate() # Pipe format if self.pipe_format.value.mime_type != MIME_TYPE_TEXT: raise Error("Only 'text/plain' pipe format supported") for param in self.pipe_format.value.params.keys(): if param not in ('charset', 'errors'): raise Error( f"Unsupported MIME parameter '{param}' in pipe format") # Service description SERVICE_AGENT: AgentDescriptor = \ AgentDescriptor(uid=SERVICE_UID, name='saturnin.firebird.trace.session', version=SERVICE_VERSION, vendor_uid=VENDOR_UID, classification='firebird-trace/session') SERVICE_DESCRIPTOR: ServiceDescriptor = \ ServiceDescriptor(agent=SERVICE_AGENT, api=[], description="Firebird trace session provider microservice", facilities=['firebird'], package=pkg_name(__name__), factory=f'{pkg_name(__name__)}.service:FbTraceSessionMicro', config=partial(create_config, FbTraceSessionConfig, f'{SERVICE_AGENT.name}_service'))
- Only 'charset' and 'errors' MIME parameters are alowed for `pipe_format`. """ super().validate() # Pipe format if self.pipe_format.value.mime_type != MIME_TYPE_TEXT: raise Error("Only 'text/plain' pipe format supported") for param in self.pipe_format.value.params.keys(): if param not in ('charset', 'errors'): raise Error( f"Unsupported MIME parameter '{param}' in pipe format") # Service description SERVICE_AGENT: AgentDescriptor = \ AgentDescriptor(uid=SERVICE_UID, name='saturnin.firebird.log.fromsrv', version=SERVICE_VERSION, vendor_uid=VENDOR_UID, classification='firebird-log/provider') SERVICE_DESCRIPTOR: ServiceDescriptor = \ ServiceDescriptor(agent=SERVICE_AGENT, api=[], description="Firebird log from server provider microservice", facilities=['firebird'], package=pkg_name(__name__), factory=f'{pkg_name(__name__)}.service:FbLogFromSrvMicro', config=partial(create_config, FbLogFromSrvConfig, f'{SERVICE_AGENT.name}_service'))
class DummyConfig(ComponentConfig): """Text file reader microservice configuration. """ def __init__(self, name: str): super().__init__(name) self.fail_on: EnumOption = \ EnumOption('fail_on', FailOn, "Stage when dummy should raise an exception", default=FailOn.NEVER) self.schedule: ListOption = \ ListOption('schedule', int, "Delays for dummy scheduled actions", default=list()) # Service description SERVICE_AGENT: AgentDescriptor = \ AgentDescriptor(uid=SERVICE_UID, name="saturnin.micro.dummy", version=SERVICE_VERSION, vendor_uid=VENDOR_UID, classification="test/dummy") SERVICE_DESCRIPTOR: ServiceDescriptor = \ ServiceDescriptor(agent=SERVICE_AGENT, api=[], description="Test dummy microservice", facilities=[], package=pkg_name(__name__), factory=f'{pkg_name(__name__)}.service:MicroDummySvc', config=partial(create_config, DummyConfig, f'{SERVICE_AGENT.name}.service'))