f06d71f0dbb1450148f350aa4fe2c37778e19569
[controller.git] / opendaylight / md-sal / samples / clustering-test-app / karaf-cli / src / main / java / org / opendaylight / clustering / it / karaf / cli / car / purchase / BuyCarCommand.java
1 /*
2  * Copyright (c) 2021 PANTHEON.tech, s.r.o. and others.  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.clustering.it.karaf.cli.car.purchase;
9
10 import com.google.common.util.concurrent.ListenableFuture;
11 import org.apache.karaf.shell.api.action.Argument;
12 import org.apache.karaf.shell.api.action.Command;
13 import org.apache.karaf.shell.api.action.lifecycle.Reference;
14 import org.apache.karaf.shell.api.action.lifecycle.Service;
15 import org.opendaylight.clustering.it.karaf.cli.AbstractRpcAction;
16 import org.opendaylight.clustering.it.karaf.cli.InstanceIdentifierSupport;
17 import org.opendaylight.mdsal.binding.api.RpcConsumerRegistry;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.purchase.rev140818.BuyCarInputBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.purchase.rev140818.CarPurchaseService;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.rev140818.CarId;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.people.rev140818.PersonId;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.people.rev140818.PersonRef;
23 import org.opendaylight.yangtools.yang.common.RpcResult;
24
25 @Service
26 @Command(scope = "test-app", name = "buy-car", description = "Run a buy-car test")
27 public class BuyCarCommand extends AbstractRpcAction {
28     @Reference
29     private RpcConsumerRegistry rpcService;
30     @Reference
31     private InstanceIdentifierSupport iidSupport;
32     @Argument(index = 0, name = "person-ref", required = true)
33     String personRef;
34     @Argument(index = 1, name = "car-id", required = true)
35     CarId carId;
36     @Argument(index = 2, name = "person-id", required = true)
37     PersonId personId;
38
39     @Override
40     protected ListenableFuture<? extends RpcResult<?>> invokeRpc() {
41         return rpcService.getRpcService(CarPurchaseService.class).buyCar(new BuyCarInputBuilder()
42             .setPerson(new PersonRef(iidSupport.parseArgument(personRef)))
43             .setCarId(carId)
44             .setPersonId(personId)
45             .build());
46     }
47 }