c7f587c7fe00e52a63c3b57c0edd13098dda2690
[transportpce.git] / tests / stubrenderer / src / main / java / org / opendaylight / transportpce / stubrenderer / SendingRendererRPCs.java
1 /*
2  * Copyright © 2017 Orange, Inc. 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
9 package org.opendaylight.transportpce.stubrenderer;
10
11 import com.google.common.util.concurrent.ListenableFuture;
12 import com.google.common.util.concurrent.ListeningExecutorService;
13
14 import java.util.ArrayList;
15 import java.util.List;
16 import java.util.concurrent.Callable;
17
18 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service.TopologyBuilder;
19 import org.opendaylight.yang.gen.v1.http.org.openroadm.topology.rev161014.topology.AToZ;
20 import org.opendaylight.yang.gen.v1.http.org.openroadm.topology.rev161014.topology.ZToA;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
23
24 /**
25  *Class for Sending
26  * Renderer requests :
27  * - Service-implementation-request
28  * - Service-delete-request.
29  * @author Martial Coulibaly ( martial.coulibaly@gfi.com ) on behalf of Orange
30  *
31  */
32 public class SendingRendererRPCs {
33     /** Logging. */
34     private static final Logger LOG = LoggerFactory.getLogger(SendingRendererRPCs.class);
35     /** define procedure success (or not ). */
36     private Boolean success;
37     /** define type of request<br>
38      * <code>true</code> pathcomputation <br>
39      * <code>false</code> cancelresourcereserve. */
40     private TopologyBuilder topology;
41     private List<AToZ> atoz;
42     private List<ZToA> ztoa;
43     private String error;
44     private final ListeningExecutorService executor;
45
46     public SendingRendererRPCs(ListeningExecutorService executor) {
47         success = true;
48         setTopology(null);
49         this.executor = executor;
50         setError("");
51     }
52
53     private void buildAtoZ() {
54         atoz = new ArrayList<AToZ>();
55     }
56
57     private void buildZtoA() {
58         ztoa = new ArrayList<ZToA>();
59     }
60
61     public ListenableFuture<Boolean> serviceDelete() {
62         LOG.info("ServiceDelete request ...");
63         success = false;
64         return executor.submit(new Callable<Boolean>() {
65             @Override
66             public Boolean call() throws Exception {
67                 Boolean output = true;
68                 LOG.info("Wait for 10s til beginning the Renderer serviceDelete request");
69                 try {
70                     Thread.sleep(10000); //sleep for 10s
71                 } catch (InterruptedException e) {
72                     output = false;
73                     LOG.error(e.toString());
74                 }
75                 buildAtoZ();
76                 buildZtoA();
77                 success = true;
78                 return output;
79             }
80         });
81     }
82
83     public ListenableFuture<Boolean> serviceImplementation() {
84         LOG.info("serviceImplementation request ...");
85         success = false;
86         return executor.submit(new Callable<Boolean>() {
87             @Override
88             public Boolean call() throws Exception {
89                 Boolean output = true;
90                 LOG.info("Wait for 10s til beginning the Renderer serviceDelete request");
91                 try {
92                     Thread.sleep(10000); //sleep for 10s
93                 } catch (InterruptedException e) {
94                     output = false;
95                     LOG.error(e.toString());
96                 }
97                 buildAtoZ();
98                 buildZtoA();
99                 setTopology(new TopologyBuilder()
100                         .setAToZ(atoz)
101                         .setZToA(ztoa));
102                 output = true;
103                 success = true;
104                 return output;
105             }
106         });
107     }
108
109     public Boolean getSuccess() {
110         return success;
111     }
112
113     public void setSuccess(Boolean success) {
114         this.success = success;
115     }
116
117     public TopologyBuilder getTopology() {
118         return topology;
119     }
120
121     public void setTopology(TopologyBuilder topo) {
122         this.topology = topo;
123     }
124
125     public String getError() {
126         return error;
127     }
128
129     public void setError(String error) {
130         this.error = error;
131     }
132 }