From 9a55549bd44151c424d3033692f677d697f4f1a5 Mon Sep 17 00:00:00 2001 From: Venkata Harish K Kajur Date: Fri, 19 May 2017 11:31:27 -0400 Subject: Add the necessary tools for resources and logbacks Change-Id: Ia86de3587ffafe98c427f0fcfd45d2e6453f6db2 Signed-off-by: Venkata Harish K Kajur --- .../etc/appprops/aaiconfig.properties | 11 +- aai-resources/pom.xml | 17 +- .../java/org/openecomp/aai/dbgen/DataSnapshot.java | 280 +++++++++ .../org/openecomp/aai/util/DeleteResource.java | 221 +++++++ .../java/org/openecomp/aai/util/GetResource.java | 140 +++++ .../org/openecomp/aai/util/HttpsAuthClient.java | 179 ++++++ .../java/org/openecomp/aai/util/PostResource.java | 170 +++++ .../java/org/openecomp/aai/util/PutResource.java | 412 +++++++++++++ .../org/openecomp/aai/util/RestController.java | 685 +++++++++++++++++++++ .../org/openecomp/aai/util/UpdateResource.java | 126 ++++ aai-resources/src/main/scripts/audit_schema.sh | 48 ++ aai-resources/src/main/scripts/dataGrooming.sh | 134 ++++ .../src/main/scripts/dataRestoreFromSnapshot.sh | 88 +++ aai-resources/src/main/scripts/dataSnapshot.sh | 54 ++ aai-resources/src/main/scripts/deleteTool.sh | 56 ++ aai-resources/src/main/scripts/deobfuscatePW.sh | 57 ++ aai-resources/src/main/scripts/edgeTagger.sh | 96 +++ aai-resources/src/main/scripts/forceDeleteTool.sh | 100 +++ aai-resources/src/main/scripts/getTool.sh | 56 ++ aai-resources/src/main/scripts/notifyTool.sh | 56 ++ aai-resources/src/main/scripts/postTool.sh | 56 ++ aai-resources/src/main/scripts/putTool.sh | 56 ++ aai-resources/src/main/scripts/rshipTool.sh | 70 +++ aai-resources/src/main/scripts/schemaMod.sh | 89 +++ aai-resources/src/main/scripts/updateTool.sh | 56 ++ 25 files changed, 3303 insertions(+), 10 deletions(-) create mode 100644 aai-resources/src/main/java/org/openecomp/aai/dbgen/DataSnapshot.java create mode 100644 aai-resources/src/main/java/org/openecomp/aai/util/DeleteResource.java create mode 100644 aai-resources/src/main/java/org/openecomp/aai/util/GetResource.java create mode 100644 aai-resources/src/main/java/org/openecomp/aai/util/HttpsAuthClient.java create mode 100644 aai-resources/src/main/java/org/openecomp/aai/util/PostResource.java create mode 100644 aai-resources/src/main/java/org/openecomp/aai/util/PutResource.java create mode 100644 aai-resources/src/main/java/org/openecomp/aai/util/RestController.java create mode 100644 aai-resources/src/main/java/org/openecomp/aai/util/UpdateResource.java create mode 100644 aai-resources/src/main/scripts/audit_schema.sh create mode 100644 aai-resources/src/main/scripts/dataGrooming.sh create mode 100644 aai-resources/src/main/scripts/dataRestoreFromSnapshot.sh create mode 100644 aai-resources/src/main/scripts/dataSnapshot.sh create mode 100644 aai-resources/src/main/scripts/deleteTool.sh create mode 100644 aai-resources/src/main/scripts/deobfuscatePW.sh create mode 100644 aai-resources/src/main/scripts/edgeTagger.sh create mode 100644 aai-resources/src/main/scripts/forceDeleteTool.sh create mode 100644 aai-resources/src/main/scripts/getTool.sh create mode 100644 aai-resources/src/main/scripts/notifyTool.sh create mode 100644 aai-resources/src/main/scripts/postTool.sh create mode 100644 aai-resources/src/main/scripts/putTool.sh create mode 100644 aai-resources/src/main/scripts/rshipTool.sh create mode 100644 aai-resources/src/main/scripts/schemaMod.sh create mode 100644 aai-resources/src/main/scripts/updateTool.sh diff --git a/aai-resources/bundleconfig-local/etc/appprops/aaiconfig.properties b/aai-resources/bundleconfig-local/etc/appprops/aaiconfig.properties index 46f9856..ad651d2 100644 --- a/aai-resources/bundleconfig-local/etc/appprops/aaiconfig.properties +++ b/aai-resources/bundleconfig-local/etc/appprops/aaiconfig.properties @@ -21,14 +21,17 @@ aai.transaction.logging=true aai.transaction.logging.get=true aai.transaction.logging.post=true +aai.tools.enableBasicAuth=true +aai.tools.username=AAI +aai.tools.password=AAI ecm.openstack.tenantid=b0a529aba48440a39e0caf1aea9b27e3 aai.avpn.interim.laginterface=ae0 -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.server.url.base=https://localhost:8447/aai/ +aai.server.url=https://localhost:8447/aai/v10/ +aai.global.callback.url=https://localhost:8447/aai/ aai.auth.cspcookies_on=false aai.dbmodel.filename=ex5.json @@ -57,7 +60,7 @@ aai.precheck.cloudinfrastructure.complex.defaults.region=US # single primary server aai.primary.filetransfer.serverlist=ONAPserverTBD -aai.primary.filetransfer.primarycheck=echo:8443/aai/util/echo +aai.primary.filetransfer.primarycheck=echo:8447/aai/util/echo aai.primary.filetransfer.pingtimeout=5000 aai.primary.filetransfer.pingcount=5 diff --git a/aai-resources/pom.xml b/aai-resources/pom.xml index e66b72b..5222ab9 100644 --- a/aai-resources/pom.xml +++ b/aai-resources/pom.xml @@ -20,7 +20,7 @@ ${basedir}/target/swm/package/nix/dist_files/ yyyyMMdd'T'HHmmss 1.0.0 - 1.1.0-SNAPSHOT + 1.1.0-SNAPSHOT java jacoco ${project.build.directory}/surefire-reports @@ -31,7 +31,7 @@ - org.openecomp.aai + org.onap.aai.aai-common aai-core ${aai-core.version} @@ -42,9 +42,9 @@ - org.openecomp.aai + org.onap.aai.aai-common aai-schema - ${aai-schema.version} + ${aai.schema.version} ajsc-runner @@ -445,6 +445,11 @@ json-path 2.0.0 + + com.sun.jersey + jersey-json + 1.18 + aai-resources @@ -496,9 +501,9 @@ - org.openecomp.aai + org.onap.aai.aai-common aai-schema - ${aai-schema.version} + ${aai.schema.version} bundleconfig-local/etc oxm/*.xml 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 new file mode 100644 index 0000000..68bebc2 --- /dev/null +++ b/aai-resources/src/main/java/org/openecomp/aai/dbgen/DataSnapshot.java @@ -0,0 +1,280 @@ +/*- + * ============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.ByteArrayOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Iterator; +import java.util.Properties; +import java.util.TimeZone; + +import org.apache.tinkerpop.gremlin.structure.io.IoCore; +import org.apache.tinkerpop.gremlin.structure.io.graphson.LegacyGraphSONReader; + +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.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import com.thinkaurelius.titan.core.TitanGraph; +import com.thinkaurelius.titan.core.TitanVertex; +import com.thinkaurelius.titan.core.util.TitanCleanup; + +public class DataSnapshot { + + private static EELFLogger LOGGER; + /** + * 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_DATA_SNAPSHOT_LOGBACK_PROPS); + props.setProperty(Configuration.PROPERTY_LOGGING_FILE_PATH, AAIConstants.AAI_HOME_ETC_APP_PROPERTIES); + LOGGER = EELFManager.getInstance().getLogger(DataSnapshot.class); + Boolean dbClearFlag = false; + TitanGraph graph = null; + String command = "JUST_TAKE_SNAPSHOT"; // This is the default + String oldSnapshotFileName = ""; + if (args.length == 1) { + command = args[0]; + } + if (args.length == 2) { + // If they pass in a RELOAD_ENTIRE_DB argument, then we will be + // reloading the database + // from the filename passed in -which will be expected to be found + // in our snapshot directory. + command = args[0]; + oldSnapshotFileName = args[1]; + } + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + try { + AAIConfig.init(); + ErrorLogHelper.loadProperties(); + System.out.println("Command = " + command + ", oldSnapshotFileName = " + oldSnapshotFileName); + String targetDir = AAIConstants.AAI_HOME + AAIConstants.AAI_FILESEP + "logs" + AAIConstants.AAI_FILESEP + "data" + AAIConstants.AAI_FILESEP + "dataSnapshots"; + + // Make sure the dataSnapshots directory is there + new File(targetDir).mkdirs(); + + 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 DataSnapshot.java\n"; + System.out.println(emsg); + System.exit(1); + } + + if (command.equals("JUST_TAKE_SNAPSHOT")) { + // ------------------------------------------ + // They just want to take a snapshot. + // ------------------------------------------ + SimpleDateFormat d = new SimpleDateFormat("yyyyMMddHHmm"); + d.setTimeZone(TimeZone.getTimeZone("GMT")); + String dteStr = d.format(new Date()).toString(); + String newSnapshotOutFname = targetDir + AAIConstants.AAI_FILESEP + "dataSnapshot.graphSON." + dteStr; + + graph.io(IoCore.graphson()).writeGraph(newSnapshotOutFname); + + System.out.println("Snapshot written to " + newSnapshotOutFname); + /**** + * Don't really want to do this every hour ************** int + * vCount = 0; Iterator vIt = + * graph.query().vertices().iterator(); while( vIt.hasNext() ){ + * vCount++; vIt.next(); } System.out.println( + * "A little after taking the snapshot, we see: " + vCount + + * " vertices in the db."); + ************/ + } else if (command.equals("CLEAR_ENTIRE_DATABASE")) { + // ------------------------------------------------------------------ + // They are calling this to clear the db before re-loading it + // later + // ------------------------------------------------------------------ + + // First - make sure the backup file they will be using can be + // found and has data + if (oldSnapshotFileName.equals("")) { + String emsg = "No oldSnapshotFileName passed to DataSnapshot."; + System.out.println(emsg); + System.exit(1); + } + String oldSnapshotFullFname = targetDir + AAIConstants.AAI_FILESEP + oldSnapshotFileName; + File f = new File(oldSnapshotFullFname); + if (!f.exists()) { + String emsg = "oldSnapshotFile " + oldSnapshotFullFname + " could not be found."; + System.out.println(emsg); + System.exit(1); + } else if (!f.canRead()) { + String emsg = "oldSnapshotFile " + oldSnapshotFullFname + " could not be read."; + System.out.println(emsg); + System.exit(1); + } else if (f.length() == 0) { + String emsg = "oldSnapshotFile " + oldSnapshotFullFname + " had no data."; + System.out.println(emsg); + System.exit(1); + } + + System.out.println("\n>>> WARNING <<<< "); + System.out.println(">>> All data and schema in this database will be removed at this point. <<<"); + System.out.println(">>> Processing will begin in 5 seconds. <<<"); + System.out.println(">>> WARNING <<<< "); + + try { + // Give them a chance to back out of this + Thread.sleep(5000); + } catch (java.lang.InterruptedException ie) { + System.out.println(" DB Clearing has been aborted. "); + System.exit(1); + } + + System.out.println(" Begin clearing out old data. "); + graph.close(); + TitanCleanup.clear(graph); + System.out.println(" Done clearing data. "); + System.out.println(">>> IMPORTANT - NOTE >>> you need to run the SchemaGenerator (use GenTester) before "); + System.out.println(" reloading data or the data will be put in without indexes. "); + dbClearFlag = true; + + } else if (command.equals("RELOAD_LEGACY_DATA")) { + // ------------------------------------------------------------------- + // They want to restore the database from an old snapshot file + // ------------------------------------------------------------------- + if (oldSnapshotFileName.equals("")) { + String emsg = "No oldSnapshotFileName passed to DataSnapshot when RELOAD_LEGACY_DATA used."; + System.out.println(emsg); + System.exit(1); + } + String oldSnapshotFullFname = targetDir + AAIConstants.AAI_FILESEP + oldSnapshotFileName; + File f = new File(oldSnapshotFullFname); + if (!f.exists()) { + String emsg = "oldSnapshotFile " + oldSnapshotFullFname + " could not be found."; + System.out.println(emsg); + System.exit(1); + } else if (!f.canRead()) { + String emsg = "oldSnapshotFile " + oldSnapshotFullFname + " could not be read."; + System.out.println(emsg); + System.exit(1); + } else if (f.length() == 0) { + String emsg = "oldSnapshotFile " + oldSnapshotFullFname + " had no data."; + System.out.println(emsg); + System.exit(1); + } + + System.out.println("We will load data IN from the file = " + oldSnapshotFullFname); + System.out.println(" Begin reloading Titan 0.5 data. "); + + LegacyGraphSONReader lgr = LegacyGraphSONReader.build().create(); + InputStream is = new FileInputStream(oldSnapshotFullFname); + lgr.readGraph(is, graph); + + System.out.println("Completed the inputGraph command, now try to commit()... "); + graph.tx().commit(); + System.out.println("Completed reloading Titan 0.5 data."); + + int vCount = 0; + Iterator vIt = graph.query().vertices().iterator(); + while (vIt.hasNext()) { + vCount++; + vIt.next(); + } + System.out.println("A little after repopulating from an old snapshot, we see: " + vCount + " vertices in the db."); + } else if (command.equals("RELOAD_DATA")) { + // ------------------------------------------------------------------- + // They want to restore the database from an old snapshot file + // ------------------------------------------------------------------- + if (oldSnapshotFileName.equals("")) { + String emsg = "No oldSnapshotFileName passed to DataSnapshot when RELOAD_DATA used."; + System.out.println(emsg); + System.exit(1); + } + String oldSnapshotFullFname = targetDir + AAIConstants.AAI_FILESEP + oldSnapshotFileName; + File f = new File(oldSnapshotFullFname); + if (!f.exists()) { + String emsg = "oldSnapshotFile " + oldSnapshotFullFname + " could not be found."; + System.out.println(emsg); + System.exit(1); + } else if (!f.canRead()) { + String emsg = "oldSnapshotFile " + oldSnapshotFullFname + " could not be read."; + System.out.println(emsg); + System.exit(1); + } else if (f.length() == 0) { + String emsg = "oldSnapshotFile " + oldSnapshotFullFname + " had no data."; + System.out.println(emsg); + System.exit(1); + } + + System.out.println("We will load data IN from the file = " + oldSnapshotFullFname); + System.out.println(" Begin reloading data. "); + graph.io(IoCore.graphson()).readGraph(oldSnapshotFullFname); + System.out.println("Completed the inputGraph command, now try to commit()... "); + graph.tx().commit(); + System.out.println("Completed reloading data."); + + int vCount = 0; + Iterator vIt = graph.query().vertices().iterator(); + while (vIt.hasNext()) { + vCount++; + vIt.next(); + } + System.out.println("A little after repopulating from an old snapshot, we see: " + vCount + " vertices in the db."); + } else { + String emsg = "Bad command passed to DataSnapshot: [" + command + "]"; + System.out.println(emsg); + System.exit(1); + } + + } catch (AAIException e) { + ErrorLogHelper.logError("AAI_6128", e.getMessage()); + } catch (Exception ex) { + ErrorLogHelper.logError("AAI_6128", ex.getMessage()); + } finally { + if (!dbClearFlag && graph != null) { + // Any changes that worked correctly should have already done + // thier commits. + if (graph.isOpen()) { + graph.tx().rollback(); + graph.close(); + } + } + try { + baos.close(); + } catch (IOException iox) { + } + } + + System.exit(0); + + }// End of main() + +} 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 new file mode 100644 index 0000000..81ee621 --- /dev/null +++ b/aai-resources/src/main/java/org/openecomp/aai/util/DeleteResource.java @@ -0,0 +1,221 @@ +/*- + * ============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.lang.reflect.Field; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Properties; +import java.util.Scanner; +import java.util.UUID; + +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 com.att.eelf.configuration.Configuration; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import com.google.common.base.CaseFormat; + + +public class DeleteResource { + + private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(DeleteResource.class); + 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 + // code may need to be adjusted if different nodetypes are added here + private static final String[] nodeTypeList = {"complex", "availability-zone", "oam-network", + "dvs-switch", "vserver", "vpe", "vpls-pe"}; + + private static final String USAGE_STRING = "Usage: deleteTool.sh \n + " + + "for example: resource-path for a particular customer is business/customers/customer/global-customer-id-1 \n"; + + /** + * The main method. + * + * @param the generic type + * @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_DELTOOL_LOGBACK_PROPS); + props.setProperty(Configuration.PROPERTY_LOGGING_FILE_PATH, AAIConstants.AAI_HOME_ETC_APP_PROPERTIES); + + String url = null; + try { + if ((args.length < 1) || ((args.length > 1) )) { + System.out.println("Insufficient or Invalid arguments"); + System.out.println(USAGE_STRING); + System.exit(1); + } + + Boolean bResVersionEnabled = false; + + try + { + String strEnableResVersion = AAIConfig.get(AAIConstants.AAI_RESVERSION_ENABLEFLAG); + if (strEnableResVersion != null && !strEnableResVersion.isEmpty()) + bResVersionEnabled = Boolean.valueOf(strEnableResVersion); + } + catch (Exception e) { + + } + + // Assume the config AAI_SERVER_URL has a last slash so remove if + // resource-path has it as the first char + String path = args[0].replaceFirst("^/", ""); + + Path p = Paths.get(path); + + // if the node type has one key + String resource = p.getName(p.getNameCount() - 2).toString(); + + IngestModelMoxyOxm moxyMod = new IngestModelMoxyOxm(); + DbMaps dbMaps = null; + try { + ArrayList defaultVerLst = new ArrayList (); + defaultVerLst.add( AAIConfig.get(AAIConstants.AAI_DEFAULT_API_VERSION_PROP) ); + moxyMod.init( defaultVerLst, false); + // Just make sure we can get DbMaps - don't actually need it until later. + dbMaps = IngestModelMoxyOxm.dbMapsContainer.get(AAIConfig.get(AAIConstants.AAI_DEFAULT_API_VERSION_PROP)); + } + catch (Exception ex){ + ErrorLogHelper.logError("AAI_7402", " ERROR - Could not get the DbMaps object: " + ex.getMessage()); + System.exit(1); + } + // if the node type has two keys - this assumes max 2 keys + if (!dbMaps.NodeKeyProps.containsKey(resource)) + resource = p.getName(p.getNameCount() - 3).toString(); + 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); + + if (bResVersionEnabled) + { + RestObject restObj = new RestObject(); + @SuppressWarnings("unchecked") + T t = (T)getInstance(Class.forName(resourceClass)); + restObj.set(t); + + try + { + RestController.Get(t, FROMAPPID, TRANSID, path, restObj, false); + t = restObj.get(); + LOGGER.info(" GET resoruceversion succeeded\n"); + String resourceUpdateVersion = GetResourceVersion(t); + path += "?resource-version=" + resourceUpdateVersion; + } catch (AAIException e) { + if (e.getMessage().contains("with status=404") && resource.equals("named-query")) { + System.out.println("Delete succeeded, the resource doesn't exist in the DB. " + p); + System.exit(0); + } else { + System.out.println("Delete failed. Resource Not found in the DB."); + System.exit(1); + } + } catch (Exception e1){ + System.out.println("Delete failed. Resource Not found in the DB."); + System.exit(1); + } + } + + System.out.print("\nAre you sure you would like to delete the resource \n" + url + "? (y/n): "); + Scanner s = new Scanner(System.in); + s.useDelimiter(""); + String confirm = s.next(); + + if (!confirm.equalsIgnoreCase("y")) { + LOGGER.info("User chose to exit before deleting"); + System.exit(1); + } + + RestController.Delete(FROMAPPID, TRANSID, path); + + s.close(); + System.exit(0); + + } catch (AAIException e) { + ErrorLogHelper.logException(e); + System.exit(1); + } catch (Exception e) { + ErrorLogHelper.logError("AAI_7402", e.getMessage()); + System.exit(1); + } + + } + + /** + * Gets the single instance of DeleteResource. + * + * @param the generic type + * @param clazz the clazz + * @return single instance of DeleteResource + * @throws IllegalAccessException the illegal access exception + * @throws InstantiationException the instantiation exception + */ + public static T getInstance(Class clazz) throws IllegalAccessException, InstantiationException + { + return clazz.newInstance(); + } + + /** + * Gets the resource version. + * + * @param the generic type + * @param resource the resource + * @return the string + */ + public static String GetResourceVersion(T resource) + { + Field[] fields = resource.getClass().getDeclaredFields(); + if (fields != null) + { + for (Field field : fields) + { + try + { + field.setAccessible(true); + if ( field.getName().equalsIgnoreCase("resourceVersion") ) + { + Object obj = field.get(resource); + return (String)obj; + } + + + } + catch (Exception e) + { + + } + + + } + } + return null; + } +} 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 new file mode 100644 index 0000000..f16efb3 --- /dev/null +++ b/aai-resources/src/main/java/org/openecomp/aai/util/GetResource.java @@ -0,0 +1,140 @@ +/*- + * ============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.security.KeyManagementException; +import java.util.Properties; +import java.util.UUID; + +import org.openecomp.aai.exceptions.AAIException; +import org.openecomp.aai.logging.ErrorLogHelper; +import com.att.eelf.configuration.Configuration; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.sun.jersey.api.client.Client; +import com.sun.jersey.api.client.ClientResponse; + + +public class GetResource { + + private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(GetResource.class); + 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 + " + + "for example: resource-path for a particular customer is business/customers/customer/global-customer-id-1 \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_GETRES_LOGBACK_PROPS); + props.setProperty(Configuration.PROPERTY_LOGGING_FILE_PATH, AAIConstants.AAI_HOME_ETC_APP_PROPERTIES); + + String url = null; + try { + if (args.length < 1) { + System.out.println("Nothing to get or Insufficient arguments"); + System.out.println(USAGE_STRING); + System.exit(1); + } else { + // Assume the config AAI_SERVER_URL has a last slash so remove if + // resource-path has it as the first char + url = args[0].replaceFirst("^/", ""); + url = AAIConfig.get(AAIConstants.AAI_SERVER_URL) + url; + + LOGGER.debug("url=" + url); + getNode(url); + System.exit(0); + } + } catch (AAIException e) { + LOGGER.error("GET failed: " + e.getMessage()); + ErrorLogHelper.logException(e); + System.exit(1); + } catch (Exception e) { + LOGGER.error("GET failed: " + e.getMessage()); + ErrorLogHelper.logError("AAI_7402", e.getMessage()); + System.exit(1); + } + + } + + /** + * Gets the node. + * + * @param aaiLogger the aai logger + * @param logline the logline + * @param url the url + * @return the node + * @throws AAIException the AAI exception + */ + public static void getNode(String url) throws AAIException { + try { + String useBasicAuth = AAIConfig.get("aai.tools.enableBasicAuth"); + Client client = null; + + if("true".equals(useBasicAuth)){ + client = HttpsAuthClient.getBasicAuthClient(); + } else { + client = HttpsAuthClient.getTwoWaySSLClient(); + } + + System.out.println("Getting the resource...: " + url); + + ClientResponse cres = client.resource(url) + .header("X-TransactionId", TRANSID) + .header("X-FromAppId", FROMAPPID) + .header("Authorization", HttpsAuthClient.getBasicAuthHeaderValue()) + + .accept("application/json") + .get(ClientResponse.class); + + if (cres.getStatus() == 404) { // resource not found + LOGGER.info("\nResource does not exist: " + cres.getStatus() + + ":" + cres.getEntity(String.class)); + throw new AAIException("AAI_7404", "Resource does not exist"); + } else if (cres.getStatus() == 200){ + String msg = cres.getEntity(String.class); + ObjectMapper mapper = new ObjectMapper(); + Object json = mapper.readValue(msg, Object.class); + String indented = mapper.writerWithDefaultPrettyPrinter() + .writeValueAsString(json); + LOGGER.info(indented); + } else { + LOGGER.error("Getting the Resource failed: " + cres.getStatus() + + ":\n" + cres.getEntity(String.class)); + throw new AAIException("AAI_7402", "Error during GET"); + } + } catch (AAIException e) { + throw e; + } catch (KeyManagementException e) { + throw new AAIException("AAI_7401", e, "Error during GET"); + } catch (Exception e) { + throw new AAIException("AAI_7402", e, "Error during GET"); + } + } + +} 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 new file mode 100644 index 0000000..89562f7 --- /dev/null +++ b/aai-resources/src/main/java/org/openecomp/aai/util/HttpsAuthClient.java @@ -0,0 +1,179 @@ +/*- + * ============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.FileInputStream; +import java.security.KeyManagementException; +import java.security.KeyStore; + +import javax.net.ssl.HostnameVerifier; +import javax.net.ssl.HttpsURLConnection; +import javax.net.ssl.KeyManagerFactory; +import javax.net.ssl.SSLContext; +import javax.net.ssl.SSLSession; + +import org.openecomp.aai.domain.yang.Customers; +import org.openecomp.aai.exceptions.AAIException; +import com.sun.jersey.api.client.Client; +import com.sun.jersey.api.client.ClientResponse; +import com.sun.jersey.api.client.config.ClientConfig; +import com.sun.jersey.api.client.config.DefaultClientConfig; +import com.sun.jersey.api.client.filter.LoggingFilter; +import com.sun.jersey.api.json.JSONConfiguration; +import com.sun.jersey.client.urlconnection.HTTPSProperties; + +import static java.util.Base64.getEncoder; + +public class HttpsAuthClient{ + + /** + * The main method. + * + * @param args the arguments + */ + public static void main(String[] args) { + try { + String url = AAIConfig.get(AAIConstants.AAI_SERVER_URL) + "business/customers"; + System.out.println("Making Jersey https call..."); + Client client = HttpsAuthClient.getTwoWaySSLClient(); + + ClientResponse res = client.resource(url) + .accept("application/json") + .header("X-TransactionId", "PROV001") + .header("X-FromAppId", "AAI") + .type("application/json") + .get(ClientResponse.class); + +// System.out.println("Jersey result: "); +// System.out.println(res.getEntity(String.class).toString()); + + Customers customers = res.getEntity(Customers.class); + System.out.println("Jersey result: "); + System.out.println("Number of customers: " + customers.getCustomer().size()); + + } catch (KeyManagementException e) { + e.printStackTrace(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + + /** + * Gets the client. + * + * @return the client + * @throws KeyManagementException the key management exception + */ + public static Client getTwoWaySSLClient() 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; + } + + public static Client getBasicAuthClient() throws AAIException { + + String truststore_path = AAIConstants.AAI_HOME_ETC_AUTH + AAIConfig.get(AAIConstants.AAI_TRUSTSTORE_FILENAME); + System.setProperty("javax.net.ssl.trustStore", truststore_path); + + javax.net.ssl.HttpsURLConnection.setDefaultHostnameVerifier(new javax.net.ssl.HostnameVerifier() { + public boolean verify(String hostname, javax.net.ssl.SSLSession sslSession) { + return true; + } + }); + + String userName = AAIConfig.get("aai.tools.username"); + String password = AAIConfig.get("aai.tools.password"); + // ClientConfig config = new DefaultClientConfig(); + Client client = Client.create(); + //client.addFilter(new HTTPBasicAuthFilter(userName, password)); + + + + + return client; + } + + public static String getBasicAuthHeaderValue() throws AAIException { + + + String userName = AAIConfig.get("aai.tools.username", ""); + String password = AAIConfig.get("aai.tools.password", ""); + String authString = userName + ":" + password; + byte[] s = getEncoder().encode(authString.getBytes()); + String basicauthStringEnc = new String(s); + + return "Basic " + basicauthStringEnc; + + } + +} 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 new file mode 100644 index 0000000..72fcd86 --- /dev/null +++ b/aai-resources/src/main/java/org/openecomp/aai/util/PostResource.java @@ -0,0 +1,170 @@ +/*- + * ============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.nio.file.Path; +import java.nio.file.Paths; +import java.util.Properties; +import java.util.UUID; + +import org.openecomp.aai.exceptions.AAIException; +import org.openecomp.aai.logging.ErrorLogHelper; +import com.att.eelf.configuration.Configuration; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.common.base.CaseFormat; + +/* + * Allows to call POST REST API that AAI supports - currently for edge-tag-query + */ +public class PostResource { + + private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(PostResource.class); + 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" + + "resource-path for a particular resource or query starting after the aai/\n" + + "filename is the path to a file which contains the json input for the payload\n" + + "for example: postTool.sh search/edge-tag-query /tmp/query-input.json\n"; + + /** + * The main method. + * + * @param the generic type + * @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_POSTTOOL_LOGBACK_PROPS); + props.setProperty(Configuration.PROPERTY_LOGGING_FILE_PATH, AAIConstants.AAI_HOME_ETC_APP_PROPERTIES); + + try { + if (args.length < 2) { + System.out.println("Insufficient arguments"); + System.out.println(USAGE_STRING); + System.exit(1); + } + + // Assume the config AAI_SERVER_URL has a last slash so remove if + // resource-path has it as the first char + String path = args[0].replaceFirst("^/", ""); + Path p = Paths.get(path); + + // currently , it is for edge-taq-query only + String query = p.getName(p.getNameCount() - 1).toString(); + String resourceClass = null; + if (query.equals("edge-tag-query")) + resourceClass = "org.openecomp.aai.domain.search." + + CaseFormat.LOWER_HYPHEN.to(CaseFormat.UPPER_CAMEL, query) + "Request"; + else { + ErrorLogHelper.logError("AAI_7403", "Incorrect resource or query"); + System.exit(1); + } + + LOGGER.debug("class=" + resourceClass); + LOGGER.debug("path=" + path); + + @SuppressWarnings("unchecked") + T resJson1 = (T)readJsonFile(Class.forName(resourceClass), args[1]); + + String response = RestController.Post(resJson1, FROMAPPID, TRANSID, path); + 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!!"); + + System.exit(0); + + } catch (AAIException e) { + ErrorLogHelper.logException(e); + System.exit(1); + } catch (Exception e) { + ErrorLogHelper.logError("AAI_7402", e.getMessage()); + System.exit(1); + } + } + + /** + * Gets the single instance of PostResource. + * + * @param the generic type + * @param clazz the clazz + * @return single instance of PostResource + * @throws IllegalAccessException the illegal access exception + * @throws InstantiationException the instantiation exception + */ + public static T getInstance(Class clazz) throws IllegalAccessException, InstantiationException + { + return clazz.newInstance(); + } + + /** + * Read json file. + * + * @param the generic type + * @param clazz the clazz + * @param fName the f name + * @return the t + * @throws AAIException the AAI exception + */ + public static T readJsonFile( Class clazz, String fName ) throws AAIException + { + String jsonData = ""; + BufferedReader br = null; + T t; + + 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) { + ex.printStackTrace(); + throw new AAIException("AAI_7403", ex, "Error closing json file"); + } + } + + try { + t = MapperUtil.readWithDashesAsObjectOf(clazz, jsonData); + } + catch (Exception je){ + throw new AAIException("AAI_7403", je, "Error parsing json file"); + } + + return t; + + }//End readJsonFile() +} 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 new file mode 100644 index 0000000..70fccb1 --- /dev/null +++ b/aai-resources/src/main/java/org/openecomp/aai/util/PutResource.java @@ -0,0 +1,412 @@ +/*- + * ============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.lang.reflect.Field; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.security.KeyManagementException; +import java.util.ArrayList; +import java.util.Properties; +import java.util.UUID; + +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 com.att.eelf.configuration.Configuration; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import com.google.common.base.CaseFormat; +import com.sun.jersey.api.client.Client; +import com.sun.jersey.api.client.ClientResponse; + +/* + * SWGK - 09/03/2015 - Added Generics to Put as well as to Get the object that was created/updated + * by Put to get the Object back. + */ +public class PutResource { + + private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(PutResource.class); + 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" + + "resource-path for a particular resource starting after the aai/\n" + + "filename is the path to a file which contains the json input for the payload\n" + + "optional UpdatingRelationshiplist setting 1 for updating the relationship list and if setting 0 relationship list will not be updated.\n" + + "optional UpdatingChild setting 1 for updating the child(r)en and if setting 0 child(ren) will not be updated.\n" + + "optional ChildNameList is a comma-separated child(ren) name list only applicable if UpdatingChild is set to 1.\n" + + "optional SkipIfExisting setting 1 to skip the update if resource exists and if setting 0 put will be done.\n" + + "for example 1: putTool.sh cloud-infrastructure/oam-networks/oam-network/test-100-oam /tmp/putoam.json\n" + + "for example 2: putTool.sh cloud-infrastructure/pservers/pserver/dpa2r04c009-swgk-009 /tmp/pserver.json 0 1 PInterfaces,LagInterfaces\n" + + "for example 2: putTool.sh cloud-infrastructure/pservers/pserver/dpa2r04c009-swgk-009 /tmp/pserver.json 0 1 PInterfaces,LagInterfaces 1\n"; + + /** + * The main method. + * + * @param the generic type + * @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_PUTTOOL_LOGBACK_PROPS); + props.setProperty(Configuration.PROPERTY_LOGGING_FILE_PATH, AAIConstants.AAI_HOME_ETC_APP_PROPERTIES); + + Boolean bResVersionEnabled = false; + + try + { + String strEnableResVersion = AAIConfig.get(AAIConstants.AAI_RESVERSION_ENABLEFLAG); + if (strEnableResVersion != null && !strEnableResVersion.isEmpty()) + bResVersionEnabled = Boolean.valueOf(strEnableResVersion); + } + catch (Exception e) { + + } + + boolean doPutIfExists = true; + if (args.length > 5) + if (args[5].equals("1")) + doPutIfExists = false; + + try { + if (args.length < 2) { + System.out.println("Insufficient arguments"); + System.out.println(USAGE_STRING); + System.exit(1); + } + + // Assume the config AAI_SERVER_URL has a last slash so remove if + // resource-path has it as the first char + String path = args[0].replaceFirst("^/", ""); + Path p = Paths.get(path); + + // if the node type has one key + String resource = p.getName(p.getNameCount() - 2).toString(); + // if the node type has two keys - this assumes max 2 keys + IngestModelMoxyOxm moxyMod = new IngestModelMoxyOxm(); + DbMaps dbMaps = null; + try { + ArrayList defaultVerLst = new ArrayList (); + defaultVerLst.add( AAIConfig.get(AAIConstants.AAI_DEFAULT_API_VERSION_PROP) ); + moxyMod.init( defaultVerLst, false); + // Just make sure we can get DbMaps - don't actually need it until later. + dbMaps = IngestModelMoxyOxm.dbMapsContainer.get(AAIConfig.get(AAIConstants.AAI_DEFAULT_API_VERSION_PROP)); + } + catch (Exception ex){ + ErrorLogHelper.logError("AAI_7402", "ERROR - Could not get the DbMaps object."); + System.exit(1); + } + + if (!dbMaps.NodeKeyProps.containsKey(resource)) + resource = p.getName(p.getNameCount() - 3).toString(); + 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); + + RestObject restObj = new RestObject(); + @SuppressWarnings("unchecked") + T t2 = (T)getInstance(Class.forName(resourceClass)); + restObj.set(t2); + + boolean bExist = true; + + try + { + if ( !doPutIfExists ) { + + String url = AAIConfig.get(AAIConstants.AAI_SERVER_URL) + path; + + 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); + } + + } + RestController.Get(t2, FROMAPPID, TRANSID, path, restObj, false); + t2 = restObj.get(); + LOGGER.info(" GET succeeded\n"); + } catch (AAIException e) { + if ( !doPutIfExists ) { + LOGGER.warn("Caught exception while attempting to PUT resource", e); + } + bExist = false; + } + catch (Exception e1) + { + if ( !doPutIfExists ) { + LOGGER.warn(" GET exception ignored with skipExists parameter\n", e1); + } + bExist = false; + } + + + @SuppressWarnings("unchecked") + T resJson1 = (T)readJsonFile(Class.forName(resourceClass), args[1]); + String resourceUpdateVersion = GetResourceVersion(resJson1); + + + if (bResVersionEnabled && bExist) + { + + 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); + } + + 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"); + + System.exit(1); + } + + if ( DBresourceVersion != null && !DBresourceVersion.isEmpty() ) + { + 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"); + System.exit(1); + } + } + } + else //sanity check + { + 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); + } + + } + + if (bExist) //merge + { + boolean bUpdateChildren = false; + boolean bUpdateRL = false; + + if (args.length == 3) + { + if (args[2].equals("1")) + bUpdateRL = true; + resJson1 = MergeResource.merge(t2, resJson1, false, bUpdateRL); + } + else if (args.length == 4) + { + if (args[2].equals("1")) + bUpdateRL = true; + if (args[3].equals("1")) + bUpdateChildren = true; + resJson1 = MergeResource.merge(t2, resJson1, bUpdateChildren, bUpdateRL); + } + else if (args.length == 5) + { + if (args[2].equals("1")) + bUpdateRL = true; + if (args[3].equals("1")) + bUpdateChildren = true; + String[] strChildArray = args[4].split("\\,"); + resJson1 = MergeResource.merge(t2, resJson1, bUpdateChildren, strChildArray, bUpdateRL); + + } + else + resJson1 = MergeResource.merge(t2, resJson1); + + } + + RestController.Put(resJson1, FROMAPPID, TRANSID, path, false); + + LOGGER.info(" PUT succeeded"); + LOGGER.info("Done!!"); + + System.exit(0); + + } catch (AAIException e) { + 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!!"); + System.exit(0); + } + } + } + + ErrorLogHelper.logException(e); + System.exit(1); + } catch (Exception e) { + ErrorLogHelper.logError("AAI_7402", e.getMessage()); + System.exit(1); + } + } + + /** + * Gets the single instance of PutResource. + * + * @param the generic type + * @param clazz the clazz + * @return single instance of PutResource + * @throws IllegalAccessException the illegal access exception + * @throws InstantiationException the instantiation exception + */ + public static T getInstance(Class clazz) throws IllegalAccessException, InstantiationException + { + return clazz.newInstance(); + } + + /** + * Read json file. + * + * @param the generic type + * @param clazz the clazz + * @param fName the f name + * @return the t + * @throws AAIException the AAI exception + */ + public static T readJsonFile( Class clazz, String fName ) throws AAIException + { + String jsonData = ""; + BufferedReader br = null; + T t; + + 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 { + t = MapperUtil.readWithDashesAsObjectOf(clazz, jsonData); + } + catch (Exception je){ + throw new AAIException("AAI_7403", je, "Error parsing json file"); + } + + return t; + + }//End readJsonFile() + + /** + * Gets the resource version. + * + * @param the generic type + * @param resource the resource + * @return the string + */ + public static String GetResourceVersion(T resource) + { + Field[] fields = resource.getClass().getDeclaredFields(); + if (fields != null) + { + for (Field field : fields) + { + try + { + field.setAccessible(true); + if ( field.getName().equalsIgnoreCase("resourceVersion") ) + { + Object obj = field.get(resource); + return (String)obj; + } + + + } + catch (Exception e) + { + + } + + + } + } + return null; + } + + /** + * Node exists. + * + * @param url the url + * @return true, if successful + * @throws AAIException the AAI exception + */ + public static boolean nodeExists(String url) throws AAIException { + try{ + String useBasicAuth = AAIConfig.get("aai.tools.enableBasicAuth"); + Client client = null; + + if("true".equals(useBasicAuth)){ + client = HttpsAuthClient.getBasicAuthClient(); + } else { + client = HttpsAuthClient.getTwoWaySSLClient(); + } + + LOGGER.info("Getting the resource...: " + url); + + ClientResponse cres = client.resource(url) + .header("X-TransactionId", TRANSID) + .header("X-FromAppId", FROMAPPID) + .header("Authorization", HttpsAuthClient.getBasicAuthHeaderValue()) + .accept("application/json") + .get(ClientResponse.class); + + + if (cres.getStatus() == 404) { // resource not found + return false; + } else if (cres.getStatus() == 200){ + return true; + } else { + LOGGER.error("Getting the Resource failed: " + cres.getStatus() + + ": " + cres.getEntity(String.class)); + return false; + } + } catch (KeyManagementException e) { + throw new AAIException("AAI_7401", e, "Error during GET"); + } catch (Exception e) { + throw new AAIException("AAI_7402", e, "Error during GET"); + } + } + +} diff --git a/aai-resources/src/main/java/org/openecomp/aai/util/RestController.java b/aai-resources/src/main/java/org/openecomp/aai/util/RestController.java new file mode 100644 index 0000000..e21fd90 --- /dev/null +++ b/aai-resources/src/main/java/org/openecomp/aai/util/RestController.java @@ -0,0 +1,685 @@ +/*- + * ============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.net.MalformedURLException; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; +import java.security.KeyManagementException; +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +import org.openecomp.aai.exceptions.AAIException; +import org.openecomp.aai.logging.LoggingContext; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.type.TypeFactory; +import com.sun.jersey.api.client.Client; +import com.sun.jersey.api.client.ClientHandlerException; +import com.sun.jersey.api.client.ClientResponse; + +public class RestController { + + private static EELFLogger LOGGER = EELFManager.getInstance().getLogger(RestController.class); + + private static Client client = null; + + private String restSrvrBaseURL; + + //To do - Come up with helper function that will automatically + //generate the REST API path based on path parameter(s) and query parameter(s)! + public static final String REST_APIPATH_COMPLEXES = "cloud-infrastructure/complexes"; + public static final String REST_APIPATH_COMPLEX = "cloud-infrastructure/complexes/complex/"; + public static final String REST_APIPATH_PSERVERS = "cloud-infrastructure/pservers"; + public static final String REST_APIPATH_PSERVER = "cloud-infrastructure/pservers/pserver/"; + public static final String REST_APIPATH_PHYSICALLINKS = "network/physical-links/"; + public static final String REST_APIPATH_PHYSICALLINK = "network/physical-links/physical-link/"; + public static final String REST_APIPATH_PINTERFACES = "network/p-interfaces/"; + public static final String REST_APIPATH_PINTERFACE = "network/p-interfaces/p-interface/"; + public static final String REST_APIPATH_VPLSPES = "network/vpls-pes/"; + public static final String REST_APIPATH_VPLSPE = "network/vpls-pes/vpls-pe/"; + public static final String REST_APIPATH_UPDATE = "actions/update/"; + public static final String REST_APIPATH_SEARCH = "search/nodes-query?search-node-type="; + + public static final String REST_APIPATH_CLOUDREGION = "cloud-infrastructure/cloud-regions/cloud-region/"; + public static final String REST_APIPATH_TENANT = "cloud-infrastructure/tenants/tenant/"; + public static final String REST_APIPATH_VPE = "network/vpes/vpe/"; + public static final String REST_APIPATH_VIRTUAL_DATA_CENTER = "cloud-infrastructure/virtual-data-centers/virtual-data-center/"; + public static final String REST_APIPATH_VIRTUAL_DATA_CENTERS = "cloud-infrastructure/virtual-data-centers/"; + //network/generic-vnfs/generic-vnf/{vnf-id} + public static final String REST_APIPATH_GENERIC_VNF = "network/generic-vnfs/generic-vnf/"; + public static final String REST_APIPATH_GENERIC_VNFS = "network/generic-vnfs"; + public static final String REST_APIPATH_L3_NETWORK = "network/l3-networks/l3-network/"; + public static final String REST_APIPATH_L3_NETWORKS = "network/l3-networks"; + public static final String REST_APIPATH_INSTANCE_GROUP = "network/instance-groups/instance-group"; + public static final String REST_APIPATH_INSTANCE_GROUPS = "network/instance-groups"; + + public static final String REST_APIPATH_VCE = "network/vces/vce/"; + + public static final String REST_APIPATH_SERVICE = "service-design-and-creation/services/service/"; + public static final String REST_APIPATH_LOGICALLINKS = "network/logical-links/"; + public static final String REST_APIPATH_LOGICALLINK = "network/logical-links/logical-link/"; + + /** + * Inits the rest client. + * + * @throws AAIException the AAI exception + */ + private static void initRestClient() throws AAIException + { + if (client == null) { + try { + String useBasicAuth = AAIConfig.get("aai.tools.enableBasicAuth"); + if (useBasicAuth != null && useBasicAuth.equals("true")) { + + client = HttpsAuthClient.getBasicAuthClient(); + } else { + client = HttpsAuthClient.getTwoWaySSLClient(); + } + + } + catch (KeyManagementException e){ + throw new AAIException("AAI_7117", "KeyManagementException in REST call to DB: " + e.toString()); + } catch (Exception e) { + throw new AAIException("AAI_7117", " Exception in REST call to DB: " + e.toString()); + } + } + } + + /** + * Sets the rest srvr base URL. + * + * @param baseURL the base URL + * @throws AAIException the AAI exception + */ + public void SetRestSrvrBaseURL(String baseURL) throws AAIException + { + if (baseURL == null) + throw new AAIException("AAI_7117", "REST Server base URL cannot be null."); + restSrvrBaseURL = baseURL; + } + + /** + * Gets the rest srvr base URL. + * + * @return the rest srvr base URL + */ + public String getRestSrvrBaseURL() + { + return restSrvrBaseURL; + } + + /** + * To do - optimization and automation. Also make it as generic as possible. + * + * @param the generic type + * @param t the t + * @param sourceID the source ID + * @param transId the trans id + * @param path the path + * @param restObject the rest object + * @param oldserver the oldserver + * @throws AAIException the AAI exception + */ + @SuppressWarnings("unchecked") + public static void Get(T t, String sourceID, String transId, String path, RestObject restObject, boolean oldserver) throws AAIException { + String methodName = "Get"; + String url=""; + transId += ":" + UUID.randomUUID().toString(); + + LoggingContext.save(); + LoggingContext.partnerName(sourceID); + + LOGGER.debug(methodName + " start"); + + restObject.set(t); + + if (oldserver) + url = AAIConfig.get(AAIConstants.AAI_OLDSERVER_URL) + path; + else + url = AAIConfig.get(AAIConstants.AAI_SERVER_URL) + path; + initRestClient(); + LOGGER.debug(url + " for the get REST API"); + ClientResponse cres = client.resource(url) + .accept("application/json") + .header("X-TransactionId", transId) + .header("X-FromAppId", sourceID) + .header("Authorization", HttpsAuthClient.getBasicAuthHeaderValue()) + .type("application/json") + .get(ClientResponse.class); + +// System.out.println("cres.EntityInputSream()="+cres.getEntityInputStream().toString()); +// System.out.println("cres.tostring()="+cres.toString()); + + if (cres.getStatus() == 200) { +// System.out.println(methodName + ": url=" + url); + t = (T) cres.getEntity(t.getClass()); + restObject.set(t); + LOGGER.debug(methodName + "REST api GET was successfull!"); + } else { + LoggingContext.restore(); +// System.out.println(methodName + ": url=" + url + " failed with status=" + cres.getStatus()); + throw new AAIException("AAI_7116", methodName +" with status="+cres.getStatus()+", url="+url); + } + + LoggingContext.restore(); + } + + + /** + * + * @param the generic type + * @param t the t + * @param sourceID the source ID + * @param transId the trans id + * @param path the path + * @param restObject the rest object + * @param apiVersion the api version + * @throws AAIException the AAI exception + */ + @SuppressWarnings("unchecked") + public static void Get(T t, String sourceID, String transId, String path, RestObject restObject, String apiVersion) throws AAIException { + String methodName = "Get"; + String url=""; + transId += ":" + UUID.randomUUID().toString(); + LOGGER.debug(methodName + " start"); + + restObject.set(t); + + url = AAIConfig.get(AAIConstants.AAI_SERVER_URL_BASE) + apiVersion + "/"+ path; + + initRestClient(); + LOGGER.debug(url + " for the get REST API"); + ClientResponse cres = client.resource(url) + .accept("application/json") + .header("X-TransactionId", transId) + .header("X-FromAppId", sourceID) + .header("Authorization", HttpsAuthClient.getBasicAuthHeaderValue()) + .type("application/json") + .get(ClientResponse.class); + +// System.out.println("cres.EntityInputSream()="+cres.getEntityInputStream().toString()); +// System.out.println("cres.tostring()="+cres.toString()); + + if (cres.getStatus() == 200) { +// System.out.println(methodName + ": url=" + url); + t = (T) cres.getEntity(t.getClass()); + restObject.set(t); + LOGGER.debug(methodName + "REST api GET was successfull!"); + + } else { +// System.out.println(methodName + ": url=" + url + " failed with status=" + cres.getStatus()); + throw new AAIException("AAI_7116", methodName +" with status="+cres.getStatus()+", url="+url); + } + + } + + /** + * Gets the. + * + * @param the generic type + * @param t the t + * @param requestObj the request obj + * @throws AAIException the AAI exception + */ + public static void Get(T t, Request requestObj) throws AAIException { + String methodName = "Get"; + String url=""; + String transId = requestObj.transactionId; + transId += ":" + UUID.randomUUID().toString(); + LOGGER.debug(methodName + " start"); + + requestObj.restObj.set(t); + + if (requestObj.oldServer) + url = AAIConfig.get(AAIConstants.AAI_SERVER_URL_BASE) + "server/" + requestObj.path; + else + url = AAIConfig.get(AAIConstants.AAI_SERVER_URL_BASE) + requestObj.path; + initRestClient(); + + try { + URL urlObj= new URL(url); + URI uri = new URI(urlObj.getProtocol(), urlObj.getUserInfo(), urlObj.getHost(), urlObj.getPort(), urlObj.getPath(), urlObj.getQuery(), urlObj.getRef()); + url = uri.toASCIIString(); + } catch (URISyntaxException | MalformedURLException e) { + throw new AAIException("AAI_7116", "bad URL"); + + } + LOGGER.debug(url + " for the get REST API"); + ClientResponse cres = client.resource(url) + .accept("application/json") + .header("X-TransactionId", transId) + .header("X-FromAppId", requestObj.fromAppId) + .header("Authorization", HttpsAuthClient.getBasicAuthHeaderValue()) + .type("application/json") + .get(ClientResponse.class); + +// System.out.println("cres.EntityInputSream()="+cres.getEntityInputStream().toString()); +// System.out.println("cres.tostring()="+cres.toString()); + + if (cres.getStatus() == 200) { +// System.out.println(methodName + ": url=" + url); + t = (T) cres.getEntity(t.getClass()); + requestObj.restObj.set(t); + LOGGER.debug(methodName + "REST api GET was successfull!"); + + } else { +// System.out.println(methodName + ": url=" + url + " failed with status=" + cres.getStatus()); + throw new AAIException("AAI_7116", methodName +" with status="+cres.getStatus()+", url="+url); + } + + } + + /** + * Put. + * + * @param the generic type + * @param t the t + * @param requestObj the request obj + * @throws AAIException the AAI exception + */ + public static void Put(T t, Request requestObj) throws AAIException { + String methodName = "Put"; + String url=""; + String transId = requestObj.transactionId; + transId += ":" + UUID.randomUUID().toString(); + LOGGER.debug(methodName + " start"); + + initRestClient(); + + if (requestObj.oldServer) + url = AAIConfig.get(AAIConstants.AAI_SERVER_URL_BASE) + "server/" + requestObj.path; + else + url = AAIConfig.get(AAIConstants.AAI_SERVER_URL_BASE) + requestObj.path; + + try { + URL urlObj= new URL(url); + URI uri = new URI(urlObj.getProtocol(), urlObj.getUserInfo(), urlObj.getHost(), urlObj.getPort(), urlObj.getPath(), urlObj.getQuery(), urlObj.getRef()); + url = uri.toASCIIString(); + } catch (URISyntaxException | MalformedURLException e) { + throw new AAIException("AAI_7116", "bad URL"); + + } + ClientResponse cres = client.resource(url) + .accept("application/json") + .header("X-TransactionId", transId) + .header("X-FromAppId", requestObj.fromAppId) + .header("Authorization", HttpsAuthClient.getBasicAuthHeaderValue()) + .type("application/json") + .entity(t) + .put(ClientResponse.class); + + int statuscode = cres.getStatus(); + if ( statuscode >= 200 && statuscode <= 299 ) { + LOGGER.debug(methodName+": url=" + url + ", request=" + url); + } else { + throw new AAIException("AAI_7116", methodName +" with status="+statuscode+", url="+url); + } + } + + /** + * Multiple Generic Get. + * + * @param the generic type + * @param t the t + * @param sourceID the source ID + * @param transId the trans id + * @param path the path + * @param oldserver the oldserver + * @return the list + * @throws AAIException the AAI exception + */ + public static List Get(T t, String sourceID, String transId, String path, boolean oldserver) throws AAIException { + String methodName = "Get"; + String url=""; + transId += ":" + UUID.randomUUID().toString(); + LOGGER.debug(methodName + " start"); + + List list; + + try { + if (oldserver) + url = AAIConfig.get(AAIConstants.AAI_OLDSERVER_URL) + path; + else + url = AAIConfig.get(AAIConstants.AAI_SERVER_URL) + path; + initRestClient(); + LOGGER.debug(url + " for the get REST API"); + ClientResponse cres = client.resource(url) + .accept("application/json") + .header("X-TransactionId", transId) + .header("X-FromAppId", sourceID) + .header("Authorization", HttpsAuthClient.getBasicAuthHeaderValue()) + .type("application/json") + .get(ClientResponse.class); + + + //System.out.println("cres.EntityInputSream()="+cres.getEntityInputStream().toString()); + //System.out.println("cres.tostring()="+cres.toString()); + + if (cres.getStatus() == 200) { + //System.out.println(methodName + ": url=" + url); + //list = cres.getEntity(new GenericType>() { }); + String datainJson = cres.getEntity(String.class); + list = mapJsonToObjectList(t, datainJson, t.getClass()); + + LOGGER.debug(methodName + "REST api GET was successfull!"); + return list; + + } else { + throw new AAIException("AAI_7116", methodName +" with status="+cres.getStatus()+", url="+url); + } + } catch (AAIException e) { + throw new AAIException("AAI_7116", methodName + " with url="+url+ ", Exception: " + e.toString()); + } catch (Exception e) + { + throw new AAIException("AAI_7116", methodName + " with url="+url+ ", Exception: " + e.toString()); + + } + + } + + /** + * Map json to object list. + * + * @param the generic type + * @param typeDef the type def + * @param json the json + * @param clazz the clazz + * @return the list + * @throws Exception the exception + */ + private static List mapJsonToObjectList(T typeDef,String json, Class clazz) throws Exception + { + List list; + ObjectMapper mapper = new ObjectMapper(); + System.out.println(json); + TypeFactory t = TypeFactory.defaultInstance(); + list = mapper.readValue(json, t.constructCollectionType(ArrayList.class,clazz)); + + return list; + } + + /** + * Put. + * + * @param the generic type + * @param t the t + * @param sourceID the source ID + * @param transId the trans id + * @param path the path + * @throws AAIException the AAI exception + */ + public static void Put(T t, String sourceID, String transId, String path) throws AAIException { + Put( t, sourceID, transId, path, false); + } + + /** + * Put. + * + * @param the generic type + * @param t the t + * @param sourceID the source ID + * @param transId the trans id + * @param path the path + * @param oldserver the oldserver + * @throws AAIException the AAI exception + */ + public static void Put(T t, String sourceID, String transId, String path, boolean oldserver) throws AAIException { + String methodName = "Put"; + String url=""; + transId += ":" + UUID.randomUUID().toString(); + + LOGGER.debug(methodName + " start"); + + initRestClient(); + + if (oldserver) + url = AAIConfig.get(AAIConstants.AAI_OLDSERVER_URL) + path; + else + url = AAIConfig.get(AAIConstants.AAI_SERVER_URL) + path; + + ClientResponse cres = client.resource(url) + .accept("application/json") + .header("X-TransactionId", transId) + .header("X-FromAppId", sourceID) + .header("Authorization", HttpsAuthClient.getBasicAuthHeaderValue()) + .type("application/json") + .entity(t) + .put(ClientResponse.class); + +// System.out.println("cres.tostring()="+cres.toString()); + + int statuscode = cres.getStatus(); + if ( statuscode >= 200 && statuscode <= 299 ) { + LOGGER.debug(methodName+": url=" + url + ", request=" + path); + } else { + throw new AAIException("AAI_7116", methodName +" with status="+statuscode+", url="+url + ", msg=" + cres.getEntity(String.class)); + } + } + + /** + * Delete. + * + * @param requestObj the request obj + * @throws AAIException the AAI exception + */ + public static void Delete(Request requestObj) throws AAIException { + String methodName = "Delete"; + + String url=""; + String transId = requestObj.transactionId; + transId += ":" + UUID.randomUUID().toString(); + + LOGGER.debug(methodName + " start"); + + initRestClient(); + + if (requestObj.oldServer) + url = AAIConfig.get(AAIConstants.AAI_SERVER_URL_BASE) + "servers/" + requestObj.path; + else + url = AAIConfig.get(AAIConstants.AAI_SERVER_URL_BASE) + requestObj.path; + + try { + URL urlObj= new URL(url); + URI uri = new URI(urlObj.getProtocol(), urlObj.getUserInfo(), urlObj.getHost(), urlObj.getPort(), urlObj.getPath(), urlObj.getQuery(), urlObj.getRef()); + url = uri.toASCIIString(); + } catch (URISyntaxException | MalformedURLException e) { + throw new AAIException("AAI_7116", "bad URL"); + + } + + ClientResponse cres = client.resource(url) + .accept("application/json") + .header("X-TransactionId", transId) + .header("X-FromAppId", requestObj.fromAppId) + .header("Authorization", HttpsAuthClient.getBasicAuthHeaderValue()) + .type("application/json") + .entity("{}") + .delete(ClientResponse.class); + + if (cres.getStatus() == 204) { + LOGGER.debug(methodName+": url=" + url); + } else { + throw new AAIException("AAI_7116", methodName +" with status="+cres.getStatus()+", url="+url); + } + + } + + /** + * Delete. + * + * @param sourceID the source ID + * @param transId the trans id + * @param path the path + * @throws AAIException the AAI exception + */ + public static void Delete(String sourceID, String transId, String path) throws AAIException { + String methodName = "Delete"; + String url=""; + transId += ":" + UUID.randomUUID().toString(); + LOGGER.debug(methodName + " start"); + + initRestClient(); + String request = "{}"; + url = AAIConfig.get(AAIConstants.AAI_SERVER_URL) + path; + ClientResponse cres = client.resource(url) + .accept("application/json") + .header("X-TransactionId", transId) + .header("X-FromAppId", sourceID) + .header("Authorization", HttpsAuthClient.getBasicAuthHeaderValue()) + .type("application/json") + .entity(request) + .delete(ClientResponse.class); + + if (cres.getStatus() == 404) { // resource not found + LOGGER.info("Resource does not exist...: " + cres.getStatus() + + ":" + cres.getEntity(String.class)); + } else if (cres.getStatus() == 200 || cres.getStatus() == 204){ + LOGGER.info("Resource " + url + " deleted"); + } else { + LOGGER.error("Deleting Resource failed: " + cres.getStatus() + + ":" + cres.getEntity(String.class)); + throw new AAIException("AAI_7116", "Error during DELETE"); + } + } + + /** + * Post. + * + * @param the generic type + * @param t the t + * @param sourceID the source ID + * @param transId the trans id + * @param path the path + * @return the string + * @throws Exception the exception + */ + public static String Post(T t, String sourceID, String transId, String path) throws Exception { + String methodName = "Post"; + String url=""; + transId += ":" + UUID.randomUUID().toString(); + + LOGGER.debug(methodName + " start"); + + try { + + initRestClient(); + + url = AAIConfig.get(AAIConstants.AAI_SERVER_URL) + path; + + ClientResponse cres = client.resource(url) + .accept("application/json") + .header("X-TransactionId", transId) + .header("X-FromAppId", sourceID) + .header("Authorization", HttpsAuthClient.getBasicAuthHeaderValue()) + .type("application/json") + .entity(t) + .post(ClientResponse.class); + + int statuscode = cres.getStatus(); + if ( statuscode >= 200 && statuscode <= 299 ) { + LOGGER.debug(methodName + "REST api POST was successful!"); + return cres.getEntity(String.class); + } else { + throw new AAIException("AAI_7116", methodName +" with status="+statuscode+", url="+url + ", msg=" + cres.getEntity(String.class)); + } + + } catch (AAIException e) { + throw new AAIException("AAI_7116", methodName + " with url="+url+ ", Exception: " + e.toString()); + } catch (Exception e) + { + throw new AAIException("AAI_7116", methodName + " with url="+url+ ", Exception: " + e.toString()); + + } + } + + + /** + * Gets the single instance of RestController. + * + * @param the generic type + * @param clazz the clazz + * @return single instance of RestController + * @throws IllegalAccessException the illegal access exception + * @throws InstantiationException the instantiation exception + */ + public static T getInstance(Class clazz) throws IllegalAccessException, InstantiationException + { + return clazz.newInstance(); + } + + /** + * Does resource exist. + * + * @param the generic type + * @param resourcePath the resource path + * @param resourceClassName the resource class name + * @param fromAppId the from app id + * @param transId the trans id + * @return the t + */ + /* + * DoesResourceExist + * + * To check whether a resource exist or get a copy of the existing version of the resource + * + * Resourcepath: should contain the qualified resource path (including encoded unique key identifier value), + * resourceClassName: is the canonical name of the resource class name, + * fromAppId: + * transId: + * + * Will return null (if the resource doesn’t exist) (or) + * Will return the specified resource from the Graph. + * + * Example: + * LogicalLink llink = new LogicalLink(); + * String resourceClassName = llink.getClass().getCanonicalName(); + * llink = RestController.DoesResourceExist("network/logical-links/logical-link/" + , resourceClassName, fromAppId, transId); + */ + public static T DoesResourceExist(String resourcePath, String resourceClassName, String fromAppId, String transId) { + + try { + + RestObject restObj = new RestObject(); + @SuppressWarnings("unchecked") + T resourceObj = (T)getInstance(Class.forName(resourceClassName)); + restObj.set(resourceObj); + RestController.Get(resourceObj, fromAppId, transId, resourcePath, restObj, false); + + resourceObj = restObj.get(); + if (resourceObj != null) + return resourceObj; + + } catch (AAIException e) { + + } catch (ClientHandlerException che) { + + }catch (Exception e) { + + } + + return null; + } + +} 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 new file mode 100644 index 0000000..adecfb1 --- /dev/null +++ b/aai-resources/src/main/java/org/openecomp/aai/util/UpdateResource.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.util; + +import java.util.Properties; +import java.util.UUID; + +import org.openecomp.aai.domain.yang.Action; +import org.openecomp.aai.domain.yang.ActionData; +import org.openecomp.aai.domain.yang.Update; +import org.openecomp.aai.exceptions.AAIException; +import org.openecomp.aai.logging.ErrorLogHelper; +import com.att.eelf.configuration.Configuration; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + + +public class UpdateResource { + + private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(UpdateResource.class.getName()); + private static final String FROMAPPID = "AAIUPDT"; + private static final String TRANSID = UUID.randomUUID().toString(); + private static final String UPDATE_URL = "actions/update"; + private static final String USAGE_STRING = "Usage: updateTool.sh \n" + + " :[,: the generic type + * @param aaiLogger the aai logger + * @param logline the logline + * @param nodeType the node type + * @param nodeURI the node URI + * @param updValueList the upd value list + * @throws AAIException the AAI exception + */ + public static void update(String nodeType, String nodeURI, String updValueList) throws AAIException { + try { + Update update = new Update(); + update.setUpdateNodeType(nodeType); + update.setUpdateNodeUri(nodeURI); + + Action action = new Action(); + action.setActionType("replace"); + + for (String updValue: updValueList.split(",")) { + ActionData data = new ActionData(); + data.setPropertyName(updValue.substring(0, updValue.indexOf(':'))); + data.setPropertyValue(updValue.substring(updValue.indexOf(':') + 1)); + action.getActionData().add(data); + } + + update.getAction().add(action); + + LOGGER.info("updating the resource... "); + + RestController.Put(update, FROMAPPID, TRANSID, UPDATE_URL); + LOGGER.info("Update Successful"); + } catch (AAIException e) { + throw e; + } catch (Exception e) { + throw new AAIException("AAI_7402", e, "Error during UPDATE"); + } + } +} diff --git a/aai-resources/src/main/scripts/audit_schema.sh b/aai-resources/src/main/scripts/audit_schema.sh new file mode 100644 index 0000000..d402c1a --- /dev/null +++ b/aai-resources/src/main/scripts/audit_schema.sh @@ -0,0 +1,48 @@ +#!/bin/sh + +### +# ============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========================================================= +### + +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 [ -f "/etc/profile.d/aai.sh" ]; then + source /etc/profile.d/aai.sh +else + echo "File not found: /etc/profile.d/aai.sh"; + exit +fi + +JAVA=$JAVA_HOME/bin/java + +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 -Dhttps.protocols=TLSv1.1,TLSv1.2 -DAJSC_HOME=$PROJECT_HOME -Daai.home=$PROJECT_HOME -cp $CLASSPATH org.openecomp.aai.db.schema.ScriptDriver $@ diff --git a/aai-resources/src/main/scripts/dataGrooming.sh b/aai-resources/src/main/scripts/dataGrooming.sh new file mode 100644 index 0000000..d1df7b0 --- /dev/null +++ b/aai-resources/src/main/scripts/dataGrooming.sh @@ -0,0 +1,134 @@ +#!/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 dataGrooming java class to run some tests and generate a report and +# potentially do some auto-deleteing. +# +# Here are the allowed Parameters. Note - they are all optional and can be mixed and matched. +# +# -f oldFileName (see note below) +# -autoFix +# -sleepMinutes nn +# -edgesOnly +# -dontFixOrphans +# -maxFix +# -skipHostCheck +# -singleCommits +# -dupeCheckOff +# -dupeFixOn +# -ghost2CheckOff +# -ghost2FixOn +# +# NOTES: +# -f The name of a previous report can optionally be passed in with the "-f" option. +# Just the filename -- ie. "dataGrooming.sh -f dataGrooming.201504272106.out" +# The file will be assumed to be in the directory that it was created in. +# If a filename is passed, then the "deleteCandidate" vertex-id's and bad edges +# listed inside that report file will be deleted on this run if they are encountered as +# bad nodes/edges again. +# +# -autoFix If you don't use the "-f" option, you could choose to use "-autofix" which will +# automatically run the script twice: once to look for problems, then after +# sleeping for a few minutes, it will re-run with the inital-run's output as +# an input file. +# +# -maxFix When using autoFix, you might want to limit how many 'bad' records get fixed. +# This is a safeguard against accidently deleting too many records automatically. +# It has a default value set in AAIConstants: AAI_GROOMING_DEFAULT_MAX_FIX = 15; +# If there are more than maxFix candidates found -- then none will be deleted (ie. +# someone needs to look into it) +# +# -sleepMinutes When using autoFix, this defines how many minutes we sleep before the second run. +# It has a default value set in AAIConstants: AAI_GROOMING_DEFAULT_SLEEP_MINUTES = 7; +# The reason we sleep at all between runs is that our DB is "eventually consistant", so +# we want to give it time to resolve itself if possible. +# +# -edgesOnly Can be used any time you want to limit this tool so it only looks at edges. +# It runs much more quickly when it's just doing edges and sometimes all our +# problems are with bad edges so it can be nice to focus on edges only sometimes. +# +# -dontFixOrphans Since there can sometimes be a lot of orphan nodes, and they don't +# harm processing as much as phantom-nodes or bad-edges, it is useful to be +# able to ignore them when fixing things. +# +# -skipHostCheck By default, the grooming tool will check to see that it is running +# on the host that is the first one in the list found in: +# aaiconfig.properties aai.primary.filetransfer.serverlist +# This is so that when run from the cron, it only runs on one machine. +# This option lets you turn that checking off. +# +# -singleCommits By default, the grooming tool will do all of its processing and then do +# a commit of all the changes at once. This option (maybe could have been named better) +# is letting the user override the default behavior and do a commit for each +# individual 'remove" one by one as they are encountered by the grooming logic. +# NOTE - this only applies when using either the "-f" or "-autoFix" options since +# those are the only two that make changes to the database. +# +# -dupeCheckOff By default, we will check all of our nodes for duplicates. This parameter lets +# us turn this check off if we don't want to do it for some reason. +# +# -dupeFixOn When we're fixing data, by default we will NOT fix duplicates This parameter lets us turn +# that fixing ON when we are comfortable that it can pick the correct duplicate to preserve. +# +# -ghost2CheckOff By default, we will check for the "new" kind of ghost that we saw on +# Production in early February 2016. This parameter lets us turn this check off if we +# don't want to do it for some reason. +# +# -ghost2FixOn When we're fixing data, by default we will NOT try to fix the "new" ghost nodes. +# This parameter lets us turn that fixing ON if we want to try to fix them. +# + +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 + +for JAR in `ls $PROJECT_HOME/extJars/*.jar` +do + CLASSPATH=$CLASSPATH:$JAR +done + +for JAR in `ls $PROJECT_HOME/jetty/webapps/*/webapp/WEB-INF/lib/*.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.DataGrooming "$@" + +echo `date` " Done $0" +exit 0 diff --git a/aai-resources/src/main/scripts/dataRestoreFromSnapshot.sh b/aai-resources/src/main/scripts/dataRestoreFromSnapshot.sh new file mode 100644 index 0000000..afe7256 --- /dev/null +++ b/aai-resources/src/main/scripts/dataRestoreFromSnapshot.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 uses the dataSnapshot and SchemaGenerator (via GenTester) java classes to restore +# data to a database by doing three things: +# 1) clear out whatever data and schema are currently in the db +# 2) rebuild the schema (using the SchemaGenerator) +# 3) reload data from the passed-in datafile (which must found in the dataSnapShots directory and +# contain an xml view of the db data). +# + +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 1 ]; then + echo "Illegal number of parameters" + echo "usage: $0 previous_snapshot_filename" + exit 1 +fi + +. /etc/profile.d/aai.sh + +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 + +#### Step 1) clear out the database +$JAVA_HOME/bin/java -classpath $CLASSPATH -Dhttps.protocols=TLSv1.1,TLSv1.2 -DAJSC_HOME=$PROJECT_HOME -Daai.home=$PROJECT_HOME \ + org.openecomp.aai.dbgen.DataSnapshot CLEAR_ENTIRE_DATABASE $1 +if [ "$?" -ne "0" ]; then + echo "Problem clearing out database." + exit 1 +fi + +#### Step 2) rebuild the db-schema +$JAVA_HOME/bin/java -classpath $CLASSPATH -Dhttps.protocols=TLSv1.1,TLSv1.2 -DAJSC_HOME=$PROJECT_HOME -Daai.home=$PROJECT_HOME \ + org.openecomp.aai.dbgen.GenTester GEN_DB_WITH_NO_DEFAULT_CR +if [ "$?" -ne "0" ]; then + echo "Problem rebuilding the schema (SchemaGenerator)." + exit 1 +fi + +#### Step 3) reload the data from a snapshot file +$JAVA_HOME/bin/java -classpath $CLASSPATH -Dhttps.protocols=TLSv1.1,TLSv1.2 -DAJSC_HOME=$PROJECT_HOME -Daai.home=$PROJECT_HOME \ + org.openecomp.aai.dbgen.DataSnapshot RELOAD_DATA $1 +if [ "$?" -ne "0" ]; then + echo "Problem reloading data into the database." + exit 1 +fi + + + +echo `date` " Done $0" +exit 0 diff --git a/aai-resources/src/main/scripts/dataSnapshot.sh b/aai-resources/src/main/scripts/dataSnapshot.sh new file mode 100644 index 0000000..ef22eb6 --- /dev/null +++ b/aai-resources/src/main/scripts/dataSnapshot.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 + +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.DataSnapshot JUST_TAKE_SNAPSHOT + +echo `date` " Done $0" +exit 0 diff --git a/aai-resources/src/main/scripts/deleteTool.sh b/aai-resources/src/main/scripts/deleteTool.sh new file mode 100644 index 0000000..585f333 --- /dev/null +++ b/aai-resources/src/main/scripts/deleteTool.sh @@ -0,0 +1,56 @@ +#!/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 Deletion java class to delete customer, subs, dvs-switch, service-capability or tenants +# + +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 + +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.DeleteResource "$@" +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/deobfuscatePW.sh b/aai-resources/src/main/scripts/deobfuscatePW.sh new file mode 100644 index 0000000..965525d --- /dev/null +++ b/aai-resources/src/main/scripts/deobfuscatePW.sh @@ -0,0 +1,57 @@ +#!/bin/sh + +### +# ============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 utils.JettyObfuscationConversionCommandLineUtil class to +# deobfuscate an obfuscated name from aaiconfig property file +# e.g. +# ./deobfuscatePW.sh odl.auth.password +# will return: +# admin +# + +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 + +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 \ + -Dcom.att.eelf.logging.file=default-logback.xml -Dcom.att.eelf.logging.path="$PROJECT_HOME/bundleconfig/etc/appprops/" \ + org.openecomp.aai.util.AAIConfigCommandLinePropGetter $1 + +echo `date` " Done $0" diff --git a/aai-resources/src/main/scripts/edgeTagger.sh b/aai-resources/src/main/scripts/edgeTagger.sh new file mode 100644 index 0000000..5a120a2 --- /dev/null +++ b/aai-resources/src/main/scripts/edgeTagger.sh @@ -0,0 +1,96 @@ +#!/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 synch-up the data in the database with the "edge-tags" definitions found in the DbEdgeRules.java file. +# It is not needed during normal operation, but if a new tag (really a property) is defined for an edge or if an +# existing tag is changed, then this script should be run to migrate existing data so that it matches the new +# definition. Note: it is only dealing with the "tags" defined after position 2. For example, for our existing +# rules, we have have "isParent" defined in position 2, and then other tags in positions 3, 4 and 5 as +# mapped in DbEdgeRules.EdgeInfoMap: +# +# public static final Map EdgeInfoMap; +# static { +# EdgeInfoMap = new HashMap(); +# EdgeInfoMap.put(0, "edgeLabel"); +# EdgeInfoMap.put(1, "direction"); +# EdgeInfoMap.put(2, "isParent" ); +# EdgeInfoMap.put(3, "usesResource" ); +# EdgeInfoMap.put(4, "hasDelTarget" ); +# EdgeInfoMap.put(5, "SVC-INFRA" ); +# } +# +# -- The map above is used to interpret the data in the DbEdgeRules.EdgeRules map: +# +# public static final Multimap EdgeRules = +# new ImmutableSetMultimap.Builder() +# .putAll("availability-zone|complex","groupsResourcesIn,OUT,false,false,false,reverse") +# .putAll("availability-zone|service-capability","supportsServiceCapability,OUT,false,false,false,false") +# .putAll("complex|ctag-pool","hasCtagPool,OUT,true,false,false,false") +# .putAll("complex|l3-network","usesL3Network,OUT,false,false,false,true") +# etc... +# +# -- Valid values for the "tags" can be "true", "false" or "reverse". Read the T-space +# write-up for a detailed explanation of this... +# +# +# To use this script, You can either pass the parameter, "all" to update all the edge rules, or +# you can pass the KEY to a single edge rule that you would like to update. NOTE - the +# key is that first part of each edge rule that looks like, "nodeTypeA|nodeTypeB". +# +# Ie. ./edgeTagger.sh "all" +# or ./edgeTagger.sh "complex|ctag-pool" +# + +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 + +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 \ + -Dcom.att.eelf.logging.file=default-logback.xml -Dcom.att.eelf.logging.path="$PROJECT_HOME/bundleconfig/etc/appprops/" \ + org.openecomp.aai.dbgen.UpdateEdgeTags $1 +if [ "$?" -ne "0" ]; then + echo "Problem executing UpdateEdgeTags " + exit 1 +fi + + +echo `date` " Done $0" +exit 0 diff --git a/aai-resources/src/main/scripts/forceDeleteTool.sh b/aai-resources/src/main/scripts/forceDeleteTool.sh new file mode 100644 index 0000000..a9dd11b --- /dev/null +++ b/aai-resources/src/main/scripts/forceDeleteTool.sh @@ -0,0 +1,100 @@ +#!/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========================================================= +### + +# +# forceDeleteTool.sh -- This tool is used to delete nodes that cannot be deleted using +# the normal REST API because of internal DB problems. For example, Phantom nodes +# and duplicate nodes cause errors to happen in "normal" REST API codes and must +# be deleted using this tool. +# Since it is not using the "normal" REST logic, it is also not invoking the "normal" +# edge rules that we use to cascade deletes to "child" nodes. So - this tool can be dangerous. +# Ie. if you accidently delete a parent node (like a cloud-region) that has many dependent +# child nodes, there will be no way to get to any of those child-nodes after the cloud-region +# has been deleted. +# There are several environment variables defined in aaiconfig.properties to help minimize errors like that. +# aai.forceDel.protected.nt.list=cloud-region +# aai.forceDel.protected.edge.count=10 +# aai.forceDel.protected.descendant.count=10 +# +# Parameters: +# +# -action (required) valid values: COLLECT_DATA or DELETE_NODE or DELETE_EDGE +# -userId (required) must be followed by a userid +# -params4Collect (followed by a string to tell what properties/values to use +# as part of a COLLECT_DATA request. Must be in the format +# of “propertName|propValue” use commas to separate if there +# are more than one name/value being passed. +# -vertexId - required for a DELETE_NODE request +# -edgeId - required for a DELETE_EDGE request +# -overRideProtection --- WARNING – This over-rides the protections we introduced! +# It will let you override a protected vertex or vertex that has more +# than the allowed number of edges or descendants. +# -DISPLAY_ALL_VIDS (optional) - in the rare case when you want to see the +# vertex-ids (vids) of all the CONNECTED vertices, you can use this. By +# default, we do not show them. +# +# +# For example: +# +# forceDeleteTool.sh -action COLLECT_DATA -userId am8383 -params4Collect "tenant-id|junk tenant01 ID 0224" +# +# forceDeleteTool.sh -action COLLECT_DATA -userId am8383 -params4Collect "cloud-owner|junkTesterCloudOwner 0224,cloud-region-id|junkTesterCloud REgion ID 0224" +# +# forceDeleteTool.sh -action DELETE_NODE -userId am8383 -vertexId 1234567 +# +# forceDeleteTool.sh -action DELETE_EDGE -userId am8383 -edgeId 9876543 +# +# + + +echo +echo `date` " Starting $0" + +echo " NOTE - if you are deleting data, please run the dataSnapshot.sh script first or " +echo " at least make a note the details of the node that you are deleting. " + +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 + +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.ForceDeleteTool "$@" + + +echo `date` " Done $0" + +exit 0 diff --git a/aai-resources/src/main/scripts/getTool.sh b/aai-resources/src/main/scripts/getTool.sh new file mode 100644 index 0000000..2da20eb --- /dev/null +++ b/aai-resources/src/main/scripts/getTool.sh @@ -0,0 +1,56 @@ +#!/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" + +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 + +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.GetResource "$@" +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/notifyTool.sh b/aai-resources/src/main/scripts/notifyTool.sh new file mode 100644 index 0000000..2ecf1f4 --- /dev/null +++ b/aai-resources/src/main/scripts/notifyTool.sh @@ -0,0 +1,56 @@ +#!/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 PutActionsNotify java class to PUT a actions/notify request for a given JSON payload. +# + +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 + +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.PutActionsNotify "$@" +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/postTool.sh b/aai-resources/src/main/scripts/postTool.sh new file mode 100644 index 0000000..a773915 --- /dev/null +++ b/aai-resources/src/main/scripts/postTool.sh @@ -0,0 +1,56 @@ +#!/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 PostResource java class to POST on a resource +# + +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 + +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.PostResource "$@" +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/putTool.sh b/aai-resources/src/main/scripts/putTool.sh new file mode 100644 index 0000000..9d3f1dd --- /dev/null +++ b/aai-resources/src/main/scripts/putTool.sh @@ -0,0 +1,56 @@ +#!/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 PutResource java class to PUT on a resource +# + +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 + +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.PutResource "$@" +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/rshipTool.sh b/aai-resources/src/main/scripts/rshipTool.sh new file mode 100644 index 0000000..316d0f5 --- /dev/null +++ b/aai-resources/src/main/scripts/rshipTool.sh @@ -0,0 +1,70 @@ +#!/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 RelationshipputDel java class to PUT/DELETE a relationship +# +# sample json file for an oam-network node to put a relationship to a complex +#{ +# "related-to": "complex", +# "relationship-data": [ { +# "relationship-key": "complex.physical-location-id", +# "relationship-value": "CHCGILCL73W" +# }] +#} +# + +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 + +for JAR in `ls $PROJECT_HOME/extJars/*.jar` +do + CLASSPATH=$CLASSPATH:$JAR +done + +for JAR in `ls $PROJECT_HOME/jetty/webapps/*/webapp/WEB-INF/lib/*.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.RelationshipPutDel "$@" +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 new file mode 100644 index 0000000..f4fd4d5 --- /dev/null +++ b/aai-resources/src/main/scripts/schemaMod.sh @@ -0,0 +1,89 @@ +#!/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 correct mistakes made in the database schema. +# It currently just allows you to change either the dataType and/or indexType on properties used by nodes. +# +# NOTE - Titan is not elegant in 0.5.3 about making changes to the schema. Bad properties never +# actually leave the database, they just get renamed and stop getting used. So it is +# really worthwhile to get indexes and dataTypes correct the first time around. +# 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 June 2015) 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 June 2015) 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 either the index or dataType on +# targetDataType -- whether it's changing or not, you need to give it: String, Integer, Boolean or Long +# targetIndexInfo -- whether it's changing or not, you need to give it: index, noIndex or uniqueIndex +# preserveDataFlag -- true or false. The only reason I can think of why you'd ever want to +# set this to false would be maybe if you were changing to an incompatible dataType so didn't +# want it to try to use the old data (and fail). But 99% of the time this will just be 'true'. +# +# Ie. schemaMod flavor-id String index 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 targetDataType targetIndexInfo preserveDataFlag" + exit 1 +fi + +. /etc/profile.d/aai.sh + +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.SchemaMod $1 $2 $3 $4 +if [ "$?" -ne "0" ]; then + echo "Problem executing schemaMod " + exit 1 +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 new file mode 100644 index 0000000..25670f6 --- /dev/null +++ b/aai-resources/src/main/scripts/updateTool.sh @@ -0,0 +1,56 @@ +#!/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" + +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 + +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.UpdateResource "$@" +ret_code=$? +if [ $ret_code != 0 ]; then + echo `date` " Done $0" + exit $ret_code +fi + +echo `date` " Done $0" +exit 0 -- cgit 1.2.3-korg