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;
14 import org.opendaylight.ovsdb.openstack.netvirt.api.EventDispatcher;
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 {
32 static final Logger logger = LoggerFactory.getLogger(AbstractHandler.class);
34 // The implementation for each of these services is resolved by the OSGi Service Manager
35 private volatile EventDispatcher eventDispatcher;
38 * Convert failure status returned by the manager into
39 * neutron API service errors.
41 * @param status manager status
42 * @return An error to be returned to neutron API service.
44 protected static final int getException(Status status) {
45 int result = HttpURLConnection.HTTP_INTERNAL_ERROR;
47 assert !status.isSuccess();
49 StatusCode code = status.getCode();
50 logger.debug(" Exception code - {}, description - {}",
51 code, status.getDescription());
53 if (code == StatusCode.BADREQUEST) {
54 result = HttpURLConnection.HTTP_BAD_REQUEST;
55 } else if (code == StatusCode.CONFLICT) {
56 result = HttpURLConnection.HTTP_CONFLICT;
57 } else if (code == StatusCode.NOTACCEPTABLE) {
58 result = HttpURLConnection.HTTP_NOT_ACCEPTABLE;
59 } else if (code == StatusCode.NOTFOUND) {
60 result = HttpURLConnection.HTTP_NOT_FOUND;
62 result = HttpURLConnection.HTTP_INTERNAL_ERROR;
71 * @param event the {@link org.opendaylight.ovsdb.openstack.netvirt.AbstractEvent} event to be handled.
72 * @see org.opendaylight.ovsdb.openstack.netvirt.api.EventDispatcher
74 protected void enqueueEvent(AbstractEvent abstractEvent) {
75 Preconditions.checkNotNull(eventDispatcher);
76 eventDispatcher.enqueueEvent(abstractEvent);
82 * @param event the {@link org.opendaylight.ovsdb.openstack.netvirt.AbstractEvent} event to be handled.
83 * @see org.opendaylight.ovsdb.openstack.netvirt.api.EventDispatcher
85 public abstract void processEvent(AbstractEvent abstractEvent);