aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/org/onap/aai/migration/v12/MigratePATHEvcInventory.java
blob: 28b5b7b4e981ae5f5e573d44fc2007fd54eae607 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
/**
 * ============LICENSE_START=======================================================
 * org.onap.aai
 * ================================================================================
 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ============LICENSE_END=========================================================
 */
package org.onap.aai.migration.v12;
/*-
 * ============LICENSE_START=======================================================
 * org.onap.aai
 * ================================================================================
 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ============LICENSE_END=========================================================
 */


import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Optional;

import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.onap.aai.db.props.AAIProperties;
import org.onap.aai.edges.EdgeIngestor;
import org.onap.aai.introspection.Introspector;
import org.onap.aai.introspection.LoaderFactory;
import org.onap.aai.migration.MigrationDangerRating;
import org.onap.aai.migration.MigrationPriority;
import org.onap.aai.migration.Migrator;
import org.onap.aai.migration.Status;
import org.onap.aai.serialization.db.EdgeSerializer;
import org.onap.aai.serialization.engines.TransactionalGraphEngine;
import org.onap.aai.setup.SchemaVersions;
import org.onap.aai.util.AAIConfig;


@MigrationPriority(29)
@MigrationDangerRating(100)
public class MigratePATHEvcInventory extends Migrator {

	private static Map<String, Vertex> portList = new HashMap<String, Vertex>();
	private static Map<String, Vertex> pnfList = new HashMap<String, Vertex>();
	private final String FORWARDER_EVC_NODE_TYPE = "forwarder-evc";
	private final String LAGINTERFACE_NODE_TYPE = "lag-interface";
	private final String CONFIGURATION_NODE_TYPE = "configuration";
	private final String FORWARDING_PATH_NODE_TYPE = "forwarding-path";
	private final String FORWARDING_PATH_ID = "forwarding-path-id";
	private final String PROPERTY_CONFIGURATION_ID = "configuration-id";
	private final String PNF_NODE_TYPE = "pnf";
	private final String PROPERTY_PNF_NAME = "pnf-name";
	private final String PROPERTY_INTERFACE_NAME = "interface-name";
	private final String PINTERFACE_NODE_TYPE = "p-interface";
	private static boolean success = true;
    private static boolean checkLog = false;
    private static GraphTraversalSource g = null;
    private int headerLength;
    
    //Create a map to store the evcs processed where lag-interfaces were found to track the sequence of ports
    //key contains the evcName
    //value is a map that contains the mapping for sequence of forwarders and corresponding portAids in the order they are found 
    
    private static Map<String, Map<Vertex, String>> pathFileMap = new HashMap<String, Map<Vertex, String>>();
  
    private static int processedEvcsCount = 0;
    private static int falloutEvcsCount = 0;
    
    //Map with lineNumber and the reason for failure for each EVC
    private static Map<Integer, String> falloutEvcsList = new HashMap<Integer, String>();
    private static final String homeDir = System.getProperty("AJSC_HOME");
	private static List<String> dmaapMsgList = new ArrayList<String>();
	
	
    public MigratePATHEvcInventory(TransactionalGraphEngine engine, LoaderFactory loaderFactory, EdgeIngestor edgeIngestor, EdgeSerializer edgeSerializer, SchemaVersions schemaVersions) {
        super(engine, loaderFactory, edgeIngestor, edgeSerializer, schemaVersions);
        this.g = this.engine.asAdmin().getTraversalSource();
    }

