Merge "Added per-flow TEP and per-port TEP example in SW schema IT"
[ovsdb.git] / openstack / net-virt / src / main / java / org / opendaylight / ovsdb / openstack / netvirt / AbstractHandler.java
1 /*
2  * Copyright (C) 2013 Red Hat, Inc.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Authors : Madhu Venugopal, Brent Salisbury
9  */
10 package org.opendaylight.ovsdb.openstack.netvirt;
11
12 import org.opendaylight.controller.sal.utils.Status;
13 import org.opendaylight.controller.sal.utils.StatusCode;
14
15 import org.slf4j.Logger;
16 import org.slf4j.LoggerFactory;
17
18 import java.net.HttpURLConnection;
19
20 /**
21  * Abstract class for utility functions used by neutron handlers.
22  */
23 public abstract class AbstractHandler {
24
25     /**
26      * Logger instance.
27      */
28     static final Logger logger = LoggerFactory.getLogger(AbstractHandler.class);
29
30     /**
31      * Convert failure status returned by the  manager into
32      * neutron API service errors.
33      *
34      * @param status  manager status
35      * @return  An error to be returned to neutron API service.
36      */
37     protected static final int getException(Status status) {
38         int result = HttpURLConnection.HTTP_INTERNAL_ERROR;
39
40         assert !status.isSuccess();
41
42         StatusCode code = status.getCode();
43         logger.debug(" Exception code - {}, description - {}",
44                 code, status.getDescription());
45
46         if (code == StatusCode.BADREQUEST) {
47             result = HttpURLConnection.HTTP_BAD_REQUEST;
48         } else if (code == StatusCode.CONFLICT) {
49             result = HttpURLConnection.HTTP_CONFLICT;
50         } else if (code == StatusCode.NOTACCEPTABLE) {
51             result = HttpURLConnection.HTTP_NOT_ACCEPTABLE;
52         } else if (code == StatusCode.NOTFOUND) {
53             result = HttpURLConnection.HTTP_NOT_FOUND;
54         } else {
55             result = HttpURLConnection.HTTP_INTERNAL_ERROR;
56         }
57
58         return result;
59     }
60 }