2 * Copyright (c) 2013 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
11 * Generated from: yang module name: config-pcep-topology-provider yang module local name: pcep-topology-impl
12 * Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
13 * Generated at: Mon Nov 18 21:08:29 CET 2013
15 * Do not modify this file unless it is present under src/main directory
17 package org.opendaylight.controller.config.yang.pcep.topology.provider;
19 import com.google.common.base.Charsets;
20 import com.google.common.net.InetAddresses;
22 import java.net.InetAddress;
23 import java.net.InetSocketAddress;
24 import java.util.concurrent.ExecutionException;
26 import org.opendaylight.bgpcep.pcep.topology.provider.PCEPTopologyProvider;
27 import org.opendaylight.controller.config.api.JmxAttributeValidationException;
28 import org.opendaylight.controller.config.yang.pcep.impl.PCEPDispatcherImplModuleMXBean;
29 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
30 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
31 import org.opendaylight.tcpmd5.api.KeyMapping;
32 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
33 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
34 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
35 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
36 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
37 import org.slf4j.Logger;
38 import org.slf4j.LoggerFactory;
43 public final class PCEPTopologyProviderModule extends
44 org.opendaylight.controller.config.yang.pcep.topology.provider.AbstractPCEPTopologyProviderModule {
45 private static final Logger LOG = LoggerFactory.getLogger(PCEPTopologyProviderModule.class);
47 private static final String IS_NOT_SET = "is not set.";
49 public PCEPTopologyProviderModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier,
50 final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
51 super(identifier, dependencyResolver);
54 public PCEPTopologyProviderModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier,
55 final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, final PCEPTopologyProviderModule oldModule,
56 final java.lang.AutoCloseable oldInstance) {
57 super(identifier, dependencyResolver, oldModule, oldInstance);
60 private KeyMapping contructKeys() {
61 final KeyMapping ret = new KeyMapping();
62 if (getClient() != null) {
63 for (Client c : getClient()) {
64 if (c.getAddress() == null) {
65 LOG.warn("Client {} does not have an address skipping it", c);
68 if (c.getPassword() != null) {
69 final String s = getAddressString(c.getAddress());
70 ret.put(InetAddresses.forString(s), c.getPassword().getValue().getBytes(Charsets.US_ASCII));
78 private String getAddressString(final IpAddress address) {
79 if (address.getIpv4Address() != null) {
80 return address.getIpv4Address().getValue();
82 if (address.getIpv6Address() != null) {
83 return address.getIpv6Address().getValue();
86 throw new IllegalArgumentException(String.format("Address %s is invalid", address));
91 public void customValidation() {
92 JmxAttributeValidationException.checkNotNull(getTopologyId(), IS_NOT_SET, topologyIdJmxAttribute);
93 JmxAttributeValidationException.checkNotNull(getListenAddress(), IS_NOT_SET, listenAddressJmxAttribute);
94 JmxAttributeValidationException.checkNotNull(getListenPort(), IS_NOT_SET, listenPortJmxAttribute);
95 JmxAttributeValidationException.checkNotNull(getStatefulPlugin(), IS_NOT_SET, statefulPluginJmxAttribute);
97 final KeyMapping keys = contructKeys();
98 if (!keys.isEmpty()) {
100 * This is a nasty hack, but we don't have another clean solution. We cannot allow
101 * password being set if the injected dispatcher does not have the optional
102 * md5-server-channel-factory set.
104 * FIXME: this is a use case for Module interfaces, e.g. PCEPDispatcherImplModule
105 * should something like isMd5ServerSupported()
108 PCEPDispatcherImplModuleMXBean dispatcherProxy = dependencyResolver.newMXBeanProxy(getDispatcher(),
109 PCEPDispatcherImplModuleMXBean.class);
110 boolean md5ServerSupported = dispatcherProxy.getMd5ServerChannelFactory() != null;
111 JmxAttributeValidationException.checkCondition(md5ServerSupported,
112 "password is not compatible with selected dispatcher", clientJmxAttribute);
117 private InetAddress listenAddress() {
118 final IpAddress a = getListenAddress();
119 if (a.getIpv4Address() != null) {
120 return InetAddresses.forString(a.getIpv4Address().getValue());
121 } else if (a.getIpv6Address() != null) {
122 return InetAddresses.forString(a.getIpv6Address().getValue());
124 throw new IllegalArgumentException("Address " + a + " not supported");
129 public java.lang.AutoCloseable createInstance() {
130 final InstanceIdentifier<Topology> topology = InstanceIdentifier.builder(NetworkTopology.class).child(Topology.class,
131 new TopologyKey(getTopologyId())).toInstance();
132 final InetSocketAddress address = new InetSocketAddress(listenAddress(), getListenPort().getValue());
133 final KeyMapping keys = contructKeys();
136 return PCEPTopologyProvider.create(getDispatcherDependency(), address, keys.isEmpty() ? null : keys, getSchedulerDependency(),
137 getDataProviderDependency(), getRpcRegistryDependency(), topology, getStatefulPluginDependency());
138 } catch (InterruptedException | ExecutionException | TransactionCommitFailedException | ReadFailedException e) {
139 LOG.error("Failed to instantiate topology provider at {}", address, e);
140 throw new IllegalStateException("Failed to instantiate provider", e);