def innerResourceInstanceMethod(*args,**kwargs) :
     resourceInstance = args[0]
     completeResponse = None
     if logRequest :
         log.prettyJson(
             resourceInstanceMethod,
             'bodyRequest',
             json.loads(Serializer.jsonifyIt(args[1:])),
             condition = logRequest,
             logLevel = log.DEBUG
         )
     try :
         FlaskManager.validateKwargs(
             kwargs,
             resourceInstance,
             innerResourceInstanceMethod,
             requestHeaderClass = requestHeaderClass,
             requestParamClass = requestParamClass
         )
         FlaskManager.validateArgs(args, requestClass, innerResourceInstanceMethod)
         completeResponse = resourceInstanceMethod(*args,**kwargs)
         FlaskManager.validateResponseClass(responseClass, completeResponse)
     except Exception as exception :
         log.warning(innerResourceInstanceMethod, 'Not posssible to complete request', exception=exception)
         raise exception
     controllerResponse = completeResponse[0] if ObjectHelper.isNotNone(completeResponse[0]) else {'message' : completeResponse[1].enumName}
     if logResponse :
         log.prettyJson(
             resourceInstanceMethod,
             'bodyResponse',
             json.loads(Serializer.jsonifyIt(controllerResponse)),
             condition = logResponse,
             logLevel = log.DEBUG
         )
     return completeResponse[0]
Esempio n. 2
0
 def innerResourceInstanceMethod(*args,**kwargs) :
     resourceInstance = args[0]
     try :
         FlaskManager.validateArgs(args,requestClass,innerResourceInstanceMethod)
         methodReturn = resourceInstanceMethod(*args,**kwargs)
     except Exception as exception :
         FlaskManager.raiseGlobalException(exception, resourceInstance, resourceInstanceMethod)
     return methodReturn
 def innerResourceInstanceMethod(*args, **kwargs):
     f'''(*args, {FlaskUtil.KW_HEADERS}={{}}, {FlaskUtil.KW_PARAMETERS}={{}}, **kwargs)'''
     resourceInstance = args[0]
     clientResponse = None
     completeResponse = None
     try :
         FlaskManager.validateKwargs(
             kwargs,
             resourceInstance,
             resourceInstanceMethod,
             requestHeaderClass,
             requestParamClass
         )
         FlaskManager.validateArgs(args, requestClass, resourceInstanceMethod)
         clientResponse = None
         httpClientEvent = getHttpClientEvent(resourceInstanceMethod, *args, **kwargs)
         if isinstance(httpClientEvent, ManualHttpClientEvent):
             completeResponse = httpClientEvent.completeResponse
         elif isinstance(httpClientEvent, HttpClientEvent):
             try :
                 clientResponse = HTTP_CLIENT_RESOLVERS_MAP.get(
                     httpClientEvent.verb,
                     raiseHttpClientEventNotFoundException
                 )(
                     resourceInstance,
                     *httpClientEvent.args,
                     **httpClientEvent.kwargs
                 )
             except Exception as exception:
                 raiseException(clientResponse, exception)
             raiseExceptionIfNeeded(clientResponse)
             completeResponse = getCompleteResponse(clientResponse, responseClass, produces)
             FlaskManager.validateCompleteResponse(responseClass, completeResponse)
         else:
             raise Exception('Unknown http client event')
     except Exception as exception:
         log.log(innerResourceInstanceMethod, 'Failure at client method execution', exception=exception, muteStackTrace=True)
         FlaskManager.raiseAndPersistGlobalException(exception, resourceInstance, resourceInstanceMethod, context=HttpDomain.CLIENT_CONTEXT)
     clientResponseStatus = completeResponse[-1]
     clientResponseHeaders = completeResponse[1]
     clientResponseBody = completeResponse[0] if ObjectHelper.isNotNone(completeResponse[0]) else {'message' : HttpStatus.map(clientResponseStatus).enumName}
     if resourceInstance.logResponse or logResponse :
         log.prettyJson(
             resourceInstanceMethod,
             '[CLIENT    ] Response',
             {
                 'headers': clientResponseHeaders,
                 'body': Serializer.getObjectAsDictionary(clientResponseBody),
                 'status': clientResponseStatus
             },
             condition = True,
             logLevel = log.INFO
         )
     if returnOnlyBody:
         return completeResponse[0]
     else:
         return completeResponse
 def innerResourceInstanceMethod(*args, **kwargs):
     resourceInstance = args[0]
     try:
         FlaskManager.validateArgs(args, requestClass,
                                   innerResourceInstanceMethod)
         args = FlaskManager.getArgsWithResponseClassInstanceAppended(
             args, responseClass)
         methodReturn = resourceInstanceMethod(*args, **kwargs)
     except Exception as exception:
         FlaskManager.raiseAndPersistGlobalException(
             exception, resourceInstance, resourceInstanceMethod)
     return methodReturn
 def innerResourceInstanceMethod(*args, **kwargs):
     resourceInstance = args[0]
     completeResponse = None
     try:
         FlaskManager.validateArgs(args, requestClass,
                                   resourceInstanceMethod)
         completeResponse = resourceInstanceMethod(*args, **kwargs)
         ###- This simple client cannot handle headers or anything this much elegant
         if ObjectHelper.isTuple(
                 completeResponse) and 0 < len(completeResponse):
             completeResponse = completeResponse[0]
     except Exception as exception:
         log.log(innerResourceInstanceMethod,
                 'Failure at client method execution',
                 exception=exception,
                 muteStackTrace=True)
         raise exception
     return completeResponse
