summaryrefslogtreecommitdiffstats
path: root/aai-traversal/src/main/java/org/onap/aai/util
diff options
context:
space:
mode:
Diffstat (limited to 'aai-traversal/src/main/java/org/onap/aai/util')
-rw-r--r--aai-traversal/src/main/java/org/onap/aai/util/AAIAppServletContextListener.java111
-rw-r--r--aai-traversal/src/main/java/org/onap/aai/util/MakeNamedQuery.java177
-rw-r--r--aai-traversal/src/main/java/org/onap/aai/util/TraversalConstants.java39
3 files changed, 124 insertions, 203 deletions
diff --git a/aai-traversal/src/main/java/org/onap/aai/util/AAIAppServletContextListener.java b/aai-traversal/src/main/java/org/onap/aai/util/AAIAppServletContextListener.java
deleted file mode 100644
index d743adb..0000000
--- a/aai-traversal/src/main/java/org/onap/aai/util/AAIAppServletContextListener.java
+++ /dev/null
@@ -1,111 +0,0 @@
-/**
- * ============LICENSE_START=======================================================
- * org.onap.aai
- * ================================================================================
- * Copyright © 2017-2018 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.onap.aai.util;
-
-import java.io.IOException;
-import java.util.UUID;
-import javax.servlet.ServletContextEvent;
-import javax.servlet.ServletContextListener;
-
-import org.onap.aai.dbmap.AAIGraph;
-import org.onap.aai.exceptions.AAIException;
-import org.onap.aai.introspection.ModelInjestor;
-import org.onap.aai.logging.ErrorLogHelper;
-import org.onap.aai.logging.LogFormatTools;
-import org.onap.aai.logging.LoggingContext;
-import org.onap.aai.logging.LoggingContext.StatusCode;
-
-import com.att.eelf.configuration.EELFLogger;
-import com.att.eelf.configuration.EELFManager;
-
-public class AAIAppServletContextListener implements ServletContextListener {
-
- private static final String MICRO_SVC="aai-traversal";
- private static final String ACTIVEMQ_TCP_URL = "tcp://localhost:61446";
- private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(AAIAppServletContextListener.class.getName());
-
- /**
- * Destroys Context
- *
- * @param arg0 the ServletContextEvent
- */
- public void contextDestroyed(ServletContextEvent arg0) {
- }
-
- /**
- * Initializes Context
- *
- * @param arg0 the ServletContextEvent
- */
- public void contextInitialized(ServletContextEvent arg0) {
- System.setProperty("org.onap.aai.serverStarted", "false");
- System.setProperty("aai.service.name", "traversal");
-
- LoggingContext.save();
- LoggingContext.component("init");
- LoggingContext.partnerName("NA");
- LoggingContext.targetEntity(MICRO_SVC);
- LoggingContext.requestId(UUID.randomUUID().toString());
- LoggingContext.serviceName(MICRO_SVC);
- LoggingContext.targetServiceName("contextInitialized");
- LoggingContext.statusCode(StatusCode.COMPLETE);
- LOGGER.info("AAI Server initialization started...");
- try {
- LOGGER.info("Loading aaiconfig.properties");
- AAIConfig.init();
-
- LOGGER.info("Loading error.properties");
- ErrorLogHelper.loadProperties();
-
- LOGGER.info("Loading graph database");
-
- AAIGraph.getInstance();
- ModelInjestor.getInstance();
-
- LOGGER.info("A&AI Server initialization succcessful.");
- System.setProperty("activemq.tcp.url", ACTIVEMQ_TCP_URL);
- System.setProperty("org.onap.aai.serverStarted", "true");
-
- Runtime.getRuntime().addShutdownHook(new Thread() {
- public void run() {
- LOGGER.info("AAIGraph shutting down");
- AAIGraph.getInstance().graphShutdown();
- LOGGER.info("AAIGraph shutdown");
- System.out.println("Shutdown hook triggered.");
- }
- });
-
- } catch (AAIException e) {
- ErrorLogHelper.logException(e);
- throw new RuntimeException("AAIException caught while initializing A&AI server", e);
- } catch (IOException e) {
- ErrorLogHelper.logError("AAI_4000", e.getMessage());
- throw new RuntimeException("IOException caught while initializing A&AI server", e);
- } catch (Exception e) {
- LOGGER.error("Unknown failure while initializing A&AI Server" + LogFormatTools.getStackTop(e));
- throw new RuntimeException("Unknown failure while initializing A&AI server", e);
- }
-
- LOGGER.info("Graph-Query MicroService Started");
- LOGGER.debug("Graph-Query MicroService Started");
- LoggingContext.restore();
-
- }
-}
diff --git a/aai-traversal/src/main/java/org/onap/aai/util/MakeNamedQuery.java b/aai-traversal/src/main/java/org/onap/aai/util/MakeNamedQuery.java
index 68d204f..a805e19 100644
--- a/aai-traversal/src/main/java/org/onap/aai/util/MakeNamedQuery.java
+++ b/aai-traversal/src/main/java/org/onap/aai/util/MakeNamedQuery.java
@@ -24,17 +24,18 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map.Entry;
-import java.util.Optional;
import java.util.UUID;
import org.apache.commons.io.FileUtils;
-
+import org.onap.aai.config.SpringContextAware;
import org.onap.aai.introspection.Introspector;
import org.onap.aai.introspection.Loader;
import org.onap.aai.introspection.LoaderFactory;
import org.onap.aai.introspection.ModelType;
-import org.onap.aai.introspection.Version;
import org.onap.aai.introspection.exceptions.AAIUnknownObjectException;
+import org.onap.aai.setup.SchemaVersion;
+import org.onap.aai.setup.SchemaVersions;
+import org.springframework.context.annotation.AnnotationConfigApplicationContext;
public class MakeNamedQuery {
@@ -67,104 +68,98 @@ public class MakeNamedQuery {
System.exit(0);
}
+ AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(
+ "org.onap.aai.config",
+ "org.onap.aai.setup"
+ );
- Loader loader = LoaderFactory.createLoaderForVersion(ModelType.MOXY, Version.valueOf(_apiVersion));
+ LoaderFactory loaderFactory = ctx.getBean(LoaderFactory.class);
+ SchemaVersions schemaVersions = ctx.getBean(SchemaVersions.class);
- // iterate the collection of resources
+ if(schemaVersions.getVersions().contains(_apiVersion)){
- ArrayList<String> processedWidgets = new ArrayList<>();
+ Loader loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, new SchemaVersion(_apiVersion));
+ // iterate the collection of resources
- HashMap<String, List<Introspector>> widgetToRelationship = new HashMap<String, List<Introspector>>();
- for (Entry<String, Introspector> aaiResEnt : loader.getAllObjects().entrySet()) {
- Introspector meObject = loader.introspectorFromName("model");
- // no need for a ModelVers DynamicEntity
+ ArrayList<String> processedWidgets = new ArrayList<>();
- Introspector aaiRes = aaiResEnt.getValue();
- if (!(aaiRes.isContainer() || aaiRes.getName().equals("aai-internal"))) {
- String resource = aaiRes.getName();
+ HashMap<String, List<Introspector>> widgetToRelationship = new HashMap<>();
+ for (Entry<String, Introspector> aaiResEnt : loader.getAllObjects().entrySet()) {
+ Introspector meObject = loader.introspectorFromName("model");
+ // no need for a ModelVers DynamicEntity
- if (processedWidgets.contains(resource)) {
- continue;
- }
- processedWidgets.add(resource);
-
- String widgetName = resource;
- String filePathString = widgetJsonDir + "/" + widgetName + "-" + modelVersion + ".json";
- File f = new File(filePathString);
- if (f.exists()) {
- System.out.println(f.toString());
- String json = FileUtils.readFileToString(f);
-
- meObject = loader.unmarshal("Model", json);
- String modelInvariantId = meObject.getValue("model-invariant-id");
- if (meObject.hasProperty("model-vers")) {
- Introspector modelVers = meObject.getWrappedValue("model-vers");
- List<Introspector> modelVerList = modelVers.getWrappedListValue("model-ver");
- for (Introspector modelVer : modelVerList) {
-
- List<Introspector> relList = new ArrayList<Introspector>();
- Introspector widgetRelationship = makeWidgetRelationship(loader, modelInvariantId,
- modelVer.getValue("model-version-id").toString());
- relList.add(widgetRelationship);
-
- widgetToRelationship.put(widgetName, relList);
+ Introspector aaiRes = aaiResEnt.getValue();
+
+ if (!(aaiRes.isContainer() || aaiRes.getName().equals("aai-internal"))) {
+ String resource = aaiRes.getName();
+
+ if (processedWidgets.contains(resource)) {
+ continue;
+ }
+ processedWidgets.add(resource);
+
+ String widgetName = resource;
+ String filePathString = widgetJsonDir + "/" + widgetName + "-" + modelVersion + ".json";
+ File f = new File(filePathString);
+ if (f.exists()) {
+ System.out.println(f.toString());
+ String json = FileUtils.readFileToString(f);
+
+ meObject = loader.unmarshal("Model", json);
+ String modelInvariantId = meObject.getValue("model-invariant-id");
+ if (meObject.hasProperty("model-vers")) {
+ Introspector modelVers = meObject.getWrappedValue("model-vers");
+ List<Introspector> modelVerList = (List<Introspector>) modelVers.getWrappedListValue("model-ver");
+ for (Introspector modelVer : modelVerList) {
+
+ List<Introspector> relList = new ArrayList<Introspector>();
+ Introspector widgetRelationship = makeWidgetRelationship(loader, modelInvariantId,
+ modelVer.getValue("model-version-id").toString());
+ relList.add(widgetRelationship);
+
+ widgetToRelationship.put(widgetName, relList);
+ }
}
}
}
}
- }
-
-// esr-system-info-from-vnf=builder.store('x').union(\
-// builder.newInstance().createEdgeTraversal(EdgeType.COUSIN, 'generic-vnf', 'vserver').store('x').union(\
-// builder.newInstance().createEdgeTraversal(EdgeType.TREE, 'vserver', 'tenant').store('x')\
-// .createEdgeTraversal(EdgeType.TREE, 'tenant', 'cloud-region').store('x')\
-// .createEdgeTraversal(EdgeType.TREE, 'cloud-region', 'esr-system-info').store('x')\
-// )).cap('x').unfold.dedup()
-
- //source vnf-id, related service-instance-id, all related vnfs in this service-instance-id
-
- //this should be abstracted and moved to a file
-
- HashMap<String, List<Introspector>> relationshipMap = new HashMap<String, List<Introspector>>();
-
- List<Introspector> genericVnfRelationship = widgetToRelationship.get("generic-vnf");
- List<Introspector> vserverRelationship = widgetToRelationship.get("vserver");
- List<Introspector> tenantRelationship = widgetToRelationship.get("tenant");
- List<Introspector> cloudRegionRelationship = widgetToRelationship.get("cloud-region");
- List<Introspector> esrSystemInfoRelationship = widgetToRelationship.get("esr-system-info");
-
- Introspector namedQueryObj = loader.introspectorFromName("named-query");
- namedQueryObj.setValue("named-query-uuid", namedQueryUuid);
- namedQueryObj.setValue("named-query-name", "vnf-to-esr-system-info");
- namedQueryObj.setValue("named-query-version", "1.0");
- namedQueryObj.setValue("description", "Named Query - VNF to ESR System Info");
-
- Optional<Introspector> genericVnfNQE = tryToSetUpNQElements(Optional.of(namedQueryObj), genericVnfRelationship);
-
- Optional<Introspector> vserverNQE = tryToSetUpNQElements(genericVnfNQE, vserverRelationship);
-
- Optional<Introspector> tenantNQE = tryToSetUpNQElements(vserverNQE, tenantRelationship);
-
- Optional<Introspector> cloudRegionNQE = tryToSetUpNQElements(tenantNQE, cloudRegionRelationship);
- Optional<Introspector> esrSystemInfoNQE = tryToSetUpNQElements(cloudRegionNQE, esrSystemInfoRelationship);
-
- System.out.println(namedQueryObj.marshal(true));
-
- System.exit(0);
+ //source vnf-id, related service-instance-id, all related vnfs in this service-instance-id
+ //this should be abstracted and moved to a file
- }
+ HashMap<String, List<Introspector>> relationshipMap = new HashMap<String, List<Introspector>>();
+
+ List<Introspector> genericVnfRelationship = widgetToRelationship.get("generic-vnf");
+ List<Introspector> vserverRelationship = widgetToRelationship.get("vserver");
+ List<Introspector> tenantRelationship = widgetToRelationship.get("tenant");
+ List<Introspector> cloudRegionRelationship = widgetToRelationship.get("cloud-region");
+ List<Introspector> esrSystemInfoRelationship = widgetToRelationship.get("esr-system-info");
+
+ Introspector namedQueryObj = loader.introspectorFromName("named-query");
+ namedQueryObj.setValue("named-query-uuid", namedQueryUuid);
+ namedQueryObj.setValue("named-query-name", "vnf-to-esr-system-info");
+ namedQueryObj.setValue("named-query-version", "1.0");
+ namedQueryObj.setValue("description", "Named Query - VNF to ESR System Info");
+
+ Introspector genericVnfNQE = setupNQElements(namedQueryObj, genericVnfRelationship);
+
+ Introspector vserverNQE = setupNQElements(genericVnfNQE, vserverRelationship);
+
+ Introspector tenantNQE = setupNQElements(vserverNQE, tenantRelationship);
+
+ Introspector cloudRegionNQE = setupNQElements(tenantNQE, cloudRegionRelationship);
+
+ Introspector esrSystemInfoNQE = setupNQElements(cloudRegionNQE, esrSystemInfoRelationship);
+
+ System.out.println(namedQueryObj.marshal(true));
- private static Optional<Introspector> tryToSetUpNQElements(Optional<Introspector> genericVnfNQE, List<Introspector> vserverRelationship) {
- if(genericVnfNQE.isPresent()) {
- return Optional.ofNullable(setupNQElements(genericVnfNQE.get(), vserverRelationship));
- } else {
- return Optional.empty();
}
- }
+ System.exit(0);
+
+ }
private static List<Introspector> getRels(String widgetName, HashMap<String, Introspector> widgetToRelationship) {
List<Introspector> relList = new ArrayList<Introspector>();
Introspector genericVnfRelationship = widgetToRelationship.get(widgetName);
@@ -180,16 +175,14 @@ public class MakeNamedQuery {
if (nqeObj.getWrappedValue("named-query-elements") != null) {
newNQElements = nqeObj.getWrappedValue("named-query-elements");
nqElementList = newNQElements.getValue("named-query-element");
- } else {
+ } else {
newNQElements = nqeObj.newIntrospectorInstanceOfProperty("named-query-elements");
nqeObj.setValue("named-query-elements", newNQElements.getUnderlyingObject());
- nqElementList = newNQElements.getValue("named-query-element");
+ nqElementList = (List<Object>)newNQElements.getValue("named-query-element");
}
newNQElement = loadNQElement(newNQElements, listOfRelationships);
- if (newNQElement != null) {
- nqElementList.add(newNQElement.getUnderlyingObject());
- }
-
+ nqElementList.add(newNQElement.getUnderlyingObject());
+
} catch (AAIUnknownObjectException e) {
// TODO Auto-generated catch block
e.printStackTrace();
@@ -210,7 +203,7 @@ public class MakeNamedQuery {
Introspector newRelationshipList = newNqElement.getLoader().introspectorFromName("relationship-list");
newNqElement.setValue("relationship-list", newRelationshipList.getUnderlyingObject());
- List<Object> newRelationshipListList = newRelationshipList.getValue("relationship");
+ List<Object> newRelationshipListList = (List<Object>)newRelationshipList.getValue("relationship");
for (Introspector rel : listOfRelationships) {
newRelationshipListList.add(rel.getUnderlyingObject());
@@ -232,7 +225,7 @@ public class MakeNamedQuery {
try {
newRelationship = loader.introspectorFromName("relationship");
- List<Object> newRelationshipData = newRelationship.getValue("relationship-data");
+ List<Object> newRelationshipData = (List<Object>)newRelationship.getValue("relationship-data");
newRelationship.setValue("related-to", "model");
diff --git a/aai-traversal/src/main/java/org/onap/aai/util/TraversalConstants.java b/aai-traversal/src/main/java/org/onap/aai/util/TraversalConstants.java
new file mode 100644
index 0000000..69e1e9f
--- /dev/null
+++ b/aai-traversal/src/main/java/org/onap/aai/util/TraversalConstants.java
@@ -0,0 +1,39 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017-2018 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.onap.aai.util;
+
+public final class TraversalConstants {
+ public static final int AAI_QUERY_PORT = 8446;
+
+ public static final String AAI_TRAVERSAL_TIMEOUT_LIMIT = "aai.traversal.timeoutlimit";
+ public static final String AAI_TRAVERSAL_TIMEOUT_ENABLED = "aai.traversal.timeoutenabled";
+ public static final String AAI_TRAVERSAL_TIMEOUT_APP = "aai.traversal.timeout.appspecific";
+
+ public static final String AAI_TRAVERSAL_DSL_TIMEOUT_LIMIT = "aai.traversal.dsl.timeoutlimit";
+ public static final String AAI_TRAVERSAL_DSL_TIMEOUT_ENABLED = "aai.traversal.dsl.timeoutenabled";
+ public static final String AAI_TRAVERSAL_DSL_TIMEOUT_APP = "aai.traversal.dsl.timeout.appspecific";
+
+ public static final long HISTORY_MAX_HOURS = 192;
+
+ private TraversalConstants() {
+ // prevent instantiation
+ }
+
+}