aboutsummaryrefslogtreecommitdiffstats
path: root/cmso-service/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'cmso-service/src/main')
-rw-r--r--cmso-service/src/main/java/org/onap/optf/cmso/JerseyConfiguration.java2
-rw-r--r--cmso-service/src/main/java/org/onap/optf/cmso/common/BasicAuthenticatorFilter.java30
-rw-r--r--cmso-service/src/main/java/org/onap/optf/cmso/common/Mdc.java211
-rw-r--r--cmso-service/src/main/java/org/onap/optf/cmso/test/loopback/SchedulerTestLoopbackService.java93
-rw-r--r--cmso-service/src/main/java/org/onap/optf/cmso/test/loopback/SchedulerTestLoopbackServiceImpl.java238
5 files changed, 0 insertions, 574 deletions
diff --git a/cmso-service/src/main/java/org/onap/optf/cmso/JerseyConfiguration.java b/cmso-service/src/main/java/org/onap/optf/cmso/JerseyConfiguration.java
index eb4160a..b58b728 100644
--- a/cmso-service/src/main/java/org/onap/optf/cmso/JerseyConfiguration.java
+++ b/cmso-service/src/main/java/org/onap/optf/cmso/JerseyConfiguration.java
@@ -49,7 +49,6 @@ import org.onap.optf.cmso.filters.CmsoContainerFilters;
import org.onap.optf.cmso.service.rs.AdminToolImpl;
import org.onap.optf.cmso.service.rs.CmsoServiceImpl;
import org.onap.optf.cmso.service.rs.HealthCheckImpl;
-import org.onap.optf.cmso.test.loopback.SchedulerTestLoopbackServiceImpl;
import org.onap.optf.cmso.test.loopback.TicketMgtLoopbackServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
@@ -83,7 +82,6 @@ public class JerseyConfiguration extends ResourceConfig {
@Autowired
public JerseyConfiguration( /* LogRequestFilter lrf */ ) {
register(CmsoServiceImpl.class);
- register(SchedulerTestLoopbackServiceImpl.class);
register(TicketMgtLoopbackServiceImpl.class);
register(HealthCheckImpl.class);
register(AdminToolImpl.class);
diff --git a/cmso-service/src/main/java/org/onap/optf/cmso/common/BasicAuthenticatorFilter.java b/cmso-service/src/main/java/org/onap/optf/cmso/common/BasicAuthenticatorFilter.java
index 048c44c..8f9c00c 100644
--- a/cmso-service/src/main/java/org/onap/optf/cmso/common/BasicAuthenticatorFilter.java
+++ b/cmso-service/src/main/java/org/onap/optf/cmso/common/BasicAuthenticatorFilter.java
@@ -21,7 +21,6 @@ import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
-import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.client.ClientRequestContext;
import javax.ws.rs.client.ClientRequestFilter;
import javax.ws.rs.core.MultivaluedMap;
@@ -69,33 +68,4 @@ public class BasicAuthenticatorFilter implements ClientRequestFilter {
}
}
- /**
- * Gets the user.
- *
- * @param request the request
- * @return the user
- */
- public static String getUser(HttpServletRequest request) {
- String user = "";
- String header = request.getHeader("Authorization");
- if (header != null) {
- String[] auth = header.split("Basic ");
- if (auth.length == 2) {
- String token = getToken(auth[1]);
- if (token.contains(":")) {
- String[] tokens = token.split(":");
- user = tokens[0];
- }
- }
- }
- return user;
- }
-
- private static String getToken(String auth) {
- try {
- return new String(DatatypeConverter.parseBase64Binary(auth));
- } catch (Exception e) {
- return auth;
- }
- }
}
diff --git a/cmso-service/src/main/java/org/onap/optf/cmso/common/Mdc.java b/cmso-service/src/main/java/org/onap/optf/cmso/common/Mdc.java
index d18ded4..503f42c 100644
--- a/cmso-service/src/main/java/org/onap/optf/cmso/common/Mdc.java
+++ b/cmso-service/src/main/java/org/onap/optf/cmso/common/Mdc.java
@@ -34,30 +34,17 @@ package org.onap.optf.cmso.common;
import static com.att.eelf.configuration.Configuration.MDC_BEGIN_TIMESTAMP;
import static com.att.eelf.configuration.Configuration.MDC_ELAPSED_TIME;
import static com.att.eelf.configuration.Configuration.MDC_END_TIMESTAMP;
-import static com.att.eelf.configuration.Configuration.MDC_INSTANCE_UUID;
-import static com.att.eelf.configuration.Configuration.MDC_KEY_REQUEST_ID;
import static com.att.eelf.configuration.Configuration.MDC_PARTNER_NAME;
-import static com.att.eelf.configuration.Configuration.MDC_REMOTE_HOST;
import static com.att.eelf.configuration.Configuration.MDC_RESPONSE_CODE;
import static com.att.eelf.configuration.Configuration.MDC_RESPONSE_DESC;
-import static com.att.eelf.configuration.Configuration.MDC_SERVER_FQDN;
-import static com.att.eelf.configuration.Configuration.MDC_SERVER_IP_ADDRESS;
-import static com.att.eelf.configuration.Configuration.MDC_SERVICE_INSTANCE_ID;
-import static com.att.eelf.configuration.Configuration.MDC_SERVICE_NAME;
import static com.att.eelf.configuration.Configuration.MDC_STATUS_CODE;
import static com.att.eelf.configuration.Configuration.MDC_TARGET_ENTITY;
import static com.att.eelf.configuration.Configuration.MDC_TARGET_SERVICE_NAME;
-
import com.att.eelf.utils.Stopwatch;
-import java.net.InetAddress;
import java.net.URI;
import java.util.Date;
import java.util.Map;
-import java.util.UUID;
-import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.core.Response;
-import org.onap.optf.cmso.filters.MessageHeaders;
-import org.quartz.JobExecutionContext;
import org.slf4j.MDC;
/**
@@ -91,211 +78,13 @@ public class Mdc {
ErrorCode, ErrorDescription, Timer,
}
- /**
- * Begin.
- *
- * @param request the request
- * @param requestId the request id
- */
- public static void begin(HttpServletRequest request, String requestId) {
- MDC.clear();
- Stopwatch.start();
- // MDC.put(MDC_ALERT_SEVERITY, "");
- MDC.put(MDC_BEGIN_TIMESTAMP, Stopwatch.isoFormatter.format(new Date()));
- // MDC.put(MDC_ELAPSED_TIME, String.valueOf(Stopwatch.getDuration()));
- // MDC.put(MDC_END_TIMESTAMP, "");
- MDC.put(MDC_INSTANCE_UUID, UUID.randomUUID().toString());
- // MDC.put(MDC_KEY_REQUEST_ID, requestId);
- setRequestId(request, requestId);
- // MDC.put(MDC_PROCESS_KEY, "");
- MDC.put(MDC_REMOTE_HOST, request.getRemoteHost());
- // MDC.put(MDC_RESPONSE_CODE, "");
- // MDC.put(MDC_RESPONSE_DESC, "");
- // MDC.put(MDC_SERVICE_NAME, "");
- try {
- MDC.put(MDC_SERVER_FQDN, InetAddress.getLocalHost().getHostName());
- } catch (Exception e) {
- MDC.put(MDC_SERVER_FQDN, e.getMessage());
- }
- try {
- MDC.put(MDC_SERVER_IP_ADDRESS, InetAddress.getLocalHost().getHostAddress());
- } catch (Exception e) {
- MDC.put(MDC_SERVER_FQDN, e.getMessage());
- }
- MDC.put(MDC_SERVICE_INSTANCE_ID, "UNKNOWN");
- MDC.put(MDC_SERVICE_NAME, "cmso");
- // MDC.put(MDC_STATUS_CODE, "");
- setPartherTargetFromUri(request.getRequestURL().toString());
- // Override partner hostname with username
- MDC.put(MDC_PARTNER_NAME, BasicAuthenticatorFilter.getUser(request));
- // MDC.put(MDC_TARGET_ENTITY, "");
- // MDC.put(MDC_TARGET_SERVICE_NAME, "");
- // MDC.put(MDC_TARGET_VIRTUAL_ENTITY, "");
- MDC.put(Enum.ClassName.name(), getCaller(3));
- // MDC.put(MdcEnum.CustomField1.name(), "");
- // MDC.put(MdcEnum.CustomField2.name(), "");
- // MDC.put(MdcEnum.CustomField3.name(), "");
- // MDC.put(MdcEnum.CustomField4.name(), "");
- // MDC.put(MdcEnum.ErrorCode.name(), "");
- // MDC.put(MdcEnum.ErrorDescription.name(), "");
- // MDC.put(MdcEnum.Timer.name(), "");
- // MDC.put(MdcEnum.Unused.name(), "");
- // MDC.put(MdcEnum.VirtualServerName.name(), "");
-
- }
-
- private static void setRequestId(HttpServletRequest request, String requestId) {
-
- String transactionId = request.getHeader(MessageHeaders.HeadersEnum.TransactionID.toString());
- if (transactionId == null) {
- transactionId = requestId;
- }
- if (transactionId == null) {
- transactionId = "Unknown";
- }
- MDC.put(MDC_KEY_REQUEST_ID, transactionId);
- }
-
- /**
- * End.
- *
- * @param response the response
- */
- public static void end(Response response) {
- Stopwatch.stop();
- // MDC.put(MDC_ALERT_SEVERITY, "");
- // MDC.put(MDC_BEGIN_TIMESTAMP, Stopwatch.isoFormatter.format(new
- // Date()));
- MDC.put(MDC_ELAPSED_TIME, String.valueOf(Stopwatch.getDuration()));
- MDC.put(MDC_END_TIMESTAMP, Stopwatch.isoFormatter.format(new Date()));
- // MDC.put(MDC_INSTANCE_UUID, "");
- // MDC.put(MDC_KEY_REQUEST_ID, "");
- // MDC.put(MDC_PARTNER_NAME, "");
- // MDC.put(MDC_PROCESS_KEY, "");
- // MDC.put(MDC_REMOTE_HOST, "");
- MDC.put(MDC_RESPONSE_CODE, String.valueOf(response.getStatus()));
- MDC.put(MDC_RESPONSE_DESC, response.getStatusInfo().getReasonPhrase());
- // MDC.put(MDC_SERVICE_NAME, "");
- // MDC.put(MDC_SERVER_FQDN, "");
- // MDC.put(MDC_SERVER_IP_ADDRESS, "");
- // MDC.put(MDC_SERVICE_INSTANCE_ID, "");
- // MDC.put(MDC_SERVICE_NAME, "");
- MDC.put(MDC_STATUS_CODE, "COMPLETE");
- if (response.getStatus() == 500) {
- MDC.put(MDC_STATUS_CODE, "ERROR");
- }
- // MDC.put(MDC_TARGET_ENTITY, "");
- // MDC.put(MDC_TARGET_SERVICE_NAME, "");
- // MDC.put(MDC_TARGET_VIRTUAL_ENTITY, "");
- MDC.put(Enum.ClassName.name(), getCaller(3));
- // MDC.put(MdcEnum.CustomField1.name(), "");
- // MDC.put(MdcEnum.CustomField2.name(), "");
- // MDC.put(MdcEnum.CustomField3.name(), "");
- // MDC.put(MdcEnum.CustomField4.name(), "");
- // MDC.put(MdcEnum.ErrorCode.name(), "");
- // MDC.put(MdcEnum.ErrorDescription.name(), "");
- // MDC.put(MdcEnum.Timer.name(), "");
- // MDC.put(MdcEnum.Unused.name(), "");
- // MDC.put(MdcEnum.VirtualServerName.name(), "");
- }
public static String getCaller(int back) {
StackTraceElement[] stackTraceElements = Thread.currentThread().getStackTrace();
return stackTraceElements[back].getClassName() + "." + stackTraceElements[back].getMethodName();
}
- /**
- * Quartz job begin.
- *
- * @param context the context
- */
- public static void quartzJobBegin(JobExecutionContext context) {
- MDC.clear();
- Stopwatch.start();
- // MDC.put(MDC_ALERT_SEVERITY, "");
- MDC.put(MDC_BEGIN_TIMESTAMP, Stopwatch.isoFormatter.format(new Date()));
- // MDC.put(MDC_ELAPSED_TIME, String.valueOf(Stopwatch.getDuration()));
- // MDC.put(MDC_END_TIMESTAMP, "");
- MDC.put(MDC_INSTANCE_UUID, UUID.randomUUID().toString());
- // MDC.put(MDC_KEY_REQUEST_ID);
- // MDC.put(MDC_PARTNER_NAME, request.getRemoteUser());
- // MDC.put(MDC_PROCESS_KEY, "");
- // MDC.put(MDC_REMOTE_HOST, request.getRemoteHost());
- // MDC.put(MDC_RESPONSE_CODE, "");
- // MDC.put(MDC_RESPONSE_DESC, "");
- // MDC.put(MDC_SERVICE_NAME, "");
- try {
- MDC.put(MDC_SERVER_FQDN, InetAddress.getLocalHost().getHostName());
- } catch (Exception e) {
- MDC.put(MDC_SERVER_FQDN, e.getMessage());
- }
- try {
- MDC.put(MDC_SERVER_IP_ADDRESS, InetAddress.getLocalHost().getHostAddress());
- } catch (Exception e) {
- MDC.put(MDC_SERVER_FQDN, e.getMessage());
- }
- MDC.put(MDC_SERVICE_INSTANCE_ID, "UNKNOWN");
- MDC.put(MDC_SERVICE_NAME, "cmso");
- // MDC.put(MDC_STATUS_CODE, "");
- // MDC.put(MDC_TARGET_ENTITY, "");
- // MDC.put(MDC_TARGET_SERVICE_NAME, "");
- // MDC.put(MDC_TARGET_VIRTUAL_ENTITY, "");
- MDC.put(Enum.ClassName.name(), getCaller(3));
- // MDC.put(MdcEnum.CustomField1.name(), "");
- // MDC.put(MdcEnum.CustomField2.name(), "");
- // MDC.put(MdcEnum.CustomField3.name(), "");
- // MDC.put(MdcEnum.CustomField4.name(), "");
- // MDC.put(MdcEnum.ErrorCode.name(), "");
- // MDC.put(MdcEnum.ErrorDescription.name(), "");
- // MDC.put(MdcEnum.Timer.name(), "");
- // MDC.put(MdcEnum.Unused.name(), "");
- // MDC.put(MdcEnum.VirtualServerName.name(), "");
-
- }
-
- /**
- * Quartz job end.
- *
- * @param context the context
- */
- public static void quartzJobEnd(JobExecutionContext context) {
- Stopwatch.stop();
- // MDC.put(MDC_ALERT_SEVERITY, "");
- MDC.put(MDC_END_TIMESTAMP, Stopwatch.isoFormatter.format(new Date()));
- MDC.put(MDC_ELAPSED_TIME, String.valueOf(Stopwatch.getDuration()));
- // MDC.put(MDC_START_TIMESTAMP, "");
- // MDC.put(MDC_INSTANCE_UUID, UUID.randomUUID().toString());
- // MDC.put(MDC_KEY_REQUEST_ID);
- // MDC.put(MDC_PARTNER_NAME, request.getRemoteUser());
- // MDC.put(MDC_PROCESS_KEY, "");
- // MDC.put(MDC_REMOTE_HOST, request.getRemoteHost());
- // MDC.put(MDC_RESPONSE_CODE, "");
- // MDC.put(MDC_RESPONSE_DESC, "");
- // MDC.put(MDC_SERVICE_NAME, "");
- // try{ MDC.put(MDC_SERVER_FQDN, InetAddress.getLocalHost().getHostName()); }
- // catch (Exception e){ MDC.put(MDC_SERVER_FQDN, e.getMessage());}
- // try{ MDC.put(MDC_SERVER_IP_ADDRESS,
- // InetAddress.getLocalHost().getHostAddress()); } catch (Exception e){
- // MDC.put(MDC_SERVER_FQDN, e.getMessage());}
- // MDC.put(MDC_SERVICE_INSTANCE_ID, "UNKNOWN");
- // MDC.put(MDC_SERVICE_NAME, "cmso");
- // MDC.put(MDC_STATUS_CODE, "");
- // MDC.put(MDC_TARGET_ENTITY, "");
- // MDC.put(MDC_TARGET_SERVICE_NAME, "");
- // MDC.put(MDC_TARGET_VIRTUAL_ENTITY, "");
- MDC.put(Enum.ClassName.name(), getCaller(3));
- // MDC.put(MdcEnum.CustomField1.name(), "");
- // MDC.put(MdcEnum.CustomField2.name(), "");
- // MDC.put(MdcEnum.CustomField3.name(), "");
- // MDC.put(MdcEnum.CustomField4.name(), "");
- // MDC.put(MdcEnum.ErrorCode.name(), "");
- // MDC.put(MdcEnum.ErrorDescription.name(), "");
- // MDC.put(MdcEnum.Timer.name(), "");
- // MDC.put(MdcEnum.Unused.name(), "");
- // MDC.put(MdcEnum.VirtualServerName.name(), "");
-
- }
public static Map<String, String> save() {
Map<String, String> save = MDC.getCopyOfContextMap();
diff --git a/cmso-service/src/main/java/org/onap/optf/cmso/test/loopback/SchedulerTestLoopbackService.java b/cmso-service/src/main/java/org/onap/optf/cmso/test/loopback/SchedulerTestLoopbackService.java
deleted file mode 100644
index 0200520..0000000
--- a/cmso-service/src/main/java/org/onap/optf/cmso/test/loopback/SchedulerTestLoopbackService.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * Copyright © 2017-2018 AT&T Intellectual Property. Modifications Copyright © 2018 IBM.
- *
- * 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.
- *
- *
- * Unless otherwise specified, all documentation contained herein is licensed under the Creative
- * Commons License, Attribution 4.0 Intl. (the "License"); you may not use this documentation except
- * in compliance with the License. You may obtain a copy of the License at
- *
- * https://creativecommons.org/licenses/by/4.0/
- *
- * Unless required by applicable law or agreed to in writing, documentation 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.
- */
-
-package org.onap.optf.cmso.test.loopback;
-
-import io.swagger.annotations.Api;
-import io.swagger.annotations.ApiOperation;
-import io.swagger.annotations.ApiParam;
-import io.swagger.annotations.ApiResponse;
-import io.swagger.annotations.ApiResponses;
-import javax.ws.rs.GET;
-import javax.ws.rs.POST;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.core.UriInfo;
-import org.onap.optf.cmso.optimizer.model.OptimizerRequest;
-import org.onap.optf.cmso.optimizer.model.OptimizerResponse;
-import org.onap.optf.cmso.so.bean.MsoOrchestrationQueryResponse;
-import org.onap.optf.cmso.wf.bean.WfChangeManagementResponse;
-
-@Api
-@Path("/v1/loopbacktest")
-@Produces({MediaType.APPLICATION_JSON})
-public interface SchedulerTestLoopbackService {
- // ******************************************************************
- @POST
- @Path("/optimize/schedule")
- @Produces({MediaType.APPLICATION_JSON})
- @ApiOperation(value = "", notes = "Test Optimizer connection in loopback mode.")
- @ApiResponses(value = {@ApiResponse(code = 202, message = "OK"),
- @ApiResponse(code = 500, message = "Unexpected Runtime error", response = Exception.class)})
- public Response putToOptimizer(@ApiParam(value = "Optimizer request message") OptimizerRequest request,
- @Context UriInfo uri);
-
- // ******************************************************************
- @GET
- @Path("/optimize/schedule/{id}")
- @Produces({MediaType.APPLICATION_JSON})
- @ApiOperation(value = "", notes = "Test Optimizer connection in loopback mode.", response = OptimizerResponse.class)
- @ApiResponses(value = {@ApiResponse(code = 200, message = "OK"),
- @ApiResponse(code = 500, message = "Unexpected Runtime error", response = Exception.class)})
- public Response getOptimizerResponse(@ApiParam(value = "Optimizer request is") @PathParam("id") String id,
- @Context UriInfo uri);
-
- // ******************************************************************
- @POST
- @Path("/onap/so/infra/orchestrationRequests/v7/schedule/{vnfName}")
- @Produces({MediaType.APPLICATION_JSON})
- @ApiOperation(value = "", notes = "Test SO sheduling in loopback mode.",
- response = WfChangeManagementResponse.class)
- @ApiResponses(value = {@ApiResponse(code = 200, message = "OK"),
- @ApiResponse(code = 500, message = "Unexpected Runtime error", response = Exception.class)})
- public Response soScheduleLoopback(@ApiParam(value = "vnfName") @PathParam("vnfName") String vnfName,
- @ApiParam(value = "SO request message") String request, @Context UriInfo uri);
-
- // ******************************************************************
- @GET
- @Path("/onap/so/infra/orchestrationRequests/v7/{requestId}")
- @Produces({MediaType.APPLICATION_JSON})
- @ApiOperation(value = "", notes = "Test SO Status query loopback.", response = MsoOrchestrationQueryResponse.class)
- @ApiResponses(value = {@ApiResponse(code = 200, message = "OK"),
- @ApiResponse(code = 500, message = "Unexpected Runtime error", response = Exception.class)})
- public Response soQueryLoopback(@ApiParam(value = "MSO request ID") @PathParam("requestId") String requestId,
- @Context UriInfo uri);
-
-}
diff --git a/cmso-service/src/main/java/org/onap/optf/cmso/test/loopback/SchedulerTestLoopbackServiceImpl.java b/cmso-service/src/main/java/org/onap/optf/cmso/test/loopback/SchedulerTestLoopbackServiceImpl.java
deleted file mode 100644
index a834878..0000000
--- a/cmso-service/src/main/java/org/onap/optf/cmso/test/loopback/SchedulerTestLoopbackServiceImpl.java
+++ /dev/null
@@ -1,238 +0,0 @@
-/*
- * Copyright © 2017-2018 AT&T Intellectual Property. Modifications Copyright © 2018 IBM.
- *
- * 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.
- *
- *
- * Unless otherwise specified, all documentation contained herein is licensed under the Creative
- * Commons License, Attribution 4.0 Intl. (the "License"); you may not use this documentation except
- * in compliance with the License. You may obtain a copy of the License at
- *
- * https://creativecommons.org/licenses/by/4.0/
- *
- * Unless required by applicable law or agreed to in writing, documentation 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.
- */
-
-package org.onap.optf.cmso.test.loopback;
-
-import com.att.eelf.configuration.EELFLogger;
-import com.att.eelf.configuration.EELFManager;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.UUID;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.core.Response.Status;
-import javax.ws.rs.core.UriInfo;
-import org.joda.time.DateTime;
-import org.onap.observations.Observation;
-import org.onap.optf.cmso.common.LogMessages;
-import org.onap.optf.cmso.common.PropertiesManagement;
-import org.onap.optf.cmso.common.exceptions.CmsoException;
-import org.onap.optf.cmso.optimizer.model.OptimizerElementInfo;
-import org.onap.optf.cmso.optimizer.model.OptimizerRequest;
-import org.onap.optf.cmso.optimizer.model.OptimizerResponse;
-import org.onap.optf.cmso.optimizer.model.OptimizerScheduleInfo;
-import org.onap.optf.cmso.optimizer.model.ScheduledElement;
-import org.onap.optf.cmso.optimizer.model.ScheduledElement.ScheduleType;
-import org.onap.optf.cmso.optimizer.model.UnScheduledElement;
-import org.onap.optf.cmso.service.rs.models.v2.ChangeWindow;
-import org.onap.optf.cmso.wf.bean.WfCmResponse200;
-import org.onap.optf.cmso.wf.bean.WfMsoRequestReferences;
-import org.onap.optf.cmso.wf.bean.WfMsoResponse;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.core.env.Environment;
-import org.springframework.stereotype.Controller;
-
-@Controller
-public class SchedulerTestLoopbackServiceImpl implements SchedulerTestLoopbackService {
- private static EELFLogger log = EELFManager.getInstance().getLogger(SchedulerTestLoopbackServiceImpl.class);
- private static EELFLogger debug = EELFManager.getInstance().getDebugLogger();
-
- @Autowired
- Environment env;
-
- @Autowired
- PropertiesManagement pm;
-
- // **
- // This is test mode only code.
- private static Map<String, String> optimizerResponses = new HashMap<>();
-
- @Override
- public Response putToOptimizer(OptimizerRequest request, UriInfo uri) {
- //
- try {
- OptimizerResponse rsp = new OptimizerResponse();
- rsp.setRequestId(request.getRequestId());
- rsp.setStatus(OptimizerResponse.OptimizeScheduleStatus.COMPLETED);
- List<OptimizerScheduleInfo> schedules = getSchedules(request);
- rsp.setSchedules(schedules);
- ObjectMapper om = new ObjectMapper();
- String response = om.writeValueAsString(rsp);
- optimizerResponses.put(rsp.getRequestId(), response);
- return Response.accepted().build();
- } catch (Exception e) {
- log.error("Unexpected exception", e);
- }
- return Response.serverError().build();
- }
-
- private List<OptimizerScheduleInfo> getSchedules(OptimizerRequest request) {
- List<OptimizerScheduleInfo> list = new ArrayList<>();
- OptimizerScheduleInfo osi = new OptimizerScheduleInfo();
- List<ScheduledElement> scheduledList = new ArrayList<>();
- List<UnScheduledElement> unscheduledList = new ArrayList<>();
- osi.setScheduledElements(scheduledList);
- osi.setUnScheduledElements(unscheduledList);
- list.add(osi);
-
-
- List<ChangeWindow> cws = request.getChangeWindows();
- // Assume we cannot get here without at least 1 CW
- ChangeWindow cw = cws.get(0);
-
- // This is a dumb opt. WIll not make sense for multiple groups
- // Use the code in the callback to help
- Map<String, String> nodes = new HashMap<>();
- List<String> nodeList = new ArrayList<>();
- // get total number of nodes across all groups.
- for (OptimizerElementInfo sr : request.getElements()) {
- nodes.put(sr.getElementId(), sr.getGroupId());
- nodeList.add(sr.getElementId());
- }
-
- DateTime startTime = new DateTime(cw.getStartTime().getTime());
-
-
- long add = request.getAdditionalDuration() * 1000L;
- long normal = request.getNormalDuration() * 1000L;
- int concurrencyLimit = request.getConcurrencyLimit();
- long totalDuration = add + normal;
- long serialized = 0;
- if (nodes.size() > concurrencyLimit) {
- serialized = (nodes.size() / concurrencyLimit);
- serialized = (serialized * totalDuration);
- }
- DateTime latestInstanceStartTime = startTime.plus(serialized);
- // Reformat request into a response setting the groups start finish
- // time based upon
-
- Map<String, Map<String, Long>> startAndFinishTimeMap = new HashMap<String, Map<String, Long>>();
- try {
- makeMap(startTime.getMillis(), latestInstanceStartTime.getMillis(),
- concurrencyLimit, totalDuration, nodeList, startAndFinishTimeMap);
- for (String node : nodes.keySet()) {
- Map<String, Long> map = startAndFinishTimeMap.get(node);
- Long nodeStart = map.get("startTime");
- Long nodeEnd = map.get("finishTime");
- ScheduledElement se = new ScheduledElement();
- se.setElementId(node);
- se.setDurationSeconds((nodeEnd - nodeStart) / 1000); // in seconds
- se.setStartTime(new Date(nodeStart));
- se.setEndTime(new Date(nodeEnd));
- se.setScheduleType(ScheduleType.INDIVIDUAL);
- se.setGroupId(nodes.get(node));
- scheduledList.add(se);
- }
- } catch (Exception e) {
- Observation.report(LogMessages.EXPECTED_EXCEPTION, e, e.getMessage());
- }
-
- return list;
- }
-
- @Override
- public Response getOptimizerResponse(String id, UriInfo uri) {
- //
- try {
- String rsp = optimizerResponses.get(id);
- return Response.ok(rsp).build();
- } catch (Exception e) {
- log.error("Unexpected exception", e);
- }
- return Response.serverError().build();
- }
-
-
- @Override
- public Response soScheduleLoopback(String vnfName, String request, UriInfo uri) {
- String msoRequestId = env.getProperty("loopback.mso.requestId", "4ccbfb85-1d05-442e");
- String ruuid = UUID.randomUUID().toString();
- WfMsoRequestReferences rr = new WfMsoRequestReferences();
- rr.setInstanceId(ruuid);
- rr.setRequestId(msoRequestId);
- WfMsoResponse mso = new WfMsoResponse();
- mso.setRequestReferences(rr);
- WfCmResponse200 cmResponse = new WfCmResponse200();
- cmResponse.setEntity(mso);
- cmResponse.setStatus(202);;
- return Response.status(Status.OK).entity(cmResponse).build();
- }
-
- @Override
- public Response soQueryLoopback(String requestId, UriInfo uri) {
- // Abbreviated response. Only interested in requestStatus....
- String response = "{\"request\" : {" + "\"requestId\" : \"dummy-request-id\","
- + "\"startTime\" : \"Wed, 26 Aug 2017 06:36:07 GMT\"," + "\"requestScope\" : \"vfModule\","
- + "\"requestType\" : \"createInstance\"," + "\"requestDetails\" : {},"
- + "\"instanceReferences\" : {}," + "\"requestStatus\" : { " + "\"requestState\" : \"COMPLETE\","
- + "\"statusMessage\" : \"Vf Module has been created successfully.\","
- + "\"percentProgress\" : 100," + "\"finishTime\" : \"Crap so cmso uses current time\"}}}";
- return Response.ok().entity(response).build();
- }
-
- /**
- * Make map.
- *
- * @param startTime the start time
- * @param latestInstanceStartTime the latest instance start time
- * @param concurrencyLimit the concurrency limit
- * @param totalDuration the total duration
- * @param nodeList the node list
- * @param startAndFinishTimeMap the start and finish time map
- * @throws CmsoException the CMS exception
- */
- public static void makeMap(Long startTime, Long latestInstanceStartTime, int concurrencyLimit, long totalDuration,
- List<String> nodeList, Map<String, Map<String, Long>> startAndFinishTimeMap) throws CmsoException {
- Long nextStartTime = null;
- Long nextFinishTime = null;
- for (int nodeNumber = 0; nodeNumber < nodeList.size(); nodeNumber++) {
- if (nodeNumber % concurrencyLimit == 0) {
- if (nodeNumber == 0) {
- nextStartTime = startTime;
- }
- else {
- nextStartTime = nextStartTime + totalDuration;
- }
- if (nextStartTime > latestInstanceStartTime) {
- throw new CmsoException(Status.BAD_REQUEST, LogMessages.UNABLE_TO_ALLOCATE_VNF_TIMESLOTS,
- startTime.toString(), latestInstanceStartTime.toString(), String.valueOf(totalDuration),
- String.valueOf(concurrencyLimit), String.valueOf(nodeList.size()));
- }
- nextFinishTime = nextStartTime + totalDuration;
- }
- Map<String, Long> map = new HashMap<String, Long>();
- map.put("startTime", nextStartTime);
- map.put("finishTime", nextFinishTime);
- String node = nodeList.get(nodeNumber);
- startAndFinishTimeMap.put(node, map);
- }
-
- }
-
-}