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),
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}",
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;
}
+ /**
+ * 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.
*
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;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
+/**
+ * The Class OptimizerManager.
+ */
@Component
public class OptimizerManager {
@Autowired
TopologyRequestManager topologyRequestManager;
+ @Autowired
+ TicketMgtRequestManager ticketMgtRequestManager;
+
/**
* Validate optimizer request.
*
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();
}
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");
+ }
+
}
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;
@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.
*