BUG-6650: ep-ip/sgt, rename groupbasedpolicy-ise-adapter to sxp-ise-adapter
[groupbasedpolicy.git] / sxp-integration / sxp-ise-adapter / src / main / java / org / opendaylight / groupbasedpolicy / sxp_ise_adapter / impl / GbpIseAdapterProvider.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
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
9 package org.opendaylight.groupbasedpolicy.sxp_ise_adapter.impl;
10
11 import org.opendaylight.controller.md.sal.binding.api.ClusteredDataTreeChangeListener;
12 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
13 import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
14 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
15 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
16 import org.opendaylight.controller.sal.binding.api.BindingAwareProvider;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.groupbasedpolicy.gbp.sxp.ise.adapter.model.rev160630.GbpSxpIseAdapter;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.groupbasedpolicy.gbp.sxp.ise.adapter.model.rev160630.gbp.sxp.ise.adapter.IseSourceConfig;
19 import org.opendaylight.yangtools.concepts.ListenerRegistration;
20 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
23
24 import com.google.common.base.Preconditions;
25
26 /**
27  * Purpose: main provider of gbp-ise adapter (for reading sgts and generating EndpointPolicyTemplates)
28  */
29 public class GbpIseAdapterProvider implements AutoCloseable, BindingAwareProvider {
30
31     private static final Logger LOG = LoggerFactory.getLogger(GbpIseAdapterProvider.class);
32
33     private final DataBroker dataBroker;
34     private ListenerRegistration<ClusteredDataTreeChangeListener<IseSourceConfig>> registration;
35
36     public GbpIseAdapterProvider(final DataBroker dataBroker, final BindingAwareBroker brokerDependency) {
37         this.dataBroker = Preconditions.checkNotNull(dataBroker, "provided dataBroker must not be null");
38         brokerDependency.registerProvider(this);
39     }
40
41     @Override
42     public void close() {
43         if (registration != null) {
44             LOG.info("closing GbpIseAdapterProvider");
45             registration.close();
46             registration = null;
47         }
48     }
49
50     @Override
51     public void onSessionInitiated(final BindingAwareBroker.ProviderContext providerContext) {
52         LOG.info("Starting GbpIseAdapterProvider ..");
53
54         // setup harvesting and processing pipeline
55         final SgtInfoProcessor epgGenerator = new SgtToEpgGeneratorImpl(dataBroker);
56         final SgtInfoProcessor templateGenerator = new SgtToEPTemplateGeneratorImpl(dataBroker);
57         final GbpIseSgtHarvester gbpIseSgtHarvester = new GbpIseSgtHarvesterImpl(epgGenerator, templateGenerator);
58         final GbpIseConfigListenerImpl gbpIseConfigListener = new GbpIseConfigListenerImpl(dataBroker, gbpIseSgtHarvester);
59
60         // build data-tree path
61         final DataTreeIdentifier<IseSourceConfig> dataTreePath = new DataTreeIdentifier<>(
62                 LogicalDatastoreType.CONFIGURATION,
63                 InstanceIdentifier.create(GbpSxpIseAdapter.class).child(IseSourceConfig.class));
64
65         // register config listener
66         registration = dataBroker.registerDataTreeChangeListener(dataTreePath,
67                 gbpIseConfigListener);
68
69         LOG.info("Started");
70     }
71 }