2 * Copyright (c) 2015 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
8 package org.opendaylight.netconf.topology.pipeline;
10 import akka.actor.ActorRef;
11 import akka.actor.ActorSystem;
12 import akka.actor.PoisonPill;
13 import akka.actor.TypedActor;
14 import akka.cluster.Cluster;
15 import akka.cluster.Member;
17 import org.opendaylight.controller.cluster.schema.provider.impl.RemoteYangTextSourceProviderImpl;
18 import org.opendaylight.netconf.topology.pipeline.messages.AnnounceClusteredDeviceSourcesResolverUp;
19 import org.opendaylight.netconf.topology.pipeline.messages.AnnounceMasterOnSameNodeUp;
20 import org.opendaylight.netconf.topology.pipeline.messages.AnnounceMasterSourceProviderUp;
21 import org.opendaylight.netconf.util.NetconfTopologyPathCreator;
22 import org.opendaylight.yangtools.yang.model.repo.api.SchemaRepository;
23 import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
27 public class MasterSourceProviderImpl extends RemoteYangTextSourceProviderImpl
28 implements MasterSourceProvider {
30 private static Logger LOG = LoggerFactory.getLogger(MasterSourceProviderImpl.class);
32 private final ActorSystem actorSystem;
33 private final String topologyId;
34 private final String nodeId;
36 public MasterSourceProviderImpl(SchemaRepository schemaRepo, Set<SourceIdentifier> providedSources, ActorSystem actorSystem, String topologyId, String nodeId) {
37 super(schemaRepo, providedSources);
38 this.actorSystem = actorSystem;
39 this.topologyId = topologyId;
44 public void onReceive(Object o, ActorRef actorRef) {
45 if(o instanceof AnnounceClusteredDeviceSourcesResolverUp) {
46 LOG.debug("Received source resolver up");
47 actorRef.tell(new AnnounceMasterSourceProviderUp(), TypedActor.context().self());
52 public void preStart() {
53 Cluster cluster = Cluster.get(actorSystem);
54 cluster.join(cluster.selfAddress());
55 LOG.debug("Notifying members master schema source provider is up.");
56 for(Member node : cluster.state().getMembers()) {
57 final NetconfTopologyPathCreator pathCreator = new NetconfTopologyPathCreator(node.address().toString(),topologyId);
58 final String path = pathCreator.withSuffix(nodeId).withSuffix(NetconfTopologyPathCreator.CLUSTERED_DEVICE_SOURCES_RESOLVER).build();
59 if(node.address().equals(cluster.selfAddress())) {
60 actorSystem.actorSelection(path).tell(new AnnounceMasterOnSameNodeUp(), TypedActor.context().self());
61 actorSystem.actorSelection(path).tell(PoisonPill.getInstance(), TypedActor.context().self());
63 //TODO extract string constant to util class
64 actorSystem.actorSelection(path).tell(new AnnounceMasterSourceProviderUp(), TypedActor.context().self());