    @Override
    public void run() {
        logger.info("---------- Start migration of PATH EVC Inventory  ----------");
        String configDir = System.getProperty("BUNDLECONFIG_DIR");
        if (homeDir == null) {
            logger.info("ERROR: Could not find sys prop AJSC_HOME");
            success = false;
            return;
        }
        if (configDir == null) {
            success = false;
            return;
        }
        
        String feedDir = homeDir + "/" + configDir + "/" + "migration-input-files/sarea-inventory/";
        int fileLineCounter = 0;
        String fileName = feedDir+ "path.csv";
        logger.info(fileName);
        logger.info("---------- Processing PATH Entries from file  ----------");
        try {
        	List<String> lines = Files.readAllLines(Paths.get(fileName));
            Iterator<String> lineItr = lines.iterator();
            while (lineItr.hasNext()){
                String line = lineItr.next().replace("\n", "").replace("\r", "");
                logger.info("\n");
                if (!line.isEmpty()) {
                    if (fileLineCounter != 0) {
                        String[] colList = line.split(",", -1);
                        if (colList.length != headerLength) {
                            logger.info("ERROR: PATH line should contain " + headerLength + " columns, contains " + colList.length + " instead.");
//                            success = false;
                            continue;
                        }
                        Map<String, String> pathColValues = new HashMap<String, String>();
                        pathColValues.put("evcName", colList[1].trim());
                        pathColValues.put("bearerFacingCircuit", colList[4].trim());
                        pathColValues.put("bearerCvlan", colList[6].trim());
                    	pathColValues.put("bearerSvlan", colList[7].trim());
                    	pathColValues.put("bearerPtniiName", colList[8].trim());
                    	String bearerPortAid = colList[12].trim().replaceAll("^\"|\"$", "").replaceAll("\\s+","");
                    	pathColValues.put("bearerPortAid", bearerPortAid);
                    	pathColValues.put("collectorFacingCircuit", colList[14].trim());
                    	pathColValues.put("collectorCvlan", colList[16].trim());
                    	pathColValues.put("collectorSvlan", colList[17].trim());
                    	pathColValues.put("collectorPtniiName", colList[18].trim());
                    	String collectorPortAid = colList[22].trim().replaceAll("^\"|\"$", "").replaceAll("\\s+","");
                    	pathColValues.put("collectorPortAid", collectorPortAid);
                    	
                    	
                    	String evcName = pathColValues.get("evcName");
                        if (!AAIConfig.isEmpty(evcName)) {
                        	logger.info("---------- Processing Line " + line + "----------");
                            logger.info("\t Evc Name = " + evcName );
                            
                            boolean isEntryValid = validatePnfsAndPorts(pathColValues, evcName);
                            
                            if (!isEntryValid){
                            	logger.info("\t ERROR: Skipping processing for line containing evc-name [" +evcName+ "]");
									falloutEvcsCount++;
									falloutEvcsList.put(Integer.valueOf(fileLineCounter -1 ), "["+ evcName +"] Ptnii or port does not exist");
								continue;
                            }
                            // Get the forwarding path containing forwarders
                            GraphTraversal<Vertex, Vertex> forwardingPathList = g.V().has(this.FORWARDING_PATH_ID, evcName).has(AAIProperties.NODE_TYPE, this.FORWARDING_PATH_NODE_TYPE)
                            		.where(__.in("org.onap.relationships.inventory.BelongsTo").has("aai-node-type","forwarder"));
                            
                            if (!forwardingPathList.hasNext()){
                            	createNewForwardersFromPATHData(pathColValues, evcName, fileLineCounter);
                            	processedEvcsCount++;
                            } else {
                            	Vertex forwardingPathVtx = forwardingPathList.next();
                            	List<Vertex> forwardersList = g.V(forwardingPathVtx.id()).in("org.onap.relationships.inventory.BelongsTo").toList();
                            	Iterator<Vertex> forwardersItr = forwardersList.iterator();
                            	List<String> forwarderRoleList =  new ArrayList<String>();
                            	while (forwardersItr.hasNext()){
                            		Vertex forwarderVtx = forwardersItr.next();
                            		String role = forwarderVtx.value("forwarder-role");
                            		if (role!= null ){
                            			forwarderRoleList.add(role);
                            		}
                            	}
                            	if (forwarderRoleList!= null && !forwarderRoleList.isEmpty()) {
                            		if (forwarderRoleList.contains("ingress") && forwarderRoleList.contains("egress")){
                            			logger.info("\t Skipping processing for EVC[" + evcName + "] because forwarders related to this EVC already exist.");
                            			falloutEvcsCount++;
                            			falloutEvcsList.put(Integer.valueOf(fileLineCounter -1 ), "["+ evcName +"] Forwarders already exists for EVC");
                            		} else {
                                		createNewForwardersFromPATHData(pathColValues, evcName, fileLineCounter);
                            		} 
                            	}
                            }
                        }
                    } else {
                        this.headerLength = line.split(",", -1).length;
                        logger.info("headerLength: " + headerLength);
                        if (this.headerLength < 24){
                            logger.info("ERROR: Input file should have 24 columns");
                            this.success = false;
                            return;
                        }
                    }
                }
                fileLineCounter++;
            }
            logger.info ("\n \n ******* Final Summary for PATH FILE Migration ********* \n");
            logger.info("Evcs processed: "+processedEvcsCount);
            logger.info("Total Rows Count: "+(fileLineCounter + 1));
            logger.info("Fallout Rows Count : "+falloutEvcsCount +"\n");
            if (!falloutEvcsList.isEmpty()) {
            	logger.info("------ Fallout Details: ------");
            	falloutEvcsList.forEach((lineNumber, errorMsg) -> {
            		logger.info(errorMsg + ": on row "+lineNumber.toString());
            	});
            }
        } catch (FileNotFoundException e) {
            logger.info("ERROR: Could not file file " + fileName, e.getMessage());
            success = false;
            checkLog = true;
        } catch (IOException e) {
            logger.info("ERROR: Issue reading file " + fileName, e);
            success = false;
        } catch (Exception e) {
            logger.info("encountered exception", e);
            success = false;
        }
    }
    
    
	private boolean validatePnfsAndPorts(Map<String, String> pathColValues, String evcName) {
    	
    	String collectorPtniiName = pathColValues.get("collectorPtniiName");
    	String bearerPtniiName = pathColValues.get("bearerPtniiName");
    	String collectorPortAid = pathColValues.get("collectorPortAid");
    	String bearerPortAid = pathColValues.get("bearerPortAid");
		boolean isValid = validateCollectorPnf(collectorPtniiName, evcName) && validateBearerPnf(bearerPtniiName, evcName) 
				&& validateCollectorPort(pathColValues, collectorPortAid, collectorPtniiName, evcName) 
				&& validateBearerPort(pathColValues, bearerPortAid, bearerPtniiName, evcName) ;
		return isValid;
	}

