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 {
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 logger.info(">>>>> init {}", this.getClass());
42 * Convert failure status returned by the manager into
43 * neutron API service errors.
45 * @param status manager status
46 * @return An error to be returned to neutron API service.
48 protected static final int getException(Status status) {
49 int result = HttpURLConnection.HTTP_INTERNAL_ERROR;
51 assert !status.isSuccess();
53 StatusCode code = status.getCode();
54 logger.debug(" Exception code - {}, description - {}",
55 code, status.getDescription());
57 if (code == StatusCode.BADREQUEST) {
58 result = HttpURLConnection.HTTP_BAD_REQUEST;
59 } else if (code == StatusCode.CONFLICT) {
60 result = HttpURLConnection.HTTP_CONFLICT;
61 } else if (code == StatusCode.NOTACCEPTABLE) {
62 result = HttpURLConnection.HTTP_NOT_ACCEPTABLE;
63 } else if (code == StatusCode.NOTFOUND) {
64 result = HttpURLConnection.HTTP_NOT_FOUND;
66 result = HttpURLConnection.HTTP_INTERNAL_ERROR;
75 * @param abstractEvent the {@link org.opendaylight.ovsdb.openstack.netvirt.AbstractEvent} event to be handled.
76 * @see org.opendaylight.ovsdb.openstack.netvirt.api.EventDispatcher
78 protected void enqueueEvent(AbstractEvent abstractEvent) {
79 Preconditions.checkNotNull(eventDispatcher);
80 eventDispatcher.enqueueEvent(abstractEvent);
86 * @param abstractEvent the {@link org.opendaylight.ovsdb.openstack.netvirt.AbstractEvent} event to be handled.
87 * @see org.opendaylight.ovsdb.openstack.netvirt.api.EventDispatcher
89 public abstract void processEvent(AbstractEvent abstractEvent);