fix import extra separations
[transportpce.git] / servicehandler / src / main / java / org / opendaylight / transportpce / servicehandler / MappingConstraints.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
10 package org.opendaylight.transportpce.servicehandler;
11
12 import java.util.ArrayList;
13 import java.util.List;
14 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.node.types.rev181130.NodeIdType;
15 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev190329.Constraints;
16 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev190329.constraints.CoRoutingOrGeneral;
17 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev190329.constraints.co.routing.or.general.CoRouting;
18 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev190329.constraints.co.routing.or.general.General;
19 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev190329.constraints.co.routing.or.general.general.Diversity;
20 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev190329.constraints.co.routing.or.general.general.Exclude;
21 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev190329.constraints.co.routing.or.general.general.Include;
22 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev190329.constraints.co.routing.or.general.general.Latency;
23 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev190329.routing.constraints.HardConstraints;
24 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev190329.routing.constraints.SoftConstraints;
25 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev171017.ConstraintsSp;
26 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev171017.constraints.sp.co.routing.or.general.co.routing.CoRoutingBuilder;
27 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev171017.constraints.sp.co.routing.or.general.general.DiversityBuilder;
28 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev171017.constraints.sp.co.routing.or.general.general.ExcludeBuilder;
29 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev171017.constraints.sp.co.routing.or.general.general.IncludeBuilder;
30 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev171017.constraints.sp.co.routing.or.general.general.LatencyBuilder;
31 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev171017.diversity.existing.service.contraints.sp.ExistingServiceApplicabilityBuilder;
32 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev171017.routing.constraints.sp.HardConstraintsBuilder;
33 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev171017.routing.constraints.sp.SoftConstraintsBuilder;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
36
37 /**
38  * Class for mapping
39  * Hard/soft constraint from Service 1.2
40  * to servicePath 1.4.
41  * @author Martial Coulibaly ( martial.coulibaly@gfi.com ) on behalf of Orange
42  *
43  */
44 public class MappingConstraints {
45     /** Logging. */
46     private static final Logger LOG = LoggerFactory.getLogger(MappingConstraints.class);
47     private HardConstraints serviceHardConstraints;
48     private SoftConstraints serviceSoftConstraints;
49     private org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface
50         .routing.constraints.rev171017.routing.constraints.sp.HardConstraints servicePathHardConstraints;
51     private org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface
52         .routing.constraints.rev171017.routing.constraints.sp.SoftConstraints servicePathSoftConstraints;
53
54     /**
55      * MappingConstraints class constructor
56      * for hard/soft from service 1.2.
57      *
58      * @param hard HardConstraints
59      * @param soft SoftConstraints
60      */
61     public MappingConstraints(HardConstraints hard, SoftConstraints soft) {
62         setServiceHardConstraints(hard);
63         setServiceSoftConstraints(soft);
64     }
65
66     /**
67      * MappingConstraints class constructor
68      * for hard/soft from servicePath 1.4.
69      *
70      * @param hard HardConstraints
71      * @param soft SoftConstraints
72      */
73     public MappingConstraints(org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface
74             .routing.constraints.rev171017.routing.constraints.sp.HardConstraints hard,
75             org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface
76             .routing.constraints.rev171017.routing.constraints.sp.SoftConstraints soft) {
77         setServicePathHardConstraints(hard);
78         setServicePathSoftConstraints(soft);
79     }
80
81     /**
82      *get all constraints informations
83      *from service constraints to map to
84      *servicePath constraints.
85      *
86      * @param input HardConstraints or SoftConstraints
87      * @return ConstraintsSp HardConstraintsSp or HardConstraintsSp
88      */
89     private <T> ConstraintsSp getConstraints(T input) {
90         CoRoutingOrGeneral coRoutingOrGeneral = null;
91         HardConstraintsBuilder tempHard = new HardConstraintsBuilder();
92         SoftConstraintsBuilder tempSoft = new SoftConstraintsBuilder();
93         if ((input  !=  null) && (input instanceof Constraints)) {
94             Constraints constraints = (Constraints)input;
95             coRoutingOrGeneral = constraints.getCoRoutingOrGeneral();
96             General tmpGeneral = null;
97             CoRouting tmpCoRouting = null;
98             if (coRoutingOrGeneral  !=  null) {
99                 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints
100                     .rev171017.constraints.sp.co.routing.or.general.GeneralBuilder finalGeneral =
101                     new org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints
102                     .rev171017.constraints.sp.co.routing.or.general.GeneralBuilder();
103                 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints
104                     .rev171017.constraints.sp.co.routing.or.general.CoRoutingBuilder finalCoRouting =
105                     new org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints
106                     .rev171017.constraints.sp.co.routing.or.general.CoRoutingBuilder();
107                 if (coRoutingOrGeneral instanceof General) {
108                     tmpGeneral = (General) coRoutingOrGeneral;
109                     if (tmpGeneral  !=  null) {
110                         Diversity tmpDiversity =  tmpGeneral.getDiversity();
111                         if (tmpDiversity  !=  null) {
112                             finalGeneral.setDiversity(
113                                     new DiversityBuilder()
114                                     .setExistingService(tmpDiversity.getExistingService())
115                                     .setExistingServiceApplicability(
116                                             new ExistingServiceApplicabilityBuilder()
117                                             .setClli(tmpDiversity.getExistingServiceApplicability().isSite())
118                                             .setNode(tmpDiversity.getExistingServiceApplicability().isNode())
119                                             .setSrlg(tmpDiversity.getExistingServiceApplicability().isSrlg())
120                                             .build())
121                                     .build());
122                         }
123                         Exclude tmpExclude = tmpGeneral.getExclude();
124                         if (tmpExclude  !=  null) {
125                             List<String> nodeIdList = new ArrayList<>();
126                             for (NodeIdType nodeId : tmpExclude.getNodeId()) {
127                                 nodeIdList.add(nodeId.getValue());
128                             }
129                             finalGeneral.setExclude(
130                                     new ExcludeBuilder()
131                                     .setSupportingServiceName(tmpExclude.getSupportingServiceName())
132                                     .setClli(tmpExclude.getSite())
133                                     .setNodeId(nodeIdList)
134                                     //.setAffinity(value)
135                                     //.setSRLG(value)
136                                     .build());
137                         }
138                         Include tmpInclude = tmpGeneral.getInclude();
139                         if (tmpInclude  !=  null) {
140                             finalGeneral.setInclude(
141                                     new IncludeBuilder()
142                                     //.setOrderedHops()
143                                     .build());
144                         }
145                         Latency tmpLatency = tmpGeneral.getLatency();
146                         if (tmpLatency != null) {
147                             finalGeneral.setLatency(
148                                     new LatencyBuilder()
149                                     .setMaxLatency(tmpLatency.getMaxLatency())
150                                     .build());
151                         }
152                     }
153                     tempHard.setCoRoutingOrGeneral(finalGeneral.build())
154                         .setCustomerCode(constraints.getCustomerCode());
155                     tempSoft.setCoRoutingOrGeneral(finalGeneral.build())
156                         .setCustomerCode(constraints.getCustomerCode());
157                 } else if (coRoutingOrGeneral instanceof CoRouting) {
158                     tmpCoRouting = (CoRouting)coRoutingOrGeneral;
159                     if (tmpCoRouting  !=  null) {
160                         org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev190329
161                             .constraints.co.routing.or.general.co.routing.CoRouting tmpCoRoutingCoRouting =
162                             tmpCoRouting.getCoRouting();
163                         if (tmpCoRoutingCoRouting  !=  null) {
164                             finalCoRouting.setCoRouting(
165                                     new CoRoutingBuilder()
166                                     .setExistingService(tmpCoRoutingCoRouting.getExistingService())
167                                     .build());
168                         }
169                     }
170                     tempHard.setCoRoutingOrGeneral(finalCoRouting.build())
171                         .setCustomerCode(constraints.getCustomerCode());
172                     tempSoft.setCoRoutingOrGeneral(finalCoRouting.build())
173                         .setCustomerCode(constraints.getCustomerCode());
174                 }
175             }
176         }
177         if (input instanceof HardConstraints) {
178             return tempHard.build();
179         } else if (input instanceof SoftConstraints) {
180             return tempSoft.build();
181         } else {
182             return null;
183         }
184     }
185
186     /**
187      * map hard/soft constraints from Service 1.2
188      * to ServicePath 1.4.
189      */
190     public void serviceToServicePathConstarints() {
191         LOG.info("Mapping Service Constraints to ServicePath Constraints");
192         if (serviceHardConstraints  !=  null) {
193             org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints
194                 .rev171017.routing.constraints.sp.HardConstraints tempHard = (org.opendaylight.yang.gen
195                     .v1.http.org.transportpce.b.c._interface.routing.constraints.rev171017.routing
196                     .constraints.sp.HardConstraints) getConstraints(serviceHardConstraints);
197             if (tempHard != null) {
198                 servicePathHardConstraints = tempHard;
199             }
200         } else if (serviceSoftConstraints  !=  null) {
201             org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints
202                 .rev171017.routing.constraints.sp.SoftConstraints tempSoft = (org.opendaylight.yang.gen
203                     .v1.http.org.transportpce.b.c._interface.routing.constraints.rev171017.routing
204                     .constraints.sp.SoftConstraints) getConstraints(serviceSoftConstraints);
205             if (tempSoft != null) {
206                 servicePathSoftConstraints = tempSoft;
207             }
208         }
209     }
210
211
212     public HardConstraints getServiceHardConstraints() {
213         return serviceHardConstraints;
214     }
215
216
217     public void setServiceHardConstraints(HardConstraints serviceHardConstraints) {
218         this.serviceHardConstraints = serviceHardConstraints;
219     }
220
221
222     public SoftConstraints getServiceSoftConstraints() {
223         return serviceSoftConstraints;
224     }
225
226
227     public void setServiceSoftConstraints(SoftConstraints serviceSoftConstraints) {
228         this.serviceSoftConstraints = serviceSoftConstraints;
229     }
230
231
232     public org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface
233         .routing.constraints.rev171017.routing.constraints.sp.HardConstraints getServicePathHardConstraints() {
234         return servicePathHardConstraints;
235     }
236
237
238     public void setServicePathHardConstraints(org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface
239             .routing.constraints.rev171017.routing.constraints.sp.HardConstraints servicePathHardConstraints) {
240         this.servicePathHardConstraints = servicePathHardConstraints;
241     }
242
243
244     public org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface
245         .routing.constraints.rev171017.routing.constraints.sp.SoftConstraints getServicePathSoftConstraints() {
246         return servicePathSoftConstraints;
247     }
248
249
250     public void setServicePathSoftConstraints(org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface
251             .routing.constraints.rev171017.routing.constraints.sp.SoftConstraints servicePathSoftConstraints) {
252         this.servicePathSoftConstraints = servicePathSoftConstraints;
253     }
254
255 }