8dbbff5bbe03e2d2508911929512340e80b8ad38
[controller.git] / opendaylight / md-sal / sal-remoterpc-connector / src / main / java / org / opendaylight / controller / remote / rpc / RemoteDOMActionFuture.java
1 /*
2  * Copyright (c) 2019 Nordix Foundation.  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 package org.opendaylight.controller.remote.rpc;
9
10 import org.eclipse.jdt.annotation.NonNull;
11 import org.opendaylight.controller.remote.rpc.messages.ActionResponse;
12 import org.opendaylight.mdsal.dom.api.DOMActionException;
13 import org.opendaylight.mdsal.dom.api.DOMActionResult;
14 import org.opendaylight.mdsal.dom.spi.SimpleDOMActionResult;
15 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
16 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
17 import scala.concurrent.Future;
18
19 final class RemoteDOMActionFuture extends AbstractRemoteFuture<DOMActionResult, DOMActionException> {
20     RemoteDOMActionFuture(final @NonNull SchemaPath type, final @NonNull Future<Object> requestFuture) {
21         super(type, requestFuture);
22     }
23
24     @Override
25     DOMActionResult processReply(final Object reply) {
26         if (reply instanceof ActionResponse) {
27             final ActionResponse actionReply = (ActionResponse) reply;
28             final ContainerNode output = actionReply.getOutput();
29             return output == null ? new SimpleDOMActionResult(actionReply.getErrors())
30                     : new SimpleDOMActionResult(output, actionReply.getErrors());
31         }
32
33         return null;
34     }
35
36     @Override
37     Class<DOMActionException> exceptionClass() {
38         return DOMActionException.class;
39     }
40
41     @Override
42     DOMActionException wrapCause(final Throwable cause) {
43         return new RemoteDOMActionException("Exception during invoking ACTION", cause);
44     }
45 }