	private boolean validateCollectorPnf(String collectorPtniiName, String evcName) {
		
		boolean isValid = false;
		if (!AAIConfig.isEmpty(collectorPtniiName)) {
			if (!pnfList.isEmpty() && pnfList.containsKey(collectorPtniiName)){
				isValid = true;
				logger.info("\t Pnf [" + collectorPtniiName + "] found in AAI");
				return isValid;
			}
			List<Vertex> collectorPnfList = g.V().has(this.PROPERTY_PNF_NAME, collectorPtniiName).has(AAIProperties.NODE_TYPE, PNF_NODE_TYPE).toList();
			if (collectorPnfList != null && collectorPnfList.size() == 1) {
				isValid = true;
				pnfList.put(collectorPtniiName, collectorPnfList.get(0));
				logger.info("\t Pnf [" + collectorPtniiName + "] found in AAI");
			} else if (collectorPnfList == null || collectorPnfList.size() == 0) {
				logger.info("\t ERROR: Failure to find Pnf [" + collectorPtniiName	+ "] for EVC ["	+ evcName + "]");
			}
		}
		return isValid;
	}
	
	private boolean validateBearerPnf(String bearerPtniiName, String evcName) {
		boolean isValid = false;
		if (!AAIConfig.isEmpty(bearerPtniiName)) {
			if (!pnfList.isEmpty() && pnfList.containsKey(bearerPtniiName)){
				isValid = true;
				logger.info("\t Pnf [" + bearerPtniiName + "] found in AAI");
				return isValid;
			}
			List<Vertex> bearerPnfList = g.V().has(this.PROPERTY_PNF_NAME, bearerPtniiName).has(AAIProperties.NODE_TYPE, PNF_NODE_TYPE).toList();
	    	if (bearerPnfList!= null && bearerPnfList.size() == 1){
	            isValid = true;
	            pnfList.put(bearerPtniiName, bearerPnfList.get(0));
	            logger.info("\t Pnf ["+ bearerPtniiName + "] found in AAI");
	        }
	        else if (bearerPnfList == null || bearerPnfList.size() == 0) {
	        	logger.info("\t ERROR:  Failure to find Pnf ["+ bearerPtniiName + "]  for EVC [" + evcName + "]");
	        }	
	    }
    	return isValid;
	}
	
