From 16ea5afacc6140573ff431bf5622a6c8cc07925b Mon Sep 17 00:00:00 2001 From: Venkata Harish K Kajur Date: Wed, 24 May 2017 14:06:58 -0400 Subject: Pull the latest code resources internal Remove the test that should not be in resources Change-Id: Ic20fe3942bae3ec217933284d2b176bb8079788e Signed-off-by: Venkata Harish K Kajur --- aai-resources/.gitignore | 1 - aai-resources/ajsc-shared-config/etc/logback.xml | 8 +- .../etc/appprops/aaiconfig.properties | 9 +- .../etc/appprops/createDBSchema-logback.xml | 4 +- .../etc/appprops/dataGrooming-logback.xml | 4 +- .../etc/appprops/dataSnapshot-logback.xml | 4 +- .../etc/appprops/deltool-logback.xml | 4 +- .../etc/appprops/error.properties | 4 +- .../etc/appprops/getres-logback.xml | 4 +- .../etc/appprops/posttool-logback.xml | 4 +- .../etc/appprops/prov-logback.xml | 4 +- .../etc/appprops/pullInvData-logback.xml | 4 +- .../etc/appprops/puttool-logback.xml | 4 +- .../etc/appprops/rshiptool-logback.xml | 4 +- .../etc/appprops/updtool-logback.xml | 4 +- .../etc/sysprops/sys-props.properties | 2 +- .../aai/dbgen/AddResourceVersionProp.java | 126 + .../aai/dbgen/ChangePropertyCardinality.java | 307 ++ .../java/org/openecomp/aai/dbgen/DataSnapshot.java | 2 +- .../org/openecomp/aai/dbgen/ForceDeleteTool.java | 722 +++ .../org/openecomp/aai/dbgen/GraphMLReaderNew.java | 353 ++ .../org/openecomp/aai/dbgen/GraphMLTokens.java | 57 + .../org/openecomp/aai/dbgen/GraphMLWriterNew.java | 358 ++ .../openecomp/aai/dbgen/PropertyNameChange.java | 317 ++ .../java/org/openecomp/aai/dbgen/SchemaMod.java | 441 ++ .../org/openecomp/aai/dbgen/UpdateEdgeTags.java | 380 ++ .../aai/dmaap/AAIDmaapEventJMSConsumer.java | 2 +- .../org/openecomp/aai/migration/EventAction.java | 27 + .../aai/migration/NotificationHelper.java | 103 + .../org/openecomp/aai/migration/VertexMerge.java | 245 + .../org/openecomp/aai/rest/LegacyMoxyConsumer.java | 17 +- .../java/org/openecomp/aai/rest/RestTokens.java | 36 + .../org/openecomp/aai/rest/retired/V7V8Models.java | 28 + .../aai/rest/retired/V7V8NamedQueries.java | 28 + .../openecomp/aai/rest/ueb/NotificationEvent.java | 15 +- .../openecomp/aai/rest/ueb/UEBNotification.java | 10 +- .../openecomp/aai/util/DataConversionHelper.java | 63 + .../org/openecomp/aai/util/DeleteResource.java | 22 +- .../java/org/openecomp/aai/util/GetResource.java | 30 +- .../org/openecomp/aai/util/HttpsAuthClient.java | 58 + .../JettyObfuscationConversionCommandLineUtil.java | 99 + .../java/org/openecomp/aai/util/PostResource.java | 27 +- .../java/org/openecomp/aai/util/PutResource.java | 84 +- .../org/openecomp/aai/util/RelationshipPutDel.java | 211 + .../openecomp/aai/util/StoreNotificationEvent.java | 102 +- .../org/openecomp/aai/util/UpdateResource.java | 18 +- .../src/main/scripts/PropertyChangeName.sh | 83 + .../src/main/scripts/addResourceVersionProperty.sh | 55 + .../src/main/scripts/changePropertyCardinality.sh | 88 + aai-resources/src/main/scripts/createDBSchema.sh | 1 + aai-resources/src/main/scripts/deleteTool.sh | 1 + aai-resources/src/main/scripts/deobfuscatePW.sh | 1 + aai-resources/src/main/scripts/edgeTagger.sh | 1 + aai-resources/src/main/scripts/getTool.sh | 1 + aai-resources/src/main/scripts/notifyTool.sh | 1 + aai-resources/src/main/scripts/postTool.sh | 1 + aai-resources/src/main/scripts/putTool.sh | 1 + aai-resources/src/main/scripts/rshipTool.sh | 1 + .../src/main/scripts/run_DbTestProcessBuilder.sh | 54 + aai-resources/src/main/scripts/run_FixXSD.sh | 68 + aai-resources/src/main/scripts/schemaMod.sh | 1 + .../src/main/scripts/uniquePropertyCheck.sh | 60 + aai-resources/src/main/scripts/updateTool.sh | 1 + .../java/org/openecomp/aai/dbgen/DbMethTest.java | 90 + .../java/org/openecomp/aai/dbgen/DbRunTest.java | 341 ++ .../openecomp/aai/migration/VertexMergeTest.java | 190 + .../aai/query/builder/TraversalQueryTest.java | 105 - .../org/openecomp/aai/schema/db/AuditOXMTest.java | 2 +- .../openecomp/aai/schema/db/ManageSchemaTest.java | 2 +- .../java/org/openecomp/aai/util/AAITxnLogTest.java | 361 ++ .../aai/util/DataConversionHelperTest.java | 88 + .../org/openecomp/aai/util/DeleteResourceTest.java | 108 + ...tyObfuscationConversionCommandLineUtilTest.java | 71 + .../etc/appprops/aaiconfig.properties | 12 +- .../etc/appprops/error.properties | 1 + .../com/att/aai/introspection/aai_oxm_v10.xml | 9 +- .../com/att/aai/introspection/aai_oxm_v9.xml | 5659 +++++++++++++++++++- 77 files changed, 11300 insertions(+), 514 deletions(-) create mode 100644 aai-resources/src/main/java/org/openecomp/aai/dbgen/AddResourceVersionProp.java create mode 100644 aai-resources/src/main/java/org/openecomp/aai/dbgen/ChangePropertyCardinality.java create mode 100644 aai-resources/src/main/java/org/openecomp/aai/dbgen/ForceDeleteTool.java create mode 100644 aai-resources/src/main/java/org/openecomp/aai/dbgen/GraphMLReaderNew.java create mode 100644 aai-resources/src/main/java/org/openecomp/aai/dbgen/GraphMLTokens.java create mode 100644 aai-resources/src/main/java/org/openecomp/aai/dbgen/GraphMLWriterNew.java create mode 100644 aai-resources/src/main/java/org/openecomp/aai/dbgen/PropertyNameChange.java create mode 100644 aai-resources/src/main/java/org/openecomp/aai/dbgen/SchemaMod.java create mode 100644 aai-resources/src/main/java/org/openecomp/aai/dbgen/UpdateEdgeTags.java create mode 100644 aai-resources/src/main/java/org/openecomp/aai/migration/EventAction.java create mode 100644 aai-resources/src/main/java/org/openecomp/aai/migration/NotificationHelper.java create mode 100644 aai-resources/src/main/java/org/openecomp/aai/migration/VertexMerge.java create mode 100644 aai-resources/src/main/java/org/openecomp/aai/rest/RestTokens.java create mode 100644 aai-resources/src/main/java/org/openecomp/aai/rest/retired/V7V8Models.java create mode 100644 aai-resources/src/main/java/org/openecomp/aai/rest/retired/V7V8NamedQueries.java create mode 100644 aai-resources/src/main/java/org/openecomp/aai/util/DataConversionHelper.java create mode 100644 aai-resources/src/main/java/org/openecomp/aai/util/JettyObfuscationConversionCommandLineUtil.java create mode 100644 aai-resources/src/main/java/org/openecomp/aai/util/RelationshipPutDel.java create mode 100644 aai-resources/src/main/scripts/PropertyChangeName.sh create mode 100644 aai-resources/src/main/scripts/addResourceVersionProperty.sh create mode 100644 aai-resources/src/main/scripts/changePropertyCardinality.sh create mode 100644 aai-resources/src/main/scripts/run_DbTestProcessBuilder.sh create mode 100644 aai-resources/src/main/scripts/run_FixXSD.sh create mode 100644 aai-resources/src/main/scripts/uniquePropertyCheck.sh create mode 100644 aai-resources/src/test/java/org/openecomp/aai/dbgen/DbMethTest.java create mode 100644 aai-resources/src/test/java/org/openecomp/aai/dbgen/DbRunTest.java create mode 100644 aai-resources/src/test/java/org/openecomp/aai/migration/VertexMergeTest.java delete mode 100644 aai-resources/src/test/java/org/openecomp/aai/query/builder/TraversalQueryTest.java create mode 100644 aai-resources/src/test/java/org/openecomp/aai/util/AAITxnLogTest.java create mode 100644 aai-resources/src/test/java/org/openecomp/aai/util/DataConversionHelperTest.java create mode 100644 aai-resources/src/test/java/org/openecomp/aai/util/DeleteResourceTest.java create mode 100644 aai-resources/src/test/java/org/openecomp/aai/util/JettyObfuscationConversionCommandLineUtilTest.java (limited to 'aai-resources') diff --git a/aai-resources/.gitignore b/aai-resources/.gitignore index cd21128..4a3cb42 100644 --- a/aai-resources/.gitignore +++ b/aai-resources/.gitignore @@ -1,7 +1,6 @@ .settings target/ **/logs/ -bundleconfig-local/etc/auth/aai-client-cert.p12 bundleconfig-local/etc/oxm src/main/aai_schema bundleconfig-local/etc/logback.xml diff --git a/aai-resources/ajsc-shared-config/etc/logback.xml b/aai-resources/ajsc-shared-config/etc/logback.xml index 4c4e774..3775b95 100644 --- a/aai-resources/ajsc-shared-config/etc/logback.xml +++ b/aai-resources/ajsc-shared-config/etc/logback.xml @@ -2,9 +2,9 @@ ${module.ajsc.namespace.name} - - - + + + @@ -186,7 +186,7 @@ - ${eelfLogPattern} + ${eelfMetricLogPattern} diff --git a/aai-resources/bundleconfig-local/etc/appprops/aaiconfig.properties b/aai-resources/bundleconfig-local/etc/appprops/aaiconfig.properties index ad651d2..be3a6f2 100644 --- a/aai-resources/bundleconfig-local/etc/appprops/aaiconfig.properties +++ b/aai-resources/bundleconfig-local/etc/appprops/aaiconfig.properties @@ -29,9 +29,9 @@ ecm.openstack.tenantid=b0a529aba48440a39e0caf1aea9b27e3 aai.avpn.interim.laginterface=ae0 -aai.server.url.base=https://localhost:8447/aai/ -aai.server.url=https://localhost:8447/aai/v10/ -aai.global.callback.url=https://localhost:8447/aai/ +aai.server.url.base=https://localhost:8443/aai/ +aai.server.url=https://localhost:8443/aai/v10/ +aai.global.callback.url=https://localhost:8443/aai/ aai.auth.cspcookies_on=false aai.dbmodel.filename=ex5.json @@ -60,7 +60,7 @@ aai.precheck.cloudinfrastructure.complex.defaults.region=US # single primary server aai.primary.filetransfer.serverlist=ONAPserverTBD -aai.primary.filetransfer.primarycheck=echo:8447/aai/util/echo +aai.primary.filetransfer.primarycheck=echo:8443/aai/util/echo aai.primary.filetransfer.pingtimeout=5000 aai.primary.filetransfer.pingcount=5 @@ -124,3 +124,4 @@ aai.server.rebind=g # This is a fake one just for test so please ignore ecm.auth.password.x=OBF:1igd1i9a1jnb1yte1vv11vu91yt81jk71i6o1idt +aai.run.migrations=false diff --git a/aai-resources/bundleconfig-local/etc/appprops/createDBSchema-logback.xml b/aai-resources/bundleconfig-local/etc/appprops/createDBSchema-logback.xml index 937324e..41cfb4f 100644 --- a/aai-resources/bundleconfig-local/etc/appprops/createDBSchema-logback.xml +++ b/aai-resources/bundleconfig-local/etc/appprops/createDBSchema-logback.xml @@ -1,7 +1,7 @@ - - + + diff --git a/aai-resources/bundleconfig-local/etc/appprops/dataGrooming-logback.xml b/aai-resources/bundleconfig-local/etc/appprops/dataGrooming-logback.xml index 966ec4c..072c6f2 100644 --- a/aai-resources/bundleconfig-local/etc/appprops/dataGrooming-logback.xml +++ b/aai-resources/bundleconfig-local/etc/appprops/dataGrooming-logback.xml @@ -1,7 +1,7 @@ - - + + diff --git a/aai-resources/bundleconfig-local/etc/appprops/dataSnapshot-logback.xml b/aai-resources/bundleconfig-local/etc/appprops/dataSnapshot-logback.xml index 40e729a..58cf01d 100644 --- a/aai-resources/bundleconfig-local/etc/appprops/dataSnapshot-logback.xml +++ b/aai-resources/bundleconfig-local/etc/appprops/dataSnapshot-logback.xml @@ -1,7 +1,7 @@ - - + + diff --git a/aai-resources/bundleconfig-local/etc/appprops/deltool-logback.xml b/aai-resources/bundleconfig-local/etc/appprops/deltool-logback.xml index 8a138c6..6a70d4a 100644 --- a/aai-resources/bundleconfig-local/etc/appprops/deltool-logback.xml +++ b/aai-resources/bundleconfig-local/etc/appprops/deltool-logback.xml @@ -1,7 +1,7 @@ - - + + diff --git a/aai-resources/bundleconfig-local/etc/appprops/error.properties b/aai-resources/bundleconfig-local/etc/appprops/error.properties index 4e98d62..3baf55c 100644 --- a/aai-resources/bundleconfig-local/etc/appprops/error.properties +++ b/aai-resources/bundleconfig-local/etc/appprops/error.properties @@ -27,6 +27,7 @@ AAI_3006=5:6:WARN:3006:404:3001:Node cannot be directly accessed for write, must AAI_3007=5:6:INFO:3007:410:3007:This version (%1) of the API is retired, please migrate to %2 AAI_3008=5:6:ERROR:3008:400:3008:URI is not encoded in UTF-8 AAI_3009=5:6:ERROR:3009:400:3002:Malformed URL +AAI_3010=5:6:ERROR:3010:400:3002:Cannot write via this URL # pol errors AAI_3100=5:1:WARN:3100:400:3100:Unsupported operation %1 AAI_3101=5:1:WARN:3101:403:3101:Attempt by client %1 to execute API %2 @@ -110,6 +111,7 @@ AAI_6142=5:4:INFO:6142:400:3000:Retrying transaction AAI_6143=5:4:INFO:6143:400:3000:Ghost vertex found AAI_6144=5:4:WARN:6144:400:3000:Cycle found in graph AAI_6145=5:4:ERROR:6145:400:3000:Cannot create a nested/containment edge via relationship +AAI_6146=5:4:ERROR:6146:400:3000:Ambiguous identity map found, use a URI instead #--- aaicsvp: 7101-7199 AAI_7101=5:4:ERROR:7101:500:3002:Unexpected error in CSV file processing @@ -160,4 +162,4 @@ AAI_9107=5:0:WARN:9107:403:3300:SSL is not provided in request, please contact a #--- aaiinstar: 9201-9299 AAI_9201=5:4:ERROR:9201:500:3002:Unable to send notification -AAI_9202=5:4:ERROR:9202:500:3002:Unable to start a thread +AAI_9202=5:4:ERROR:9202:500:3002:Unable to start a thread \ No newline at end of file diff --git a/aai-resources/bundleconfig-local/etc/appprops/getres-logback.xml b/aai-resources/bundleconfig-local/etc/appprops/getres-logback.xml index 3f05c17..3b14ca2 100644 --- a/aai-resources/bundleconfig-local/etc/appprops/getres-logback.xml +++ b/aai-resources/bundleconfig-local/etc/appprops/getres-logback.xml @@ -1,7 +1,7 @@ - - + + diff --git a/aai-resources/bundleconfig-local/etc/appprops/posttool-logback.xml b/aai-resources/bundleconfig-local/etc/appprops/posttool-logback.xml index 5ba965f..a03713b 100644 --- a/aai-resources/bundleconfig-local/etc/appprops/posttool-logback.xml +++ b/aai-resources/bundleconfig-local/etc/appprops/posttool-logback.xml @@ -1,7 +1,7 @@ - - + + diff --git a/aai-resources/bundleconfig-local/etc/appprops/prov-logback.xml b/aai-resources/bundleconfig-local/etc/appprops/prov-logback.xml index 6a280ad..3f0a7da 100644 --- a/aai-resources/bundleconfig-local/etc/appprops/prov-logback.xml +++ b/aai-resources/bundleconfig-local/etc/appprops/prov-logback.xml @@ -1,7 +1,7 @@ - - + + diff --git a/aai-resources/bundleconfig-local/etc/appprops/pullInvData-logback.xml b/aai-resources/bundleconfig-local/etc/appprops/pullInvData-logback.xml index 3cab017..6691b91 100644 --- a/aai-resources/bundleconfig-local/etc/appprops/pullInvData-logback.xml +++ b/aai-resources/bundleconfig-local/etc/appprops/pullInvData-logback.xml @@ -1,7 +1,7 @@ - - + + diff --git a/aai-resources/bundleconfig-local/etc/appprops/puttool-logback.xml b/aai-resources/bundleconfig-local/etc/appprops/puttool-logback.xml index 45fafee..8c74ae5 100644 --- a/aai-resources/bundleconfig-local/etc/appprops/puttool-logback.xml +++ b/aai-resources/bundleconfig-local/etc/appprops/puttool-logback.xml @@ -1,7 +1,7 @@ - - + + diff --git a/aai-resources/bundleconfig-local/etc/appprops/rshiptool-logback.xml b/aai-resources/bundleconfig-local/etc/appprops/rshiptool-logback.xml index a10ffd1..4fe87ca 100644 --- a/aai-resources/bundleconfig-local/etc/appprops/rshiptool-logback.xml +++ b/aai-resources/bundleconfig-local/etc/appprops/rshiptool-logback.xml @@ -1,7 +1,7 @@ - - + + diff --git a/aai-resources/bundleconfig-local/etc/appprops/updtool-logback.xml b/aai-resources/bundleconfig-local/etc/appprops/updtool-logback.xml index ef6a9b2..2dd9f11 100644 --- a/aai-resources/bundleconfig-local/etc/appprops/updtool-logback.xml +++ b/aai-resources/bundleconfig-local/etc/appprops/updtool-logback.xml @@ -1,7 +1,7 @@ - - + + diff --git a/aai-resources/bundleconfig-local/etc/sysprops/sys-props.properties b/aai-resources/bundleconfig-local/etc/sysprops/sys-props.properties index 8ae26b7..5365f47 100644 --- a/aai-resources/bundleconfig-local/etc/sysprops/sys-props.properties +++ b/aai-resources/bundleconfig-local/etc/sysprops/sys-props.properties @@ -1,6 +1,6 @@ #This file is used for defining AJSC system properties for different configuration schemes and is necessary for the AJSC to run properly. #The sys-props.properties file is used for running locally. The template.sys-props.properties file will be used when deployed -#to a SOA/CSI Cloud node. +#to a SOA/CSI Cloud node. #AJSC System Properties. The following properties are required for ALL AJSC services. If you are adding System Properties for your #particular service, please add them AFTER all AJSC related System Properties. diff --git a/aai-resources/src/main/java/org/openecomp/aai/dbgen/AddResourceVersionProp.java b/aai-resources/src/main/java/org/openecomp/aai/dbgen/AddResourceVersionProp.java new file mode 100644 index 0000000..15c9b1e --- /dev/null +++ b/aai-resources/src/main/java/org/openecomp/aai/dbgen/AddResourceVersionProp.java @@ -0,0 +1,126 @@ +/*- + * ============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.Iterator; +import java.util.Properties; + +import org.openecomp.aai.dbmap.AAIGraph; +import org.openecomp.aai.exceptions.AAIException; +import org.openecomp.aai.logging.ErrorLogHelper; +import org.openecomp.aai.util.AAIConfig; +import org.openecomp.aai.util.AAIConstants; +import com.att.eelf.configuration.Configuration; +import com.thinkaurelius.titan.core.TitanGraph; +import com.thinkaurelius.titan.core.TitanVertex; +import org.apache.tinkerpop.gremlin.structure.Vertex; + + +public class AddResourceVersionProp { + + + /** + * The main method. + * + * @param args the arguments + */ + public static void main(String[] args) { + + // Set the logging file properties to be used by EELFManager + Properties props = System.getProperties(); + props.setProperty(Configuration.PROPERTY_LOGGING_FILE_NAME, AAIConstants.AAI_SCHEMA_MOD_LOGBACK_PROPS); + props.setProperty(Configuration.PROPERTY_LOGGING_FILE_PATH, AAIConstants.AAI_HOME_ETC_APP_PROPERTIES); + + // NOTE -- This is a one-time migration for adding the new property "resource-version" to ALL of our nodes. + // Also -- since it's a one-time thing, we just re-use AAI_SCHEMA_MOD_LOG4J_PROPS + + TitanGraph graph = null; + + System.out.println(">>> WARNING: this script affects all nodes in the database. <<<< " ); + System.out.println(">>> Processing will begin in 5 seconds (unless interrupted). <<<"); + try { + // Give them a chance to back out of this + Thread.sleep(5000); + } catch ( java.lang.InterruptedException ie) { + System.out.println( " AddResourceVersionProp script has been aborted. "); + System.exit(1); + } + + try { + AAIConfig.init(); + ErrorLogHelper.loadProperties(); + + System.out.println(" ---- NOTE --- about to open graph (takes a little while)\n"); + + graph = AAIGraph.getInstance().getGraph(); + if( graph == null ){ + String emsg = "Not able to get a graph object in AddResourceVersionProp.java\n"; + System.out.println( emsg ); + System.exit(1); + } + + + // For each node in the db -- update the "resource-version" and the last mod timestamp. + Iterable verts = null; + verts= graph.query().vertices(); + Iterator it = verts.iterator(); + int vtxCount = 0; + long unixTimeNow = System.currentTimeMillis() / 1000L; + String timeNowInSec = "" + unixTimeNow; + + while( it.hasNext() ){ + vtxCount++; + TitanVertex tmpVtx = (TitanVertex)it.next(); + tmpVtx.property( "aai-last-mod-ts", timeNowInSec ); + tmpVtx.property( "resource-version", timeNowInSec ); + } + + System.out.println("Updated data for " + vtxCount + " vertexes. Now call graph.tx().commit(). "); + graph.tx().commit(); + + } + catch (AAIException e) { + System.out.print("Threw a AAIException: \n"); + System.out.println(e.getErrorObject().toString()); + } + catch (Exception ex) { + System.out.print("Threw a regular Exception:\n"); + System.out.println(ex.getMessage()); + } + finally { + if( graph != null ){ + // Any changes that worked correctly should have already done their commits. + graph.tx().rollback(); + graph.close(); + } + + } + + + System.exit(0); + + }// End of main() + + +} + + diff --git a/aai-resources/src/main/java/org/openecomp/aai/dbgen/ChangePropertyCardinality.java b/aai-resources/src/main/java/org/openecomp/aai/dbgen/ChangePropertyCardinality.java new file mode 100644 index 0000000..f92cfbc --- /dev/null +++ b/aai-resources/src/main/java/org/openecomp/aai/dbgen/ChangePropertyCardinality.java @@ -0,0 +1,307 @@ +/*- + * ============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.text.SimpleDateFormat; +import java.util.Date; +import java.util.Iterator; +import java.util.Properties; +import java.util.TimeZone; + +import org.openecomp.aai.dbmap.AAIGraph; +import org.openecomp.aai.exceptions.AAIException; +import org.openecomp.aai.ingestModel.DbMaps; +import org.openecomp.aai.ingestModel.IngestModelMoxyOxm; +import org.openecomp.aai.logging.ErrorLogHelper; +import org.openecomp.aai.util.AAIConfig; +import org.openecomp.aai.util.AAIConstants; +import com.att.eelf.configuration.Configuration; +import com.thinkaurelius.titan.core.Cardinality; +import com.thinkaurelius.titan.core.PropertyKey; +import com.thinkaurelius.titan.core.TitanGraph; +import com.thinkaurelius.titan.core.TitanVertex; +import com.thinkaurelius.titan.core.schema.TitanManagement; +import org.apache.tinkerpop.gremlin.structure.Vertex; + + +public class ChangePropertyCardinality { + + + /** + * The main method. + * + * @param args the arguments + */ + public static void main(String[] args) { + + //public static void ChangePropertyCardinality( String[] args ) { + + // Set the logging file properties to be used by EELFManager + Properties props = System.getProperties(); + props.setProperty(Configuration.PROPERTY_LOGGING_FILE_NAME, AAIConstants.AAI_SCHEMA_MOD_LOGBACK_PROPS); + props.setProperty(Configuration.PROPERTY_LOGGING_FILE_PATH, AAIConstants.AAI_HOME_ETC_APP_PROPERTIES); + + // NOTE -- We're just working with properties that are used for NODES + String propName = ""; + String targetDataType = "String"; + String targetCardinality = "SET"; + String preserveDataFlag = "false"; + boolean preserveData = false; + + + String usageString = "Usage: ChangePropertyCardinality propertyName targetDataType targetCardinality preserveDataFlag \n"; + if( args.length != 4 ){ + String emsg = "Four Parameters are required. \n" + usageString; + System.out.println( emsg ); + System.exit(1); + } + else { + propName = args[0]; + targetDataType = args[1]; + targetCardinality = args[2]; + preserveDataFlag = args[3]; + } + + if( propName.equals("") ){ + String emsg = "Bad parameter - propertyName cannot be empty. \n" + usageString; + System.out.println( emsg ); + System.exit(1); + } + else if( !targetDataType.equals("String") ){ + // && !targetDataType.equals("Integer") + // && !targetDataType.equals("Long") + // && !targetDataType.equals("Boolean") ){ + // String emsg = "Unsupported targetDataType. We only support String, Integer, Long or Boolean for now.\n" + usageString; + String emsg = "Unsupported targetDataType. We only support String for now.\n" + usageString; + System.out.println( emsg ); + System.exit(1); + } + else if( !targetCardinality.equals("SET") ){ + // && !targetCardinality.equals("LIST") + // && !targetCardinality.equals("SINGLE") ){ + String emsg = "Unsupported targetCardinality. We only support SET for now.\n" + usageString; + System.out.println( emsg ); + System.exit(1); + } + else { + if( preserveDataFlag.equals("true") ){ + preserveData = true; + String emsg = "Unsupported preserveDataFlag. For now, we only support: 'false'.\n" + usageString; + System.out.println( emsg ); + System.exit(1); + } + else if (preserveDataFlag.equals("false") ){ + preserveData = false; + } + else { + String emsg = "Unsupported preserveDataFlag. We only support: 'true' or 'false'.\n" + usageString; + System.out.println( emsg ); + System.exit(1); + } + } + + String targetDataTypeStr = ""; + if( targetCardinality.equals("SINGLE") ){ + targetDataTypeStr = targetDataType; + } + else if( targetCardinality.equals("SET") ){ + targetDataTypeStr = "Set<" + targetDataType + ">"; + } + else if( targetCardinality.equals("LIST") ){ + targetDataTypeStr = "List<" + targetDataType + ">"; + } + + Class dType = null; + if(targetDataType.equals("String")){ dType = String.class; } + else if(targetDataType.equals("Integer")){ dType = Integer.class; } + else if(targetDataType.equals("Boolean")){ dType = Boolean.class; } + else if(targetDataType.equals("Character")){ dType = Character.class; } + else if(targetDataType.equals("Long")){ dType = Long.class; } + else if(targetDataType.equals("Float")){ dType = Float.class; } + else if(targetDataType.equals("Double")){ dType = Double.class; } + + System.out.println("\n>> WARNING/NOTE - If the passed cardinality is not in synch with what is in the ex5.json file, "); + System.out.println("\n>> then this will cause problems when new environments are created."); + + // Give a big warning if the DbMaps.PropertyDataTypeMap value does not agree with what we're doing + DbMaps dbMaps = null; + try { + dbMaps = IngestModelMoxyOxm.dbMapsContainer.get(AAIConfig.get(AAIConstants.AAI_DEFAULT_API_VERSION_PROP)); + } + catch( AAIException ae ){ + String emsg = "Could not instantiate a copy of dbMaps. "; + System.out.println( emsg ); + System.exit(1); + } + + String warningMsg = ""; + if( !dbMaps.PropertyDataTypeMap.containsKey(propName) ){ + String emsg = "Property Name = [" + propName + "] not found in PropertyDataTypeMap. "; + System.out.println( emsg ); + System.exit(1); + } + else { + String currentDataType = dbMaps.PropertyDataTypeMap.get(propName); + if( !currentDataType.equals(targetDataTypeStr) ){ + warningMsg = "TargetDataType [" + targetDataTypeStr + "] does not match what is in DbMaps (" + currentDataType + ")."; + } + } + + if( !warningMsg.equals("") ){ + System.out.println("\n>>> WARNING <<<< " ); + System.out.println(">>> " + warningMsg + " <<<"); + System.out.println(">>> !!! WARNING -- this change may be overwritten in some environments if <<<"); + System.out.println(">>> !!! entries are out of synch with what is done with this script. <<<"); + System.out.println(">>> WARNING <<<< " ); + } + + System.out.println(">>> Processing will begin in 5 seconds (unless interrupted). <<<"); + try { + // Give them a chance to back out of this + Thread.sleep(5000); + } catch ( java.lang.InterruptedException ie) { + System.out.println( " DB Schema Update has been aborted. "); + System.exit(1); + } + + TitanManagement graphMgt = null; + TitanGraph graph = null; + try { + AAIConfig.init(); + ErrorLogHelper.loadProperties(); + + System.out.println(" ---- NOTE --- about to open graph (takes a little while)\n"); + + graph = AAIGraph.getInstance().getGraph(); + if( graph == null ){ + String emsg = "Not able to get a graph object in ChangePropertyCardinality.java\n"; + System.out.println( emsg ); + System.exit(1); + } + + // Make sure this property is in the DB. + graphMgt = graph.openManagement(); + if( graphMgt == null ){ + String emsg = "Not able to get a graph Management object in ChangePropertyCardinality.java\n"; + System.out.println( emsg ); + System.exit(1); + } + + PropertyKey origPropKey = graphMgt.getPropertyKey(propName); + if( origPropKey == null ){ + // The old one wasn't there, so there's nothing to do + String emsg = "The propName = [" + propName + "] is not defined in our graph. "; + System.out.println( emsg ); + System.exit(1); + } + + if( origPropKey.cardinality().equals(Cardinality.valueOf(targetCardinality)) ){ + // The existing one already has cardinality of what they're asking for. + String emsg = "The propName = [" + propName + "] already has Cardinality of [" + targetCardinality + "]. "; + System.out.println( emsg ); + System.exit(0); + } + + // Rename this property to a backup name (old name with "retired_" appended plus a dateStr) + SimpleDateFormat d = new SimpleDateFormat("MMddHHmm"); + d.setTimeZone(TimeZone.getTimeZone("GMT")); + String dteStr = d.format(new Date()).toString(); + String retiredName = propName + "-" + dteStr + "-RETIRED"; + graphMgt.changeName( origPropKey, retiredName ); + + // Create a new property using the original property name and the targetDataType + PropertyKey freshPropKey = graphMgt.makePropertyKey(propName).dataType(dType).cardinality(Cardinality.valueOf(targetCardinality)).make(); + + System.out.println("Committing schema changes with graphMgt.tx().commit()"); + graphMgt.commit(); + graph.tx().commit(); + graph.close(); + + + // Get A new graph object + System.out.println(" ---- NOTE --- about to open a second graph object (takes a little while)\n"); + + graph = AAIGraph.getInstance().getGraph(); + if( graph == null ){ + String emsg = "Not able to get a graph object in SchemaMod.java\n"; + System.out.println( emsg ); + System.exit(1); + } + + // For each node that has this property, update the new from the old and then remove the + // old property from that node + // ---- NOTE ---- We're not preserving data at this point + Iterable verts = null; + verts= graph.query().has(retiredName).vertices(); + Iterator it = verts.iterator(); + int vtxCount = 0; + while( it.hasNext() ){ + vtxCount++; + TitanVertex tmpVtx = (TitanVertex)it.next(); + String tmpVid = tmpVtx.id().toString(); + + Object origVal = tmpVtx.property(retiredName).orElse(null); + if( preserveData ){ + tmpVtx.property(propName,origVal); + System.out.println("INFO -- just did the add of the freshPropertyKey and updated it with the orig value (" + + origVal.toString() + ")"); + } + else { + // existing nodes just won't have this property anymore + // + } + tmpVtx.property(retiredName).remove(); + System.out.println("INFO -- just did the remove of the " + retiredName + " from this vertex. (vid=" + tmpVid + ")"); + } + + System.out.println("Updated data for " + vtxCount + " vertexes. Now call graph.tx().commit(). "); + graph.tx().commit(); + + } + catch (AAIException e) { + System.out.print("Threw a AAIException: \n"); + System.out.println(e.getErrorObject().toString()); + } + catch (Exception ex) { + System.out.print("Threw a regular Exception:\n"); + System.out.println(ex.getMessage()); + } + finally { + if( graphMgt != null && graphMgt.isOpen() ){ + // Any changes that worked correctly should have already done their commits. + graphMgt.rollback(); + } + if( graph != null ){ + // Any changes that worked correctly should have already done their commits. + graph.tx().rollback(); + graph.close(); + } + + } + + System.exit(0); + + }// End of main() + + +} + + diff --git a/aai-resources/src/main/java/org/openecomp/aai/dbgen/DataSnapshot.java b/aai-resources/src/main/java/org/openecomp/aai/dbgen/DataSnapshot.java index 68bebc2..d03a5e3 100644 --- a/aai-resources/src/main/java/org/openecomp/aai/dbgen/DataSnapshot.java +++ b/aai-resources/src/main/java/org/openecomp/aai/dbgen/DataSnapshot.java @@ -277,4 +277,4 @@ public class DataSnapshot { }// End of main() -} +} diff --git a/aai-resources/src/main/java/org/openecomp/aai/dbgen/ForceDeleteTool.java b/aai-resources/src/main/java/org/openecomp/aai/dbgen/ForceDeleteTool.java new file mode 100644 index 0000000..20d5c9f --- /dev/null +++ b/aai-resources/src/main/java/org/openecomp/aai/dbgen/ForceDeleteTool.java @@ -0,0 +1,722 @@ +/*- + * ============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.Iterator; +import java.util.Properties; +import java.util.Scanner; +import org.apache.tinkerpop.gremlin.structure.Direction; +import org.apache.tinkerpop.gremlin.structure.Edge; +import org.apache.tinkerpop.gremlin.structure.Vertex; +import org.apache.tinkerpop.gremlin.structure.VertexProperty; +import org.slf4j.MDC; + +import org.openecomp.aai.exceptions.AAIException; +import org.openecomp.aai.util.AAIConfig; +import org.openecomp.aai.util.AAIConstants; +import com.att.eelf.configuration.Configuration; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import com.thinkaurelius.titan.core.TitanEdge; +import com.thinkaurelius.titan.core.TitanFactory; +import com.thinkaurelius.titan.core.TitanGraph; +import com.thinkaurelius.titan.core.TitanGraphQuery; +import com.thinkaurelius.titan.core.TitanVertex; + + + +public class ForceDeleteTool { + + + private static final int MAXDESCENDENTDEPTH = 15; + + /** + * The main method. + * + * @param args the arguments + */ + public static void main(String[] args) { + + //SWGK 01/21/2016 - To suppress the warning message when the tool is run from the Terminal. + + // Set the logging file properties to be used by EELFManager + Properties props = System.getProperties(); + props.setProperty(Configuration.PROPERTY_LOGGING_FILE_NAME, "forceDelete-logback.xml"); + props.setProperty(Configuration.PROPERTY_LOGGING_FILE_PATH, AAIConstants.AAI_HOME_ETC_APP_PROPERTIES); + EELFLogger logger = EELFManager.getInstance().getLogger(ForceDeleteTool.class.getSimpleName()); + MDC.put("logFilenameAppender", ForceDeleteTool.class.getSimpleName()); + + String actionVal = ""; + String userIdVal = ""; + String dataString = ""; + Boolean displayAllVidsFlag = false; // Note - This should rarely be needed + Boolean overRideProtection = false; // This should rarely be used - it overrides all our new checking + long vertexIdLong = 0; + String edgeIdStr = ""; + String argStr4Msg = ""; + + if (args != null && args.length > 0) { + // They passed some arguments in that will affect processing + for (int i = 0; i < args.length; i++) { + String thisArg = args[i]; + argStr4Msg = argStr4Msg + " " + thisArg; + + if (thisArg.equals("-action")) { + i++; + if (i >= args.length) { + logger.error(" No value passed with -action option. "); + System.exit(0); + } + actionVal = args[i]; + argStr4Msg = argStr4Msg + " " + actionVal; + } + else if (thisArg.equals("-userId")) { + i++; + if (i >= args.length) { + logger.error(" No value passed with -userId option. "); + System.exit(0); + } + userIdVal = args[i]; + argStr4Msg = argStr4Msg + " " + userIdVal; + } + else if (thisArg.equals("-overRideProtection")) { + overRideProtection = true; + } + else if (thisArg.equals("-DISPLAY_ALL_VIDS")) { + displayAllVidsFlag = true; + } + else if (thisArg.equals("-vertexId")) { + i++; + if (i >= args.length) { + logger.error(" No value passed with -vertexId option. "); + System.exit(0); + } + String nextArg = args[i]; + argStr4Msg = argStr4Msg + " " + nextArg; + try { + vertexIdLong = Long.parseLong(nextArg); + } catch (Exception e) { + logger.error("Bad value passed with -vertexId option: [" + + nextArg + "]"); + System.exit(0); + } + } + else if (thisArg.equals("-params4Collect")) { + i++; + if (i >= args.length) { + logger.error(" No value passed with -params4Collect option. "); + System.exit(0); + } + dataString = args[i]; + argStr4Msg = argStr4Msg + " " + dataString; + } + else if (thisArg.equals("-edgeId")) { + i++; + if (i >= args.length) { + logger.error(" No value passed with -edgeId option. "); + System.exit(0); + } + String nextArg = args[i]; + argStr4Msg = argStr4Msg + " " + nextArg; + edgeIdStr = nextArg; + } + else { + logger.error(" Unrecognized argument passed to ForceDeleteTool: [" + + thisArg + "]. "); + logger.error(" Valid values are: -action -userId -vertexId -edgeId -overRideProtection -params4Collect -DISPLAY_ALL_VIDS"); + System.exit(0); + } + } + } + + if( !actionVal.equals("COLLECT_DATA") && !actionVal.equals("DELETE_NODE") && !actionVal.equals("DELETE_EDGE")){ + String emsg = "Bad action parameter [" + actionVal + "] passed to ForceDeleteTool(). Valid values = COLLECT_DATA or DELETE_NODE or DELETE_EDGE\n"; + System.out.println(emsg); + logger.error(emsg); + System.exit(0); + } + + if( actionVal.equals("DELETE_NODE") && vertexIdLong == 0 ){ + String emsg = "ERROR: No vertex ID passed on DELETE_NODE request. \n"; + System.out.println(emsg); + logger.error(emsg); + System.exit(0); + } + else if( actionVal.equals("DELETE_EDGE") && edgeIdStr.equals("")){ + String emsg = "ERROR: No edge ID passed on DELETE_EDGE request. \n"; + System.out.println(emsg); + logger.error(emsg); + System.exit(0); + } + + + userIdVal = userIdVal.trim(); + if( (userIdVal.length() < 6) || userIdVal.toUpperCase().equals("AAIADMIN") ){ + String emsg = "Bad userId parameter [" + userIdVal + "] passed to ForceDeleteTool(). must be not empty and not aaiadmin \n"; + System.out.println(emsg); + logger.error(emsg); + System.exit(0); + } + + String msg = ""; + TitanGraph graph = null; + try { + AAIConfig.init(); + System.out.println(" ---- NOTE --- about to open graph (takes a little while)--------\n"); + graph = TitanFactory.open(AAIConstants.REALTIME_DB_CONFIG); + if( graph == null ){ + String emsg = "could not get graph object in ForceDeleteTool() \n"; + System.out.println(emsg); + logger.error(emsg); + System.exit(0); + } + } + catch (AAIException e1) { + msg = e1.getErrorObject().toString(); + System.out.println(msg); + logger.error(msg); + System.exit(0); + } + catch (Exception e2) { + msg = e2.toString(); + System.out.println(msg); + logger.error(msg); + System.exit(0); + } + + msg = "ForceDelete called by: userId [" + userIdVal + "] with these params: [" + argStr4Msg + "]"; + System.out.println(msg); + logger.info(msg); + + + if( actionVal.equals("COLLECT_DATA") ){ + // When doing COLLECT_DATA, we expect the dataString string to be comma separated + // name value pairs like this: + // "propName1|propVal1,propName2|propVal2" etc. We will look for a node or nodes + // that have properties that ALL match what was passed in. + + int resCount = 0; + int firstPipeLoc = dataString.indexOf("|"); + if( firstPipeLoc <= 0 ){ + msg = "Must use the -params4Collect option when collecting data with data string in a format like: 'propName1|propVal1,propName2|propVal2'"; + System.out.println(msg); + logger.error(msg); + System.exit(0); + } + TitanGraphQuery tgQ = graph.query(); + String qStringForMsg = " graph.query()"; + // Note - if they're only passing on parameter, there won't be any commas + String [] paramArr = dataString.split(","); + for( int i = 0; i < paramArr.length; i++ ){ + int pipeLoc = paramArr[i].indexOf("|"); + if( pipeLoc <= 0 ){ + msg = "Must use the -params4Collect option when collecting data with data string in a format like: 'propName1|propVal1,propName2|propVal2'"; + System.out.println(msg); + logger.error(msg); + System.exit(0); + } + else { + String propName = paramArr[i].substring(0,pipeLoc); + String propVal = paramArr[i].substring(pipeLoc + 1); + tgQ = tgQ.has(propName,propVal); + qStringForMsg = qStringForMsg + ".has(" + propName + "," + propVal + ")"; + } + } + if( (tgQ != null) && (tgQ instanceof TitanGraphQuery) ){ + Iterable verts = (Iterable) tgQ.vertices(); + Iterator vertItor = verts.iterator(); + while( vertItor.hasNext() ){ + resCount++; + TitanVertex v = (TitanVertex)vertItor.next(); + showNodeInfo( logger, v, displayAllVidsFlag ); + int descendantCount = countDescendants( logger, v, 0 ); + String infMsg = " Found " + descendantCount + " descendant nodes \n"; + System.out.println( infMsg ); + logger.info( infMsg ); + } + } + else { + msg = "Bad TitanGraphQuery object. "; + System.out.println(msg); + logger.error(msg); + System.exit(0); + } + + String infMsg = "\n\n Found: " + resCount + " nodes for this query: [" + qStringForMsg + "]\n"; + System.out.println( infMsg ); + logger.info( infMsg ); + } + else if( actionVal.equals("DELETE_NODE") ){ + Iterator vtxItr = graph.vertices( vertexIdLong ); + if( vtxItr != null && vtxItr.hasNext() ) { + Vertex vtx = vtxItr.next(); + showNodeInfo( logger, vtx, displayAllVidsFlag ); + int descendantCount = countDescendants( logger, (TitanVertex)vtx, 0 ); + String infMsg = " Found " + descendantCount + " descendant nodes. Note - forceDelete does not cascade to " + + " child nodes, but they may become unreachable after the delete. \n"; + System.out.println( infMsg ); + logger.info( infMsg ); + + int edgeCount = countEdges( logger, vtx ); + + infMsg = " Found total of " + edgeCount + " edges incident on this node. \n"; + System.out.println( infMsg ); + logger.info( infMsg ); + + if( getNodeDelConfirmation(logger, userIdVal, vtx, descendantCount, edgeCount, overRideProtection) ){ + vtx.remove(); + graph.tx().commit(); + infMsg = ">>>>>>>>>> Removed node with vertexId = " + vertexIdLong; + logger.info( infMsg ); + System.out.println(infMsg); + } + else { + infMsg = " Delete Cancelled. "; + System.out.println(infMsg); + logger.info( infMsg ); + } + } + else { + String infMsg = ">>>>>>>>>> Vertex with vertexId = " + vertexIdLong + " not found."; + System.out.println( infMsg ); + logger.info( infMsg ); + } + } + else if( actionVal.equals("DELETE_EDGE") ){ + TitanEdge thisEdge = null; + Iterator edItr = graph.edges( edgeIdStr ); + if( edItr != null && edItr.hasNext() ) { + thisEdge = (TitanEdge)edItr.next(); + } + + if( thisEdge == null ){ + String infMsg = ">>>>>>>>>> Edge with edgeId = " + edgeIdStr + " not found."; + logger.info( infMsg ); + System.out.println(infMsg); + System.exit(0); + } + + if( getEdgeDelConfirmation(logger, userIdVal, thisEdge, overRideProtection) ){ + thisEdge.remove(); + graph.tx().commit(); + String infMsg = ">>>>>>>>>> Removed edge with edgeId = " + edgeIdStr; + logger.info( infMsg ); + System.out.println(infMsg); + } + else { + String infMsg = " Delete Cancelled. "; + System.out.println(infMsg); + logger.info( infMsg ); + } + System.exit(0); + } + else { + String emsg = "Unknown action parameter [" + actionVal + "] passed to ForceDeleteTool(). Valid values = COLLECT_DATA, DELETE_NODE or DELETE_EDGE \n"; + System.out.println(emsg); + logger.info( emsg ); + System.exit(0); + } + + System.exit(0); + + }// end of main() + + + public static void showNodeInfo(EELFLogger logger, Vertex tVert, Boolean displayAllVidsFlag ){ + + try { + Iterator> pI = tVert.properties(); + String infStr = ">>> Found Vertex with VertexId = " + tVert.id() + ", properties: "; + System.out.println( infStr ); + logger.info(infStr); + while( pI.hasNext() ){ + VertexProperty tp = pI.next(); + infStr = " [" + tp.key() + "|" + tp.value() + "] "; + System.out.println( infStr ); + logger.info(infStr); + } + + ArrayList retArr = collectEdgeInfoForNode( logger, tVert, displayAllVidsFlag ); + for( String infoStr : retArr ){ + System.out.println( infoStr ); + logger.info(infoStr); + } + } + catch (Exception e){ + String warnMsg = " -- Error -- trying to display edge info. [" + e.getMessage() + "]"; + System.out.println( warnMsg ); + logger.warn(warnMsg); + } + + }// End of showNodeInfo() + + + public static void showPropertiesForEdge( EELFLogger logger, TitanEdge tEd ){ + String infMsg = ""; + if( tEd == null ){ + infMsg = "null Edge object passed to showPropertiesForEdge()"; + System.out.print(infMsg); + logger.info(infMsg); + return; + } + + // Try to show the edge properties + try { + infMsg =" Label for this Edge = [" + tEd.label() + "] "; + System.out.print(infMsg); + logger.info(infMsg); + + infMsg =" EDGE Properties for edgeId = " + tEd.id() + ": "; + System.out.print(infMsg); + logger.info(infMsg); + Iterator pI = tEd.keys().iterator(); + while( pI.hasNext() ){ + String propKey = pI.next(); + infMsg = "Prop: [" + propKey + "], val = [" + + tEd.property(propKey) + "] "; + System.out.print(infMsg); + logger.info(infMsg); + } + } + catch( Exception ex ){ + infMsg = " Could not retrieve properties for this edge. exMsg = [" + + ex.getMessage() + "] "; + System.out.println( infMsg ); + logger.info(infMsg); + } + + // Try to show what's connected to the IN side of this Edge + try { + infMsg = " Looking for the Vertex on the IN side of the edge: "; + System.out.print(infMsg); + logger.info(infMsg); + TitanVertex inVtx = tEd.inVertex(); + Iterator> pI = inVtx.properties(); + String infStr = ">>> Found Vertex with VertexId = " + inVtx.id() + + ", properties: "; + System.out.println( infStr ); + logger.info(infStr); + while( pI.hasNext() ){ + VertexProperty tp = pI.next(); + infStr = " [" + tp.key() + "|" + tp.value() + "] "; + System.out.println( infStr ); + logger.info(infStr); + } + } + catch( Exception ex ){ + infMsg = " Could not retrieve vertex data for the IN side of " + + "the edge. exMsg = [" + ex.getMessage() + "] "; + System.out.println( infMsg ); + logger.info(infMsg); + } + + // Try to show what's connected to the OUT side of this Edge + try { + infMsg = " Looking for the Vertex on the OUT side of the edge: "; + System.out.print(infMsg); + logger.info(infMsg); + TitanVertex outVtx = tEd.outVertex(); + Iterator> pI = outVtx.properties(); + String infStr = ">>> Found Vertex with VertexId = " + outVtx.id() + + ", properties: "; + System.out.println( infStr ); + logger.info(infStr); + while( pI.hasNext() ){ + VertexProperty tp = pI.next(); + infStr = " [" + tp.key() + "|" + tp.value() + "] "; + System.out.println( infStr ); + logger.info(infStr); + } + } + catch( Exception ex ){ + infMsg = " Could not retrieve vertex data for the OUT side of " + + "the edge. exMsg = [" + ex.getMessage() + "] "; + System.out.println( infMsg ); + logger.info(infMsg); + } + + }// end showPropertiesForEdge() + + + + public static ArrayList collectEdgeInfoForNode( EELFLogger logger, Vertex tVert, boolean displayAllVidsFlag ){ + ArrayList retArr = new ArrayList (); + Direction dir = Direction.OUT; + for ( int i = 0; i <= 1; i++ ){ + if( i == 1 ){ + // Second time through we'll look at the IN edges. + dir = Direction.IN; + } + Iterator eI = tVert.edges(dir); + if( ! eI.hasNext() ){ + retArr.add("No " + dir + " edges were found for this vertex. "); + } + while( eI.hasNext() ){ + Edge ed = eI.next(); + String lab = ed.label(); + Vertex vtx = null; + if( dir == Direction.OUT ){ + // get the vtx on the "other" side + vtx = ed.inVertex(); + } + else { + // get the vtx on the "other" side + vtx = ed.outVertex(); + } + if( vtx == null ){ + retArr.add(" >>> COULD NOT FIND VERTEX on the other side of this edge edgeId = " + ed.id() + " <<< "); + } + else { + String nType = vtx.property("aai-node-type").orElse(null); + if( displayAllVidsFlag ){ + // This should rarely be needed + String vid = vtx.id().toString(); + retArr.add("Found an " + dir + " edge (" + lab + ") between this vertex and a [" + nType + "] node with VtxId = " + vid ); + } + else { + // This is the normal case + retArr.add("Found an " + dir + " edge (" + lab + ") between this vertex and a [" + nType + "] node. "); + } + } + } + } + return retArr; + + }// end of collectEdgeInfoForNode() + + + public static int countEdges( EELFLogger logger, Vertex vtx ){ + int edgeCount = 0; + try { + Iterator edgesItr = vtx.edges(Direction.BOTH); + while( edgesItr.hasNext() ){ + edgesItr.next(); + edgeCount++; + } + } + catch (Exception e) { + String wMsg = "-- ERROR -- Stopping the counting of edges because of Exception [" + e.getMessage() + "]"; + System.out.println( wMsg ); + logger.warn( wMsg ); + } + return edgeCount; + + }// end of countEdges() + + + public static int countDescendants(EELFLogger logger, TitanVertex vtx, int levelVal ){ + int totalCount = 0; + int thisLevel = levelVal + 1; + + if( thisLevel > MAXDESCENDENTDEPTH ){ + String wMsg = "Warning -- Stopping the counting of descendents because we reached the max depth of " + MAXDESCENDENTDEPTH; + System.out.println( wMsg ); + logger.warn( wMsg ); + return totalCount; + } + + try { + Iterable verts = vtx.query().direction(Direction.OUT).has("isParent",true).vertices(); + Iterator vertI = verts.iterator(); + while( vertI != null && vertI.hasNext() ){ + totalCount++; + TitanVertex childVtx = (TitanVertex) vertI.next(); + totalCount = totalCount + countDescendants( logger, childVtx, thisLevel ); + } + } + catch (Exception e) { + String wMsg = "Error -- Stopping the counting of descendents because of Exception [" + e.getMessage() + "]"; + System.out.println( wMsg ); + logger.warn( wMsg ); + } + + return totalCount; + }// end of countDescendants() + + + public static boolean getEdgeDelConfirmation( EELFLogger logger, String uid, TitanEdge ed, + Boolean overRideProtection ) { + + showPropertiesForEdge( logger, ed ); + System.out.print("\n Are you sure you want to delete this EDGE? (y/n): "); + Scanner s = new Scanner(System.in); + s.useDelimiter(""); + String confirm = s.next(); + s.close(); + + if (!confirm.equalsIgnoreCase("y")) { + String infMsg = " User [" + uid + "] has chosen to abandon this delete request. "; + System.out.println("\n" + infMsg); + logger.info(infMsg); + return false; + } + else { + String infMsg = " User [" + uid + "] has confirmed this delete request. "; + System.out.println("\n" + infMsg); + logger.info(infMsg); + return true; + } + + } // End of getEdgeDelConfirmation() + + + public static boolean getNodeDelConfirmation( EELFLogger logger, String uid, Vertex vtx, int edgeCount, + int descendantCount, Boolean overRideProtection ) { + String thisNodeType = ""; + try { + thisNodeType = vtx.property("aai-node-type").orElse(null); + } + catch ( Exception nfe ){ + // Let the user know something is going on - but they can confirm the delete if they want to. + String infMsg = " -- WARNING -- could not get an aai-node-type for this vertex. -- WARNING -- "; + System.out.println( infMsg ); + logger.warn( infMsg ); + } + + String ntListString = ""; + String maxDescString = ""; + String maxEdgeString = ""; + + int maxDescCount = 10; // default value + int maxEdgeCount = 10; // default value + ArrayList protectedNTypes = new ArrayList (); + protectedNTypes.add("cloud-region"); // default value + + try { + ntListString = AAIConfig.get("aai.forceDel.protected.nt.list"); + maxDescString = AAIConfig.get("aai.forceDel.protected.descendant.count"); + maxEdgeString = AAIConfig.get("aai.forceDel.protected.edge.count"); + } + catch ( Exception nfe ){ + // Don't worry, we will use default values + String infMsg = "-- WARNING -- could not get aai.forceDel.protected values from aaiconfig.properties -- will use default values. "; + System.out.println( infMsg ); + logger.warn( infMsg ); + } + + if( maxDescString != null && !maxDescString.equals("") ){ + try { + maxDescCount = Integer.parseInt(maxDescString); + } + catch ( Exception nfe ){ + // Don't worry, we will leave "maxDescCount" set to the default value + } + } + + if( maxEdgeString != null && !maxEdgeString.equals("") ){ + try { + maxEdgeCount = Integer.parseInt(maxEdgeString); + } + catch ( Exception nfe ){ + // Don't worry, we will leave "maxEdgeCount" set to the default value + } + } + + if( ntListString != null && !ntListString.trim().equals("") ){ + String [] nodeTypes = ntListString.split("\\|"); + for( int i = 0; i < nodeTypes.length; i++ ){ + protectedNTypes.add(nodeTypes[i]); + } + } + + boolean giveProtOverRideMsg = false; + boolean giveProtErrorMsg = false; + if( descendantCount > maxDescCount ){ + // They are trying to delete a node with a lots of descendants + String infMsg = " >> WARNING >> This node has more descendant edges than the max ProtectedDescendantCount: " + edgeCount + ". Max = " + + maxEdgeCount + ". It can be DANGEROUS to delete one of these. << WARNING << "; + System.out.println(infMsg); + logger.info(infMsg); + if( ! overRideProtection ){ + // They cannot delete this kind of node without using the override option + giveProtErrorMsg = true; + } + else { + giveProtOverRideMsg = true; + } + } + + if( edgeCount > maxEdgeCount ){ + // They are trying to delete a node with a lot of edges + String infMsg = " >> WARNING >> This node has more edges than the max ProtectedEdgeCount: " + edgeCount + ". Max = " + + maxEdgeCount + ". It can be DANGEROUS to delete one of these. << WARNING << "; + System.out.println(infMsg); + logger.info(infMsg); + if( ! overRideProtection ){ + // They cannot delete this kind of node without using the override option + giveProtErrorMsg = true; + } + else { + giveProtOverRideMsg = true; + } + } + + if( thisNodeType != null && !thisNodeType.equals("") && protectedNTypes.contains(thisNodeType) ){ + // They are trying to delete a protected Node Type + String infMsg = " >> WARNING >> This node is a PROTECTED NODE-TYPE (" + thisNodeType + "). " + + " It can be DANGEROUS to delete one of these. << WARNING << "; + System.out.println(infMsg); + logger.info(infMsg); + if( ! overRideProtection ){ + // They cannot delete this kind of node without using the override option + giveProtErrorMsg = true; + } + else { + giveProtOverRideMsg = true; + } + } + + if( giveProtOverRideMsg ){ + String infMsg = " !!>> WARNING >>!! you are using the overRideProtection parameter which will let you do this potentially dangerous delete."; + System.out.println("\n" + infMsg); + logger.info(infMsg); + } + else if( giveProtErrorMsg ) { + String errMsg = " ERROR >> this kind of node can only be deleted if you pass the overRideProtection parameter."; + System.out.println("\n" + errMsg); + logger.error(errMsg); + return false; + } + + System.out.print("\n Are you sure you want to do this delete? (y/n): "); + Scanner s = new Scanner(System.in); + s.useDelimiter(""); + String confirm = s.next(); + s.close(); + + if (!confirm.equalsIgnoreCase("y")) { + String infMsg = " User [" + uid + "] has chosen to abandon this delete request. "; + System.out.println("\n" + infMsg); + logger.info(infMsg); + return false; + } + else { + String infMsg = " User [" + uid + "] has confirmed this delete request. "; + System.out.println("\n" + infMsg); + logger.info(infMsg); + return true; + } + + } // End of getNodeDelConfirmation() + +} + + diff --git a/aai-resources/src/main/java/org/openecomp/aai/dbgen/GraphMLReaderNew.java b/aai-resources/src/main/java/org/openecomp/aai/dbgen/GraphMLReaderNew.java new file mode 100644 index 0000000..4f3fee0 --- /dev/null +++ b/aai-resources/src/main/java/org/openecomp/aai/dbgen/GraphMLReaderNew.java @@ -0,0 +1,353 @@ +/*- + * ============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.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; +import java.lang.reflect.Array; +import java.nio.charset.Charset; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Map.Entry; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.events.XMLEvent; + +import org.apache.tinkerpop.gremlin.structure.Edge; +import org.apache.tinkerpop.gremlin.structure.Graph; +import org.apache.tinkerpop.gremlin.structure.Vertex; + +//import com.infrasight.model.UnicodeUtil; +import com.thinkaurelius.titan.core.TitanGraph; + +/** + * GraphMLReader writes the data from a GraphML stream to a graph. + */ +public class GraphMLReaderNew { + public static final Charset charset = Charset.forName("UTF8"); + + /** + * Input the GraphML stream data into the graph. + * In practice, usually the provided graph is empty. + * + * @param graph the graph to populate with the GraphML data + * @param titanGraph the titan graph + * @param graphMLInputStream an InputStream of GraphML data + * @return the map + * @throws XMLStreamException thrown when the GraphML data is not correctly formatted + */ + public static Map inputGraph(final Graph graph, final TitanGraph titanGraph, final InputStream graphMLInputStream) throws XMLStreamException { + return inputGraph(graph, titanGraph, new InputStreamReader(graphMLInputStream, charset), 1000); + } + +/* public static void inputGraphFiltered(final Graph graph, final InputStream graphMLInputStream) throws XMLStreamException { + inputGraph(graph, UnicodeUtil.createFilteredReader(new InputStreamReader(graphMLInputStream, charset)), 1000); + }*/ + + private static class KeySpec { + String attrName; + String attrType; + + /** + * Instantiates a new key spec. + * + * @param name the name + * @param type the type + */ + public KeySpec(String name, String type) { + this.attrName = name; + this.attrType = type; + } + } + + /** + * Input the GraphML stream data into the graph. + * More control over how data is streamed is provided by this method. + * + * @param graph the graph to populate with the GraphML data + * @param titanGraph the titan graph + * @param inputReader an Reader of GraphML character data + * @param bufferSize the amount of elements to hold in memory before committing a transactions (only valid for TransactionalGraphs) + * @return the map + * @throws XMLStreamException thrown when the GraphML data is not correctly formatted + */ + public static Map inputGraph(final Graph graph, final TitanGraph titanGraph, final Reader inputReader, int bufferSize) throws XMLStreamException { + + XMLInputFactory inputFactory = XMLInputFactory.newInstance(); + inputFactory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false); + inputFactory.setProperty(XMLInputFactory.SUPPORT_DTD, false); + XMLStreamReader reader = inputFactory.createXMLStreamReader(inputReader); + + //final BatchGraph graph = BatchGraph.wrap(inputGraph, bufferSize); + + Map keyMap = new HashMap(); + + // Buffered Vertex Data + String vertexId = null; + Map vertexProps = null; + boolean inVertex = false; + + // Buffered Edge Data + String edgeId = null; + String edgeLabel = null; + Vertex edgeInVertex = null; + Vertex edgeOutVertex = null; + Map edgeProps = null; + boolean inEdge = false; + Map vertexIdSetMap = new HashMap(); + + while (reader.hasNext()) { + + Integer eventType = reader.next(); + if (eventType.equals(XMLEvent.START_ELEMENT)) { + String elementName = reader.getName().getLocalPart(); + + if (elementName.equals(GraphMLTokens.KEY)) { + String id = reader.getAttributeValue(null, GraphMLTokens.ID); + String attributeName = reader.getAttributeValue(null, GraphMLTokens.ATTR_NAME); + String attributeType = reader.getAttributeValue(null, GraphMLTokens.ATTR_TYPE); + keyMap.put(id, new KeySpec(attributeName, attributeType)); + + } else if (elementName.equals(GraphMLTokens.NODE)) { + vertexId = reader.getAttributeValue(null, GraphMLTokens.ID); + inVertex = true; + vertexProps = new HashMap(); + + } else if (elementName.equals(GraphMLTokens.EDGE)) { + + + edgeId = reader.getAttributeValue(null, GraphMLTokens.ID); + edgeLabel = reader.getAttributeValue(null, GraphMLTokens.LABEL); + edgeLabel = edgeLabel == null ? GraphMLTokens._DEFAULT : edgeLabel; + + String outVertexId = reader.getAttributeValue(null, GraphMLTokens.SOURCE); + String inVertexId = reader.getAttributeValue(null, GraphMLTokens.TARGET); + + edgeOutVertex = graph.vertices(outVertexId).next(); + edgeInVertex = graph.vertices(inVertexId).next(); + + if (null == edgeOutVertex) { + edgeOutVertex = graph.addVertex(outVertexId); + } + if (null == edgeInVertex) { + edgeInVertex = graph.addVertex(inVertexId); + } + + inEdge = true; + edgeProps = new HashMap(); + + } else if (elementName.equals(GraphMLTokens.DATA)) { + String key = reader.getAttributeValue(null, GraphMLTokens.KEY); + KeySpec keySpec = keyMap.get(key); + + if (keySpec != null) { + Object value = readData(reader, keySpec.attrType); + if(value == null) + throw new RuntimeException("Empty data"); + if (inVertex == true) { + vertexProps.put(keySpec.attrName, value); + } else if (inEdge == true) { + edgeProps.put(keySpec.attrName, value); + } + } + + } + } else if (eventType.equals(XMLEvent.END_ELEMENT)) { + String elementName = reader.getName().getLocalPart(); + + if (elementName.equals(GraphMLTokens.NODE)) { + + Vertex currentVertex = graph.vertices(vertexId).next(); + if (currentVertex != null) + throw new RuntimeException("Duplicate vertex ID: "+vertexId); + currentVertex = graph.addVertex(vertexId); + Boolean hasCollection = false; + for (Entry prop : vertexProps.entrySet()) { + // multi-properties need a addProperty and need to use a TitanVertex - BluePrint + // Vertex does not support this + Object value = prop.getValue(); + if (value instanceof Collection) { + hasCollection = true; + vertexIdSetMap.put(currentVertex.id().toString() + "." + prop.getKey(), vertexProps); + currentVertex.property("has-collection", "true"); + } else { + currentVertex.property(prop.getKey(), value); + } + } + if (hasCollection) + System.out.println("---Found node with SET property vertex id:" + vertexId + " properties:" + vertexProps.toString()); + vertexId = null; + vertexProps = null; + inVertex = false; + } else if (elementName.equals(GraphMLTokens.EDGE)) { + Edge currentEdge = edgeOutVertex.addEdge(edgeLabel, edgeInVertex); + //addEdge(edgeId, edgeOutVertex, edgeInVertex, edgeLabel); + + for (Entry prop : edgeProps.entrySet()) { + currentEdge.property(prop.getKey(), prop.getValue()); + } + + edgeId = null; + edgeLabel = null; + edgeInVertex = null; + edgeOutVertex = null; + edgeProps = null; + inEdge = false; + } + + } + + } + + reader.close(); + graph.tx().close(); + + return vertexIdSetMap; + + } + + /** + * Read data. + * + * @param reader the reader + * @param type the type + * @return the object + * @throws XMLStreamException the XML stream exception + */ + private static Object readData(XMLStreamReader reader, String type) throws XMLStreamException { + Collection col = new ArrayList(); + + int pos = type.indexOf('-'); + if(pos < 0) + return typeCastValue(reader.getElementText(), type); + String arrayType = type.substring(0, pos); + type = type.substring(pos+1); + + boolean done = false; + while(!done) { + Integer eventType = reader.next(); + if(eventType.equals(XMLEvent.START_ELEMENT)) { + String text = reader.getElementText(); + Object value = typeCastValue(text, type); + col.add(value); + } + if(eventType.equals(XMLEvent.END_ELEMENT)) { + String elementName = reader.getName().getLocalPart(); + if(elementName.equals(GraphMLTokens.DATA)) { + done = true; + continue; + } + } + } + + if(arrayType.equals(GraphMLTokens.ARRAY)) { + Object arr = Array.newInstance(typeToClass(type), col.size()); + int i = 0; + for(Object obj : col) { + Array.set(arr, i, obj); + i++; + } + return arr; + } + else if(arrayType.equals(GraphMLTokens.SET)) + return new HashSet(col); + else if(type.startsWith(GraphMLTokens.LIST)) + return new HashSet(col); + + return col; + } + + /** + * Type to class. + * + * @param type the type + * @return the class + */ + private static Class typeToClass(String type) { + if (type.equals(GraphMLTokens.STRING)) + return String.class; + else if (type.equals(GraphMLTokens.FLOAT)) + return Float.TYPE; + else if (type.equals(GraphMLTokens.INT)) + return Integer.TYPE; + else if (type.equals(GraphMLTokens.DOUBLE)) + return Double.TYPE; + else if (type.equals(GraphMLTokens.BOOLEAN)) + return Boolean.TYPE; + else if (type.equals(GraphMLTokens.LONG)) + return Long.TYPE; + else + throw new RuntimeException("Unsupported type: "+type); + } + + /** + * Type cast value. + * + * @param value the value + * @param type the type + * @return the object + */ + private static Object typeCastValue(String value, String type) { + if (type.equals(GraphMLTokens.STRING)) + return value; + else if (type.equals(GraphMLTokens.FLOAT)) + return Float.valueOf(value); + else if (type.equals(GraphMLTokens.INT)) + return Integer.valueOf(value); + else if (type.equals(GraphMLTokens.DOUBLE)) + return Double.valueOf(value); + else if (type.equals(GraphMLTokens.BOOLEAN)) + return Boolean.valueOf(value); + else if (type.equals(GraphMLTokens.LONG)) + return Long.valueOf(value); + else + throw new RuntimeException("Unsupported type: "+type); + } + +/* TitanVertex titanVertex = (TitanVertex) titanGraph.getVertex(vertexId); + if (titanVertex != null) + throw new RuntimeException("Duplicate vertex ID: "+vertexId); + titanVertex = (TitanVertex) titanGraph.addVertex(vertexId); + for (Entry prop : vertexProps.entrySet()) { + // multi-properties need a addProperty and need to use a TitanVertex - BluePrint + // Vertex does not support this + Object value = prop.getValue(); + if (value instanceof Collection) { + try { + for(Object obj : ((Collection)value)) { + System.out.println("vertex id:property name:property value="+ vertexId + ":" + prop.getKey() + ":" + obj.toString()); + titanVertex.addProperty(prop.getKey(), obj.toString()); + } + } + catch (Exception e) { + System.out.println("Can't set SET/LIST properties - skipping"); + } + + } else + titanVertex.setProperty(prop.getKey(), prop.getValue()); + }*/ +} diff --git a/aai-resources/src/main/java/org/openecomp/aai/dbgen/GraphMLTokens.java b/aai-resources/src/main/java/org/openecomp/aai/dbgen/GraphMLTokens.java new file mode 100644 index 0000000..f863a52 --- /dev/null +++ b/aai-resources/src/main/java/org/openecomp/aai/dbgen/GraphMLTokens.java @@ -0,0 +1,57 @@ +/*- + * ============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; + +/** + * A collection of tokens used for GraphML related data. + */ +public class GraphMLTokens { + public static final String GRAPHML = "graphml"; + public static final String XMLNS = "xmlns"; + public static final String GRAPHML_XMLNS = "http://graphml.graphdrawing.org/xmlns"; + public static final String G = "G"; + public static final String EDGEDEFAULT = "edgedefault"; + public static final String DIRECTED = "directed"; + public static final String KEY = "key"; + public static final String FOR = "for"; + public static final String ID = "id"; + public static final String ATTR_NAME = "attr.name"; + public static final String ATTR_TYPE = "attr.type"; + public static final String GRAPH = "graph"; + public static final String NODE = "node"; + public static final String EDGE = "edge"; + public static final String SOURCE = "source"; + public static final String TARGET = "target"; + public static final String DATA = "data"; + public static final String LABEL = "label"; + public static final String STRING = "string"; + public static final String FLOAT = "float"; + public static final String DOUBLE = "double"; + public static final String LONG = "long"; + public static final String BOOLEAN = "boolean"; + public static final String INT = "int"; + public static final String ARRAY = "array"; + public static final String SET = "set"; + public static final String LIST = "list"; + public static final String ITEM = "item"; + public static final String _DEFAULT = "_default"; + +} diff --git a/aai-resources/src/main/java/org/openecomp/aai/dbgen/GraphMLWriterNew.java b/aai-resources/src/main/java/org/openecomp/aai/dbgen/GraphMLWriterNew.java new file mode 100644 index 0000000..1704428 --- /dev/null +++ b/aai-resources/src/main/java/org/openecomp/aai/dbgen/GraphMLWriterNew.java @@ -0,0 +1,358 @@ +/*- + * ============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.io.OutputStream; +import java.lang.reflect.Array; +import java.util.Collection; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import javax.xml.stream.XMLOutputFactory; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tinkerpop.gremlin.structure.Direction; +import org.apache.tinkerpop.gremlin.structure.Edge; +import org.apache.tinkerpop.gremlin.structure.Graph; +import org.apache.tinkerpop.gremlin.structure.Property; +import org.apache.tinkerpop.gremlin.structure.Vertex; +import org.apache.tinkerpop.gremlin.structure.VertexProperty; + +/** + * GraphMLWriter writes a Graph to a GraphML OutputStream. + */ +public class GraphMLWriterNew { + + private static class KeySpec { + String attrName; + String attrType; + + /** + * Instantiates a new key spec. + * + * @param name the name + * @param type the type + */ + public KeySpec(String name, String type) { + this.attrName = name; + this.attrType = type; + } + } + + /** + * Write the data in a Graph to a GraphML OutputStream. + * + * @param graph the Graph to pull the data from + * @param graphMLOutputStream the GraphML OutputStream to write the Graph data to + * @throws XMLStreamException thrown if there is an error generating the GraphML data + */ + public static void outputGraph(final Graph graph, final OutputStream graphMLOutputStream) throws XMLStreamException { + Map vertexKeyTypes = new HashMap(); + Map edgeKeyTypes = new HashMap(); + + + Iterator vertices = graph.vertices(); + Vertex vertex = null; + Iterator> propertyIterator = null; + VertexProperty property = null; + while (vertices.hasNext()) { + vertex = vertices.next(); + propertyIterator = vertex.properties(); + while (propertyIterator.hasNext()) { + property = propertyIterator.next(); + Object value = property.value(); + String key = property.key(); + if(value == null) + continue; + String type = getStringType(value); + if(type == null) + continue; + String id = key+"-"+type; + if (!vertexKeyTypes.containsKey(id)) { + vertexKeyTypes.put(id, new KeySpec(key, type)); + } + } + } + Iterator edges = graph.edges(); + Edge edge = null; + Iterator> edgePropertyIterator = null; + Property edgeProperty = null; + + while (edges.hasNext()) { + edge = edges.next(); + edgePropertyIterator = edge.properties(); + while (edgePropertyIterator.hasNext()) { + edgeProperty = edgePropertyIterator.next(); + Object value = edgeProperty.value(); + String key = edgeProperty.key(); + if(value == null) + continue; + String type = getStringType(value); + if(type == null) + continue; + String id = key+"-"+type; + if (!edgeKeyTypes.containsKey(id)) { + edgeKeyTypes.put(id, new KeySpec(key, type)); + } + } + } + outputGraph(graph, graphMLOutputStream, vertexKeyTypes, edgeKeyTypes); + } + + /** + * Write the data in a Graph to a GraphML OutputStream. + * + * @param graph the Graph to pull the data from + * @param graphMLOutputStream the GraphML OutputStream to write the Graph data to + * @param vertexKeyTypes a Map of the data types of the vertex keys + * @param edgeKeyTypes a Map of the data types of the edge keys + * @throws XMLStreamException thrown if there is an error generating the GraphML data + */ + public static void outputGraph(final Graph graph, final OutputStream graphMLOutputStream, final Map vertexKeyTypes, final Map edgeKeyTypes) throws XMLStreamException { + XMLOutputFactory inputFactory = XMLOutputFactory.newInstance(); + XMLStreamWriter writer = inputFactory.createXMLStreamWriter(graphMLOutputStream, "UTF8"); + + writer.writeStartDocument("UTF-8", "1.0"); + writer.writeStartElement(GraphMLTokens.GRAPHML); + writer.writeAttribute(GraphMLTokens.XMLNS, GraphMLTokens.GRAPHML_XMLNS); + // + for (Map.Entry entry : vertexKeyTypes.entrySet()) { + writer.writeStartElement(GraphMLTokens.KEY); + writer.writeAttribute(GraphMLTokens.ID, entry.getKey()); + writer.writeAttribute(GraphMLTokens.FOR, GraphMLTokens.NODE); + writer.writeAttribute(GraphMLTokens.ATTR_NAME, entry.getValue().attrName); + writer.writeAttribute(GraphMLTokens.ATTR_TYPE, entry.getValue().attrType); + writer.writeEndElement(); + } + for (Map.Entry entry : edgeKeyTypes.entrySet()) { + writer.writeStartElement(GraphMLTokens.KEY); + writer.writeAttribute(GraphMLTokens.ID, entry.getKey()); + writer.writeAttribute(GraphMLTokens.FOR, GraphMLTokens.EDGE); + writer.writeAttribute(GraphMLTokens.ATTR_NAME, entry.getValue().attrName); + writer.writeAttribute(GraphMLTokens.ATTR_TYPE, entry.getValue().attrType); + writer.writeEndElement(); + } + + writer.writeStartElement(GraphMLTokens.GRAPH); + writer.writeAttribute(GraphMLTokens.ID, GraphMLTokens.G); + writer.writeAttribute(GraphMLTokens.EDGEDEFAULT, GraphMLTokens.DIRECTED); + Iterator vertices = graph.vertices(); + Vertex vertex = null; + Iterator> propertyIterator = null; + VertexProperty property = null; + while (vertices.hasNext()) { + vertex = vertices.next(); + writer.writeStartElement(GraphMLTokens.NODE); + writer.writeAttribute(GraphMLTokens.ID, vertex.id().toString()); + propertyIterator = vertex.properties(); + while (propertyIterator.hasNext()) { + property = propertyIterator.next(); + String key = property.key(); + writeData(writer, key, property.value()); + } + writer.writeEndElement(); + } + + Iterator edges = graph.edges(); + Edge edge = null; + Iterator> edgePropertyIterator = null; + Property edgeProperty = null; + + while (edges.hasNext()) { + edge = edges.next(); + edgePropertyIterator = edge.properties(); + writer.writeStartElement(GraphMLTokens.EDGE); + writer.writeAttribute(GraphMLTokens.ID, edge.id().toString()); + writer.writeAttribute(GraphMLTokens.SOURCE, edge.outVertex().id().toString()); + writer.writeAttribute(GraphMLTokens.TARGET, edge.inVertex().id().toString()); + writer.writeAttribute(GraphMLTokens.LABEL, edge.label()); + + while (edgePropertyIterator.hasNext()) { + edgeProperty = edgePropertyIterator.next(); + String key = edgeProperty.key(); + writeData(writer, key, edgeProperty.value()); + } + writer.writeEndElement(); + } + + writer.writeEndElement(); // graph + writer.writeEndElement(); // graphml + writer.writeEndDocument(); + + writer.flush(); + writer.close(); + + } + + /** + * Write data. + * + * @param writer the writer + * @param key the key + * @param value the value + * @throws XMLStreamException the XML stream exception + */ + private static void writeData(XMLStreamWriter writer, String key, Object value) throws XMLStreamException { + if(value == null) + return; + String type = getStringType(value); + if(type == null) + return; + String id = key+"-"+type; + + writer.writeStartElement(GraphMLTokens.DATA); + writer.writeAttribute(GraphMLTokens.KEY, id); + if(type.startsWith(GraphMLTokens.ARRAY) || + type.startsWith(GraphMLTokens.LIST) || + type.startsWith(GraphMLTokens.SET)) + writeDataArray(writer, value); + else + writer.writeCharacters(propertyValueToString(value)); + writer.writeEndElement(); + } + + /** + * Write data array. + * + * @param writer the writer + * @param value the value + * @throws XMLStreamException the XML stream exception + */ + private static void writeDataArray(XMLStreamWriter writer, Object value) throws XMLStreamException { + if(value.getClass().isArray()) { + for(int i = 0; i < Array.getLength(value); i++) { + writer.writeStartElement(GraphMLTokens.ITEM); + writer.writeCharacters(Array.get(value, i).toString()); + writer.writeEndElement(); + } + } + else if(value instanceof Collection) { + for(Object obj : ((Collection)value)) { + writer.writeStartElement(GraphMLTokens.ITEM); + writer.writeCharacters(obj.toString()); + writer.writeEndElement(); + } + } + } + + /** + * Gets the string type. + * + * @param object the object + * @return the string type + */ + private static String getStringType(final Object object) { + if(object.getClass().isArray()) + return GraphMLTokens.ARRAY+"-"+getStringType(object.getClass().getComponentType()); + if(object instanceof Collection) { + String colType; + if(object instanceof Set) + colType = GraphMLTokens.SET; + else if(object instanceof List) + colType = GraphMLTokens.LIST; + else + throw new RuntimeException("Unhandled Collection type: "+object.getClass()); + + Collection col = (Collection)object; + if(col.size() == 0) + return null; + return colType+"-"+getStringType(col.iterator().next()); + } + if (object instanceof String) + return GraphMLTokens.STRING; + else if (object instanceof Integer) + return GraphMLTokens.INT; + else if (object instanceof Long) + return GraphMLTokens.LONG; + else if (object instanceof Float) + return GraphMLTokens.FLOAT; + else if (object instanceof Double) + return GraphMLTokens.DOUBLE; + else if (object instanceof Boolean) + return GraphMLTokens.BOOLEAN; + else + throw new RuntimeException("Unsupported type: "+object.getClass()); + } + + /** + * Gets the string type. + * + * @param clazz the clazz + * @return the string type + */ + private static String getStringType(final Class clazz) { + if(clazz.equals(String.class)) + return GraphMLTokens.STRING; + else if(clazz.equals(Integer.TYPE) || clazz.equals(Integer.class)) + return GraphMLTokens.INT; + else if(clazz.equals(Long.TYPE) || clazz.equals(Long.class)) + return GraphMLTokens.LONG; + else if(clazz.equals(Float.TYPE) || clazz.equals(Float.class)) + return GraphMLTokens.FLOAT; + else if(clazz.equals(Double.TYPE) || clazz.equals(Double.class)) + return GraphMLTokens.DOUBLE; + else if(clazz.equals(Boolean.TYPE) || clazz.equals(Boolean.class)) + return GraphMLTokens.BOOLEAN; + else + throw new RuntimeException("Unsupported array item type: "+clazz); + } + + /** + * Property value to string. + * + * @param value the value + * @return the string + */ + private static String propertyValueToString(Object value) { + if(value == null) + return null; + + if(value.getClass().isArray()) { + String str = "["; + for(int i = 0; i < Array.getLength(value); i++) { + if(i > 0) + str += ", "; + str += Array.get(value, i); + } + str += "]"; + return str; + } + else if(value instanceof Collection) { + String str = "["; + int i = 0; + for(Object obj : ((Collection)value)) { + if(i > 0) + str += ", "; + str += obj.toString(); + i++; + } + str += "]"; + return str; + } + return value.toString(); + } + +} diff --git a/aai-resources/src/main/java/org/openecomp/aai/dbgen/PropertyNameChange.java b/aai-resources/src/main/java/org/openecomp/aai/dbgen/PropertyNameChange.java new file mode 100644 index 0000000..3f7f351 --- /dev/null +++ b/aai-resources/src/main/java/org/openecomp/aai/dbgen/PropertyNameChange.java @@ -0,0 +1,317 @@ +/*- + * ============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.Iterator; +import java.util.Properties; + +import org.apache.tinkerpop.gremlin.structure.Vertex; +import org.apache.tinkerpop.gremlin.structure.VertexProperty; + +import org.openecomp.aai.dbmap.AAIGraph; +import org.openecomp.aai.logging.ErrorLogHelper; +import org.openecomp.aai.util.AAIConfig; +import org.openecomp.aai.util.AAIConstants; +import com.att.eelf.configuration.Configuration; +import com.thinkaurelius.titan.core.PropertyKey; +import com.thinkaurelius.titan.core.TitanGraph; +import com.thinkaurelius.titan.core.TitanProperty; +import com.thinkaurelius.titan.core.TitanVertex; +import com.thinkaurelius.titan.core.schema.TitanManagement; + + +public class PropertyNameChange { + + /** + * The main method. + * + * @param args the arguments + */ + public static void main(String[] args) { + + // Set the logging file properties to be used by EELFManager + Properties props = System.getProperties(); + props.setProperty(Configuration.PROPERTY_LOGGING_FILE_NAME, AAIConstants.AAI_SCHEMA_MOD_LOGBACK_PROPS); + props.setProperty(Configuration.PROPERTY_LOGGING_FILE_PATH, AAIConstants.AAI_HOME_ETC_APP_PROPERTIES); + + // NOTE -- We're just working with properties that are used for NODES for now. + + TitanGraph graph = null; + TitanManagement graphMgt = null;; + Boolean preserveData = true; + String propName = ""; + String targetPropName = ""; + String targetNodeType = ""; + String skipCommit = ""; + boolean noCommit = false; + + + String usageString = "Usage: PropertyNameChange propertyName targetPropertyName nodeType(or NA) skipCommit(true|false) \n"; + if( args.length != 4 ){ + String emsg = "Four Parameters are required. \n" + usageString; + System.out.println( emsg ); + System.exit(1); + } + else { + propName = args[0]; + targetPropName = args[1]; + targetNodeType = args[2]; + skipCommit = args[3]; + if ( skipCommit.toLowerCase().equals("true")) + noCommit = true; + } + + if( propName.equals("") ){ + String emsg = "Bad parameter - propertyName cannot be empty. \n" + usageString; + System.out.println( emsg ); + System.exit(1); + } + + + + try { + AAIConfig.init(); + ErrorLogHelper.loadProperties(); + } + catch( Exception ae ){ + String emsg = "Problem with either AAIConfig.init() or ErrorLogHelper.LoadProperties(). "; + System.out.println( emsg + "[" + ae.getMessage() + "]"); + System.exit(1); + } + + + System.out.println(">>> Processing will begin in 5 seconds (unless interrupted). <<<"); + try { + // Give them a chance to back out of this + Thread.sleep(5000); + } catch ( java.lang.InterruptedException ie) { + System.out.println( " DB Schema Update has been aborted. "); + System.exit(1); + } + + try { + System.out.println(" ---- NOTE --- about to open graph (takes a little while)\n"); + + graph = AAIGraph.getInstance().getGraph(); + if( graph == null ){ + String emsg = "Not able to get a graph object in SchemaMod.java\n"; + System.out.println( emsg ); + System.exit(1); + } + + // Make sure this property is in the DB. + graphMgt = graph.openManagement(); + if( graphMgt == null ){ + String emsg = "Not able to get a graph Management object in SchemaMod.java\n"; + System.out.println( emsg ); + System.exit(1); + } + PropertyKey origPropKey = graphMgt.getPropertyKey(propName); + if( origPropKey == null ){ + String emsg = "The propName = [" + propName + "] is not defined in our graph. "; + System.out.println( emsg ); + System.exit(1); + } + origPropKey = graphMgt.getPropertyKey(targetPropName); + if( origPropKey == null ){ + String emsg = "The targetPropName = [" + targetPropName + "] is not defined in our graph. "; + System.out.println( emsg ); + System.exit(1); + } + + if ( !targetNodeType.equals("NA")) { + if ( graphMgt.getVertexLabel(targetNodeType) == null ) { + String emsg = "The targetNodeType = [" + targetNodeType + "] is not defined in our graph. "; + System.out.println( emsg ); + System.exit(1); + } + } + + // For each node that has this property, update the new from the old and then remove the + // old property from that node + Iterable verts = null; + int vtxCount = 0; + String label; + long longId; + + int propertyCount; + + Iterator> titanProperties = null; + + VertexProperty tmpProperty = null; + Object origVal; + Object targetVal; + + if ( targetNodeType.equals("NA")) { + verts= graph.query().has(propName).vertices(); + Iterator it = verts.iterator(); + + while( it.hasNext() ){ + + TitanVertex tmpVtx = (TitanVertex)it.next(); + String tmpVid = tmpVtx.id().toString(); + + origVal = tmpVtx.property(propName).orElse(null); + targetVal = tmpVtx.property(targetPropName).orElse(null); + + label = tmpVtx.label(); + longId = tmpVtx.longId(); + + if ( targetVal != null ) { + System.out.println( "vertex [" + label + "] id " + tmpVid + " has " + targetPropName + + " with value " + targetVal + ", skip adding with value " + origVal); + continue; + } + vtxCount++; + titanProperties = tmpVtx.properties(); // current properties + + propertyCount = 0; + + while( titanProperties.hasNext() ){ + + tmpProperty = titanProperties.next(); + + if ( propertyCount == 0 ) + System.out.print( "adding to [" + label + "] vertex id " + tmpVid + " with existing properties " + + tmpProperty.toString() ); + else + System.out.print(", " + tmpProperty.toString()); + ++propertyCount; + } + + if ( propertyCount > 0 ) { + System.out.println(""); + + tmpVtx.property(targetPropName,origVal); + System.out.println("INFO -- just did the add using " + longId + + " with label " + label + "] and updated it with the orig value (" + + origVal.toString() + ")"); + titanProperties = tmpVtx.properties(); // current properties + propertyCount = 0; + + + while( titanProperties.hasNext() ){ + tmpProperty = titanProperties.next(); + if ( propertyCount == 0 ) + System.out.print( "new property list for [" + label + "] vertex id " + tmpVid + " with existing properties " + + tmpProperty.toString() ); + else + System.out.print(", " + tmpProperty.toString()); + ++propertyCount; + } + + if ( propertyCount > 0 ) + System.out.println(""); + } + } + } else { + // targetNodeType is NA + + verts= graph.query().has("aai-node-type", targetNodeType).vertices(); + if( verts != null ){ + // We did find some matching vertices + Iterator it = verts.iterator(); + Object propVal; + while( it.hasNext() ){ + TitanVertex v = (TitanVertex)it.next(); + label = v.label(); + longId = v.longId(); + targetVal = v.property(targetPropName).orElse(null); + origVal = v.property(propName).orElse(null); + + if ( origVal == null) + continue; + + if ( targetVal != null ) { + System.out.println( "vertex [" + label + "] id " + longId + " has " + targetPropName + + " with value " + targetVal + ", skip adding with value " + origVal); + continue; + } + titanProperties = v.properties(); // current properties + propertyCount = 0; + if ( v.property(propName).orElse(null) != null ) { + propVal = v.property(propName).orElse(null); + v.property(targetPropName, propVal); + ++vtxCount; + while( titanProperties.hasNext() ){ + + tmpProperty = titanProperties.next(); + if ( propertyCount == 0 ) + System.out.print( "adding to vertex id " + longId + " with existing properties " + + tmpProperty.toString() ); + else + System.out.print(", " + tmpProperty.toString()); + ++propertyCount; + } + + if ( propertyCount > 0 ) + System.out.println(""); + System.out.println("INFO -- just did the add target [" + targetNodeType + "] using " + longId + + " with label " + label + "] and updated it with the orig value (" + + propVal.toString() + ")"); + propertyCount = 0; + while( titanProperties.hasNext() ){ + + tmpProperty = titanProperties.next(); + if ( propertyCount == 0 ) + System.out.print( "new property list for vertex [" + label + "] id " + longId + " with existing properties " + + tmpProperty.toString() ); + else + System.out.print(", " + tmpProperty.toString()); + ++propertyCount; + } + + if ( propertyCount > 0 ) + System.out.println(""); + } + } + } + + } + + System.out.println("added properties data for " + vtxCount + " vertexes. noCommit " + noCommit); + if ( !noCommit ) + graph.tx().commit(); + } + catch (Exception ex) { + System.out.print("Threw a regular Exception:\n"); + System.out.println(ex.getMessage()); + } + finally { + if( graphMgt != null && graphMgt.isOpen() ){ + // Any changes that worked correctly should have already done their commits. + graphMgt.rollback(); + } + if( graph != null ){ + // Any changes that worked correctly should have already done their commits. + graph.tx().rollback(); + graph.close(); + } + } + + System.exit(0); + + }// End of main() + + +} + + diff --git a/aai-resources/src/main/java/org/openecomp/aai/dbgen/SchemaMod.java b/aai-resources/src/main/java/org/openecomp/aai/dbgen/SchemaMod.java new file mode 100644 index 0000000..9cc6cf3 --- /dev/null +++ b/aai-resources/src/main/java/org/openecomp/aai/dbgen/SchemaMod.java @@ -0,0 +1,441 @@ +/*- + * ============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.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.Iterator; +import java.util.Properties; +import java.util.TimeZone; +import java.util.UUID; + +import org.apache.tinkerpop.gremlin.structure.Direction; +import org.apache.tinkerpop.gremlin.structure.Edge; +import org.apache.tinkerpop.gremlin.structure.Vertex; +import org.apache.tinkerpop.gremlin.structure.VertexProperty; +import org.slf4j.MDC; + +import org.openecomp.aai.dbmap.AAIGraph; +import org.openecomp.aai.exceptions.AAIException; +import org.openecomp.aai.ingestModel.DbMaps; +import org.openecomp.aai.ingestModel.IngestModelMoxyOxm; +import org.openecomp.aai.logging.ErrorLogHelper; +import org.openecomp.aai.util.AAIConfig; +import org.openecomp.aai.util.AAIConstants; +import org.openecomp.aai.util.UniquePropertyCheck; +import com.att.eelf.configuration.Configuration; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import com.thinkaurelius.titan.core.Cardinality; +import com.thinkaurelius.titan.core.PropertyKey; +import com.thinkaurelius.titan.core.TitanEdge; +import com.thinkaurelius.titan.core.TitanGraph; +import com.thinkaurelius.titan.core.TitanVertex; +import com.thinkaurelius.titan.core.schema.TitanManagement; + +public class SchemaMod { + + private static final String FROMAPPID = "AAI-UTILS"; + private static final String TRANSID = UUID.randomUUID().toString(); + private static final String COMPONENT = "SchemaMod"; + + /** + * The main method. + * + * @param args the arguments + */ + public static void main(String[] args) { + + SchemaMod.execute(args); + System.exit(0); + + }// End of main() + + /** + * Execute. + * + * @param args the args + */ + public static void execute(String[] args) { + + // Set the logging file properties to be used by EELFManager + Properties props = System.getProperties(); + props.setProperty(Configuration.PROPERTY_LOGGING_FILE_NAME, AAIConstants.AAI_SCHEMA_MOD_LOGBACK_PROPS); + props.setProperty(Configuration.PROPERTY_LOGGING_FILE_PATH, AAIConstants.AAI_HOME_ETC_APP_PROPERTIES); + + EELFLogger logger = EELFManager.getInstance().getLogger(UniquePropertyCheck.class.getSimpleName()); + MDC.put("logFilenameAppender", SchemaMod.class.getSimpleName()); + + // NOTE -- We're just working with properties that are used for NODES + // for now. + + TitanGraph graph = null; + TitanManagement graphMgt = null; + + Boolean preserveData = true; + String propName = ""; + String targetDataType = ""; + String targetIndexInfo = ""; + String preserveDataFlag = ""; + + String usageString = "Usage: SchemaMod propertyName targetDataType targetIndexInfo preserveDataFlag \n"; + if (args.length != 4) { + String emsg = "Four Parameters are required. \n" + usageString; + logAndPrint(logger, emsg); + System.exit(1); + } else { + propName = args[0]; + targetDataType = args[1]; + targetIndexInfo = args[2]; + preserveDataFlag = args[3]; + } + + if (propName.equals("")) { + String emsg = "Bad parameter - propertyName cannot be empty. \n" + usageString; + logAndPrint(logger, emsg); + System.exit(1); + } else if (!targetDataType.equals("String") && !targetDataType.equals("Set") + && !targetDataType.equals("Integer") && !targetDataType.equals("Long") + && !targetDataType.equals("Boolean")) { + String emsg = "Unsupported targetDataType. We only support String, Set, Integer, Long or Boolean for now.\n" + + usageString; + logAndPrint(logger, emsg); + System.exit(1); + } else if (!targetIndexInfo.equals("uniqueIndex") && !targetIndexInfo.equals("index") + && !targetIndexInfo.equals("noIndex")) { + String emsg = "Unsupported IndexInfo. We only support: 'uniqueIndex', 'index' or 'noIndex'.\n" + + usageString; + logAndPrint(logger, emsg); + System.exit(1); + } else { + if (preserveDataFlag.equals("true")) { + preserveData = true; + } else if (preserveDataFlag.equals("false")) { + preserveData = false; + } else { + String emsg = "Unsupported preserveDataFlag. We only support: 'true' or 'false'.\n" + usageString; + logAndPrint(logger, emsg); + System.exit(1); + } + } + + try { + AAIConfig.init(); + ErrorLogHelper.loadProperties(); + } catch (Exception ae) { + String emsg = "Problem with either AAIConfig.init() or ErrorLogHelper.LoadProperties(). "; + logAndPrint(logger, emsg + "[" + ae.getMessage() + "]"); + System.exit(1); + } + + DbMaps dbMaps = null; + try { + ArrayList apiVersions = new ArrayList(); + apiVersions.add(AAIConfig.get(AAIConstants.AAI_DEFAULT_API_VERSION_PROP)); + final IngestModelMoxyOxm m = new IngestModelMoxyOxm(); + m.init(apiVersions, false); + dbMaps = m.dbMapsContainer.get(AAIConfig.get(AAIConstants.AAI_DEFAULT_API_VERSION_PROP)); + } catch (AAIException ae) { + String emsg = "Could not instantiate a copy of DbMaps. "; + logAndPrint(logger, emsg + "[" + ae.getMessage() + "]"); + System.exit(1); + } catch (Exception e) { + String emsg = "exception, Could not instantiate a copy of DbMaps. "; + logAndPrint(logger, emsg + "[" + e.getMessage() + "]"); + System.exit(1); + } + // Give a big warning if the DbMaps.PropertyDataTypeMap value does not + // agree with what we're doing + String warningMsg = ""; + /*if (!dbMaps.PropertyDataTypeMap.containsKey(propName)) { + String emsg = "Property Name = [" + propName + "] not found in PropertyDataTypeMap. "; + logAndPrint(logger, emsg); + System.exit(1); + } else { + String currentDataType = dbMaps.PropertyDataTypeMap.get(propName); + if (!currentDataType.equals(targetDataType)) { + warningMsg = "TargetDataType [" + targetDataType + "] does not match what is in DbRules.java (" + + currentDataType + ")."; + } + }*/ + + if (!warningMsg.equals("")) { + logAndPrint(logger, "\n>>> WARNING <<<< "); + logAndPrint(logger, ">>> " + warningMsg + " <<<"); + } + + logAndPrint(logger, ">>> Processing will begin in 5 seconds (unless interrupted). <<<"); + try { + // Give them a chance to back out of this + Thread.sleep(5000); + } catch (java.lang.InterruptedException ie) { + logAndPrint(logger, " DB Schema Update has been aborted. "); + System.exit(1); + } + + try { + Class dType = null; + if (targetDataType.equals("String")) { + dType = String.class; + } else if (targetDataType.equals("Set")) { + dType = String.class; + } else if (targetDataType.equals("Integer")) { + dType = Integer.class; + } else if (targetDataType.equals("Boolean")) { + dType = Boolean.class; + } else if (targetDataType.equals("Character")) { + dType = Character.class; + } else if (targetDataType.equals("Long")) { + dType = Long.class; + } else if (targetDataType.equals("Float")) { + dType = Float.class; + } else if (targetDataType.equals("Double")) { + dType = Double.class; + } else { + String emsg = "Not able translate the targetDataType [" + targetDataType + "] to a Class variable.\n"; + logAndPrint(logger, emsg); + System.exit(1); + } + String cardinality = "SINGLE"; // Default cardinality to SINGLE + + if (targetDataType.equals("Set")) { + cardinality = "SET"; + } + logAndPrint(logger, " ---- NOTE --- about to open graph (takes a little while)\n"); + + graph = AAIGraph.getInstance().getGraph(); + if (graph == null) { + String emsg = "Not able to get a graph object in SchemaMod.java\n"; + logAndPrint(logger, emsg); + System.exit(1); + } + + // Make sure this property is in the DB. + graphMgt = graph.openManagement(); + if (graphMgt == null) { + String emsg = "Not able to get a graph Management object in SchemaMod.java\n"; + logAndPrint(logger, emsg); + System.exit(1); + } + PropertyKey origPropKey = graphMgt.getPropertyKey(propName); + if (origPropKey == null) { + String emsg = "The propName = [" + propName + "] is not defined in our graph. "; + logAndPrint(logger, emsg); + System.exit(1); + } + + if (targetIndexInfo.equals("uniqueIndex")) { + // Make sure the data in the property being changed can have a + // unique-index put on it. + // Ie. if there are duplicate values, we will not be able to + // migrate the data back into the property. + Boolean foundDupesFlag = UniquePropertyCheck.runTheCheckForUniqueness(TRANSID, FROMAPPID, + graph.newTransaction(), propName, logger); + if (foundDupesFlag) { + logAndPrint(logger, + "\n\n!!!!!! >> Cannot add a uniqueIndex for the property: [" + propName + + "] because duplicate values were found. See the log for details on which" + + " nodes have this value. \nThey will need to be resolved (by updating those values to new" + + " values or deleting unneeded nodes) using the standard REST-API \n"); + System.exit(1); + } + } + + // -------------- If we made it to here - we must be OK with making + // this change ------------ + + // Rename this property to a backup name (old name with "retired_" + // appended plus a dateStr) + + SimpleDateFormat d = new SimpleDateFormat("MMddHHmm"); + d.setTimeZone(TimeZone.getTimeZone("GMT")); + String dteStr = d.format(new Date()).toString(); + String retiredName = propName + "-" + dteStr + "-RETIRED"; + graphMgt.changeName(origPropKey, retiredName); + + // Create a new property using the original property name and the + // targetDataType + PropertyKey freshPropKey = graphMgt.makePropertyKey(propName).dataType(dType) + .cardinality(Cardinality.valueOf(cardinality)).make(); + + // Create the appropriate index (if any) + if (targetIndexInfo.equals("uniqueIndex")) { + String freshIndexName = propName + dteStr; + graphMgt.buildIndex(freshIndexName, Vertex.class).addKey(freshPropKey).unique().buildCompositeIndex(); + } else if (targetIndexInfo.equals("index")) { + String freshIndexName = propName + dteStr; + graphMgt.buildIndex(freshIndexName, Vertex.class).addKey(freshPropKey).buildCompositeIndex(); + } + + logAndPrint(logger, "Committing schema changes with graphMgt.commit()"); + graphMgt.commit(); + graph.tx().commit(); + + // Get A new graph object + logAndPrint(logger, " ---- NOTE --- about to open a second graph object (takes a little while)\n"); + + // For each node that has this property, update the new from the old + // and then remove the + // old property from that node + Iterable verts = null; + verts = graph.query().has(retiredName).vertices(); + Iterator it = verts.iterator(); + int vtxCount = 0; + ArrayList alreadySeenVals = new ArrayList(); + while (it.hasNext()) { + vtxCount++; + TitanVertex tmpVtx = (TitanVertex) it.next(); + String tmpVid = tmpVtx.id().toString(); + + Object origVal = tmpVtx. property(retiredName).orElse(null); + if (preserveData) { + tmpVtx.property(propName, origVal); + if (targetIndexInfo.equals("uniqueIndex")) { + // We're working on a property that is being used as a + // unique index + String origValStr = ""; + if (origVal != null) { + origValStr = origVal.toString(); + } + if (alreadySeenVals.contains(origValStr)) { + // This property is supposed to be unique, but we've + // already seen this value in this loop + // This should have been caught up in the first part + // of SchemaMod, but since it wasn't, we + // will just log the problem. + logAndPrint(logger, + "\n\n ---------- ERROR - could not migrate the old data [" + origValStr + + "] for propertyName [" + propName + + "] because this property is having a unique index put on it."); + showPropertiesAndEdges(TRANSID, FROMAPPID, tmpVtx, logger); + logAndPrint(logger, "-----------------------------------\n"); + } else { + // Ok to add this prop in as a unique value + tmpVtx.property(propName, origVal); + logAndPrint(logger, + "INFO -- just did the add of the freshPropertyKey and updated it with the orig value (" + + origValStr + ")"); + } + alreadySeenVals.add(origValStr); + } else { + // We are not working with a unique index + tmpVtx.property(propName, origVal); + logAndPrint(logger, + "INFO -- just did the add of the freshPropertyKey and updated it with the orig value (" + + origVal.toString() + ")"); + } + } else { + // existing nodes just won't have that property anymore + // Not sure if we'd ever actually want to do this -- maybe + // we'd do this if the new + // data type was not compatible with the old? + } + tmpVtx.property(retiredName).remove(); + + logAndPrint(logger, "INFO -- just did the remove of the " + retiredName + " from this vertex. (vid=" + + tmpVid + ")"); + } + + logAndPrint(logger, "Updated data for " + vtxCount + " vertexes. Now call graph2.commit(). "); + graph.tx().commit(); + } catch (Exception ex) { + logAndPrint(logger, "Threw a regular Exception: "); + logAndPrint(logger, ex.getMessage()); + } finally { + if (graphMgt != null && graphMgt.isOpen()) { + // Any changes that worked correctly should have already done + // their commits. + graphMgt.rollback(); + } + if (graph != null) { + // Any changes that worked correctly should have already done + // their commits. + graph.tx().rollback(); + graph.close(); + } + } + + } + + /** + * Show properties and edges. + * + * @param transId the trans id + * @param fromAppId the from app id + * @param tVert the t vert + * @param logger the logger + */ + private static void showPropertiesAndEdges(String transId, String fromAppId, TitanVertex tVert, EELFLogger logger) { + + if (tVert == null) { + logAndPrint(logger, "Null node passed to showPropertiesAndEdges."); + } else { + String nodeType = ""; + Object ob = tVert. property("aai-node-type"); + if (ob == null) { + nodeType = "null"; + } else { + nodeType = ob.toString(); + } + + logAndPrint(logger, " AAINodeType/VtxID for this Node = [" + nodeType + "/" + tVert.id() + "]"); + logAndPrint(logger, " Property Detail: "); + Iterator> pI = tVert.properties(); + while (pI.hasNext()) { + VertexProperty tp = pI.next(); + Object val = tp.value(); + logAndPrint(logger, "Prop: [" + tp.key() + "], val = [" + val + "] "); + } + + Iterator eI = tVert.edges(Direction.BOTH); + if (!eI.hasNext()) { + logAndPrint(logger, "No edges were found for this vertex. "); + } + while (eI.hasNext()) { + TitanEdge ed = (TitanEdge) eI.next(); + String lab = ed.label(); + TitanVertex vtx = (TitanVertex) ed.otherVertex(tVert); + if (vtx == null) { + logAndPrint(logger, + " >>> COULD NOT FIND VERTEX on the other side of this edge edgeId = " + ed.id() + " <<< "); + } else { + String nType = vtx. property("aai-node-type").orElse(null); + String vid = vtx.id().toString(); + logAndPrint(logger, "Found an edge (" + lab + ") from this vertex to a [" + nType + + "] node with VtxId = " + vid); + } + } + } + } // End of showPropertiesAndEdges() + + /** + * Log and print. + * + * @param logger the logger + * @param msg the msg + */ + protected static void logAndPrint(EELFLogger logger, String msg) { + System.out.println(msg); + logger.info(msg); + } + +} 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 new file mode 100644 index 0000000..c2ebf6f --- /dev/null +++ b/aai-resources/src/main/java/org/openecomp/aai/dbgen/UpdateEdgeTags.java @@ -0,0 +1,380 @@ +/*- + * ============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 org.apache.tinkerpop.gremlin.structure.Direction; +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.TitanEdge; +import com.thinkaurelius.titan.core.TitanGraph; +import com.thinkaurelius.titan.core.TitanTransaction; +import com.thinkaurelius.titan.core.TitanVertex; + + + +public class UpdateEdgeTags { + + private static final String FROMAPPID = "AAI-DB"; + private static final String TRANSID = UUID.randomUUID().toString(); + + /** + * The main method. + * + * @param args the arguments + */ + public static void main(String[] args) { + + if( args == null || args.length != 1 ){ + String msg = "usage: UpdateEdgeTags edgeRuleKey (edgeRuleKey can be either, all, or a rule key like 'nodeTypeA|nodeTypeB') \n"; + System.out.println(msg); + System.exit(1); + } + String edgeRuleKeyVal = args[0]; + + TitanGraph graph = null; + + HashMap edgeRuleHash = new HashMap (); + HashMap edgeRulesFullHash = new HashMap (); + HashMap edgeRuleLabelToKeyHash = new HashMap (); + ArrayList labelMapsToMultipleKeys = new 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 edgeRulesIterator = DbEdgeRules.EdgeRules.keySet().iterator(); + while( edgeRulesIterator.hasNext() ){ + String ruleKey = edgeRulesIterator.next(); + Collection edRuleColl = DbEdgeRules.EdgeRules.get(ruleKey); + Iterator 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]; + 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. + // So we take it out of mapping hash and add it to the list of ones that + // we'll need to look up later. + edgeRuleLabelToKeyHash.remove(edgeLabel); + labelMapsToMultipleKeys.add(edgeLabel); + } + else { + edgeRuleLabelToKeyHash.put(edgeLabel, ruleKey); + } + } + } + + 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 edRuleColl = DbEdgeRules.EdgeRules.get(edgeRuleKeyVal); + Iterator 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(); + edgeRuleHash.put(edgeRuleKeyVal, edRule); + System.out.println("Adding this rule to list of rules to do: key = " + edgeRuleKeyVal + ", rule = [" + edRule + "]"); + } + else { + String msg = " Error - Unrecognized edgeRuleKey: [" + edgeRuleKeyVal + "]. "; + System.out.println(msg); + System.exit(0); + } + } + else { + // They didn't pass a target ruleKey in, so we'll work on all types of edges + edgeRuleHash.putAll(edgeRulesFullHash); + } + + try { + AAIConfig.init(); + System.out.println(" ---- NOTE --- about to open graph (takes a little while)--------\n"); + ErrorLogHelper.loadProperties(); + + graph = AAIGraph.getInstance().getGraph(); + + if( graph == null ){ + String emsg = "null graph object in updateEdgeTags() \n"; + System.out.println(emsg); + System.exit(0); + } + } + catch (AAIException e1) { + String msg = e1.getErrorObject().toString(); + System.out.println(msg); + System.exit(0); + } + catch (Exception e2) { + String msg = e2.toString(); + System.out.println(msg); + e2.printStackTrace(); + System.exit(0); + } + + TitanTransaction g = graph.newTransaction(); + try { + Iterable edges = graph.query().edges(); + Iterator edgeItr = edges.iterator(); + + // Loop through all edges and update their tags if they are a type we are interested in. + // Sorry about looping over everything, but for now, I can't find a way to just select one type of edge at a time...!? + StringBuffer sb; + boolean missingEdge = false; + while( edgeItr != null && edgeItr.hasNext() ){ + TitanEdge tmpEd = (TitanEdge) edgeItr.next(); + String edLab = tmpEd.label().toString(); + + // Since we have edgeLabels that can be used for different pairs of node-types, we have to + // look to see what nodeTypes this edge is connecting (if it is a label that could do this). + String derivedEdgeKey = ""; + if( labelMapsToMultipleKeys.contains(edLab) ){ + // need to figure out which key is right for this edge + derivedEdgeKey = deriveEdgeRuleKeyForThisEdge( TRANSID, FROMAPPID, g, tmpEd ); + } + else { + // This kind of label only maps to one key -- so we can just look it up. + if ( edgeRuleLabelToKeyHash.get(edLab) == null ) { + if ( !missingEdge ) { + System.out.print("DEBUG - missing edge(s) in edgeRuleLabelToKeyHash " + edgeRuleLabelToKeyHash.toString()); + missingEdge = true; + } + sb = new StringBuffer(); + Vertex vIn = null; + Vertex vOut = null; + Object obj = null; + vIn = tmpEd.vertex(Direction.IN); + if ( vIn != null ){ + obj = vIn.property("aai-node-type").orElse(null); + if ( obj != null ) { + sb.append("from node-type " + obj.toString()); + + obj = vIn.id(); + sb.append(" id " + obj.toString()); + } else { + sb.append(" missing from node-type "); + } + } else { + sb.append(" missing inbound vertex "); + } + vOut = tmpEd.vertex(Direction.OUT); + if ( vOut != null ) { + obj = vOut.property("aai-node-type").orElse(null); + if ( obj != null ) { + sb.append(" to node-type " + obj.toString()); + obj = vOut.id(); + sb.append(" id " + obj.toString()); + } else { + sb.append(" missing to node-type "); + } + } else { + sb.append(" missing to vertex "); + } + System.out.println("DEBUG - null entry for [" + edLab + "] between " + sb.toString()); + continue; + } + derivedEdgeKey = edgeRuleLabelToKeyHash.get(edLab).toString(); + } + + if( edgeRuleHash.containsKey(derivedEdgeKey) ){ + // this is an edge that we want to update + System.out.print("DEBUG - key = " + derivedEdgeKey + ", label = " + edLab + + ", for id = " + tmpEd.id().toString() + ", set: "); + Map edgeRules = getEdgeTagPropPutHash(TRANSID, FROMAPPID, derivedEdgeKey); + for (String key : edgeRules.keySet()) { + if (tmpEd.label().equals(key)) { + EdgeRules.getInstance().addProperties(tmpEd, edgeRules.get(key)); + } + } + System.out.print("\n"); + } + } // End of looping over all edges + graph.tx().commit(); + System.out.println("DEBUG - committed updates for listed edges " ); + } + catch (Exception e2) { + String msg = e2.toString(); + System.out.println(msg); + e2.printStackTrace(); + if( graph != null ){ + graph.tx().rollback(); + } + System.exit(0); + } + + System.exit(0); + + }// end of main() + + + /** + * Derive edge rule key for this edge. + * + * @param transId the trans id + * @param fromAppId the from app id + * @param graph the graph + * @param tEdge the t edge + * @return String - key to look up edgeRule (fromNodeType|toNodeType) + * @throws AAIException the AAI exception + */ + public static String deriveEdgeRuleKeyForThisEdge( String transId, String fromAppId, TitanTransaction graph, + TitanEdge tEdge ) throws AAIException{ + + TitanVertex fromVtx = tEdge.outVertex(); + TitanVertex toVtx = tEdge.inVertex(); + String startNodeType = fromVtx.property("aai-node-type").orElse(null); + String targetNodeType = toVtx.property("aai-node-type").orElse(null); + String key = startNodeType + "|" + targetNodeType; + if( EdgeRules.getInstance().hasEdgeRule(startNodeType, targetNodeType) ){ + // We can use the node info in the order they were given + return( key ); + } + else { + key = targetNodeType + "|" + startNodeType; + if( EdgeRules.getInstance().hasEdgeRule(targetNodeType, startNodeType) ){ + return( key ); + } + else { + // Couldn't find a rule for this edge + 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 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 retEdgePropPutMap = new HashMap (); + + 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. + * + * @param transId the trans id + * @param fromAppId the from app id + * @param edgeRuleKey the edge rule key + * @return the edge tag prop put hash + * @throws AAIException the AAI exception + */ + public static Map 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. + // Note - this code is also used by the updateEdgeTags.java code + + 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 + "."); + } + + Map edgeRules = EdgeRules.getInstance().getEdgeRules(edgeRuleKeys[0], edgeRuleKeys[1]); + + return edgeRules; + + } // End of getEdgeTagPropPutHash() + + + +} + + + diff --git a/aai-resources/src/main/java/org/openecomp/aai/dmaap/AAIDmaapEventJMSConsumer.java b/aai-resources/src/main/java/org/openecomp/aai/dmaap/AAIDmaapEventJMSConsumer.java index fc11e5d..c016bb1 100644 --- a/aai-resources/src/main/java/org/openecomp/aai/dmaap/AAIDmaapEventJMSConsumer.java +++ b/aai-resources/src/main/java/org/openecomp/aai/dmaap/AAIDmaapEventJMSConsumer.java @@ -126,7 +126,7 @@ public class AAIDmaapEventJMSConsumer implements MessageListener { //String aaiEvent = ""; //String eventName = ""; - + //String environment = ""; //if (message instanceof TextMessage) { diff --git a/aai-resources/src/main/java/org/openecomp/aai/migration/EventAction.java b/aai-resources/src/main/java/org/openecomp/aai/migration/EventAction.java new file mode 100644 index 0000000..82b7cad --- /dev/null +++ b/aai-resources/src/main/java/org/openecomp/aai/migration/EventAction.java @@ -0,0 +1,27 @@ +/*- + * ============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.migration; + +public enum EventAction { + CREATE, + UPDATE, + DELETE +} diff --git a/aai-resources/src/main/java/org/openecomp/aai/migration/NotificationHelper.java b/aai-resources/src/main/java/org/openecomp/aai/migration/NotificationHelper.java new file mode 100644 index 0000000..b956705 --- /dev/null +++ b/aai-resources/src/main/java/org/openecomp/aai/migration/NotificationHelper.java @@ -0,0 +1,103 @@ +/*- + * ============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.migration; + +import java.io.UnsupportedEncodingException; +import java.net.URI; +import java.util.HashMap; +import java.util.List; + +import javax.ws.rs.core.Response.Status; + +import org.apache.tinkerpop.gremlin.structure.Vertex; + +import org.openecomp.aai.exceptions.AAIException; +import org.openecomp.aai.introspection.Introspector; +import org.openecomp.aai.introspection.Loader; +import org.openecomp.aai.introspection.exceptions.AAIUnknownObjectException; +import org.openecomp.aai.rest.ueb.UEBNotification; +import org.openecomp.aai.serialization.db.DBSerializer; +import org.openecomp.aai.serialization.engines.TransactionalGraphEngine; +import org.openecomp.aai.serialization.engines.query.QueryEngine; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +public class NotificationHelper { + + private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(NotificationHelper.class); + protected final DBSerializer serializer; + protected final Loader loader; + protected final TransactionalGraphEngine engine; + protected final String transactionId; + protected final String sourceOfTruth; + protected final UEBNotification notification; + + public NotificationHelper(Loader loader, DBSerializer serializer, TransactionalGraphEngine engine, String transactionId, String sourceOfTruth) { + this.loader = loader; + this.serializer = serializer; + this.engine = engine; + this.transactionId = transactionId; + this.sourceOfTruth = sourceOfTruth; + this.notification = new UEBNotification(loader); + } + + public void addEvent(Vertex v, Introspector obj, EventAction action, URI uri) throws UnsupportedEncodingException, AAIException { + HashMap relatedObjects = new HashMap<>(); + Status status = mapAction(action); + if (!obj.isTopLevel()) { + relatedObjects = this.getRelatedObjects(serializer, engine.getQueryEngine(), v); + } + notification.createNotificationEvent(transactionId, sourceOfTruth, status, uri, obj, relatedObjects); + + } + + private HashMap getRelatedObjects(DBSerializer serializer, QueryEngine queryEngine, Vertex v) throws AAIException { + HashMap relatedVertices = new HashMap<>(); + List vertexChain = queryEngine.findParents(v); + for (Vertex vertex : vertexChain) { + try { + final Introspector vertexObj = serializer.getVertexProperties(vertex); + relatedVertices.put(vertexObj.getObjectId(), vertexObj); + } catch (AAIUnknownObjectException | UnsupportedEncodingException e) { + LOGGER.warn("Unable to get vertex properties, partial list of related vertices returned"); + } + + } + + return relatedVertices; + } + + private Status mapAction(EventAction action) { + if (EventAction.CREATE.equals(action)) { + return Status.CREATED; + } else if (EventAction.UPDATE.equals(action)) { + return Status.OK; + } else if (EventAction.DELETE.equals(action)) { + return Status.NO_CONTENT; + } else { + return Status.OK; + } + } + + public void triggerEvents() throws AAIException { + notification.triggerEvents(); + } +} diff --git a/aai-resources/src/main/java/org/openecomp/aai/migration/VertexMerge.java b/aai-resources/src/main/java/org/openecomp/aai/migration/VertexMerge.java new file mode 100644 index 0000000..6bb17a9 --- /dev/null +++ b/aai-resources/src/main/java/org/openecomp/aai/migration/VertexMerge.java @@ -0,0 +1,245 @@ +/*- + * ============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.migration; + +import java.io.UnsupportedEncodingException; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Map; +import java.util.Optional; +import java.util.Set; + +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; +import org.apache.tinkerpop.gremlin.structure.Vertex; + +import org.openecomp.aai.db.props.AAIProperties; +import org.openecomp.aai.exceptions.AAIException; +import org.openecomp.aai.introspection.Introspector; +import org.openecomp.aai.introspection.Loader; +import org.openecomp.aai.introspection.exceptions.AAIUnknownObjectException; +import org.openecomp.aai.serialization.db.DBSerializer; +import org.openecomp.aai.serialization.db.EdgeRules; +import org.openecomp.aai.serialization.db.EdgeType; +import org.openecomp.aai.serialization.engines.TransactionalGraphEngine; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +/** + * This class recursively merges two vertices passed in. + *
+ * You can start with any two vertices, but after the vertices are merged based off the equality of their keys + * + */ +public class VertexMerge { + + private final EELFLogger logger = EELFManager.getInstance().getLogger(this.getClass().getSimpleName()); + + private final GraphTraversalSource g; + private final TransactionalGraphEngine engine; + private final DBSerializer serializer; + private final EdgeRules rules; + private final Loader loader; + private final NotificationHelper notificationHelper; + private final boolean hasNotifications; + private VertexMerge(Builder builder) { + this.engine = builder.getEngine(); + this.serializer = builder.getSerializer(); + this.g = engine.asAdmin().getTraversalSource(); + this.rules = EdgeRules.getInstance(); + this.loader = builder.getLoader(); + this.notificationHelper = builder.getHelper(); + this.hasNotifications = builder.isHasNotifications(); + } + + /** + * Merges vertices. forceCopy is a map of the form [{aai-node-type}:{set of properties}] + * @param primary + * @param secondary + * @param forceCopy + * @throws AAIException + * @throws UnsupportedEncodingException + */ + public void performMerge(Vertex primary, Vertex secondary, Map> forceCopy) throws AAIException, UnsupportedEncodingException { + final Optional secondarySnapshot; + if (this.hasNotifications) { + secondarySnapshot = Optional.of(serializer.getLatestVersionView(secondary)); + } else { + secondarySnapshot = Optional.empty(); + } + mergeProperties(primary, secondary, forceCopy); + + Collection secondaryChildren = this.engine.getQueryEngine().findChildren(secondary); + Collection primaryChildren = this.engine.getQueryEngine().findChildren(primary); + + mergeChildren(primary, secondary, primaryChildren, secondaryChildren, forceCopy); + + Collection secondaryCousins = this.engine.getQueryEngine().findCousinVertices(secondary); + Collection primaryCousins = this.engine.getQueryEngine().findCousinVertices(primary); + + secondaryCousins.removeAll(primaryCousins); + logger.info("removing vertex after merge: " + secondary ); + if (this.hasNotifications && secondarySnapshot.isPresent()) { + this.notificationHelper.addEvent(secondary, secondarySnapshot.get(), EventAction.DELETE, this.serializer.getURIForVertex(secondary, false)); + } + secondary.remove(); + for (Vertex v : secondaryCousins) { + this.rules.addEdgeIfPossible(g, v, primary); + } + if (this.hasNotifications) { + final Introspector primarySnapshot = serializer.getLatestVersionView(primary); + this.notificationHelper.addEvent(primary, primarySnapshot, EventAction.UPDATE, this.serializer.getURIForVertex(primary, false)); + } + } + + /** + * This method may go away if we choose to event on each modification performed + * @param primary + * @param secondary + * @param forceCopy + * @throws AAIException + * @throws UnsupportedEncodingException + */ + protected void performMergeHelper(Vertex primary, Vertex secondary, Map> forceCopy) throws AAIException, UnsupportedEncodingException { + mergeProperties(primary, secondary, forceCopy); + + Collection secondaryChildren = this.engine.getQueryEngine().findChildren(secondary); + Collection primaryChildren = this.engine.getQueryEngine().findChildren(primary); + + mergeChildren(primary, secondary, primaryChildren, secondaryChildren, forceCopy); + + Collection secondaryCousins = this.engine.getQueryEngine().findCousinVertices(secondary); + Collection primaryCousins = this.engine.getQueryEngine().findCousinVertices(primary); + + secondaryCousins.removeAll(primaryCousins); + secondary.remove(); + for (Vertex v : secondaryCousins) { + this.rules.addEdgeIfPossible(g, v, primary); + } + } + + private String getURI(Vertex v) throws UnsupportedEncodingException, AAIException { + Introspector obj = loader.introspectorFromName(v.property(AAIProperties.NODE_TYPE).orElse("")); + this.serializer.dbToObject(Collections.singletonList(v), obj, 0, true, "false"); + return obj.getURI(); + + } + private void mergeChildren(Vertex primary, Vertex secondary, Collection primaryChildren, Collection secondaryChildren, Map> forceCopy) throws UnsupportedEncodingException, AAIException { + Map primaryMap = uriMap(primaryChildren); + Map secondaryMap = uriMap(secondaryChildren); + Set primaryKeys = new HashSet<>(primaryMap.keySet()); + Set secondaryKeys = new HashSet<>(secondaryMap.keySet()); + primaryKeys.retainAll(secondaryKeys); + final Set mergeItems = new HashSet<>(primaryKeys); + primaryKeys = new HashSet<>(primaryMap.keySet()); + secondaryKeys = new HashSet<>(secondaryMap.keySet()); + secondaryKeys.removeAll(primaryKeys); + final Set copyItems = new HashSet<>(secondaryKeys); + + for (String key : mergeItems) { + this.performMergeHelper(primaryMap.get(key), secondaryMap.get(key), forceCopy); + } + + for (String key : copyItems) { + this.rules.addTreeEdgeIfPossible(g, secondaryMap.get(key), primary); + this.serializer.getEdgeBetween(EdgeType.TREE, secondary, secondaryMap.get(key)).remove(); + } + + } + + private Map uriMap(Collection vertices) throws UnsupportedEncodingException, AAIException { + final Map result = new HashMap<>(); + for (Vertex v : vertices) { + result.put(getURI(v), v); + } + return result; + } + + private void mergeProperties(Vertex primary, Vertex secondary, Map> forceCopy) throws AAIUnknownObjectException { + final String primaryType = primary.property(AAIProperties.NODE_TYPE).orElse(""); + final String secondaryType = secondary.property(AAIProperties.NODE_TYPE).orElse(""); + + final Introspector secondaryObj = loader.introspectorFromName(secondaryType); + secondary.properties().forEachRemaining(prop -> { + if (!primary.property(prop.key()).isPresent() || forceCopy.getOrDefault(primaryType, new HashSet()).contains(prop.key())) { + primary.property(prop.key(), prop.value()); + } + if (primary.property(prop.key()).isPresent() && secondary.property(prop.key()).isPresent() && secondaryObj.isListType(prop.key())) { + mergeCollection(primary, prop.key(), secondary.values(prop.key())); + } + }); + } + private void mergeCollection(Vertex primary, String propName, Iterator secondaryValues) { + secondaryValues.forEachRemaining(item -> { + primary.property(propName, item); + }); + } + + + public static class Builder { + private final TransactionalGraphEngine engine; + + private final DBSerializer serializer; + private final Loader loader; + private NotificationHelper helper = null; + private boolean hasNotifications = false; + public Builder(Loader loader, TransactionalGraphEngine engine, DBSerializer serializer) { + this.loader = loader; + this.engine = engine; + this.serializer = serializer; + } + + public Builder addNotifications(NotificationHelper helper) { + this.helper = helper; + this.hasNotifications = true; + return this; + } + + + public VertexMerge build() { + return new VertexMerge(this); + } + + protected TransactionalGraphEngine getEngine() { + return engine; + } + + protected DBSerializer getSerializer() { + return serializer; + } + + protected Loader getLoader() { + return loader; + } + + protected NotificationHelper getHelper() { + return helper; + } + + protected boolean isHasNotifications() { + return hasNotifications; + } + + } + +} diff --git a/aai-resources/src/main/java/org/openecomp/aai/rest/LegacyMoxyConsumer.java b/aai-resources/src/main/java/org/openecomp/aai/rest/LegacyMoxyConsumer.java index 7af432d..ca5fc33 100644 --- a/aai-resources/src/main/java/org/openecomp/aai/rest/LegacyMoxyConsumer.java +++ b/aai-resources/src/main/java/org/openecomp/aai/rest/LegacyMoxyConsumer.java @@ -140,6 +140,7 @@ public class LegacyMoxyConsumer extends RESTAPI { dbEngine = httpEntry.getDbEngine(); URI uriObject = UriBuilder.fromPath(uri).build(); + this.validateURI(uriObject); QueryParser uriQuery = dbEngine.getQueryBuilder().createQueryFromURI(uriObject); @@ -421,7 +422,8 @@ public class LegacyMoxyConsumer extends RESTAPI { throw new AAIException("AAI_3102", "You must supply a relationship"); } URI uriObject = UriBuilder.fromPath(uri).build(); - + this.validateURI(uriObject); + QueryParser uriQuery = dbEngine.getQueryBuilder().createQueryFromURI(uriObject); Introspector wrappedEntity = loader.unmarshal("relationship", content, org.openecomp.aai.restcore.MediaType.getEnum(this.getInputMediaType(inputMediaType))); @@ -524,7 +526,6 @@ public class LegacyMoxyConsumer extends RESTAPI { Boolean success = true; try { - validateRequest(info); version = Version.valueOf(versionParam); @@ -533,7 +534,7 @@ public class LegacyMoxyConsumer extends RESTAPI { loader = httpEntry.getLoader(); dbEngine = httpEntry.getDbEngine(); URI uriObject = UriBuilder.fromPath(uri).build(); - + this.validateURI(uriObject); QueryParser uriQuery = dbEngine.getQueryBuilder().createQueryFromURI(uriObject); String objName = uriQuery.getResultType(); if (content.length() == 0) { @@ -580,4 +581,14 @@ public class LegacyMoxyConsumer extends RESTAPI { return response; } + private void validateURI(URI uri) throws AAIException { + if (hasRelatedTo(uri)) { + throw new AAIException("AAI_3010"); + } + } + private boolean hasRelatedTo(URI uri) { + + return uri.toString().contains("/" + RestTokens.COUSIN + "/"); + + } } diff --git a/aai-resources/src/main/java/org/openecomp/aai/rest/RestTokens.java b/aai-resources/src/main/java/org/openecomp/aai/rest/RestTokens.java new file mode 100644 index 0000000..13bfe65 --- /dev/null +++ b/aai-resources/src/main/java/org/openecomp/aai/rest/RestTokens.java @@ -0,0 +1,36 @@ +/*- + * ============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.rest; + +public enum RestTokens { + + COUSIN("related-to"); + private final String name; + + private RestTokens(String name) { + this.name = name; + } + + @Override + public String toString() { + return name; + } +} diff --git a/aai-resources/src/main/java/org/openecomp/aai/rest/retired/V7V8Models.java b/aai-resources/src/main/java/org/openecomp/aai/rest/retired/V7V8Models.java new file mode 100644 index 0000000..3eb53da --- /dev/null +++ b/aai-resources/src/main/java/org/openecomp/aai/rest/retired/V7V8Models.java @@ -0,0 +1,28 @@ +/*- + * ============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.rest.retired; + +import javax.ws.rs.Path; + +@Path("{version: v[78]}/service-design-and-creation/models") +public class V7V8Models extends RetiredConsumer { + +} diff --git a/aai-resources/src/main/java/org/openecomp/aai/rest/retired/V7V8NamedQueries.java b/aai-resources/src/main/java/org/openecomp/aai/rest/retired/V7V8NamedQueries.java new file mode 100644 index 0000000..3f022a2 --- /dev/null +++ b/aai-resources/src/main/java/org/openecomp/aai/rest/retired/V7V8NamedQueries.java @@ -0,0 +1,28 @@ +/*- + * ============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.rest.retired; + +import javax.ws.rs.Path; + +@Path("{version: v[78]}/service-design-and-creation/named-queries") +public class V7V8NamedQueries extends RetiredConsumer { + +} diff --git a/aai-resources/src/main/java/org/openecomp/aai/rest/ueb/NotificationEvent.java b/aai-resources/src/main/java/org/openecomp/aai/rest/ueb/NotificationEvent.java index 389d296..e473e9d 100644 --- a/aai-resources/src/main/java/org/openecomp/aai/rest/ueb/NotificationEvent.java +++ b/aai-resources/src/main/java/org/openecomp/aai/rest/ueb/NotificationEvent.java @@ -31,12 +31,13 @@ import org.openecomp.aai.util.StoreNotificationEvent; */ public class NotificationEvent { - private Loader loader = null; + private final Loader loader; - private Introspector eventHeader = null; - - private Introspector obj = null; + private final Introspector eventHeader; + private final Introspector obj; + private final String transactionId; + private final String sourceOfTruth; /** * Instantiates a new notification event. * @@ -44,10 +45,12 @@ public class NotificationEvent { * @param eventHeader the event header * @param obj the obj */ - public NotificationEvent (Loader loader, Introspector eventHeader, Introspector obj) { + public NotificationEvent (Loader loader, Introspector eventHeader, Introspector obj, String transactionId, String sourceOfTruth) { this.loader = loader; this.eventHeader = eventHeader; this.obj = obj; + this.transactionId = transactionId; + this.sourceOfTruth = sourceOfTruth; } /** @@ -57,7 +60,7 @@ public class NotificationEvent { */ public void trigger() throws AAIException { - StoreNotificationEvent sne = new StoreNotificationEvent(); + StoreNotificationEvent sne = new StoreNotificationEvent(transactionId, sourceOfTruth); sne.storeEvent(loader, eventHeader, obj); diff --git a/aai-resources/src/main/java/org/openecomp/aai/rest/ueb/UEBNotification.java b/aai-resources/src/main/java/org/openecomp/aai/rest/ueb/UEBNotification.java index 397082f..8cb16e1 100644 --- a/aai-resources/src/main/java/org/openecomp/aai/rest/ueb/UEBNotification.java +++ b/aai-resources/src/main/java/org/openecomp/aai/rest/ueb/UEBNotification.java @@ -50,7 +50,6 @@ public class UEBNotification { private Loader currentVersionLoader = null; protected List events = null; - private String urlBase = null; private Version notificationVersion = null; /** @@ -61,7 +60,6 @@ public class UEBNotification { public UEBNotification(Loader loader) { events = new ArrayList<>(); currentVersionLoader = LoaderFactory.createLoaderForVersion(loader.getModelType(), AAIProperties.LATEST); - urlBase = AAIConfig.get("aai.server.url.base",""); notificationVersion = Version.valueOf(AAIConfig.get("aai.notification.current.version","v10")); } @@ -78,7 +76,7 @@ public class UEBNotification { * @throws IllegalArgumentException the illegal argument exception * @throws UnsupportedEncodingException the unsupported encoding exception */ - public void createNotificationEvent(String transactionId, String sourceOfTruth, Status status, URI uri, Introspector obj, HashMap relatedObjects) throws AAIException, IllegalArgumentException, UnsupportedEncodingException { + public void createNotificationEvent(String transactionId, String sourceOfTruth, Status status, URI uri, Introspector obj, HashMap relatedObjects) throws AAIException, UnsupportedEncodingException { String action = "UPDATE"; @@ -96,9 +94,9 @@ public class UEBNotification { String entityLink = ""; if (uri.toString().startsWith("/")) { - entityLink = urlBase + notificationVersion + uri; + entityLink = "/aai/" + notificationVersion + uri; } else { - entityLink = urlBase + notificationVersion + "/" + uri; + entityLink = "/aai/" + notificationVersion + "/" + uri; } @@ -148,7 +146,7 @@ public class UEBNotification { } } - final NotificationEvent event = new NotificationEvent(currentVersionLoader, eventHeader, eventObject); + final NotificationEvent event = new NotificationEvent(currentVersionLoader, eventHeader, eventObject, transactionId, sourceOfTruth); events.add(event); } catch (AAIUnknownObjectException e) { throw new RuntimeException("Fatal error - notification-event-header object not found!"); diff --git a/aai-resources/src/main/java/org/openecomp/aai/util/DataConversionHelper.java b/aai-resources/src/main/java/org/openecomp/aai/util/DataConversionHelper.java new file mode 100644 index 0000000..c1d601d --- /dev/null +++ b/aai-resources/src/main/java/org/openecomp/aai/util/DataConversionHelper.java @@ -0,0 +1,63 @@ +/*- + * ============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.util; + + +/** + * Utility to convert data from one form to another + * + */ +public class DataConversionHelper { + + public static final String IPVERSION_IPV4 = "ipv4"; + public static final String IPVERSION_IPV6 = "ipv6"; + public static final String IPVERSION_UNKNOWN = "unknown"; + + /** + * Instantiates a new data conversion helper. + */ + public DataConversionHelper() { } + + /** + * Convert from 4 or 6 to ipv4 or ipv6. Returns unknown if 4 or 6 not passed. + * @param numVal expects good input but won't error if that's not what's passed + * @return IPVERSION constant, . + * @see org.openecomp.aai.domain.yang.IpVersion + */ + public static String convertIPVersionNumToString(String numVal) { + if ("4".equals(numVal)) return IPVERSION_IPV4; + else if ("6".equals(numVal))return IPVERSION_IPV6; + else return IPVERSION_UNKNOWN; + } + + /** + * Convert from ipv4 or ipv6 to 4 or 6. Returns 0 on bad input. + * @param stringVal expects good input but won't error if that's not what's passed + * @return 4 or 6, or 0 if a bad string is sent. + * @see org.openecomp.aai.domain.yang.IpVersion + */ + public static String convertIPVersionStringToNum(String stringVal) { + if (IPVERSION_IPV4.equals(stringVal)) return "4"; + else if (IPVERSION_IPV6.equals(stringVal)) return "6"; + else return "0"; + } + +} diff --git a/aai-resources/src/main/java/org/openecomp/aai/util/DeleteResource.java b/aai-resources/src/main/java/org/openecomp/aai/util/DeleteResource.java index 81ee621..5e60c5c 100644 --- a/aai-resources/src/main/java/org/openecomp/aai/util/DeleteResource.java +++ b/aai-resources/src/main/java/org/openecomp/aai/util/DeleteResource.java @@ -41,7 +41,7 @@ import com.google.common.base.CaseFormat; public class DeleteResource { - private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(DeleteResource.class); + private static EELFLogger LOGGER; private static final String FROMAPPID = "AAI-TOOLS"; private static final String TRANSID = UUID.randomUUID().toString(); // the logic below to parse the url is dependent on the node types @@ -64,7 +64,7 @@ public class DeleteResource { Properties props = System.getProperties(); props.setProperty(Configuration.PROPERTY_LOGGING_FILE_NAME, AAIConstants.AAI_DELTOOL_LOGBACK_PROPS); props.setProperty(Configuration.PROPERTY_LOGGING_FILE_PATH, AAIConstants.AAI_HOME_ETC_APP_PROPERTIES); - + LOGGER = EELFManager.getInstance().getLogger(DeleteResource.class); String url = null; try { if ((args.length < 1) || ((args.length > 1) )) { @@ -113,8 +113,12 @@ public class DeleteResource { String resourceClass = CaseFormat.LOWER_HYPHEN.to(CaseFormat.UPPER_CAMEL, resource); resourceClass = "org.openecomp.aai.domain.yang." + resourceClass; - LOGGER.debug("class=" + resourceClass); - LOGGER.debug("path=" + path); + String dMsg = "class=" + resourceClass; + System.out.println(dMsg); + LOGGER.debug(dMsg); + dMsg = "path=" + path; + System.out.println(dMsg); + LOGGER.debug(dMsg); if (bResVersionEnabled) { @@ -127,7 +131,9 @@ public class DeleteResource { { RestController.Get(t, FROMAPPID, TRANSID, path, restObj, false); t = restObj.get(); - LOGGER.info(" GET resoruceversion succeeded\n"); + String infMsg = " GET resoruceversion succeeded\n"; + System.out.println(infMsg); + LOGGER.info(infMsg); String resourceUpdateVersion = GetResourceVersion(t); path += "?resource-version=" + resourceUpdateVersion; } catch (AAIException e) { @@ -150,12 +156,14 @@ public class DeleteResource { String confirm = s.next(); if (!confirm.equalsIgnoreCase("y")) { - LOGGER.info("User chose to exit before deleting"); + String infMsg = "User chose to exit before deleting"; + System.out.println(infMsg); + LOGGER.info(infMsg); System.exit(1); } RestController.Delete(FROMAPPID, TRANSID, path); - + s.close(); System.exit(0); diff --git a/aai-resources/src/main/java/org/openecomp/aai/util/GetResource.java b/aai-resources/src/main/java/org/openecomp/aai/util/GetResource.java index f16efb3..a0a3297 100644 --- a/aai-resources/src/main/java/org/openecomp/aai/util/GetResource.java +++ b/aai-resources/src/main/java/org/openecomp/aai/util/GetResource.java @@ -36,7 +36,7 @@ import com.sun.jersey.api.client.ClientResponse; public class GetResource { - private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(GetResource.class); + private static EELFLogger LOGGER; private static final String FROMAPPID = "AAI-TOOLS"; private static final String TRANSID = UUID.randomUUID().toString(); private static final String USAGE_STRING = "Usage: getTool.sh \n + " @@ -53,7 +53,7 @@ public class GetResource { Properties props = System.getProperties(); props.setProperty(Configuration.PROPERTY_LOGGING_FILE_NAME, AAIConstants.AAI_GETRES_LOGBACK_PROPS); props.setProperty(Configuration.PROPERTY_LOGGING_FILE_PATH, AAIConstants.AAI_HOME_ETC_APP_PROPERTIES); - + LOGGER = EELFManager.getInstance().getLogger(GetResource.class); String url = null; try { if (args.length < 1) { @@ -66,16 +66,23 @@ public class GetResource { url = args[0].replaceFirst("^/", ""); url = AAIConfig.get(AAIConstants.AAI_SERVER_URL) + url; - LOGGER.debug("url=" + url); + String dmsg = "url=" + url; + LOGGER.debug( dmsg ); + System.out.println( dmsg ); + getNode(url); System.exit(0); } } catch (AAIException e) { - LOGGER.error("GET failed: " + e.getMessage()); + String emsg = "GET failed: " + e.getMessage(); + System.out.println(emsg); + LOGGER.error(emsg); ErrorLogHelper.logException(e); System.exit(1); } catch (Exception e) { - LOGGER.error("GET failed: " + e.getMessage()); + String emsg = "GET failed: " + e.getMessage(); + System.out.println(emsg); + LOGGER.error(emsg); ErrorLogHelper.logError("AAI_7402", e.getMessage()); System.exit(1); } @@ -113,8 +120,10 @@ public class GetResource { .get(ClientResponse.class); if (cres.getStatus() == 404) { // resource not found - LOGGER.info("\nResource does not exist: " + cres.getStatus() - + ":" + cres.getEntity(String.class)); + String infmsg = "\nResource does not exist: " + cres.getStatus() + + ":" + cres.getEntity(String.class); + System.out.println(infmsg); + LOGGER.info(infmsg); throw new AAIException("AAI_7404", "Resource does not exist"); } else if (cres.getStatus() == 200){ String msg = cres.getEntity(String.class); @@ -122,10 +131,13 @@ public class GetResource { Object json = mapper.readValue(msg, Object.class); String indented = mapper.writerWithDefaultPrettyPrinter() .writeValueAsString(json); + System.out.println(indented); LOGGER.info(indented); } else { - LOGGER.error("Getting the Resource failed: " + cres.getStatus() - + ":\n" + cres.getEntity(String.class)); + String emsg = "Getting the Resource failed: " + cres.getStatus() + + ":\n" + cres.getEntity(String.class); + System.out.println(emsg); + LOGGER.error(emsg); throw new AAIException("AAI_7402", "Error during GET"); } } catch (AAIException e) { diff --git a/aai-resources/src/main/java/org/openecomp/aai/util/HttpsAuthClient.java b/aai-resources/src/main/java/org/openecomp/aai/util/HttpsAuthClient.java index 89562f7..000ebd0 100644 --- a/aai-resources/src/main/java/org/openecomp/aai/util/HttpsAuthClient.java +++ b/aai-resources/src/main/java/org/openecomp/aai/util/HttpsAuthClient.java @@ -176,4 +176,62 @@ public class HttpsAuthClient{ } + + public static Client getClient() throws KeyManagementException { + + ClientConfig config = new DefaultClientConfig(); + config.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE); + config.getClasses().add(org.openecomp.aai.restcore.CustomJacksonJaxBJsonProvider.class); + + SSLContext ctx = null; + try { + String truststore_path = AAIConstants.AAI_HOME_ETC_AUTH + AAIConfig.get(AAIConstants.AAI_TRUSTSTORE_FILENAME); + String truststore_password = AAIConfig.get(AAIConstants.AAI_TRUSTSTORE_PASSWD); + String keystore_path = AAIConstants.AAI_HOME_ETC_AUTH + AAIConfig.get(AAIConstants.AAI_KEYSTORE_FILENAME); + String keystore_password = AAIConfig.get(AAIConstants.AAI_KEYSTORE_PASSWD); + + System.setProperty("javax.net.ssl.trustStore", truststore_path); + System.setProperty("javax.net.ssl.trustStorePassword", truststore_password); + HttpsURLConnection.setDefaultHostnameVerifier( new HostnameVerifier(){ + public boolean verify(String string,SSLSession ssls) { + return true; + } + }); + + ctx = SSLContext.getInstance("TLSv1.2"); + KeyManagerFactory kmf = null; + try { + kmf = KeyManagerFactory.getInstance("SunX509"); + FileInputStream fin = new FileInputStream(keystore_path); + KeyStore ks = KeyStore.getInstance("PKCS12"); + char[] pwd = keystore_password.toCharArray(); + ks.load(fin, pwd); + kmf.init(ks, pwd); + } catch (Exception e) { + System.out.println("Error setting up kmf: exiting"); + e.printStackTrace(); + System.exit(1); + } + + ctx.init(kmf.getKeyManagers(), null, null); + config.getProperties().put(HTTPSProperties.PROPERTY_HTTPS_PROPERTIES, + new HTTPSProperties( new HostnameVerifier() { + @Override + public boolean verify( String s, SSLSession sslSession ) { + return true; + } + }, ctx)); + } catch (Exception e) { + System.out.println("Error setting up config: exiting"); + e.printStackTrace(); + System.exit(1); + } + + Client client = Client.create(config); + // uncomment this line to get more logging for the request/response + // client.addFilter(new LoggingFilter(System.out)); + + return client; + } + } diff --git a/aai-resources/src/main/java/org/openecomp/aai/util/JettyObfuscationConversionCommandLineUtil.java b/aai-resources/src/main/java/org/openecomp/aai/util/JettyObfuscationConversionCommandLineUtil.java new file mode 100644 index 0000000..befa59c --- /dev/null +++ b/aai-resources/src/main/java/org/openecomp/aai/util/JettyObfuscationConversionCommandLineUtil.java @@ -0,0 +1,99 @@ +/*- + * ============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.util; + +import org.apache.commons.cli.BasicParser; +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.CommandLineParser; +import org.apache.commons.cli.Options; +import org.apache.commons.cli.ParseException; +import org.eclipse.jetty.util.security.Password; + +import org.openecomp.aai.exceptions.AAIException; + +/* + * The purpose of this class is to be a tool for + * manually applying jetty obfuscation/deobfuscation + * so that one can obfuscate the various passwords/secrets + * in aaiconfig.properties. + * + * Originally, they were being encrypted by a similar + * command line utility, however the encryption key + * was being hardcoded in the src package + * which is a security violation. + * Since this ultimately just moved the problem of how + * to hide secrets to a different secret in a different file, + * and since that encryption was really just being done to + * obfuscate those values in case someone needed to look at + * properties with others looking at their screen, + * we decided that jetty obfuscation would be adequate + * for that task as well as + * removing the "turtles all the way down" secret-to-hide- + * the-secret-to-hide-the-secret problem. + */ +public class JettyObfuscationConversionCommandLineUtil { + + /** + * The main method. + * + * @param args the arguments + */ + public static void main(String[] args){ + Options options = new Options(); + options.addOption("e", true, "obfuscate the given string"); + options.addOption("d", true, "deobfuscate the given string"); + + CommandLineParser parser = new BasicParser(); + + try { + CommandLine cmd = parser.parse(options, args); + String toProcess = null; + + if (cmd.hasOption("e")){ + toProcess = cmd.getOptionValue("e"); + String encoded = Password.obfuscate(toProcess); + System.out.println(encoded); + } else if (cmd.hasOption("d")) { + toProcess = cmd.getOptionValue("d"); + String decoded_str = Password.deobfuscate(toProcess); + System.out.println(decoded_str); + } else { + usage(); + } + } catch (ParseException e) { + System.out.println("failed to parse input"); + System.out.println(e.toString()); + usage(); + } catch (Exception e) { + System.out.println("exception:" + e.toString()); + } + } + + /** + * Usage. + */ + private static void usage(){ + System.out.println("usage:");; + System.out.println("-e [string] to obfuscate"); + System.out.println("-d [string] to deobfuscate"); + System.out.println("-h help"); + } +} diff --git a/aai-resources/src/main/java/org/openecomp/aai/util/PostResource.java b/aai-resources/src/main/java/org/openecomp/aai/util/PostResource.java index 72fcd86..1caeb09 100644 --- a/aai-resources/src/main/java/org/openecomp/aai/util/PostResource.java +++ b/aai-resources/src/main/java/org/openecomp/aai/util/PostResource.java @@ -41,7 +41,7 @@ import com.google.common.base.CaseFormat; */ public class PostResource { - private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(PostResource.class); + private static EELFLogger LOGGER; private static final String FROMAPPID = "AAI-TOOLS"; private static final String TRANSID = UUID.randomUUID().toString(); private static final String USAGE_STRING = "Usage: postTool.sh \n" + @@ -61,7 +61,7 @@ public class PostResource { Properties props = System.getProperties(); props.setProperty(Configuration.PROPERTY_LOGGING_FILE_NAME, AAIConstants.AAI_POSTTOOL_LOGBACK_PROPS); props.setProperty(Configuration.PROPERTY_LOGGING_FILE_PATH, AAIConstants.AAI_HOME_ETC_APP_PROPERTIES); - + LOGGER = EELFManager.getInstance().getLogger(PostResource.class); try { if (args.length < 2) { System.out.println("Insufficient arguments"); @@ -85,8 +85,13 @@ public class PostResource { System.exit(1); } - LOGGER.debug("class=" + resourceClass); - LOGGER.debug("path=" + path); + String dMsg = "class=" + resourceClass; + System.out.println(dMsg); + LOGGER.debug(dMsg); + + dMsg = "path=" + path; + System.out.println(dMsg); + LOGGER.debug(dMsg); @SuppressWarnings("unchecked") T resJson1 = (T)readJsonFile(Class.forName(resourceClass), args[1]); @@ -95,9 +100,17 @@ public class PostResource { ObjectMapper mapper = new ObjectMapper(); Object json = mapper.readValue(response, Object.class); - LOGGER.info(" POST succeeded\n"); - LOGGER.info("Response = " + mapper.writer().withDefaultPrettyPrinter().writeValueAsString(json)); - LOGGER.info("\nDone!!"); + String infMsg = " POST succeeded\n"; + System.out.println(infMsg); + LOGGER.info(infMsg); + + infMsg = "Response = " + mapper.writer().withDefaultPrettyPrinter().writeValueAsString(json); + System.out.println(infMsg); + LOGGER.info(infMsg); + + infMsg = "\nDone!!"; + System.out.println(infMsg); + LOGGER.info(infMsg); System.exit(0); diff --git a/aai-resources/src/main/java/org/openecomp/aai/util/PutResource.java b/aai-resources/src/main/java/org/openecomp/aai/util/PutResource.java index 70fccb1..b4275b7 100644 --- a/aai-resources/src/main/java/org/openecomp/aai/util/PutResource.java +++ b/aai-resources/src/main/java/org/openecomp/aai/util/PutResource.java @@ -48,7 +48,7 @@ import com.sun.jersey.api.client.ClientResponse; */ public class PutResource { - private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(PutResource.class); + private static EELFLogger LOGGER; private static final String FROMAPPID = "AAI-TOOLS"; private static final String TRANSID = UUID.randomUUID().toString(); private static final String USAGE_STRING = "Usage: putTool.sh \n" + @@ -74,7 +74,7 @@ public class PutResource { Properties props = System.getProperties(); props.setProperty(Configuration.PROPERTY_LOGGING_FILE_NAME, AAIConstants.AAI_PUTTOOL_LOGBACK_PROPS); props.setProperty(Configuration.PROPERTY_LOGGING_FILE_PATH, AAIConstants.AAI_HOME_ETC_APP_PROPERTIES); - + LOGGER = EELFManager.getInstance().getLogger(PutResource.class); Boolean bResVersionEnabled = false; try @@ -144,16 +144,21 @@ public class PutResource { LOGGER.debug("url=" + url); if ( nodeExists( url) ) { - LOGGER.info("PUT succeeded, the resource exists already in the DB. Skipping the put based on the skipIfExists command line parameter.\n"); - System.exit(0); + String infMsg ="PUT succeeded, the resource exists already in the DB. Skipping the put based on the skipIfExists command line parameter.\n"; + System.out.println(infMsg); + LOGGER.info(infMsg); + System.exit(0); } - } RestController.Get(t2, FROMAPPID, TRANSID, path, restObj, false); t2 = restObj.get(); - LOGGER.info(" GET succeeded\n"); + String infMsg = " GET succeeded\n"; + System.out.println(infMsg); + LOGGER.info(infMsg); + } catch (AAIException e) { - if ( !doPutIfExists ) { + if ( !doPutIfExists ) { + System.out.println("Warning - Caught exception while attempting to PUT resource"); LOGGER.warn("Caught exception while attempting to PUT resource", e); } bExist = false; @@ -161,6 +166,7 @@ public class PutResource { catch (Exception e1) { if ( !doPutIfExists ) { + System.out.println("Warning - GET exception ignored with skipExists parameter\n"); LOGGER.warn(" GET exception ignored with skipExists parameter\n", e1); } bExist = false; @@ -177,17 +183,24 @@ public class PutResource { String DBresourceVersion = GetResourceVersion(t2); if ( !doPutIfExists ) { - LOGGER.info("PUT succeeded, the resource exists already in the DB. Skipping the put based on the skipIfExists command line parameter.\n"); - System.exit(0); + String infMsg = "PUT succeeded, the resource exists already in the DB. Skipping the put based on the skipIfExists command line parameter.\n"; + System.out.println(infMsg); + LOGGER.info(infMsg); + System.exit(0); } if (resourceUpdateVersion == null || resourceUpdateVersion.isEmpty()) { - if ( DBresourceVersion != null && !DBresourceVersion.isEmpty()) - LOGGER.error("The resource with version = " + DBresourceVersion + " exists already in the DB. Please supply the right resourceVersion in input data file.\n"); - else - LOGGER.error("The resource exists already in the DB. Please supply the right resourceVersion in input data file.\n"); - + if ( DBresourceVersion != null && !DBresourceVersion.isEmpty()){ + String eMsg = "The resource with version = " + DBresourceVersion + " exists already in the DB. Please supply the right resourceVersion in input data file.\n"; + System.out.println(eMsg); + LOGGER.error(eMsg); + } + else{ + String eMsg = "The resource exists already in the DB. Please supply the right resourceVersion in input data file.\n"; + System.out.println(eMsg); + LOGGER.error(eMsg); + } System.exit(1); } @@ -196,7 +209,9 @@ public class PutResource { if ( resourceUpdateVersion != null && !resourceUpdateVersion.isEmpty() ) if (!DBresourceVersion.equals(resourceUpdateVersion)) { - LOGGER.error("DB version doesn't match current version. Please get the latest version and modify.\n"); + String eMsg = "DB version doesn't match current version. Please get the latest version and modify.\n"; + System.out.println(eMsg); + LOGGER.error(eMsg); System.exit(1); } } @@ -205,8 +220,10 @@ public class PutResource { { if ( bResVersionEnabled && resourceUpdateVersion != null && !resourceUpdateVersion.isEmpty()) { - LOGGER.error("DB doesn't have this resource any more. Please create a new version by taking out the resourceVersion tag from your input resource data file.\n"); - System.exit(1); + String eMsg = "DB doesn't have this resource any more. Please create a new version by taking out the resourceVersion tag from your input resource data file.\n"; + System.out.println(eMsg); + LOGGER.error(eMsg); + System.exit(1); } } @@ -247,8 +264,12 @@ public class PutResource { RestController.Put(resJson1, FROMAPPID, TRANSID, path, false); - LOGGER.info(" PUT succeeded"); - LOGGER.info("Done!!"); + String infMsg = " PUT succeeded"; + System.out.println(infMsg); + LOGGER.info(infMsg); + infMsg = "Done!!"; + System.out.println(infMsg); + LOGGER.info(infMsg); System.exit(0); @@ -256,8 +277,13 @@ public class PutResource { if ( !doPutIfExists ) { // ignore 412 failure if ( e.getMessage().equals("AAI_7116") ) { if ( e.getMessage().indexOf("status=412") > 0) { - LOGGER.info("PUT succeeded, return 412 ignored\n"); - LOGGER.info("\nDone!!"); + String infMsg = "PUT succeeded, return 412 ignored\n"; + System.out.println(infMsg); + LOGGER.info(infMsg); + + infMsg = "\nDone!!"; + System.out.println(infMsg); + LOGGER.info(infMsg); System.exit(0); } } @@ -383,12 +409,14 @@ public class PutResource { client = HttpsAuthClient.getTwoWaySSLClient(); } - LOGGER.info("Getting the resource...: " + url); - + String infMsg = "Getting the resource...: " + url; + System.out.println(infMsg); + LOGGER.info(infMsg); + ClientResponse cres = client.resource(url) .header("X-TransactionId", TRANSID) .header("X-FromAppId", FROMAPPID) - .header("Authorization", HttpsAuthClient.getBasicAuthHeaderValue()) + .header("Authorization", HttpsAuthClient.getBasicAuthHeaderValue()) .accept("application/json") .get(ClientResponse.class); @@ -398,9 +426,11 @@ public class PutResource { } else if (cres.getStatus() == 200){ return true; } else { - LOGGER.error("Getting the Resource failed: " + cres.getStatus() - + ": " + cres.getEntity(String.class)); - return false; + String eMsg = "Getting the Resource failed: " + cres.getStatus() + + ": " + cres.getEntity(String.class); + System.out.println(eMsg); + LOGGER.error(eMsg); + return false; } } catch (KeyManagementException e) { throw new AAIException("AAI_7401", e, "Error during GET"); diff --git a/aai-resources/src/main/java/org/openecomp/aai/util/RelationshipPutDel.java b/aai-resources/src/main/java/org/openecomp/aai/util/RelationshipPutDel.java new file mode 100644 index 0000000..a6a21ca --- /dev/null +++ b/aai-resources/src/main/java/org/openecomp/aai/util/RelationshipPutDel.java @@ -0,0 +1,211 @@ +/*- + * ============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.util; + +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; +import java.security.KeyManagementException; +import java.util.Properties; +import java.util.UUID; + +import org.openecomp.aai.domain.yang.Relationship; +import org.openecomp.aai.exceptions.AAIException; +import com.att.eelf.configuration.Configuration; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import com.sun.jersey.api.client.Client; +import com.sun.jersey.api.client.ClientResponse; + + +public class RelationshipPutDel { + + private static final String FROMAPPID = "AAI-TOOLS"; + private static final String TRANSID = UUID.randomUUID().toString(); + private static EELFLogger LOGGER; + private static final String USAGE_STRING = "Usage: rshipTool.sh \n" + + "resource-path for a particular resource starting after the aai/, relationship-list/relationship gets added by script\n" + + "filename is the path to a file which contains the json input for the relationship payload" + + "for example: relTool.sh PUT cloud-infrastructure/oam-networks/oam-network/test-100-oam /tmp/putrship.json\n"; + + /** + * The main method. + * + * @param args the arguments + */ + public static void main(String[] args) { + + // Set the logging file properties to be used by EELFManager + Properties props = System.getProperties(); + props.setProperty(Configuration.PROPERTY_LOGGING_FILE_NAME, AAIConstants.AAI_RSHIPTOOL_LOGBACK_PROPS); + props.setProperty(Configuration.PROPERTY_LOGGING_FILE_PATH, AAIConstants.AAI_HOME_ETC_APP_PROPERTIES); + LOGGER = EELFManager.getInstance().getLogger(RelationshipPutDel.class); + String dMsg = "Start processing..."; + System.out.println(dMsg); + LOGGER.debug(dMsg); + + String rshipURL, resURL = null; + Relationship rship = null; + + try { + if ((args.length < 3) || (!args[0].equalsIgnoreCase("PUT") && !args[0].equalsIgnoreCase("DELETE"))) { + System.out.println("Insufficient or Invalid arguments"); + System.out.println(USAGE_STRING); + System.exit(1); + } + + rship = readJsonFile(args[2]); + + // Assume the config AAI_SERVER_URL has a last slash so remove if + // resource-path has it as the first char + resURL = args[1].replaceFirst("^/", ""); + resURL = AAIConfig.get(AAIConstants.AAI_SERVER_URL) + resURL; + rshipURL = resURL.concat("/relationship-list/relationship"); + + dMsg = "Resource URL=" + rshipURL; + System.out.println(dMsg); + LOGGER.debug(dMsg); + + PutDelRelationship(rshipURL, rship, args[0]); + + String infMsg = args[0] + " Relationship succeeded to: " + rship.getRelatedTo() + "\n"; + System.out.println(infMsg); + LOGGER.info(infMsg); + + GetResource.getNode(resURL); + infMsg = "Done!!"; + System.out.println(infMsg); + LOGGER.info(infMsg); + + System.exit(0); + + } catch (AAIException e) { + LOGGER.error(args[0] + " Relationship PUT/DELETE failed", e); + System.out.println(args[0] + " Relationship PUT/DELETE failed"); + System.exit(1); + } catch (Exception e) { + LOGGER.error(args[0] + " Relationship PUT/DELETE failed", e); + System.out.println(args[0] + " Relationship PUT/DELETE failed"); + System.exit(1); + } + } + + /** + * Read json file. + * + * @param fName the f name + * @return the relationship + * @throws AAIException the AAI exception + */ + public static Relationship readJsonFile( String fName ) throws AAIException { + String jsonData = ""; + BufferedReader br = null; + Relationship rship = new Relationship(); + + try { + String line; + br = new BufferedReader(new FileReader(fName)); + while ((line = br.readLine()) != null) { + jsonData += line + "\n"; + } + } catch (IOException e) { + throw new AAIException("AAI_7403", e, "Error opening json file"); + } finally { + try { + if (br != null) + br.close(); + } catch (IOException ex) { + throw new AAIException("AAI_7403", ex, "Error closing json file"); + } + } + + try { + rship = MapperUtil.readWithDashesAsObjectOf(Relationship.class, jsonData); + } + catch (Exception je){ + throw new AAIException("AAI_7403", je, "Error parsing json file"); + } + + return rship; + + }//End readJsonFile() + + + /** + * Put del relationship. + * + * @param aaiLogger the aai logger + * @param logline the logline + * @param rshipURL the rship URL + * @param rship the rship + * @param action the action + * @throws AAIException the AAI exception + */ + public static void PutDelRelationship(String rshipURL, + Relationship rship, + String action) throws AAIException{ + try { + Client client = HttpsAuthClient.getClient(); + ClientResponse cres = null; + + if (action.equalsIgnoreCase("PUT")) + cres = client.resource(rshipURL) + .header("X-TransactionId", TRANSID) + .header("X-FromAppId", FROMAPPID) + .accept("application/json") + .entity(rship) + .put(ClientResponse.class); + else + cres = client.resource(rshipURL) + .header("X-TransactionId", TRANSID) + .header("X-FromAppId", FROMAPPID) + .accept("application/json") + .entity(rship) + .delete(ClientResponse.class); + + if (cres.getStatus() == 404) { // resource not found + String infMsg = "Resource does not exist...: " + cres.getStatus() + + ":\n" + cres.getEntity(String.class); + System.out.println(infMsg); + LOGGER.info(infMsg); + throw new AAIException("AAI_7404", "Resource does not exist"); + } else if ((action.equalsIgnoreCase("PUT") && cres.getStatus() == 200) || + (action.equalsIgnoreCase("DELETE") && cres.getStatus() == 204)) { + String infMsg = action + " Resource status: " + cres.getStatus(); + System.out.println(infMsg); + LOGGER.info(infMsg); + } else { + String eMsg = action + " Resource failed: " + cres.getStatus() + + ":\n" + cres.getEntity(String.class); + System.out.println(eMsg); + LOGGER.error(eMsg); + throw new AAIException("AAI_7402", "Error during PutDel"); + } + } catch (AAIException e) { + throw e; + } catch (KeyManagementException e) { + throw new AAIException("AAI_7401", "Error during PutDel"); + } catch (Exception e) { + throw new AAIException("AAI_7402", "Error during PutDel"); + } + } + +} diff --git a/aai-resources/src/main/java/org/openecomp/aai/util/StoreNotificationEvent.java b/aai-resources/src/main/java/org/openecomp/aai/util/StoreNotificationEvent.java index ea674ed..181627b 100644 --- a/aai-resources/src/main/java/org/openecomp/aai/util/StoreNotificationEvent.java +++ b/aai-resources/src/main/java/org/openecomp/aai/util/StoreNotificationEvent.java @@ -25,20 +25,17 @@ import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Iterator; -import java.util.List; -import java.util.Map; import java.util.UUID; import javax.xml.bind.Marshaller; -import org.apache.cxf.helpers.CastUtils; -import org.apache.cxf.message.Message; -import org.apache.cxf.phase.PhaseInterceptorChain; import org.eclipse.persistence.dynamic.DynamicEntity; import org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext; import org.json.JSONException; import org.json.JSONObject; + import org.openecomp.aai.dmaap.AAIDmaapEventJMSProducer; +import org.openecomp.aai.domain.notificationEvent.NotificationEvent; import org.openecomp.aai.exceptions.AAIException; import org.openecomp.aai.introspection.Introspector; import org.openecomp.aai.introspection.Loader; @@ -49,31 +46,90 @@ public class StoreNotificationEvent { private AAIDmaapEventJMSProducer messageProducer; private String fromAppId = ""; private String transId = ""; - + private final String transactionId; + private final String sourceOfTruth; /** * Instantiates a new store notification event. */ - public StoreNotificationEvent() { + public StoreNotificationEvent(String transactionId, String sourceOfTruth) { this.messageProducer = new AAIDmaapEventJMSProducer(); - Message inMessage = PhaseInterceptorChain.getCurrentMessage().getExchange().getInMessage(); - Map> headersList = CastUtils.cast((Map) inMessage.get(Message.PROTOCOL_HEADERS)); - if (headersList != null) { - List xt = headersList.get("X-TransactionId"); - if (xt != null) { - for (String transIdValue : xt) { - transId = transIdValue; - } - } - List fa = headersList.get("X-FromAppId"); - if (fa != null) { - for (String fromAppIdValue : fa) { + this.transactionId = transactionId; + this.sourceOfTruth = sourceOfTruth; + } - fromAppId = fromAppIdValue; - } - } + /** + * Store event. + * + * @param eh + * the eh + * @param obj + * the obj + * @throws AAIException + * the AAI exception + */ + public void storeEvent(NotificationEvent.EventHeader eh, Object obj) throws AAIException { + + if (obj == null) { + throw new AAIException("AAI_7350"); } - } + org.openecomp.aai.domain.notificationEvent.ObjectFactory factory = new org.openecomp.aai.domain.notificationEvent.ObjectFactory(); + + org.openecomp.aai.domain.notificationEvent.NotificationEvent ne = factory.createNotificationEvent(); + + if (eh.getId() == null) { + eh.setId(genDate2() + "-" + UUID.randomUUID().toString()); + } + if (eh.getTimestamp() == null) { + eh.setTimestamp(genDate()); + } + + // there's no default, but i think we want to put this in hbase? + + if (eh.getEntityLink() == null) { + eh.setEntityLink("UNK"); + } + + if (eh.getAction() == null) { + eh.setAction("UNK"); + } + + if (eh.getEventType() == null) { + eh.setEventType(AAIConfig.get("aai.notificationEvent.default.eventType", "UNK")); + } + + if (eh.getDomain() == null) { + eh.setDomain(AAIConfig.get("aai.notificationEvent.default.domain", "UNK")); + } + + if (eh.getSourceName() == null) { + eh.setSourceName(AAIConfig.get("aai.notificationEvent.default.sourceName", "UNK")); + } + + if (eh.getSequenceNumber() == null) { + eh.setSequenceNumber(AAIConfig.get("aai.notificationEvent.default.sequenceNumber", "UNK")); + } + + if (eh.getSeverity() == null) { + eh.setSeverity(AAIConfig.get("aai.notificationEvent.default.severity", "UNK")); + } + + if (eh.getVersion() == null) { + eh.setVersion(AAIConfig.get("aai.notificationEvent.default.version", "UNK")); + } + + ne.setCambriaPartition(AAIConstants.UEB_PUB_PARTITION_AAI); + ne.setEventHeader(eh); + ne.setEntity(obj); + + try { + PojoUtils pu = new PojoUtils(); + String entityJson = pu.getJsonFromObject(ne); + sendToDmaapJmsQueue(entityJson); + } catch (Exception e) { + throw new AAIException("AAI_7350", e); + } + } /** * Store dynamic event. diff --git a/aai-resources/src/main/java/org/openecomp/aai/util/UpdateResource.java b/aai-resources/src/main/java/org/openecomp/aai/util/UpdateResource.java index adecfb1..1597a7b 100644 --- a/aai-resources/src/main/java/org/openecomp/aai/util/UpdateResource.java +++ b/aai-resources/src/main/java/org/openecomp/aai/util/UpdateResource.java @@ -35,7 +35,7 @@ import com.att.eelf.configuration.EELFManager; public class UpdateResource { - private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(UpdateResource.class.getName()); + private static EELFLogger LOGGER; private static final String FROMAPPID = "AAIUPDT"; private static final String TRANSID = UUID.randomUUID().toString(); private static final String UPDATE_URL = "actions/update"; @@ -59,7 +59,7 @@ public class UpdateResource { Properties props = System.getProperties(); props.setProperty(Configuration.PROPERTY_LOGGING_FILE_NAME, AAIConstants.AAI_UPDTOOL_LOGBACK_PROPS); props.setProperty(Configuration.PROPERTY_LOGGING_FILE_PATH, AAIConstants.AAI_HOME_ETC_APP_PROPERTIES); - + LOGGER = EELFManager.getInstance().getLogger(UpdateResource.class.getName()); try { if (args.length < 3) { System.out.println("Nothing to update or Insufficient arguments"); @@ -76,9 +76,11 @@ public class UpdateResource { System.exit(0); } catch (AAIException e) { + System.out.println("Error - Update Failed."); ErrorLogHelper.logException(e); System.exit(1); } catch (Exception e) { + System.out.println("Error - Update Failed." + e.getMessage()); ErrorLogHelper.logError("AAI_7402", "Update failed: " + e.getMessage()); System.exit(1); } @@ -113,10 +115,16 @@ public class UpdateResource { update.getAction().add(action); - LOGGER.info("updating the resource... "); - + String infMsg = "updating the resource... "; + System.out.println(infMsg); + LOGGER.info(infMsg); + RestController.Put(update, FROMAPPID, TRANSID, UPDATE_URL); - LOGGER.info("Update Successful"); + + infMsg = "Update Successful"; + System.out.println(infMsg); + LOGGER.info(infMsg); + } catch (AAIException e) { throw e; } catch (Exception e) { diff --git a/aai-resources/src/main/scripts/PropertyChangeName.sh b/aai-resources/src/main/scripts/PropertyChangeName.sh new file mode 100644 index 0000000..af61403 --- /dev/null +++ b/aai-resources/src/main/scripts/PropertyChangeName.sh @@ -0,0 +1,83 @@ +#!/bin/ksh + +### +# ============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========================================================= +### + +# +# This script is used to add a target property name with the same value in the database schema +# to a vertex which has an existing property. The existing property is not removed. +# +# Note also - This script just makes changes to the schema that is currently live. +# If you were to create a new schema in a brandy-new environment, it would look like +# whatever the oxm (as of July 2016) told it to look like. So, part of making a +# change to the db schema should Always first be to make the change in the oxm so that +# future environments will have the change. This script is just to change existing +# instances of the schema since schemaGenerator (as of July 2015) does not update things - it +# just does the initial creation. +# +# To use this script, you need to pass four parameters: +# propertyName -- the name of the property that has the value to be used in the targetProperty +# targetPropertyName -- the name of the targetProperty +# targetNodeType -- NA if all propertyName instances in the DB are impacted, otherwise limit the change to this nodeType +# skipCommit -- true or false. For testing, skips the commit when set to true. +# +# Ie. propertyNameChange service-id persona-model-id service-instance true +# + +echo +echo `date` " Starting $0" + + +userid=$( id | cut -f2 -d"(" | cut -f1 -d")" ) +if [ "${userid}" != "aaiadmin" ]; then + echo "You must be aaiadmin to run $0. The id used $userid." + exit 1 +fi + + +if [ "$#" -ne 4 ]; then + echo "Illegal number of parameters" + echo "usage: $0 propertyName targetPropertyName targetNodeType skipCommit" + exit 1 +fi + +. /etc/profile.d/aai.sh +PROJECT_HOME=/opt/app/aai-resources + +for JAR in `ls $PROJECT_HOME/extJars/*.jar` +do + CLASSPATH=$CLASSPATH:$JAR +done + +for JAR in `ls $PROJECT_HOME/lib/*.jar` +do + CLASSPATH=$CLASSPATH:$JAR +done + +$JAVA_HOME/bin/java -classpath $CLASSPATH -Dhttps.protocols=TLSv1.1,TLSv1.2 -DAJSC_HOME=$PROJECT_HOME -Daai.home=$PROJECT_HOME \ + org.openecomp.aai.dbgen.PropertyNameChange $1 $2 $3 $4 +if [ "$?" -ne "0" ]; then + echo "Problem executing propertyNameChange " + exit 1 +fi + + +echo `date` " Done $0" +exit 0 diff --git a/aai-resources/src/main/scripts/addResourceVersionProperty.sh b/aai-resources/src/main/scripts/addResourceVersionProperty.sh new file mode 100644 index 0000000..821275a --- /dev/null +++ b/aai-resources/src/main/scripts/addResourceVersionProperty.sh @@ -0,0 +1,55 @@ +#!/bin/ksh + +### +# ============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========================================================= +### + +# +# The script invokes the AddResourceVersionProp java class as a one-time (per database instance) migration tool +# which adds the new property "resource-version" to every node in the db. +# + +echo +echo `date` " Starting $0" + +. /etc/profile.d/aai.sh +PROJECT_HOME=/opt/app/aai-resources + +for JAR in `ls $PROJECT_HOME/extJars/*.jar` +do + CLASSPATH=$CLASSPATH:$JAR +done + +for JAR in `ls $PROJECT_HOME/lib/*.jar` +do + CLASSPATH=$CLASSPATH:$JAR +done + +userid=$( id | cut -f2 -d"(" | cut -f1 -d")" ) +if [ "${userid}" != "aaiadmin" ]; then + echo "You must be aaiadmin to run $0. The id used $userid." + exit 1 +fi + + +$JAVA_HOME/bin/java -classpath $CLASSPATH -Dhttps.protocols=TLSv1.1,TLSv1.2 -DAJSC_HOME=$PROJECT_HOME -Daai.home=$PROJECT_HOME \ + org.openecomp.aai.dbgen.AddResourceVersionProp + +echo `date` " Done $0" +exit 0 diff --git a/aai-resources/src/main/scripts/changePropertyCardinality.sh b/aai-resources/src/main/scripts/changePropertyCardinality.sh new file mode 100644 index 0000000..0eeac6d --- /dev/null +++ b/aai-resources/src/main/scripts/changePropertyCardinality.sh @@ -0,0 +1,88 @@ +#!/bin/ksh + +### +# ============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========================================================= +### + +# +# This script is used to change the cardinality of an existing database property. +# It currently just allows you to change TO a SET cardinality with dataType = String. +# It does not currently let you preserve the data (since we're just doing this for one +# field which nobody uses yet). +# +# Note also - This script just makes changes to the schema that is currently live. +# If you were to create a new schema in a brandy-new environment, it would look like +# whatever ex5.json (as of Jan 2016) told it to look like. So, part of making a +# change to the db schema should Always first be to make the change in ex5.json so that +# future environments will have the change. This script is just to change existing +# instances of the schema since schemaGenerator (as of Jan 2016) does not update things - it +# just does the initial creation. +# +# Boy, this is getting to be a big comment section... +# +# To use this script, you need to pass four parameters: +# propertyName -- the name of the property that you need to change Cardinality on. +# targetDataType -- whether it's changing or not, you need to give it: For now -- we only allow "String" +# targetCardinality -- For now -- only accepts "SET". In the future we should support ("SET", "LIST" or "SINGLE") +# preserveDataFlag -- true or false. For now -- only supports "false" +# +# Ie. changePropertyCardinality.sh supplier-release-list String SET false +# + +echo +echo `date` " Starting $0" + + +userid=$( id | cut -f2 -d"(" | cut -f1 -d")" ) +if [ "${userid}" != "aaiadmin" ]; then + echo "You must be aaiadmin to run $0. The id used $userid." + exit 1 +fi + + +if [ "$#" -ne 4 ]; then + echo "Illegal number of parameters" + echo "usage: $0 propertyName targetDataType targetCardinality preserveDataFlag" + exit 1 +fi + +. /etc/profile.d/aai.sh +PROJECT_HOME=/opt/app/aai-resources + +for JAR in `ls $PROJECT_HOME/extJars/*.jar` +do + CLASSPATH=$CLASSPATH:$JAR +done + +for JAR in `ls $PROJECT_HOME/lib/*.jar` +do + CLASSPATH=$CLASSPATH:$JAR +done + + +$JAVA_HOME/bin/java -classpath $CLASSPATH -Dhttps.protocols=TLSv1.1,TLSv1.2 -DAJSC_HOME=$PROJECT_HOME -Daai.home=$PROJECT_HOME \ + org.openecomp.aai.dbgen.ChangePropertyCardinality $1 $2 $3 $4 +if [ "$?" -ne "0" ]; then + echo "Problem executing ChangePropertyCardinality " + exit 1 +fi + + +echo `date` " Done $0" +exit 0 diff --git a/aai-resources/src/main/scripts/createDBSchema.sh b/aai-resources/src/main/scripts/createDBSchema.sh index 51668de..3cdbcd3 100644 --- a/aai-resources/src/main/scripts/createDBSchema.sh +++ b/aai-resources/src/main/scripts/createDBSchema.sh @@ -33,6 +33,7 @@ echo echo `date` " Starting $0" . /etc/profile.d/aai.sh +PROJECT_HOME=/opt/app/aai-resources for JAR in `ls $PROJECT_HOME/extJars/*.jar` diff --git a/aai-resources/src/main/scripts/deleteTool.sh b/aai-resources/src/main/scripts/deleteTool.sh index 585f333..c91f564 100644 --- a/aai-resources/src/main/scripts/deleteTool.sh +++ b/aai-resources/src/main/scripts/deleteTool.sh @@ -34,6 +34,7 @@ if [ "${userid}" != "aaiadmin" ]; then fi . /etc/profile.d/aai.sh +PROJECT_HOME=/opt/app/aai-resources for JAR in `ls $PROJECT_HOME/extJars/*.jar` do diff --git a/aai-resources/src/main/scripts/deobfuscatePW.sh b/aai-resources/src/main/scripts/deobfuscatePW.sh index 965525d..0a1f09a 100644 --- a/aai-resources/src/main/scripts/deobfuscatePW.sh +++ b/aai-resources/src/main/scripts/deobfuscatePW.sh @@ -39,6 +39,7 @@ if [ "${userid}" != "aaiadmin" ]; then fi . /etc/profile.d/aai.sh +PROJECT_HOME=/opt/app/aai-resources for JAR in `ls $PROJECT_HOME/extJars/*.jar` do diff --git a/aai-resources/src/main/scripts/edgeTagger.sh b/aai-resources/src/main/scripts/edgeTagger.sh index 5a120a2..35c214c 100644 --- a/aai-resources/src/main/scripts/edgeTagger.sh +++ b/aai-resources/src/main/scripts/edgeTagger.sh @@ -72,6 +72,7 @@ if [ "${userid}" != "aaiadmin" ]; then fi . /etc/profile.d/aai.sh +PROJECT_HOME=/opt/app/aai-resources for JAR in `ls $PROJECT_HOME/extJars/*.jar` do diff --git a/aai-resources/src/main/scripts/getTool.sh b/aai-resources/src/main/scripts/getTool.sh index 2da20eb..6f54299 100644 --- a/aai-resources/src/main/scripts/getTool.sh +++ b/aai-resources/src/main/scripts/getTool.sh @@ -34,6 +34,7 @@ if [ "${userid}" != "aaiadmin" ]; then fi . /etc/profile.d/aai.sh +PROJECT_HOME=/opt/app/aai-resources for JAR in `ls $PROJECT_HOME/extJars/*.jar` do diff --git a/aai-resources/src/main/scripts/notifyTool.sh b/aai-resources/src/main/scripts/notifyTool.sh index 2ecf1f4..9a0eede 100644 --- a/aai-resources/src/main/scripts/notifyTool.sh +++ b/aai-resources/src/main/scripts/notifyTool.sh @@ -34,6 +34,7 @@ if [ "${userid}" != "aaiadmin" ]; then fi . /etc/profile.d/aai.sh +PROJECT_HOME=/opt/app/aai-resources for JAR in `ls $PROJECT_HOME/extJars/*.jar` do diff --git a/aai-resources/src/main/scripts/postTool.sh b/aai-resources/src/main/scripts/postTool.sh index a773915..9a059e2 100644 --- a/aai-resources/src/main/scripts/postTool.sh +++ b/aai-resources/src/main/scripts/postTool.sh @@ -34,6 +34,7 @@ if [ "${userid}" != "aaiadmin" ]; then fi . /etc/profile.d/aai.sh +PROJECT_HOME=/opt/app/aai-resources for JAR in `ls $PROJECT_HOME/extJars/*.jar` do diff --git a/aai-resources/src/main/scripts/putTool.sh b/aai-resources/src/main/scripts/putTool.sh index 9d3f1dd..db581f8 100644 --- a/aai-resources/src/main/scripts/putTool.sh +++ b/aai-resources/src/main/scripts/putTool.sh @@ -34,6 +34,7 @@ if [ "${userid}" != "aaiadmin" ]; then fi . /etc/profile.d/aai.sh +PROJECT_HOME=/opt/app/aai-resources for JAR in `ls $PROJECT_HOME/extJars/*.jar` do diff --git a/aai-resources/src/main/scripts/rshipTool.sh b/aai-resources/src/main/scripts/rshipTool.sh index 316d0f5..5c71f51 100644 --- a/aai-resources/src/main/scripts/rshipTool.sh +++ b/aai-resources/src/main/scripts/rshipTool.sh @@ -43,6 +43,7 @@ if [ "${userid}" != "aaiadmin" ]; then fi . /etc/profile.d/aai.sh +PROJECT_HOME=/opt/app/aai-resources for JAR in `ls $PROJECT_HOME/extJars/*.jar` do diff --git a/aai-resources/src/main/scripts/run_DbTestProcessBuilder.sh b/aai-resources/src/main/scripts/run_DbTestProcessBuilder.sh new file mode 100644 index 0000000..7cf1c5f --- /dev/null +++ b/aai-resources/src/main/scripts/run_DbTestProcessBuilder.sh @@ -0,0 +1,54 @@ +#!/bin/ksh + +### +# ============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========================================================= +### + +# +# This script invokes the dataSnapshot java class passing an option to tell it to take +# a snapshot of the database and store it as a single-line XML file. +# + +echo +echo `date` " Starting $0" + + +userid=$( id | cut -f2 -d"(" | cut -f1 -d")" ) +if [ "${userid}" != "aaiadmin" ]; then + echo "You must be aaiadmin to run $0. The id used $userid." + exit 1 +fi + +. /etc/profile.d/aai.sh +PROJECT_HOME=/opt/app/aai-resources + +for JAR in `ls $PROJECT_HOME/extJars/*.jar` +do + CLASSPATH=$CLASSPATH:$JAR +done + +for JAR in `ls $PROJECT_HOME/lib/*.jar` +do + CLASSPATH=$CLASSPATH:$JAR +done + +$JAVA_HOME/bin/java -classpath $CLASSPATH -Dhttps.protocols=TLSv1.1,TLSv1.2 -DAJSC_HOME=$PROJECT_HOME -Daai.home=$PROJECT_HOME org.openecomp.aai.util.DbTestProcessBuilder "$@" + +echo `date` " Done $0" +exit 0 diff --git a/aai-resources/src/main/scripts/run_FixXSD.sh b/aai-resources/src/main/scripts/run_FixXSD.sh new file mode 100644 index 0000000..9293ded --- /dev/null +++ b/aai-resources/src/main/scripts/run_FixXSD.sh @@ -0,0 +1,68 @@ +#!/bin/ksh + +### +# ============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========================================================= +### + +# +# The script invokes GetResource java class to get all nodes +# + +echo +echo `date` " Starting $0" + +REV=$1 +AAIHOME=$2 +echo "AAIHOME: $AAIHOME" + +if test "$REV" = "" +then + REV=v6 +fi + +. /etc/profile.d/aai.sh +PROJECT_HOME=/opt/app/aai-resources + +if test "$AAIHOME" = "" +then + AAIHOME=$PROJECT_HOME +fi + + +for JAR in `ls $AAIHOME/target/*.jar` +do + CLASSPATH=$CLASSPATH:$JAR +done + +for JAR in `ls $PROJECT_HOME/lib/*.jar` +do + CLASSPATH=$CLASSPATH:$JAR +done + +export REV=$REV +echo "FixXSD $REV $AAIHOME" +$JAVA_HOME/bin/java -classpath $CLASSPATH -DAJSC_HOME=$AAIHOME org.openecomp.aai.util.FixXSDNew $REV +ret_code=$? +if [ $ret_code != 0 ]; then + echo `date` " Done $0" + exit $ret_code +fi + +echo `date` " Done $0" +exit 0 diff --git a/aai-resources/src/main/scripts/schemaMod.sh b/aai-resources/src/main/scripts/schemaMod.sh index f4fd4d5..3204900 100644 --- a/aai-resources/src/main/scripts/schemaMod.sh +++ b/aai-resources/src/main/scripts/schemaMod.sh @@ -66,6 +66,7 @@ if [ "$#" -ne 4 ]; then fi . /etc/profile.d/aai.sh +PROJECT_HOME=/opt/app/aai-resources for JAR in `ls $PROJECT_HOME/extJars/*.jar` do diff --git a/aai-resources/src/main/scripts/uniquePropertyCheck.sh b/aai-resources/src/main/scripts/uniquePropertyCheck.sh new file mode 100644 index 0000000..cee03b9 --- /dev/null +++ b/aai-resources/src/main/scripts/uniquePropertyCheck.sh @@ -0,0 +1,60 @@ +#!/bin/ksh + +### +# ============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========================================================= +### + +# +# The script invokes UniqueProperty java class to see if the passed property is unique in the db and if +# not, to display where duplicate values are found. +# +# For example: uniquePropertyCheck.sh subscriber-name +# + +echo +echo `date` " Starting $0" + +userid=$( id | cut -f2 -d"(" | cut -f1 -d")" ) +if [ "${userid}" != "aaiadmin" ]; then + echo "You must be aaiadmin to run $0. The id used $userid." + exit 1 +fi + +. /etc/profile.d/aai.sh +PROJECT_HOME=/opt/app/aai-resources + +for JAR in `ls $PROJECT_HOME/extJars/*.jar` +do + CLASSPATH=$CLASSPATH:$JAR +done + +for JAR in `ls $PROJECT_HOME/lib/*.jar` +do + CLASSPATH=$CLASSPATH:$JAR +done + +$JAVA_HOME/bin/java -classpath $CLASSPATH -Dhttps.protocols=TLSv1.1,TLSv1.2 -DAJSC_HOME=$PROJECT_HOME -Daai.home=$PROJECT_HOME org.openecomp.aai.util.UniquePropertyCheck "$@" +ret_code=$? +if [ $ret_code != 0 ]; then + echo `date` " Done $0" + exit $ret_code +fi + +echo `date` " Done $0" +exit 0 diff --git a/aai-resources/src/main/scripts/updateTool.sh b/aai-resources/src/main/scripts/updateTool.sh index 25670f6..bdb47e2 100644 --- a/aai-resources/src/main/scripts/updateTool.sh +++ b/aai-resources/src/main/scripts/updateTool.sh @@ -34,6 +34,7 @@ if [ "${userid}" != "aaiadmin" ]; then fi . /etc/profile.d/aai.sh +PROJECT_HOME=/opt/app/aai-resources for JAR in `ls $PROJECT_HOME/extJars/*.jar` do diff --git a/aai-resources/src/test/java/org/openecomp/aai/dbgen/DbMethTest.java b/aai-resources/src/test/java/org/openecomp/aai/dbgen/DbMethTest.java new file mode 100644 index 0000000..420daa7 --- /dev/null +++ b/aai-resources/src/test/java/org/openecomp/aai/dbgen/DbMethTest.java @@ -0,0 +1,90 @@ +/*- + * ============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 static org.junit.Assert.assertEquals; + +import java.util.HashMap; +import java.util.Map; + +import org.junit.Ignore; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + +import org.openecomp.aai.exceptions.AAIException; + +public class DbMethTest { + + @Rule + public ExpectedException expectedEx = ExpectedException.none(); + + @Test + public void testGetEdgeTagPropPutHash() throws AAIException { + Map expectedMap = new HashMap<>(); + expectedMap.put("usesResource", "false"); + expectedMap.put("isParent", "false"); + expectedMap.put("SVC-INFRA", "true"); + expectedMap.put("hasDelTarget", "false"); + + assertEquals(expectedMap, DbMeth.getEdgeTagPropPutHash("", "", "pserver|complex").get("locatedIn").getEdgeProperties()); + } + + @Test + public void testGetEdgeTagPropPutHash2() throws AAIException { + Map expectedMap = new HashMap<>(); + expectedMap.put("usesResource", "false"); + expectedMap.put("isParent", "false"); + expectedMap.put("SVC-INFRA", "false"); + expectedMap.put("hasDelTarget", "false"); + + assertEquals(expectedMap, DbMeth.getEdgeTagPropPutHash("", "", "service-instance|allotted-resource").get("uses").getEdgeProperties()); + } + + @Test + public void testGetEdgeTagPropPutHash3() throws AAIException { + Map expectedMap = new HashMap<>(); + expectedMap.put("usesResource", "false"); + expectedMap.put("isParent", "true"); + expectedMap.put("SVC-INFRA", "false"); + expectedMap.put("hasDelTarget", "false"); + + assertEquals(expectedMap, DbMeth.getEdgeTagPropPutHash("", "", "service-instance|allotted-resource").get("has").getEdgeProperties()); + } + + @Ignore + @Test + public void getGetEdgeTagPropPutHashThrowsExceptionWhenNoRuleExists() throws Exception { + expectedEx.expect(AAIException.class); + expectedEx.expectMessage("AAI_6120"); + DbMeth.getEdgeTagPropPutHash("", "", "complex|pserver"); + } + + @Ignore + @Test + public void getGetEdgeTagPropPutHashThrowsExceptionWhenNoRuleExists1() throws Exception { + expectedEx.expect(AAIException.class); + expectedEx.expectMessage("AAI_6120"); + DbMeth.getEdgeTagPropPutHash("", "", "complex"); + } + + +} diff --git a/aai-resources/src/test/java/org/openecomp/aai/dbgen/DbRunTest.java b/aai-resources/src/test/java/org/openecomp/aai/dbgen/DbRunTest.java new file mode 100644 index 0000000..cef8019 --- /dev/null +++ b/aai-resources/src/test/java/org/openecomp/aai/dbgen/DbRunTest.java @@ -0,0 +1,341 @@ +/*- + * ============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.nio.file.attribute.FileTime; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.HashMap; +import java.util.Iterator; + +import org.openecomp.aai.dbmap.AAIGraph; +import org.openecomp.aai.exceptions.AAIException; +import org.openecomp.aai.logging.ErrorLogHelper; +import org.openecomp.aai.util.AAIConfig; +import org.openecomp.aai.util.DbTestGetFileTime; +import com.thinkaurelius.titan.core.TitanTransaction; +import com.thinkaurelius.titan.core.TitanVertex; + +public class DbRunTest { + + /** + * The main method. + * + * @param args the arguments + */ + public static void main(String[] args) { + + String testid = "NA"; + TitanTransaction graph = null; + + boolean runIt = false; + try { + AAIConfig.init(); + ErrorLogHelper.loadProperties(); + if (args.length > 0) { + System.out.println( "DbRunTest called with " + args.length + " arguments"); + + + } else { + System.out.print("usage: DbRunTest \n"); + return; + } + } catch (AAIException e) { + System.out.print("Threw a AAIException -- \n"); + System.out.println(e.getMessage()); + } catch (Exception ex) { + System.out.print("Threw a regular ole Exception \n"); + System.out.println(ex.getMessage()); + } + + + + //System.out.println("skipping Titan graph for now..."); + //TitanGraph graph = null; + + + String processName = "NA"; + if ( args.length > 1 ) + processName = args[2].trim(); + + try { + System.out.println(processName + " ---- NOTE --- about to open graph (takes a little while)--------\n"); + + graph = AAIGraph.getInstance().getGraph().newTransaction(); + + if( graph == null ){ + System.out.println(processName + "Error creating Titan graph. \n"); + return; + } + } catch( Exception ex ){ + System.out.println( processName + " ERROR: caught this exception: " + ex ); + return; + } + + testid = args[0].trim(); + runIt = true; + Integer processDelay = new Integer(args[1].trim() ); // delay of write + Integer loopCnt = new Integer(args[3].trim() ); // delay of write + + String path = "NA"; + try { + + path = AAIConfig.get("dbruntest.path" ); // uses file create-timestamp + Integer writeDelay = new Integer(AAIConfig.get("dbruntest.delay" )); // delay seconds from create-timestamp + Integer loopDelay = new Integer(AAIConfig.get("dbruntest.loopdelay" )); // delay seconds from create-timestamp for next loop + + DbTestGetFileTime getFileTime = new DbTestGetFileTime(); + FileTime fileTime = getFileTime.createFileReturnTime( path ); + long createMillis = fileTime.toMillis(); + System.out.println(processName + " delays to use " + writeDelay + " processDelay " + processDelay); + System.out.println(processName + " test control file " + path + " creation time :" + + new SimpleDateFormat("dd/MM/yyyy HH:mm:ss:SSS") + .format(fileTime.toMillis())); + + long delayMillis = writeDelay * 60 * 1000; + long loopMillis = loopDelay * 60 * 1000; + + int loops = loopCnt.intValue(); + + long sleepTime; + for ( int i = 0; i < loops; ++i ) { + + if ( i > 0 ) + delayMillis = loopMillis * i; // to find the time the write will be done + delayMillis += processDelay.intValue(); + + System.out.println(processName + " test control file " + path + " write time :" + + new SimpleDateFormat("dd/MM/yyyy HH:mm:ss:SSS") + .format(createMillis + delayMillis)); + + Calendar now = Calendar.getInstance(); + long myMillis = now.getTimeInMillis(); + System.out.println(processName + " test control file " + path + " current time :" + + new SimpleDateFormat("dd/MM/yyyy HH:mm:ss:SSS") + .format(myMillis)); + // total sleep based on current time, time file was created, and any delay per process + + if ( i == 0 ) + sleepTime = createMillis + delayMillis - myMillis; // + processDelay.intValue() + else + sleepTime = createMillis + ( loopMillis * i ) - myMillis; + sleepTime += processDelay.intValue(); + System.out.println(processName + " sleep " + sleepTime + " current time :" + + new SimpleDateFormat("dd/MM/yyyy HH:mm:ss:SSS") + .format(myMillis)); + Thread.sleep(sleepTime); + + System.out.println(processName + " out of sleep for loop count " + i); + + if (runIt) { + // include loop in unique-id string + runMultiLevelTest(graph, testid + i + "-", processName); + } + + } // end loop + + + } catch ( Exception io ) { + System.out.println( processName + " Exception getting creation time " + path + " message " + io.getMessage()); + io.printStackTrace(); + } + + + + + + if( graph != null && graph.isOpen() ){ + System.out.println(processName + "About to call graph.shutdown()"); + graph.tx().close(); + System.out.println(processName + " -- AFTER call graph.shutdown()"); + } + + System.out.println(processName + " -- Boom!"); + System.exit(0); + + }// end of main() + + + + /** + * Run multi level test. + * + * @param graph the graph + * @param testIdentifier the test identifier + * @param processName the process name + */ + private static void runMultiLevelTest(TitanTransaction graph, String testIdentifier, String processName) { + + try { + String useRollback = AAIConfig.get("dbruntest.rollback"); + + // l3-interface-ipv6-address-list -> vlan -> l-interface -> vnic -> vserver -> tenant + + HashMap propHash7 = new HashMap(); + propHash7.put("tenant-name", testIdentifier + "tenantName"); + propHash7.put("tenant-id", testIdentifier + "tenantId"); + TitanVertex tenantVtx = DbMeth.persistAaiNode("junkTransId", + "testApp", graph, "tenant", propHash7, true, null); + + + HashMap propHash8 = new HashMap(); + propHash8.put("vserver-selflink", testIdentifier + "vserverSelfThing"); + propHash8.put("vserver-id", testIdentifier + "vserverID"); + propHash8.put("vserver-name", testIdentifier + "vserverName"); + propHash8.put("vserver-name2", testIdentifier + "vserverName2"); + TitanVertex vserverVtx = DbMeth.persistAaiNode("junkTransId", + "testApp", graph, "vserver", propHash8, true, tenantVtx); + + HashMap propHash10 = new HashMap(); + propHash10.put("interface-name", testIdentifier + "logIntfOnVpe"); + TitanVertex logIntfVtx = DbMeth.persistAaiNode("junkTransId", + "testApp", graph, "l-interface", propHash10, true, vserverVtx); + + HashMap propHash11 = new HashMap(); + propHash11.put("vlan-interface", testIdentifier + "vlanIntf"); + TitanVertex vlanVtx = DbMeth.persistAaiNode("junkTransId", + "testApp", graph, "vlan", propHash11, true, logIntfVtx); + + HashMap propHash12 = new HashMap(); + propHash12.put("l3-interface-ipv6-address", testIdentifier + "v6 pool"); + TitanVertex l3PoolVtx = DbMeth.persistAaiNode("junkTransId", + "testApp", graph, "l3-interface-ipv6-address-list", propHash12, true, vlanVtx); + + System.out.println(processName + " ---- did the persist on all the nodes -- "); + + DbMeth.persistAaiEdge("junkTransId", "junkApp", graph, vserverVtx, tenantVtx); + DbMeth.persistAaiEdge("junkTransId", "junkApp", graph, logIntfVtx, vserverVtx); + DbMeth.persistAaiEdge("junkTransId", "junkApp", graph, vlanVtx, logIntfVtx); + DbMeth.persistAaiEdge("junkTransId", "junkApp", graph, l3PoolVtx, vlanVtx); + + System.out.println(processName + " ---- persisted all the edges -- "); + + if ( useRollback.toUpperCase().equals("Y")) { + System.out.print(processName + " using rollback for unittesting\n"); + if (graph != null) { + graph.tx().rollback(); + } + } else { + graph.tx().commit(); + System.out.println(processName + " ---- Ran graph.commit() -- "); + } + HashMap propHash0 = new HashMap(); + propHash0.put("l3-interface-ipv6-address-list.l3-interface-ipv6-address", testIdentifier + "v6 pool"); + propHash0.put("tenant.tenant-name", testIdentifier + "tenantName"); + propHash0.put("tenant.tenant-id", testIdentifier + "tenantId"); + propHash0.put("vserver.vserver-selflink", testIdentifier + "vserverSelfThing"); + propHash0.put("vserver.vserver-id", testIdentifier + "vserverID"); + propHash0.put("vserver.vserver-name", testIdentifier + "vserverName"); + propHash0.put("vserver.vserver-name2", testIdentifier + "vserverName2"); + propHash0.put("l-interface.interface-name", testIdentifier + "logIntfOnVpe"); + propHash0.put("vlan.vlan-interface", testIdentifier + "vlanIntf"); + + + System.out.println(processName + " ---- First try the getUniqueNodeWithDepParams trail: "); + + TitanVertex poolV = DbMeth.getUniqueNodeWithDepParams("junkTransId", "junkAppId", graph, "l3-interface-ipv6-address-list", propHash0, null); + + ArrayList retArr = DbMeth.showPropertiesForNode("junkTransId", "junkFromAppId", poolV); + for( String info : retArr ){ System.out.println(info); } + +/* + * RelationshipUtils replaced with RelationshipGraph + * System.out.println(processName + " ---- Next try the figureRelData trail: "); + List relDatList = RelationshipUtils.figureRelData("junkTransId", "junkAppId", graph, poolV, ""); + System.out.println(processName + " ---- Looks like it worked ----------"); + Iterator iterDat = relDatList.iterator(); + while (iterDat.hasNext()) { + RelationshipData relDat = iterDat.next(); + System.out.println(processName + " relData: key = [" + + relDat.getRelationshipKey() + "], val = [" + + relDat.getRelationshipValue() + "]"); + }*/ + + + HashMap propHash = new HashMap(); + ArrayList vertList; + + propHash.put("tenant-id", testIdentifier + "tenantId"); + vertList = DbMeth.getNodes("junkTransId", + "testApp", graph, "tenant", propHash, false, null, true); + + Iterator iter = vertList.iterator(); + + int vertexCnt = 0; + while( iter.hasNext() ) { + ++vertexCnt; + TitanVertex tvx = iter.next(); + System.out.println(processName + " Found tenant " + vertexCnt ); + DbMeth.showPropertiesForNode( "junkId", "junkApp", tvx ); + } + if ( vertexCnt == 0 ) + System.out.println(processName + " no tenant found" ); + + propHash = new HashMap(); + + propHash.put("vserver-id", testIdentifier + "vserverID"); + vertList = DbMeth.getNodes("junkTransId", + "testApp", graph, "vserver", propHash, false, null, true); + + iter = vertList.iterator(); + + vertexCnt = 0; + while( iter.hasNext() ) { + ++vertexCnt; + TitanVertex tvx = iter.next(); + System.out.println(processName + " Found vserver " + vertexCnt ); + DbMeth.showPropertiesForNode( "junkId", "junkApp", tvx ); + } + if ( vertexCnt == 0 ) + System.out.println(processName + " no vserver found" ); + + if ( useRollback.toUpperCase().equals("Y")) { + System.out.print(processName + " using rollback for unittesting\n"); + if (graph != null) { + graph.tx().rollback(); + } + } + + } + catch (AAIException e) { + System.out.print(processName + " Threw an AAIException -- calling graph.rollback()\n"); + System.out.println("exMsg = [" + e.getMessage() + "]"); + if (graph != null) { + graph.tx().rollback(); + } + } + catch (Exception ex) { + System.out.print(processName + " Threw a regular ole Exception calling graph.rollback()\n"); + System.out.println(ex.getMessage()); + System.out.println(ex.toString()); + if (graph != null) { + graph.tx().rollback(); + } + } + + + + return; + } + + +} diff --git a/aai-resources/src/test/java/org/openecomp/aai/migration/VertexMergeTest.java b/aai-resources/src/test/java/org/openecomp/aai/migration/VertexMergeTest.java new file mode 100644 index 0000000..1b5b67b --- /dev/null +++ b/aai-resources/src/test/java/org/openecomp/aai/migration/VertexMergeTest.java @@ -0,0 +1,190 @@ +/*- + * ============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.migration; + +import static org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertThat; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.when; + +import java.io.UnsupportedEncodingException; +import java.util.Arrays; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; +import org.apache.tinkerpop.gremlin.structure.Vertex; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Ignore; +import org.junit.Test; + +import org.openecomp.aai.db.props.AAIProperties; +import org.openecomp.aai.dbmap.DBConnectionType; +import org.openecomp.aai.introspection.Loader; +import org.openecomp.aai.introspection.LoaderFactory; +import org.openecomp.aai.introspection.ModelType; +import org.openecomp.aai.introspection.Version; +import org.openecomp.aai.serialization.db.DBSerializer; +import org.openecomp.aai.serialization.db.EdgeRules; +import org.openecomp.aai.serialization.engines.QueryStyle; +import org.openecomp.aai.serialization.engines.TitanDBEngine; +import org.openecomp.aai.serialization.engines.TransactionalGraphEngine; +//import org.openecomp.aai.serialization.queryformats.QueryFormatTestHelper; +import org.openecomp.aai.util.AAIConstants; +import com.thinkaurelius.titan.core.Cardinality; +import com.thinkaurelius.titan.core.TitanFactory; +import com.thinkaurelius.titan.core.TitanGraph; +import com.thinkaurelius.titan.core.TitanTransaction; +import com.thinkaurelius.titan.core.schema.TitanManagement; + +@Ignore +public class VertexMergeTest { + + + private final static Version version = Version.v10; + private final static ModelType introspectorFactoryType = ModelType.MOXY; + private final static QueryStyle queryStyle = QueryStyle.TRAVERSAL; + private final static DBConnectionType type = DBConnectionType.REALTIME; + private static Loader loader; + private static TransactionalGraphEngine dbEngine; + private static TitanGraph graph; + private static EdgeRules rules; + private static GraphTraversalSource g; + private static TitanTransaction tx; + @BeforeClass + public static void setUp() throws NoSuchFieldException, SecurityException, Exception { + graph = TitanFactory.build().set("storage.backend","inmemory").open(); + tx = graph.newTransaction(); + g = tx.traversal(); + System.setProperty("AJSC_HOME", "."); + System.setProperty("BUNDLECONFIG_DIR", "bundleconfig-local"); +// QueryFormatTestHelper.setFinalStatic(AAIConstants.class.getField("AAI_HOME_ETC_OXM"), "src/test/resources/org/openecomp/aai/introspection/"); + loader = LoaderFactory.createLoaderForVersion(introspectorFactoryType, version); + dbEngine = new TitanDBEngine( + queryStyle, + type, + loader); + rules = EdgeRules.getInstance(); + + TitanManagement mgmt = graph.openManagement(); + mgmt.makePropertyKey("test-list").dataType(String.class).cardinality(Cardinality.SET).make(); + mgmt.commit(); + Vertex pserverSkeleton = g.addV().property("aai-node-type", "pserver").property("hostname", "TEST1") + .property("source-of-truth", "AAI-EXTENSIONS").property("fqdn", "test1.com").property("test-list", "value1").next(); + + Vertex pInterface1 = g.addV().property("aai-node-type", "p-interface").property("interface-name", "p-interface1") + .property(AAIProperties.AAI_URI, "/cloud-infrastructure/pservers/pserver/TEST1/p-interfaces/p-interface/p-interface1").next(); + + Vertex pInterface2 = g.addV().property("aai-node-type", "p-interface").property("interface-name", "p-interface2") + .property(AAIProperties.AAI_URI, "/cloud-infrastructure/pservers/pserver/TEST1/p-interfaces/p-interface/p-interface2").next(); + + Vertex pInterface2Secondary = g.addV().property("aai-node-type", "p-interface").property("interface-name", "p-interface2").property("special-prop", "value") + .property(AAIProperties.AAI_URI, "/cloud-infrastructure/pservers/pserver/TEST1/p-interfaces/p-interface/p-interface2").next(); + + Vertex lInterface1 = g.addV().property("aai-node-type", "l-interface").property("interface-name", "l-interface1").property("special-prop", "value") + .property(AAIProperties.AAI_URI, "/cloud-infrastructure/pservers/pserver/TEST1/p-interfaces/p-interface/p-interface2/l-interfaces/l-interface/l-interface1").next(); + + Vertex lInterface1Canopi = g.addV().property("aai-node-type", "l-interface").property("interface-name", "l-interface1") + .property(AAIProperties.AAI_URI, "/cloud-infrastructure/pservers/pserver/TEST1/p-interfaces/p-interface/p-interface2/l-interfaces/l-interface/l-interface1").next(); + + Vertex logicalLink = g.addV().property("aai-node-type", "logical-link").property("link-name", "logical-link1") + .property(AAIProperties.AAI_URI, "/network/logical-links/logical-link/logical-link1").next(); + Vertex pserverCanopi = g.addV().property("aai-node-type", "pserver").property("hostname", "TEST1") + .property("source-of-truth", "CANOPI-WS").property("fqdn", "test2.com").property("test-list", "value2").next(); + + Vertex complex1 = g.addV().property("aai-node-type", "complex").property("physical-location-id", "complex1") + .property("source-of-truth", "RO").next(); + + Vertex complex2 = g.addV().property("aai-node-type", "complex").property("physical-location-id", "complex2") + .property("source-of-truth", "RCT").next(); + + Vertex vserver1 = g.addV().property("aai-node-type", "vserver").property("vserver-id", "vserver1") + .property("source-of-truth", "RO").next(); + + Vertex vserver2 = g.addV().property("aai-node-type", "vserver").property("vserver-id", "vserver2") + .property("source-of-truth", "RCT").next(); + Vertex vserver3 = g.addV().property("aai-node-type", "vserver").property("vserver-id", "vserver3") + .property("source-of-truth", "RCT").next(); + Vertex vserver4 = g.addV().property("aai-node-type", "vserver").property("vserver-id", "vserver4") + .property("source-of-truth", "RCT").next(); + Vertex vserver5 = g.addV().property("aai-node-type", "vserver").property("vserver-id", "vserver5") + .property("source-of-truth", "RCT").next(); + + + rules.addEdge(g, pserverSkeleton, complex1); + rules.addEdge(g, pserverSkeleton, vserver1); + rules.addEdge(g, pserverSkeleton, vserver2); + rules.addTreeEdge(g, pserverSkeleton, pInterface1); + rules.addTreeEdge(g, pserverSkeleton, pInterface2Secondary); + rules.addTreeEdge(g, pInterface2Secondary, lInterface1); + rules.addEdge(g, lInterface1, logicalLink); + rules.addEdge(g, pserverCanopi, complex2); + rules.addEdge(g, pserverCanopi, vserver3); + rules.addEdge(g, pserverCanopi, vserver4); + rules.addEdge(g, pserverCanopi, vserver5); + rules.addTreeEdge(g, pserverCanopi, pInterface2); + rules.addTreeEdge(g, pInterface2, lInterface1Canopi); + + Map> forceCopy = new HashMap<>(); + Set forceSet = new HashSet<>(); + forceSet.add("fqdn"); + forceCopy.put("pserver", forceSet); + + TransactionalGraphEngine spy = spy(dbEngine); + TransactionalGraphEngine.Admin adminSpy = spy(dbEngine.asAdmin()); + GraphTraversalSource traversal = g; + GraphTraversalSource readOnly = g; + when(spy.asAdmin()).thenReturn(adminSpy); + when(adminSpy.getTraversalSource()).thenReturn(traversal); + when(adminSpy.getReadOnlyTraversalSource()).thenReturn(readOnly); + DBSerializer serializer = new DBSerializer(version, spy, introspectorFactoryType, "Merge test"); + + VertexMerge merge = new VertexMerge.Builder(loader, spy, serializer).build(); + merge.performMerge(pserverCanopi, pserverSkeleton, forceCopy); + } + @AfterClass + public static void cleanUp() { + tx.rollback(); + graph.close(); + } + + @Test + public void run() throws UnsupportedEncodingException { + + assertEquals("pserver merged", false, g.V().has("hostname", "TEST1").has("source-of-truth", "AAI-EXTENSIONS").hasNext()); + assertThat("pserver list merge", Arrays.asList("value1", "value2"), containsInAnyOrder(g.V().has("hostname", "TEST1").values("test-list").toList().toArray())); + assertEquals("canopi pserver has one edge to vserver2", 1, g.V().has("hostname", "TEST1").both().has("vserver-id", "vserver2").toList().size()); + assertEquals("canopi pserver has one edge to vserver1", 1, g.V().has("hostname", "TEST1").both().has("vserver-id", "vserver1").toList().size()); + assertEquals("canopi pserver retained edge to complex2", true, g.V().has("hostname", "TEST1").both().has("physical-location-id", "complex2").hasNext()); + assertEquals("canopi pserver received forced prop", "test1.com", g.V().has("hostname", "TEST1").values("fqdn").next()); + assertEquals("pserver skeleton child copied", true, g.V().has("hostname", "TEST1").both().has("interface-name", "p-interface1").hasNext()); + assertEquals("pserver skeleton child merged", true, g.V().has("hostname", "TEST1").both().has("interface-name", "p-interface2").has("special-prop", "value").hasNext()); + assertEquals("l-interface child merged", true, g.V().has("hostname", "TEST1").both().has("interface-name", "p-interface2").both().has("interface-name", "l-interface1").has("special-prop", "value").hasNext()); + assertEquals("l-interface child cousin edge merged", true, g.V().has("hostname", "TEST1").both().has("interface-name", "p-interface2").both().has("interface-name", "l-interface1").both().has("link-name", "logical-link1").hasNext()); + assertEquals("one l-interface1 found", new Long(1), g.V().has("interface-name", "l-interface1").count().next()); + assertEquals("one p-interface2 found", new Long(1), g.V().has("interface-name", "p-interface2").count().next()); + + } +} diff --git a/aai-resources/src/test/java/org/openecomp/aai/query/builder/TraversalQueryTest.java b/aai-resources/src/test/java/org/openecomp/aai/query/builder/TraversalQueryTest.java deleted file mode 100644 index 694e99e..0000000 --- a/aai-resources/src/test/java/org/openecomp/aai/query/builder/TraversalQueryTest.java +++ /dev/null @@ -1,105 +0,0 @@ -/*- - * ============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.query.builder; - -import static org.junit.Assert.assertEquals; - -import java.io.UnsupportedEncodingException; -import java.net.URI; -import java.net.URISyntaxException; - -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.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Test; -import org.mockito.Mock; - -import org.openecomp.aai.db.props.AAIProperties; -import org.openecomp.aai.exceptions.AAIException; -import org.openecomp.aai.introspection.Introspector; -import org.openecomp.aai.introspection.Loader; -import org.openecomp.aai.introspection.LoaderFactory; -import org.openecomp.aai.introspection.ModelType; -//import org.openecomp.aai.serialization.queryformats.QueryFormatTestHelper; -import org.openecomp.aai.util.AAIConstants; - -public class TraversalQueryTest { - - public static Loader loader; - @Mock public GraphTraversalSource g; - @BeforeClass - public static void configure() throws NoSuchFieldException, SecurityException, Exception { - - System.setProperty("AJSC_HOME", "."); - System.setProperty("BUNDLECONFIG_DIR", "bundleconfig-local"); -// QueryFormatTestHelper.setFinalStatic(AAIConstants.class.getField("AAI_HOME_ETC_OXM"), "src/test/resources/org/openecomp/aai/introspection/"); - loader = LoaderFactory.createLoaderForVersion(ModelType.MOXY, AAIProperties.LATEST); - } - - @Test - public void unionQuery() { - TraversalQuery tQ = new TraversalQuery(loader, g); - TraversalQuery tQ2 = new TraversalQuery(loader, g); - TraversalQuery tQ3 = new TraversalQuery(loader, g); - tQ.union( - tQ2.getVerticesByProperty("test1", "value1"), - tQ3.getVerticesByIndexedProperty("test2", "value2")); - - GraphTraversal expected = __.start() - .union(__.has("test1", "value1"),__.has("test2", "value2")); - - assertEquals("they are equal", expected, tQ.getQuery()); - - } - - @Test - @Ignore - public void traversalClones() throws UnsupportedEncodingException, AAIException, URISyntaxException { - TraversalQuery tQ = new TraversalQuery(loader, g); - Introspector test = loader.introspectorFromName("test-object"); - QueryBuilder builder = tQ.createQueryFromURI(new URI("network/test-objects/test-object/key1")).getQueryBuilder(); - GraphTraversal expected = __.start().has("vnf-id", "key1").has("aai-node-type", "test-object"); - GraphTraversal containerExpected = __.start().has("aai-node-type", "test-object"); - - assertEquals("query object", expected.toString(), builder.getQuery().toString()); - assertEquals("container query object", containerExpected.toString(), builder.getContainerQuery().getQuery().toString()); - - } - - @Test - public void nestedTraversalClones() throws UnsupportedEncodingException, AAIException, URISyntaxException { - - TraversalQuery tQ = new TraversalQuery(loader, g); - QueryBuilder builder = tQ.createQueryFromURI(new URI("network/generic-vnfs/generic-vnf/key1/l-interfaces/l-interface/key2")).getQueryBuilder(); - GraphTraversal expected = __.start().has("vnf-id", "key1").has("aai-node-type", "generic-vnf").out("hasLInterface").has(AAIProperties.NODE_TYPE, "l-interface").has("interface-name", "key2"); - GraphTraversal containerExpected = __.start().has("vnf-id", "key1").has("aai-node-type", "generic-vnf").out("hasLInterface").has(AAIProperties.NODE_TYPE, "l-interface"); - - assertEquals("query object", expected.toString(), builder.getQuery().toString()); - assertEquals("container query object", containerExpected.toString(), builder.getContainerQuery().getQuery().toString()); - - } - - - -} diff --git a/aai-resources/src/test/java/org/openecomp/aai/schema/db/AuditOXMTest.java b/aai-resources/src/test/java/org/openecomp/aai/schema/db/AuditOXMTest.java index 8188bdd..8e9e322 100644 --- a/aai-resources/src/test/java/org/openecomp/aai/schema/db/AuditOXMTest.java +++ b/aai-resources/src/test/java/org/openecomp/aai/schema/db/AuditOXMTest.java @@ -45,7 +45,7 @@ public class AuditOXMTest { */ @BeforeClass public static void before() { - System.setProperty("AJSC_HOME", "./src/test/resources/");; + System.setProperty("AJSC_HOME", "."); System.setProperty("BUNDLECONFIG_DIR", "bundleconfig-local"); } diff --git a/aai-resources/src/test/java/org/openecomp/aai/schema/db/ManageSchemaTest.java b/aai-resources/src/test/java/org/openecomp/aai/schema/db/ManageSchemaTest.java index 9b7dd7c..9dade87 100644 --- a/aai-resources/src/test/java/org/openecomp/aai/schema/db/ManageSchemaTest.java +++ b/aai-resources/src/test/java/org/openecomp/aai/schema/db/ManageSchemaTest.java @@ -43,7 +43,7 @@ public class ManageSchemaTest { private TitanGraph graph = null; @BeforeClass public static void before() { - System.setProperty("AJSC_HOME", "./src/test/resources/");; + System.setProperty("AJSC_HOME", "."); System.setProperty("BUNDLECONFIG_DIR", "bundleconfig-local"); } diff --git a/aai-resources/src/test/java/org/openecomp/aai/util/AAITxnLogTest.java b/aai-resources/src/test/java/org/openecomp/aai/util/AAITxnLogTest.java new file mode 100644 index 0000000..57ba3eb --- /dev/null +++ b/aai-resources/src/test/java/org/openecomp/aai/util/AAITxnLogTest.java @@ -0,0 +1,361 @@ +/*- + * ============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.util; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.io.IOException; +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; +import java.util.List; + +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.hbase.HBaseConfiguration; +import org.apache.hadoop.hbase.client.Get; +import org.apache.hadoop.hbase.client.HTable; +import org.apache.hadoop.hbase.client.Result; +import org.apache.hadoop.hbase.client.ResultScanner; +import org.apache.hadoop.hbase.client.Scan; +import org.apache.hadoop.hbase.util.Bytes; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Rule; +import org.junit.Test; +import org.mockito.Mockito; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.agent.PowerMockAgent; +import org.powermock.modules.junit4.rule.PowerMockRule; + +import org.openecomp.aai.domain.notificationEvent.NotificationEvent; +import org.openecomp.aai.domain.translog.TransactionLogEntries; +import org.openecomp.aai.domain.translog.TransactionLogEntry; +import org.openecomp.aai.exceptions.AAIException; +import com.fasterxml.jackson.core.JsonGenerationException; +import com.fasterxml.jackson.databind.JsonMappingException; + + +@Ignore +@PrepareForTest({HBaseConfiguration.class, Configuration.class, + HTable.class, Result.class, ResultScanner.class, Scan.class, + Get.class, NotificationEvent.class, + NotificationEvent.EventHeader.class, PojoUtils.class, AAITxnLog.class}) + +public class AAITxnLogTest { + + @Rule + public PowerMockRule rule = new PowerMockRule(); + + static { + PowerMockAgent.initializeIfNeeded(); + } + + AAITxnLog aaiTnxLog; + Configuration config; + HTable htable; + Result result; + ResultScanner resScanner; + Scan scan; + Get g; + NotificationEvent notif; + NotificationEvent.EventHeader ehNotif; + PojoUtils pu; + + boolean hasNotifEvent = true; + final String notifPayload = "A random payload"; + final String notifID = "1"; + final String notifEntityLink = "nLink"; + final String notifAction = "nAction"; + final String notifStatus = "nStatus"; + final String notifTopic = "nTopic"; + + final String tid = "tidVal"; + final String status = "statusVal"; + final String rqstTm = "rqstTmVal"; + final String respTm = "respTmVal"; + final String srcId = "srcIdVal"; + final String rsrcId = "rsrcIdVal"; + final String rsrcType = "rsrcTypeVal"; + final String rqstBuf = "rqstBufVal"; + final String respBuf = "respBufVal"; + + + /** + * Initialize. + */ + @Before + public void initialize(){ + partialSetupForAAIConfig(); + PowerMockito.mockStatic(HBaseConfiguration.class); + config = PowerMockito.mock(Configuration.class); + htable = PowerMockito.mock(HTable.class); + result = PowerMockito.mock(Result.class); + resScanner = PowerMockito.mock(ResultScanner.class); + scan = PowerMockito.mock(Scan.class); + g = PowerMockito.mock(Get.class); + notif = PowerMockito.mock(NotificationEvent.class); + ehNotif = PowerMockito.mock(NotificationEvent.EventHeader.class); + pu = PowerMockito.mock(PojoUtils.class); + + + mockNotificationEvent(); + + Mockito.when(HBaseConfiguration.create()).thenReturn(config); + aaiTnxLog = new AAITxnLog(tid, srcId); + + try { + PowerMockito.whenNew(HTable.class).withAnyArguments().thenReturn(htable); + PowerMockito.whenNew(Get.class).withAnyArguments().thenReturn(g); + PowerMockito.whenNew(PojoUtils.class).withAnyArguments().thenReturn(pu); + PowerMockito.whenNew(Scan.class).withAnyArguments().thenReturn(scan); + } catch (Exception e) { + e.printStackTrace(); + } + + mockResult(); + + try { + PowerMockito.when(htable.get(g)).thenReturn(result); + PowerMockito.when(htable.getScanner(scan)).thenReturn(resScanner); + } catch (IOException e) { + e.printStackTrace(); + } + } + + /** + * Method to test 'put' operation without a notification event. + */ + @Test + public void testPut_withoutNotifEvent(){ + String htid = aaiTnxLog.put(tid, status, rqstTm, respTm, srcId, rsrcId, rsrcType, rqstBuf, respBuf); + try { + TransactionLogEntry tle = aaiTnxLog.get(htid); + hasNotifEvent = false; + validateTransactionLogEntry(tle); + } catch (AAIException e) { + fail("Cant read back data from htable"); + e.printStackTrace(); + } + } + + /** + * Method to test 'put' operation with a notification event. + */ + @Test + public void testPut_withNotifEvent(){ + hasNotifEvent = true; + String htid = aaiTnxLog.put(tid, status, rqstTm, respTm, srcId, rsrcId, rsrcType, rqstBuf, respBuf, hasNotifEvent, notif); + try { + TransactionLogEntry tle = aaiTnxLog.get(htid); + validateTransactionLogEntry(tle); + } catch (AAIException e) { + fail("Cant read back data from htable"); + e.printStackTrace(); + } + } + + /** + * Method to test 'scan' over an empty htable. + */ + @Test + public void testScan_withEmptyHTable(){ + String key = tid; + List res = aaiTnxLog.scan(key); + assertTrue("Scan output should be empty", res.size() == 0 ); + } + + /** + * Method to test 'scan' operation. + */ + @Test + public void testScan(){ + try { + PowerMockito.when(resScanner.next()).thenReturn(result).thenReturn(null); + } catch (IOException e) { + e.printStackTrace(); + } + List res = aaiTnxLog.scan(tid); + assertTrue("Scan output should not be empty", res.size()==1); + assertTrue("Did not find entry in 'scan'", res.get(0).equals(result.toString())); + } + + /** + * Method to test 'scanFiltered' with an empty htable. + */ + @Test + public void testScanFiltered_withEmptyHTable(){ + aaiTnxLog.put(tid, status, rqstTm, respTm, srcId, rsrcId, rsrcType, rqstBuf, respBuf, true, new NotificationEvent()); + TransactionLogEntries tles = aaiTnxLog.scanFiltered(0, 100, null, null, null, null, null); + assertTrue ("scanFilstered output should be empty", tles.getTransactionLogEntries().size() == 0); + } + + /** + * Method to test 'scanFiltered' operation. + */ + @Test + public void testScanFiltered(){ + try { + PowerMockito.when(resScanner.next()).thenReturn(result).thenReturn(null); + } catch (IOException e) { + e.printStackTrace(); + } + aaiTnxLog.put(tid, status, rqstTm, respTm, srcId, rsrcId, rsrcType, rqstBuf, respBuf, true, new NotificationEvent()); + TransactionLogEntries tles = aaiTnxLog.scanFiltered(0, 100, null, null, null, null, null); + assertFalse ("scanFilstered output should not be empty", tles.getTransactionLogEntries().size() == 0); + validateTransactionLogEntry(tles.getTransactionLogEntries().get(0)); + } + + /** + * Helper method to validate the contents of a TransactionalLogEntry. + * + * @param tle TransactionalLogEntry to compare against + */ + public void validateTransactionLogEntry(TransactionLogEntry tle){ + String pre = "validateTransactionLogEntry: "; + String post = " didn't match"; + assertEquals(pre + "tid" + post, tle.getTransactionLogEntryId(), tid); + assertEquals(pre + "status" + post, tle.getStatus(), status); + assertEquals(pre + "rqstDate" + post, tle.getRqstDate(), rqstTm); + assertEquals(pre + "respDate" + post, tle.getRespDate(), respTm); + assertEquals(pre + "srcId" + post, tle.getSourceId(), srcId); + assertEquals(pre + "rsrcId" + post, tle.getResourceId(), rsrcId); + assertEquals(pre + "rqstBuf" + post, tle.getRqstBuf(), rqstBuf); + assertEquals(pre + "respBuf" + post, tle.getrespBuf(), respBuf); + if ( hasNotifEvent){ + assertEquals(pre + "notifPayload" + post, tle.getNotificationPayload(), notifPayload); + assertEquals(pre + "notifStatus" + post, tle.getNotificationStatus(), notifStatus); + assertEquals(pre + "notifID" + post, tle.getNotificationId(), notifID); + assertEquals(pre + "notifTopic" + post, tle.getNotificationTopic(), notifTopic); + assertEquals(pre + "notifEntityLink" + post, tle.getNotificationEntityLink(), notifEntityLink); + assertEquals(pre + "notifAction" + post, tle.getNotificationAction(), notifAction); + } + } + + + + /** + * Helper method to mock PojoUtils. + */ + public void mockPojoUtils(){ + + try { + PowerMockito.when(pu.getJsonFromObject(notif)).thenReturn(notifPayload); + } catch (JsonGenerationException e) {e.printStackTrace();} + catch (JsonMappingException e) {e.printStackTrace();} + catch (IOException e) {e.printStackTrace(); } + } + + + + /** + * Helper method to mock a notification event handler. + */ + public void mockNotifEventHandler(){ + PowerMockito.when(ehNotif.getId()).thenReturn(notifID); + PowerMockito.when(ehNotif.getEntityLink()).thenReturn(notifEntityLink); + PowerMockito.when(ehNotif.getAction()).thenReturn(notifAction); + PowerMockito.when(ehNotif.getStatus()).thenReturn(notifStatus); + } + + /** + * Helper method to mock a notification event. + */ + public void mockNotificationEvent(){ + mockPojoUtils(); + mockNotifEventHandler(); + PowerMockito.when(notif.getEventHeader()).thenReturn(ehNotif); + PowerMockito.when(notif.getEventHeader().getEventType()).thenReturn(null); + PowerMockito.when(notif.getEventHeader().getStatus()).thenReturn(null); + } + + + /** + * Helper method to build a mock-Result. + */ + public void mockResult(){ + PowerMockito.when(result.getValue(Bytes.toBytes("transaction"),Bytes.toBytes("tid"))).thenReturn(Bytes.toBytes(tid)); + PowerMockito.when(result.getValue(Bytes.toBytes("transaction"),Bytes.toBytes("status"))).thenReturn(Bytes.toBytes(status)); + PowerMockito.when(result.getValue(Bytes.toBytes("transaction"),Bytes.toBytes("rqstDate"))).thenReturn(Bytes.toBytes(rqstTm)); + PowerMockito.when(result.getValue(Bytes.toBytes("transaction"),Bytes.toBytes("respDate"))).thenReturn(Bytes.toBytes(respTm)); + PowerMockito.when(result.getValue(Bytes.toBytes("transaction"),Bytes.toBytes("sourceId"))).thenReturn(Bytes.toBytes(srcId)); + + PowerMockito.when(result.getValue(Bytes.toBytes("resource"),Bytes.toBytes("resourceId"))).thenReturn(Bytes.toBytes(rsrcId)); + PowerMockito.when(result.getValue(Bytes.toBytes("resource"),Bytes.toBytes("resourceType"))).thenReturn(Bytes.toBytes(rsrcType)); + + PowerMockito.when(result.getValue(Bytes.toBytes("payload"),Bytes.toBytes("rqstBuf"))).thenReturn(Bytes.toBytes(rqstBuf)); + PowerMockito.when(result.getValue(Bytes.toBytes("payload"),Bytes.toBytes("respBuf"))).thenReturn(Bytes.toBytes(respBuf)); + + PowerMockito.when(result.getValue(Bytes.toBytes("notification"),Bytes.toBytes("notificationPayload"))).thenReturn(Bytes.toBytes(notifPayload)); + PowerMockito.when(result.getValue(Bytes.toBytes("notification"),Bytes.toBytes("notificationStatus"))).thenReturn(Bytes.toBytes(notifStatus)); + PowerMockito.when(result.getValue(Bytes.toBytes("notification"),Bytes.toBytes("notificationId"))).thenReturn(Bytes.toBytes(notifID)); + PowerMockito.when(result.getValue(Bytes.toBytes("notification"),Bytes.toBytes("notificationTopic"))).thenReturn(Bytes.toBytes(notifTopic)); + PowerMockito.when(result.getValue(Bytes.toBytes("notification"),Bytes.toBytes("notificationEntityLink"))).thenReturn(Bytes.toBytes(notifEntityLink)); + PowerMockito.when(result.getValue(Bytes.toBytes("notification"),Bytes.toBytes("notificationAction"))).thenReturn(Bytes.toBytes(notifAction)); + } + + + /** + * Helper method to load aai config from test configuration file + * This requires that the 'test_aaiconfig.properties' file is available + */ + + static void setFinalStatic(Field field, Object newValue) throws Exception { + field.setAccessible(true); + Field modifiersField = Field.class.getDeclaredField("modifiers"); + modifiersField.setAccessible(true); + modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL); + field.set(null, newValue); + } + + /** + * Partial setup for AAI config. + */ + public void partialSetupForAAIConfig(){ + + try { + setFinalStatic(AAIConfig.class.getDeclaredField("GlobalPropFileName"), "src/test/resources/test_aaiconfig.properties"); + } + catch (SecurityException e) {fail();} + catch (NoSuchFieldException e) {fail();} + catch (Exception e) {fail();} + + AAIConfig.reloadConfig(); + } + + /** + * Helper method to set the file name of aaiconfig.properties file + * + * @param field Private static filed for update + * @param newValue New value to be used + * @throws Exception the exception + */ + public void modifyFinalStatic(Field field, Object newValue) throws Exception { + field.setAccessible(true); + Field modifiersField = Field.class.getDeclaredField("modifiers"); + modifiersField.setAccessible(true); + modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL); + field.set(null, newValue); + } + +} diff --git a/aai-resources/src/test/java/org/openecomp/aai/util/DataConversionHelperTest.java b/aai-resources/src/test/java/org/openecomp/aai/util/DataConversionHelperTest.java new file mode 100644 index 0000000..356010a --- /dev/null +++ b/aai-resources/src/test/java/org/openecomp/aai/util/DataConversionHelperTest.java @@ -0,0 +1,88 @@ +/*- + * ============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.util; + +import static org.junit.Assert.assertEquals; + +import org.junit.Rule; +import org.junit.Test; +import org.powermock.modules.agent.PowerMockAgent; +import org.powermock.modules.junit4.rule.PowerMockRule; + +public class DataConversionHelperTest { + + @Rule + public PowerMockRule rule = new PowerMockRule(); + + static { + PowerMockAgent.initializeIfNeeded(); + } + + /** + * Test convertIPVersionNumToString with value "4". + */ + @Test + public void testConvertIPVersionNumToString_withNum4(){ + assertEquals(DataConversionHelper.IPVERSION_IPV4, DataConversionHelper.convertIPVersionNumToString("4")); + } + + /** + * Test convertIPVersionNumToString with value "6". + */ + @Test + public void testConvertIPVersionNumToString_withNum6(){ + assertEquals(DataConversionHelper.IPVERSION_IPV6, DataConversionHelper.convertIPVersionNumToString("6")); + } + + /** + * Test convertIPVersionNumToString with a value other than "4" or "6". + */ + @Test + public void testConvertIPVersionNumToString_withAThirdNumber(){ + assertEquals(DataConversionHelper.IPVERSION_UNKNOWN, DataConversionHelper.convertIPVersionNumToString("-1")); + } + + /** + * Test convertIPVersionStringToNum with "v4". + */ + @Test + public void testConvertIPVersionStringToNum_withV4(){ + assertEquals("4", DataConversionHelper.convertIPVersionStringToNum(DataConversionHelper.IPVERSION_IPV4)); + } + + /** + * Test convertIPVersionStringToNum with "v6". + */ + @Test + public void testConvertIPVersionStringToNum_withV6(){ + assertEquals("6", DataConversionHelper.convertIPVersionStringToNum(DataConversionHelper.IPVERSION_IPV6)); + } + + /** + * Test convertIPVersionStringToNum with an illegal version. + */ + @Test + public void testConvertIPVersionStringToNum_withRandomString(){ + assertEquals("0", DataConversionHelper.convertIPVersionStringToNum("test string")); + } + + +} diff --git a/aai-resources/src/test/java/org/openecomp/aai/util/DeleteResourceTest.java b/aai-resources/src/test/java/org/openecomp/aai/util/DeleteResourceTest.java new file mode 100644 index 0000000..1522e80 --- /dev/null +++ b/aai-resources/src/test/java/org/openecomp/aai/util/DeleteResourceTest.java @@ -0,0 +1,108 @@ +/*- + * ============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.util; + + + +import static org.junit.Assert.assertEquals; + +import static org.junit.Assert.assertFalse; + +import static org.junit.Assert.assertTrue; + +import static org.junit.Assert.fail; + +import org.junit.Test; + + + +import org.openecomp.aai.domain.yang.PhysicalLink; + + + +public class DeleteResourceTest { + + + + /** + * Test getInstance. + */ + + @Test + + public void testGetInstance(){ + + Object obj = null; + + try { + + obj = DeleteResource.getInstance(DeleteResource.class); + + } catch (IllegalAccessException | InstantiationException e) { + + e.printStackTrace(); + + } + + assertTrue("Didn't get right instance", obj instanceof DeleteResource); + + } + + + + /** + * Test GetResourceVersion. + */ + + @Test + + public void testGetResourceVersion(){ + + String version = "aVersion"; + + PhysicalLink plink = new PhysicalLink(); + + plink.setResourceVersion(version); + + assertEquals("Versions didn't match", version, DeleteResource.GetResourceVersion(plink)); + + } + + + + /** + * Test null in GetResourceVersion. + */ + + @Test + + public void testGetResourceVersion_withNull(){ + + PhysicalLink plink = new PhysicalLink(); + + assertEquals("Versions didn't match", null, DeleteResource.GetResourceVersion(plink)); + + } + + + +} + diff --git a/aai-resources/src/test/java/org/openecomp/aai/util/JettyObfuscationConversionCommandLineUtilTest.java b/aai-resources/src/test/java/org/openecomp/aai/util/JettyObfuscationConversionCommandLineUtilTest.java new file mode 100644 index 0000000..e1fb24a --- /dev/null +++ b/aai-resources/src/test/java/org/openecomp/aai/util/JettyObfuscationConversionCommandLineUtilTest.java @@ -0,0 +1,71 @@ +/*- + * ============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.util; + +import static org.junit.Assert.*; + +import java.io.ByteArrayOutputStream; +import java.io.PrintStream; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.junit.Test; + + +public class JettyObfuscationConversionCommandLineUtilTest { + private final ByteArrayOutputStream testOut = new ByteArrayOutputStream(); + + /** + * Test. + */ + @Test + public void test() { + //setup, this will catch main's print statements for evaluation + System.setOut(new PrintStream(testOut)); + + /* ------ TEST OBFUSCATION ----*/ + JettyObfuscationConversionCommandLineUtil.main(new String[]{"-e", "hello world"}); + /* + * testOut was also catching any logging statements which interfered with result checking. + * This regex business was the workaround - it tries to find the expected value in + * the results and asserts against that. + */ + String obfResult = testOut.toString(); + String obfExpected = "OBF:1thf1ugo1x151wfw1ylz11tr1ymf1wg21x1h1uh21th7"; + Pattern obfExpectPat = Pattern.compile(obfExpected); + Matcher obfMatch = obfExpectPat.matcher(obfResult); + assertTrue(obfMatch.find()); + + testOut.reset(); //clear out previous result + + /* ------ TEST DEOBFUSCATION ----- */ + JettyObfuscationConversionCommandLineUtil.main(new String[]{"-d", obfExpected}); + String deobfResult = testOut.toString(); + String deobfExpected = "hello world"; + Pattern deobfExpectPat = Pattern.compile(deobfExpected); + Matcher deobfMatch = deobfExpectPat.matcher(deobfResult); + assertTrue(deobfMatch.find()); + + //clean up, resets to stdout + System.setOut(null); + } + +} diff --git a/aai-resources/src/test/resources/bundleconfig-local/etc/appprops/aaiconfig.properties b/aai-resources/src/test/resources/bundleconfig-local/etc/appprops/aaiconfig.properties index 0558b26..3bd26bf 100644 --- a/aai-resources/src/test/resources/bundleconfig-local/etc/appprops/aaiconfig.properties +++ b/aai-resources/src/test/resources/bundleconfig-local/etc/appprops/aaiconfig.properties @@ -49,7 +49,7 @@ ecm.auth.password.x=OBF:1igd1i9a1jnb1yte1vv11vu91yt81jk71i6o1idt aai.avpn.interim.laginterface=ae0 aai.server.url.base=https://localhost:8443/aai/ -aai.server.url=https://localhost:8443/aai/v9/ +aai.server.url=https://localhost:8443/aai/v10/ aai.global.callback.url=https://localhost:8443/aai/ aai.auth.cspcookies_on=false @@ -94,22 +94,22 @@ aai.servicedescription.vusp=VIRTUAL USP aai.servicedescription.vvig=vVIGaaS aai.servicedescription.lrsi=LRSI-OSPF -aai.notification.current.version=v9 +aai.notification.current.version=v10 aai.notificationEvent.default.status=UNPROCESSED aai.notificationEvent.default.eventType=AAI-EVENT aai.notificationEvent.default.domain=devINT1 aai.notificationEvent.default.sourceName=aai aai.notificationEvent.default.sequenceNumber=0 aai.notificationEvent.default.severity=NORMAL -aai.notificationEvent.default.version=v9 +aai.notificationEvent.default.version=v10 # This one lets us enable/disable resource-version checking on updates/deletes aai.resourceversion.enableflag=true aai.logging.maxStackTraceEntries=10 -aai.default.api.version=v9 +aai.default.api.version=v10 # Used by Model-processing code aai.model.delete.sleep.per.vtx.msec=500 -aai.model.query.resultset.maxcount=30 +aai.model.query.resultset.maxcount=50 aai.model.query.timeout.sec=90 # Used by Data Grooming @@ -138,3 +138,5 @@ aai.dmaap.workload.enableEventProcessing=true aai.realtime.clients=RO,SDNC,MSO aai.server.rebind=g +aai.run.migrations=false +ecm.auth.password.x=OBF:1igd1i9a1jnb1yte1vv11vu91yt81jk71i6o1idt diff --git a/aai-resources/src/test/resources/bundleconfig-local/etc/appprops/error.properties b/aai-resources/src/test/resources/bundleconfig-local/etc/appprops/error.properties index 4e98d62..11416ca 100644 --- a/aai-resources/src/test/resources/bundleconfig-local/etc/appprops/error.properties +++ b/aai-resources/src/test/resources/bundleconfig-local/etc/appprops/error.properties @@ -110,6 +110,7 @@ AAI_6142=5:4:INFO:6142:400:3000:Retrying transaction AAI_6143=5:4:INFO:6143:400:3000:Ghost vertex found AAI_6144=5:4:WARN:6144:400:3000:Cycle found in graph AAI_6145=5:4:ERROR:6145:400:3000:Cannot create a nested/containment edge via relationship +AAI_6146=5:4:ERROR:6146:400:3000:Ambiguous identity map found, use a URI instead #--- aaicsvp: 7101-7199 AAI_7101=5:4:ERROR:7101:500:3002:Unexpected error in CSV file processing diff --git a/aai-resources/src/test/resources/com/att/aai/introspection/aai_oxm_v10.xml b/aai-resources/src/test/resources/com/att/aai/introspection/aai_oxm_v10.xml index cf53ad2..8479470 100644 --- a/aai-resources/src/test/resources/com/att/aai/introspection/aai_oxm_v10.xml +++ b/aai-resources/src/test/resources/com/att/aai/introspection/aai_oxm_v10.xml @@ -8,9 +8,7 @@ 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 - + 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. @@ -1215,7 +1213,7 @@ - + @@ -1598,6 +1596,7 @@ + @@ -5818,6 +5817,7 @@ value="the ASDC model id for this resource or service model." /> + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - - + - + + - + - + - + - + + - + - + - + + - - + - - - - - - + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + - + + + + + + + - - - + + + + + - + - - - - - - - - - - + + + - + - + - + - + - + - + - + - + + + + + + - + + + + + + + + + + - + @@ -359,12 +5692,12 @@ - + - + @@ -378,219 +5711,5 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- cgit 1.2.3-korg