2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.aai.migration.v12;
23 import java.util.Optional;
25 import org.apache.commons.lang.exception.ExceptionUtils;
26 import org.apache.tinkerpop.gremlin.structure.Edge;
27 import org.onap.aai.migration.MigrationDangerRating;
28 import org.onap.aai.migration.Enabled;
29 import org.onap.aai.migration.MigrationPriority;
30 import org.onap.aai.migration.Migrator;
31 import org.onap.aai.migration.Status;
32 import org.onap.aai.serialization.db.AAIDirection;
33 import org.onap.aai.serialization.db.EdgeProperty;
34 import org.onap.aai.serialization.engines.TransactionalGraphEngine;
39 @MigrationPriority(-100)
40 @MigrationDangerRating(10)
41 public class ContainmentDeleteOtherVPropertyMigration extends Migrator {
43 private boolean success = true;
45 public ContainmentDeleteOtherVPropertyMigration(TransactionalGraphEngine engine) {
49 //just for testing using test edge rule files
50 public ContainmentDeleteOtherVPropertyMigration(TransactionalGraphEngine engine, String edgeRulesFile) {
57 engine.asAdmin().getTraversalSource().E().sideEffect(t -> {
59 logger.info("out vertex: " + e.outVertex().property("aai-node-type").value() +
60 " in vertex: " + e.inVertex().property("aai-node-type").value() +
61 " label : " + e.label());
62 if (e.property(EdgeProperty.CONTAINS.toString()).isPresent() &&
63 e.property(EdgeProperty.DELETE_OTHER_V.toString()).isPresent()) {
65 if (!("constrained-element-set".equals(e.inVertex().property("aai-node-type").value())
66 && "model-element".equals(e.outVertex().property("aai-node-type").value()))) {
67 //skip the weird horrible problem child edge
68 String containment = (String) e.property(EdgeProperty.CONTAINS.toString()).value();
69 if (AAIDirection.OUT.toString().equalsIgnoreCase(containment) ||
70 AAIDirection.IN.toString().equalsIgnoreCase(containment) ||
71 AAIDirection.BOTH.toString().equalsIgnoreCase(containment)) {
72 logger.info("updating delete-other-v property");
73 e.property(EdgeProperty.DELETE_OTHER_V.toString(), containment);
78 } catch (Exception e) {
79 logger.info("error encountered " + e.getClass() + " " + e.getMessage() + " " + ExceptionUtils.getFullStackTrace(e));
80 logger.error("error encountered " + e.getClass() + " " + e.getMessage() + " " + ExceptionUtils.getFullStackTrace(e));
87 public Status getStatus() {
89 return Status.SUCCESS;
91 return Status.FAILURE;
96 public Optional<String[]> getAffectedNodeTypes() {
97 return Optional.empty();
101 public String getMigrationName() {
102 return "migrate-containment-delete-other-v";