	private boolean validateCollectorPort(Map<String, String> pathColValues, String collectorPortAid, String collectorPtniiName, String evcName) {
		boolean isValid = false;
		
		if (!AAIConfig.isEmpty(collectorPortAid)) {
			
			boolean isPortAidALagIntf = false;
			GraphTraversal<Vertex, Vertex> collectorPortList;
			String lagInterface = null;
			
			int lagIdentifierIndex = collectorPortAid.indexOf("_");
			
			if (lagIdentifierIndex > 0) {
				String[] subStringList = collectorPortAid.split("_");
				lagInterface = subStringList[0]; //forwarder will be related to this lagInterface
				isPortAidALagIntf = true;
			}
			
			if (isPortAidALagIntf)
			{
				if (!portList.isEmpty() && portList.containsKey(collectorPtniiName+"_"+lagInterface)){
					isValid = true;
					logger.info("\t lag-interface [" + lagInterface	+ "] found in AAI");
					populatePathFileMapWithForwarderInfo(collectorPtniiName, evcName, lagInterface, portList.get(collectorPtniiName+"_"+lagInterface));
					return isValid;
				}
				Vertex collectorPnfVtx  = pnfList.get(collectorPtniiName);
				if (collectorPnfVtx == null ) {
					logger.info("\t ERROR: Failure to find lag-interface ["+ lagInterface + "] for EVC [" + evcName + "]");
					return isValid;
				} else {
					collectorPortList = g.V(collectorPnfVtx).in("tosca.relationships.network.BindsTo").has("interface-name", lagInterface).has("aai-node-type", "lag-interface");
					 
			    	if (collectorPortList!= null && collectorPortList.hasNext()) {
			    		Vertex lagInterfaceVtx = collectorPortList.next();
			            if (lagInterfaceVtx != null && lagInterfaceVtx.property("interface-name").isPresent()) {
							isValid = true;
							portList.put(collectorPtniiName+"_"+lagInterface, lagInterfaceVtx);
							populatePathFileMapWithForwarderInfo(collectorPtniiName, evcName, lagInterface,	lagInterfaceVtx);
							logger.info("\t lag-interface [" + lagInterface
									+ "] found in AAI");
						}
			        }
			        else if (collectorPortList == null || !collectorPortList.hasNext()) {
			        	logger.info("\t ERROR: Failure to find lag-interface ["+ lagInterface + "] for EVC [" + evcName + "]");
			        }
				}
			} 
			else if (!isPortAidALagIntf)
			{
				if (!portList.isEmpty() && portList.containsKey(collectorPtniiName+"_"+collectorPortAid)){
					isValid = true;
					logger.info("\t p-interface [" + collectorPortAid + "] found in AAI");
					populatePathFileMapWithForwarderInfo(collectorPtniiName, evcName, collectorPortAid, portList.get(collectorPtniiName+"_"+collectorPortAid));
					return isValid;
				}
				
				Vertex collectorPnfVtx  = pnfList.get(collectorPtniiName);
				if (collectorPnfVtx == null ) {
					logger.info("\t ERROR: Failure to find p-interface ["+ collectorPortAid + "] for EVC [" + evcName + "]");
					return isValid;
				} else {
					collectorPortList =g.V(collectorPnfVtx).in("tosca.relationships.network.BindsTo").has("interface-name", collectorPortAid).has("aai-node-type", "p-interface");
							
			    	if (collectorPortList!= null && collectorPortList.hasNext()) {
			    		Vertex pInterfaceVtx = collectorPortList.next();
			    		if (pInterfaceVtx != null && pInterfaceVtx.property("interface-name").isPresent()) {
							isValid = true;
							portList.put(collectorPtniiName+"_"+collectorPortAid, pInterfaceVtx );
							populatePathFileMapWithForwarderInfo(collectorPtniiName, evcName, collectorPortAid, pInterfaceVtx);
							logger.info("\t p-interface [" + collectorPortAid
									+ "] found in AAI");
						}
			        }
			        else if (collectorPortList == null || !collectorPortList.hasNext()) {
			        	logger.info("\t ERROR: Failure to find p-interface ["+ collectorPortAid + "] for EVC [" + evcName + "]");
			        }
				}
			}
		}
    	return isValid;
	}

