Search in sources :

Example 1 with InvokeActionMessage

use of org.opendaylight.netconf.topology.singleton.messages.action.InvokeActionMessage in project netconf by opendaylight.

the class NetconfNodeActor method handleReceive.

@SuppressWarnings("checkstyle:IllegalCatch")
@Override
public void handleReceive(final Object message) {
    LOG.debug("{}:  received message {}", id, message);
    if (message instanceof CreateInitialMasterActorData) {
        // master
        final CreateInitialMasterActorData masterActorData = (CreateInitialMasterActorData) message;
        sourceIdentifiers = masterActorData.getSourceIndentifiers();
        this.deviceDataBroker = masterActorData.getDeviceDataBroker();
        this.netconfService = masterActorData.getNetconfDataTreeService();
        final DOMDataTreeReadTransaction tx = deviceDataBroker.newReadOnlyTransaction();
        readTxActor = context().actorOf(ReadTransactionActor.props(tx));
        this.deviceRpc = masterActorData.getDeviceRpc();
        this.deviceAction = masterActorData.getDeviceAction();
        sender().tell(new MasterActorDataInitialized(), self());
        LOG.debug("{}: Master is ready.", id);
    } else if (message instanceof RefreshSetupMasterActorData) {
        setup = ((RefreshSetupMasterActorData) message).getNetconfTopologyDeviceSetup();
        id = ((RefreshSetupMasterActorData) message).getRemoteDeviceId();
        sender().tell(new MasterActorDataInitialized(), self());
    } else if (message instanceof AskForMasterMountPoint) {
        // master
        AskForMasterMountPoint askForMasterMountPoint = (AskForMasterMountPoint) message;
        // only master contains reference to deviceDataBroker
        if (deviceDataBroker != null) {
            LOG.debug("{}: Sending RegisterMountPoint reply to {}", id, askForMasterMountPoint.getSlaveActorRef());
            askForMasterMountPoint.getSlaveActorRef().tell(new RegisterMountPoint(sourceIdentifiers, self()), sender());
        } else {
            LOG.warn("{}: Received {} but we don't appear to be the master", id, askForMasterMountPoint);
            sender().tell(new Failure(new NotMasterException(self())), self());
        }
    } else if (message instanceof YangTextSchemaSourceRequest) {
        // master
        final YangTextSchemaSourceRequest yangTextSchemaSourceRequest = (YangTextSchemaSourceRequest) message;
        sendYangTextSchemaSourceProxy(yangTextSchemaSourceRequest.getSourceIdentifier(), sender());
    } else if (message instanceof NewReadTransactionRequest) {
        // master
        sender().tell(new Success(readTxActor), self());
    } else if (message instanceof NewWriteTransactionRequest) {
        // master
        try {
            final DOMDataTreeWriteTransaction tx = deviceDataBroker.newWriteOnlyTransaction();
            final ActorRef txActor = context().actorOf(WriteTransactionActor.props(tx, writeTxIdleTimeout));
            sender().tell(new Success(txActor), self());
        } catch (final Exception t) {
            sender().tell(new Failure(t), self());
        }
    } else if (message instanceof NewReadWriteTransactionRequest) {
        try {
            final DOMDataTreeReadWriteTransaction tx = deviceDataBroker.newReadWriteTransaction();
            final ActorRef txActor = context().actorOf(ReadWriteTransactionActor.props(tx, writeTxIdleTimeout));
            sender().tell(new Success(txActor), self());
        } catch (final Exception t) {
            sender().tell(new Failure(t), self());
        }
    } else if (message instanceof InvokeRpcMessage) {
        // master
        final InvokeRpcMessage invokeRpcMessage = (InvokeRpcMessage) message;
        invokeSlaveRpc(invokeRpcMessage.getSchemaPath().lastNodeIdentifier(), invokeRpcMessage.getNormalizedNodeMessage(), sender());
    } else if (message instanceof InvokeActionMessage) {
        // master
        final InvokeActionMessage invokeActionMessage = (InvokeActionMessage) message;
        LOG.info("InvokeActionMessage Details : {}", invokeActionMessage.toString());
        invokeSlaveAction(invokeActionMessage.getSchemaPath(), invokeActionMessage.getContainerNodeMessage(), invokeActionMessage.getDOMDataTreeIdentifier(), sender());
    } else if (message instanceof RegisterMountPoint) {
        // slaves
        RegisterMountPoint registerMountPoint = (RegisterMountPoint) message;
        sourceIdentifiers = registerMountPoint.getSourceIndentifiers();
        registerSlaveMountPoint(registerMountPoint.getMasterActorRef());
        sender().tell(new Success(null), self());
    } else if (message instanceof UnregisterSlaveMountPoint) {
        // slaves
        unregisterSlaveMountPoint();
    } else if (message instanceof RefreshSlaveActor) {
        // slave
        actorResponseWaitTime = ((RefreshSlaveActor) message).getActorResponseWaitTime();
        id = ((RefreshSlaveActor) message).getId();
        schemaRegistry = ((RefreshSlaveActor) message).getSchemaRegistry();
        setup = ((RefreshSlaveActor) message).getSetup();
        schemaRepository = ((RefreshSlaveActor) message).getSchemaRepository();
    } else if (message instanceof NetconfDataTreeServiceRequest) {
        ActorRef netconfActor = context().actorOf(NetconfDataTreeServiceActor.props(netconfService, writeTxIdleTimeout));
        sender().tell(new Success(netconfActor), self());
    }
}
Also used : NewWriteTransactionRequest(org.opendaylight.netconf.topology.singleton.messages.transactions.NewWriteTransactionRequest) NewReadWriteTransactionRequest(org.opendaylight.netconf.topology.singleton.messages.transactions.NewReadWriteTransactionRequest) CreateInitialMasterActorData(org.opendaylight.netconf.topology.singleton.messages.CreateInitialMasterActorData) ActorRef(akka.actor.ActorRef) DOMDataTreeWriteTransaction(org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction) UnregisterSlaveMountPoint(org.opendaylight.netconf.topology.singleton.messages.UnregisterSlaveMountPoint) NetconfDataTreeServiceRequest(org.opendaylight.netconf.topology.singleton.messages.netconf.NetconfDataTreeServiceRequest) RefreshSetupMasterActorData(org.opendaylight.netconf.topology.singleton.messages.RefreshSetupMasterActorData) AskForMasterMountPoint(org.opendaylight.netconf.topology.singleton.messages.AskForMasterMountPoint) Success(akka.actor.Status.Success) NotMasterException(org.opendaylight.netconf.topology.singleton.messages.NotMasterException) AskTimeoutException(akka.pattern.AskTimeoutException) IOException(java.io.IOException) InvokeRpcMessage(org.opendaylight.netconf.topology.singleton.messages.rpc.InvokeRpcMessage) RefreshSlaveActor(org.opendaylight.netconf.topology.singleton.messages.RefreshSlaveActor) DOMDataTreeReadWriteTransaction(org.opendaylight.mdsal.dom.api.DOMDataTreeReadWriteTransaction) YangTextSchemaSourceRequest(org.opendaylight.netconf.topology.singleton.messages.YangTextSchemaSourceRequest) MasterActorDataInitialized(org.opendaylight.netconf.topology.singleton.messages.MasterActorDataInitialized) NewReadTransactionRequest(org.opendaylight.netconf.topology.singleton.messages.transactions.NewReadTransactionRequest) InvokeActionMessage(org.opendaylight.netconf.topology.singleton.messages.action.InvokeActionMessage) RegisterMountPoint(org.opendaylight.netconf.topology.singleton.messages.RegisterMountPoint) NotMasterException(org.opendaylight.netconf.topology.singleton.messages.NotMasterException) DOMDataTreeReadTransaction(org.opendaylight.mdsal.dom.api.DOMDataTreeReadTransaction) Failure(akka.actor.Status.Failure)

