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.yangtools.yang.model.repo.api.SchemaRepository;
22 import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
26 public class MasterSourceProviderImpl extends RemoteYangTextSourceProviderImpl
27 implements MasterSourceProvider {
29 private static Logger LOG = LoggerFactory.getLogger(MasterSourceProviderImpl.class);
31 private final ActorSystem actorSystem;
32 private final String topologyId;
33 private final String nodeId;
35 public MasterSourceProviderImpl(SchemaRepository schemaRepo, Set<SourceIdentifier> providedSources, ActorSystem actorSystem, String topologyId, String nodeId) {
36 super(schemaRepo, providedSources);
37 this.actorSystem = actorSystem;
38 this.topologyId = topologyId;
43 public void onReceive(Object o, ActorRef actorRef) {
44 if(o instanceof AnnounceClusteredDeviceSourcesResolverUp) {
45 LOG.debug("Received source resolver up");
46 actorRef.tell(new AnnounceMasterSourceProviderUp(), TypedActor.context().self());
51 public void preStart() {
52 Cluster cluster = Cluster.get(actorSystem);
53 cluster.join(cluster.selfAddress());
54 LOG.debug("Notifying members master schema source provider is up.");
55 for(Member node : cluster.state().getMembers()) {
56 final String path = node.address() + "/user/" + topologyId + "/" + nodeId + "/clusteredDeviceSourcesResolver";
57 if(node.address().equals(cluster.selfAddress())) {
58 actorSystem.actorSelection(path).tell(new AnnounceMasterOnSameNodeUp(), TypedActor.context().self());
59 actorSystem.actorSelection(path).tell(PoisonPill.getInstance(), TypedActor.context().self());
61 //TODO extract string constant to util class
62 actorSystem.actorSelection(path).tell(new AnnounceMasterSourceProviderUp(), TypedActor.context().self());