Commit d45e9d4b authored by Spiros Koulouzis's avatar Spiros Koulouzis

added timeout

parent 80c0c3f6
version: '3' version: '3'
services: services:
#nginx: nginx:
#image: nginx image: nginx
#volumes: volumes:
#- ./nginx.conf:/etc/nginx/nginx.conf - ./nginx.conf:/etc/nginx/nginx.conf
#- ./cert.pem:/etc/nginx/cert.pem - ./cert.pem:/etc/nginx/cert.pem
#- ./privkey.pem:/etc/nginx/privkey.pem - ./privkey.pem:/etc/nginx/privkey.pem
##- ./www:/data/www #- ./www:/data/www
#ports: ports:
#- "80:80" - "80:80"
#- "443:443" - "443:443"
#rabbit: rabbit:
#image: rabbitmq:3.8-management image: rabbitmq:3.8-management
#ports: ports:
#- "5671-5672:5671-5672" - "5671-5672:5671-5672"
#- "15672:15672" - "15672:15672"
#- "4369:4369" - "4369:4369"
#- "15671:15671" - "15671:15671"
mysql: mysql:
image: mysql:5.7 image: mysql:5.7
...@@ -49,18 +49,18 @@ services: ...@@ -49,18 +49,18 @@ services:
depends_on: depends_on:
- mysql - mysql
#mongo: mongo:
#image: mongo:4 image: mongo:4
#ports: ports:
#- "27017:27017" - "27017:27017"
#sure-tosca: sure-tosca:
#image: qcdis/sure-tosca image: qcdis/sure-tosca
#ports: ports:
#- "8081:8081" - "8081:8081"
......
...@@ -12,25 +12,25 @@ services: ...@@ -12,25 +12,25 @@ services:
- "80:80" - "80:80"
- "443:443" - "443:443"
#rabbit: rabbit:
#image: rabbitmq:3.8-management image: rabbitmq:3.8-management
#ports: ports:
#- "5671-5672:5671-5672" - "5671-5672:5671-5672"
#- "15672:15672" - "15672:15672"
#- "4369:4369" - "4369:4369"
#- "15671:15671" - "15671:15671"
#mysql: mysql:
#image: mysql:5.7 image: mysql:5.7
#volumes: volumes:
#- ./mysql.cnf:/etc/mysql/mysql.conf.d/mysqld.cnf - ./mysql.cnf:/etc/mysql/mysql.conf.d/mysqld.cnf
#environment: environment:
#MYSQL_RANDOM_ROOT_PASSWORD: 'yes' MYSQL_RANDOM_ROOT_PASSWORD: 'yes'
#MYSQL_DATABASE: semaphore MYSQL_DATABASE: semaphore
#MYSQL_USER: semaphore MYSQL_USER: semaphore
#MYSQL_PASSWORD: semaphore MYSQL_PASSWORD: semaphore
##ports: #ports:
##- "3306:3306" #- "3306:3306"
semaphore: semaphore:
image: qcdis/docker_ansible_semaphore image: qcdis/docker_ansible_semaphore
...@@ -81,21 +81,21 @@ services: ...@@ -81,21 +81,21 @@ services:
ports: ports:
- "3001:3000" - "3001:3000"
manager: #manager:
depends_on: #depends_on:
- rabbit #- rabbit
- mongo #- mongo
- sure-tosca #- sure-tosca
image: qcdis/manager #image: qcdis/manager
environment: #environment:
RABBITMQ_HOST: rabbit #RABBITMQ_HOST: rabbit
MONGO_HOST: mongo #MONGO_HOST: mongo
SURE_TOSCA_BASE_PATH: http://sure-tosca:8081/tosca-sure/1.0.0 #SURE_TOSCA_BASE_PATH: http://sure-tosca:8081/tosca-sure/1.0.0
CREDENTIAL_SECRET: top_secret #CREDENTIAL_SECRET: top_secret
ports: #ports:
- "8080:8080" #- "8080:8080"
sure-tosca: sure-tosca:
image: qcdis/sure-tosca image: qcdis/sure-tosca
......
...@@ -43,18 +43,23 @@ public class PlannerApiController implements PlannerApi { ...@@ -43,18 +43,23 @@ public class PlannerApiController implements PlannerApi {
// String accept = request.getHeader("Accept"); // String accept = request.getHeader("Accept");
// if (accept != null && accept.contains("text/plain")) { // if (accept != null && accept.contains("text/plain")) {
try { try {
String planedYemplateId = dripService.plan(id); String planedYemplateId = dripService.plan(id);
return new ResponseEntity<>(planedYemplateId, HttpStatus.OK); return new ResponseEntity<>(planedYemplateId, HttpStatus.OK);
} catch (ApiException | NotFoundException | IOException | TimeoutException | InterruptedException ex) { } catch (NotFoundException | java.util.NoSuchElementException ex) {
java.util.logging.Logger.getLogger(PlannerApiController.class.getName()).log(Level.SEVERE, null, ex); java.util.logging.Logger.getLogger(ToscaTemplateApiController.class.getName()).log(Level.WARNING, null, ex);
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); return new ResponseEntity<>(HttpStatus.NOT_FOUND);
} } catch (TimeoutException ex) {
java.util.logging.Logger.getLogger(PlannerApiController.class.getName()).log(Level.SEVERE, null, ex);
return new ResponseEntity<>(HttpStatus.GATEWAY_TIMEOUT);
} catch (ApiException | IOException | InterruptedException ex) {
java.util.logging.Logger.getLogger(PlannerApiController.class.getName()).log(Level.SEVERE, null, ex);
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
}
// } else { // } else {
// return new ResponseEntity<>(HttpStatus.NOT_ACCEPTABLE); // return new ResponseEntity<>(HttpStatus.NOT_ACCEPTABLE);
// } // }
} }
} }
...@@ -54,38 +54,40 @@ public class ToscaTemplateApiController implements ToscaTemplateApi { ...@@ -54,38 +54,40 @@ public class ToscaTemplateApiController implements ToscaTemplateApi {
@Valid @RequestParam(value = "node_names", required = false) List<String> nodeName) { @Valid @RequestParam(value = "node_names", required = false) List<String> nodeName) {
// String accept = request.getHeader("Accept"); // String accept = request.getHeader("Accept");
// if (accept != null && accept.contains("text/plain")) { // if (accept != null && accept.contains("text/plain")) {
try { try {
dripService.delete(id, nodeName); dripService.delete(id, nodeName);
return new ResponseEntity<>(id, HttpStatus.OK); return new ResponseEntity<>(id, HttpStatus.OK);
} catch (IOException | ApiException | TypeExeption | TimeoutException | InterruptedException ex) { } catch (IOException | ApiException | TypeExeption | TimeoutException | InterruptedException ex) {
java.util.logging.Logger.getLogger(ToscaTemplateApiController.class.getName()).log(Level.SEVERE, null, ex); java.util.logging.Logger.getLogger(ToscaTemplateApiController.class.getName()).log(Level.SEVERE, null, ex);
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
} catch (NotFoundException ex) { } catch (NotFoundException ex) {
return new ResponseEntity<>(HttpStatus.NOT_FOUND); return new ResponseEntity<>(HttpStatus.NOT_FOUND);
} }
// } else { // } else {
// return new ResponseEntity<>(HttpStatus.NOT_ACCEPTABLE); // return new ResponseEntity<>(HttpStatus.NOT_ACCEPTABLE);
// } // }
} }
@Override @Override
public ResponseEntity<String> getToscaTemplateByID(@ApiParam(value = "ID of topolog template to return", required = true) public ResponseEntity<String> getToscaTemplateByID(@ApiParam(value = "ID of topolog template to return", required = true)
@PathVariable("id") String id) { @PathVariable("id") String id) {
// String accept = request.getHeader("Accept"); // String accept = request.getHeader("Accept");
// if (accept != null && accept.contains("text/plain")) { // if (accept != null && accept.contains("text/plain")) {
try { try {
java.util.logging.Logger.getLogger(ToscaTemplateApiController.class.getName()).log(Level.INFO, "Requestsed ID: {0}", id); java.util.logging.Logger.getLogger(ToscaTemplateApiController.class.getName()).log(Level.INFO, "Requestsed ID: {0}", id);
String ymlStr = toscaTemplateService.findByID(id); String ymlStr = toscaTemplateService.findByID(id);
return new ResponseEntity<>(ymlStr, HttpStatus.OK); return new ResponseEntity<>(ymlStr, HttpStatus.OK);
} catch (JsonProcessingException | NotFoundException ex) { } catch (NotFoundException | java.util.NoSuchElementException ex) {
java.util.logging.Logger.getLogger(ToscaTemplateApiController.class.getName()).log(Level.SEVERE, null, ex); java.util.logging.Logger.getLogger(ToscaTemplateApiController.class.getName()).log(Level.WARNING, null, ex);
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); return new ResponseEntity<>(HttpStatus.NOT_FOUND);
} } catch (JsonProcessingException ex) {
java.util.logging.Logger.getLogger(ToscaTemplateApiController.class.getName()).log(Level.SEVERE, null, ex);
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
}
// } else { // } else {
// return new ResponseEntity<>(HttpStatus.NOT_ACCEPTABLE); // return new ResponseEntity<>(HttpStatus.NOT_ACCEPTABLE);
// } // }
} }
@Override @Override
...@@ -95,14 +97,14 @@ public class ToscaTemplateApiController implements ToscaTemplateApi { ...@@ -95,14 +97,14 @@ public class ToscaTemplateApiController implements ToscaTemplateApi {
@Valid @RequestPart("file") MultipartFile file) { @Valid @RequestPart("file") MultipartFile file) {
// String accept = request.getHeader("Accept"); // String accept = request.getHeader("Accept");
// if (accept != null && accept.contains("text/plain")) { // if (accept != null && accept.contains("text/plain")) {
try { try {
id = toscaTemplateService.updateToscaTemplateByID(id, file); id = toscaTemplateService.updateToscaTemplateByID(id, file);
return new ResponseEntity<>(id, HttpStatus.OK); return new ResponseEntity<>(id, HttpStatus.OK);
} catch (IOException e) { } catch (IOException e) {
log.error("Couldn't serialize response for content type ", e); log.error("Couldn't serialize response for content type ", e);
java.util.logging.Logger.getLogger(ToscaTemplateApiController.class.getName()).log(Level.SEVERE, null, e); java.util.logging.Logger.getLogger(ToscaTemplateApiController.class.getName()).log(Level.SEVERE, null, e);
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
} }
// } else { // } else {
// return new ResponseEntity<>(HttpStatus.NOT_ACCEPTABLE); // return new ResponseEntity<>(HttpStatus.NOT_ACCEPTABLE);
// } // }
...@@ -112,14 +114,14 @@ public class ToscaTemplateApiController implements ToscaTemplateApi { ...@@ -112,14 +114,14 @@ public class ToscaTemplateApiController implements ToscaTemplateApi {
public ResponseEntity<String> uploadToscaTemplate(@ApiParam(value = "file detail") @Valid @RequestPart("file") MultipartFile file) { public ResponseEntity<String> uploadToscaTemplate(@ApiParam(value = "file detail") @Valid @RequestPart("file") MultipartFile file) {
// String accept = request.getHeader("Accept"); // String accept = request.getHeader("Accept");
// if (accept != null && accept.contains("*/*")) { // if (accept != null && accept.contains("*/*")) {
try { try {
String id = toscaTemplateService.saveFile(file); String id = toscaTemplateService.saveFile(file);
return new ResponseEntity<>(id, HttpStatus.OK); return new ResponseEntity<>(id, HttpStatus.OK);
} catch (IOException e) { } catch (IOException e) {
java.util.logging.Logger.getLogger(ToscaTemplateApiController.class.getName()).log(Level.SEVERE, null, e); java.util.logging.Logger.getLogger(ToscaTemplateApiController.class.getName()).log(Level.SEVERE, null, e);
log.error("Couldn't serialize response for content type application/json", e); log.error("Couldn't serialize response for content type application/json", e);
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
} }
// } else { // } else {
// return new ResponseEntity<>(HttpStatus.NOT_ACCEPTABLE); // return new ResponseEntity<>(HttpStatus.NOT_ACCEPTABLE);
// } // }
...@@ -130,8 +132,8 @@ public class ToscaTemplateApiController implements ToscaTemplateApi { ...@@ -130,8 +132,8 @@ public class ToscaTemplateApiController implements ToscaTemplateApi {
public ResponseEntity<List<String>> getToscaTemplateIDs() { public ResponseEntity<List<String>> getToscaTemplateIDs() {
// String accept = request.getHeader("Accept"); // String accept = request.getHeader("Accept");
// if (accept != null && accept.contains("application/json")) { // if (accept != null && accept.contains("application/json")) {
List<String> ids = toscaTemplateService.getAllIds(); List<String> ids = toscaTemplateService.getAllIds();
return new ResponseEntity<>(ids, HttpStatus.OK); return new ResponseEntity<>(ids, HttpStatus.OK);
// } else { // } else {
// return new ResponseEntity<>(HttpStatus.NOT_ACCEPTABLE); // return new ResponseEntity<>(HttpStatus.NOT_ACCEPTABLE);
// } // }
......
...@@ -9,9 +9,12 @@ import com.rabbitmq.client.ConnectionFactory; ...@@ -9,9 +9,12 @@ import com.rabbitmq.client.ConnectionFactory;
import com.rabbitmq.client.DefaultConsumer; import com.rabbitmq.client.DefaultConsumer;
import com.rabbitmq.client.Envelope; import com.rabbitmq.client.Envelope;
import java.io.IOException; import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue; import java.util.concurrent.BlockingQueue;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException; import java.util.concurrent.TimeoutException;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
...@@ -64,7 +67,11 @@ public class DRIPCaller implements AutoCloseable { ...@@ -64,7 +67,11 @@ public class DRIPCaller implements AutoCloseable {
connection = factory.newConnection(); connection = factory.newConnection();
channel = connection.createChannel(); channel = connection.createChannel();
// create a single callback queue per client not per requests. // create a single callback queue per client not per requests.
// Map<String, Object> args = new HashMap<String, Object>();
// args.put("x-message-ttl", 60000);
// channel.queueDeclare("myqueue", false, false, false, args);
replyQueueName = channel.queueDeclare().getQueue(); replyQueueName = channel.queueDeclare().getQueue();
} }
} }
...@@ -107,9 +114,11 @@ public class DRIPCaller implements AutoCloseable { ...@@ -107,9 +114,11 @@ public class DRIPCaller implements AutoCloseable {
final String corrId = UUID.randomUUID().toString(); final String corrId = UUID.randomUUID().toString();
AMQP.BasicProperties props = new AMQP.BasicProperties.Builder() AMQP.BasicProperties props = new AMQP.BasicProperties.Builder()
.correlationId(corrId) .correlationId(corrId)
.expiration("10000")
.replyTo(getReplyQueueName()) .replyTo(getReplyQueueName())
.build(); .build();
Logger.getLogger(DRIPCaller.class.getName()).log(Level.INFO, "Sending: {0} to queue: {1}", new Object[]{jsonInString, getRequestQeueName()}); Logger.getLogger(DRIPCaller.class.getName()).log(Level.INFO, "Sending: {0} to queue: {1}", new Object[]{jsonInString, getRequestQeueName()});
getChannel().basicPublish("", getRequestQeueName(), props, jsonInString.getBytes("UTF-8")); getChannel().basicPublish("", getRequestQeueName(), props, jsonInString.getBytes("UTF-8"));
final BlockingQueue<String> response = new ArrayBlockingQueue(1); final BlockingQueue<String> response = new ArrayBlockingQueue(1);
...@@ -122,9 +131,19 @@ public class DRIPCaller implements AutoCloseable { ...@@ -122,9 +131,19 @@ public class DRIPCaller implements AutoCloseable {
} }
} }
}); });
String resp = response.take(); // String resp = response.take();
int timeOut = 25;
if (getRequestQeueName().equals("planner")) {
timeOut = 5;
}
if (getRequestQeueName().equals("provisioner")) {
timeOut = 10;
}
String resp = response.poll(timeOut, TimeUnit.MINUTES);
Logger.getLogger(DRIPCaller.class.getName()).log(Level.INFO, "Got: {0}", resp); Logger.getLogger(DRIPCaller.class.getName()).log(Level.INFO, "Got: {0}", resp);
if (resp == null) {
throw new TimeoutException("Timeout on qeue: " + getRequestQeueName());
}
return mapper.readValue(resp, Message.class); return mapper.readValue(resp, Message.class);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment