From ef7de76229b02b2597a9d20248b8c9edeacec078 Mon Sep 17 00:00:00 2001 From: gsavvas Date: Fri, 29 Mar 2024 13:52:08 +0200 Subject: [PATCH] Implement new edge node endpoints, test flow, add applicationId handling and sanitize http error of SAL Change-Id: I2ce2828053762d4ae46a0ca330693471da066b88 --- .../handlers/consumer/AMQPSalMessageHandler.groovy | 4 ++-- .../exn/modules/sal/processors/AbstractProcessor.groovy | 9 ++++++--- .../exn/modules/sal/processors/impl/NodeProcessor.groovy | 2 +- .../modules/sal/repository/AbstractSalRepository.groovy | 6 +++++- .../sal/repository/node/AbstractNodeRepository.groovy | 8 ++------ .../sal/repository/node/EdgeNodeRepository.groovy | 6 ++++++ 6 files changed, 22 insertions(+), 13 deletions(-) diff --git a/exn-middleware-core/src/main/groovy/eu/nebulouscloud/exn/modules/sal/middleware/handlers/consumer/AMQPSalMessageHandler.groovy b/exn-middleware-core/src/main/groovy/eu/nebulouscloud/exn/modules/sal/middleware/handlers/consumer/AMQPSalMessageHandler.groovy index 0e97353..d5f2c1c 100644 --- a/exn-middleware-core/src/main/groovy/eu/nebulouscloud/exn/modules/sal/middleware/handlers/consumer/AMQPSalMessageHandler.groovy +++ b/exn-middleware-core/src/main/groovy/eu/nebulouscloud/exn/modules/sal/middleware/handlers/consumer/AMQPSalMessageHandler.groovy @@ -61,7 +61,7 @@ public class AMQPSalMessageHandler extends Handler { String tempKey = message.replyTo() + message.correlationId() Publisher tempPublisher = new Publisher(tempKey, message.replyTo(), true, true) - tempPublisher.send(response, null, amqpProperties) + tempPublisher.send(response, message.subject(), amqpProperties) context.unregisterPublisher(tempKey) return @@ -74,7 +74,7 @@ public class AMQPSalMessageHandler extends Handler { // Publisher publisher = context.getPublisher(StringUtils.substringAfter(destination,context.base+'.')) as StringPublisher Publisher publisher = context.getPublisher(StringUtils.substringAfter(destination, context.base + '.')) - publisher.send(response, null, amqpProperties) + publisher.send(response, message.subject(), amqpProperties) } catch (Exception e) { log.error('Pre Sent caught exception', e) } diff --git a/exn-middleware-core/src/main/groovy/eu/nebulouscloud/exn/modules/sal/processors/AbstractProcessor.groovy b/exn-middleware-core/src/main/groovy/eu/nebulouscloud/exn/modules/sal/processors/AbstractProcessor.groovy index 4f048fa..2c05caf 100644 --- a/exn-middleware-core/src/main/groovy/eu/nebulouscloud/exn/modules/sal/processors/AbstractProcessor.groovy +++ b/exn-middleware-core/src/main/groovy/eu/nebulouscloud/exn/modules/sal/processors/AbstractProcessor.groovy @@ -69,19 +69,22 @@ abstract class AbstractProcessor implements Processor { } catch (HttpClientErrorException e) { logger.error("[{} -> {}] Client Exception during gateway request for {}", metaData?.user, method, o, e) logger.error('RAW HTTP CLIENT ERROR:\n {}', e.getMessage()) + String sanitizedError = StringUtils.substringBetween(e.getMessage(),'Message','

Exception') ?: 'Unparsable Http Client Error' ret.status = e.getStatusCode().value() - ret.body = ["key": "gateway-client-exception-error", "message": StringUtils.substring(e.getMessage(), 0, 50)] + ret.body = ["key": "gateway-client-exception-error", "message": StringUtils.substring(sanitizedError, 0, 300)] } catch (HttpServerErrorException e) { logger.error("[{} -> {}] Server Exception during gateway request for {}", metaData?.user, method, o, e) logger.error('RAW HTTP SERVER ERROR:\n {}',e.getMessage()) + String sanitizedError = StringUtils.substringBetween(e.getMessage(),'Message','

Exception') ?: 'Unparsable Http Server Error' ret.status = e.getStatusCode().value() - ret.body = ["key": "gateway-server-exception-error", "message": StringUtils.substring(e.getMessage(),0,50)] + ret.body = ["key": "gateway-server-exception-error", "message": StringUtils.substring(sanitizedError,0,300)] } catch (Exception e) { logger.error("[{} -> {}] Exception for {}", metaData?.user, method, o, e) logger.error('RAW EXCEPTION ERROR:\n {}',e.getMessage()) + String sanitizedError = StringUtils.substringBetween(e.getMessage(),'Message','

Exception') ?: 'Unparsable Generic Internal Error' ret.status = HttpStatus.INTERNAL_SERVER_ERROR.value() - ret.body = ["key": "generic-exception-error", "message": 'Generic exception while handling request for user ' + StringUtils.substring(e.getMessage(),0,50)] + ret.body = ["key": "generic-exception-error", "message": 'Generic exception while handling request for user ' + StringUtils.substring(sanitizedError,0,300)] } metaData.status = ret.status diff --git a/exn-middleware-core/src/main/groovy/eu/nebulouscloud/exn/modules/sal/processors/impl/NodeProcessor.groovy b/exn-middleware-core/src/main/groovy/eu/nebulouscloud/exn/modules/sal/processors/impl/NodeProcessor.groovy index a3cfef7..85fbe0f 100644 --- a/exn-middleware-core/src/main/groovy/eu/nebulouscloud/exn/modules/sal/processors/impl/NodeProcessor.groovy +++ b/exn-middleware-core/src/main/groovy/eu/nebulouscloud/exn/modules/sal/processors/impl/NodeProcessor.groovy @@ -123,7 +123,7 @@ class NodeProcessor extends AbstractProcessor{ HttpHeaders headers = new HttpHeaders() headers.add('sessionid',sessionId) - Object response = nodeRegistrarRepository.deleteById(metaData.jobId as String, headers) + Object response = nodeRegistrarRepository.deleteById(metaData.nodeId as String, headers) return [ "status": HttpStatus.OK.value(), diff --git a/exn-middleware-core/src/main/groovy/eu/nebulouscloud/exn/modules/sal/repository/AbstractSalRepository.groovy b/exn-middleware-core/src/main/groovy/eu/nebulouscloud/exn/modules/sal/repository/AbstractSalRepository.groovy index 8346ca8..e19cf20 100644 --- a/exn-middleware-core/src/main/groovy/eu/nebulouscloud/exn/modules/sal/repository/AbstractSalRepository.groovy +++ b/exn-middleware-core/src/main/groovy/eu/nebulouscloud/exn/modules/sal/repository/AbstractSalRepository.groovy @@ -83,6 +83,10 @@ abstract class AbstractSalRepository{ //PUT protected Object put(String url, String body, HttpHeaders headers) throws HttpStatusCodeException{ + if(!headers.containsKey('Content-Type')) { + headers.add('Content-Type', 'application/json') + } + RequestEntity entity = new RequestEntity(body, headers, HttpMethod.PUT, new URI(baseUrl+'/'+resource+(url? '/'+url:''))) return restTemplate.exchange(entity, Object.class).getBody() @@ -104,7 +108,7 @@ abstract class AbstractSalRepository{ } def getById(String id, HttpHeaders headers){ - return get(id, headers, Map.class) + return get(id, headers, Object.class) } diff --git a/exn-middleware-core/src/main/groovy/eu/nebulouscloud/exn/modules/sal/repository/node/AbstractNodeRepository.groovy b/exn-middleware-core/src/main/groovy/eu/nebulouscloud/exn/modules/sal/repository/node/AbstractNodeRepository.groovy index 9ae1f22..64e1ca0 100644 --- a/exn-middleware-core/src/main/groovy/eu/nebulouscloud/exn/modules/sal/repository/node/AbstractNodeRepository.groovy +++ b/exn-middleware-core/src/main/groovy/eu/nebulouscloud/exn/modules/sal/repository/node/AbstractNodeRepository.groovy @@ -24,12 +24,8 @@ abstract class AbstractNodeRepository extends AbstractSalRepository implements N } @Override - def deleteById(String jobId, HttpHeaders headers){ - //Payload not clear enough if this work for other type of nodes, if not override this in the derived class - if(jobId) { - return delete('remove/job/' + jobId, headers) - } + def deleteById(String edgeId, HttpHeaders headers){ - return delete('remove',headers) + return delete(edgeId,headers) } } diff --git a/exn-middleware-core/src/main/groovy/eu/nebulouscloud/exn/modules/sal/repository/node/EdgeNodeRepository.groovy b/exn-middleware-core/src/main/groovy/eu/nebulouscloud/exn/modules/sal/repository/node/EdgeNodeRepository.groovy index 77f914b..5aa0a1d 100644 --- a/exn-middleware-core/src/main/groovy/eu/nebulouscloud/exn/modules/sal/repository/node/EdgeNodeRepository.groovy +++ b/exn-middleware-core/src/main/groovy/eu/nebulouscloud/exn/modules/sal/repository/node/EdgeNodeRepository.groovy @@ -1,5 +1,6 @@ package eu.nebulouscloud.exn.modules.sal.repository.node +import org.springframework.http.HttpHeaders import org.springframework.stereotype.Repository @Repository @@ -8,4 +9,9 @@ class EdgeNodeRepository extends AbstractNodeRepository{ EdgeNodeRepository() { super('edge') } + + @Override + def register(String jobId, String body, HttpHeaders headers){ + post('register', body, headers) + } }