diff options
author | Venkata Harish K Kajur <vk250x@att.com> | 2017-09-17 23:45:00 -0400 |
---|---|---|
committer | Venkata Harish K Kajur <vk250x@att.com> | 2017-09-17 23:46:16 -0400 |
commit | 109616a0d9728fb4042d4d4978603597672f5eee (patch) | |
tree | 1eea6c09fe5024ac1884d9cd42cdcf94df14b24c /aai-resources/src/main/java/org | |
parent | ad07a8ba9780e2ffdb16c77d6a2970db42b1a957 (diff) |
Fix update edge tags got broken in cleanup
Also add the license tag that didn't get added
Need to ensure new files need to have license
since the plugin to automatically add license got removed
Issue-ID: AAI-213
Change-Id: I85c1208c5800f624b23b24feadf66b2fe1833e6d
Signed-off-by: Venkata Harish K Kajur <vk250x@att.com>
Diffstat (limited to 'aai-resources/src/main/java/org')
-rw-r--r-- | aai-resources/src/main/java/org/openecomp/aai/dbgen/UpdateEdgeTags.java | 144 |
1 files changed, 29 insertions, 115 deletions
diff --git a/aai-resources/src/main/java/org/openecomp/aai/dbgen/UpdateEdgeTags.java b/aai-resources/src/main/java/org/openecomp/aai/dbgen/UpdateEdgeTags.java index abe2a10..c79abec 100644 --- a/aai-resources/src/main/java/org/openecomp/aai/dbgen/UpdateEdgeTags.java +++ b/aai-resources/src/main/java/org/openecomp/aai/dbgen/UpdateEdgeTags.java @@ -1,45 +1,18 @@ -/*- - * ============LICENSE_START======================================================= - * org.openecomp.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========================================================= - */ - package org.openecomp.aai.dbgen; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; -import java.util.UUID; - +import com.google.common.collect.Multimap; +import com.thinkaurelius.titan.core.TitanGraph; import org.apache.tinkerpop.gremlin.structure.Edge; import org.apache.tinkerpop.gremlin.structure.Graph; import org.apache.tinkerpop.gremlin.structure.Vertex; import org.openecomp.aai.dbmap.AAIGraph; -import org.openecomp.aai.dbmodel.DbEdgeRules; import org.openecomp.aai.exceptions.AAIException; import org.openecomp.aai.logging.ErrorLogHelper; import org.openecomp.aai.serialization.db.EdgeRule; import org.openecomp.aai.serialization.db.EdgeRules; import org.openecomp.aai.util.AAIConfig; -import com.thinkaurelius.titan.core.TitanGraph; - +import java.util.*; public class UpdateEdgeTags { @@ -62,33 +35,34 @@ public class UpdateEdgeTags { String edgeRuleKeyVal = args[0]; TitanGraph graph = null; + EdgeRules edgeRulesInstance = EdgeRules.getInstance(); + Multimap<String, EdgeRule> edgeRuleMultimap = edgeRulesInstance.getAllRules(); HashMap <String,Object> edgeRuleHash = new HashMap <String,Object>(); HashMap <String,Object> edgeRulesFullHash = new HashMap <String,Object>(); HashMap <String,Object> edgeRuleLabelToKeyHash = new HashMap <String,Object>(); ArrayList <String> labelMapsToMultipleKeys = new <String> ArrayList (); - int tagCount = DbEdgeRules.EdgeInfoMap.size(); // Loop through all the edge-rules make sure they look right and // collect info about which labels support duplicate ruleKeys. - Iterator<String> edgeRulesIterator = DbEdgeRules.EdgeRules.keySet().iterator(); + Iterator<String> edgeRulesIterator = edgeRuleMultimap.keySet().iterator(); + while( edgeRulesIterator.hasNext() ){ String ruleKey = edgeRulesIterator.next(); - Collection <String> edRuleColl = DbEdgeRules.EdgeRules.get(ruleKey); - Iterator <String> ruleItr = edRuleColl.iterator(); + Collection <EdgeRule> edRuleColl = edgeRuleMultimap.get(ruleKey); + Iterator <EdgeRule> ruleItr = edRuleColl.iterator(); if( ruleItr.hasNext() ){ // For now, we only look for one type of edge between two nodes. - String fullRuleString = ruleItr.next(); - edgeRulesFullHash.put(ruleKey,fullRuleString); - // An EdgeRule is comma-separated and the first item is the edgeLabel - String [] rules = fullRuleString.split(","); - //System.out.println( "rules.length = " + rules.length + ", tagCount = " + tagCount ); - if( rules.length != tagCount ){ - String detail = "Bad EdgeRule data (itemCount=" + rules.length + ") for key = [" + ruleKey + "]."; - System.out.println(detail); - System.exit(0); - } - String edgeLabel = rules[0]; + EdgeRule edgeRule = ruleItr.next(); + String edgeRuleString = String.format("%s,%s,%s,%s,%s,%s", + edgeRule.getLabel(), + edgeRule.getDirection(), + edgeRule.getMultiplicityRule(), + edgeRule.getContains(), + edgeRule.getDeleteOtherV(), + edgeRule.getServiceInfrastructure()); + edgeRulesFullHash.put(ruleKey,edgeRuleString); + String edgeLabel = edgeRule.getLabel(); if( edgeRuleLabelToKeyHash.containsKey(edgeLabel) ){ // This label maps to more than one edge rule - we'll have to figure out // which rule applies when we look at each edge that uses this label. @@ -106,11 +80,11 @@ public class UpdateEdgeTags { if( ! edgeRuleKeyVal.equals( "all" ) ){ // If they passed in a (non-"all") argument, that is the single edgeRule that they want to update. // Note - the key looks like "nodeA|nodeB" as it appears in DbEdgeRules.EdgeRules - Collection <String> edRuleColl = DbEdgeRules.EdgeRules.get(edgeRuleKeyVal); - Iterator <String> ruleItr = edRuleColl.iterator(); + Collection <EdgeRule> edRuleColl = edgeRuleMultimap.get(edgeRuleKeyVal); + Iterator <EdgeRule> ruleItr = edRuleColl.iterator(); if( ruleItr.hasNext() ){ // For now, we only look for one type of edge between two nodes (Ie. for one key). - String edRule = ruleItr.next(); + EdgeRule edRule = ruleItr.next(); edgeRuleHash.put(edgeRuleKeyVal, edRule); System.out.println("Adding this rule to list of rules to do: key = " + edgeRuleKeyVal + ", rule = [" + edRule + "]"); } @@ -150,6 +124,7 @@ public class UpdateEdgeTags { System.exit(0); } + Graph g = graph.newTransaction(); try { Iterator<Edge> edgeItr = graph.traversal().E(); @@ -166,7 +141,7 @@ public class UpdateEdgeTags { String derivedEdgeKey = ""; if( labelMapsToMultipleKeys.contains(edLab) ){ // need to figure out which key is right for this edge - derivedEdgeKey = deriveEdgeRuleKeyForThisEdge( TRANSID, FROMAPPID, graph, tmpEd ); + derivedEdgeKey = deriveEdgeRuleKeyForThisEdge( TRANSID, FROMAPPID, g, tmpEd ); } else { // This kind of label only maps to one key -- so we can just look it up. @@ -254,7 +229,7 @@ public class UpdateEdgeTags { * @throws AAIException the AAI exception */ public static String deriveEdgeRuleKeyForThisEdge( String transId, String fromAppId, Graph graph, - Edge tEdge ) throws AAIException{ + Edge tEdge ) throws AAIException { Vertex fromVtx = tEdge.outVertex(); Vertex toVtx = tEdge.inVertex(); @@ -272,74 +247,13 @@ public class UpdateEdgeTags { } else { // Couldn't find a rule for this edge - throw new AAIException("AAI_6120", "No EdgeRule found for passed nodeTypes: " + startNodeType + ", " + throw new AAIException("AAI_6120", "No EdgeRule found for passed nodeTypes: " + startNodeType + ", " + targetNodeType); } } }// end of deriveEdgeRuleKeyForThisEdge() - /** - * Gets the edge tag prop put hash 4 rule. - * - * @param transId the trans id - * @param fromAppId the from app id - * @param edRule the ed rule - * @return the edge tag prop put hash 4 rule - * @throws AAIException the AAI exception - */ - public static HashMap <String,Object> getEdgeTagPropPutHash4Rule( String transId, String fromAppId, String edRule ) - throws AAIException{ - // For a given edgeRule - already pulled out of DbEdgeRules.EdgeRules -- parse out the "tags" that - // need to be set for this kind of edge. - // These are the Boolean properties like, "isParent", "usesResource" etc. - HashMap <String,Object> retEdgePropPutMap = new HashMap <String,Object>(); - - if( (edRule == null) || edRule.equals("") ){ - // No edge rule found for this - throw new AAIException("AAI_6120", "blank edRule passed to getEdgeTagPropPutHash4Rule()"); - } - - int tagCount = DbEdgeRules.EdgeInfoMap.size(); - String [] rules = edRule.split(","); - if( rules.length != tagCount ){ - throw new AAIException("AAI_6121", "Bad EdgeRule data (itemCount =" + rules.length + ") for rule = [" + edRule + "]."); - } - - // In DbEdgeRules.EdgeRules -- What we have as "edRule" is a comma-delimited set of strings. - // The first item is the edgeLabel. - // The second in the list is always "direction" which is always OUT for the way we've implemented it. - // Items starting at "firstTagIndex" and up are all assumed to be booleans that map according to - // tags as defined in EdgeInfoMap. - // Note - if they are tagged as 'reverse', that means they get the tag name with "-REV" on it - for( int i = DbEdgeRules.firstTagIndex; i < tagCount; i++ ){ - String booleanStr = rules[i]; - Integer mapKey = new Integer(i); - String propName = DbEdgeRules.EdgeInfoMap.get(mapKey); - String revPropName = propName + "-REV"; - - if( booleanStr.equals("true") ){ - retEdgePropPutMap.put(propName, true); - retEdgePropPutMap.put(revPropName,false); - } - else if( booleanStr.equals("false") ){ - retEdgePropPutMap.put(propName, false); - retEdgePropPutMap.put(revPropName,false); - } - else if( booleanStr.equals("reverse") ){ - retEdgePropPutMap.put(propName, false); - retEdgePropPutMap.put(revPropName,true); - } - else { - throw new AAIException("AAI_6121", "Bad EdgeRule data for rule = [" + edRule + "], val = [" + booleanStr + "]."); - } - - } - return retEdgePropPutMap; - - } // End of getEdgeTagPropPutHash() - - /** * Gets the edge tag prop put hash. * @@ -349,8 +263,8 @@ public class UpdateEdgeTags { * @return the edge tag prop put hash * @throws AAIException the AAI exception */ - public static Map<String, EdgeRule> getEdgeTagPropPutHash( String transId, String fromAppId, String edgeRuleKey ) - throws AAIException{ + public static Map<String, EdgeRule> getEdgeTagPropPutHash(String transId, String fromAppId, String edgeRuleKey ) + throws AAIException { // For a given edgeRuleKey (nodeTypeA|nodeTypeB), look up the rule that goes with it in // DbEdgeRules.EdgeRules and parse out the "tags" that need to be set on each edge. // These are the Boolean properties like, "isParent", "usesResource" etc. @@ -359,7 +273,7 @@ public class UpdateEdgeTags { String[] edgeRuleKeys = edgeRuleKey.split("\\|"); if (edgeRuleKeys.length < 2 || ! EdgeRules.getInstance().hasEdgeRule(edgeRuleKeys[0], edgeRuleKeys[1])) { - throw new AAIException("AAI_6120", "Could not find an DbEdgeRule entry for passed edgeRuleKey (nodeTypeA|nodeTypeB): " + edgeRuleKey + "."); + throw new AAIException("AAI_6120", "Could not find an DbEdgeRule entry for passed edgeRuleKey (nodeTypeA|nodeTypeB): " + edgeRuleKey + "."); } Map<String, EdgeRule> edgeRules = EdgeRules.getInstance().getEdgeRules(edgeRuleKeys[0], edgeRuleKeys[1]); |