Merge changes from topic 'BUG-3774'
[openflowplugin.git] / applications / forwardingrules-manager / src / main / java / org / opendaylight / openflowplugin / applications / config / yang / forwardingrules_manager / ForwardingRulesManagerModule.java
1 /**
2  * Copyright (c) 2015 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.openflowplugin.applications.config.yang.forwardingrules_manager;
10
11 import org.opendaylight.openflowplugin.applications.frm.impl.ForwardingRulesManagerConfig;
12 import org.opendaylight.openflowplugin.applications.frm.impl.ForwardingRulesManagerImpl;
13 import org.slf4j.Logger;
14 import org.slf4j.LoggerFactory;
15
16 public class ForwardingRulesManagerModule extends org.opendaylight.openflowplugin.applications.config.yang.forwardingrules_manager.AbstractForwardingRulesManagerModule {
17
18     private static final Logger LOG = LoggerFactory.getLogger(ForwardingRulesManagerModule.class);
19     private static final boolean ENABLE_FGM_STALE_MARKING = false;
20
21     public ForwardingRulesManagerModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
22         super(identifier, dependencyResolver);
23     }
24
25     public ForwardingRulesManagerModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, org.opendaylight.openflowplugin.applications.config.yang.forwardingrules_manager.ForwardingRulesManagerModule oldModule, java.lang.AutoCloseable oldInstance) {
26         super(identifier, dependencyResolver, oldModule, oldInstance);
27     }
28
29     @Override
30     public void customValidation() {
31         // add custom validation form module attributes here.
32     }
33
34     @Override
35     public java.lang.AutoCloseable createInstance() {
36         LOG.info("FRM module initialization.");
37         final ForwardingRulesManagerConfig config = readConfig();
38         final ForwardingRulesManagerImpl forwardingrulessManagerProvider =
39                 new ForwardingRulesManagerImpl(getDataBrokerDependency(), getRpcRegistryDependency(), config);
40         forwardingrulessManagerProvider.start();
41         LOG.info("FRM module started successfully.");
42         return new AutoCloseable() {
43             @Override
44             public void close() throws Exception {
45                 try {
46                     forwardingrulessManagerProvider.close();
47                 } catch (final Exception e) {
48                     LOG.warn("Unexpected error by stopping FRM", e);
49                 }
50                 LOG.info("FRM module stopped.");
51             }
52         };
53     }
54
55     private ForwardingRulesManagerConfig readConfig(){
56
57         final ForwardingRulesManagerConfig.ForwardingRulesManagerConfigBuilder fwdRulesMgrCfgBuilder = ForwardingRulesManagerConfig.builder();
58         if (getForwardingManagerSettings() != null && getForwardingManagerSettings().getStaleMarkingEnabled() != null){
59             fwdRulesMgrCfgBuilder.setStaleMarkingEnabled(getForwardingManagerSettings().getStaleMarkingEnabled());
60         }
61         else{
62             LOG.warn("Could not load XML configuration file via ConfigSubsystem! Fallback to default config value(s)");
63             fwdRulesMgrCfgBuilder.setStaleMarkingEnabled(ENABLE_FGM_STALE_MARKING);
64         }
65
66         return fwdRulesMgrCfgBuilder.build();
67
68     }
69
70 }