Commit e1d04a45 authored by Spiros Koulouzis's avatar Spiros Koulouzis

Added eample error message

Added exception handling 
parent 9f6a8fda
{"creationDate":1488794695660,"parameters":[{"name":"com.amazonaws.AmazonServiceException","encoding":"UTF-8","value":"The maximum number of VPCs has been reached. (Service: AmazonEC2; Status Code: 400; Error Code: VpcLimitExceeded; Request ID: e854939e-5386-46f3-baa8-4e3c425b98ee)"}]}
\ No newline at end of file
{"creationDate":1488368936945,"parameters":[{"name":"f293ff03-4b82-49e2-871a-899aadf821ce","encoding":"UTF-8","value":"publicKeyPath: /tmp/Input-4007028381500/user.pem\nuserName: zh9314\nsubnets:\n- {name: s1, subnet: 192.168.10.0, netmask: 255.255.255.0}\ncomponents:\n- name: faab6756-61b6-4800-bffa-ae9d859a9d6c\n type: Switch.nodes.Compute\n nodetype: t2.medium\n OStype: Ubuntu 16.04\n domain: ec2.us-east-1.amazonaws.com\n script: /tmp/Input-4007028381500/guiscipt.sh\n installation: null\n role: master\n dockers: mogswitch/InputDistributor\n public_address: 54.144.0.91\n instanceId: i-0e78cbf853328b820\n ethernet_port:\n - {name: p1, subnet_name: s1, address: 192.168.10.10}\n- name: 1c75eedf-8497-46fe-aeb8-dab6a62154cb\n type: Switch.nodes.Compute\n nodetype: t2.medium\n OStype: Ubuntu 16.04\n domain: ec2.us-east-1.amazonaws.com\n script: /tmp/Input-4007028381500/guiscipt.sh\n installation: null\n role: slave\n dockers: mogswitch/ProxyTranscoder\n public_address: 34.207.254.160\n instanceId: i-0a99ea18fcc77ed7a\n ethernet_port:\n - {name: p1, subnet_name: s1, address: 192.168.10.11}\n"},{"name":"kubernetes","encoding":"UTF-8","value":"54.144.0.91 ubuntu /tmp/Input-4007028381500/Virginia.pem master\n34.207.254.160 ubuntu /tmp/Input-4007028381500/Virginia.pem slave\n"}]}
\ No newline at end of file
/*
* Copyright 2017 S. Koulouzis, Wang Junchao, Huan Zhou, Yang Hu
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package nl.uva.sne.drip.api.exception;
/**
*
* @author S. Koulouzis
*/
public class ExceptionHandler {
public static RuntimeException generateException(String name, String value) {
if (value.contains("The maximum number of VPCs has been reached")) {
return new VMLimitException(name + "." + value);
}
else{
return new InternalServerErrorExeption();
}
}
}
/*
* Copyright 2017 S. Koulouzis, Wang Junchao, Huan Zhou, Yang Hu
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package nl.uva.sne.drip.api.exception;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
/**
*
* @author S. Koulouzis
*/
@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
public class InternalServerErrorExeption extends RuntimeException {
public InternalServerErrorExeption(String massage) {
super(massage);
}
public InternalServerErrorExeption() {
super();
}
}
/*
* Copyright 2017 S. Koulouzis, Wang Junchao, Huan Zhou, Yang Hu
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package nl.uva.sne.drip.api.exception;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
/**
*
* @author S. Koulouzis
*/
@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR, reason = "The maximum number of VMs has been reached")
public class VMLimitException extends RuntimeException {
public VMLimitException(String string) {
super(string);
}
public VMLimitException() {
super();
}
}
......@@ -45,6 +45,7 @@ import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import nl.uva.sne.drip.api.exception.BadRequestException;
import nl.uva.sne.drip.api.exception.CloudCredentialsNotFoundException;
import nl.uva.sne.drip.api.exception.ExceptionHandler;
import nl.uva.sne.drip.api.exception.InternalServerErrorException;
import nl.uva.sne.drip.api.exception.NotFoundException;
import nl.uva.sne.drip.api.exception.PlanNotFoundException;
......@@ -129,14 +130,15 @@ public class ProvisionController {
try (DRIPCaller provisioner = new ProvisionerCaller(messageBrokerHost);) {
Message provisionerInvokationMessage = buildProvisionerMessage(req);
Message response = (provisioner.call(provisionerInvokationMessage));
Message response = (provisioner.call(provisionerInvokationMessage));
// Message response = generateFakeResponse();
List<MessageParameter> params = response.getParameters();
for (MessageParameter p : params) {
String name = p.getName();
if (name.toLowerCase().contains("exception")) {
throw new InternalServerErrorException(name + ". " + p.getValue());
throw ExceptionHandler.generateException(name, p.getValue());
}
if (!name.equals("kubernetes")) {
String value = p.getValue();
......
......@@ -129,6 +129,7 @@ public class Consumer extends DefaultConsumer {
+ ex.getClass().getName() + "\",\"attributes\": null}]}";
}
} finally {
Logger.getLogger(Consumer.class.getName()).log(Level.INFO, "Sending Response: {0}", response);
//We send the response back. No need to change anything here
channel.basicPublish("", properties.getReplyTo(), replyProps, response.getBytes("UTF-8"));
channel.basicAck(envelope.getDeliveryTag(), false);
......
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