From 5032434b101f25fa44d2e1f8dc8393e30af1ed4f Mon Sep 17 00:00:00 2001 From: "Stone, Avi (as206k)" Date: Thu, 12 Apr 2018 15:46:31 +0300 Subject: DCAE-D be initial commit DCAE-D be initial commit Issue-ID: SDC-1218 Change-Id: Id18ba96c499e785aa9ac395fbaf32d57f08c281b Signed-off-by: Stone, Avi (as206k) --- dcaedt_catalog/.gitignore | 12 + dcaedt_catalog/api/pom.xml | 198 ++ .../java/org/onap/sdc/dcae/catalog/Catalog.java | 440 +++++ .../onap/sdc/dcae/catalog/asdc/ASDCCatalog.java | 1227 ++++++++++++ .../api/src/main/resources/log4j.properties | 8 + .../org/onap/sdc/dcae/catalog/ASDCCatalogTest.java | 88 + dcaedt_catalog/asdc/pom.xml | 139 ++ .../java/org/onap/sdc/dcae/catalog/asdc/ASDC.java | 1101 +++++++++++ .../onap/sdc/dcae/catalog/asdc/ASDCController.java | 0 .../org/onap/sdc/dcae/catalog/asdc/ASDCEngine.java | 25 + .../onap/sdc/dcae/catalog/asdc/ASDCException.java | 18 + .../org/onap/sdc/dcae/catalog/asdc/ASDCUtils.java | 448 +++++ .../sdc/dcae/catalog/asdc/ASDCUtilsController.java | 76 + .../onap/sdc/dcae/catalog/asdc/Blueprinter.java | 76 + .../org/onap/sdc/dcae/catalog/asdc/Cloudify.java | 249 +++ .../java/org/onap/sdc/dcae/client/ISdcClient.java | 47 + .../org/onap/sdc/dcae/client/SdcRestClient.java | 221 +++ .../org/onap/sdc/dcae/enums/ArtifactGroupType.java | 5 + .../java/org/onap/sdc/dcae/enums/ArtifactType.java | 16 + .../java/org/onap/sdc/dcae/enums/AssetType.java | 5 + .../sdc/dcae/enums/LifecycleOperationType.java | 16 + .../org/onap/sdc/dcae/enums/SdcConsumerInfo.java | 5 + .../sdc/dcae/errormng/AbstractSdncException.java | 97 + .../org/onap/sdc/dcae/errormng/BaseException.java | 61 + .../org/onap/sdc/dcae/errormng/OkResponseInfo.java | 8 + .../onap/sdc/dcae/errormng/PolicyException.java | 11 + .../org/onap/sdc/dcae/errormng/RequestError.java | 65 + .../org/onap/sdc/dcae/errormng/ResponseFormat.java | 75 + .../onap/sdc/dcae/errormng/ServiceException.java | 12 + .../java/org/onap/sdc/dcae/utils/Normalizers.java | 34 + .../sdc/dcae/utils/SDCResponseErrorHandler.java | 43 + .../onap/sdc/dcae/utils/SdcRestClientUtils.java | 85 + .../org/onap/sdc/dcae/utils/NormalizersTest.java | 51 + dcaedt_catalog/commons/pom.xml | 135 ++ .../org/onap/sdc/dcae/catalog/commons/Action.java | 11 + .../org/onap/sdc/dcae/catalog/commons/Actions.java | 201 ++ .../org/onap/sdc/dcae/catalog/commons/Future.java | 35 + .../sdc/dcae/catalog/commons/FutureHandler.java | 13 + .../org/onap/sdc/dcae/catalog/commons/Futures.java | 257 +++ .../org/onap/sdc/dcae/catalog/commons/Http.java | 107 ++ .../catalog/commons/JSONHttpMessageConverter.java | 100 + .../onap/sdc/dcae/catalog/commons/ListBuilder.java | 59 + .../onap/sdc/dcae/catalog/commons/MapBuilder.java | 80 + .../org/onap/sdc/dcae/catalog/commons/Neo.java | 54 + .../org/onap/sdc/dcae/catalog/commons/Proxies.java | 37 + .../org/onap/sdc/dcae/catalog/commons/Proxy.java | 144 ++ .../org/onap/sdc/dcae/catalog/commons/Proxy.pojo | 145 ++ .../sdc/dcae/catalog/commons/ProxyBuilder.java | 92 + .../onap/sdc/dcae/catalog/commons/Recycler.java | 329 ++++ dcaedt_catalog/db/pom.xml | 149 ++ .../java/org/onap/sdc/dcae/db/neo4j/Modeled.java | 1980 ++++++++++++++++++++ .../db/src/main/resources/tosca-schema.yaml | 1231 ++++++++++++ .../src/main/resources/tosca-storage-schema.yaml | 37 + dcaedt_catalog/pom.xml | 29 + dcaedt_catalog/service/README.md | 4 + dcaedt_catalog/service/pom.xml | 80 + .../sdc/dcae/catalog/engine/CatalogController.java | 594 ++++++ .../sdc/dcae/catalog/engine/CatalogEngine.java | 26 + .../onap/sdc/dcae/catalog/engine/CatalogError.java | 20 + .../sdc/dcae/catalog/engine/CatalogMessage.java | 27 + .../sdc/dcae/catalog/engine/CatalogRequest.java | 27 + .../sdc/dcae/catalog/engine/CatalogResponse.java | 39 + .../sdc/dcae/catalog/engine/ElementRequest.java | 6 + .../sdc/dcae/catalog/engine/ElementsLookup.java | 49 + .../onap/sdc/dcae/catalog/engine/ItemsRequest.java | 16 + .../service/src/main/resources/log4j.properties | 15 + 66 files changed, 11090 insertions(+) create mode 100644 dcaedt_catalog/.gitignore create mode 100644 dcaedt_catalog/api/pom.xml create mode 100644 dcaedt_catalog/api/src/main/java/org/onap/sdc/dcae/catalog/Catalog.java create mode 100644 dcaedt_catalog/api/src/main/java/org/onap/sdc/dcae/catalog/asdc/ASDCCatalog.java create mode 100644 dcaedt_catalog/api/src/main/resources/log4j.properties create mode 100644 dcaedt_catalog/api/src/test/java/org/onap/sdc/dcae/catalog/ASDCCatalogTest.java create mode 100644 dcaedt_catalog/asdc/pom.xml create mode 100644 dcaedt_catalog/asdc/src/main/java/org/onap/sdc/dcae/catalog/asdc/ASDC.java create mode 100644 dcaedt_catalog/asdc/src/main/java/org/onap/sdc/dcae/catalog/asdc/ASDCController.java create mode 100644 dcaedt_catalog/asdc/src/main/java/org/onap/sdc/dcae/catalog/asdc/ASDCEngine.java create mode 100644 dcaedt_catalog/asdc/src/main/java/org/onap/sdc/dcae/catalog/asdc/ASDCException.java create mode 100644 dcaedt_catalog/asdc/src/main/java/org/onap/sdc/dcae/catalog/asdc/ASDCUtils.java create mode 100644 dcaedt_catalog/asdc/src/main/java/org/onap/sdc/dcae/catalog/asdc/ASDCUtilsController.java create mode 100644 dcaedt_catalog/asdc/src/main/java/org/onap/sdc/dcae/catalog/asdc/Blueprinter.java create mode 100644 dcaedt_catalog/asdc/src/main/java/org/onap/sdc/dcae/catalog/asdc/Cloudify.java create mode 100644 dcaedt_catalog/asdc/src/main/java/org/onap/sdc/dcae/client/ISdcClient.java create mode 100644 dcaedt_catalog/asdc/src/main/java/org/onap/sdc/dcae/client/SdcRestClient.java create mode 100644 dcaedt_catalog/asdc/src/main/java/org/onap/sdc/dcae/enums/ArtifactGroupType.java create mode 100644 dcaedt_catalog/asdc/src/main/java/org/onap/sdc/dcae/enums/ArtifactType.java create mode 100644 dcaedt_catalog/asdc/src/main/java/org/onap/sdc/dcae/enums/AssetType.java create mode 100644 dcaedt_catalog/asdc/src/main/java/org/onap/sdc/dcae/enums/LifecycleOperationType.java create mode 100644 dcaedt_catalog/asdc/src/main/java/org/onap/sdc/dcae/enums/SdcConsumerInfo.java create mode 100644 dcaedt_catalog/asdc/src/main/java/org/onap/sdc/dcae/errormng/AbstractSdncException.java create mode 100644 dcaedt_catalog/asdc/src/main/java/org/onap/sdc/dcae/errormng/BaseException.java create mode 100644 dcaedt_catalog/asdc/src/main/java/org/onap/sdc/dcae/errormng/OkResponseInfo.java create mode 100644 dcaedt_catalog/asdc/src/main/java/org/onap/sdc/dcae/errormng/PolicyException.java create mode 100644 dcaedt_catalog/asdc/src/main/java/org/onap/sdc/dcae/errormng/RequestError.java create mode 100644 dcaedt_catalog/asdc/src/main/java/org/onap/sdc/dcae/errormng/ResponseFormat.java create mode 100644 dcaedt_catalog/asdc/src/main/java/org/onap/sdc/dcae/errormng/ServiceException.java create mode 100644 dcaedt_catalog/asdc/src/main/java/org/onap/sdc/dcae/utils/Normalizers.java create mode 100644 dcaedt_catalog/asdc/src/main/java/org/onap/sdc/dcae/utils/SDCResponseErrorHandler.java create mode 100644 dcaedt_catalog/asdc/src/main/java/org/onap/sdc/dcae/utils/SdcRestClientUtils.java create mode 100644 dcaedt_catalog/asdc/src/test/org/onap/sdc/dcae/utils/NormalizersTest.java create mode 100644 dcaedt_catalog/commons/pom.xml create mode 100644 dcaedt_catalog/commons/src/main/java/org/onap/sdc/dcae/catalog/commons/Action.java create mode 100644 dcaedt_catalog/commons/src/main/java/org/onap/sdc/dcae/catalog/commons/Actions.java create mode 100644 dcaedt_catalog/commons/src/main/java/org/onap/sdc/dcae/catalog/commons/Future.java create mode 100644 dcaedt_catalog/commons/src/main/java/org/onap/sdc/dcae/catalog/commons/FutureHandler.java create mode 100644 dcaedt_catalog/commons/src/main/java/org/onap/sdc/dcae/catalog/commons/Futures.java create mode 100644 dcaedt_catalog/commons/src/main/java/org/onap/sdc/dcae/catalog/commons/Http.java create mode 100644 dcaedt_catalog/commons/src/main/java/org/onap/sdc/dcae/catalog/commons/JSONHttpMessageConverter.java create mode 100644 dcaedt_catalog/commons/src/main/java/org/onap/sdc/dcae/catalog/commons/ListBuilder.java create mode 100644 dcaedt_catalog/commons/src/main/java/org/onap/sdc/dcae/catalog/commons/MapBuilder.java create mode 100644 dcaedt_catalog/commons/src/main/java/org/onap/sdc/dcae/catalog/commons/Neo.java create mode 100644 dcaedt_catalog/commons/src/main/java/org/onap/sdc/dcae/catalog/commons/Proxies.java create mode 100644 dcaedt_catalog/commons/src/main/java/org/onap/sdc/dcae/catalog/commons/Proxy.java create mode 100644 dcaedt_catalog/commons/src/main/java/org/onap/sdc/dcae/catalog/commons/Proxy.pojo create mode 100644 dcaedt_catalog/commons/src/main/java/org/onap/sdc/dcae/catalog/commons/ProxyBuilder.java create mode 100644 dcaedt_catalog/commons/src/main/java/org/onap/sdc/dcae/catalog/commons/Recycler.java create mode 100644 dcaedt_catalog/db/pom.xml create mode 100644 dcaedt_catalog/db/src/main/java/org/onap/sdc/dcae/db/neo4j/Modeled.java create mode 100644 dcaedt_catalog/db/src/main/resources/tosca-schema.yaml create mode 100644 dcaedt_catalog/db/src/main/resources/tosca-storage-schema.yaml create mode 100644 dcaedt_catalog/pom.xml create mode 100644 dcaedt_catalog/service/README.md create mode 100644 dcaedt_catalog/service/pom.xml create mode 100644 dcaedt_catalog/service/src/main/java/org/onap/sdc/dcae/catalog/engine/CatalogController.java create mode 100644 dcaedt_catalog/service/src/main/java/org/onap/sdc/dcae/catalog/engine/CatalogEngine.java create mode 100644 dcaedt_catalog/service/src/main/java/org/onap/sdc/dcae/catalog/engine/CatalogError.java create mode 100644 dcaedt_catalog/service/src/main/java/org/onap/sdc/dcae/catalog/engine/CatalogMessage.java create mode 100644 dcaedt_catalog/service/src/main/java/org/onap/sdc/dcae/catalog/engine/CatalogRequest.java create mode 100644 dcaedt_catalog/service/src/main/java/org/onap/sdc/dcae/catalog/engine/CatalogResponse.java create mode 100644 dcaedt_catalog/service/src/main/java/org/onap/sdc/dcae/catalog/engine/ElementRequest.java create mode 100644 dcaedt_catalog/service/src/main/java/org/onap/sdc/dcae/catalog/engine/ElementsLookup.java create mode 100644 dcaedt_catalog/service/src/main/java/org/onap/sdc/dcae/catalog/engine/ItemsRequest.java create mode 100644 dcaedt_catalog/service/src/main/resources/log4j.properties (limited to 'dcaedt_catalog') diff --git a/dcaedt_catalog/.gitignore b/dcaedt_catalog/.gitignore new file mode 100644 index 0000000..a6609e3 --- /dev/null +++ b/dcaedt_catalog/.gitignore @@ -0,0 +1,12 @@ +.classpath +.settings/ +.project +.DS_Store + +#a bit dangerous, make sure we do not have any package named target .. +**/target/ +pom.xml.tag +pom.xml.releaseBackup +pom.xml.versionsBackup +pom.xml.next +release.properties diff --git a/dcaedt_catalog/api/pom.xml b/dcaedt_catalog/api/pom.xml new file mode 100644 index 0000000..234f12f --- /dev/null +++ b/dcaedt_catalog/api/pom.xml @@ -0,0 +1,198 @@ + + 4.0.0 + + org.onap.sdc.dcae + DCAE-DT-Catalog + 1806.0.1-SNAPSHOT + + DCAE-DT-Catalog-API + jar + DCAE DT Catalog API + + + src/main/java + src/test/java + + + maven-compiler-plugin + 3.1 + + 1.8 + 1.8 + ${project.build.sourceEncoding} + + + + org.apache.maven.plugins + maven-dependency-plugin + 2.10 + + + copy-dependencies + package + + copy-dependencies + + + ${project.build.directory}/deps + false + false + true + + + + + + org.codehaus.mojo + buildnumber-maven-plugin + 1.4 + + + validate + + create + + + + + false + false + + + + org.apache.maven.plugins + maven-jar-plugin + 2.1 + + + + true + + + ${buildNumber} + + + + + + + org.apache.maven.plugins + maven-jar-plugin + 3.0.2 + + + + test-jar + + + + + + org.apache.maven.plugins + maven-assembly-plugin + 2.6 + + + jar-with-dependencies + + + + org.onap.sdc.dcae.catalog.test.Cataloged + + + ${buildNumber} + + + + + + + + + + + false + + jcenter + Bintray JCenter + http://repo1.maven.org/maven2/ + + + + + commons-jxpath + commons-jxpath + 1.3 + + + org.apache.commons + commons-lang3 + 3.5 + + + org.apache.httpcomponents + httpasyncclient + 4.1 + + + commons-io + commons-io + 2.4 + + + commons-cli + commons-cli + 1.3 + + + + org.json + json + 20160810 + + + + org.onap.sdc.dcae + DCAE-DT-Catalog-Commons + ${project.version} + + + org.onap.sdc.dcae + DCAE-DT-Catalog-ASDC + ${project.version} + + + + org.onap.sdc.dcae + DCAE-DT-Validator-Checker + ${project.version} + + + + junit + junit + 4.12 + test + + + + org.mockito + mockito-core + 1.10.19 + test + + + + org.assertj + assertj-core + + 3.8.0 + test + + + + + diff --git a/dcaedt_catalog/api/src/main/java/org/onap/sdc/dcae/catalog/Catalog.java b/dcaedt_catalog/api/src/main/java/org/onap/sdc/dcae/catalog/Catalog.java new file mode 100644 index 0000000..b73bb09 --- /dev/null +++ b/dcaedt_catalog/api/src/main/java/org/onap/sdc/dcae/catalog/Catalog.java @@ -0,0 +1,440 @@ +package org.onap.sdc.dcae.catalog; + +import java.net.URI; + +import java.util.Arrays; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.LinkedList; +import java.util.HashMap; +import java.util.EnumSet; + +import org.json.JSONObject; +import org.onap.sdc.dcae.catalog.commons.Action; +import org.onap.sdc.dcae.catalog.commons.Future; +import org.onap.sdc.dcae.catalog.commons.Futures; +import org.onap.sdc.dcae.catalog.commons.Proxies; + + +import org.json.JSONArray; + +/* + * + */ +public interface Catalog { + + + public abstract URI getUri(); + + public abstract String namespace(); + + public abstract boolean same(Catalog theCatalog); + + public abstract T proxy(JSONObject theData, Class theType); + + + /* Base class for all Catalog objects. + */ + public static interface Element> { + + /** + * provide a typed 'self' reference + */ + public default T self() { return (T)this; } + + /** + */ + public default Class selfClass() { + return (Class)getClass().getInterfaces()[0]; + } + + /* */ + public Catalog catalog(); + + /** + */ + public String id(); + + /** + * Direct access to the underlying JSON object. + * Warning: Modifications to the JSON object are reflected in the Element. + */ + public JSONObject data(); + + /** + * Provides the labels of the artifacts (we use labels to type/classify the + * neo4j artifacts, nodes and edges. + * Currently not all queries retrieve the labels. + */ + public String[] labels(); + + /* Allows for typed deep exploration of the backing JSON data structure + *
+		 * {@code
+		 * element("type", Type.class);
+		 * }
+		 * 
+ * + * @arg theName name of a JSON entry ; It must map another JSONObject. + * @arg theType the expected wrapping catalog artifact type + * @return the JSON entry wrapped in the specified type + */ + public default > E element(String theName, Class theType) { + JSONObject elemData = data().optJSONObject(theName); + if (elemData == null) + return null; + else + return catalog().proxy(elemData, theType); + } + + /* Similar to {@link #element(String,Class)} but for collection wrapping. + * Example: + *
+		 * {@code
+		 * element("nodes", Nodes.class);
+		 * }
+		 * 
+ */ + public default E elements(String theName, Class theType) { + //throws ReflectiveOperationException { + JSONArray elemsData = data().optJSONArray(theName); + if (elemsData == null) { + return null; + } + else { + Class etype = Proxies.typeArgument(theType); + Elements elems = null; + try { + elems = theType.newInstance(); + } + catch (ReflectiveOperationException rox) { + throw new RuntimeException("Failed to instantiate " + theType, rox); + } + + try{ + for (Iterator i = elemsData.iterator(); i.hasNext();) { + JSONObject elemData = (JSONObject)i.next(); + elems.add(catalog().proxy(elemData, etype)); + } + } + catch(Exception e){ + throw new RuntimeException("Failed to fetch json data ", e); + } + return (E)elems; + } + } + + /* + */ + public default boolean same(Element theElem) { + return this.catalog().same(theElem.catalog()) && + this.id().equals(theElem.id()); + } + } + + /* + * Base class for all collections of elements. + */ + public static class Elements + extends LinkedList { + + public String toString() { + StringBuilder sb = new StringBuilder("["); + for (Element el: this) { + sb.append(el.selfClass().getSimpleName()) + .append("(") + .append(el.data()) + .append("),"); + } + sb.append("]"); + return sb.toString(); + } + } + + /* + * We need this contraption in order to store a mix of Folders and CatalogItem + * instances (Elements in self is not good because it is defined around a + * type variable so we cannot use reflection to determine the type at runtime + * - generics are resolved compile time) + */ + public static class Mixels extends Elements { + } + + /* + */ + public static interface Item> extends Element { + + public String name(); + + public String description(); + + /* catalog item native identifier */ + public String itemId(); + + /* similar to @ItemAction#withModels + */ + default public Future models() { + Templates t = elements("models", Templates.class); + if (t != null) + return Futures.succeededFuture(t); + else + return Futures.advance(catalog().item(itemId()) + .withModels() + .execute(), + item -> (Templates)item.elements("models", Templates.class)); + } + + /* similar to @ItemAction#withAnnotations + */ + default public Future annotations() { + Annotations a = elements("annotations", Annotations.class); + if (a != null) + return Futures.succeededFuture(a); + else + return Futures.advance(catalog().item(itemId()) + .withAnnotations() + .execute(), + item -> (Annotations)item.elements("annotations", Annotations.class)); + } + } + + /* + * Collection of catalog items. + */ + public static class Items extends Elements { + } + + /* + */ + public static interface Folder extends Element { + + public String name(); + + public String description(); + + public String itemId(); + + /* the namespace is immutable */ + public default String namespace() { + return catalog().namespace(); + } + + /* + */ + default public Future items() { + Items i = elements("items", Items.class); + if (i != null) + return Futures.succeededFuture(i); + else + return Futures.advance(catalog().folder(itemId()) + .withItems() + .execute(), + folder -> (Items)folder.elements("items", Items.class)); + } + + /* + */ + default public Future parts() { + Folders f = elements("parts", Folders.class); + if (f != null) + return Futures.succeededFuture(f); + else + return Futures.advance(catalog().folder(itemId()) + .withParts() + .execute(), + folder -> (Folders)folder.elements("parts", Folders.class)); + } + + /* + */ + public Future partof(); + + } + + + public static class Folders extends Elements { + } + + //no predefined properties here + public static interface Annotation extends Element { + + public default String namespace() { + return catalog().namespace(); + } + } + + public static class Annotations extends Elements { + } + + /** + * A TOSCA teamplate. + * When a deep loading method is used to obtain a Template its collection + * of inputs and nodes will be immediately available (and 'cached' within + * the backing JSON object). It can be retrieved through a call to + * {@link Element#elements(String,Class)} as in: + * elements("inputs", Inputs.class) + * or + * elements("nodes", Nodes.class) + * + * The same result will be obtained through one of the methods of the + * navigation interface, {@link #inputs()} or {@link #nodes()}; in this case + * the result does not become part of the backing JSONObject. + */ + public static interface Template extends Element