2 * Copyright (c) 2016 Cisco Systems, 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
9 package org.opendaylight.groupbasedpolicy.gbp_ise_adapter.impl;
11 import com.google.common.base.Preconditions;
12 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
13 import org.opendaylight.controller.md.sal.binding.api.DataTreeChangeListener;
14 import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
15 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
16 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
17 import org.opendaylight.controller.sal.binding.api.BindingAwareProvider;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.groupbasedpolicy.gbp.ise.adapter.model.rev160630.GbpIseAdapter;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.groupbasedpolicy.gbp.ise.adapter.model.rev160630.gbp.ise.adapter.IseHarvestConfig;
20 import org.opendaylight.yangtools.concepts.ListenerRegistration;
21 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
26 * Purpose: main provider of gbp-ise adapter (for reading sgts and generating EndpointPolicyTemplates)
28 public class GbpIseAdapterProvider implements AutoCloseable, BindingAwareProvider {
30 private static final Logger LOG = LoggerFactory.getLogger(GbpIseAdapterProvider.class);
32 private final DataBroker dataBroker;
33 private ListenerRegistration<DataTreeChangeListener<IseHarvestConfig>> registration;
35 public GbpIseAdapterProvider(final DataBroker dataBroker, final BindingAwareBroker brokerDependency) {
36 this.dataBroker = Preconditions.checkNotNull(dataBroker, "provided dataBroker must not be null");
37 brokerDependency.registerProvider(this);
41 public void close() throws Exception {
42 if (registration != null) {
43 LOG.info("closing GbpIseAdapterProvider");
50 public void onSessionInitiated(final BindingAwareBroker.ProviderContext providerContext) {
51 LOG.info("Starting GbpIseAdapterProvider ..");
53 // setup harvesting and processing pipeline
54 final SgtInfoProcessor epgGenerator = new SgtToEpgGeneratorImpl(dataBroker);
55 final SgtInfoProcessor templateGenerator = new SgtToEPTemplateGeneratorImpl(dataBroker);
56 final GbpIseSgtHarvester gbpIseSgtHarvester = new GbpIseSgtHarvesterImpl(epgGenerator, templateGenerator);
57 final GbpIseConfigListenerImpl gbpIseConfigListener = new GbpIseConfigListenerImpl(dataBroker, gbpIseSgtHarvester);
59 // build data-tree path
60 final DataTreeIdentifier<IseHarvestConfig> dataTreePath = new DataTreeIdentifier<>(
61 LogicalDatastoreType.CONFIGURATION,
62 InstanceIdentifier.create(GbpIseAdapter.class).child(IseHarvestConfig.class));
64 // register config listener
65 registration = dataBroker.registerDataTreeChangeListener(dataTreePath,
66 gbpIseConfigListener);