Skip to content

Commit

Permalink
Implement new edge node endpoints, test flow, add applicationId handl…
Browse files Browse the repository at this point in the history
…ing and sanitize http error of SAL

Change-Id: I2ce2828053762d4ae46a0ca330693471da066b88
  • Loading branch information
gsavvas-exz committed Mar 29, 2024
1 parent 3b1077c commit ef7de76
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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</b>','</p><p><b>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</b>','</p><p><b>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</b>','</p><p><b>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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> entity = new RequestEntity<String>(body, headers, HttpMethod.PUT, new URI(baseUrl+'/'+resource+(url? '/'+url:'')))

return restTemplate.exchange(entity, Object.class).getBody()
Expand All @@ -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)
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package eu.nebulouscloud.exn.modules.sal.repository.node

import org.springframework.http.HttpHeaders
import org.springframework.stereotype.Repository

@Repository
Expand All @@ -8,4 +9,9 @@ class EdgeNodeRepository extends AbstractNodeRepository{
EdgeNodeRepository() {
super('edge')
}

@Override
def register(String jobId, String body, HttpHeaders headers){
post('register', body, headers)
}
}

0 comments on commit ef7de76

Please sign in to comment.