def mdc_mapper(): """Convert the MDC dict into comma separated, name=value string :return: string format """ return ','.join(f'{k}={v}' for (k, v) in MDC.result().items() if k not in ['customField2'])
def _handler( servicer: "ArtifactManagerServicer", request: Union[BluePrintDownloadInput, BluePrintRemoveInput, BluePrintUploadInput], context: ServicerContext, ) -> BluePrintManagementOutput: try: output: BluePrintManagementOutput = func(servicer, request, context) output.status.code = 200 output.status.message = "success" except ArtifactManagerError as error: # If ArtifactManagerError is raises one of defined error occurs. # Every ArtifactManagerError based exception has status_code paramenter # which has to be set in output. Use also exception's message to # set errorMessage of the output. output: BluePrintManagementOutput = BluePrintManagementOutput() output.status.code = error.status_code output.status.message = "failure" output.status.errorMessage = str(error.message) servicer.fill_MDC_timestamps() servicer.logger.error( "Error while processing the message - blueprintName={} blueprintVersion={}" .format(request.actionIdentifiers.blueprintName, request.actionIdentifiers.blueprintVersion), extra={"mdc": MDC.result()}, ) MDC.clear() return output
def removeBlueprint(self, request: BlueprintRemoveInput, context: ServicerContext) -> BlueprintManagementOutput: """Remove blueprint file request method. Currently it only logs when is called and all base class method. :param request: BlueprintRemoveInput :param context: ServicerContext :return: BlueprintManagementOutput """ self.repository.remove_blueprint( request.actionIdentifiers.blueprintName, request.actionIdentifiers.blueprintVersion ) self.fill_MDC_timestamps() self.logger.info( "Blueprint removal successfuly processed - blueprintName={} blueprintVersion={}".format( request.actionIdentifiers.blueprintName, request.actionIdentifiers.blueprintVersion ), extra={"mdc": MDC.result()}, ) return BlueprintManagementOutput()
def downloadBlueprint(self, request: BlueprintDownloadInput, context: ServicerContext) -> BlueprintManagementOutput: """Download blueprint file request method. Currently it only logs when is called and all base class method. :param request: BlueprintDownloadInput :param context: ServicerContext :return: BlueprintManagementOutput """ output: BlueprintManagementOutput = BlueprintManagementOutput() output.fileChunk.chunk = self.repository.download_blueprint( request.actionIdentifiers.blueprintName, request.actionIdentifiers.blueprintVersion ) self.fill_MDC_timestamps() self.logger.info( "Blueprint download successfuly processed - blueprintName={} blueprintVersion={}".format( request.actionIdentifiers.blueprintName, request.actionIdentifiers.blueprintVersion ), extra={"mdc": MDC.result()}, ) return output
def augment_record(*args, **kwargs): new_record = old_record(*args, **kwargs) new_record.mdc = MDC.result() return new_record