2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright (C) 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============================================
38 package org.onap.portal.controller;
40 import java.util.UUID;
41 import javax.servlet.http.HttpServletRequest;
42 import org.json.JSONObject;
43 import org.onap.portal.logging.aop.EPAuditLog;
44 import org.onap.portal.logging.logic.EPLogUtil;
45 import org.onap.portal.scheduler.SchedulerProperties;
46 import org.onap.portal.scheduler.restobjects.RestObject;
47 import org.onap.portal.scheduler.scheduleraux.SchedulerAuxResponseWrapper;
48 import org.onap.portal.scheduler.scheduleraux.SchedulerAuxRestInterface;
49 import org.onap.portal.scheduler.scheduleraux.SchedulerAuxUtil;
50 import org.onap.portal.utils.PortalConstants;
51 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
52 import org.springframework.context.annotation.Configuration;
53 import org.springframework.context.annotation.EnableAspectJAutoProxy;
54 import org.springframework.http.HttpStatus;
55 import org.springframework.http.ResponseEntity;
56 import org.springframework.web.bind.annotation.RequestMapping;
57 import org.springframework.web.bind.annotation.RequestMethod;
58 import org.springframework.web.bind.annotation.RestController;
61 @RequestMapping(PortalConstants.PORTAL_AUX_API)
63 @EnableAspectJAutoProxy
65 public class SchedulerAuxController {
67 private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(SchedulerAuxController.class);
69 @RequestMapping(value = "/get_policy", method = RequestMethod.GET, produces = "application/json")
70 public ResponseEntity<String> getPolicyInfo(HttpServletRequest request) throws Exception {
73 logger.debug(EELFLoggerDelegate.debugLogger,
74 "SchedulerAux Controller Call Started: " + SchedulerProperties.SCHEDULERAUX_GET_CONFIG_VAL);
75 String path = SchedulerProperties.getProperty(SchedulerProperties.SCHEDULERAUX_GET_CONFIG_VAL);
76 SchedulerAuxResponseWrapper policyResWrapper = getPolicyConfig(path);
78 logger.debug(EELFLoggerDelegate.debugLogger, "SchedulerAux Request END : Response: ",
79 new ResponseEntity<>(policyResWrapper.getResponse(), HttpStatus.OK).toString());
81 return (new ResponseEntity<>(policyResWrapper.getResponse(),
82 HttpStatus.valueOf(policyResWrapper.getStatus())));
83 } catch (Exception e) {
84 SchedulerAuxResponseWrapper policyResWrapper = new SchedulerAuxResponseWrapper();
85 policyResWrapper.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
86 policyResWrapper.setEntity(e.getMessage());
87 logger.error(EELFLoggerDelegate.errorLogger, "Exception with getpolicy ", e);
88 return (new ResponseEntity<>(policyResWrapper.getResponse(), HttpStatus.INTERNAL_SERVER_ERROR));
92 private static SchedulerAuxResponseWrapper getPolicyConfig(String path) throws Exception {
93 String methodName = "getPolicyConfig";
94 String uuid = UUID.randomUUID().toString();
95 logger.debug(EELFLoggerDelegate.debugLogger, "starting getPolicyConfig ");
98 SchedulerAuxRestInterface policyRestController = new SchedulerAuxRestInterface();
99 JSONObject request = new JSONObject();
100 String policyName = SchedulerProperties.getProperty(SchedulerProperties.SCHEDULER_POLICY_NAME);
101 request.put("policyName", policyName);
102 RestObject<String> restObjStr = new RestObject<>();
104 restObjStr.setT(str);
105 policyRestController.post(str, request, uuid, path, restObjStr);
106 SchedulerAuxResponseWrapper policyRespWrapper = SchedulerAuxUtil.wrapResponse(restObjStr);
107 logger.debug(EELFLoggerDelegate.debugLogger, "Getpolicy Request END : Response: ", methodName,
108 policyRespWrapper.getResponse());
109 if (policyRespWrapper.getStatus() != 200) {
110 String message = String.format(
111 " get policy Information failed . MethodName: %s, PolicyRespWrapperResponse: %s", methodName,
112 policyRespWrapper.getResponse());
113 logger.error(EELFLoggerDelegate.errorLogger, message);
114 EPLogUtil.schedulerAccessAlarm(logger, policyRespWrapper.getStatus());
116 return policyRespWrapper;
117 } catch (Exception e) {
118 String message = String
119 .format(" EXCEPTION in getPolicyConfig . MethodName: %s and Exception: %s", methodName, e);
120 logger.error(EELFLoggerDelegate.errorLogger, "EXCEPTION in getPolicyConfig", message);