cc35a3de2362f759b8cf790e874a2023364eb063
[aai/resources.git] /
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *    http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20 package org.onap.aai.migration.v12;
21
22 import java.util.Optional;
23
24 import org.apache.commons.lang.exception.ExceptionUtils;
25 import org.apache.tinkerpop.gremlin.structure.Edge;
26 import org.onap.aai.migration.MigrationDangerRating;
27 import org.onap.aai.migration.Enabled;
28 import org.onap.aai.migration.MigrationPriority;
29 import org.onap.aai.migration.Migrator;
30 import org.onap.aai.migration.Status;
31 import org.onap.aai.serialization.db.AAIDirection;
32 import org.onap.aai.serialization.db.EdgeProperty;
33 import org.onap.aai.serialization.engines.TransactionalGraphEngine;
34
35
36
37 @Enabled
38 @MigrationPriority(-100)
39 @MigrationDangerRating(10)
40 public class ContainmentDeleteOtherVPropertyMigration extends Migrator {
41
42         private boolean success = true;
43         
44         public ContainmentDeleteOtherVPropertyMigration(TransactionalGraphEngine engine) {
45                 super(engine);
46         }
47         
48         //just for testing using test edge rule files
49         public ContainmentDeleteOtherVPropertyMigration(TransactionalGraphEngine engine, String edgeRulesFile) {
50                 super(engine);
51         }
52         
53         @Override
54         public void run() {
55                 try {
56                         engine.asAdmin().getTraversalSource().E().sideEffect(t -> {
57                                 Edge e = t.get();
58                                 logger.info("out vertex: " + e.outVertex().property("aai-node-type").value() + 
59                                                                 " in vertex: " + e.inVertex().property("aai-node-type").value() +
60                                                                 " label : " + e.label());
61                                 if (e.property(EdgeProperty.CONTAINS.toString()).isPresent() &&
62                                                 e.property(EdgeProperty.DELETE_OTHER_V.toString()).isPresent()) {
63                                         //in case of orphans
64                                         if (!("constrained-element-set".equals(e.inVertex().property("aai-node-type").value())
65                                                         && "model-element".equals(e.outVertex().property("aai-node-type").value()))) {
66                                                 //skip the weird horrible problem child edge
67                                                 String containment = (String) e.property(EdgeProperty.CONTAINS.toString()).value();
68                                                 if (AAIDirection.OUT.toString().equalsIgnoreCase(containment) ||
69                                                                 AAIDirection.IN.toString().equalsIgnoreCase(containment) ||
70                                                                 AAIDirection.BOTH.toString().equalsIgnoreCase(containment)) {
71                                                         logger.info("updating delete-other-v property");
72                                                         e.property(EdgeProperty.DELETE_OTHER_V.toString(), containment);
73                                                 }
74                                         }
75                                 }
76                         }).iterate();
77                 } catch (Exception e) {
78                         logger.info("error encountered " + e.getClass() + " " + e.getMessage() + " " + ExceptionUtils.getFullStackTrace(e));
79                         logger.error("error encountered " + e.getClass() + " " + e.getMessage() + " " + ExceptionUtils.getFullStackTrace(e));
80                         success = false;
81                 }
82                 
83         }
84
85         @Override
86         public Status getStatus() {
87                 if (success) {
88                         return Status.SUCCESS;
89                 } else {
90                         return Status.FAILURE;
91                 }
92         }
93
94         @Override
95         public Optional<String[]> getAffectedNodeTypes() {
96                 return Optional.empty();
97         }
98
99         @Override
100         public String getMigrationName() {
101                 return "migrate-containment-delete-other-v";
102         }
103
104 }