summaryrefslogtreecommitdiffstats
path: root/aai-core/src
diff options
context:
space:
mode:
authorWilliam Reehil <william.reehil@att.com>2022-11-11 13:37:57 +0000
committerGerrit Code Review <gerrit@onap.org>2022-11-11 13:37:57 +0000
commit3b096f45f2e99a3ca0fa4e87476d8c4d232be26c (patch)
tree2a48b420e1efbeefbf5c4bd5c8ad7cf7960bf5ef /aai-core/src
parent72b44a38290334c46a9dedc0be1dadcd08520515 (diff)
parent11f38de0c6e9a7d04ececaf7d291648f4406ef21 (diff)
Merge "Partially resolve resource leak warnings in aai-common"
Diffstat (limited to 'aai-core/src')
-rw-r--r--aai-core/src/main/java/org/onap/aai/audit/ListEndpoints.java27
-rw-r--r--aai-core/src/main/java/org/onap/aai/ingestModel/CreateWidgetModels.java127
-rw-r--r--aai-core/src/test/java/org/onap/aai/stress/IndexStressTest.java3
3 files changed, 80 insertions, 77 deletions
diff --git a/aai-core/src/main/java/org/onap/aai/audit/ListEndpoints.java b/aai-core/src/main/java/org/onap/aai/audit/ListEndpoints.java
index ae493ef1..2312c943 100644
--- a/aai-core/src/main/java/org/onap/aai/audit/ListEndpoints.java
+++ b/aai-core/src/main/java/org/onap/aai/audit/ListEndpoints.java
@@ -46,6 +46,7 @@ import org.onap.aai.setup.SchemaVersion;
import org.onap.aai.setup.SchemaVersions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.beans.BeansException;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
/**
@@ -68,21 +69,23 @@ public class ListEndpoints {
*/
public static void main(String[] args) {
- AnnotationConfigApplicationContext context =
- new AnnotationConfigApplicationContext("org.onap.aai.config", "org.onap.aai.setup");
+ try (AnnotationConfigApplicationContext context =
+ new AnnotationConfigApplicationContext("org.onap.aai.config", "org.onap.aai.setup")) {
+ String schemaUriBasePath = context.getEnvironment().getProperty("schema.uri.base.path");
- String schemaUriBasePath = context.getEnvironment().getProperty("schema.uri.base.path");
-
- if (schemaUriBasePath == null) {
- String errorMsg = "Unable to find the property schema.uri.base.path,"
- + " please check if specified in system property or in schema-ingest.properties";
- LOGGER.error(errorMsg);
- }
+ if (schemaUriBasePath == null) {
+ String errorMsg = "Unable to find the property schema.uri.base.path,"
+ + " please check if specified in system property or in schema-ingest.properties";
+ LOGGER.error(errorMsg);
+ }
- SchemaVersions schemaVersions = context.getBean(SchemaVersions.class);
- ListEndpoints endPoints = new ListEndpoints(schemaUriBasePath, schemaVersions.getDefaultVersion());
+ SchemaVersions schemaVersions = context.getBean(SchemaVersions.class);
+ ListEndpoints endPoints = new ListEndpoints(schemaUriBasePath, schemaVersions.getDefaultVersion());
- LOGGER.info(endPoints.toString("relationship-list"));
+ LOGGER.info(endPoints.toString("relationship-list"));
+ } catch (BeansException e) {
+ LOGGER.warn("Unable to initialize AnnotationConfigApplicationContext ", LogFormatTools.getStackTop(e));
+ }
}
/**
diff --git a/aai-core/src/main/java/org/onap/aai/ingestModel/CreateWidgetModels.java b/aai-core/src/main/java/org/onap/aai/ingestModel/CreateWidgetModels.java
index 1d66a8a5..14057e01 100644
--- a/aai-core/src/main/java/org/onap/aai/ingestModel/CreateWidgetModels.java
+++ b/aai-core/src/main/java/org/onap/aai/ingestModel/CreateWidgetModels.java
@@ -75,82 +75,83 @@ public class CreateWidgetModels {
System.exit(0);
}
- AnnotationConfigApplicationContext ctx =
- new AnnotationConfigApplicationContext("org.onap.aai.config", "org.onap.aai.setup");
+ try (AnnotationConfigApplicationContext ctx =
+ new AnnotationConfigApplicationContext("org.onap.aai.config", "org.onap.aai.setup")) {
+ LoaderFactory loaderFactory = ctx.getBean(LoaderFactory.class);
+ Loader loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, new SchemaVersion(_apiVersion));
- LoaderFactory loaderFactory = ctx.getBean(LoaderFactory.class);
- Loader loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, new SchemaVersion(_apiVersion));
+ // iterate the collection of resources
- // iterate the collection of resources
+ ArrayList<String> processedWidgets = new ArrayList<String>();
+ for (Entry<String, Introspector> aaiResEnt : loader.getAllObjects().entrySet()) {
+ Introspector meObject = loader.introspectorFromName("model");
+ // no need for a ModelVers DynamicEntity
- ArrayList<String> processedWidgets = new ArrayList<String>();
- for (Entry<String, Introspector> aaiResEnt : loader.getAllObjects().entrySet()) {
- Introspector meObject = loader.introspectorFromName("model");
- // no need for a ModelVers DynamicEntity
+ Introspector aaiRes = aaiResEnt.getValue();
- Introspector aaiRes = aaiResEnt.getValue();
+ if (!(aaiRes.isContainer() || aaiRes.getName().equals("aai-internal"))) {
+ String resource = aaiRes.getName();
- if (!(aaiRes.isContainer() || aaiRes.getName().equals("aai-internal"))) {
- String resource = aaiRes.getName();
-
- if (processedWidgets.contains(resource)) {
- continue;
- }
-
- Set<String> introspectorProperties = aaiRes.getProperties();
-
- if (!(introspectorProperties.contains("model-version-id")
- && introspectorProperties.contains("model-invariant-id"))) {
- System.out.println(aaiRes.getDbName() + " does not contain model properties so skipping");
- }
- processedWidgets.add(resource);
-
- String widgetName = resource;
- String filePathString = widgetJsonDir + "/" + widgetName + "-" + modelVersion + ".json";
- File f = new File(filePathString);
-
- String filePathString2 =
- widgetJsonDir + "/../widget-model-json-old/" + widgetName + "-" + modelVersion + ".json";
- File f2 = new File(filePathString2);
+ if (processedWidgets.contains(resource)) {
+ continue;
+ }
- if (!f.exists() && !f.isDirectory()) {
+ Set<String> introspectorProperties = aaiRes.getProperties();
- if (f2.exists()) {
- System.out.println("Using old file for " + resource + ".");
+ if (!(introspectorProperties.contains("model-version-id")
+ && introspectorProperties.contains("model-invariant-id"))) {
+ System.out.println(aaiRes.getDbName() + " does not contain model properties so skipping");
+ }
+ processedWidgets.add(resource);
+
+ String widgetName = resource;
+ String filePathString = widgetJsonDir + "/" + widgetName + "-" + modelVersion + ".json";
+ File f = new File(filePathString);
+
+ String filePathString2 =
+ widgetJsonDir + "/../widget-model-json-old/" + widgetName + "-" + modelVersion + ".json";
+ File f2 = new File(filePathString2);
+
+ if (!f.exists() && !f.isDirectory()) {
+
+ if (f2.exists()) {
+ System.out.println("Using old file for " + resource + ".");
+
+ meObject = loader.unmarshal("model", new StreamSource(f2).getReader().toString());
+ // override, some of them are wrong
+ meObject.setValue("model-version", modelVersion);
+ } else {
+ System.out.println("Making new file for " + resource + ".");
+ meObject.setValue("model-invariant-id", UUID.randomUUID().toString());
+ meObject.setValue("model-type", "widget");
+ Introspector mevObject = loader.introspectorFromName("model-ver");
+ Introspector mevsObject = loader.introspectorFromName("model-vers");
+ mevObject.setValue("model-version-id", UUID.randomUUID().toString());
+ mevObject.setValue("model-version", modelVersion);
+ mevObject.setValue("model-Name", widgetName);
+ // make a list of dynamic Entities
+ List<Object> mevsList = new ArrayList<>();
+ // add this one, it will be the only one in the list in this case
+ mevsList.add(mevObject.getUnderlyingObject());
+ mevsObject.setValue("model-ver", mevsList);
+ // Have to figure out how to add my mev object to the mevsObject,
+ // the modelVers is a list of dynamic entities so we can just attach the array here
+ meObject.setValue("model-vers", mevsObject.getUnderlyingObject());
+ }
+
+ // put it out as JSON
+
+ PrintWriter out = new PrintWriter(f);
+ out.println(meObject.marshal(true));
+ out.close();
- meObject = loader.unmarshal("model", new StreamSource(f2).getReader().toString());
- // override, some of them are wrong
- meObject.setValue("model-version", modelVersion);
} else {
- System.out.println("Making new file for " + resource + ".");
- meObject.setValue("model-invariant-id", UUID.randomUUID().toString());
- meObject.setValue("model-type", "widget");
- Introspector mevObject = loader.introspectorFromName("model-ver");
- Introspector mevsObject = loader.introspectorFromName("model-vers");
- mevObject.setValue("model-version-id", UUID.randomUUID().toString());
- mevObject.setValue("model-version", modelVersion);
- mevObject.setValue("model-Name", widgetName);
- // make a list of dynamic Entities
- List<Object> mevsList = new ArrayList<>();
- // add this one, it will be the only one in the list in this case
- mevsList.add(mevObject.getUnderlyingObject());
- mevsObject.setValue("model-ver", mevsList);
- // Have to figure out how to add my mev object to the mevsObject,
- // the modelVers is a list of dynamic entities so we can just attach the array here
- meObject.setValue("model-vers", mevsObject.getUnderlyingObject());
+ System.out.println("File already exists for " + resource + ". Skipping.");
}
-
- // put it out as JSON
-
- PrintWriter out = new PrintWriter(f);
- out.println(meObject.marshal(true));
- out.close();
-
- } else {
- System.out.println("File already exists for " + resource + ". Skipping.");
}
}
}
+
System.exit(0);
}
}
diff --git a/aai-core/src/test/java/org/onap/aai/stress/IndexStressTest.java b/aai-core/src/test/java/org/onap/aai/stress/IndexStressTest.java
index fb7ba400..78f5f089 100644
--- a/aai-core/src/test/java/org/onap/aai/stress/IndexStressTest.java
+++ b/aai-core/src/test/java/org/onap/aai/stress/IndexStressTest.java
@@ -69,8 +69,7 @@ public class IndexStressTest extends AAISetup {
if (i % 1000 == 0) {
LOGGER.debug("Committing up to index {}", i);
tx.commit();
- tx = AAIGraph.getInstance().getGraph().newTransaction();
- g = tx.traversal();
+ g = AAIGraph.getInstance().getGraph().newTransaction().traversal();
}
}