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.portalapp.portal.controller;
40 import java.util.UUID;
42 import javax.servlet.http.HttpServletRequest;
44 import org.json.simple.JSONObject;
45 import org.onap.portalapp.controller.EPRestrictedBaseController;
46 import org.onap.portalapp.portal.logging.aop.EPAuditLog;
47 import org.onap.portalapp.portal.logging.logic.EPLogUtil;
48 import org.onap.portalapp.portal.scheduler.SchedulerProperties;
49 import org.onap.portalapp.portal.scheduleraux.RestObject;
50 import org.onap.portalapp.portal.scheduleraux.SchedulerAuxResponseWrapper;
51 import org.onap.portalapp.portal.scheduleraux.SchedulerAuxRestInterfaceFactory;
52 import org.onap.portalapp.portal.scheduleraux.SchedulerAuxRestInterfaceIfc;
53 import org.onap.portalapp.portal.scheduleraux.SchedulerAuxUtil;
54 import org.onap.portalapp.portal.utils.PortalConstants;
55 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
56 import org.springframework.context.annotation.Configuration;
57 import org.springframework.context.annotation.EnableAspectJAutoProxy;
58 import org.springframework.http.HttpStatus;
59 import org.springframework.http.ResponseEntity;
60 import org.springframework.web.bind.annotation.RequestMapping;
61 import org.springframework.web.bind.annotation.GetMapping;
62 import org.springframework.web.bind.annotation.RequestMethod;
63 import org.springframework.web.bind.annotation.RestController;
66 * Controller to handle Policy requests.
70 @RequestMapping(PortalConstants.PORTAL_AUX_API)
72 @EnableAspectJAutoProxy
74 public class SchedulerAuxController extends EPRestrictedBaseController {
77 private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(SchedulerAuxController.class);
79 @GetMapping(value = "/get_policy", produces = "application/json")
80 public ResponseEntity<String> getPolicyInfo(HttpServletRequest request) throws Exception {
83 logger.debug(EELFLoggerDelegate.debugLogger,
84 "SchedulerAux Controller Call Started: " + SchedulerProperties.SCHEDULERAUX_GET_CONFIG_VAL);
85 String path = SchedulerProperties.getProperty(SchedulerProperties.SCHEDULERAUX_GET_CONFIG_VAL);
86 SchedulerAuxResponseWrapper policyResWrapper = getPolicyConfig(path);
88 logger.debug(EELFLoggerDelegate.debugLogger, "SchedulerAux Request END : Response: ",
89 new ResponseEntity<String>(policyResWrapper.getResponse(), HttpStatus.OK).toString());
91 return (new ResponseEntity<String>(policyResWrapper.getResponse(),
92 HttpStatus.valueOf(policyResWrapper.getStatus())));
93 } catch (Exception e) {
94 SchedulerAuxResponseWrapper policyResWrapper = new SchedulerAuxResponseWrapper();
95 policyResWrapper.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
96 policyResWrapper.setEntity(e.getMessage());
97 logger.error(EELFLoggerDelegate.errorLogger, "Exception with getpolicy ", e);
98 return (new ResponseEntity<String>(policyResWrapper.getResponse(), HttpStatus.INTERNAL_SERVER_ERROR));
102 protected static SchedulerAuxResponseWrapper getPolicyConfig(String path) throws Exception {
103 String methodName = "getPolicyConfig";
104 String uuid = UUID.randomUUID().toString();
105 logger.debug(EELFLoggerDelegate.debugLogger, "starting getPolicyConfig ");
108 // STARTING REST API CALL AS AN FACTORY INSTACE
109 SchedulerAuxRestInterfaceIfc policyRestController = SchedulerAuxRestInterfaceFactory.getInstance();
110 JSONObject request = new JSONObject();
111 String policyName = SchedulerProperties.getProperty(SchedulerProperties.SCHEDULER_POLICY_NAME);
112 request.put("policyName", policyName);
113 RestObject<String> restObjStr = new RestObject<String>();
114 String str = new String();
116 policyRestController.<String>Post(str, request, uuid, path, restObjStr);
117 SchedulerAuxResponseWrapper policyRespWrapper = SchedulerAuxUtil.wrapResponse(restObjStr);
118 logger.debug(EELFLoggerDelegate.debugLogger, "Getpolicy Request END : Response: ", methodName,
119 policyRespWrapper.getResponse());
120 if (policyRespWrapper.getStatus() != 200) {
121 String message = String.format(
122 " get policy Information failed . MethodName: %s, PolicyRespWrapperResponse: %s", methodName,
123 policyRespWrapper.getResponse());
124 logger.error(EELFLoggerDelegate.errorLogger, message);
125 EPLogUtil.schedulerAccessAlarm(logger, policyRespWrapper.getStatus());
127 return policyRespWrapper;
128 } catch (Exception e) {
129 String message = String.format(" EXCEPTION in getPolicyConfig . MethodName: %s and Exception: %s", methodName, e);
130 logger.error(EELFLoggerDelegate.errorLogger, "EXCEPTION in getPolicyConfig", message);