summaryrefslogtreecommitdiffstats
path: root/dcaedt_catalog
diff options
context:
space:
mode:
authorEran (ev672n), Vosk <ev672n@att.com>2018-08-06 17:02:39 +0300
committerEran (ev672n), Vosk <ev672n@att.com>2018-08-06 17:02:39 +0300
commit86457ed120fc236b1485ad3251589aedad2401bd (patch)
treea473c2faf16ffbb34aad75d4fef8afc3b2541f21 /dcaedt_catalog
parent735b58119b37ead5013c40afd941d63ef28ca053 (diff)
Changing the dcae dt main code
Updating DCAE-dt-main code for Dockerizing the DCAE-CI code Change-Id: Ia50d24e60e9ddc9bbc58dd8651d7a4f7e0dc8270 Issue-ID: SDC-1605 Signed-off-by: Eran (ev672n), Vosk <ev672n@att.com>
Diffstat (limited to 'dcaedt_catalog')
-rw-r--r--dcaedt_catalog/api/src/main/java/org/onap/sdc/dcae/catalog/Catalog.java61
-rw-r--r--dcaedt_catalog/api/src/main/java/org/onap/sdc/dcae/catalog/asdc/ASDCCatalog.java486
-rw-r--r--dcaedt_catalog/api/src/test/java/org/onap/sdc/dcae/catalog/ASDCCatalogTest.java88
-rw-r--r--dcaedt_catalog/asdc/src/main/java/org/onap/sdc/dcae/catalog/asdc/ASDC.java288
-rw-r--r--dcaedt_catalog/asdc/src/main/java/org/onap/sdc/dcae/catalog/asdc/ASDCEngine.java25
-rw-r--r--dcaedt_catalog/asdc/src/main/java/org/onap/sdc/dcae/catalog/asdc/ASDCUtils.java188
-rw-r--r--dcaedt_catalog/asdc/src/main/java/org/onap/sdc/dcae/catalog/asdc/ASDCUtilsController.java36
-rw-r--r--dcaedt_catalog/asdc/src/main/java/org/onap/sdc/dcae/catalog/asdc/Blueprinter.java65
-rw-r--r--dcaedt_catalog/asdc/src/main/java/org/onap/sdc/dcae/client/ISdcClient.java4
-rw-r--r--dcaedt_catalog/asdc/src/main/java/org/onap/sdc/dcae/client/SdcRestClient.java7
-rw-r--r--dcaedt_catalog/asdc/src/main/java/org/onap/sdc/dcae/utils/SdcRestClientUtils.java10
-rw-r--r--dcaedt_catalog/asdc/src/test/java/org/onap/sdc/dcae/utils/SDCResponseErrorHandlerTest.java2
-rw-r--r--dcaedt_catalog/commons/README0
-rw-r--r--dcaedt_catalog/commons/src/main/java/org/onap/sdc/dcae/catalog/commons/Action.java3
-rw-r--r--dcaedt_catalog/commons/src/main/java/org/onap/sdc/dcae/catalog/commons/Actions.java201
-rw-r--r--dcaedt_catalog/commons/src/main/java/org/onap/sdc/dcae/catalog/commons/Recycler.java4
-rw-r--r--dcaedt_catalog/db/src/main/java/org/onap/sdc/dcae/db/neo4j/Modeled.java1
-rw-r--r--dcaedt_catalog/service/src/main/java/org/onap/sdc/dcae/catalog/engine/CatalogController.java79
-rw-r--r--dcaedt_catalog/service/src/main/java/org/onap/sdc/dcae/catalog/engine/CatalogEngine.java14
19 files changed, 67 insertions, 1495 deletions
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
index c9813e4..d7db9e6 100644
--- 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
@@ -1,24 +1,17 @@
package org.onap.sdc.dcae.catalog;
-import java.net.URI;
-
-import java.util.Iterator;
-import java.util.LinkedList;
-
+import org.json.JSONArray;
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.onap.sdc.dcae.composition.restmodels.sdc.ResourceDetailed;
-
-import org.json.JSONArray;
+import java.util.Iterator;
+import java.util.LinkedList;
public interface Catalog {
-
- URI getUri();
-
<T> T proxy(JSONObject theData, Class<T> theType);
@@ -39,7 +32,7 @@ public interface Catalog {
*/
JSONObject data();
- /* Allows for typed deep exploration of the backing JSON data structure
+ /* Allows for typed deep exploration of the backing JSON data structure
* @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
@@ -127,18 +120,6 @@ public interface Catalog {
String itemId();
- default Future<Items> items() {
- Items i = elements("items", Items.class);
- if (i != null) {
- return Futures.succeededFuture(i);
- }
- else {
- return Futures.advance(catalog().folder(itemId())
- .withItems()
- .execute(),
- folder -> folder.elements("items", Items.class));
- }
- }
}
class Folders extends Elements<Folder> {}
@@ -234,38 +215,8 @@ public interface Catalog {
Future<Type> execute();
}
- interface FolderAction extends Action<Folder> {
-
- FolderAction withItems();
-
- FolderAction withItemAnnotations();
-
- FolderAction withItemModels();
-
- FolderAction withParts();
-
- FolderAction withPartAnnotations();
-
- @Override
- Future<Folder> execute();
- }
-
- interface ItemAction<T extends Item> extends Action<T> {
-
- ItemAction<T> withModels();
-
- @Override
- Future<T> execute();
-
- }
-
- Future<Folders> rootsByLabel(String theLabel);
-
- FolderAction folder(String theFolderId);
-
- <T extends Item> ItemAction<T> item(String theItemId);
- TemplateAction template(String theTemplateId);
+ TemplateAction template(ResourceDetailed resourceData);
TypeAction type(String theNamespace, String theTypeName);
}
diff --git a/dcaedt_catalog/api/src/main/java/org/onap/sdc/dcae/catalog/asdc/ASDCCatalog.java b/dcaedt_catalog/api/src/main/java/org/onap/sdc/dcae/catalog/asdc/ASDCCatalog.java
index dfbaeaa..8557242 100644
--- a/dcaedt_catalog/api/src/main/java/org/onap/sdc/dcae/catalog/asdc/ASDCCatalog.java
+++ b/dcaedt_catalog/api/src/main/java/org/onap/sdc/dcae/catalog/asdc/ASDCCatalog.java
@@ -5,13 +5,15 @@ import org.apache.commons.io.IOUtils;
import org.apache.commons.jxpath.JXPathContext;
import org.apache.commons.jxpath.JXPathNotFoundException;
import org.apache.commons.lang3.StringUtils;
-import org.json.JSONArray;
import org.json.JSONObject;
import org.onap.sdc.common.onaplog.Enums.LogLevel;
import org.onap.sdc.common.onaplog.OnapLoggerDebug;
import org.onap.sdc.dcae.catalog.Catalog;
import org.onap.sdc.dcae.catalog.commons.*;
import org.onap.sdc.dcae.checker.*;
+import org.onap.sdc.dcae.composition.restmodels.sdc.Artifact;
+import org.onap.sdc.dcae.composition.restmodels.sdc.ResourceDetailed;
+import org.springframework.stereotype.Component;
import java.io.*;
import java.net.URI;
@@ -22,7 +24,7 @@ import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
-@SuppressWarnings("ALL")
+@Component
public class ASDCCatalog implements Catalog {
private
@@ -36,40 +38,14 @@ public class ASDCCatalog implements Catalog {
private
static final String ITEM_ID = "itemId";
private
- static final String LABELS = "labels";
- private
- static final String ARTIFACT_URL = "artifactURL";
- private
static final String CAPABILITY = "capability";
private
- static final String DATABASE = "Database";
- private
- static final String COLLECTOR = "Collector";
- private
- static final String MICROSERVICE = "Microservice";
- private
- static final String ANALYTICS = "Analytics";
- private
- static final String POLICY = "Policy";
- private
- static final String SOURCE = "Source";
- private
- static final String UTILITY = "Utility";
- private
static final String NAME = "name";
private
static final String ID = "id";
private
- static final String ARTIFACT_NAME = "artifactName";
- private
static final String DESCRIPTION = "description";
private
- static final String MODELS = "models";
- private
- static final String ARTIFACTS = "artifacts";
- private
- static final String ITEMS = "items";
- private
static final String PROPERTIES = "']/properties";
private
static final String TOPOLOGY_TEMPLATE_NODE_TEMPLATES1 = "/topology_template/node_templates/";
@@ -82,114 +58,26 @@ public class ASDCCatalog implements Catalog {
private static OnapLoggerDebug debugLogger = OnapLoggerDebug.getInstance();
- private ASDC asdc;
-
- private JSONObject folders = new JSONObject();
- private String[] folderFields = new String[] {ID, ITEM_ID, NAME};
-
private ProxyBuilder proxies;
private Map<Target, JXPathContext> contexts = new HashMap<>();
// resource and its catalog
private Map<UUID, org.onap.sdc.dcae.checker.Catalog> catalogs = new HashMap<>();
- public ASDCCatalog(URI theURI) {
-
- this.asdc = new ASDC();
- this.asdc.setUri(theURI);
-
- initFolders();
-
+ public ASDCCatalog() {
this.proxies = new ProxyBuilder().withConverter(v -> v == null ? null : UUID.fromString(v.toString()), UUID.class)
.withExtensions(
new ImmutableMap.Builder<String, BiFunction<Proxy, Object[], Object>>().put("data", (proxy, args) -> proxy.data())
.build()).withContext(new ImmutableMap.Builder<String, Object>().put("catalog", this).build());
}
- private void initFolders() {
-
- JSONArray labels = new JSONArray();
- labels.put("Folder");
- labels.put("DCAE");
- labels.put("Superportfolio"); // for CCD compatibility
-
- folders.put(DATABASE, new JSONObject().put(NAME, DATABASE).put(ID, "dcae_database")
- .put(ITEM_ID, DATABASE).put(LABELS, labels));
- folders.put(COLLECTOR, new JSONObject().put(NAME, COLLECTOR).put(ID, "dcae_collector")
- .put(ITEM_ID, COLLECTOR).put(LABELS, labels));
- folders.put(MICROSERVICE, new JSONObject().put(NAME, MICROSERVICE).put(ID, "dcae_microservice")
- .put(ITEM_ID, MICROSERVICE).put(LABELS, labels));
- folders.put(ANALYTICS, new JSONObject().put(NAME, ANALYTICS).put(ID, "dcae_analytics")
- .put(ITEM_ID, ANALYTICS).put(LABELS, labels));
- folders.put(POLICY, new JSONObject().put(NAME, POLICY).put(ID, "dcae_policy").put(ITEM_ID, POLICY)
- .put(LABELS, labels));
- folders.put(SOURCE, new JSONObject().put(NAME, SOURCE).put(ID, "dcae_source").put(ITEM_ID, SOURCE)
- .put(LABELS, labels));
- folders.put(UTILITY, new JSONObject().put(NAME, UTILITY).put(ID, "dcae_utility")
- .put(ITEM_ID, UTILITY).put(LABELS, labels));
- }
-
- public URI getUri() {
- return this.asdc.getUri();
- }
-
- public String namespace() {
- return "asdc";
- }
-
- public boolean same(Catalog theCatalog) {
- return true;
- }
-
public <T> T proxy(JSONObject theData, Class<T> theType) {
return proxies.build(theData, theType);
}
- /** */
- public Future<Folders> roots() {
-
- Folders roots = new Folders();
- for (Iterator fi = folders.keys(); fi.hasNext();) {
- roots.add(proxies.build(folders.getJSONObject((String) fi.next()), Folder.class));
- }
- return Futures.succeededFuture(roots);
- }
-
- /** */
- public Future<Folders> rootsByLabel(String theLabel) {
-
- Folders roots = new Folders();
- for (Iterator fi = folders.keys(); fi.hasNext();) {
- JSONObject folder = folders.getJSONObject((String) fi.next());
- JSONArray labels = folder.getJSONArray(LABELS);
-
- for (int i = 0; i < labels.length(); i++) {
- if (labels.get(i).equals(theLabel)) {
- roots.add(proxies.build(folder, Folder.class));
- }
- }
- }
- return Futures.succeededFuture(roots);
- }
-
- public Future<Mixels> lookup(JSONObject theSelector) {
- return Futures.succeededFuture(new Mixels());
- }
-
- public Future<Mixels> lookup(String theAnnotation, JSONObject theSelector) {
- return Futures.succeededFuture(new Mixels());
- }
-
- public ItemAction item(String theItemId) {
- return new ResourceAction(UUID.fromString(theItemId));
- }
-
- public CatalogFolderAction folder(String theFolderId) {
- return new CatalogFolderAction(theFolderId);
- }
- public CatalogTemplateAction template(String theId) {
- return new CatalogTemplateAction(theId);
+ public CatalogTemplateAction template(ResourceDetailed resource) {
+ return new CatalogTemplateAction(resource);
}
public CatalogTypeAction type(String theItemId, String theName) {
@@ -229,35 +117,6 @@ public class ASDCCatalog implements Catalog {
Spliterator.NONNULL | Spliterator.DISTINCT | Spliterator.IMMUTABLE), false);
}
- private JSONArray selectModels(JSONArray theArtifacts) {
- JSONArray models = new JSONArray();
- if (theArtifacts == null) {
- return models;
- }
-
- for (int i = 0; i < theArtifacts.length(); i++) {
- JSONObject artifact = theArtifacts.getJSONObject(i);
- String name = artifact.optString(ARTIFACT_NAME);
- if (name != null && StringUtils.containsIgnoreCase(name, "template")) {
- models.put(new JSONObject().putOpt(NAME, artifact.optString(ARTIFACT_NAME))
- .putOpt("version", artifact.optString("artifactVersion"))
- .putOpt(DESCRIPTION, artifact.optString("artifactType"))
- .putOpt(ID, artifact.optString(ARTIFACT_URL))
- .putOpt(ITEM_ID, artifact.optString(ARTIFACT_URL)));
- }
- }
- return models;
- }
-
- private JSONObject patchResource(JSONObject theResource) {
-
- theResource.remove("resources");
- theResource.putOpt(ID, theResource.opt("uuid"));
- theResource.putOpt(ITEM_ID, theResource.opt("uuid"));
-
- return theResource;
- }
-
private static void dumpTargets(String theDirName, Collection<Target> theTargets) {
File targetDir = new File(theDirName);
if (!targetDir.exists() && !targetDir.mkdirs()) {
@@ -285,180 +144,17 @@ public class ASDCCatalog implements Catalog {
return UUID.fromString(theValue);
}
- private org.onap.sdc.dcae.checker.Catalog getCatalog(UUID theResourceId) {
+ private org.onap.sdc.dcae.checker.Catalog getCachedCatalogItem(UUID theResourceId) {
return this.catalogs.get(theResourceId);
}
- private String getArtifactVersion(JSONObject theData) {
- return theData.getString("artifactVersion");
- }
-
- private String getArtifactName(JSONObject theData) {
- return theData.getString(ARTIFACT_NAME);
- }
-
- private String getArtifactURL(JSONObject theData) {
- return theData.getString(ARTIFACT_URL);
- }
-
- private URI getArtifactURI(JSONObject theData) {
- return asURI(theData.getString(ARTIFACT_URL));
- }
-
- /** */
- public class ResourceAction implements Catalog.ItemAction<Resource> {
-
- private UUID iid;
- private boolean doModels;
-
- ResourceAction(UUID theItemId) {
- this.iid = theItemId;
- }
-
- public ResourceAction withModels() {
- this.doModels = true;
- return this;
- }
-
- public ResourceAction withAnnotations() {
- return this;
- }
-
- @Override
- public Future<Resource> execute() {
-
- return Futures.advance(asdc.getResource(this.iid, JSONObject.class), resourceData -> {
- if (doModels) {
- resourceData.put(MODELS, selectModels(resourceData.optJSONArray(ARTIFACTS)));
- }
- return proxies.build(patchResource(resourceData), Resource.class);
- });
- }
-
- protected Future<JSONObject> executeRaw() {
-
- return Futures.advance(asdc.getResource(this.iid, JSONObject.class), resourceData -> {
- if (doModels) {
- resourceData.put(MODELS, selectModels(resourceData.optJSONArray(ARTIFACTS)));
- }
- return resourceData;
- }, resourceError -> new RuntimeException("Failed to retrieve item " + this.iid, resourceError));
- }
- }
-
- public class CatalogFolderAction implements Catalog.FolderAction {
-
- private boolean doItemModels;
- private String folderName;
+ public boolean hasCachedItem(String uuid) {
+ return this.catalogs.containsKey(asUUID(uuid));
+ }
- // use the id/UUID of the folder ??
- private CatalogFolderAction(String theFolderName) {
- this.folderName = theFolderName;
- }
-
- public CatalogFolderAction withAnnotations() {
- return this;
- }
-
- public CatalogFolderAction withAnnotations(String theSelector) {
- return this;
- }
-
- public CatalogFolderAction withItems() {
- return this;
- }
-
- public CatalogFolderAction withItemAnnotations() {
- return this;
- }
-
- public CatalogFolderAction withItemAnnotations(String theSelector) {
- return this;
- }
-
- public CatalogFolderAction withItemModels() {
- doItemModels = true;
- return this;
- }
-
- public CatalogFolderAction withParts() {
- return this;
- }
-
- public CatalogFolderAction withPartAnnotations() {
- return this;
- }
-
- public CatalogFolderAction withPartAnnotations(String theSelector) {
- return this;
- }
-
- @Override
- public Future<Folder> execute() {
-
- JSONObject folder = folders.optJSONObject(this.folderName);
- if (folder == null) {
- return Futures.failedFuture(new RuntimeException("No such folder " + this.folderName));
- }
-
- final JSONObject folderView = new JSONObject(folder, folderFields);
-
- return Futures.advance(asdc.getResources(JSONArray.class, "DCAE Component", this.folderName),
- resourcesData -> {
-
- Actions.CompoundAction<Resource> itemsAction = new Actions.BasicCompoundAction<>();
- for (int i = 0; i < resourcesData.length(); i++) {
- JSONObject resource = resourcesData.getJSONObject(i);
-
- if (doItemModels) {
- itemsAction
- .addAction(new ResourceAction(asUUID(resource.getString("uuid"))).withModels());
- } else {
- folderView.append(ITEMS, patchResource(resource));
- }
- }
-
- try {
- List<Resource> items = itemsAction.execute().waitForResult();
- debugLogger.log(LogLevel.DEBUG, this.getClass().getName(), "Number of DCAE item for : {} is {}", this.folderName, items.size());
-
- for (Resource res : filterLatestVersion(items)) {
- folderView.append(ITEMS, patchResource(res.data()));
- }
- } catch (Exception x) {
- debugLogger.log(LogLevel.DEBUG, this.getClass().getName(), "Exception {}", x);
- throw new RuntimeException("Failed to retrieve folder items", x);
- }
-
- return proxies.build(folderView, Folder.class);
- }, resourcesError -> new RuntimeException("Failed to retrieve resources", resourcesError));
- }
-
- public Collection<Resource> filterLatestVersion(Collection<Resource> items) {
- if (items == null) {
- throw new IllegalArgumentException("null is not acceptable as a list of items");
- }
- Map<UUID, Resource> itemsMap = new HashMap<UUID, Resource>(items.size());
- for (Resource r : items) {
- if (itemsMap.containsKey(r.invariantUUID()) && isNewerVersion(itemsMap, r)) {
- debugLogger.log(LogLevel.DEBUG, this.getClass().getName(), "Avoiding adding item {} since it has a advanced version already", r.toString());
- continue;
- }
- itemsMap.put(r.invariantUUID(), r);
- }
- return itemsMap.values();
- }
-
- private boolean isNewerVersion(Map<UUID, Resource> itemsMap, Resource r) {
- return Float.valueOf(itemsMap.get(r.invariantUUID()).version()) > Float.valueOf(r.version());
- }
-
- }
-
- /** */
public class CatalogTemplateAction implements Catalog.TemplateAction {
- private String artifactId;
+ private ResourceDetailed resourceMetadata;
private Target target;
private org.onap.sdc.dcae.checker.Catalog catalog;
private JXPathContext ctx = JXPathContext.newContext(new HashMap());
@@ -466,13 +162,10 @@ public class ASDCCatalog implements Catalog {
private boolean doNodes, doNodeProperties, doNodePropertiesAssignments, doNodeRequirements, doNodeCapabilities,
doNodeCapabilityProperties, doNodeCapabilityPropertyAssignments;
- /*
- * expected to be the relative url provided by asdc for the template
- * artifact
- */
- CatalogTemplateAction(String theArtifactId) {
- this.artifactId = theArtifactId;
- }
+
+ CatalogTemplateAction(ResourceDetailed resourceMetadata) {
+ this.resourceMetadata = resourceMetadata;
+ }
public CatalogTemplateAction withInputs() {
return this;
@@ -500,7 +193,7 @@ public class ASDCCatalog implements Catalog {
ctx.setValue("/nodes",
nodes.entrySet().stream()
.map(nodeEntry -> new MapBuilder().put(NAME, ((Map.Entry) nodeEntry).getKey())
- .put(DESCRIPTION, this.artifactId)
+ .put(DESCRIPTION, resourceMetadata.getToscaModelURL())
.putAll(selectEntries((Map) ((Map.Entry) nodeEntry).getValue(), "type")).build())
.collect(Collectors.toList()));
@@ -852,29 +545,20 @@ public class ASDCCatalog implements Catalog {
if (this.target == null) {
- String[] parts = this.artifactId.split("/");
- if (parts.length != 8) {
- return Futures
- .failedFuture(new Exception("Unexpected artifact id for template " + this.artifactId));
- }
-
- UUID resourceId = asUUID(parts[5]);
+ UUID resourceId = asUUID(resourceMetadata.getUuid());
this.catalog = ASDCCatalog.this.catalogs.get(resourceId);
// if we find a catalog for this resource we have to figure out
// if it contains the required target ..
try {
- JSONObject resource = new ResourceAction(resourceId).executeRaw().waitForResult();
Checker checker = new Checker();
- TargetLocator locator = new ASDCLocator(resource.getJSONArray(ARTIFACTS),
- ASDCCatalog.this.catalogs.get(resourceId));
+ TargetLocator locator = new ASDCLocator(resourceMetadata.getArtifacts(), ASDCCatalog.this.catalogs.get(resourceId));
checker.setTargetLocator(locator);
-
Target template = locator.resolve("template");
if (template == null) {
- return Futures.failedFuture(new Exception("Failed to locate template in " + resource));
+ return Futures.failedFuture(new Exception("Failed to locate template in " + resourceMetadata));
}
checker.check(template);
@@ -902,8 +586,8 @@ public class ASDCCatalog implements Catalog {
.doNodeCapabilityProperties().doNodeCapabilityPropertyAssignments();
JSONObject pack = new JSONObject((Map) ctx.getContextBean()).put(NAME, this.target.getName())
- .put(ID, this.target.getLocation().toString())
- .put(ITEM_ID, this.target.getLocation().toString());
+ .put(ID, resourceMetadata.getUuid())
+ .put(ITEM_ID, resourceMetadata.getToscaModelURL());
debugLogger.log(LogLevel.DEBUG, this.getClass().getName(), pack.toString(2));
return Futures.succeededFuture(proxies.build(pack, Template.class));
@@ -918,7 +602,7 @@ public class ASDCCatalog implements Catalog {
private boolean doHierarchy = false, doRequirements = false, doCapabilities = false;
- private CatalogTypeAction(UUID theResourceId, /* Construct theConstruct, */ String theName) {
+ private CatalogTypeAction(UUID theResourceId, String theName) {
this.resourceId = theResourceId;
this.name = theName;
}
@@ -967,7 +651,7 @@ public class ASDCCatalog implements Catalog {
// the type reference, else it is a name
// (within a node type)
.put(ID,
- getCatalog(resourceId).hasType(Construct.Capability, capability)
+ getCachedCatalogItem(resourceId).hasType(Construct.Capability, capability)
? (resourceId + "/" + capability) : capability)
.build())
.put("node", new MapBuilder().putOpt(NAME, node).putOpt(ID, node == null ? null
@@ -1010,9 +694,6 @@ public class ASDCCatalog implements Catalog {
.putOpt("validSourceTypes",
((Map) capability.getValue()).get("validSourceTypes"))
.build()
- // renderEntry((Map.Entry)capability,
- // "occurrences",
- // "validSourceTypes")
).collect(Collectors.toList()));
return this;
}
@@ -1042,60 +723,12 @@ public class ASDCCatalog implements Catalog {
}
}
- public interface Resource extends Catalog.Item<Resource> {
-
- @Override
- @Proxy.DataMap(map = "uuid")
- public String id();
-
- public UUID uuid();
-
- public UUID invariantUUID();
-
- public String category();
-
- public String subCategory();
-
- public String lastUpdaterFullName();
-
- public String version();
-
- @Proxy.DataMap(proxy = true, elementType = Artifact.class)
- public Artifacts artifacts();
-
- }
-
- public static class Resources extends Elements<Resource> {
- }
-
- public interface Artifact extends Catalog.Element<Artifact> {
-
- @Proxy.DataMap(map = ARTIFACT_NAME)
- String name();
-
- @Proxy.DataMap(map = "artifactType")
- String type();
-
- @Proxy.DataMap(map = "artifactDescription")
- String description();
-
- @Proxy.DataMap(map = "artifactUUID")
- UUID uuid();
-
- @Proxy.DataMap(map = "artifactVersion")
- int version();
-
- }
-
- public static class Artifacts extends Elements<Artifact> {
- }
-
public class ASDCLocator implements TargetLocator {
- private JSONArray artifacts;
+ private List<Artifact> artifacts;
private org.onap.sdc.dcae.checker.Catalog catalog;
- private ASDCLocator(JSONArray theArtifacts, org.onap.sdc.dcae.checker.Catalog theCatalog) {
+ private ASDCLocator(List<Artifact> theArtifacts, org.onap.sdc.dcae.checker.Catalog theCatalog) {
this.artifacts = theArtifacts;
this.catalog = theCatalog;
}
@@ -1113,15 +746,8 @@ public class ASDCCatalog implements Catalog {
}
public Target resolve(String theName) {
- JSONObject targetArtifact = null;
- for (int i = 0; i < this.artifacts.length(); i++) {
- JSONObject artifact = this.artifacts.getJSONObject(i);
- String artifactName = artifact.getString(ARTIFACT_NAME);
- if (StringUtils.containsIgnoreCase(artifactName, theName)) {
- targetArtifact = artifact;
- }
- }
+ Artifact targetArtifact = this.artifacts.stream().filter(a -> StringUtils.containsIgnoreCase(a.getArtifactName(), theName)).findAny().orElse(null);
if (targetArtifact == null) {
return null;
@@ -1130,8 +756,8 @@ public class ASDCCatalog implements Catalog {
ASDCTarget target;
if (this.catalog != null) {
// this is the caching!!
- target = (ASDCTarget) this.catalog.getTarget(ASDCCatalog.this.getArtifactURI(targetArtifact));
- if (target != null && target.getVersion().equals(ASDCCatalog.this.getArtifactVersion(targetArtifact))) {
+ target = (ASDCTarget) this.catalog.getTarget(asURI(targetArtifact.getArtifactURL()));
+ if (target != null) {
return target;
}
}
@@ -1142,11 +768,10 @@ public class ASDCCatalog implements Catalog {
public class ASDCTarget extends Target {
- private String content;
- private JSONObject artifact;
+ private Artifact artifact;
- private ASDCTarget(JSONObject theArtifact) {
- super(ASDCCatalog.this.getArtifactName(theArtifact), ASDCCatalog.this.getArtifactURI(theArtifact));
+ private ASDCTarget(Artifact theArtifact) {
+ super(theArtifact.getArtifactName(), asURI(theArtifact.getArtifactURL()));
this.artifact = theArtifact;
}
@@ -1156,53 +781,8 @@ public class ASDCCatalog implements Catalog {
@Override
public Reader open() throws IOException {
- if (this.content == null) {
- try {
- this.content = ASDCCatalog.this.asdc
- .fetch(ASDCCatalog.this.getArtifactURL(this.artifact), String.class).waitForResult();
- } catch (Exception x) {
- throw new IOException("Failed to load " + ASDCCatalog.this.getArtifactURL(this.artifact), x);
- }
- }
-
- // should return immediately a reader blocked until content
- // available .. hard to handle errors
- return new StringReader(this.content);
- }
-
- public String getVersion() {
- return ASDCCatalog.this.getArtifactVersion(this.artifact);
+ return new StringReader(this.artifact.getPayloadData());
}
}
-
- public static void main(String[] theArgs) throws Exception {
-
- ASDCCatalog catalog = new ASDCCatalog(new URI(theArgs[0]));
-
- Folder f = catalog.folder(theArgs[1]).withItems().withItemModels().execute().waitForResult();
-
- debugLogger.log(LogLevel.DEBUG, ASDCCatalog.class.getName(), "folder: {}", f.data());
-
- Resources items = f.elements(ITEMS, Resources.class);
- if (items != null) {
- for (Resource item : items) {
- executeItemsNodePropertiesAssignments(catalog, item);
- }
- }
- }
-
- private static void executeItemsNodePropertiesAssignments(ASDCCatalog catalog, Resource item) throws Exception {
- debugLogger.log(LogLevel.DEBUG, ASDCCatalog.class.getName(), "\titem: {} : {}",item.name(), item.data());
- Templates templates = item.elements(MODELS, Templates.class);
- if (templates != null) {
- for (Template t : templates) {
- Template ft = catalog.template(t.id()).withNodes().withNodeProperties()
- .withNodePropertiesAssignments().execute().waitForResult();
-
- debugLogger.log(LogLevel.DEBUG, ASDCCatalog.class.getName(), "template data: {}", ft.data());
- }
- }
- }
-
}
diff --git a/dcaedt_catalog/api/src/test/java/org/onap/sdc/dcae/catalog/ASDCCatalogTest.java b/dcaedt_catalog/api/src/test/java/org/onap/sdc/dcae/catalog/ASDCCatalogTest.java
deleted file mode 100644
index 360b76d..0000000
--- a/dcaedt_catalog/api/src/test/java/org/onap/sdc/dcae/catalog/ASDCCatalogTest.java
+++ /dev/null
@@ -1,88 +0,0 @@
-package org.onap.sdc.dcae.catalog;
-
-import static org.assertj.core.api.Assertions.*;
-
-import java.net.URISyntaxException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.UUID;
-
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-import org.onap.sdc.dcae.catalog.asdc.ASDCCatalog;
-import org.onap.sdc.dcae.catalog.asdc.ASDCCatalog.CatalogFolderAction;
-import org.onap.sdc.dcae.catalog.asdc.ASDCCatalog.Resource;
-
-import static org.mockito.Mockito.*;
-
-
-public class ASDCCatalogTest {
-
- @Rule
- public ExpectedException thrown = ExpectedException.none();
-
- private static CatalogFolderAction getTarget() {
- ASDCCatalog catalog = mock(ASDCCatalog.class);
- when(catalog.folder("test")).thenCallRealMethod();
- CatalogFolderAction target = catalog.folder("test");
- return target;
- }
-
- @Test
- public void filterLatestVersion_null_throwIllegalArgumentException() {
- // arrange
- CatalogFolderAction target = getTarget();
- // assert
- thrown.expect(IllegalArgumentException.class);
- // act
- target.filterLatestVersion(null);
- }
-
- @Test
- public void filterLatestVersion_emptyItemsList_emptyItemsList() throws URISyntaxException {
- // arrange
- CatalogFolderAction target = getTarget();
- // act
- Collection<Resource> result = target.filterLatestVersion(new ArrayList<>());
- // assert
- assertThat(result).isEmpty();
- }
-
- @Test
- public void filterLatestVersion_itemWithTwoVersions_itemWithLatestVersion() {
- // arrange
- CatalogFolderAction target = getTarget();
-
- UUID invariantUUID = UUID.randomUUID();
- Resource r1v1 = mock(Resource.class);
- Resource r1v2 = mock(Resource.class);
- when(r1v1.invariantUUID()).thenReturn(invariantUUID);
- when(r1v2.invariantUUID()).thenReturn(invariantUUID);
- when(r1v1.version()).thenReturn("1.0");
- when(r1v2.version()).thenReturn("2.0");
- ArrayList<Resource> listItemWithTwoVersions = new ArrayList<Resource>(Arrays.asList(r1v1, r1v2));
- // act
- Collection<Resource> result = target.filterLatestVersion(listItemWithTwoVersions);
- // assert
- assertThat(result).containsExactly(r1v2);
- }
-
- @Test
- public void filterLatestVersion_2distinctItems_2distinctItems() {
- // arrange
- CatalogFolderAction target = getTarget();
-
- Resource r1 = mock(Resource.class);
- Resource r2 = mock(Resource.class);
- when(r1.invariantUUID()).thenReturn(UUID.randomUUID());
- when(r2.invariantUUID()).thenReturn(UUID.randomUUID());
- ArrayList<Resource> listOfTwoDistinctItems = new ArrayList<Resource>(Arrays.asList(r1, r2));
- // act
- Collection<Resource> result = target.filterLatestVersion(listOfTwoDistinctItems);
- // assert
- assertThat(result).containsExactlyInAnyOrder(r1, r2);
- }
-
-}
diff --git a/dcaedt_catalog/asdc/src/main/java/org/onap/sdc/dcae/catalog/asdc/ASDC.java b/dcaedt_catalog/asdc/src/main/java/org/onap/sdc/dcae/catalog/asdc/ASDC.java
deleted file mode 100644
index c704689..0000000
--- a/dcaedt_catalog/asdc/src/main/java/org/onap/sdc/dcae/catalog/asdc/ASDC.java
+++ /dev/null
@@ -1,288 +0,0 @@
-package org.onap.sdc.dcae.catalog.asdc;
-
-import org.apache.commons.codec.digest.DigestUtils;
-import org.json.JSONArray;
-import org.json.JSONObject;
-import org.onap.sdc.common.onaplog.Enums.LogLevel;
-import org.onap.sdc.common.onaplog.OnapLoggerDebug;
-import org.onap.sdc.common.onaplog.OnapLoggerError;
-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.JSONHttpMessageConverter;
-import org.springframework.context.annotation.Scope;
-import org.springframework.http.*;
-import org.springframework.http.client.AsyncClientHttpRequestExecution;
-import org.springframework.http.client.AsyncClientHttpRequestInterceptor;
-import org.springframework.http.client.ClientHttpResponse;
-import org.springframework.http.converter.HttpMessageConverter;
-import org.springframework.scheduling.annotation.Scheduled;
-import org.springframework.stereotype.Component;
-import org.springframework.util.Base64Utils;
-import org.springframework.util.concurrent.ListenableFuture;
-import org.springframework.util.concurrent.ListenableFutureCallback;
-import org.springframework.web.client.AsyncRestTemplate;
-import org.springframework.web.client.HttpClientErrorException;
-import org.springframework.web.client.RestClientException;
-
-import javax.annotation.PostConstruct;
-import java.io.IOException;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.util.Collections;
-import java.util.List;
-import java.util.Set;
-import java.util.UUID;
-
-@Component("asdc")
-@Scope("singleton")
-public class ASDC {
-
- public enum AssetType {
- resource,
- service,
- product
- }
-
- protected static OnapLoggerError errLogger = OnapLoggerError.getInstance();
- protected static OnapLoggerDebug debugLogger = OnapLoggerDebug.getInstance();
-
- private URI rootUri;
- private String rootPath = "/sdc/v1/catalog/";
- private String user, passwd;
- private String instanceId;
-
- public void setUri(URI theUri) {
- String userInfo = theUri.getUserInfo();
- if (userInfo != null) {
- String[] userInfoParts = userInfo.split(":");
- setUser(userInfoParts[0]);
- if (userInfoParts.length > 1) {
- setPassword(userInfoParts[1]);
- }
- }
- String fragment = theUri.getFragment();
- if (fragment == null) {
- throw new IllegalArgumentException("The URI must contain a fragment specification, to be used as ASDC instance id");
- }
- setInstanceId(fragment);
-
- try {
- this.rootUri = new URI(theUri.getScheme(), null, theUri.getHost(), theUri.getPort(), theUri.getPath(), theUri.getQuery(), null);
- }
- catch (URISyntaxException urix) {
- throw new IllegalArgumentException("Invalid uri", urix);
- }
- }
-
- public URI getUri() {
- return this.rootUri;
- }
-
- public void setUser(String theUser) {
- this.user = theUser;
- }
-
- public String getUser() {
- return this.user;
- }
-
- public void setPassword(String thePassword) {
- this.passwd = thePassword;
- }
-
- public String getPassword() {
- return this.passwd;
- }
-
- public void setInstanceId(String theId) {
- this.instanceId = theId;
- }
-
- @Scheduled(fixedRateString = "${beans.context.scripts.updateCheckFrequency?:60000}")
- public void checkForUpdates() {
- // ffu
- }
-
- @PostConstruct
- public void initASDC() {
- // ffu
- }
-
- public <T> Future<T> getResources(Class<T> theType) {
- return getAssets(AssetType.resource, theType);
- }
-
- public Future<JSONArray> getResources() {
- return getAssets(AssetType.resource, JSONArray.class);
- }
-
- public <T> Future<T> getResources(Class<T> theType, String theCategory, String theSubCategory) {
- return getAssets(AssetType.resource, theType, theCategory, theSubCategory);
- }
-
- public Future<JSONArray> getResources(String category, String subCategory, String resourceType) {
- return getAssets(AssetType.resource, JSONArray.class, category, subCategory, resourceType);
- }
-
- public <T> Future<T> getAssets(AssetType theAssetType, Class<T> theType) {
- return fetch(refAssets(theAssetType), theType);
- }
-
- public <T> Future<T> getAssets(AssetType theAssetType, Class<T> theType,
- String theCategory, String theSubCategory) {
- return getAssets(theAssetType, theType, theCategory, theSubCategory, null);
- }
-
- public <T> Future<T> getAssets(AssetType theAssetType, Class<T> theType,
- String theCategory, String theSubCategory, String theResourceType) {
- return fetch(refAssets(theAssetType) + filter(theCategory, theSubCategory, theResourceType), theType);
- }
-
- protected String refAssets(AssetType theAssetType) {
- return this.rootPath + theAssetType + "s/";
- }
-
- private String filter(String theCategory, String theSubCategory, String theResourceType) {
- StringBuilder filter = null;
- if (theCategory != null) {
- filter = new StringBuilder();
- filter.append("?category=")
- .append(theCategory);
- if (theSubCategory != null) {
- filter.append("&subCategory=")
- .append(theSubCategory);
- if (theResourceType != null) {
- filter.append("&resourceType=")
- .append(theResourceType);
- }
- }
- }
- return filter == null ? "" : filter.toString();
- }
-
- protected String refAsset(AssetType theAssetType, UUID theId) {
- return this.rootPath + theAssetType + "s/" + theId;
- }
-
- public <T> Future<T> getResource(UUID theId, Class<T> theType) {
- return getAsset(AssetType.resource, theId, theType);
- }
-
- public Future<JSONObject> getResource(UUID theId) {
- return getAsset(AssetType.resource, theId, JSONObject.class);
- }
-
- public <T> Future<T> getAsset(AssetType theAssetType, UUID theId, Class<T> theType) {
- return fetch(refAsset(theAssetType, theId) + "/metadata", theType);
- }
-
- public <T> Action<T> getAssetAction(AssetType theAssetType, UUID theId, Class<T> theType) {
- return () -> fetch(refAsset(theAssetType, theId) + "/metadata", theType);
- }
-
- public Future<byte[]> getAssetArchive(AssetType theAssetType, UUID theId) {
- return fetch(refAsset(theAssetType, theId) + "/toscaModel", byte[].class);
- }
-
- public Action<byte[]> getAssetArchiveAction(AssetType theAssetType, UUID theId) {
- return () -> fetch(refAsset(theAssetType, theId) + "/toscaModel", byte[].class);
- }
-
- protected String refAssetArtifact(AssetType theAssetType, UUID theAssetId, UUID theArtifactId) {
- return refAsset(theAssetType, theAssetId) + "/artifacts" + (theArtifactId == null ? "" : ("/" + theArtifactId));
- }
-
- public <T> Future<T> getResourceArtifact(UUID theAssetId, UUID theArtifactId, Class<T> theType) {
- return getAssetArtifact(AssetType.resource, theAssetId, theArtifactId, theType);
- }
-
- public <T> Future<T> getAssetArtifact(AssetType theAssetType, UUID theAssetId, UUID theArtifactId, Class<T> theType) {
- return fetch(refAssetArtifact(theAssetType, theAssetId, theArtifactId), theType);
- }
-
-
- public static JSONObject merge(JSONObject theOriginal, JSONObject thePatch) {
- for (String key: (Set<String>)thePatch.keySet()) {
- if (!theOriginal.has(key)) {
- theOriginal.put(key, thePatch.get(key));
- }
- }
- return theOriginal;
- }
-
- private HttpHeaders prepareHeaders() {
- HttpHeaders headers = new HttpHeaders();
- headers.add(HttpHeaders.AUTHORIZATION, "Basic " + Base64Utils.encodeToString((this.user + ":" + this.passwd).getBytes()));
- headers.add(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE);
- headers.add(HttpHeaders.ACCEPT, MediaType.APPLICATION_OCTET_STREAM_VALUE);
- headers.add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_UTF8_VALUE);
- headers.add("X-ECOMP-InstanceID", this.instanceId);
-
- return headers;
- }
-
- public <T> Future<T> fetch(String theRef, Class<T> theContentType) {
- return exchange(theRef, HttpMethod.GET, new HttpEntity(prepareHeaders()), theContentType);
- }
-
- public <T> Future<T> exchange(String theRef, HttpMethod theMethod, HttpEntity theRequest, Class<T> theResponseType) {
-
- AsyncRestTemplate restTemplate = new AsyncRestTemplate();
-
- List<HttpMessageConverter<?>> converters = restTemplate.getMessageConverters();
- converters.add(0, new JSONHttpMessageConverter());
- restTemplate.setMessageConverters(converters);
-
- restTemplate.setInterceptors(Collections.singletonList(new ContentMD5Interceptor()));
- ASDCFuture<T> result = new ASDCFuture<T>();
- String uri = this.rootUri + theRef;
- try {
- restTemplate
- .exchange(uri, theMethod, theRequest, theResponseType)
- .addCallback(result.callback);
- }
- catch (RestClientException rcx) {
- errLogger.log(LogLevel.WARN, this.getClass().getName(), "Failed to fetch {} {}", uri, rcx);
- return Futures.failedFuture(rcx);
- }
- catch (Exception x) {
- errLogger.log(LogLevel.WARN, this.getClass().getName(), "Failed to fetch {} {}", uri, x);
- return Futures.failedFuture(x);
- }
-
- return result;
- }
-
- public class ASDCFuture<T> extends Futures.BasicFuture<T> {
-
- ListenableFutureCallback<ResponseEntity<T>> callback = new ListenableFutureCallback<ResponseEntity<T>>() {
-
- public void onSuccess(ResponseEntity<T> theResult) {
- ASDCFuture.this.result(theResult.getBody());
- }
-
- public void onFailure(Throwable theError) {
- if (theError instanceof HttpClientErrorException) {
- ASDCFuture.this.cause(new ASDCException((HttpClientErrorException)theError));
- }
- else {
- ASDCFuture.this.cause(theError);
- }
- }
- };
- }
-
- public class ContentMD5Interceptor implements AsyncClientHttpRequestInterceptor {
- @Override
- public ListenableFuture<ClientHttpResponse> intercept(
- HttpRequest theRequest, byte[] theBody, AsyncClientHttpRequestExecution theExecution)
- throws IOException {
- if (HttpMethod.POST == theRequest.getMethod()) {
- HttpHeaders headers = theRequest.getHeaders();
- headers.add("Content-MD5", Base64Utils.encodeToString(DigestUtils.md5Hex(theBody).getBytes()));
- }
- return theExecution.executeAsync(theRequest, theBody);
- }
- }
-}
diff --git a/dcaedt_catalog/asdc/src/main/java/org/onap/sdc/dcae/catalog/asdc/ASDCEngine.java b/dcaedt_catalog/asdc/src/main/java/org/onap/sdc/dcae/catalog/asdc/ASDCEngine.java
deleted file mode 100644
index 73c7601..0000000
--- a/dcaedt_catalog/asdc/src/main/java/org/onap/sdc/dcae/catalog/asdc/ASDCEngine.java
+++ /dev/null
@@ -1,25 +0,0 @@
-package org.onap.sdc.dcae.catalog.asdc;
-
-import org.onap.sdc.dcae.composition.util.SystemProperties;
-import org.springframework.boot.SpringApplication;
-import org.springframework.boot.autoconfigure.SpringBootApplication;
-import org.springframework.context.annotation.Bean;
-
-@SpringBootApplication
-public class ASDCEngine {
-
- /**
- * Creates and returns a new instance of a {@link SystemProperties} class.
- *
- * @return New instance of {@link SystemProperties}.
- */
- @Bean
- public SystemProperties systemProperties() {
- return new SystemProperties();
- }
-
- public static void main(String[] args) {
- SpringApplication.run(ASDCEngine.class, args);
- }
-
-}
diff --git a/dcaedt_catalog/asdc/src/main/java/org/onap/sdc/dcae/catalog/asdc/ASDCUtils.java b/dcaedt_catalog/asdc/src/main/java/org/onap/sdc/dcae/catalog/asdc/ASDCUtils.java
deleted file mode 100644
index a3ea63d..0000000
--- a/dcaedt_catalog/asdc/src/main/java/org/onap/sdc/dcae/catalog/asdc/ASDCUtils.java
+++ /dev/null
@@ -1,188 +0,0 @@
-package org.onap.sdc.dcae.catalog.asdc;
-
-import org.apache.commons.jxpath.JXPathContext;
-import org.apache.commons.lang3.StringUtils;
-import org.json.JSONArray;
-import org.json.JSONObject;
-import org.onap.sdc.common.onaplog.Enums.LogLevel;
-import org.onap.sdc.common.onaplog.OnapLoggerDebug;
-import org.onap.sdc.common.onaplog.OnapLoggerError;
-import org.onap.sdc.dcae.catalog.commons.Actions;
-import org.onap.sdc.dcae.catalog.commons.Future;
-import org.onap.sdc.dcae.catalog.commons.Futures;
-import org.onap.sdc.dcae.catalog.commons.Recycler;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.context.properties.ConfigurationProperties;
-import org.springframework.context.annotation.Scope;
-import org.springframework.stereotype.Component;
-import org.springframework.util.Base64Utils;
-
-import java.io.*;
-import java.net.URI;
-import java.util.List;
-import java.util.Spliterators;
-import java.util.UUID;
-import java.util.function.BiFunction;
-import java.util.function.Function;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
-import java.util.stream.StreamSupport;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipInputStream;
-
-
-@Component("asdcutils")
-@Scope("singleton")
-@ConfigurationProperties(prefix="asdcutils")
-public class ASDCUtils {
-
- private static final String ARTIFACT_URL = "artifactURL";
- private static final String ARTIFACT_NAME = "artifactName";
- private static OnapLoggerError errLogger = OnapLoggerError.getInstance();
- private static OnapLoggerDebug debugLogger = OnapLoggerDebug.getInstance();
-
- @Autowired
- private ASDC asdc;
-
- @Autowired
- private Blueprinter blueprint;
-
- public ASDCUtils() {
- // Making sonar happy
- }
-
- public ASDCUtils(URI theASDCURI) {
- this(theASDCURI, null);
- }
-
- public ASDCUtils(URI theASDCURI, URI theBlueprinterURI) {
- this.asdc = new ASDC();
- this.asdc.setUri(theASDCURI);
- if (theBlueprinterURI != null) {
- this.blueprint = new Blueprinter();
- this.blueprint.setUri(theBlueprinterURI);
- }
- }
-
- public ASDCUtils(ASDC theASDC) {
- this(theASDC, null);
- }
-
- public ASDCUtils(ASDC theASDC, Blueprinter theBlueprinter) {
- this.asdc = theASDC;
- this.blueprint = theBlueprinter;
- }
-
-
- private static JSONObject lookupArtifactInfo(JSONArray theArtifacts, String theName) {
-
- for (int i = 0; theArtifacts != null && i < theArtifacts.length(); i++) {
- JSONObject artifactInfo = theArtifacts.getJSONObject(i);
- if (theName.equals(artifactInfo.getString(ARTIFACT_NAME))) {
- debugLogger.log(LogLevel.DEBUG, ASDCUtils.class.getName(), "Found artifact info {}", artifactInfo);
- return artifactInfo;
- }
- }
-
- return null;
- }
-
- private static byte[] extractArtifactData(InputStream theEntryStream) throws IOException {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- try {
- byte[] buff = new byte[4096];
- int cnt = 0;
- while ((cnt = theEntryStream.read(buff)) != -1) {
- baos.write(buff, 0, cnt);
- }
- } finally {
- baos.close();
- }
- return baos.toByteArray();
- }
-
-
- public Future<Future<String>> buildBlueprintViaToscaLab(Reader theCdump) {
- return processCdump(theCdump, (theTemplate, theArchives) -> {
- Blueprinter.BlueprintAction action = blueprint.generateBlueprint();
- processArtifacts(theArchives, (JSONObject theInfo, byte[] theData) -> new JSONObject().put(theInfo.getString(ARTIFACT_NAME).split("\\.")[0], Base64Utils.encodeToString(theData)),
- (Stream<JSONObject> theAssetArtifacts) -> theAssetArtifacts.reduce(new JSONObject(), ASDC::merge)).forEach(artifactInfo -> action.withModelInfo(artifactInfo));
-
- return action.withTemplateData(Recycler.toString(theTemplate).getBytes()).execute();
-
- });
- }
-
- /* The common process of recycling, retrieving all related artifacts and then doing 'something' */
- private <T> Future<T> processCdump(Reader theCdump, BiFunction<Object, List, T> theProcessor) {
-
- final Recycler recycler = new Recycler();
- Object template = null;
- try {
- template = recycler.recycle(theCdump);
-
- } catch (Exception x) {
- return Futures.failedFuture(x);
- }
-
- JXPathContext jxroot = JXPathContext.newContext(template);
- jxroot.setLenient(true);
-
- //based on the output of ASDCCatalog the node description will contain the UUID of the resource declaring it
- //the desc contains the full URI and the resource uuid is the 5th path element
- List uuids = (List) StreamSupport.stream(Spliterators.spliteratorUnknownSize(jxroot.iterate("topology_template/node_templates/*/description"), 16), false).distinct().filter(desc -> desc != null)
- .map(desc -> desc.toString().split("/")[5]).collect(Collectors.toList());
-
- //serialized fetch version
- final Actions.Sequence sequencer = new Actions.Sequence();
- uuids.stream().forEach(uuid -> {
- UUID rid = UUID.fromString((String) uuid);
- sequencer.add(this.asdc.getAssetArchiveAction(ASDC.AssetType.resource, rid));
- sequencer.add(this.asdc.getAssetAction(ASDC.AssetType.resource, rid, JSONObject.class));
- });
-
- final Object tmpl = template;
- return Futures.advance(sequencer.execute(), (List theArchives) -> theProcessor.apply(tmpl, theArchives));
- }
-
- private static <T> Stream<T> processArtifacts(List theArtifactData, BiFunction<JSONObject, byte[], T> theProcessor, Function<Stream<T>, T> theAggregator) {
-
- Stream.Builder<T> assetBuilder = Stream.builder();
-
- for (int i = 0; i < theArtifactData.size(); i = i + 2) { //cute old style loop
-
- JSONObject assetInfo = (JSONObject) theArtifactData.get(i + 1);
- byte[] assetData = (byte[]) theArtifactData.get(i + 0);
-
- JSONArray artifacts = assetInfo.optJSONArray("artifacts");
-
- Stream.Builder<T> artifactBuilder = Stream.builder();
-
- try (ZipInputStream zipper = new ZipInputStream(new ByteArrayInputStream(assetData))){
- //we process the artifacts in the order they are stored in the archive .. fugly
- processZipArtifacts(theProcessor, artifacts, artifactBuilder, zipper);
- } catch (IOException iox) {
- errLogger.log(LogLevel.ERROR, ASDC.class.getName(), "IOException: {}", iox);
- return null;
- }
-
- if (theAggregator != null) {
- assetBuilder.add(theAggregator.apply(artifactBuilder.build()));
- } else {
- artifactBuilder.build().forEach(entry -> assetBuilder.add(entry));
- }
- }
-
- return assetBuilder.build();
- }
-
- private static <T> void processZipArtifacts(BiFunction<JSONObject, byte[], T> theProcessor, JSONArray artifacts, Stream.Builder<T> artifactBuilder, ZipInputStream zipper) throws IOException {
- for (ZipEntry zipped = zipper.getNextEntry(); zipped != null; zipped = zipper.getNextEntry()) {
- JSONObject artifactInfo = lookupArtifactInfo(artifacts, StringUtils.substringAfterLast(zipped.getName(), "/"));
- if (artifactInfo != null) {
- artifactBuilder.add(theProcessor.apply(artifactInfo, extractArtifactData(zipper)));
- }
- zipper.closeEntry();
- }
- }
-}
diff --git a/dcaedt_catalog/asdc/src/main/java/org/onap/sdc/dcae/catalog/asdc/ASDCUtilsController.java b/dcaedt_catalog/asdc/src/main/java/org/onap/sdc/dcae/catalog/asdc/ASDCUtilsController.java
deleted file mode 100644
index 377e71b..0000000
--- a/dcaedt_catalog/asdc/src/main/java/org/onap/sdc/dcae/catalog/asdc/ASDCUtilsController.java
+++ /dev/null
@@ -1,36 +0,0 @@
-package org.onap.sdc.dcae.catalog.asdc;
-
-import org.onap.sdc.common.onaplog.Enums.LogLevel;
-import org.onap.sdc.common.onaplog.OnapLoggerDebug;
-import org.springframework.beans.BeansException;
-import org.springframework.boot.context.properties.ConfigurationProperties;
-import org.springframework.context.ApplicationContext;
-import org.springframework.context.ApplicationContextAware;
-import org.springframework.web.bind.annotation.RestController;
-
-import javax.annotation.PostConstruct;
-import javax.annotation.PreDestroy;
-
-
-@RestController
-@ConfigurationProperties(prefix="asdcUtilsController")
-public class ASDCUtilsController implements ApplicationContextAware {
-
- private OnapLoggerDebug debugLogger = OnapLoggerDebug.getInstance();
-
- public void setApplicationContext(ApplicationContext theCtx) throws BeansException {
- // no use for app context
- }
-
- @PostConstruct
- public void initController() {
- debugLogger.log(LogLevel.DEBUG, this.getClass().getName(),"initASDCUtilsController");
- debugLogger.log(LogLevel.DEBUG, this.getClass().getName(),"ASDCUtilsController started");
- }
-
- @PreDestroy
- public void cleanupController() {
- debugLogger.log(LogLevel.DEBUG, this.getClass().getName(),"cleanupASDCUtilsController");
- }
-
-}
diff --git a/dcaedt_catalog/asdc/src/main/java/org/onap/sdc/dcae/catalog/asdc/Blueprinter.java b/dcaedt_catalog/asdc/src/main/java/org/onap/sdc/dcae/catalog/asdc/Blueprinter.java
deleted file mode 100644
index 4e5349f..0000000
--- a/dcaedt_catalog/asdc/src/main/java/org/onap/sdc/dcae/catalog/asdc/Blueprinter.java
+++ /dev/null
@@ -1,65 +0,0 @@
-package org.onap.sdc.dcae.catalog.asdc;
-
-import java.net.URI;
-
-import java.util.Collections;
-
-import org.json.JSONObject;
-import org.onap.sdc.common.onaplog.OnapLoggerDebug;
-import org.onap.sdc.common.onaplog.Enums.LogLevel;
-import org.onap.sdc.dcae.catalog.commons.Action;
-import org.onap.sdc.dcae.catalog.commons.Future;
-import org.onap.sdc.dcae.catalog.commons.Http;
-
-import org.springframework.util.Base64Utils;
-
-import org.springframework.http.MediaType;
-import org.springframework.http.HttpHeaders;
-import org.springframework.http.HttpMethod;
-import org.springframework.http.HttpEntity;
-import org.springframework.stereotype.Component;
-import org.springframework.context.annotation.Scope;
-import org.springframework.boot.context.properties.ConfigurationProperties;
-
-@Component("blueprinter")
-@Scope("singleton")
-@ConfigurationProperties(prefix="blueprinter")
-public class Blueprinter {
- private URI serviceUri;
- private OnapLoggerDebug debugLogger = OnapLoggerDebug.getInstance();
-
- public void setUri(URI theUri) {
- this.serviceUri = theUri;
- }
-
- public BlueprintAction generateBlueprint() {
- return new BlueprintAction();
- }
-
- public class BlueprintAction implements Action<String> {
-
- private JSONObject body = new JSONObject();
-
- protected BlueprintAction() {
- }
-
- public BlueprintAction withModelInfo(JSONObject theModelInfo) {
- body.append("models", theModelInfo);
- return this;
- }
-
- public BlueprintAction withTemplateData(byte[] theData) {
- body.put("template", Base64Utils.encodeToString(theData));
- return this;
- }
-
- public Future<String> execute() {
-
- debugLogger.log(LogLevel.DEBUG, this.getClass().getName(), "Blueprinter::execute() | PAYLOAD to TOSCA_LAB={}", body.toString());
- HttpHeaders headers = new HttpHeaders();
- headers.setContentType(MediaType.APPLICATION_JSON);
- headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
- return Http.exchange(serviceUri.toString(), HttpMethod.POST, new HttpEntity<>(body.toString(), headers), String.class);
- }
- }
-}
diff --git a/dcaedt_catalog/asdc/src/main/java/org/onap/sdc/dcae/client/ISdcClient.java b/dcaedt_catalog/asdc/src/main/java/org/onap/sdc/dcae/client/ISdcClient.java
index c389d75..9623d4c 100644
--- a/dcaedt_catalog/asdc/src/main/java/org/onap/sdc/dcae/client/ISdcClient.java
+++ b/dcaedt_catalog/asdc/src/main/java/org/onap/sdc/dcae/client/ISdcClient.java
@@ -11,7 +11,9 @@ public interface ISdcClient {
ResourceDetailed getResource(String uuid, String requestId);
- ServiceDetailed getService(String uuid, String requestId);
+ byte[] getResourceToscaModel(String uuid, String requestId);
+
+ ServiceDetailed getService(String uuid, String requestId);
ServiceDetailed getAssetMetadata(String contextType, String uuid, String requestId);
diff --git a/dcaedt_catalog/asdc/src/main/java/org/onap/sdc/dcae/client/SdcRestClient.java b/dcaedt_catalog/asdc/src/main/java/org/onap/sdc/dcae/client/SdcRestClient.java
index b07126e..7b89465 100644
--- a/dcaedt_catalog/asdc/src/main/java/org/onap/sdc/dcae/client/SdcRestClient.java
+++ b/dcaedt_catalog/asdc/src/main/java/org/onap/sdc/dcae/client/SdcRestClient.java
@@ -52,6 +52,7 @@ public class SdcRestClient implements ISdcClient {
private static final String LIFECYCLE_STATE_PATH = "lifecycleState/{lifecycleOperation}";
private static final String METADATA_PATH = "metadata";
private static final String VERSION_PATH = "version";
+ private static final String CSAR_PATH = "toscaModel";
private static final String MONITORING_REFERENCES_PATH = "externalReferences/monitoring";
private static OnapLoggerDebug debugLogger = OnapLoggerDebug.getInstance();
@@ -93,6 +94,12 @@ public class SdcRestClient implements ISdcClient {
return getObject(url, requestId, ResourceDetailed.class);
}
+ public byte[] getResourceToscaModel(String uuid, String requestId) {
+ String url = buildRequestPath(AssetType.RESOURCE.getSdcContextPath(), uuid, CSAR_PATH);
+ debugLogger.log(LogLevel.DEBUG, this.getClass().getName(), "Get resource csar from SDC. URL={}", url);
+ return getObject(url, requestId, byte[].class);
+ }
+
public ServiceDetailed getService(String uuid, String requestId) {
return getAssetMetadata(AssetType.SERVICE.name(), uuid, requestId);
}
diff --git a/dcaedt_catalog/asdc/src/main/java/org/onap/sdc/dcae/utils/SdcRestClientUtils.java b/dcaedt_catalog/asdc/src/main/java/org/onap/sdc/dcae/utils/SdcRestClientUtils.java
index 33c2f49..1e5102e 100644
--- a/dcaedt_catalog/asdc/src/main/java/org/onap/sdc/dcae/utils/SdcRestClientUtils.java
+++ b/dcaedt_catalog/asdc/src/main/java/org/onap/sdc/dcae/utils/SdcRestClientUtils.java
@@ -72,7 +72,7 @@ public class SdcRestClientUtils {
return mapper.writeValueAsString(artifact);
}
- public static Artifact generateDeploymentArtifact(String description, String name, String type, String label, byte[] payload){
+ public static Artifact generateDeploymentArtifact(String description, String name, String type, String label, byte[] payload) {
Artifact artifact = new Artifact();
artifact.setDescription(description);
artifact.setArtifactName(name);
@@ -82,4 +82,12 @@ public class SdcRestClientUtils {
artifact.setPayloadData(Base64Utils.encodeToString(payload));
return artifact;
}
+
+ public static Artifact generateCatalogDcaeToscaArtifact(String name, String path, byte[] payload) {
+ Artifact artifact = new Artifact();
+ artifact.setArtifactName(name);
+ artifact.setArtifactURL(path);
+ artifact.setPayloadData(new String(payload));
+ return artifact;
+ }
}
diff --git a/dcaedt_catalog/asdc/src/test/java/org/onap/sdc/dcae/utils/SDCResponseErrorHandlerTest.java b/dcaedt_catalog/asdc/src/test/java/org/onap/sdc/dcae/utils/SDCResponseErrorHandlerTest.java
index 05eb4b1..15c4a8a 100644
--- a/dcaedt_catalog/asdc/src/test/java/org/onap/sdc/dcae/utils/SDCResponseErrorHandlerTest.java
+++ b/dcaedt_catalog/asdc/src/test/java/org/onap/sdc/dcae/utils/SDCResponseErrorHandlerTest.java
@@ -90,4 +90,4 @@ public class SDCResponseErrorHandlerTest {
Assert.assertFalse(result);
}
-}
+} \ No newline at end of file
diff --git a/dcaedt_catalog/commons/README b/dcaedt_catalog/commons/README
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/dcaedt_catalog/commons/README
diff --git a/dcaedt_catalog/commons/src/main/java/org/onap/sdc/dcae/catalog/commons/Action.java b/dcaedt_catalog/commons/src/main/java/org/onap/sdc/dcae/catalog/commons/Action.java
index 2c62412..6535fe5 100644
--- a/dcaedt_catalog/commons/src/main/java/org/onap/sdc/dcae/catalog/commons/Action.java
+++ b/dcaedt_catalog/commons/src/main/java/org/onap/sdc/dcae/catalog/commons/Action.java
@@ -4,6 +4,5 @@ package org.onap.sdc.dcae.catalog.commons;
*/
public interface Action<T> {
- public Future<T> execute();
-
+ Future<T> execute();
}
diff --git a/dcaedt_catalog/commons/src/main/java/org/onap/sdc/dcae/catalog/commons/Actions.java b/dcaedt_catalog/commons/src/main/java/org/onap/sdc/dcae/catalog/commons/Actions.java
deleted file mode 100644
index 132b0c0..0000000
--- a/dcaedt_catalog/commons/src/main/java/org/onap/sdc/dcae/catalog/commons/Actions.java
+++ /dev/null
@@ -1,201 +0,0 @@
-package org.onap.sdc.dcae.catalog.commons;
-
-import java.util.List;
-import java.util.LinkedList;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.concurrent.CountDownLatch;
-
-import org.onap.sdc.common.onaplog.OnapLoggerDebug;
-import org.onap.sdc.common.onaplog.OnapLoggerError;
-import org.onap.sdc.common.onaplog.Enums.LogLevel;
-import org.onap.sdc.dcae.catalog.commons.Action;
-import org.onap.sdc.dcae.catalog.commons.Future;
-import org.onap.sdc.dcae.catalog.commons.FutureHandler;
-import org.onap.sdc.dcae.catalog.commons.Futures;
-
-/**
- */
-public interface Actions {
-
- /** */
- public static interface CompoundAction<T> extends Action<List<T>> {
-
- public CompoundAction<T> addAction(Action<T> theAction);
-
- public List<Action<T>> actions();
-
- public Future<List<T>> execute();
- }
-
-
- public static class BasicCompoundAction<T> implements CompoundAction<T> {
-
- private LinkedList<Action<T>> actions = new LinkedList<Action<T>>();
-
-
-
- public CompoundAction<T> addAction(Action<T> theAction) {
- this.actions.add(theAction);
- return this;
- }
-
- public List<Action<T>> actions() {
- return this.actions;
- }
-
- public Future<List<T>> execute() {
- CompoundFuture<T> cf = new CompoundFuture<T>(this.actions.size());
- for (Action a: this.actions)
- cf.addFuture(a.execute());
- return cf;
- }
- }
-
-
- public static class CompoundFuture<T> extends Futures.BasicFuture<List<T>> {
-
- private static OnapLoggerError errLogger = OnapLoggerError.getInstance();
- private static OnapLoggerDebug debugLogger = OnapLoggerDebug.getInstance();
-
- private LinkedList<Future<T>> futures = new LinkedList<Future<T>>();
- private FutureHandler<T> hnd;
-
- CompoundFuture(int theActionCount) {
-
- hnd = new Futures.BasicHandler<T>(new CountDownLatch(theActionCount)) {
-
- private List<T> results = new ArrayList<T>(Collections.nCopies(theActionCount, null));
-
- protected void process(Future<T> theResult) {
- synchronized(CompoundFuture.this) {
- if (theResult.failed()) {
- CompoundFuture.this.cause(theResult.cause());
- //and stop processing of other results
- this.results = null;
- //??
- }
- else {
- if (this.results != null)
- this.results.set(futures.indexOf(theResult), theResult.result());
- debugLogger.log(LogLevel.DEBUG, this.getClass().getName(), "Got result for action {}. Count at {}", futures.indexOf(theResult), this.latch.getCount());
- }
- if (this.latch.getCount() == 1) {//this was the last result
- debugLogger.log(LogLevel.DEBUG, this.getClass().getName(), "Got all results: {}", this.results);
- CompoundFuture.this.result(this.results);
- }
- }
- }
- };
- }
-
- CompoundFuture<T> addFuture(Future<T> theFuture) {
- synchronized(this) {
- futures.add(theFuture);
- theFuture.setHandler(this.hnd);
- }
- return this;
- }
-
- }
-
-/*
- public static class CompoundFutureHandler<T> implements FutureHandler<T> {
-
- protected List<T> result = null;
- protected List<Throwable> error = null;
- protected CountDownLatch latch = null;
-
- CompoundFutureHandler(int theResultCount) {
- this(new CountDownLatch(theResultCount));
- }
-
- public void handle(Future<T> theResult) {
- if (this.latch != null) {
- this.latch.countDown();
- }
- }
-
- public T result()
- throws InterruptedException, RuntimeException {
- return result(true);
- }
-
- public BasicHandler<T> waitForCompletion() throws InterruptedException {
- this.latch.await();
- return this;
- }
-
- }
-*/
-
- public static class Sequence<T> implements Action<List<T>> {
-
- private static OnapLoggerError errLogger = OnapLoggerError.getInstance();
- private static OnapLoggerDebug debugLogger = OnapLoggerDebug.getInstance();
-
- private List<Action<T>> actions = new LinkedList<Action<T>>();
- private int current = 0;
- private SequenceFuture<T> future = new SequenceFuture<T>();
-
- public Sequence<T> add(Action<T> theAction) {
- if (this.current > 0)
- throw new IllegalStateException("In execution");
- this.actions.add(theAction);
- return this;
- }
-
- /* we allow 'early' access to the future so that a client can pass its reference while
- * it still builds the sequence, for example.
- */
- public Future<List<T>> future() {
- return this.future;
- }
-
- //need to add protection when for the 'no action' case
- public Future<List<T>> execute() {
- debugLogger.log(LogLevel.DEBUG, this.getClass().getName(), "Starting serialized execution of {}", actions);
- if (hasNext())
- next().execute().setHandler(future.hnd);
- return this.future;
- }
-
- protected boolean hasNext() {
- return this.current < actions.size();
- }
-
- protected Action next() {
- return actions.get(this.current++);
- }
-
- private class SequenceFuture<T> extends Futures.BasicFuture<List<T>> {
-
- private List<T> results = new LinkedList<T>();
- private FutureHandler<T> hnd = new Futures.BasicHandler<T>() {
-
- protected void process(Future<T> theResult) {
-
- if (theResult.failed()) {
- SequenceFuture.this.cause(theResult.cause());
- //and stop processing of other results
- }
- else {
- SequenceFuture.this.results.add(theResult.result());
- if (Sequence.this.hasNext()) {
- Sequence.this.next().execute().setHandler(this);
- }
- else {
- SequenceFuture.this.result(SequenceFuture.this.results);
- }
- }
- }
- };
-
-
- }
-
-
-
- }
-
-}
diff --git a/dcaedt_catalog/commons/src/main/java/org/onap/sdc/dcae/catalog/commons/Recycler.java b/dcaedt_catalog/commons/src/main/java/org/onap/sdc/dcae/catalog/commons/Recycler.java
index f6ea6ad..2711722 100644
--- a/dcaedt_catalog/commons/src/main/java/org/onap/sdc/dcae/catalog/commons/Recycler.java
+++ b/dcaedt_catalog/commons/src/main/java/org/onap/sdc/dcae/catalog/commons/Recycler.java
@@ -73,11 +73,11 @@ public class Recycler {
return this;
}
- public Object recycle(final Reader theSource) throws Exception {
+ public Map recycle(final Reader theSource) throws IOException {
return this.recycle(new ObjectMapper().readValue(theSource, (Class)HashMap.class));
}
- public Object recycle(final Object theDump) {
+ private Map recycle(final Object theDump) {
final JXPathContext jxroot = JXPathContext.newContext(theDump);
jxroot.setLenient(true);
diff --git a/dcaedt_catalog/db/src/main/java/org/onap/sdc/dcae/db/neo4j/Modeled.java b/dcaedt_catalog/db/src/main/java/org/onap/sdc/dcae/db/neo4j/Modeled.java
deleted file mode 100644
index 3a439b5..0000000
--- a/dcaedt_catalog/db/src/main/java/org/onap/sdc/dcae/db/neo4j/Modeled.java
+++ /dev/null
@@ -1 +0,0 @@
-//package org.onap.sdc.dcae.db.neo4j;
diff --git a/dcaedt_catalog/service/src/main/java/org/onap/sdc/dcae/catalog/engine/CatalogController.java b/dcaedt_catalog/service/src/main/java/org/onap/sdc/dcae/catalog/engine/CatalogController.java
index b42f8cf..b364087 100644
--- a/dcaedt_catalog/service/src/main/java/org/onap/sdc/dcae/catalog/engine/CatalogController.java
+++ b/dcaedt_catalog/service/src/main/java/org/onap/sdc/dcae/catalog/engine/CatalogController.java
@@ -18,27 +18,16 @@ under the License.
*/
package org.onap.sdc.dcae.catalog.engine;
-import org.json.JSONObject;
import org.onap.sdc.common.onaplog.Enums.LogLevel;
import org.onap.sdc.common.onaplog.OnapLoggerDebug;
-import org.onap.sdc.dcae.catalog.Catalog;
import org.onap.sdc.dcae.catalog.asdc.ASDCCatalog;
import org.onap.sdc.dcae.catalog.commons.Future;
import org.onap.sdc.dcae.catalog.commons.FutureHandler;
-import org.onap.sdc.dcae.composition.util.DcaeBeConstants;
-import org.onap.sdc.dcae.composition.util.SystemProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.async.DeferredResult;
-import javax.annotation.PostConstruct;
-import javax.annotation.PreDestroy;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.util.HashMap;
-import java.util.Map;
-
/**
* All requests body:
* {
@@ -94,73 +83,11 @@ public class CatalogController {
private static OnapLoggerDebug debugLogger = OnapLoggerDebug.getInstance();
-
@Autowired
- private SystemProperties systemProperties;
-
- private URI defaultCatalog;
- private static Map<URI, Catalog> catalogs = new HashMap<>();
-
-
- public void setDefaultCatalog(URI theUri) {
- debugLogger.log(LogLevel.DEBUG, this.getClass().getName(), "set default catalog at {}", theUri);
- this.defaultCatalog = theUri;
- }
-
- @PostConstruct
- public void initCatalog() {
- // Dump some info and construct our configuration objects
- debugLogger.log(LogLevel.DEBUG, this.getClass().getName(), "initCatalog");
-
- this.defaultCatalog = URI.create(systemProperties.getProperties().getProperty(DcaeBeConstants.Config.ASDC_CATALOG_URL));
- // Initialize default catalog connection
- debugLogger.log(LogLevel.DEBUG, this.getClass().getName(), "default catalog at {}", this.defaultCatalog);
- getCatalog(null);
-
- // Done
- debugLogger.log(LogLevel.DEBUG, this.getClass().getName(), "CatalogEngine started");
- }
-
- @PreDestroy
- public void cleanupCatalog() {
- debugLogger.log(LogLevel.DEBUG, this.getClass().getName(), "destroyCatalog");
- }
-
- public Catalog getCatalog(URI theCatalogUri) {
- //TODO: Thread safety! Check catalog is alive!
- if (theCatalogUri == null) {
- theCatalogUri = this.defaultCatalog;
- }
-
- Catalog cat = catalogs.get(theCatalogUri);
- if (cat == null && theCatalogUri != null) {
- String scheme = theCatalogUri.getScheme();
- URI catalogUri;
- try {
- catalogUri = new URI(theCatalogUri.getSchemeSpecificPart() + "#" + theCatalogUri.getFragment());
- }
- catch (URISyntaxException urisx) {
- throw new IllegalArgumentException("Invalid catalog reference '" + theCatalogUri.getSchemeSpecificPart() + "'");
- }
- debugLogger.log(LogLevel.DEBUG, this.getClass().getName(), "Build catalog for {}", catalogUri);
-
- if ("asdc".equals(scheme)) {
- cat = new ASDCCatalog(catalogUri);
- }
- else {
- return null;
- }
-
- catalogs.put(theCatalogUri, cat);
- }
- return cat;
- }
+ private ASDCCatalog catalog;
- public JSONObject patchData(Catalog theCat, JSONObject theData) {
- theData.put("catalog", theCat.getUri());
- theData.put("catalogId", theData.optLong("id"));
- theData.put("id", theData.optLong("itemId"));
- return theData;
+ public ASDCCatalog getCatalog() {
+ return catalog;
}
public abstract class CatalogHandler<T> implements FutureHandler<T> {
diff --git a/dcaedt_catalog/service/src/main/java/org/onap/sdc/dcae/catalog/engine/CatalogEngine.java b/dcaedt_catalog/service/src/main/java/org/onap/sdc/dcae/catalog/engine/CatalogEngine.java
index 042798f..98db815 100644
--- a/dcaedt_catalog/service/src/main/java/org/onap/sdc/dcae/catalog/engine/CatalogEngine.java
+++ b/dcaedt_catalog/service/src/main/java/org/onap/sdc/dcae/catalog/engine/CatalogEngine.java
@@ -1,21 +1,11 @@
package org.onap.sdc.dcae.catalog.engine;
-import org.onap.sdc.dcae.catalog.engine.CatalogEngine;
import org.springframework.boot.SpringApplication;
-import org.springframework.context.ApplicationContext;
-import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
-import org.springframework.context.annotation.ComponentScan;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.context.annotation.ImportResource;
import org.springframework.boot.autoconfigure.SpringBootApplication;
-
-
-import java.util.Arrays;
-
-
+import org.springframework.context.annotation.ComponentScan;
@SpringBootApplication
-
+@ComponentScan("org.onap.sdc.dcae")
public class CatalogEngine {
public static void main(String[] args) {