	private boolean validateBearerPort(Map<String, String> pathColValues, String bearerPortAid, String bearerPtniiName, String evcName) {
		boolean isValid = false;
		
		if (!AAIConfig.isEmpty(bearerPortAid)) {
			GraphTraversal<Vertex, Vertex> bearerPortList;
			
			boolean isPortAidALagIntf = false;
			GraphTraversal<Vertex, Vertex> collectorPortList;
			String lagInterface = null;
			
			int lagIdentifierIndex = bearerPortAid.indexOf("_");
			
			if (lagIdentifierIndex > 0) {
				String[] subStringList = bearerPortAid.split("_");
				lagInterface = subStringList[0]; //forwarder will be related to this lagInterface
				isPortAidALagIntf = true;
			}
			
			if (isPortAidALagIntf)
			{
				if (!portList.isEmpty() && portList.containsKey(bearerPtniiName+"_"+lagInterface)){
					isValid = true;
					logger.info("\t lag-interface [" + lagInterface	+ "] found in AAI");
					populatePathFileMapWithForwarderInfo(bearerPtniiName, evcName, lagInterface, portList.get(bearerPtniiName+"_"+lagInterface));
					return isValid;
				}
				Vertex bearerPnfVtx  = pnfList.get(bearerPtniiName);
				if (bearerPnfVtx == null ) {
					logger.info("\t ERROR: Failure to find lag-interface ["+ lagInterface + "] for EVC [" + evcName + "]");
					return isValid;
				} else {
					GraphTraversal<Vertex, Vertex> lagPortList = g.V(bearerPnfVtx).in("tosca.relationships.network.BindsTo").has("interface-name", lagInterface).has("aai-node-type", "lag-interface");
			    	if (lagPortList!= null && lagPortList.hasNext()) {
			    		Vertex lagInterfaceVtx = lagPortList.next();
			    		if (lagInterfaceVtx != null && lagInterfaceVtx.property("interface-name").isPresent()) {
							isValid = true;
							portList.put(bearerPtniiName+"_"+lagInterface, lagInterfaceVtx);
							populatePathFileMapWithForwarderInfo(bearerPtniiName, evcName, lagInterface, lagInterfaceVtx);
							logger.info("\t lag-interface [" + lagInterface
									+ "] found in AAI");
						}
			        }
			        else if (lagPortList == null || !lagPortList.hasNext()) {
			        	logger.info("\t ERROR: Failure to find lag-interface ["+ lagInterface + "] for EVC [" + evcName + "]");
			        }
				}
			} 
			else if (!isPortAidALagIntf) {
				if (!portList.isEmpty() && portList.containsKey(bearerPtniiName+"_"+bearerPortAid)){
					isValid = true;
					logger.info("\t p-interface [" + bearerPortAid + "] found in AAI");
					populatePathFileMapWithForwarderInfo(bearerPtniiName, evcName, bearerPortAid, portList.get(bearerPtniiName+"_"+bearerPortAid));
					return isValid;
				}
				Vertex bearerPnfVtx  = pnfList.get(bearerPtniiName);
				if (bearerPnfVtx == null ) {
					logger.info("\t ERROR: Failure to find p-interface ["+ bearerPortAid + "] for EVC [" + evcName + "]");
					return isValid;
				} else {
					bearerPortList = g.V(bearerPnfVtx).in("tosca.relationships.network.BindsTo").has("interface-name", bearerPortAid).has("aai-node-type","p-interface");
					if (bearerPortList!= null && bearerPortList.hasNext()){
						Vertex pInterfaceVtx = bearerPortList.next();
			    		if (pInterfaceVtx != null && pInterfaceVtx.property("interface-name").isPresent()) {
							isValid = true;
							portList.put(bearerPtniiName+"_"+bearerPortAid, pInterfaceVtx);
							populatePathFileMapWithForwarderInfo(bearerPtniiName, evcName, bearerPortAid, pInterfaceVtx);
							logger.info("\t p-interface [" + bearerPortAid
									+ "] found in AAI");
						}
					}
					else if (bearerPortList == null || !bearerPortList.hasNext()) {
						logger.info("\t ERROR: Failure to find p-interface ["+ bearerPortAid + "] for evc [" + evcName + "]");
					}
				}
			}
		}
    	return isValid;
	}

