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.ovsdb.openstack.netvirt.api.EventDispatcher;
13 import org.opendaylight.ovsdb.openstack.netvirt.api.Status;
14 import org.opendaylight.ovsdb.openstack.netvirt.api.StatusCode;
16 import com.google.common.base.Preconditions;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
20 import java.net.HttpURLConnection;
23 * OpenStack related events originate from multiple north callbacks as well as south.
24 * This interface provides a layer of abstraction between the event dispatcher and the
27 public abstract class AbstractHandler {
28 private static final Logger LOG = LoggerFactory.getLogger(AbstractHandler.class);
30 // The implementation for each of these services is resolved by the OSGi Service Manager
31 protected volatile EventDispatcher eventDispatcher;
34 * Convert failure status returned by the manager into
35 * neutron API service errors.
37 * @param status manager status
38 * @return An error to be returned to neutron API service.
40 protected static final int getException(Status status) {
41 int result = HttpURLConnection.HTTP_INTERNAL_ERROR;
43 assert !status.isSuccess();
45 StatusCode code = status.getCode();
46 LOG.debug(" Exception code - {}, description - {}",
47 code, status.getDescription());
49 if (code == StatusCode.BADREQUEST) {
50 result = HttpURLConnection.HTTP_BAD_REQUEST;
51 } else if (code == StatusCode.CONFLICT) {
52 result = HttpURLConnection.HTTP_CONFLICT;
53 } else if (code == StatusCode.NOTACCEPTABLE) {
54 result = HttpURLConnection.HTTP_NOT_ACCEPTABLE;
55 } else if (code == StatusCode.NOTFOUND) {
56 result = HttpURLConnection.HTTP_NOT_FOUND;
58 result = HttpURLConnection.HTTP_INTERNAL_ERROR;
67 * @param abstractEvent the {@link org.opendaylight.ovsdb.openstack.netvirt.AbstractEvent} event to be handled.
68 * @see org.opendaylight.ovsdb.openstack.netvirt.api.EventDispatcher
70 protected void enqueueEvent(AbstractEvent abstractEvent) {
71 LOG.info("enqueueEvent: evenDispatcher: {} - {}", eventDispatcher, abstractEvent);
72 Preconditions.checkNotNull(eventDispatcher);
73 eventDispatcher.enqueueEvent(abstractEvent);
79 * @param abstractEvent the {@link org.opendaylight.ovsdb.openstack.netvirt.AbstractEvent} event to be handled.
80 * @see org.opendaylight.ovsdb.openstack.netvirt.api.EventDispatcher
82 public abstract void processEvent(AbstractEvent abstractEvent);