Define interface to minizinc engine 83/83883/2
authorJerry Flood <jflood@att.com>
Mon, 1 Apr 2019 17:27:05 +0000 (13:27 -0400)
committerJerry Flood <jflood@att.com>
Mon, 1 Apr 2019 18:24:29 +0000 (14:24 -0400)
Issue-ID: OPTFRA-436
Change-Id: Icf450f06d37f6035a620b3f22a5c186f4923d63c
Signed-off-by: Jerry Flood <jflood@att.com>
17 files changed:
cmso-optimizer/pom.xml
cmso-optimizer/src/main/docker/assembly/cmso-files.xml
cmso-optimizer/src/main/java/org/onap/observations/Mdc.java
cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/availability/timewindows/RecurringWindows.java
cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/clients/optimizer/models/ElementSlot.java [new file with mode: 0644]
cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/clients/optimizer/models/OptimizerOutResults.java [new file with mode: 0644]
cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/clients/optimizer/models/OptimizerOutSchedule.java [new file with mode: 0644]
cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/clients/optimizer/models/OptimizerOutYaml.java [new file with mode: 0644]
cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/clients/optimizer/models/OptimizerParameters.java [new file with mode: 0644]
cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/clients/optimizer/models/OptimizerResponseUtility.java [new file with mode: 0644]
cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/clients/optimizer/models/OptimizerSchedule.java [new file with mode: 0644]
cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/clients/optimizer/models/Results.java [new file with mode: 0644]
cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/clients/ticketmgt/TicketMgtRequestManager.java
cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/service/rs/models/ChangeWindow.java
cmso-optimizer/src/test/data/resultsTest001.yaml [new file with mode: 0644]
cmso-optimizer/src/test/java/org/onap/optf/cmso/optimizer/clients/optimizer/models/ResultsTest.java [new file with mode: 0644]
cmso-optimizer/src/test/java/org/onap/optf/cmso/optimizer/service/rs/models/ChangeWindowTest.java [new file with mode: 0644]

index 8db7eb2..b609de5 100644 (file)
 
                        </exclusions>
                </dependency>
+               <dependency>
+                       <groupId>org.yaml</groupId>
+                       <artifactId>snakeyaml</artifactId>
+               </dependency>
+
                <!-- <dependency> <groupId>org.onap.aaf.authz</groupId> <artifactId>aaf-cadi-aaf</artifactId> 
                        <version>2.1.1</version> </dependency> -->
                <dependency>
index 37804ec..2e3f19e 100644 (file)
@@ -1,5 +1,4 @@
 <!-- ============LICENSE_START======================================================= 
-       ECOMP CMSO ================================================================================ 
        Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. ================================================================================ 
        Licensed under the Apache License, Version 2.0 (the "License"); you may not 
        use this file except in compliance with the License. You may obtain a copy 
