summaryrefslogtreecommitdiffstats
path: root/ecomp-portal-BE-common/src/main
diff options
context:
space:
mode:
authorChristopher Lott (cl778h) <clott@research.att.com>2017-07-10 14:04:15 -0400
committerChristopher Lott (cl778h) <clott@research.att.com>2017-07-10 14:10:04 -0400
commit99565bb6bd87cfc46591cea73985c58c3a3697dd (patch)
tree3d90220524af46b157a3fc9d7c555c711452c139 /ecomp-portal-BE-common/src/main
parentfec1ab242c9086a32b04e3ded4518dd20eeca7d3 (diff)
[PORTAL-20,PORTAL-23,PORTAL-32] Repair defects
PORTAL-20: remove mariadb client reference from be-common pom PORTAL-23: Release Portal's SDK version 1.1.0 PORTAL-32: API URL correction for onboarded Apps Change-Id: If75b54ca9202f94ce63c59343b94384da1040912 Signed-off-by: Christopher Lott (cl778h) <clott@research.att.com>
Diffstat (limited to 'ecomp-portal-BE-common/src/main')
-rw-r--r--ecomp-portal-BE-common/src/main/java/org/openecomp/portalapp/portal/controller/UserRecommendationController.java87
-rw-r--r--ecomp-portal-BE-common/src/main/java/org/openecomp/portalapp/portal/listener/HealthMonitor.java76
-rw-r--r--ecomp-portal-BE-common/src/main/java/org/openecomp/portalapp/portal/service/UserRolesCommonServiceImpl.java32
-rw-r--r--ecomp-portal-BE-common/src/main/webapp/WEB-INF/fusion/orm/EP.hbm.xml16
4 files changed, 72 insertions, 139 deletions
diff --git a/ecomp-portal-BE-common/src/main/java/org/openecomp/portalapp/portal/controller/UserRecommendationController.java b/ecomp-portal-BE-common/src/main/java/org/openecomp/portalapp/portal/controller/UserRecommendationController.java
deleted file mode 100644
index 3ec06ed3..00000000
--- a/ecomp-portal-BE-common/src/main/java/org/openecomp/portalapp/portal/controller/UserRecommendationController.java
+++ /dev/null
@@ -1,87 +0,0 @@
-package org.openecomp.portalapp.portal.controller;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.openecomp.portalapp.controller.EPRestrictedBaseController;
-import org.openecomp.portalapp.portal.domain.EPUser;
-import org.openecomp.portalapp.portal.logging.aop.EPAuditLog;
-import org.openecomp.portalapp.portal.service.ConsulHealthService;
-import org.openecomp.portalapp.util.EPUserUtils;
-import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
-import org.openecomp.portalsdk.core.util.SystemProperties;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.context.annotation.EnableAspectJAutoProxy;
-import org.springframework.http.HttpEntity;
-import org.springframework.http.HttpHeaders;
-import org.springframework.http.HttpMethod;
-import org.springframework.http.MediaType;
-import org.springframework.http.ResponseEntity;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.RestController;
-import org.springframework.web.client.RestTemplate;
-
-@RestController
-@org.springframework.context.annotation.Configuration
-@EnableAspectJAutoProxy
-@EPAuditLog
-public class UserRecommendationController extends EPRestrictedBaseController {
-
- private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(UserRecommendationController.class);
-
- @Autowired
- private ConsulHealthService consulHealthService;
-
- private static final String MACHINE_LEARNING_SERVICE_CTX = "/ml_api";
- private static final String GET_RECOMMENDATION = MACHINE_LEARNING_SERVICE_CTX + "/" + "getRecommendation";
- private static final String GET_RECOMM_COUNT = MACHINE_LEARNING_SERVICE_CTX + "/" + "getRecommCount";
- private static final String CONSUL_ML_SERVICE_ID = "mlearning-service";
- private static final String SERVICE_PROTOCOL = "http";
-
- @RequestMapping(value = {
- "/portalApi/getRecommendationsCount" }, method = RequestMethod.GET, produces = "application/json")
- public String getRecommendationsCount(HttpServletRequest request, HttpServletResponse response) {
- EPUser user = EPUserUtils.getUserSession(request);
- Map<String, String> requestMapping = new HashMap<String, String>();
- requestMapping.put("id", user.getOrgUserId());
- requestMapping.put("action", "reports");
-
- HttpHeaders headers = new HttpHeaders();
- headers.setContentType(MediaType.APPLICATION_JSON);
-
- // set your entity to send
- HttpEntity<Map<String,String>> entity = new HttpEntity<>(requestMapping, headers);
- String endpoint = SERVICE_PROTOCOL + "://"+ consulHealthService.getServiceLocation(CONSUL_ML_SERVICE_ID,
- SystemProperties.getProperty("microservices.m-learn.local.port")) + GET_RECOMM_COUNT;
- logger.debug(EELFLoggerDelegate.debugLogger, "Going to hit mlearning endpoint on: {1}", endpoint);
- ResponseEntity<String> out = new RestTemplate().exchange(endpoint, HttpMethod.POST, entity, String.class);
- return out.getBody();
- }
-
- @RequestMapping(value = {
- "/portalApi/getRecommendations" }, method = RequestMethod.GET, produces = "application/json")
- public String getRecommendations(HttpServletRequest request, HttpServletResponse response) {
- EPUser user = EPUserUtils.getUserSession(request);
- Map<String, String> requestMapping = new HashMap<String, String>();
- requestMapping.put("id", user.getOrgUserId());
- requestMapping.put("action", "reports");
- requestMapping.put("recommendations", "1");
-
- HttpHeaders headers = new HttpHeaders();
- headers.setContentType(MediaType.APPLICATION_JSON);
-
- // set your entity to send
- HttpEntity<Map<String,String>> entity = new HttpEntity<>(requestMapping, headers);
- String endpoint = SERVICE_PROTOCOL + "://"+
- consulHealthService.getServiceLocation(CONSUL_ML_SERVICE_ID,
- SystemProperties.getProperty("microservices.m-learn.local.port")) + GET_RECOMMENDATION;
- logger.debug(EELFLoggerDelegate.debugLogger, "Going to hit mlearning endpoint on: {1}", endpoint);
- ResponseEntity<String> out = new RestTemplate().exchange(endpoint, HttpMethod.POST, entity, String.class);
- return out.getBody();
- }
-
-} \ No newline at end of file
diff --git a/ecomp-portal-BE-common/src/main/java/org/openecomp/portalapp/portal/listener/HealthMonitor.java b/ecomp-portal-BE-common/src/main/java/org/openecomp/portalapp/portal/listener/HealthMonitor.java
index 9de7a4c9..f9a6b905 100644
--- a/ecomp-portal-BE-common/src/main/java/org/openecomp/portalapp/portal/listener/HealthMonitor.java
+++ b/ecomp-portal-BE-common/src/main/java/org/openecomp/portalapp/portal/listener/HealthMonitor.java
@@ -19,7 +19,6 @@
*/
package org.openecomp.portalapp.portal.listener;
-import java.util.Date;
import java.util.List;
import javax.annotation.PostConstruct;
@@ -28,11 +27,9 @@ import javax.annotation.PreDestroy;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
-import org.openecomp.portalapp.portal.domain.SharedContext;
import org.openecomp.portalapp.portal.logging.aop.EPMetricsLog;
import org.openecomp.portalapp.portal.logging.format.EPAppMessagesEnum;
import org.openecomp.portalapp.portal.logging.logic.EPLogUtil;
-import org.openecomp.portalapp.portal.service.SharedContextService;
import org.openecomp.portalapp.portal.ueb.EPUebHelper;
import org.openecomp.portalapp.portal.utils.EPCommonSystemProperties;
import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
@@ -47,29 +44,29 @@ import org.springframework.transaction.annotation.Transactional;
@EPMetricsLog
public class HealthMonitor {
+ private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(HealthMonitor.class);
+
@Autowired
private SessionFactory sessionFactory;
@Autowired
private EPUebHelper epUebHelper;
- @Autowired
- private SharedContextService sharedContextService;
-
private static boolean databaseUp;
private static boolean uebUp;
private static boolean frontEndUp;
private static boolean backEndUp;
private static boolean dbClusterStatusOk;
private static boolean dbPermissionsOk;
+
+ /**
+ * Read directly by external classes.
+ */
public static boolean isSuspended = false;
private Thread healthMonitorThread;
- private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(HealthMonitor.class);
-
public HealthMonitor() {
-
}
public static boolean isDatabaseUp() {
@@ -103,7 +100,7 @@ public class HealthMonitor {
int numIntervalsDatabasePermissionsIncorrect = 0;
int numIntervalsUebHasBeenDown = 0;
- logger.debug(EELFLoggerDelegate.debugLogger, "monitorEPHealth started");
+ logger.debug(EELFLoggerDelegate.debugLogger, "monitorEPHealth thread started");
long sleepInterval = (Long
.valueOf(SystemProperties.getProperty(EPCommonSystemProperties.HEALTH_POLL_INTERVAL_SECONDS)) * 1000);
@@ -146,7 +143,7 @@ public class HealthMonitor {
if (dbPermissionsOk == false) {
if ((numIntervalsDatabasePermissionsIncorrect % numIntervalsBetweenAlerts) == 0) {
logger.debug(EELFLoggerDelegate.debugLogger,
- "monitorEPHealth: database permissions not correct, logging to error log to trigger alert.");
+ "monitorEPHealth: database permissions incorrect, logging to error log to trigger alert.");
EPLogUtil.logEcompError(logger, EPAppMessagesEnum.BeHealthCheckMySqlError);
numIntervalsDatabasePermissionsIncorrect++;
} else {
@@ -162,8 +159,10 @@ public class HealthMonitor {
//
uebUp = this.checkIfUebUp();
if (uebUp == false) {
+
if ((numIntervalsUebHasBeenDown % numIntervalsBetweenAlerts) == 0) {
- logger.debug(EELFLoggerDelegate.debugLogger, "UEB down, logging to error log to trigger alert");
+ logger.debug(EELFLoggerDelegate.debugLogger,
+ "monitorEPHealth: UEB down, logging to error log to trigger alert");
// Write a Log entry that will generate an alert
EPLogUtil.logEcompError(logger, EPAppMessagesEnum.BeHealthCheckUebClusterError);
numIntervalsUebHasBeenDown++;
@@ -189,15 +188,18 @@ public class HealthMonitor {
// could return information in the json content of a health check.
//
+ //
+ // Get DB status. If down, signal alert once every X intervals.
+ //
if (Thread.interrupted()) {
- logger.debug(EELFLoggerDelegate.debugLogger, "monitorEPHealth: interrupted, leaving loop");
+ logger.info(EELFLoggerDelegate.errorLogger, "monitorEPHealth: thread interrupted");
break;
}
try {
Thread.sleep(sleepInterval);
} catch (InterruptedException e) {
- logger.error(EELFLoggerDelegate.errorLogger, "monitorEPHealth interrupted", e);
+ logger.error(EELFLoggerDelegate.errorLogger, "monitorEPHealth: sleep interrupted", e);
Thread.currentThread().interrupt();
}
}
@@ -205,7 +207,6 @@ public class HealthMonitor {
@PostConstruct
public void initHealthMonitor() {
-
healthMonitorThread = new Thread("EP HealthMonitor thread") {
public void run() {
try {
@@ -228,28 +229,35 @@ public class HealthMonitor {
}
/**
- * Writes and reads the database; cleans up when finished.
+ * This routine checks whether the database can be read. In June 2017 we
+ * experimented with checking if the database can be WRITTEN. Writes failed
+ * with some regularity in a MariaDB Galera cluster, and in that
+ * environment, the resulting alerts in the log triggered a health monitor
+ * cron job to shut down the Tomcat instance. The root cause of the cluster
+ * write failures was not determined.
*
- * @return True on success; false otherwise.
+ * @return true if the database can be read.
*/
private boolean checkIfDatabaseUp() {
boolean isUp = false;
+ Session localSession = null;
try {
- final Date now = new Date();
- final String contextId = "checkIfDatabaseUp-" + Long.toString(now.getTime());
- final String key = "checkIfDatabaseUp-key";
- final String value = "checkIfDatabaseUp-value";
- sharedContextService.addSharedContext(contextId, key, value);
- SharedContext sc = sharedContextService.getSharedContext(contextId, key);
- if (sc == null || sc.getCvalue() == null || !value.equals(sc.getCvalue()))
- throw new Exception("Failed to retrieve shared context");
- int removed = sharedContextService.deleteSharedContexts(contextId);
- if (removed != 1)
- throw new Exception("Failed to delete shared context");
- isUp = true;
+ localSession = sessionFactory.openSession();
+ if (localSession != null) {
+ String sql = "select app_name from fn_app where app_id=1";
+ Query query = localSession.createSQLQuery(sql);
+ @SuppressWarnings("unchecked")
+ List<String> queryList = query.list();
+ if (queryList != null) {
+ isUp = true;
+ }
+ }
} catch (Exception e) {
- logger.error(EELFLoggerDelegate.errorLogger, "checkIfDatabaseUp failed", e);
+ logger.debug(EELFLoggerDelegate.debugLogger, "checkIfDatabaseUp failed", e);
isUp = false;
+ } finally {
+ if (localSession != null)
+ localSession.close();
}
return isUp;
}
@@ -273,8 +281,7 @@ public class HealthMonitor {
} catch (Exception e) {
logger.error(EELFLoggerDelegate.errorLogger, "checkClusterStatus failed", e);
if ((e.getCause() != null) && (e.getCause().getMessage() != null)) {
- logger.error(EELFLoggerDelegate.errorLogger,
- "checkClusterStatus() exception cause", e.getCause());
+ logger.error(EELFLoggerDelegate.errorLogger, "checkClusterStatus failure cause", e.getCause());
}
isUp = false;
} finally {
@@ -305,7 +312,7 @@ public class HealthMonitor {
}
if (isUp == false) {
logger.error(EELFLoggerDelegate.errorLogger,
- "checkDatabaseAndPermissions() returning false. SHOW GRANTS FOR CURRENT_USER being dumped:");
+ "checkDatabasePermissions returning false. SHOW GRANTS FOR CURRENT_USER being dumped:");
for (String str : grantsList) {
logger.error(EELFLoggerDelegate.errorLogger, "grants output item = [" + str + "]");
}
@@ -314,8 +321,7 @@ public class HealthMonitor {
} catch (Exception e) {
logger.error(EELFLoggerDelegate.errorLogger, "checkDatabasePermissions failed", e);
if ((e.getCause() != null) && (e.getCause().getMessage() != null)) {
- logger.error(EELFLoggerDelegate.errorLogger,
- "checkDatabasePermissions() exception msg = ", e.getCause());
+ logger.error(EELFLoggerDelegate.errorLogger, "checkDatabasePermissions failure cause", e.getCause());
}
isUp = false;
} finally {
diff --git a/ecomp-portal-BE-common/src/main/java/org/openecomp/portalapp/portal/service/UserRolesCommonServiceImpl.java b/ecomp-portal-BE-common/src/main/java/org/openecomp/portalapp/portal/service/UserRolesCommonServiceImpl.java
index 727f83dd..80408954 100644
--- a/ecomp-portal-BE-common/src/main/java/org/openecomp/portalapp/portal/service/UserRolesCommonServiceImpl.java
+++ b/ecomp-portal-BE-common/src/main/java/org/openecomp/portalapp/portal/service/UserRolesCommonServiceImpl.java
@@ -243,7 +243,10 @@ public class UserRolesCommonServiceImpl {
if (!userRole.getRoleId().equals(PortalConstants.ACCOUNT_ADMIN_ROLE_ID) && userRole.getRoleId() != PortalConstants.SYS_ADMIN_ROLE_ID && !extRequestValue){
syncUserRolesExtension(userRole, appId, localSession, userAppRoles, newUserAppRolesMap);
}
- else if (extRequestValue){
+ else if (extRequestValue && ("PUT".equals(reqType) || "POST".equals(reqType) || "DELETE".equals(reqType))){
+ syncUserRolesExtension(userRole, appId, localSession, userAppRoles, newUserAppRolesMap);
+ }
+ else if (extRequestValue && !userRole.getRoleId().equals(PortalConstants.ACCOUNT_ADMIN_ROLE_ID)){
syncUserRolesExtension(userRole, appId, localSession, userAppRoles, newUserAppRolesMap);
}
}
@@ -276,15 +279,18 @@ public class UserRolesCommonServiceImpl {
}
EPRole role = null;
for (EcompRole userRole : newRolesToAdd) {
+ EPUserApp userApp = new EPUserApp();
if (("PUT".equals(reqType) || "POST".equals(reqType)) && userRole.getName().equals(PortalConstants.ADMIN_ROLE)) {
role = (EPRole) localSession.get(EPRole.class, new Long(PortalConstants.ACCOUNT_ADMIN_ROLE_ID));
+ userApp.setRole(role);
} else if (userRole.getId().equals(PortalConstants.ACCOUNT_ADMIN_ROLE_ID) && !extRequestValue){
continue;
+ } else {
+ userApp.setRole(rolesMap.get(userRole.getId()));
}
- EPUserApp userApp = new EPUserApp();
+
userApp.setUserId(client.getId());
userApp.setApp(app);
- userApp.setRole(("PUT".equals(reqType) || "POST".equals(reqType) && userRole.getId().equals(PortalConstants.ACCOUNT_ADMIN_ROLE_ID)) ? role : rolesMap.get(userRole.getId()));
localSession.save(userApp);
localSession.flush();
}
@@ -698,7 +704,7 @@ public class UserRolesCommonServiceImpl {
result = true;
} catch (Exception e) {
logger.error(EELFLoggerDelegate.errorLogger,
- "applyChangesInUserRolesForAppToEcompDB: failed to syncUserRoles for attuid " + userId, e);
+ "applyChangesInUserRolesForAppToEcompDB: failed to syncUserRoles for orgUserId " + userId, e);
if("DELETE".equals(reqType)){
throw new Exception(e.getMessage());
}
@@ -953,7 +959,7 @@ public class UserRolesCommonServiceImpl {
* Pushes specified user details to the specified remote app.
*
* @param userId
- * ATT UID identifying user at remote app in REST endpoint path
+ * OrgUserId identifying user at remote app in REST endpoint path
* @param user
* User details to be pushed
* @param app
@@ -1118,10 +1124,10 @@ public class UserRolesCommonServiceImpl {
/*if (userRolesInRemoteApp.size() == 0) {
logger.debug(EELFLoggerDelegate.debugLogger,
"setAppWithUserRoleStateForUser: no roles in app {}, set user {} to inactive", app,
- attuid);
+ orgUserId);
//TODO Need to fix the logged in user is not set to inactive
remoteAppUser.setActive(false);
- postUserToRemoteApp(attuid, user, app, applicationsRestClientService);
+ postUserToRemoteApp(orgUserId, user, app, applicationsRestClientService);
}*/
}
@@ -1189,7 +1195,7 @@ public class UserRolesCommonServiceImpl {
if (existingAppRole == null) {
logger.error(EELFLoggerDelegate.errorLogger, "roleInAppForUserList failed for the roles {}",
roleInAppForUserList);
- throw new Exception("'" +roleInAppForUser.getRoleName() + "'" +" role does not exist for" + appName + " application");
+ throw new Exception("'" +roleInAppForUser.getRoleName() + "'" +" role does not exist for " + appName + " application");
}
if (!existingAppRole.getActive()) {
logger.error(EELFLoggerDelegate.errorLogger, "roleInAppForUserList failed for the roles {}",
@@ -1265,10 +1271,18 @@ public class UserRolesCommonServiceImpl {
public List<RoleInAppForUser> getAppRolesForUser(Long appId, String userId, Boolean extRequestValue) {
List<RoleInAppForUser> rolesInAppForUser = null;
+ List<EPUser> userInfo = null;
try {
// for ecomp portal app, no need to make a remote call
- if (appId == PortalConstants.PORTAL_APP_ID) {
+ if (appId == PortalConstants.PORTAL_APP_ID) {
+ final Map<String, String> userParams = new HashMap<>();
+ userParams.put("orgUserIdValue", userId);
+ userInfo = checkIfUserExists(userParams);
+ if(userInfo.size() == 0 || userInfo.isEmpty())
+ {
+ createLocalUserIfNecessary(userId);
+ }
List<Role> roleList = roleService.getAvailableRoles();
List<Role> activeRoleList = new ArrayList<Role>();
diff --git a/ecomp-portal-BE-common/src/main/webapp/WEB-INF/fusion/orm/EP.hbm.xml b/ecomp-portal-BE-common/src/main/webapp/WEB-INF/fusion/orm/EP.hbm.xml
index 84f7b7ed..eea9467a 100644
--- a/ecomp-portal-BE-common/src/main/webapp/WEB-INF/fusion/orm/EP.hbm.xml
+++ b/ecomp-portal-BE-common/src/main/webapp/WEB-INF/fusion/orm/EP.hbm.xml
@@ -630,13 +630,13 @@
and a.is_for_all_roles = 'N'
) a,
(
- select a.user_id, c.role_id, c.app_id, d.APP_NAME
+ select distinct a.user_id, c.role_id, c.app_id, d.APP_NAME
from fn_user a, fn_user_role b, fn_role c, fn_app d
- where a.user_id = b.user_id
+ where COALESCE(c.app_id,1) = d.app_id
+ and a.user_id = b.user_id
and a.user_id = :user_id
and b.role_id = c.role_id
- and c.app_id = d.app_id
- and d.enabled='Y'
+ and (d.enabled='Y' or d.app_id=1)
)b
where
(
@@ -821,13 +821,13 @@ where fn_role.app_id = fn_app.app_id and fn_app.enabled='Y' order by app_name
)
) a,
(
- select a.user_id, c.role_id, c.app_id, d.APP_NAME
+ select distinct a.user_id, c.role_id, c.app_id, d.APP_NAME
from fn_user a, fn_user_role b, fn_role c, fn_app d
- where a.user_id = b.user_id
+ where COALESCE(c.app_id,1) = d.app_id
+ and a.user_id = b.user_id
and a.user_id = :user_id
and b.role_id = c.role_id
- and c.app_id = d.app_id
- and d.enabled='Y'
+ and (d.enabled='Y' or d.app_id=1)
) b
where
(