summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJerry Flood <jflood@att.com>2019-03-31 08:32:16 -0400
committerJerry Flood <jflood@att.com>2019-03-31 08:40:19 -0400
commite5c41bf11e52c885254ce8ae75127649886b559a (patch)
tree7961d98e1920f1efcfdba04250cb7571814faca8
parent9acaa2f04c92b6ffb0ae11a0f7b41aa260f2371d (diff)
Commit 3 for Define OPtimizer API mS
Multiple commits required due to commit size limitation. Change-Id: I92982e17538e19f79713efb99a1f2cc4b7ba3256 Issue-ID: OPTFRA-437 Signed-off-by: Jerry Flood <jflood@att.com>
-rw-r--r--cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/clients/topology/models/TopologyRequest.java1
-rw-r--r--cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/common/LogMessages.java59
-rw-r--r--cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/core/OptimizerManager.java93
-rw-r--r--cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/model/Request.java11
-rw-r--r--cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/service/rs/models/ChangeWindow.java64
-rw-r--r--cmso-optimizer/src/test/java/org/onap/optf/cmso/AuthProviderTest.java3
6 files changed, 211 insertions, 20 deletions
diff --git a/cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/clients/topology/models/TopologyRequest.java b/cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/clients/topology/models/TopologyRequest.java
index e0e95f7..ff6df18 100644
--- a/cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/clients/topology/models/TopologyRequest.java
+++ b/cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/clients/topology/models/TopologyRequest.java
@@ -35,6 +35,7 @@ import io.swagger.annotations.ApiModelProperty;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
+import org.onap.optf.cmso.optimizer.clients.common.models.ElementCriteria;
import org.onap.optf.cmso.optimizer.service.rs.models.NameValue;
@ApiModel(value = "Topology Request",
diff --git a/cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/common/LogMessages.java b/cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/common/LogMessages.java
index b61b02a..f36caee 100644
--- a/cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/common/LogMessages.java
+++ b/cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/common/LogMessages.java
@@ -37,6 +37,9 @@ import javax.ws.rs.core.Response.Status;
import org.apache.log4j.Level;
import org.onap.observations.ObservationInterface;
+/**
+ * The Enum LogMessages.
+ */
public enum LogMessages implements ObservationInterface {
OPTIMIZE_SCHEDULE("Optimize schedule {0} : {1}: {2} : {3}", Status.OK, Level.INFO),
@@ -60,7 +63,8 @@ public enum LogMessages implements ObservationInterface {
OUTGOING_MESSAGE_RETURNED("Outgoing message returned method={0} path={1} status={2}", Status.OK, Level.INFO, true,
false),
- UNEXPECTED_RESPONSE("Unexpected response from URL {0} : HTTP Status={1}", Status.INTERNAL_SERVER_ERROR , Level.ERROR),
+ UNEXPECTED_RESPONSE("Unexpected response from URL {0} : HTTP Status={1}", Status.INTERNAL_SERVER_ERROR,
+ Level.ERROR),
INVALID_CHANGE_WINDOW("Change window end time {0} must be after start time {1}", Status.OK, Level.INFO),
EXPECTED_EXCEPTION("Expected exception encountered during processing. {0}", Status.OK, Level.INFO),
UNABLE_TO_UPDATE_TICKET("Unable to update change ticket in TM: Schedule ID: {0} : changeid: {1} : Reason: {2}",
@@ -73,6 +77,14 @@ public enum LogMessages implements ObservationInterface {
OPTIMIZER_REQUEST("OPtimizer request {0} for {1} Command: {1}", Status.OK, Level.INFO),
TICKETS_REQUEST("Tickets request {0} for {1} URL: {1}", Status.OK, Level.INFO),
UNSUPPORTED_PERIODIC_TIME("Unsupported periodic time from policy: {0}", Status.INTERNAL_SERVER_ERROR, Level.ERROR),
+ EXCEEDED_RETRY_LIMIT("Outbound request for {0} exceeded retry limit {1}", Status.INTERNAL_SERVER_ERROR,
+ Level.ERROR),
+ FAILED_TO_CREATE_TOPOLOGY_REQUEST("Failed to create request reqeust for id={0}", Status.INTERNAL_SERVER_ERROR,
+ Level.ERROR),
+ FAILED_TO_CREATE_TICKET_REQUEST("Failed to create ticket request for id={0}", Status.INTERNAL_SERVER_ERROR,
+ Level.ERROR),
+ FAILED_TO_CREATE_OPTIMIZER_REQUEST("Failed to create optimizer request for id={0}", Status.INTERNAL_SERVER_ERROR,
+ Level.ERROR),
;
private final String defaultId;
@@ -147,43 +159,88 @@ public enum LogMessages implements ObservationInterface {
}
+ /**
+ * Gets the level.
+ *
+ * @return the level
+ */
// interface methods
@Override
public Level getLevel() {
return level;
}
+ /**
+ * Gets the message.
+ *
+ * @return the message
+ */
@Override
public String getMessage() {
return defaultMessage;
}
+ /**
+ * Gets the status.
+ *
+ * @return the status
+ */
@Override
public Status getStatus() {
return status;
}
+ /**
+ * Gets the value.
+ *
+ * @return the value
+ */
@Override
public Enum<?> getValue() {
return this;
}
+ /**
+ * Gets the domain.
+ *
+ * @return the domain
+ */
@Override
public String getDomain() {
return this.getClass().getSimpleName();
}
+ /**
+ * Gets the audit.
+ *
+ * @return the audit
+ */
@Override
public Boolean getAudit() {
return audit;
}
+ /**
+ * Gets the metric.
+ *
+ * @return the metric
+ */
@Override
public Boolean getMetric() {
return metric;
}
/**
+ * Format.
+ *
+ * @param args the args
+ * @return the string
+ */
+ public String format(String... args) {
+ return EELFResourceManager.format(this, args);
+ }
+
+ /**
* The main method.
*
* @param argv the arguments
diff --git a/cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/core/OptimizerManager.java b/cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/core/OptimizerManager.java
index 5289dae..43ecf3f 100644
--- a/cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/core/OptimizerManager.java
+++ b/cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/core/OptimizerManager.java
@@ -26,6 +26,8 @@ import java.util.Optional;
import java.util.UUID;
import javax.ws.rs.core.Response.Status;
import org.onap.optf.cmso.common.exceptions.CmsoException;
+import org.onap.optf.cmso.optimizer.clients.ticketmgt.TicketMgtRequestManager;
+import org.onap.optf.cmso.optimizer.clients.ticketmgt.models.ActiveTicketsResponse;
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;
@@ -39,6 +41,9 @@ import org.onap.optf.cmso.optimizer.service.rs.models.OptimizerResponse.Optimize
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
+/**
+ * The Class OptimizerManager.
+ */
@Component
public class OptimizerManager {
@@ -48,6 +53,9 @@ public class OptimizerManager {
@Autowired
TopologyRequestManager topologyRequestManager;
+ @Autowired
+ TicketMgtRequestManager ticketMgtRequestManager;
+
/**
* Validate optimizer request.
*
@@ -111,12 +119,18 @@ public class OptimizerManager {
throw new CmsoException(Status.BAD_REQUEST, LogMessages.MISSING_REQUIRED_ATTRIBUTE, name);
}
+ /**
+ * Process optimizer request.
+ *
+ * @param request the request
+ * @return the optimizer response
+ * @throws CmsoException the cmso exception
+ */
public OptimizerResponse processOptimizerRequest(OptimizerRequest request) throws CmsoException {
UUID uuid = UUID.fromString(request.getRequestId());
Request requestRow = null;
Optional<Request> rrOptional = requestDao.findById(uuid);
- if (rrOptional.isPresent())
- {
+ if (rrOptional.isPresent()) {
requestRow = rrOptional.get();
}
OptimizerResponse optimizerResponse = new OptimizerResponse();
@@ -135,39 +149,84 @@ public class OptimizerManager {
}
requestRow.setStatus(OptimizeScheduleStatus.FAILED.toString());
requestDao.save(requestRow);
- TopologyResponse topologyResponse = topologyRequestManager.createTopologyRequest(uuid);
+ initiateDataGathering(requestRow);
+ requestDao.save(requestRow);
+ OptimizeScheduleStatus status = OptimizeScheduleStatus.valueOf(requestRow.getStatus());
+ optimizerResponse.setStatus(status);
+ optimizerResponse.setErrorMessage("");
+ return optimizerResponse;
+ }
+
+ private void initiateDataGathering(Request requestRow) throws CmsoException {
+ TopologyResponse topologyResponse = topologyRequestManager.createTopologyRequest(requestRow);
if (topologyResponse != null) {
- switch (topologyResponse.getStatus())
- {
+ switch (topologyResponse.getStatus()) {
case COMPLETED:
requestRow.setRequestStart(System.currentTimeMillis());
requestRow.setStatus(OptimizeScheduleStatus.PENDING_TICKETS.toString());
- optimizerResponse.setStatus(OptimizeScheduleStatus.PENDING_TICKETS);
+ initiateTicketGathering(requestRow); // continue synchronous flow
+ return;
+ case FAILED:
+ requestRow.setRequestStart(System.currentTimeMillis());
+ requestRow.setRequestEnd(System.currentTimeMillis());
+ requestRow.setStatus(OptimizeScheduleStatus.FAILED.toString());
+ requestRow.setMessage(topologyResponse.getErrorMessage());
+ return;
+ case IN_PROGRESS:
+ requestRow.setRequestStart(System.currentTimeMillis());
+ requestRow.setStatus(OptimizeScheduleStatus.PENDING_TOPOLOGY.toString());
+ break;
+ default:
+ break;
+ }
+ }
+ throw new CmsoException(Status.INTERNAL_SERVER_ERROR, LogMessages.FAILED_TO_CREATE_TOPOLOGY_REQUEST,
+ requestRow.getUuid().toString());
+ }
+ private void initiateTicketGathering(Request requestRow) throws CmsoException {
+ ActiveTicketsResponse apiResponse = ticketMgtRequestManager.createTicketsRequest(requestRow);
+ if (apiResponse != null) {
+ switch (apiResponse.getStatus()) {
+ case COMPLETED:
+ requestRow.setRequestStart(System.currentTimeMillis());
+ requestRow.setStatus(OptimizeScheduleStatus.PENDING_OPTIMIZER.toString());
+ initiateOptimizer(requestRow);
break;
case FAILED:
requestRow.setRequestStart(System.currentTimeMillis());
requestRow.setRequestEnd(System.currentTimeMillis());
requestRow.setStatus(OptimizeScheduleStatus.FAILED.toString());
- optimizerResponse.setStatus(OptimizeScheduleStatus.FAILED);
- optimizerResponse.setErrorMessage(topologyResponse.getErrorMessage());
+ requestRow.setMessage(apiResponse.getErrorMessage());
break;
case IN_PROGRESS:
requestRow.setRequestStart(System.currentTimeMillis());
- requestRow.setStatus(OptimizeScheduleStatus.PENDING_TOPOLOGY.toString());
- optimizerResponse.setStatus(OptimizeScheduleStatus.PENDING_TOPOLOGY);
+ requestRow.setStatus(OptimizeScheduleStatus.PENDING_TICKETS.toString());
+ break;
+ default:
break;
}
- } else {
- requestRow.setRequestStart(System.currentTimeMillis());
- requestRow.setStatus(OptimizeScheduleStatus.PENDING_TOPOLOGY.toString());
- requestDao.save(requestRow);
- return null;
}
- requestDao.save(requestRow);
- return optimizerResponse;
+ throw new CmsoException(Status.INTERNAL_SERVER_ERROR, LogMessages.FAILED_TO_CREATE_TICKET_REQUEST,
+ requestRow.getUuid().toString());
}
+ private void initiateOptimizer(Request requestRow) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @SuppressWarnings("unused")
+ private Request getRequestRow(UUID uuid) throws CmsoException {
+ Request requestRow = null;
+ Optional<Request> requestOptional = requestDao.findById(uuid);
+ if (requestOptional.isPresent()) {
+ return requestOptional.get();
+ }
+ throw new CmsoException(Status.INTERNAL_SERVER_ERROR, LogMessages.EXPECTED_DATA_NOT_FOUND,
+ requestRow.toString(), "Request table");
+ }
+
}
diff --git a/cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/model/Request.java b/cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/model/Request.java
index 3258c15..3ae723f 100644
--- a/cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/model/Request.java
+++ b/cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/model/Request.java
@@ -54,6 +54,9 @@ public class Request implements Serializable {
private String status;
+ @Lob
+ private String message;
+
public Request() {}
public UUID getUuid() {
@@ -104,4 +107,12 @@ public class Request implements Serializable {
this.status = status;
}
+ public String getMessage() {
+ return message;
+ }
+
+ public void setMessage(String message) {
+ this.message = message;
+ }
+
}
diff --git a/cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/service/rs/models/ChangeWindow.java b/cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/service/rs/models/ChangeWindow.java
index 30104f4..d0af5c4 100644
--- a/cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/service/rs/models/ChangeWindow.java
+++ b/cmso-optimizer/src/main/java/org/onap/optf/cmso/optimizer/service/rs/models/ChangeWindow.java
@@ -36,6 +36,9 @@ import java.io.Serializable;
import java.util.Date;
import org.springframework.format.annotation.DateTimeFormat;
+/**
+ * The Class ChangeWindow.
+ */
@ApiModel(value = "Change Window", description = "Time window for which tickets are to returned")
public class ChangeWindow implements Serializable {
private static final long serialVersionUID = 1L;
@@ -49,23 +52,84 @@ public class ChangeWindow implements Serializable {
@DateTimeFormat(pattern = "yyyy-MM-dd'T'hh:mm:ss'Z'")
private Date endTime;
+ /**
+ * Gets the start time.
+ *
+ * @return the start time
+ */
public Date getStartTime() {
return startTime;
}
+ /**
+ * Sets the start time.
+ *
+ * @param startTime the new start time
+ */
public void setStartTime(Date startTime) {
this.startTime = startTime;
}
+ /**
+ * Gets the end time.
+ *
+ * @return the end time
+ */
public Date getEndTime() {
return endTime;
}
+ /**
+ * Sets the end time.
+ *
+ * @param endTime the new end time
+ */
public void setEndTime(Date endTime) {
this.endTime = endTime;
}
/**
+ * Overlaps test instance.b
+ *
+ * @param test the test window
+ * @return true, if successful
+ */
+ public boolean overlaps(ChangeWindow test) {
+ int start = startTime.compareTo(test.getStartTime());
+ int end = endTime.compareTo(test.getEndTime());
+ int startend = startTime.compareTo(test.getEndTime());
+ int endstart = endTime.compareTo(test.getStartTime());
+ // at least one of the ends match up
+ if (start == 0 || end == 0 || startend == 0 || endstart == 0) {
+ return true;
+ }
+ // end is before start or start is before end, cannot overlap
+ if (endstart == -1 || startend == 1) {
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * Absorb if overlapping window.
+ *
+ * @param test the test window
+ * @return true, if successful
+ */
+ public boolean absorbIfOverlapping(ChangeWindow test) {
+ if (overlaps(test)) {
+ if (test.getStartTime().before(getStartTime())) {
+ setStartTime(test.getStartTime());
+ }
+ if (test.getEndTime().after(getEndTime())) {
+ setEndTime(test.getEndTime());
+ }
+ return true;
+ }
+ return false;
+ }
+
+ /**
* To string.
*
* @return the string
diff --git a/cmso-optimizer/src/test/java/org/onap/optf/cmso/AuthProviderTest.java b/cmso-optimizer/src/test/java/org/onap/optf/cmso/AuthProviderTest.java
index 8047f9e..d2852d2 100644
--- a/cmso-optimizer/src/test/java/org/onap/optf/cmso/AuthProviderTest.java
+++ b/cmso-optimizer/src/test/java/org/onap/optf/cmso/AuthProviderTest.java
@@ -36,7 +36,6 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.runners.MockitoJUnitRunner;
@@ -66,4 +65,4 @@ public class AuthProviderTest {
assertTrue(authProvider.supports(UsernamePasswordAuthenticationToken.class));
assertFalse(authProvider.supports(Authentication.class));
}
-} \ No newline at end of file
+}