2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 * ===================================================================
8 * Unless otherwise specified, all software contained herein is licensed
9 * under the Apache License, Version 2.0 (the “License”);
10 * you may not use this software except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * Unless otherwise specified, all documentation contained herein is licensed
22 * under the Creative Commons License, Attribution 4.0 Intl. (the “License”);
23 * you may not use this documentation except in compliance with the License.
24 * You may obtain a copy of the License at
26 * https://creativecommons.org/licenses/by/4.0/
28 * Unless required by applicable law or agreed to in writing, documentation
29 * distributed under the License is distributed on an "AS IS" BASIS,
30 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 * See the License for the specific language governing permissions and
32 * limitations under the License.
34 * ============LICENSE_END============================================
36 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
38 package org.openecomp.portalapp.portal.controller;
40 import java.text.DateFormat;
41 import java.text.SimpleDateFormat;
42 import java.util.Date;
43 import java.util.UUID;
45 import javax.servlet.http.HttpServletRequest;
47 import org.json.simple.JSONObject;
48 import org.openecomp.portalapp.portal.logging.aop.EPAuditLog;
49 import org.openecomp.portalapp.portal.scheduler.SchedulerProperties;
50 import org.openecomp.portalapp.portal.scheduler.SchedulerRestInterface;
51 import org.openecomp.portalapp.portal.scheduler.SchedulerUtil;
52 import org.openecomp.portalapp.portal.scheduler.restobjects.GetTimeSlotsRestObject;
53 import org.openecomp.portalapp.portal.scheduler.restobjects.PostCreateNewVnfRestObject;
54 import org.openecomp.portalapp.portal.scheduler.restobjects.PostSubmitVnfChangeRestObject;
55 import org.openecomp.portalapp.portal.scheduler.wrapper.GetTimeSlotsWrapper;
56 import org.openecomp.portalapp.portal.scheduler.wrapper.PostCreateNewVnfWrapper;
57 import org.openecomp.portalapp.portal.scheduler.wrapper.PostSubmitVnfChangeTimeSlotsWrapper;
58 import org.openecomp.portalapp.portal.utils.PortalConstants;
59 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
60 import org.openecomp.portalsdk.core.util.SystemProperties;
61 import org.springframework.beans.factory.annotation.Autowired;
62 import org.springframework.context.annotation.Configuration;
63 import org.springframework.context.annotation.EnableAspectJAutoProxy;
64 import org.springframework.http.HttpStatus;
65 import org.springframework.http.ResponseEntity;
66 import org.springframework.web.bind.annotation.PathVariable;
67 import org.springframework.web.bind.annotation.RequestBody;
68 import org.springframework.web.bind.annotation.RequestMapping;
69 import org.springframework.web.bind.annotation.RequestMethod;
70 import org.springframework.web.bind.annotation.RestController;
73 @RequestMapping(PortalConstants.REST_AUX_API)
75 @EnableAspectJAutoProxy
77 public class SchedulerController implements BasicAuthenticationController {
80 private SchedulerRestInterface schedulerRestController;
82 private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(SchedulerController.class);
84 /** The request date format. */
85 public DateFormat requestDateFormat = new SimpleDateFormat("EEE, dd MMM YYYY HH:mm:ss z");
87 @RequestMapping(value = "/get_time_slots/{scheduler_request}", method = RequestMethod.GET)
88 public ResponseEntity<String> getTimeSlots(HttpServletRequest request,
89 @PathVariable("scheduler_request") String scheduler_request) throws Exception {
91 Date startingTime = new Date();
92 String startTimeRequest = requestDateFormat.format(startingTime);
94 System.out.println("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
95 System.out.println(startTimeRequest + " | Controller Scheduler GET : /get_time_slots/{scheduler_request} \n");
96 System.out.println("Original Request : \n " + scheduler_request + '\n');
98 String path = SystemProperties.getProperty(SchedulerProperties.SCHEDULER_GET_TIME_SLOTS) + scheduler_request;
100 GetTimeSlotsWrapper schedulerResWrapper = getTimeSlots(scheduler_request, path, scheduler_request);
102 Date endTime = new Date();
103 String endTimeRequest = requestDateFormat.format(endTime);
104 System.out.println(endTimeRequest + " | Controller Scheduler - GET\n");
106 return (new ResponseEntity<String>(schedulerResWrapper.getResponse(), HttpStatus.OK));
110 protected GetTimeSlotsWrapper getTimeSlots(String request, String path, String uuid) throws Exception {
113 // STARTING REST API CALL AS AN FACTORY INSTACE
114 System.out.println("<== Get Time Slots Request START \n");
116 GetTimeSlotsRestObject<String> restObjStr = new GetTimeSlotsRestObject<String>();
117 String str = new String();
121 schedulerRestController.Get(str, uuid, path, restObjStr);
122 GetTimeSlotsWrapper schedulerRespWrapper = SchedulerUtil.getTimeSlotsWrapResponse(restObjStr);
125 "<== Get Time Slots Request END : Response = " + schedulerRespWrapper.getResponse() + '\n');
127 return schedulerRespWrapper;
129 } catch (Exception e) {
130 System.out.println("<== Get Time Slots Request ERROR : " + e.toString() + '\n');
131 logger.error(EELFLoggerDelegate.errorLogger, "Get Time Slots Request failed", e);
136 @SuppressWarnings("unchecked")
137 @RequestMapping(value = "/post_create_new_vnf_change", method = RequestMethod.POST)
138 public ResponseEntity<String> postCreateNewVNFChange(HttpServletRequest request,
139 @RequestBody JSONObject scheduler_request) throws Exception {
141 Date startingTime = new Date();
142 String startTimeRequest = requestDateFormat.format(startingTime);
144 System.out.println("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
145 System.out.println(startTimeRequest + " | Controller Scheduler POST : post_create_new_vnf_change \n");
148 String uuid = UUID.randomUUID().toString();
150 scheduler_request.put("scheduleId", uuid);
151 System.out.println("<== UUID : " + uuid + '\n');
153 // adding uuid to the request payload
154 scheduler_request.put("scheduleId", uuid);
156 System.out.println("<== UUID : " + uuid + '\n');
157 System.out.println("Original Request : \n " + scheduler_request.toString() + '\n');
159 String path = SystemProperties.getProperty(SchedulerProperties.SCHEDULER_CREATE_NEW_VNF_CHANGE_INSTANCE_VAL)
162 PostCreateNewVnfWrapper responseWrapper = postSchedulingRequest(scheduler_request, path, uuid);
164 Date endTime = new Date();
165 String endTimeRequest = requestDateFormat.format(endTime);
166 System.out.println(endTimeRequest + " | Controller Scheduler - POST\n");
168 return (new ResponseEntity<String>(responseWrapper.getResponse(), HttpStatus.OK));
171 protected PostCreateNewVnfWrapper postSchedulingRequest(JSONObject request, String path, String uuid)
175 // STARTING REST API CALL AS AN FACTORY INSTACE
176 System.out.println("<== Post Create New Vnf Scheduling Request START \n");
178 PostCreateNewVnfRestObject<String> restObjStr = new PostCreateNewVnfRestObject<String>();
179 String str = new String();
182 schedulerRestController.<String>Post(str, request, path, restObjStr);
184 int status = restObjStr.getStatusCode();
185 if (status >= 200 && status <= 299) {
186 restObjStr.setUUID(uuid);
189 PostCreateNewVnfWrapper responseWrapper = SchedulerUtil.postCreateNewVnfWrapResponse(restObjStr);
191 System.out.println("<== Post Create New Vnf Scheduling Request END : Response = "
192 + responseWrapper.getResponse() + '\n');
194 return responseWrapper;
196 } catch (Exception e) {
197 System.out.println("<== Post Create New Vnf Scheduling Request ERROR : " + e.toString() + '\n');
198 logger.error(EELFLoggerDelegate.errorLogger, "Post Create New Vnf Scheduling Request failed", e);
203 @RequestMapping(value = "/submit_vnf_change_timeslots", method = RequestMethod.POST)
204 public ResponseEntity<String> postSubmitVnfChangeTimeslots(HttpServletRequest request,
205 @RequestBody JSONObject scheduler_request) throws Exception {
207 Date startingTime = new Date();
208 String startTimeRequest = requestDateFormat.format(startingTime);
210 System.out.println("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
211 System.out.println(startTimeRequest + " | Controller Scheduler POST : submit_vnf_change_timeslots \n");
214 String uuid = (String) scheduler_request.get("scheduleId");
215 scheduler_request.remove("scheduleId");
217 System.out.println("<== UUID : " + uuid + '\n');
218 System.out.println("Original Request : \n " + scheduler_request.toString() + '\n');
220 String path = SystemProperties.getProperty(SchedulerProperties.SCHEDULER_SUBMIT_NEW_VNF_CHANGE)
221 .replace("{scheduleId}", uuid);
223 PostSubmitVnfChangeTimeSlotsWrapper responseWrapper = postSubmitSchedulingRequest(scheduler_request, path,
226 Date endTime = new Date();
227 String endTimeRequest = requestDateFormat.format(endTime);
228 System.out.println(endTimeRequest + " | Controller Scheduler - POST Submit\n");
230 return (new ResponseEntity<String>(responseWrapper.getResponse(), HttpStatus.OK));
233 protected PostSubmitVnfChangeTimeSlotsWrapper postSubmitSchedulingRequest(JSONObject request, String path,
234 String uuid) throws Exception {
237 // STARTING REST API CALL AS AN FACTORY INSTACE
238 System.out.println("<== Post Submit Scheduling Request START \n");
240 PostSubmitVnfChangeRestObject<String> restObjStr = new PostSubmitVnfChangeRestObject<String>();
241 String str = new String();
244 schedulerRestController.<String>Post(str, request, path, restObjStr);
246 int status = restObjStr.getStatusCode();
247 if (status >= 200 && status <= 299) {
248 restObjStr.setUUID(uuid);
251 PostSubmitVnfChangeTimeSlotsWrapper responseWrapper = SchedulerUtil
252 .postSubmitNewVnfWrapResponse(restObjStr);
255 "<== Post Submit Scheduling Request END : Response = " + responseWrapper.getResponse() + '\n');
257 return responseWrapper;
259 } catch (Exception e) {
260 System.out.println("<== Post Submit Scheduling Request ERROR : " + e.toString() + '\n');
261 logger.error(EELFLoggerDelegate.errorLogger, "Post Submit Scheduling Request failed", e);