Example 2 with InvokeActionMessage

use of org.opendaylight.netconf.topology.singleton.messages.action.InvokeActionMessage in project netconf by opendaylight.

the class ProxyDOMActionService method invokeAction.

@Override
public FluentFuture<DOMActionResult> invokeAction(final Absolute type, final DOMDataTreeIdentifier domDataTreeIdentifier, final ContainerNode input) {
    requireNonNull(type);
    requireNonNull(input);
    requireNonNull(domDataTreeIdentifier);
    LOG.info("{}: Action Operation invoked with schema type: {} and node: {}.", id, type, input);
    final ContainerNodeMessage containerNodeMessage = new ContainerNodeMessage(input);
    final Future<Object> scalaFuture = Patterns.ask(masterActorRef, new InvokeActionMessage(new SchemaPathMessage(type), containerNodeMessage, domDataTreeIdentifier), actorResponseWaitTime);
    final SettableFuture<DOMActionResult> settableFuture = SettableFuture.create();
    scalaFuture.onComplete(new OnComplete<>() {

        @Override
        public void onComplete(final Throwable failure, final Object response) {
            if (failure != null) {
                if (failure instanceof ClusteringActionException) {
                    settableFuture.setException(failure);
                } else {
                    settableFuture.setException(new ClusteringActionException(id + ": Exception during remote Action invocation.", failure));
                }
                return;
            }
            if (response instanceof EmptyResultResponse) {
                settableFuture.set(null);
                return;
            }
            final Collection<? extends RpcError> errors = ((InvokeActionMessageReply) response).getRpcErrors();
            final ContainerNodeMessage containerNodeMessage = ((InvokeActionMessageReply) response).getContainerNodeMessage();
            final DOMActionResult result;
            if (containerNodeMessage == null) {
                result = new SimpleDOMActionResult(ImmutableList.copyOf(errors));
            } else {
                result = new SimpleDOMActionResult(containerNodeMessage.getNode(), ImmutableList.copyOf(errors));
            }
            settableFuture.set(result);
        }
    }, actorSystem.dispatcher());
    return FluentFuture.from(settableFuture);
}
Also used : SchemaPathMessage(org.opendaylight.netconf.topology.singleton.messages.SchemaPathMessage) RpcError(org.opendaylight.yangtools.yang.common.RpcError) EmptyResultResponse(org.opendaylight.netconf.topology.singleton.messages.transactions.EmptyResultResponse) SimpleDOMActionResult(org.opendaylight.mdsal.dom.spi.SimpleDOMActionResult) InvokeActionMessage(org.opendaylight.netconf.topology.singleton.messages.action.InvokeActionMessage) ClusteringActionException(org.opendaylight.netconf.topology.singleton.impl.utils.ClusteringActionException) ContainerNodeMessage(org.opendaylight.netconf.topology.singleton.messages.ContainerNodeMessage) Collection(java.util.Collection) DOMActionResult(org.opendaylight.mdsal.dom.api.DOMActionResult) SimpleDOMActionResult(org.opendaylight.mdsal.dom.spi.SimpleDOMActionResult)