Esempio n. 6
0
 def innerResourceInstanceMethod(*args, **kwargs):
     resourceInstanceName = methodClassName[:-len(
         FlaskManager.KW_SCHEDULER_RESOURCE)]
     resourceInstanceName = f'{resourceInstanceName[0].lower()}{resourceInstanceName[1:]}'
     args = FlaskManager.getArgumentInFrontOfArgs(
         args,
         ReflectionHelper.getAttributeOrMethod(
             apiInstance.resource.scheduler, resourceInstanceName))
     resourceInstance = args[0]
     methodReturn = None
     try:
         FlaskManager.validateArgs(args, requestClass,
                                   innerResourceInstanceMethod)
         methodReturn = resourceInstanceMethod(*args, **kwargs)
     except Exception as exception:
         FlaskManager.raiseGlobalException(exception, resourceInstance,
                                           resourceInstanceMethod)
         log.log(innerResourceInstanceMethod,
                 f'Not possible to run {shedulerId} properly',
                 exception=exception)
     return methodReturn
Esempio n. 7
0
 def innerResourceInstanceMethod(*args, **kwargs):
     resourceInstanceName = methodClassName[:-len(
         FlaskManager.KW_SCHEDULER_RESOURCE)]
     resourceInstanceName = f'{resourceInstanceName[0].lower()}{resourceInstanceName[1:]}'
     args = FlaskManager.getArgumentInFrontOfArgs(
         args,
         ReflectionHelper.getAttributeOrMethod(
             apiInstance.resource.scheduler, resourceInstanceName))
     resourceInstance = args[0]
     muteLogs = resourceInstance.muteLogs or resourceMethod.muteLogs
     if resourceInstance.enabled and not resourceInstance.disabled and not resourceMethod.disabled:
         if not muteLogs:
             log.debug(
                 resourceMethod,
                 f'{resourceMethod.shedulerId} scheduler started with args={methodArgs} and kwargs={methodKwargs}'
             )
         methodReturn = None
         try:
             FlaskManager.validateArgs(args, requestClass,
                                       innerResourceInstanceMethod)
             methodReturn = resourceMethod(*args, **kwargs)
         except Exception as exception:
             if not muteLogs:
                 log.warning(
                     resourceMethod,
                     f'Not possible to run {resourceMethod.shedulerId} properly',
                     exception=exception,
                     muteStackTrace=True)
             FlaskManager.raiseAndPersistGlobalException(
                 exception, resourceInstance, resourceMethod)
         if not muteLogs:
             log.debug(
                 resourceMethod,
                 f'{resourceMethod.shedulerId} scheduler finished')
         return methodReturn
     if not muteLogs:
         log.warning(
             resourceMethod,
             f'{resourceMethod.shedulerId} scheduler didn{c.SINGLE_QUOTE}t started. {"Schedulers are disabled" if not resourceInstance.enabled else "This scheduler is disabled" if resourceInstance.disabled else "This scheduler method is disabled"}'
         )