Replace tenantVlanMap with a per Node cache
[ovsdb.git] / neutron / src / main / java / org / opendaylight / ovsdb / neutron / NetworkHandler.java
1 /*
2  * Copyright (C) 2013 Red Hat, Inc.
3  *
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
7  *
8  * Authors : Madhu Venugopal, Brent Salisbury
9  */
10 package org.opendaylight.ovsdb.neutron;
11
12 import java.net.HttpURLConnection;
13
14 import org.opendaylight.controller.networkconfig.neutron.INeutronNetworkAware;
15 import org.opendaylight.controller.networkconfig.neutron.NeutronNetwork;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
18
19 /**
20  * Handle requests for Neutron Network.
21  */
22 public class NetworkHandler extends BaseHandler
23                             implements INeutronNetworkAware {
24     /**
25      * Logger instance.
26      */
27     static final Logger logger = LoggerFactory.getLogger(NetworkHandler.class);
28
29     /**
30      * Invoked when a network creation is requested
31      * to indicate if the specified network can be created.
32      *
33      * @param network  An instance of proposed new Neutron Network object.
34      * @return A HTTP status code to the creation request.
35      */
36     @Override
37     public int canCreateNetwork(NeutronNetwork network) {
38         if (network.isShared()) {
39             logger.error(" Network shared attribute not supported ");
40             return HttpURLConnection.HTTP_NOT_ACCEPTABLE;
41         }
42
43         return HttpURLConnection.HTTP_CREATED;
44     }
45
46     /**
47      * Invoked to take action after a network has been created.
48      *
49      * @param network  An instance of new Neutron Network object.
50      */
51     @Override
52     public void neutronNetworkCreated(NeutronNetwork network) {
53         int result = HttpURLConnection.HTTP_BAD_REQUEST;
54
55         result = canCreateNetwork(network);
56         if (result != HttpURLConnection.HTTP_CREATED) {
57             logger.debug("Network creation failed {} ", result);
58             return;
59         }
60
61        TenantNetworkManager.getManager().networkCreated(network.getID());
62     }
63
64     /**
65      * Invoked when a network update is requested
66      * to indicate if the specified network can be changed
67      * using the specified delta.
68      *
69      * @param delta     Updates to the network object using patch semantics.
70      * @param original  An instance of the Neutron Network object
71      *                  to be updated.
72      * @return A HTTP status code to the update request.
73      */
74     @Override
75     public int canUpdateNetwork(NeutronNetwork delta,
76                                 NeutronNetwork original) {
77         return HttpURLConnection.HTTP_OK;
78     }
79
80     /**
81      * Invoked to take action after a network has been updated.
82      *
83      * @param network An instance of modified Neutron Network object.
84      */
85     @Override
86     public void neutronNetworkUpdated(NeutronNetwork network) {
87         return;
88     }
89
90     /**
91      * Invoked when a network deletion is requested
92      * to indicate if the specified network can be deleted.
93      *
94      * @param network  An instance of the Neutron Network object to be deleted.
95      * @return A HTTP status code to the deletion request.
96      */
97     @Override
98     public int canDeleteNetwork(NeutronNetwork network) {
99         return HttpURLConnection.HTTP_OK;
100     }
101
102     /**
103      * Invoked to take action after a network has been deleted.
104      *
105      * @param network  An instance of deleted Neutron Network object.
106      */
107     @Override
108     public void neutronNetworkDeleted(NeutronNetwork network) {
109
110         int result = canDeleteNetwork(network);
111         if  (result != HttpURLConnection.HTTP_OK) {
112             logger.error(" deleteNetwork validation failed for result - {} ",
113                     result);
114             return;
115         }
116         TenantNetworkManager.getManager().networkDeleted(network.getID());
117     }
118 }