Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 1 | /** |
| 2 | * Copyright 2011, Big Switch Networks, Inc. |
| 3 | * Originally created by David Erickson, Stanford University |
| 4 | * |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 6 | * not use this file except in compliance with the License. You may obtain |
| 7 | * a copy of the License at |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 14 | * License for the specific language governing permissions and limitations |
| 15 | * under the License. |
| 16 | **/ |
| 17 | |
| 18 | package net.floodlightcontroller.storage.web; |
| 19 | |
| 20 | import java.util.HashMap; |
| 21 | import java.util.List; |
| 22 | import java.util.Map; |
| 23 | |
| 24 | import net.floodlightcontroller.storage.IStorageSourceService; |
| 25 | import net.floodlightcontroller.storage.StorageSourceNotification; |
| 26 | |
| 27 | import org.codehaus.jackson.map.ObjectMapper; |
| 28 | import org.codehaus.jackson.type.TypeReference; |
| 29 | import org.restlet.resource.Post; |
| 30 | import org.restlet.resource.ServerResource; |
| 31 | import org.slf4j.Logger; |
| 32 | import org.slf4j.LoggerFactory; |
| 33 | |
| 34 | public class StorageNotifyResource extends ServerResource { |
Yuta HIGUCHI | 6ac8d18 | 2013-10-22 15:24:56 -0700 | [diff] [blame] | 35 | protected final static Logger log = LoggerFactory.getLogger(StorageNotifyResource.class); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 36 | |
| 37 | @Post("json") |
| 38 | public Map<String,Object> notify(String entity) throws Exception { |
| 39 | List<StorageSourceNotification> notifications = null; |
| 40 | ObjectMapper mapper = new ObjectMapper(); |
| 41 | notifications = |
| 42 | mapper.readValue(entity, |
| 43 | new TypeReference<List<StorageSourceNotification>>(){}); |
| 44 | |
| 45 | IStorageSourceService storageSource = |
| 46 | (IStorageSourceService)getContext().getAttributes(). |
| 47 | get(IStorageSourceService.class.getCanonicalName()); |
| 48 | storageSource.notifyListeners(notifications); |
| 49 | |
| 50 | HashMap<String, Object> model = new HashMap<String,Object>(); |
| 51 | model.put("output", "OK"); |
| 52 | return model; |
| 53 | } |
| 54 | |
| 55 | } |