index 0686f59..5dea5aa 100644 (file)
@@ -53,7 +53,7 @@ import org.onap.observations.MessageHeaders.HeadersEnum;
 import org.slf4j.MDC;
 
 /**
- * ECOMP EELF logging MDC fields not defined in the MDC Configuration (i.e. MDC_ALERT_SEVERITY)
+ * EELF logging MDC fields not defined in the MDC Configuration (i.e. MDC_ALERT_SEVERITY)
  **/
 public class Mdc {
 
index dce64b4..84fc039 100644 (file)
@@ -32,7 +32,6 @@ import java.time.ZoneOffset;
 import java.time.ZonedDateTime;
 import java.time.temporal.ChronoUnit;
 import java.util.ArrayList;
-import java.util.Date;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
diff --git a/cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/clients/optimizer/models/ElementSlot.java b/cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/clients/optimizer/models/ElementSlot.java
new file mode 100644 (file)
index 0000000..eb90a44
--- /dev/null
@@ -0,0 +1,98 @@
+/*
+ *  ============LICENSE_START==============================================
+ *  Copyright (c) 2019 AT&T Intellectual Property.
+ *  =======================================================================
+ *  Licensed under the Apache License, Version 2.0 (the "License"); you may
+ *  not use this file except in compliance with the License. You may obtain a
+ *  copy of the License at
+ *
+ *         http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing
+ * permissions and limitations under the License.
+ * ============LICENSE_END=================================================
+ */
+
+package org.onap.optf.cmso.optimizer.clients.optimizer.models;
+
+/**
+ * The Class ElementSlot.
+ */
+/*
+     1,0,1
+     2,0,1
+     3,0,1
+     4,0,1
+     5,0,1
+ */
+public class ElementSlot {
+    private Long elementIndex = 0L;
+    private Long slot = 0L;
+    private Long loader = 0L;
+
+
+    public Long getElementIndex() {
+        return elementIndex;
+    }
+
+    public void setElementIndex(Long elementIndex) {
+        this.elementIndex = elementIndex;
+    }
+
+    /**
+     * Gets the slot.
+     *
+     * @return the slot
+     */
+    public Long getSlot() {
+        return slot;
+    }
+
+    /**
+     * Sets the slot.
+     *
+     * @param slot the new slot
+     */
+    public void setSlot(Long slot) {
+        this.slot = slot;
+    }
+
+    /**
+     * Gets the loader.
+     *
+     * @return the loader
+     */
+    public Long getLoader() {
+        return loader;
+    }
+
+    /**
+     * Sets the loader.
+     *
+     * @param loader the new loader
+     */
+    public void setLoader(Long loader) {
+        this.loader = loader;
+    }
+
+    /**
+     * Instantiates a new element slot.
+     *
+     * @param cols the values
+     */
+    public ElementSlot(String[] cols) {
+        if (cols.length > 0) {
+            elementIndex = Long.valueOf(cols[0]);
+        }
+        if (cols.length > 1) {
+            slot = Long.valueOf(cols[1]);
+        }
+        if (cols.length > 2) {
+            loader = Long.valueOf(cols[2]);
+        }
+    }
+}
+
diff --git a/cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/clients/optimizer/models/OptimizerOutResults.java b/cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/clients/optimizer/models/OptimizerOutResults.java
new file mode 100644 (file)
index 0000000..2c1c777
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ *  ============LICENSE_START==============================================
+ *  Copyright (c) 2019 AT&T Intellectual Property.
+ *  =======================================================================
+ *  Licensed under the Apache License, Version 2.0 (the "License"); you may
+ *  not use this file except in compliance with the License. You may obtain a
+ *  copy of the License at
+ *
+ *         http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing
+ * permissions and limitations under the License.
+ * ============LICENSE_END=================================================
+ */
+
+package org.onap.optf.cmso.optimizer.clients.optimizer.models;
+
+import java.util.List;
+
+/*
+
+ */
+public class OptimizerOutResults {
+    private Long elapsedMillis;
+    private List<OptimizerOutSchedule> results;
+
+    public Long getElapsedMillis() {
+        return elapsedMillis;
+    }
+
+    public void setElapsedMillis(Long elapsed_millis) {
+        this.elapsedMillis = elapsed_millis;
+    }
+
+    public List<OptimizerOutSchedule> getResults() {
+        return results;
+    }
+
+    public void setResults(List<OptimizerOutSchedule> schedules) {
+        this.results = schedules;
+    }
+
+}
diff --git a/cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/clients/optimizer/models/OptimizerOutSchedule.java b/cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/clients/optimizer/models/OptimizerOutSchedule.java
new file mode 100644 (file)
index 0000000..abcebf2
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ *  ============LICENSE_START==============================================
+ *  Copyright (c) 2019 AT&T Intellectual Property.
+ *  =======================================================================
+ *  Licensed under the Apache License, Version 2.0 (the "License"); you may
+ *  not use this file except in compliance with the License. You may obtain a
+ *  copy of the License at
+ *
+ *         http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing
+ * permissions and limitations under the License.
+ * ============LICENSE_END=================================================
+ */
+
+package org.onap.optf.cmso.optimizer.clients.optimizer.models;
+
+/*
+num_scheduled: 0
+total_completion_time: 0
+element_slot_loader: |
+  1,0,1
+  2,0,1
+  3,0,1
+  4,0,1
+  5,0,1
+ */
+public class OptimizerOutSchedule {
+    private Long numScheduled;
+    private Long totalCompletionTime;
+    private String elementSlotLoader;
+
+    public Long getNumScheduled() {
+        return numScheduled;
+    }
+
+    public void setNumScheduled(Long numScheduled) {
+        this.numScheduled = numScheduled;
+    }
+
+    public Long getTotalCompletionTime() {
+        return totalCompletionTime;
+    }
+
+    public void setTotalCompletionTime(Long totalCompletionTime) {
+        this.totalCompletionTime = totalCompletionTime;
+    }
+
+    public String getElementSlotLoader() {
+        return elementSlotLoader;
+    }
+
+    public void setElementSlotLoader(String elementSlotLoader) {
+        this.elementSlotLoader = elementSlotLoader;
+    }
+}
+
diff --git a/cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/clients/optimizer/models/OptimizerOutYaml.java b/cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/clients/optimizer/models/OptimizerOutYaml.java
new file mode 100644 (file)
index 0000000..c9c16cb
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+ *  ============LICENSE_START==============================================
+ *  Copyright (c) 2019 AT&T Intellectual Property.
+ *  =======================================================================
+ *  Licensed under the Apache License, Version 2.0 (the "License"); you may
+ *  not use this file except in compliance with the License. You may obtain a
+ *  copy of the License at
+ *
+ *         http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing
+ * permissions and limitations under the License.
+ * ============LICENSE_END=================================================
+ */
+
+package org.onap.optf.cmso.optimizer.clients.optimizer.models;
+
+/*
+results:
+ result:
+   num_scheduled: 0
+   total_completion_time: 0
+   element_slot_loader: |
+     1,0,1
+     2,0,1
+     3,0,1
+     4,0,1
+     5,0,1
+ result:
+   num_scheduled: 1
+   total_completion_time: 2
+   element_slot_loader: |
+     1,0,1
+     2,0,1
+     3,2,1
+     4,0,1
+     5,0,1
+ result:
+   num_scheduled: 4
+   total_completion_time: 8
+   element_slot_loader: |
+     1,2,1
+     2,1,1
+     3,2,1
+     4,0,1
+     5,3,1
+ elapsed_millis: 3400
+
+ */
+public class OptimizerOutYaml {
+
+    private OptimizerOutResults results;
+
+    public OptimizerOutResults getResults() {
+        return results;
+    }
+
+    public void setResults(OptimizerOutResults results) {
+        this.results = results;
+    }
+
+}
diff --git a/cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/clients/optimizer/models/OptimizerParameters.java b/cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/clients/optimizer/models/OptimizerParameters.java
new file mode 100644 (file)
index 0000000..0ab187b
--- /dev/null
@@ -0,0 +1,206 @@
+/*
+ *  ============LICENSE_START==============================================
+ *  Copyright (c) 2019 AT&T Intellectual Property.
+ *  =======================================================================
+ *  Licensed under the Apache License, Version 2.0 (the "License"); you may
+ *  not use this file except in compliance with the License. You may obtain a
+ *  copy of the License at
+ *
+ *         http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing
+ * permissions and limitations under the License.
+ * ============LICENSE_END=================================================
+ */
+
+package org.onap.optf.cmso.optimizer.clients.optimizer.models;
+
+import java.util.ArrayList;
+import java.util.List;
+
+
+/*
+ * numElements = 5;
+maxTime = 5;
+numLoaders = 1;
+noConflict = [| true , true , true , true , true
+ | true , true , true , true , true
+ | false , true , false , true , false
+ | false , false , false , false , false
+ | true , false , true , false , true
+ |];
+slotCapacity = [5, 5, 5, 5, 5];
+loaderCapacity = [|
+5, 5, 5, 5, 5
+|];
+
+
+numAttributes = 0;
+attributesRange = [];
+attributes = [];
+attributeConcurrencyLimit = [];
+ */
+public class OptimizerParameters {
+    private Long numElements;
+    private Long maxTime;
+    private Long numLoaders;
+    private List<List<Boolean>> noConflict = new ArrayList<>();
+    private List<Long> slotCapacity = new ArrayList<>();
+    private List<List<Long>> loaderCapacity = new ArrayList<>();
+
+    private Long numAttributes;
+    private List<Long> attributesRange = new ArrayList<>();
+    private List<List<Long>> attributes = new ArrayList<>();
+    private List<List<Long>> attributeConcurrencyLimit = new ArrayList<>();
+
+    public Long getNumElements() {
+        return numElements;
+    }
+
+    public void setNumElements(Long numElements) {
+        this.numElements = numElements;
+    }
+
+    public Long getMaxTime() {
+        return maxTime;
+    }
+
+    public void setMaxTime(Long maxTime) {
+        this.maxTime = maxTime;
+    }
+
+    public Long getNumLoaders() {
+        return numLoaders;
+    }
+
+    public void setNumLoaders(Long numLoaders) {
+        this.numLoaders = numLoaders;
+    }
+
+    public List<List<Boolean>> getNoConflict() {
+        return noConflict;
+    }
+
+    public void setNoConflict(List<List<Boolean>> noConflict) {
+        this.noConflict = noConflict;
+    }
+
+    public List<Long> getSlotCapacity() {
+        return slotCapacity;
+    }
+
+    public void setSlotCapacity(List<Long> slotCapacity) {
+        this.slotCapacity = slotCapacity;
+    }
+
+    public List<List<Long>> getLoaderCapacity() {
+        return loaderCapacity;
+    }
+
+    public void setLoaderCapacity(List<List<Long>> loaderCapacity) {
+        this.loaderCapacity = loaderCapacity;
+    }
+
+    public Long getNumAttributes() {
+        return numAttributes;
+    }
+
+    public void setNumAttributes(Long numAttributes) {
+        this.numAttributes = numAttributes;
+    }
+
+    public List<Long> getAttributesRange() {
+        return attributesRange;
+    }
+
+    public void setAttributesRange(List<Long> attributesRange) {
+        this.attributesRange = attributesRange;
+    }
+
+    public List<List<Long>> getAttributes() {
+        return attributes;
+    }
+
+    public void setAttributes(List<List<Long>> attributes) {
+        this.attributes = attributes;
+    }
+
+    public List<List<Long>> getAttributeConcurrencyLimit() {
+        return attributeConcurrencyLimit;
+    }
+
+    public void setAttributeConcurrencyLimit(List<List<Long>> attributeConcurrencyLimit) {
+        this.attributeConcurrencyLimit = attributeConcurrencyLimit;
+    }
+
+
+
+    public String toMiniZinc() {
+        StringBuilder sb = new StringBuilder();
+        appendAttribute(sb, "numElements", numElements.toString());
+        appendAttribute(sb, "maxTime", maxTime.toString());
+        appendAttribute(sb, "numLoaders", numLoaders.toString());
+        appendAttribute(sb, "numAttributes", numAttributes.toString());
+        appendAttribute(sb, "noConflict", "[|\n" + formatBooleanRows(noConflict) + "|]");
+        appendAttribute(sb, "slotCapacity", "[" + formatLongList(slotCapacity) + "]");
+        appendAttribute(sb, "loaderCapacity", "[|\n" + formatLongRows(loaderCapacity) + "|]");
+        appendAttribute(sb, "attributesRange", "[" + formatLongList(attributesRange) + "]");
+        appendAttribute(sb, "attributes", "[|\n" + formatLongRows(attributes) + "|]");
+        appendAttribute(sb, "attributeConcurrencyLimit", "[|\n" + formatLongRows(attributeConcurrencyLimit) + "|]");
+        return sb.toString();
+    }
+
+    private void appendAttribute(StringBuilder sb, String name, String value) {
+        sb.append(name).append(" = ").append(value).append(";\n");
+    }
+
+    // Methods to dump minizinc parameters. THese may be very large
+    //
+    private String formatBooleanRows(List<List<Boolean>> list) {
+        StringBuilder sb = new StringBuilder();
+        String row = "";
+        for (List<Boolean> objectList : list) {
+            sb.append(row).append(formatBooleanList(objectList));
+            row = "| ";
+        }
+        sb.append("\n");
+        return sb.toString();
+    }
+
+    private String formatBooleanList(List<Boolean> list) {
+        StringBuilder sb = new StringBuilder();
+        String comma = "";
+        for (Object object : list) {
+            sb.append(comma).append(object.toString());
+            comma = ", ";
+        }
+        return sb.toString();
+    }
+
+    private String formatLongRows(List<List<Long>> list) {
+        StringBuilder sb = new StringBuilder();
+        String row = "";
+        for (List<Long> objectList : list) {
+            sb.append(row).append(formatLongList(objectList));
+            row = "| ";
+        }
+        sb.append("\n");
+        return sb.toString();
+    }
+
+    private String formatLongList(List<Long> list) {
+        StringBuilder sb = new StringBuilder();
+        String comma = "";
+        for (Object object : list) {
+            sb.append(comma).append(object.toString());
+            comma = ", ";
+        }
+        return sb.toString();
+    }
+
+}
+
+
diff --git a/cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/clients/optimizer/models/OptimizerResponseUtility.java b/cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/clients/optimizer/models/OptimizerResponseUtility.java
new file mode 100644 (file)
index 0000000..aefaba8
--- /dev/null
@@ -0,0 +1,81 @@
+/*
+ *  ============LICENSE_START==============================================
+ *  Copyright (c) 2019 AT&T Intellectual Property.
+ *  =======================================================================
+ *  Licensed under the Apache License, Version 2.0 (the "License"); you may
+ *  not use this file except in compliance with the License. You may obtain a
+ *  copy of the License at
+ *
+ *         http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing
+ * permissions and limitations under the License.
+ * ============LICENSE_END=================================================
+ */
+
+package org.onap.optf.cmso.optimizer.clients.optimizer.models;
+
+import com.google.common.base.CaseFormat;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+import org.onap.observations.Observation;
+import org.onap.optf.cmso.optimizer.common.LogMessages;
+import org.yaml.snakeyaml.Yaml;
+import org.yaml.snakeyaml.constructor.Constructor;
+import org.yaml.snakeyaml.introspector.Property;
+import org.yaml.snakeyaml.introspector.PropertyUtils;
+
+public class OptimizerResponseUtility extends PropertyUtils {
+    public Results parseOptimizerResult(File resultsFile) {
+        Results results = null;
+        try (InputStream input = new FileInputStream(resultsFile)) {
+            Constructor constructor = new Constructor(OptimizerOutResults.class);
+            constructor.setPropertyUtils(this);
+            Yaml yaml = new Yaml(constructor);
+            OptimizerOutResults optimizerOut = yaml.load(input);
+            results = marshall(optimizerOut);
+        } catch (Exception e) {
+            Observation.report(LogMessages.UNEXPECTED_EXCEPTION, e, e.getMessage());
+        }
+        return results;
+    }
+
+    private Results marshall(OptimizerOutResults optimizerOut) {
+        Results results = new Results();
+        results.setElapsedMillis(optimizerOut.getElapsedMillis());
+        List<OptimizerSchedule> schedules = new ArrayList<>();
+        results.setSchedules(schedules);
+        for (OptimizerOutSchedule sch : optimizerOut.getResults()) {
+            schedules.add(marshall(sch));
+        }
+        return results;
+    }
+
+    private OptimizerSchedule marshall(OptimizerOutSchedule sch) {
+        OptimizerSchedule optimizerSchedule = new OptimizerSchedule();
+        optimizerSchedule.setNumScheduled(sch.getNumScheduled());
+        optimizerSchedule.setTotalCompletionTime(sch.getTotalCompletionTime());
+        String[] rows = sch.getElementSlotLoader().split("\n");
+        List<ElementSlot> slots = new ArrayList<>();
+        optimizerSchedule.setElementSlotLoader(slots);
+        for (String row : rows) {
+            String[] cols = row.split(",");
+            ElementSlot slot = new ElementSlot(cols);
+            slots.add(slot);
+        }
+        return optimizerSchedule;
+    }
+
+    @Override
+    public Property getProperty(Class<? extends Object> type, String name) {
+        name = CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, name);
+        return super.getProperty(type, name);
+    }
+
+}
diff --git a/cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/clients/optimizer/models/OptimizerSchedule.java b/cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/clients/optimizer/models/OptimizerSchedule.java
new file mode 100644 (file)
index 0000000..d4bc008
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ *  ============LICENSE_START==============================================
+ *  Copyright (c) 2019 AT&T Intellectual Property.
+ *  =======================================================================
+ *  Licensed under the Apache License, Version 2.0 (the "License"); you may
+ *  not use this file except in compliance with the License. You may obtain a
+ *  copy of the License at
+ *
+ *         http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing
+ * permissions and limitations under the License.
+ * ============LICENSE_END=================================================
+ */
+
+package org.onap.optf.cmso.optimizer.clients.optimizer.models;
+
+import java.util.List;
+
+/*
+num_scheduled: 0
+total_completion_time: 0
+element_slot_loader: |
+  1,0,1
+  2,0,1
+  3,0,1
+  4,0,1
+  5,0,1
+ */
+public class OptimizerSchedule {
+    private Long numScheduled;
+    private Long totalCompletionTime;
+    private List<ElementSlot> elementSlotLoader;
+
+    public Long getNumScheduled() {
+        return numScheduled;
+    }
+
+    public void setNumScheduled(Long numScheduled) {
+        this.numScheduled = numScheduled;
+    }
+
+    public Long getTotalCompletionTime() {
+        return totalCompletionTime;
+    }
+
+    public void setTotalCompletionTime(Long totalCompletionTime) {
+        this.totalCompletionTime = totalCompletionTime;
+    }
+
+    public List<ElementSlot> getElementSlotLoader() {
+        return elementSlotLoader;
+    }
+
+    public void setElementSlotLoader(List<ElementSlot> elementSlotLoader) {
+        this.elementSlotLoader = elementSlotLoader;
+    }
+
+}
+
diff --git a/cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/clients/optimizer/models/Results.java b/cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/clients/optimizer/models/Results.java
new file mode 100644 (file)
index 0000000..402bdf2
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ *  ============LICENSE_START==============================================
+ *  Copyright (c) 2019 AT&T Intellectual Property.
+ *  =======================================================================
+ *  Licensed under the Apache License, Version 2.0 (the "License"); you may
+ *  not use this file except in compliance with the License. You may obtain a
+ *  copy of the License at
+ *
+ *         http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing
+ * permissions and limitations under the License.
+ * ============LICENSE_END=================================================
+ */
+
+package org.onap.optf.cmso.optimizer.clients.optimizer.models;
+
+import java.util.List;
+
+/*
+
+ */
+public class Results {
+    private Long elapsedMillis;
+    private List<OptimizerSchedule> schedules;
+
+    public Long getElapsedMillis() {
+        return elapsedMillis;
+    }
+
+    public void setElapsedMillis(Long elapsed_millis) {
+        this.elapsedMillis = elapsed_millis;
+    }
+
+    public List<OptimizerSchedule> getSchedules() {
+        return schedules;
+    }
+
+    public void setSchedules(List<OptimizerSchedule> schedules) {
+        this.schedules = schedules;
+    }
+
+}
index 8c7dfb6..8520809 100644 (file)
 package org.onap.optf.cmso.optimizer.clients.ticketmgt;
 
 import java.util.Optional;
