blob: 081c7f94de764e474dc038be135599dd1b3847fa [file] [log] [blame]
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -08001/**
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
18package net.floodlightcontroller.storage.web;
19
20import java.util.HashMap;
21import java.util.List;
22import java.util.Map;
23
24import net.floodlightcontroller.storage.IStorageSourceService;
25import net.floodlightcontroller.storage.StorageSourceNotification;
26
27import org.codehaus.jackson.map.ObjectMapper;
28import org.codehaus.jackson.type.TypeReference;
29import org.restlet.resource.Post;
30import org.restlet.resource.ServerResource;
31import org.slf4j.Logger;
32import org.slf4j.LoggerFactory;
33
34public class StorageNotifyResource extends ServerResource {
Yuta HIGUCHI6ac8d182013-10-22 15:24:56 -070035 protected final static Logger log = LoggerFactory.getLogger(StorageNotifyResource.class);
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080036
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}