2 * Copyright (c) 2018 Red Hat, Inc. and others. All rights reserved.
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 package org.opendaylight.neutron.northbound.impl;
10 import com.google.common.base.Optional;
11 import javax.inject.Inject;
12 import javax.inject.Singleton;
13 import javax.ws.rs.core.MultivaluedHashMap;
15 import org.opendaylight.netconf.sal.restconf.api.JSONRestconfService;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.northbound.api.config.rev181024.NeutronNorthboundApiConfig;
17 import org.opendaylight.yangtools.yang.common.OperationFailedException;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
22 public class PortStatusUpdateInitializer {
23 private static final Logger LOG = LoggerFactory.getLogger(PortStatusUpdateInitializer.class);
25 private static final String SUBSCRIBE_JSON = "{\n"
27 + " \"path\": \"/neutron:neutron/neutron:ports\", \n"
28 + " \"sal-remote-augment:notification-output-type\": \"JSON\", \n"
29 + " \"sal-remote-augment:datastore\": \"OPERATIONAL\", \n"
30 + " \"sal-remote-augment:scope\": \"SUBTREE\"\n"
34 private final NeutronNorthboundApiConfig cfg;
35 private final JSONRestconfService jsonRestconfService;
38 public PortStatusUpdateInitializer(JSONRestconfService jsonRestconfService,
39 final NeutronNorthboundApiConfig neutronNorthboundApiConfig) {
40 this.cfg = neutronNorthboundApiConfig;
41 this.jsonRestconfService = jsonRestconfService;
43 boolean preRegister = cfg.isPreRegisterPortStatusWebsocket() == null || cfg.isPreRegisterPortStatusWebsocket();
48 LOG.info("PortStatusUpdateInitializer: Skipping pre-register of websockets");
52 private void subscribeWebsocket() {
53 dataChangeEventSubscription();
57 private void dataChangeEventSubscription() {
59 Optional<String> res = jsonRestconfService.invokeRpc(
60 "sal-remote:create-data-change-event-subscription", Optional.of(SUBSCRIBE_JSON));
61 LOG.info("create-data-change-event-subscription returned {}", res);
62 } catch (OperationFailedException e) {
63 LOG.error("exception while calling create-data-change-event-subscription", e);
67 private void streamSubscribe() {
68 String identifier = "data-change-event-subscription/neutron:neutron/neutron:ports"
69 + "/datastore=OPERATIONAL/scope=SUBTREE";
70 MultivaluedHashMap map = new MultivaluedHashMap<String, String>();
71 map.add("odl-leaf-nodes-only", "true");
72 Optional<String> res = null;
74 res = jsonRestconfService.subscribeToStream(identifier, map);
75 LOG.info("subscribeToStream returned {}", res);
76 } catch (OperationFailedException e) {
77 LOG.error("exception while calling subscribeToStream", e);