2 * ================================================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ================================================================================
20 package org.openecomp.portalapp.service.sessionmgt;
22 import java.util.Calendar;
23 import java.util.Date;
24 import java.util.List;
26 import org.openecomp.portalapp.portal.logging.aop.EPMetricsLog;
27 import org.openecomp.portalapp.portal.service.EPAppService;
28 import org.openecomp.portalapp.portal.transport.OnboardingApp;
29 import org.openecomp.portalapp.portal.utils.EcompPortalUtils;
30 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
31 import org.openecomp.portalsdk.core.onboarding.listener.PortalTimeoutHandler;
32 import org.openecomp.portalsdk.core.util.SystemProperties;
33 import org.quartz.CronExpression;
34 import org.springframework.beans.factory.annotation.Autowired;
35 import org.springframework.context.annotation.EnableAspectJAutoProxy;
36 import org.springframework.stereotype.Service;
37 import org.springframework.util.StringUtils;
39 @Service("manageService")
40 @org.springframework.context.annotation.Configuration
41 @EnableAspectJAutoProxy
43 public class ManageService implements PortalTimeoutHandler.SessionCommInf {
44 EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(ManageService.class);
47 EPAppService appService;
50 SessionCommunication sessionCommunication;
52 public Integer fetchSessionSlotCheckInterval(String... params) throws Exception {
54 String defaultCronExpressionStr = "0 0/5 * * * ? *";
55 String cronExpressionStr = SystemProperties.getProperty(SystemProperties.SESSIONTIMEOUT_FEED_CRON);
57 if (cronExpressionStr == null) {
58 cronExpressionStr = defaultCronExpressionStr;
61 CronExpression cal = new CronExpression(cronExpressionStr);
62 final Date nowTime = Calendar.getInstance().getTime();
63 Date nextTime = cal.getNextValidTimeAfter(nowTime);
64 Date nextNextTime = cal.getNextValidTimeAfter(nextTime);
66 final int timeDiff = (int)(nextNextTime.getTime()-nextTime.getTime());
67 logger.debug(EELFLoggerDelegate.debugLogger, "Time interval between subsequent session checks " + timeDiff);
72 public void extendSessionTimeOuts(String... params) throws Exception {
74 String sessionMap = params[3];
76 logger.debug(EELFLoggerDelegate.debugLogger, "Extending the App sessions for last minute request: " + sessionMap);
78 if (StringUtils.isEmpty(sessionMap)) {
79 logger.error(EELFLoggerDelegate.errorLogger, "extendSessionTimeOuts: Skipping session updates since the portal session value is empty.");
81 List<OnboardingApp> appList = appService.getEnabledNonOpenOnboardingApps();
82 for (OnboardingApp onApp : appList) {
83 sessionCommunication.pingSession(onApp, sessionMap);
85 updateSessionExtensions(sessionMap);
86 sessionCommunication.clear(false);
88 } catch (Exception e) {
89 logger.error(EELFLoggerDelegate.errorLogger, "Exception occurred in extendSessionTimeOuts(). Details: " + EcompPortalUtils.getStackTrace(e));
93 public String gatherSessionExtenstions() {
94 return PortalTimeoutHandler.gatherSessionExtensions();
97 public void updateSessionExtensions(String sessionTimeoutMapStr) throws Exception {
98 PortalTimeoutHandler.updateSessionExtensions(sessionTimeoutMapStr);