/* * Copyright (C) 2013 Red Hat, Inc. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html * * Authors : Madhu Venugopal, Brent Salisbury */ package org.opendaylight.ovsdb.openstack.netvirt; import org.opendaylight.controller.sal.utils.Status; import org.opendaylight.controller.sal.utils.StatusCode; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.net.HttpURLConnection; /** * Abstract class for utility functions used by neutron handlers. */ public abstract class AbstractHandler { /** * Logger instance. */ static final Logger logger = LoggerFactory.getLogger(AbstractHandler.class); /** * Convert failure status returned by the manager into * neutron API service errors. * * @param status manager status * @return An error to be returned to neutron API service. */ protected static final int getException(Status status) { int result = HttpURLConnection.HTTP_INTERNAL_ERROR; assert !status.isSuccess(); StatusCode code = status.getCode(); logger.debug(" Exception code - {}, description - {}", code, status.getDescription()); if (code == StatusCode.BADREQUEST) { result = HttpURLConnection.HTTP_BAD_REQUEST; } else if (code == StatusCode.CONFLICT) { result = HttpURLConnection.HTTP_CONFLICT; } else if (code == StatusCode.NOTACCEPTABLE) { result = HttpURLConnection.HTTP_NOT_ACCEPTABLE; } else if (code == StatusCode.NOTFOUND) { result = HttpURLConnection.HTTP_NOT_FOUND; } else { result = HttpURLConnection.HTTP_INTERNAL_ERROR; } return result; } }