Aggregations

InvokeActionMessage (org.opendaylight.netconf.topology.singleton.messages.action.InvokeActionMessage)2 ActorRef (akka.actor.ActorRef)1 Failure (akka.actor.Status.Failure)1 Success (akka.actor.Status.Success)1 AskTimeoutException (akka.pattern.AskTimeoutException)1 IOException (java.io.IOException)1 Collection (java.util.Collection)1 DOMActionResult (org.opendaylight.mdsal.dom.api.DOMActionResult)1 DOMDataTreeReadTransaction (org.opendaylight.mdsal.dom.api.DOMDataTreeReadTransaction)1 DOMDataTreeReadWriteTransaction (org.opendaylight.mdsal.dom.api.DOMDataTreeReadWriteTransaction)1 DOMDataTreeWriteTransaction (org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction)1 SimpleDOMActionResult (org.opendaylight.mdsal.dom.spi.SimpleDOMActionResult)1 ClusteringActionException (org.opendaylight.netconf.topology.singleton.impl.utils.ClusteringActionException)1 AskForMasterMountPoint (org.opendaylight.netconf.topology.singleton.messages.AskForMasterMountPoint)1 ContainerNodeMessage (org.opendaylight.netconf.topology.singleton.messages.ContainerNodeMessage)1 CreateInitialMasterActorData (org.opendaylight.netconf.topology.singleton.messages.CreateInitialMasterActorData)1 MasterActorDataInitialized (org.opendaylight.netconf.topology.singleton.messages.MasterActorDataInitialized)1 NotMasterException (org.opendaylight.netconf.topology.singleton.messages.NotMasterException)1 RefreshSetupMasterActorData (org.opendaylight.netconf.topology.singleton.messages.RefreshSetupMasterActorData)1 RefreshSlaveActor (org.opendaylight.netconf.topology.singleton.messages.RefreshSlaveActor)1