+import java.util.UUID;
 import org.onap.observations.Observation;
 import org.onap.optf.cmso.optimizer.clients.ticketmgt.models.ActiveTicketsResponse;
 import org.onap.optf.cmso.optimizer.common.LogMessages;
 import org.onap.optf.cmso.optimizer.model.Request;
 import org.onap.optf.cmso.optimizer.model.Ticket;
+import org.onap.optf.cmso.optimizer.model.Topology;
 import org.onap.optf.cmso.optimizer.model.dao.RequestDao;
 import org.onap.optf.cmso.optimizer.model.dao.TicketDao;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -53,13 +55,12 @@ public class TicketMgtRequestManager {
     TicketMgtClient ticketmgtClient;
 
     /**
-     * Creates the topology request.
+     * Creates the tickets request.
      *
      * @param requestRow the uuid
      * @return the active tickets response
      */
     public ActiveTicketsResponse createTicketsRequest(Request requestRow) {
-        try {
             Ticket row = null;
             Optional<Ticket> rowOpt = ticketDao.findById(requestRow.getUuid());
             if (rowOpt.isPresent()) {
@@ -72,22 +73,21 @@ public class TicketMgtRequestManager {
                 row.setTicketsRetries(0);
             }
             ActiveTicketsResponse apiResponse = ticketmgtClient.makeRequest(requestRow, row);
-            switch (apiResponse.getStatus()) {
-                case COMPLETED:
-                    break;
-                case FAILED:
-                    break;
-                case IN_PROGRESS:
-                    break;
-                default:
-                    break;
-            }
+            ticketDao.save(row);
             return apiResponse;
-        } catch (Exception e) {
-            Observation.report(LogMessages.UNEXPECTED_EXCEPTION, e, e.getMessage());
+            }
+    /**
+     * Gets the existing tickets.
+     *
+     * @param uuid the uuid
+     * @return the existing tickets
+     */
+    public Ticket getExistingTickets(UUID uuid) {
+        Optional<Ticket> opt = ticketDao.findById(uuid);
+        if (opt.isPresent()) {
+            return opt.get();
         }
         return null;
-
     }
 
 }
index d0af5c4..fe2c10c 100644 (file)
@@ -110,6 +110,20 @@ public class ChangeWindow implements Serializable {
         return true;
     }
 
+    /**
+     * Test if this window contains the passed window.
+     *
+     * @param test the test
+     * @return true, if this change window contains the passed change window
+     */
+    public boolean contains(ChangeWindow test) {
+        if (!test.getStartTime().before(getStartTime()) &&
+            !test.getEndTime().after(getEndTime())) {
+            return true;
+        }
+        return false;
+    }
+
     /**
      * Absorb if overlapping window.
      *
diff --git a/cmso-optimizer/src/test/data/resultsTest001.yaml b/cmso-optimizer/src/test/data/resultsTest001.yaml
new file mode 100644 (file)
index 0000000..1c7eed6
--- /dev/null
@@ -0,0 +1,28 @@
+results:
+  - num_scheduled: 0
+    total_completion_time: 0
+    element_slot_loader: |
+      1,0,1
+      2,0,1
+      3,0,1
+      4,0,1
+      5,0,1
+  -
+    num_scheduled: 1
+    total_completion_time: 2
+    element_slot_loader: |
+      1,0,1
+      2,0,1
+      3,2,1
+      4,0,1
+      5,0,1
+  -
+    num_scheduled: 4
+    total_completion_time: 8
+    element_slot_loader: |
+      1,2,1
+      2,1,1
+      3,2,1
+      4,0,1
+      5,3,1
+elapsed_millis: 3400
\ No newline at end of file
diff --git a/cmso-optimizer/src/test/java/org/onap/optf/cmso/optimizer/clients/optimizer/models/ResultsTest.java b/cmso-optimizer/src/test/java/org/onap/optf/cmso/optimizer/clients/optimizer/models/ResultsTest.java
new file mode 100644 (file)
index 0000000..a3ffedd
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ *  ============LICENSE_START==============================================
+ *  Copyright (c) 2019 AT&T Intellectual Property.
+ *  =======================================================================
+ *  Licensed under the Apache License, Version 2.0 (the "License"); you may
+ *  not use this file except in compliance with the License. You may obtain a
+ *  copy of the License at
+ *
+ *         http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing
+ * permissions and limitations under the License.
+ * ============LICENSE_END=================================================
+ */
+
+package org.onap.optf.cmso.optimizer.clients.optimizer.models;
+
+import java.io.File;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.yaml.snakeyaml.introspector.PropertyUtils;
+
+@RunWith(MockitoJUnitRunner.class)
+public class ResultsTest extends PropertyUtils {
+    @Test
+    public void yamlTests() {
+        OptimizerResponseUtility util = new OptimizerResponseUtility();
+        File resultsFile = new File("src/test/data/resultsTest001.yaml");
+        Results results = util.parseOptimizerResult(resultsFile);
+        Assert.assertTrue(results != null);
+
+    }
+
+
+}
diff --git a/cmso-optimizer/src/test/java/org/onap/optf/cmso/optimizer/service/rs/models/ChangeWindowTest.java b/cmso-optimizer/src/test/java/org/onap/optf/cmso/optimizer/service/rs/models/ChangeWindowTest.java
new file mode 100644 (file)
index 0000000..b1309fb
--- /dev/null
@@ -0,0 +1,53 @@
+package org.onap.optf.cmso.optimizer.service.rs.models;
+
+/*
+ * ============LICENSE_START==============================================
+ * Copyright (c) 2019 AT&T Intellectual Property.
+ * =======================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may
+ * not use this file except in compliance with the License. You may obtain a
+ * copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing
+ * permissions and limitations under the License.
+ * ============LICENSE_END=================================================
+ *
+ */
+
+import java.time.Instant;
+import java.util.Date;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.runners.MockitoJUnitRunner;
+
+@RunWith(MockitoJUnitRunner.class)
+public class ChangeWindowTest {
+
+
+    @Test
+    public void chagneWindowTest() {
+        ChangeWindow window = new ChangeWindow();
+        window.setStartTime(Date.from(Instant.parse("2019-03-08T00:00:00.00Z")));
+        window.setEndTime(Date.from(Instant.parse("2019-03-12T00:00:00.00Z")));
+        testContains(window, "2019-03-08T00:00:00.00Z", "2019-03-12T00:00:00.00Z", true);
+        testContains(window, "2019-03-07T23:59:59Z", "2019-03-12T00:00:00.00Z", false);
+        testContains(window, "2019-03-09T23:59:59Z", "2019-03-11T00:00:00.00Z", true);
+        testContains(window, "2019-03-06T23:59:59Z", "2019-03-06T23:59:59Z", false);
+        testContains(window, "2019-03-12T23:59:59Z", "2019-03-13T00:00:00.00Z", false);
+
+    }
+
+    private void testContains(ChangeWindow window, String from, String to, boolean contains) {
+        ChangeWindow test = new ChangeWindow();
+        test.setStartTime(Date.from(Instant.parse(from)));
+        test.setEndTime(Date.from(Instant.parse(to)));
+        Assert.assertTrue(window.contains(test) == contains);
+    }
+
+}