	private void populatePathFileMapWithForwarderInfo(String ptniiName, String evcName, String lagInterface, Vertex interfaceVtx) {
		int size = 0;
		Map<Vertex, String> interfaceMap = new HashMap<Vertex, String>();
		interfaceMap = pathFileMap.get(evcName);
		if (interfaceMap != null && !interfaceMap.isEmpty()) {
			size = interfaceMap.size();
		}
		String sequence = Integer.toString(size + 1);
		if (interfaceMap != null && size > 0){
			interfaceMap.put(interfaceVtx, sequence +"_"+ ptniiName+"_"+lagInterface);
		} else{
			interfaceMap = new HashMap<Vertex, String>();
			interfaceMap.put(interfaceVtx, sequence +"_"+ptniiName+"_"+lagInterface );
		}
		pathFileMap.put(evcName, interfaceMap);
	}

    private void createNewForwardersFromPATHData(Map<String, String> pathColValues, String evcName, int fileLineCounter) {
    	Map<Vertex, String> forwarderMap = pathFileMap.get(evcName);
    	List<Vertex> forwardingPathVtxList  = g.V().has(this.FORWARDING_PATH_ID, evcName).has(AAIProperties.NODE_TYPE, FORWARDING_PATH_NODE_TYPE).toList();
    	if (forwardingPathVtxList != null && !forwardingPathVtxList.isEmpty())  {
    		Vertex forwardingPathVtx = forwardingPathVtxList.get(0);
			if (forwarderMap != null && !forwarderMap.isEmpty()) {
				//for each forwarder, create the new forwarder object
				forwarderMap.forEach((portVtx, port) -> {

					Vertex forwarderVtx = createForwarderObject(evcName, portVtx, port, forwardingPathVtx);
					if (forwarderVtx != null) {
						String forwarderRole = forwarderVtx.value("forwarder-role").toString();
						Vertex configurationVtx = createConfigurationObject(evcName, portVtx, port, forwarderVtx);
						createForwarderEvcObject(pathColValues, forwarderRole, portVtx, port,
								configurationVtx);
					}
				});
			}
		} else {
			falloutEvcsList.put((fileLineCounter + 1), "["+ evcName +"] Forwarding-path does not exist for EVC");
			falloutEvcsCount++;
			//Reduce the count of processed evcs since this EVC row cannot be processed
			processedEvcsCount--;
			logger.info("\t ERROR: Forwarding-path does not exist for EVC [" + evcName + "] skipping processing for this EVC.");
		}
	}

	private Vertex createForwarderObject(String evcName, Vertex intfVertex, String port, Vertex forwardingPathVtx) {
    	Vertex forwarderVtx = null;

		try {
			//check if the forwarder was already created
			List<Vertex> forwardersList = g.V(forwardingPathVtx.id()).in("org.onap.relationships.inventory.BelongsTo").toList();
        	Iterator<Vertex> forwardersItr = forwardersList.iterator();
        	while (forwardersItr.hasNext()){
        		Vertex existingForwarderVtx = forwardersItr.next();
        		Vertex existingIntfVtx = g.V(existingForwarderVtx).out("org.onap.relationships.inventory.ForwardsTo").toList().get(0);
        		if( existingIntfVtx.id().equals(intfVertex.id())) {
        			//this forwarder has already been created from the forwarderMap
        			return null;
        		}
        	}
			Integer sequence = getSequenceFromPathMapPort(port);
			String role = getForwarderRole(port);
			
			Introspector forwarder = loader.introspectorFromName("forwarder");
			forwarderVtx = serializer.createNewVertex(forwarder);
			
			if (sequence != null && role != null) {
				forwarder.setValue("sequence", sequence);
				forwarder.setValue("forwarder-role", role );
				
				//Create tree edge from forwarding-path
				this.createTreeEdge(forwardingPathVtx, forwarderVtx);
				//Create cousin edge to p-interface or lag-interface
				this.createCousinEdge(intfVertex, forwarderVtx);
				
				serializer.serializeSingleVertex(forwarderVtx, forwarder, "migrations");
				
//				String forwarderVtxProps = this.asString(forwarderVtx);
//				logger.info(" forwarderVtxProps:" + forwarderVtxProps);
				
				String forwarderVtxSequence = forwarderVtx.value("sequence").toString() ;
				String forwarderVtxRole = forwarderVtx.value("forwarder-role").toString();
				String forwardingPathId = forwardingPathVtx.value("forwarding-path-id").toString();
				
				logger.info("\t Created new forwarder " + forwarderVtx + " with sequence = " + forwarderVtxSequence + " with role [" + forwarderVtxRole 
						+"] as a child of forwarding-path [" + forwardingPathId + "]" );
				
				String dmaapMsg = System.nanoTime() + "_" + forwarderVtx.id().toString() + "_"	+ forwarderVtx.value("resource-version").toString();
				dmaapMsgList.add(dmaapMsg);
				
//				Introspector forwarderIntrospector = serializer.getLatestVersionView(forwarderVtx);
//				this.notificationHelper.addEvent(forwarderVtx, forwarderIntrospector, EventAction.CREATE, this.serializer
//						.getURIForVertex(forwarderVtx, false));
//				logger.info("\t Dmaap event sent for " + forwarderVtx + " for port ["+intfVertex.toString() + "] with sequence = [" + sequence + "] and role [" + role +"]" );
			}
		} catch (Exception e) {
			logger.info("\t ERROR: Failure to PUT forwarder for EVC [" + evcName + "]" );
		}
		return forwarderVtx;
	}
	
