From 86457ed120fc236b1485ad3251589aedad2401bd Mon Sep 17 00:00:00 2001 From: "Eran (ev672n), Vosk" Date: Mon, 6 Aug 2018 17:02:39 +0300 Subject: 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 --- .../org/onap/sdc/dcae/catalog/commons/Action.java | 3 +- .../org/onap/sdc/dcae/catalog/commons/Actions.java | 201 --------------------- .../onap/sdc/dcae/catalog/commons/Recycler.java | 4 +- 3 files changed, 3 insertions(+), 205 deletions(-) delete mode 100644 dcaedt_catalog/commons/src/main/java/org/onap/sdc/dcae/catalog/commons/Actions.java (limited to 'dcaedt_catalog/commons/src/main/java/org') 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 { - public Future execute(); - + Future 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 extends Action> { - - public CompoundAction addAction(Action theAction); - - public List> actions(); - - public Future> execute(); - } - - - public static class BasicCompoundAction implements CompoundAction { - - private LinkedList> actions = new LinkedList>(); - - - - public CompoundAction addAction(Action theAction) { - this.actions.add(theAction); - return this; - } - - public List> actions() { - return this.actions; - } - - public Future> execute() { - CompoundFuture cf = new CompoundFuture(this.actions.size()); - for (Action a: this.actions) - cf.addFuture(a.execute()); - return cf; - } - } - - - public static class CompoundFuture extends Futures.BasicFuture> { - - private static OnapLoggerError errLogger = OnapLoggerError.getInstance(); - private static OnapLoggerDebug debugLogger = OnapLoggerDebug.getInstance(); - - private LinkedList> futures = new LinkedList>(); - private FutureHandler hnd; - - CompoundFuture(int theActionCount) { - - hnd = new Futures.BasicHandler(new CountDownLatch(theActionCount)) { - - private List results = new ArrayList(Collections.nCopies(theActionCount, null)); - - protected void process(Future 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 addFuture(Future theFuture) { - synchronized(this) { - futures.add(theFuture); - theFuture.setHandler(this.hnd); - } - return this; - } - - } - -/* - public static class CompoundFutureHandler implements FutureHandler { - - protected List result = null; - protected List error = null; - protected CountDownLatch latch = null; - - CompoundFutureHandler(int theResultCount) { - this(new CountDownLatch(theResultCount)); - } - - public void handle(Future theResult) { - if (this.latch != null) { - this.latch.countDown(); - } - } - - public T result() - throws InterruptedException, RuntimeException { - return result(true); - } - - public BasicHandler waitForCompletion() throws InterruptedException { - this.latch.await(); - return this; - } - - } -*/ - - public static class Sequence implements Action> { - - private static OnapLoggerError errLogger = OnapLoggerError.getInstance(); - private static OnapLoggerDebug debugLogger = OnapLoggerDebug.getInstance(); - - private List> actions = new LinkedList>(); - private int current = 0; - private SequenceFuture future = new SequenceFuture(); - - public Sequence add(Action 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> future() { - return this.future; - } - - //need to add protection when for the 'no action' case - public Future> 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 extends Futures.BasicFuture> { - - private List results = new LinkedList(); - private FutureHandler hnd = new Futures.BasicHandler() { - - protected void process(Future 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); -- cgit 1.2.3-korg