aboutsummaryrefslogtreecommitdiffstats
path: root/cmso-optimizer/src/main/java/org
diff options
context:
space:
mode:
Diffstat (limited to 'cmso-optimizer/src/main/java/org')
-rw-r--r--cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/clients/optimizer/OptimizerRequestManager.java185
-rw-r--r--cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/clients/optimizer/models/ElementSlot.java34
-rw-r--r--cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/clients/optimizer/models/OptimizerEngineResponse.java65
-rw-r--r--cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/clients/optimizer/models/OptimizerParameters.java39
-rw-r--r--cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/clients/optimizer/models/OptimizerResponseUtility.java9
-rw-r--r--cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/clients/optimizer/models/OptimizerResults.java46
-rw-r--r--cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/clients/topology/TopologyRequestManager.java15
7 files changed, 366 insertions, 27 deletions
diff --git a/cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/clients/optimizer/OptimizerRequestManager.java b/cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/clients/optimizer/OptimizerRequestManager.java
new file mode 100644
index 0000000..34de3df
--- /dev/null
+++ b/cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/clients/optimizer/OptimizerRequestManager.java
@@ -0,0 +1,185 @@
+/*
+ * ============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;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import java.util.List;
+import java.util.Optional;
+import java.util.UUID;
+import org.onap.observations.Observation;
+import org.onap.optf.cmso.optimizer.clients.optimizer.models.OptimizerEngineResponse;
+import org.onap.optf.cmso.optimizer.clients.optimizer.models.OptimizerEngineResponse.OptimizerEngineResponseStatus;
+import org.onap.optf.cmso.optimizer.clients.optimizer.models.OptimizerResults;
+import org.onap.optf.cmso.optimizer.clients.optimizer.models.OptimizerSchedule;
+import org.onap.optf.cmso.optimizer.clients.topology.TopologyRequestManager;
+import org.onap.optf.cmso.optimizer.clients.topology.models.TopologyResponse;
+import org.onap.optf.cmso.optimizer.common.LogMessages;
+import org.onap.optf.cmso.optimizer.model.Optimizer;
+import org.onap.optf.cmso.optimizer.model.Request;
+import org.onap.optf.cmso.optimizer.model.Response;
+import org.onap.optf.cmso.optimizer.model.dao.OptimizerDao;
+import org.onap.optf.cmso.optimizer.model.dao.RequestDao;
+import org.onap.optf.cmso.optimizer.model.dao.ResponseDao;
+import org.onap.optf.cmso.optimizer.service.rs.models.OptimizerRequest;
+import org.onap.optf.cmso.optimizer.service.rs.models.OptimizerResponse;
+import org.onap.optf.cmso.optimizer.service.rs.models.OptimizerResponse.OptimizeScheduleStatus;
+import org.onap.optf.cmso.optimizer.service.rs.models.OptimizerScheduleInfo;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.env.Environment;
+import org.springframework.stereotype.Component;
+
+/**
+ * The Class OPtimizerRequestManager.
+ */
+@Component
+public class OptimizerRequestManager {
+
+ @Autowired
+ Environment env;
+
+ @Autowired
+ RequestDao requestDao;
+
+ @Autowired
+ OptimizerDao optimizerDao;
+
+ @Autowired
+ ResponseDao responseDao;
+
+ @Autowired
+ OptimizerClient optimizerClient;
+
+ @Autowired
+ TopologyRequestManager topologyRequestManager;
+
+ /**
+ * Creates the Optimizer request.
+ *
+ * @param requestRow the request row
+ * @return the Optimizer response
+ */
+ public OptimizerEngineResponse createOptimizerRequest(Request requestRow) {
+ //
+ if (okToDispatch()) {
+ Optimizer optimizer = getExistingOptmizer(requestRow.getUuid());
+ if (optimizer == null) {
+ optimizer = new Optimizer();
+ optimizer.setUuid(requestRow.getUuid());
+ optimizer.setOptimizeRetries(0);
+ }
+ optimizer.setOptimizeStart(System.currentTimeMillis());
+ OptimizerEngineResponse apiResponse = optimizerClient.makeRequest(requestRow, optimizer);
+ if (apiResponse.getStatus() == OptimizerEngineResponseStatus.COMPLETED) {
+ optimizer.setOptimizeEnd(System.currentTimeMillis());
+ optimizer.setOptimizeResponse(""); // Perhaps we do not need to persist...
+ buildFinalResponse(requestRow, apiResponse);
+ }
+ optimizerDao.save(optimizer);
+ return apiResponse;
+ } else {
+ OptimizerEngineResponse apiResponse = new OptimizerEngineResponse();
+ apiResponse.setRequestId(requestRow.getUuid().toString());
+ apiResponse.setStatus(OptimizerEngineResponseStatus.IN_QUEUE);
+ apiResponse.setPollingSeconds(60);
+ return apiResponse;
+ }
+ }
+
+
+ private void buildFinalResponse(Request requestRow, OptimizerEngineResponse apiResponse) {
+ Optional<Response> opt = responseDao.findById(requestRow.getUuid());
+ Response responseRow = null;
+ if (opt.isPresent())
+ {
+ responseRow = opt.get();
+ }
+ if (responseRow == null)
+ {
+ responseRow = new Response();
+ responseRow.setUuid(requestRow.getUuid());
+ }
+
+ try
+ {
+ OptimizerResults results = apiResponse.getOptimizerResults();
+ OptimizerResponse response = new OptimizerResponse();
+ response.setRequestId(requestRow.getUuid().toString());
+
+ String optString = requestRow.getRequest();
+
+ OptimizerRequest optimizerResquest = new ObjectMapper().readValue(optString, OptimizerRequest.class);
+ TopologyResponse topologyResponse = topologyRequestManager.getTopologyResponse(requestRow.getUuid());
+ ElementWindowMapping ewm = new ElementWindowMapping(optimizerResquest, topologyResponse);
+ ewm.initializeForProcessResult();
+ for (OptimizerSchedule result : results.getSchedules()) {
+ OptimizerScheduleInfo info = ewm.processResult(result);
+ if (info != null) {
+ response.getSchedules().add(info);
+ }
+ }
+ responseRow.setRepsonse(new ObjectMapper().writeValueAsString(response));
+ requestRow.setStatus(OptimizeScheduleStatus.COMPLETED.toString());
+ responseDao.save(responseRow);
+ requestDao.save(requestRow);
+ }
+ catch (Exception e)
+ {
+ Observation.report(LogMessages.UNEXPECTED_EXCEPTION, e, e.getMessage());
+ requestRow.setStatus(OptimizeScheduleStatus.FAILED.toString());
+ requestRow.setMessage(e.getMessage());
+ responseRow.setRepsonse("");
+ responseDao.save(responseRow);
+ requestDao.save(requestRow);
+ }
+ }
+
+
+
+ private boolean okToDispatch() {
+ // TODO Auto-generated method stub
+
+ // Will probably change to @Async on makeRequest to queue requests in a different thread.
+ return true;
+ }
+
+
+ /**
+ * Gets the existing optimizer row.
+ *
+ * @param uuid the uuid
+ * @return the existing optmizer row
+ */
+ public Optimizer getExistingOptmizer(UUID uuid) {
+ Optional<Optimizer> oppt = optimizerDao.findById(uuid);
+ if (oppt.isPresent()) {
+ return oppt.get();
+ }
+ return null;
+ }
+
+
+ public List<OptimizerScheduleInfo> getScheduleInfo(Response responseRow) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+
+
+}
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
index eb90a44..8f76b10 100644
--- 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
@@ -29,16 +29,16 @@ package org.onap.optf.cmso.optimizer.clients.optimizer.models;
5,0,1
*/
public class ElementSlot {
- private Long elementIndex = 0L;
- private Long slot = 0L;
- private Long loader = 0L;
+ private Integer elementIndex = 0;
+ private Integer slot = 0;
+ private Integer loader = 0;
+ private Long time = 0L;
-
- public Long getElementIndex() {
+ public Integer getElementIndex() {
return elementIndex;
}
- public void setElementIndex(Long elementIndex) {
+ public void setElementIndex(Integer elementIndex) {
this.elementIndex = elementIndex;
}
@@ -47,7 +47,7 @@ public class ElementSlot {
*
* @return the slot
*/
- public Long getSlot() {
+ public Integer getSlot() {
return slot;
}
@@ -56,7 +56,7 @@ public class ElementSlot {
*
* @param slot the new slot
*/
- public void setSlot(Long slot) {
+ public void setSlot(Integer slot) {
this.slot = slot;
}
@@ -65,7 +65,7 @@ public class ElementSlot {
*
* @return the loader
*/
- public Long getLoader() {
+ public Integer getLoader() {
return loader;
}
@@ -74,7 +74,7 @@ public class ElementSlot {
*
* @param loader the new loader
*/
- public void setLoader(Long loader) {
+ public void setLoader(Integer loader) {
this.loader = loader;
}
@@ -85,14 +85,22 @@ public class ElementSlot {
*/
public ElementSlot(String[] cols) {
if (cols.length > 0) {
- elementIndex = Long.valueOf(cols[0]);
+ elementIndex = Integer.valueOf(cols[0]);
}
if (cols.length > 1) {
- slot = Long.valueOf(cols[1]);
+ slot = Integer.valueOf(cols[1]);
}
if (cols.length > 2) {
- loader = Long.valueOf(cols[2]);
+ loader = Integer.valueOf(cols[2]);
}
}
+
+ public Long getTime() {
+ return time;
+ }
+
+ public void setTime(Long time) {
+ this.time = time;
+ }
}
diff --git a/cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/clients/optimizer/models/OptimizerEngineResponse.java b/cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/clients/optimizer/models/OptimizerEngineResponse.java
new file mode 100644
index 0000000..7315b31
--- /dev/null
+++ b/cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/clients/optimizer/models/OptimizerEngineResponse.java
@@ -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;
+
+public class OptimizerEngineResponse
+{
+
+ public enum OptimizerEngineResponseStatus {
+ IN_PROGRESS, COMPLETED, FAILED, IN_QUEUE,
+ }
+
+ private String requestId;
+ private OptimizerResults optimizerResults;
+ private OptimizerEngineResponseStatus status;
+ private Integer pollingSeconds;
+ private String errorMessage;
+ public String getRequestId() {
+ return requestId;
+ }
+ public void setRequestId(String requestId) {
+ this.requestId = requestId;
+ }
+ public OptimizerResults getOptimizerResults() {
+ return optimizerResults;
+ }
+ public void setOptimizerResults(OptimizerResults oprimizerResults) {
+ this.optimizerResults = oprimizerResults;
+ }
+ public OptimizerEngineResponseStatus getStatus() {
+ return status;
+ }
+ public void setStatus(OptimizerEngineResponseStatus status) {
+ this.status = status;
+ }
+ public Integer getPollingSeconds() {
+ return pollingSeconds;
+ }
+ public void setPollingSeconds(Integer pollingSeconds) {
+ this.pollingSeconds = pollingSeconds;
+ }
+ public String getErrorMessage() {
+ return errorMessage;
+ }
+ public void setErrorMessage(String errorMessage) {
+ this.errorMessage = errorMessage;
+ }
+
+
+}
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
index 0ab187b..be74e37 100644
--- 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
@@ -45,10 +45,10 @@ attributeConcurrencyLimit = [];
*/
public class OptimizerParameters {
private Long numElements;
- private Long maxTime;
private Long numLoaders;
+ private List<Long> elementSlotCapacity = new ArrayList<>();
+ private Long maxTime;
private List<List<Boolean>> noConflict = new ArrayList<>();
- private List<Long> slotCapacity = new ArrayList<>();
private List<List<Long>> loaderCapacity = new ArrayList<>();
private Long numAttributes;
@@ -88,12 +88,12 @@ public class OptimizerParameters {
this.noConflict = noConflict;
}
- public List<Long> getSlotCapacity() {
- return slotCapacity;
+ public List<Long> getElementSlotCapacity() {
+ return elementSlotCapacity;
}
- public void setSlotCapacity(List<Long> slotCapacity) {
- this.slotCapacity = slotCapacity;
+ public void setElementSlotCapacity(List<Long> slotCapacity) {
+ this.elementSlotCapacity = slotCapacity;
}
public List<List<Long>> getLoaderCapacity() {
@@ -144,12 +144,31 @@ public class OptimizerParameters {
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, "elementSlotCapacity", "[" + formatLongList(elementSlotCapacity) + "]");
appendAttribute(sb, "loaderCapacity", "[|\n" + formatLongRows(loaderCapacity) + "|]");
- appendAttribute(sb, "attributesRange", "[" + formatLongList(attributesRange) + "]");
- appendAttribute(sb, "attributes", "[|\n" + formatLongRows(attributes) + "|]");
- appendAttribute(sb, "attributeConcurrencyLimit", "[|\n" + formatLongRows(attributeConcurrencyLimit) + "|]");
+
+
+ if (attributesRange.size() > 0) {
+ appendAttribute(sb, "attributesRange", "[" + formatLongList(attributesRange) + "]");
+ }
+ else {
+ appendAttribute(sb, "attributesRange", "[]");
+ }
+ if (attributes.size() > 0) {
+ appendAttribute(sb, "attributes", "[|\n" + formatLongRows(attributes) + "|]");
+ }
+ else {
+ appendAttribute(sb, "attributes", "array2d(1..numElements, 1..numAttributes, [])");
+ }
+ if (attributeConcurrencyLimit.size() > 0) {
+ appendAttribute(sb, "attributeConcurrencyLimit", "[|\n" + formatLongRows(attributeConcurrencyLimit) + "|]");
+ }
+ else
+ {
+ appendAttribute(sb, "attributeConcurrencyLimit", "array2d(1..numAttributes, 1..maxTime, [])");
+ }
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
index aefaba8..89208b2 100644
--- 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
@@ -32,8 +32,9 @@ 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;
+
+ public OptimizerResults parseOptimizerResult(File resultsFile) {
+ OptimizerResults results = null;
try (InputStream input = new FileInputStream(resultsFile)) {
Constructor constructor = new Constructor(OptimizerOutResults.class);
constructor.setPropertyUtils(this);
@@ -46,8 +47,8 @@ public class OptimizerResponseUtility extends PropertyUtils {
return results;
}
- private Results marshall(OptimizerOutResults optimizerOut) {
- Results results = new Results();
+ private OptimizerResults marshall(OptimizerOutResults optimizerOut) {
+ OptimizerResults results = new OptimizerResults();
results.setElapsedMillis(optimizerOut.getElapsedMillis());
List<OptimizerSchedule> schedules = new ArrayList<>();
results.setSchedules(schedules);
diff --git a/cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/clients/optimizer/models/OptimizerResults.java b/cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/clients/optimizer/models/OptimizerResults.java
new file mode 100644
index 0000000..9c31a9f
--- /dev/null
+++ b/cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/clients/optimizer/models/OptimizerResults.java
@@ -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 OptimizerResults {
+ 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;
+ }
+
+}
diff --git a/cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/clients/topology/TopologyRequestManager.java b/cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/clients/topology/TopologyRequestManager.java
index ce0d583..a1cb51d 100644
--- a/cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/clients/topology/TopologyRequestManager.java
+++ b/cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/clients/topology/TopologyRequestManager.java
@@ -19,6 +19,10 @@
package org.onap.optf.cmso.optimizer.clients.topology;
+import com.fasterxml.jackson.core.JsonParseException;
+import com.fasterxml.jackson.databind.JsonMappingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import java.io.IOException;
import java.util.Optional;
import java.util.UUID;
import org.onap.optf.cmso.optimizer.clients.topology.models.TopologyResponse;
@@ -81,4 +85,15 @@ public class TopologyRequestManager {
}
return null;
}
+
+
+ public TopologyResponse getTopologyResponse(UUID uuid) throws JsonParseException, JsonMappingException, IOException {
+ Topology row = getExistingTopology(uuid);
+ if (row != null)
+ {
+ String responseString = row.getTopology();
+ return new ObjectMapper().readValue(responseString, TopologyResponse.class);
+ }
+ return null;
+ }
}