	private Integer getSequenceFromPathMapPort(String port) {
		String[] subStringList = port.split("_");
		String sequenceStr = subStringList[0]; //forwarder will be have this sequence
		if (sequenceStr != null && !sequenceStr.isEmpty()) {
			return Integer.parseInt(sequenceStr);
		} else {
			return null;
		}
		
	}

	private Vertex createConfigurationObject(String evcName, Vertex portVtx, String port, Vertex forwarderVtx) {
		Vertex configurationVtx = null;
		String configurationId = null;
		try {
			Introspector configuration = loader.introspectorFromName(CONFIGURATION_NODE_TYPE);
			
			configurationVtx = serializer.createNewVertex(configuration);
			String sequence = forwarderVtx.value("sequence").toString();
			configurationId = evcName + "-" + sequence;
			configuration.setValue("configuration-id", configurationId);
			configuration.setValue("configuration-type", "forwarder");
			configuration.setValue("configuration-sub-type", "forwarder");
			this.createCousinEdge(forwarderVtx, configurationVtx);
			serializer.serializeSingleVertex(configurationVtx, configuration, "migrations");
			
			logger.info("\t Created new configuration for forwarder " + configurationVtx + " with configuration-id= " + configurationVtx.value("configuration-id").toString() );
			
			String dmaapMsg = System.nanoTime() + "_" + configurationVtx.id().toString() + "_"	+ configurationVtx.value("resource-version").toString();
			dmaapMsgList.add(dmaapMsg);
//			Introspector introspector = serializer.getLatestVersionView(configurationVtx);
//			this.notificationHelper.addEvent(configurationVtx, introspector, EventAction.CREATE, this.serializer.getURIForVertex(configurationVtx, false));
//			logger.info("\t Dmaap event sent for " + configurationVtx + " with configuration-id = " + configurationVtx.value("configuration-id").toString() );
			
			return configurationVtx;
		} catch (Exception e) {
			logger.info("\t ERROR: Failure to PUT Configuration for forwarder [" + configurationId + "]" );
		}
		return configurationVtx;
	}

