2 * Copyright (C) 2013 Red Hat, Inc.
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
8 * Authors : Madhu Venugopal, Brent Salisbury
10 package org.opendaylight.ovsdb.openstack.netvirt;
12 import org.opendaylight.controller.sal.utils.Status;
13 import org.opendaylight.controller.sal.utils.StatusCode;
15 import org.slf4j.Logger;
16 import org.slf4j.LoggerFactory;
18 import java.net.HttpURLConnection;
21 * Abstract class for utility functions used by neutron handlers.
23 public abstract class AbstractHandler {
28 static final Logger logger = LoggerFactory.getLogger(AbstractHandler.class);
31 * Convert failure status returned by the manager into
32 * neutron API service errors.
34 * @param status manager status
35 * @return An error to be returned to neutron API service.
37 protected static final int getException(Status status) {
38 int result = HttpURLConnection.HTTP_INTERNAL_ERROR;
40 assert !status.isSuccess();
42 StatusCode code = status.getCode();
43 logger.debug(" Exception code - {}, description - {}",
44 code, status.getDescription());
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;
55 result = HttpURLConnection.HTTP_INTERNAL_ERROR;