	private Vertex createForwarderEvcObject(Map<String, String> pathColValues, String forwarderRole, Vertex portVtx, String port, Vertex configurationVtx) {
		Vertex forwarderEvcVtx = null;
		String configurationId = null;
		try {
			Introspector forwarderEvc = loader.introspectorFromName(FORWARDER_EVC_NODE_TYPE);
			forwarderEvcVtx = serializer.createNewVertex(forwarderEvc);
			configurationId = configurationVtx.value(this.PROPERTY_CONFIGURATION_ID).toString();
			
			String collectorFacingCircuit = pathColValues.get("collectorFacingCircuit");
			String bearerFacingCircuit = pathColValues.get("bearerFacingCircuit");
			String collectorCvlan = pathColValues.get("collectorCvlan");
			String bearerCvlan = pathColValues.get("bearerCvlan");
			String collectorSvlan = pathColValues.get("collectorSvlan");
			String bearerSvlan = pathColValues.get("bearerSvlan");
			
			forwarderEvc.setValue("forwarder-evc-id", configurationId);
			
			//Don't set circuitid for forwarder-evc connected to configuration that's connected to intermediate forwarder.
			if ("ingress".equalsIgnoreCase(forwarderRole)){
				forwarderEvc.setValue("circuit-id", checkForNull(collectorFacingCircuit));
				if (collectorCvlan != null && !collectorCvlan.isEmpty()) {
					forwarderEvc.setValue("cvlan", collectorCvlan);
				}
				if (collectorSvlan != null && !collectorSvlan.isEmpty()) {
					forwarderEvc.setValue("svlan", collectorSvlan);
				}
			} else if ("egress".equalsIgnoreCase(forwarderRole)){
				forwarderEvc.setValue("circuit-id", bearerFacingCircuit);
				if (bearerCvlan != null && !bearerCvlan.isEmpty()) {
					forwarderEvc.setValue("cvlan", bearerCvlan);
				}
				if (bearerSvlan != null && !bearerSvlan.isEmpty()) {
					forwarderEvc.setValue("svlan", bearerSvlan);
				}
			} else {
				int lastIndex = configurationId.lastIndexOf("-");
				String sequenceStr = configurationId.substring(lastIndex);
				int i = Integer.parseInt(sequenceStr);
				if (i%2 == 0){
					forwarderEvc.setValue("cvlan", checkForNull(bearerCvlan));
					forwarderEvc.setValue("svlan", checkForNull(bearerSvlan));
				} else {
					forwarderEvc.setValue("cvlan", checkForNull(collectorCvlan));
					forwarderEvc.setValue("svlan", checkForNull(collectorSvlan));
				}
			}
			this.createTreeEdge(configurationVtx, forwarderEvcVtx);
			serializer.serializeSingleVertex(forwarderEvcVtx, forwarderEvc, "migrations");
			
			logger.info("\t Created new forwarder-evc as a child of configuration " + forwarderEvcVtx + " with forwarder-evc-id= " + forwarderEvcVtx.value("forwarder-evc-id").toString() );
			String dmaapMsg = System.nanoTime() + "_" + forwarderEvcVtx.id().toString() + "_"	+ forwarderEvcVtx.value("resource-version").toString();
			dmaapMsgList.add(dmaapMsg);
			
//			logger.info("\t Forwarder-evc: "+ this.asString(forwarderEvcVtx));
			
//			Introspector introspector = serializer.getLatestVersionView(forwarderEvcVtx);
//			this.notificationHelper.addEvent(forwarderEvcVtx, introspector, EventAction.CREATE, this.serializer.getURIForVertex(forwarderEvcVtx, false));
//			logger.info("\t Dmaap event sent for " + forwarderEvcVtx + " with forwarder-evc-id = " + forwarderEvcVtx.value("forwarder-evc-id").toString() );
		}  catch (Exception e) {
			logger.info("\t ERROR: Failure to PUT fowarder-evc for configuration [" + configurationId + "]" );
		}
		return forwarderEvcVtx;

	}

	private String getForwarderRole( String port) {
		String role = null;
		Integer seq = getSequenceFromPathMapPort(port);
		if (seq != null ) {
			int sequence = seq.intValue();
			if (sequence == 1){
				role = "ingress";
			} else if (sequence > 1 && port.indexOf(".") > 0) {
				role = "egress";
			} else {
				role = "intermediate";
			}
		}
		return role;
	}
	
	private String checkForNull(String s){
    	if (s!= null && !s.isEmpty()){
    		return s;
    	}
    	return null;
    }

    @Override
    public Status getStatus() {
        if (checkLog) {
            return Status.CHECK_LOGS;
        }
        else if (success) {
            return Status.SUCCESS;
        }
        else {
            return Status.FAILURE;
        }
    }

    @Override
	public void commit() {
		engine.commit();
		createDmaapFiles(dmaapMsgList);
	}
    
    @Override
    public Optional<String[]> getAffectedNodeTypes() {
        return Optional.of(new String[]{this.FORWARDING_PATH_NODE_TYPE});
    }

    @Override
    public String getMigrationName() {
        return "MigratePATHEvcInventory";
    }
}