diff --git a/ArgusCore/src/main/java/com/salesforce/dva/argus/entity/Alert.java b/ArgusCore/src/main/java/com/salesforce/dva/argus/entity/Alert.java index 62697f20e..c1941b8e8 100644 --- a/ArgusCore/src/main/java/com/salesforce/dva/argus/entity/Alert.java +++ b/ArgusCore/src/main/java/com/salesforce/dva/argus/entity/Alert.java @@ -809,7 +809,7 @@ public Alert deserialize(JsonParser jp, DeserializationContext ctxt) throws IOEx SimpleModule module = new SimpleModule(); module.addDeserializer(Trigger.class, new Trigger.Deserializer()); module.addDeserializer(Notification.class, new Notification.Deserializer()); - module.addDeserializer(PrincipalUser.class, new PrincipalUser.Deserializer()); + module.addDeserializer(PrincipalUser.class, new Alert.PrincipalUserDeserializer()); ObjectMapper mapper = new ObjectMapper(); mapper.registerModule(module); @@ -892,5 +892,39 @@ private boolean _contains(BigInteger triggerID, List triggersWithIDsOnl } + public static class PrincipalUserSerializer extends JsonSerializer { + + @Override + public void serialize(PrincipalUser value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException { + jgen.writeStartObject(); + jgen.writeStringField("id", value.getId().toString()); + jgen.writeStringField("username", value.getUserName()); + jgen.writeStringField("email", value.getEmail()); + jgen.writeEndObject(); + } + } + + public static class PrincipalUserDeserializer extends JsonDeserializer { + + @Override + public PrincipalUser deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { + + PrincipalUser user = new PrincipalUser(); + JsonNode rootNode = jp.getCodec().readTree(jp); + + BigInteger id = new BigInteger(rootNode.get("id").asText()); + user.id = id; + + String username = rootNode.get("username").asText(); + user.setUserName(username); + + String email = rootNode.get("email").asText(); + user.setEmail(email); + + return user; + } + + } + } /* Copyright (c) 2016, Salesforce.com, Inc. All rights reserved. */ diff --git a/ArgusCore/src/main/java/com/salesforce/dva/argus/entity/PrincipalUser.java b/ArgusCore/src/main/java/com/salesforce/dva/argus/entity/PrincipalUser.java index aa1e5a46d..2fae27d19 100644 --- a/ArgusCore/src/main/java/com/salesforce/dva/argus/entity/PrincipalUser.java +++ b/ArgusCore/src/main/java/com/salesforce/dva/argus/entity/PrincipalUser.java @@ -45,9 +45,13 @@ import java.io.Serializable; import java.math.BigInteger; import java.util.ArrayList; +import java.util.Date; import java.util.HashMap; +import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.Map.Entry; + import javax.persistence.Basic; import javax.persistence.Column; import javax.persistence.ElementCollection; @@ -100,11 +104,26 @@ public class PrincipalUser extends JPAEntity implements Serializable { public static class Serializer extends JsonSerializer { @Override - public void serialize(PrincipalUser value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException { + public void serialize(PrincipalUser user, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException { jgen.writeStartObject(); - jgen.writeStringField("id", value.getId().toString()); - jgen.writeStringField("username", value.getUserName()); - jgen.writeStringField("email", value.getEmail()); + jgen.writeStringField("id", user.getId().toString()); + jgen.writeStringField("username", user.getUserName()); + jgen.writeStringField("email", user.getEmail()); + jgen.writeBooleanField("privileged", user.isPrivileged()); + jgen.writeObjectField("preferences", user.getPreferences()); + + jgen.writeArrayFieldStart("ownedDashboardIds"); + for(Dashboard dashboard : user.getOwnedDashboards()) { + jgen.writeNumber(dashboard.getId()); + } + jgen.writeEndArray(); + + jgen.writeNumberField("createdDate", user.getCreatedDate().getTime()); + jgen.writeNumberField("modifiedDate", user.getModifiedDate().getTime()); + jgen.writeFieldName("createdBy"); + jgen.writeNumber(user.getCreatedBy().getId()); + jgen.writeFieldName("modifiedBy"); + jgen.writeNumber(user.getModifiedBy().getId()); jgen.writeEndObject(); } } @@ -126,6 +145,36 @@ public PrincipalUser deserialize(JsonParser jp, DeserializationContext ctxt) thr String email = rootNode.get("email").asText(); user.setEmail(email); + user.setPrivileged(rootNode.get("privileged").asBoolean()); + + Map preferences = new HashMap<>(); + JsonNode preferencesNode = rootNode.get("preferences"); + if(preferencesNode.isObject()) { + Iterator> fieldsIter = preferencesNode.fields(); + while(fieldsIter.hasNext()) { + Entry field = fieldsIter.next(); + preferences.put(Preference.valueOf(field.getKey()), field.getValue().asText()); + } + } + user.preferences = preferences; + + List ownedDashboards = new ArrayList<>(); + JsonNode ownedDashboardIds = rootNode.get("ownedDashboardIds"); + if(ownedDashboardIds.isArray()) { + for(JsonNode ownedDashboardId : ownedDashboardIds) { + Dashboard d = new Dashboard(); + d.id = new BigInteger(ownedDashboardId.asText()); + ownedDashboards.add(d); + } + } + user.setOwnedDashboards(ownedDashboards); + + user.setCreatedBy(new PrincipalUser(new BigInteger(rootNode.get("createdBy").asText()))); + user.createdDate = new Date(rootNode.get("createdDate").asLong()); + + user.setModifiedBy(new PrincipalUser(new BigInteger(rootNode.get("modifiedBy").asText()))); + user.modifiedDate = new Date(rootNode.get("modifiedDate").asLong()); + return user; } @@ -136,15 +185,19 @@ public PrincipalUser deserialize(JsonParser jp, DeserializationContext ctxt) thr @Basic(optional = false) @Column(nullable = false, unique = true) private String userName; + @Basic(optional = false) @Column(nullable = false, unique = true) private String email; + @ElementCollection @MapKeyColumn(name = "name") @Column(name = "preference") private Map preferences = new HashMap<>(); + @OneToMany(mappedBy = "owner") private List ownedDashboards = new ArrayList<>(); + private boolean privileged = false; //~ Constructors ********************************************************************************************************************************* @@ -155,7 +208,7 @@ public PrincipalUser deserialize(JsonParser jp, DeserializationContext ctxt) thr * @param userName The user name for the * @param email The email address for the user. */ - public PrincipalUser(String userName, String email) { + private PrincipalUser(String userName, String email) { this(null, userName, email); } @@ -176,6 +229,10 @@ public PrincipalUser(PrincipalUser creator, String userName, String email) { protected PrincipalUser() { super(null); } + + private PrincipalUser(BigInteger id) { + this.id = id; + } //~ Methods ************************************************************************************************************************************** diff --git a/ArgusCore/src/main/java/com/salesforce/dva/argus/service/alert/DefaultAlertService.java b/ArgusCore/src/main/java/com/salesforce/dva/argus/service/alert/DefaultAlertService.java index 5ecb2e0a0..cbd7ebcc7 100644 --- a/ArgusCore/src/main/java/com/salesforce/dva/argus/service/alert/DefaultAlertService.java +++ b/ArgusCore/src/main/java/com/salesforce/dva/argus/service/alert/DefaultAlertService.java @@ -161,7 +161,7 @@ private void _initializeObjectMapper() { module.addSerializer(Alert.class, new Alert.Serializer()); module.addSerializer(Trigger.class, new Trigger.Serializer()); module.addSerializer(Notification.class, new Notification.Serializer()); - module.addSerializer(PrincipalUser.class, new PrincipalUser.Serializer()); + module.addSerializer(PrincipalUser.class, new Alert.PrincipalUserSerializer()); module.addDeserializer(Alert.class, new Alert.Deserializer()); _mapper.registerModule(module); diff --git a/ArgusCore/src/main/java/com/salesforce/dva/argus/service/users/CachedUserService.java b/ArgusCore/src/main/java/com/salesforce/dva/argus/service/users/CachedUserService.java new file mode 100644 index 000000000..c492438bc --- /dev/null +++ b/ArgusCore/src/main/java/com/salesforce/dva/argus/service/users/CachedUserService.java @@ -0,0 +1,164 @@ +package com.salesforce.dva.argus.service.users; + +import static com.salesforce.dva.argus.system.SystemAssert.requireArgument; +import static java.math.BigInteger.ZERO; + +import java.io.IOException; +import java.math.BigInteger; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.module.SimpleModule; +import com.google.inject.Inject; +import com.salesforce.dva.argus.entity.PrincipalUser; +import com.salesforce.dva.argus.service.AuditService; +import com.salesforce.dva.argus.service.CacheService; +import com.salesforce.dva.argus.service.NamedBinding; +import com.salesforce.dva.argus.service.UserService; +import com.salesforce.dva.argus.service.jpa.DefaultJPAService; +import com.salesforce.dva.argus.system.SystemConfiguration; + +public class CachedUserService extends DefaultJPAService implements UserService { + + //TTL of 30 days + private static final int TTL_SECS = 30 * 24 * 60 * 60; + + private final Logger _logger = LoggerFactory.getLogger(getClass()); + private final CacheService _cacheService; + private final UserService _defaultUserService; + private ObjectMapper _mapper; + + /** + * Creates a new CachedUserService object. + * + * @param auditService The audit service. Cannot be null. + * @param config Service properties + */ + @Inject + public CachedUserService(AuditService auditService, SystemConfiguration config, CacheService cacheService, + @NamedBinding UserService userService) { + super(auditService, config); + _cacheService = cacheService; + _defaultUserService = userService; + + _mapper = new ObjectMapper(); + SimpleModule module = new SimpleModule(); + module.addSerializer(PrincipalUser.class, new PrincipalUser.Serializer()); + module.addDeserializer(PrincipalUser.class, new PrincipalUser.Deserializer()); + _mapper.registerModule(module); + } + + @Override + public PrincipalUser findUserByUsername(String userName) { + requireNotDisposed(); + requireArgument(userName != null && !userName.trim().isEmpty(), "User name cannot be null or empty."); + + String cachedUser = _cacheService.get(userName); + + if(cachedUser != null) { + try { + PrincipalUser user = _mapper.readValue(cachedUser, PrincipalUser.class); + return user; + } catch (IOException e) { + _logger.warn("Failed to deserialize user object retrieved from cache. Will get from persistent storage."); + } + } + + _logger.debug("User not found in cache. Will read from persistent storage."); + PrincipalUser user = _defaultUserService.findUserByUsername(userName); + if(user != null) { + try { + _cacheService.put(user.getUserName(), _mapper.writeValueAsString(user), TTL_SECS); + _cacheService.put(user.getId().toString(), _mapper.writeValueAsString(user), TTL_SECS); + } catch (JsonProcessingException e) { + _logger.warn("Failed to serialize user object. User {} will not be cached.", user); + } + } + + return user; + } + + @Override + public PrincipalUser findUserByPrimaryKey(BigInteger id) { + requireNotDisposed(); + requireArgument(id != null && id.compareTo(ZERO) > 0, "ID must be a positive non-zero value."); + + String cachedUser = _cacheService.get(id.toString()); + + if(cachedUser != null) { + try { + PrincipalUser user = _mapper.readValue(cachedUser, PrincipalUser.class); + return user; + } catch (IOException e) { + _logger.warn("Failed to deserialize user object retrieved from cache. Will get from persistent storage."); + } + } + + _logger.debug("User not found in cache. Will read from persistent storage."); + PrincipalUser user = _defaultUserService.findUserByPrimaryKey(id); + if(user != null) { + try { + _cacheService.put(user.getUserName(), _mapper.writeValueAsString(user), TTL_SECS); + _cacheService.put(user.getId().toString(), _mapper.writeValueAsString(user), TTL_SECS); + } catch (JsonProcessingException e) { + _logger.warn("Failed to serialize user object. User {} will not be cached.", user); + } + } + + return user; + } + + @Override + public void deleteUser(PrincipalUser user) { + requireNotDisposed(); + requireArgument(user != null && user.getId() != null && user.getId().compareTo(ZERO) > 0, "User cannot be null and must have a valid ID."); + + _cacheService.delete(user.getId().toString()); + + if(user.getUserName() == null || user.getUserName().isEmpty()) { + user = findUserByPrimaryKey(user.getId()); + _cacheService.delete(user.getUserName().toString()); + } + _defaultUserService.deleteUser(user); + } + + @Override + public PrincipalUser updateUser(PrincipalUser user) { + requireNotDisposed(); + requireArgument(user != null, "User cannot be null."); + + if(user.getId() != null) { + _cacheService.delete(user.getId().toString()); + } + + if(user.getUserName() != null) { + _cacheService.delete(user.getUserName().toString()); + } + return _defaultUserService.updateUser(user); + } + + @Override + public PrincipalUser findAdminUser() { + requireNotDisposed(); + + return _defaultUserService.findAdminUser(); + } + + @Override + public PrincipalUser findDefaultUser() { + requireNotDisposed(); + + return _defaultUserService.findDefaultUser(); + } + + @Override + public long getUniqueUserCount() { + requireNotDisposed(); + + return _defaultUserService.getUniqueUserCount(); + } + +} diff --git a/ArgusCore/src/main/java/com/salesforce/dva/argus/service/jpa/DefaultUserService.java b/ArgusCore/src/main/java/com/salesforce/dva/argus/service/users/DefaultUserService.java similarity index 84% rename from ArgusCore/src/main/java/com/salesforce/dva/argus/service/jpa/DefaultUserService.java rename to ArgusCore/src/main/java/com/salesforce/dva/argus/service/users/DefaultUserService.java index c6dd54be2..51b1c8eb4 100644 --- a/ArgusCore/src/main/java/com/salesforce/dva/argus/service/jpa/DefaultUserService.java +++ b/ArgusCore/src/main/java/com/salesforce/dva/argus/service/users/DefaultUserService.java @@ -29,25 +29,23 @@ * POSSIBILITY OF SUCH DAMAGE. */ -package com.salesforce.dva.argus.service.jpa; +package com.salesforce.dva.argus.service.users; -import com.google.common.cache.CacheBuilder; -import com.google.common.cache.CacheLoader; -import com.google.common.cache.LoadingCache; import com.google.inject.Inject; import com.google.inject.Provider; import com.google.inject.Singleton; import com.google.inject.persist.Transactional; import com.salesforce.dva.argus.entity.PrincipalUser; -import com.salesforce.dva.argus.inject.SLF4JTypeListener; import com.salesforce.dva.argus.service.AuditService; import com.salesforce.dva.argus.service.UserService; +import com.salesforce.dva.argus.service.jpa.DefaultJPAService; import com.salesforce.dva.argus.system.SystemConfiguration; import com.salesforce.dva.argus.system.SystemException; import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import java.lang.reflect.Method; import java.math.BigInteger; -import java.util.Optional; import javax.persistence.EntityManager; @@ -61,14 +59,10 @@ */ @Singleton public class DefaultUserService extends DefaultJPAService implements UserService { - - private static final int NUM_USERS_TO_CACHE = 50; - private static LoadingCache> USERCACHE; //~ Instance fields ****************************************************************************************************************************** - @SLF4JTypeListener.InjectLogger - private Logger _logger; + private Logger _logger = LoggerFactory.getLogger(getClass()); @Inject Provider emf; @@ -84,23 +78,13 @@ public class DefaultUserService extends DefaultJPAService implements UserService @Inject public DefaultUserService(AuditService auditService, SystemConfiguration _sysConfig) { super(auditService, _sysConfig); - - USERCACHE = CacheBuilder - .newBuilder() - .maximumSize(NUM_USERS_TO_CACHE) - .build(new CacheLoader>() { - - @Override - public Optional load(String username) { - return Optional.ofNullable(_findUserByUsernameFromDB(username)); - } - }); } //~ Methods ************************************************************************************************************************************** @Transactional - private PrincipalUser _findUserByUsernameFromDB(String userName) { + @Override + public PrincipalUser findUserByUsername(String userName) { requireNotDisposed(); requireArgument(userName != null && !userName.trim().isEmpty(), "User name cannot be null or empty."); @@ -109,17 +93,6 @@ private PrincipalUser _findUserByUsernameFromDB(String userName) { _logger.debug("Retrieving user having username {} from db.", userName); return result; } - - @Override - public PrincipalUser findUserByUsername(String userName) { - PrincipalUser user = USERCACHE.getUnchecked(userName).orElse(null); - if(user == null) { - USERCACHE.invalidate(userName); - } - - _logger.info("Query for user having username {} resulted in : {}", userName, user); - return user; - } @Override @Transactional @@ -139,8 +112,6 @@ public void deleteUser(PrincipalUser user) { requireNotDisposed(); requireArgument(user != null && user.getId() != null && user.getId().compareTo(ZERO) > 0, "User cannot be null and must have a valid ID."); _logger.debug("Deleting user {}.", user); - - USERCACHE.invalidate(user.getUserName()); EntityManager em = emf.get(); deleteEntity(em, user); @@ -152,8 +123,6 @@ public void deleteUser(PrincipalUser user) { public PrincipalUser updateUser(PrincipalUser user) { requireNotDisposed(); requireArgument(user != null, "User cannot be null."); - - USERCACHE.invalidate(user.getUserName()); EntityManager em = emf.get(); PrincipalUser result = mergeEntity(em, user); diff --git a/ArgusCore/src/main/java/com/salesforce/dva/argus/system/SystemInitializer.java b/ArgusCore/src/main/java/com/salesforce/dva/argus/system/SystemInitializer.java index a7d7a91a4..4f8b1bac1 100644 --- a/ArgusCore/src/main/java/com/salesforce/dva/argus/system/SystemInitializer.java +++ b/ArgusCore/src/main/java/com/salesforce/dva/argus/system/SystemInitializer.java @@ -51,13 +51,14 @@ import com.salesforce.dva.argus.service.jpa.DefaultGlobalInterlockService; import com.salesforce.dva.argus.service.jpa.DefaultNamespaceService; import com.salesforce.dva.argus.service.jpa.DefaultServiceManagementService; -import com.salesforce.dva.argus.service.jpa.DefaultUserService; import com.salesforce.dva.argus.service.management.DefaultManagementService; import com.salesforce.dva.argus.service.metric.AsyncMetricService; import com.salesforce.dva.argus.service.monitor.DefaultMonitorService; import com.salesforce.dva.argus.service.schema.CachedDiscoveryService; import com.salesforce.dva.argus.service.schema.DefaultDiscoveryService; import com.salesforce.dva.argus.service.tsdb.CachedTSDBService; +import com.salesforce.dva.argus.service.users.CachedUserService; +import com.salesforce.dva.argus.service.users.DefaultUserService; import com.salesforce.dva.argus.service.warden.DefaultWardenService; import com.salesforce.dva.argus.system.SystemConfiguration.Property; @@ -236,10 +237,11 @@ private void configureServices() { // Named annotation binding bindConcreteClassWithNamedAnnotation(getConcreteClassToBind(Property.TSDB_SERVICE_IMPL_CLASS, TSDBService.class), TSDBService.class); bindConcreteClassWithNamedAnnotation(DefaultDiscoveryService.class, DiscoveryService.class); + bindConcreteClassWithNamedAnnotation(DefaultUserService.class, UserService.class); // static binding bindConcreteClass(CachedTSDBService.class, TSDBService.class); - bindConcreteClass(DefaultUserService.class, UserService.class); + bindConcreteClass(CachedUserService.class, UserService.class); bindConcreteClass(DefaultDashboardService.class, DashboardService.class); bindConcreteClass(DefaultCollectionService.class, CollectionService.class); bindConcreteClass(AsyncMetricService.class, MetricService.class); diff --git a/ArgusCore/src/test/java/com/salesforce/dva/argus/service/AlertServiceTest.java b/ArgusCore/src/test/java/com/salesforce/dva/argus/service/AlertServiceTest.java index 62d7ce42f..ddc76e05b 100644 --- a/ArgusCore/src/test/java/com/salesforce/dva/argus/service/AlertServiceTest.java +++ b/ArgusCore/src/test/java/com/salesforce/dva/argus/service/AlertServiceTest.java @@ -41,6 +41,7 @@ import java.util.List; import java.util.Set; +import org.junit.Before; import org.junit.Test; import com.fasterxml.jackson.databind.ObjectMapper; @@ -58,6 +59,12 @@ public class AlertServiceTest extends AbstractTest { private static final String EXPRESSION = "DIVIDE(-1h:argus.jvm:file.descriptor.open{host=unknown-host}:avg, -1h:argus.jvm:file.descriptor.max{host=unknown-host}:avg)"; + private PrincipalUser admin; + + @Before + public void setup() { + admin = system.getServiceFactory().getUserService().findAdminUser(); + } @Test public void testUpdateAlert() { @@ -139,7 +146,7 @@ public void testDeleteAlert() { public void testFindAlertByNameAndOwner() { AlertService alertService = system.getServiceFactory().getAlertService(); String alertName = "testAlert"; - PrincipalUser expectedUser = new PrincipalUser("testUser", "testuser@testcompany.com"); + PrincipalUser expectedUser = new PrincipalUser(admin, "testUser", "testuser@testcompany.com"); Alert expectedAlert = new Alert(expectedUser, expectedUser, alertName, EXPRESSION, "* * * * *"); expectedAlert = alertService.updateAlert(expectedAlert); @@ -156,7 +163,7 @@ public void testfindAlertsByOwner() { AlertService alertService = system.getServiceFactory().getAlertService(); String userName = createRandomName(); int alertsCount = random.nextInt(20) + 1; - PrincipalUser user = new PrincipalUser(userName, userName + "@testcompany.com"); + PrincipalUser user = new PrincipalUser(admin ,userName, userName + "@testcompany.com"); user = userService.updateUser(user); @@ -184,7 +191,7 @@ public void testfindAlertsByOwnerMeta() { AlertService alertService = system.getServiceFactory().getAlertService(); String userName = createRandomName(); int alertsCount = random.nextInt(20) + 1; - PrincipalUser user = new PrincipalUser(userName, userName + "@testcompany.com"); + PrincipalUser user = new PrincipalUser(admin, userName, userName + "@testcompany.com"); user = userService.updateUser(user); @@ -212,7 +219,7 @@ public void findAllAlerts() { AlertService alertService = system.getServiceFactory().getAlertService(); String userName = createRandomName(); int alertsCount = random.nextInt(100) + 1; - PrincipalUser user = new PrincipalUser(userName, userName + "@testcompany.com"); + PrincipalUser user = new PrincipalUser(admin, userName, userName + "@testcompany.com"); user = userService.updateUser(user); @@ -240,7 +247,7 @@ public void testFindAllAlertsMeta() { AlertService alertService = system.getServiceFactory().getAlertService(); String userName = createRandomName(); int alertsCount = random.nextInt(100) + 1; - PrincipalUser user = new PrincipalUser(userName, userName + "@testcompany.com"); + PrincipalUser user = new PrincipalUser(admin, userName, userName + "@testcompany.com"); user = userService.updateUser(user); @@ -339,7 +346,7 @@ public void testAlertEnqueue() { public void testSharedAlertWhenOneSharedAlert() { UserService userService = system.getServiceFactory().getUserService(); AlertService alertService = system.getServiceFactory().getAlertService(); - PrincipalUser user1 = userService.updateUser(new PrincipalUser("test1", "test1@salesforce.com")); + PrincipalUser user1 = userService.updateUser(new PrincipalUser(admin, "test1", "test1@salesforce.com")); alertService.updateAlert(new Alert(user1, user1, "alert-name1", EXPRESSION, "* * * * *")); Alert alertShared = alertService.updateAlert(new Alert(user1, user1, "alert-name-shared2", EXPRESSION, "* * * * *")); @@ -357,8 +364,8 @@ public void testSharedAlertWhenOneSharedAlert() { public void testSharedAlertWhenTwoSharedAlert() { UserService userService = system.getServiceFactory().getUserService(); AlertService alertService = system.getServiceFactory().getAlertService(); - PrincipalUser user1 = userService.updateUser(new PrincipalUser("test1", "test1@salesforce.com")); - PrincipalUser user2 = userService.updateUser(new PrincipalUser("test2", "test2@salesforce.com")); + PrincipalUser user1 = userService.updateUser(new PrincipalUser(admin, "test1", "test1@salesforce.com")); + PrincipalUser user2 = userService.updateUser(new PrincipalUser(admin, "test2", "test2@salesforce.com")); Alert alertSharedUser1 = alertService.updateAlert(new Alert(user1, user1, "alert-name_shared1", EXPRESSION, "* * * * *")); Alert alertSharedUser2 = alertService.updateAlert(new Alert(user2, user2, "alert-name-shared2", EXPRESSION, "* * * * *")); @@ -380,8 +387,8 @@ public void testSharedAlertWhenTwoSharedAlert() { public void testFindSharedAlertsMeta() { UserService userService = system.getServiceFactory().getUserService(); AlertService alertService = system.getServiceFactory().getAlertService(); - PrincipalUser user1 = userService.updateUser(new PrincipalUser("test1", "test1@salesforce.com")); - PrincipalUser user2 = userService.updateUser(new PrincipalUser("test2", "test2@salesforce.com")); + PrincipalUser user1 = userService.updateUser(new PrincipalUser(admin, "test1", "test1@salesforce.com")); + PrincipalUser user2 = userService.updateUser(new PrincipalUser(admin, "test2", "test2@salesforce.com")); Alert alertSharedUser1 = alertService.updateAlert(new Alert(user1, user1, "alert-name_shared1", EXPRESSION, "* * * * *")); Alert alertSharedUser2 = alertService.updateAlert(new Alert(user2, user2, "alert-name-shared2", EXPRESSION, "* * * * *")); @@ -427,7 +434,7 @@ public void testAlertSerDes() { module.addSerializer(Alert.class, new Alert.Serializer()); module.addSerializer(Trigger.class, new Trigger.Serializer()); module.addSerializer(Notification.class, new Notification.Serializer()); - module.addSerializer(PrincipalUser.class, new PrincipalUser.Serializer()); + module.addSerializer(PrincipalUser.class, new Alert.PrincipalUserSerializer()); module.addDeserializer(Alert.class, new Alert.Deserializer()); mapper.registerModule(module); diff --git a/ArgusCore/src/test/java/com/salesforce/dva/argus/service/DashboardServiceTest.java b/ArgusCore/src/test/java/com/salesforce/dva/argus/service/DashboardServiceTest.java index c6ce567f3..e37465e63 100644 --- a/ArgusCore/src/test/java/com/salesforce/dva/argus/service/DashboardServiceTest.java +++ b/ArgusCore/src/test/java/com/salesforce/dva/argus/service/DashboardServiceTest.java @@ -44,6 +44,7 @@ public class DashboardServiceTest extends AbstractTest { + private PrincipalUser admin; DashboardService dService; UserService uService; @@ -53,11 +54,12 @@ public void setUp() { super.setUp(); dService = system.getServiceFactory().getDashboardService(); uService = system.getServiceFactory().getUserService(); + admin = system.getServiceFactory().getUserService().findAdminUser(); } @Test public void testDashboardCrud() { - PrincipalUser owner = new PrincipalUser("owner", "owner@mycompany.abc"); + PrincipalUser owner = new PrincipalUser(admin, "owner", "owner@mycompany.abc"); Dashboard dashboard = new Dashboard(uService.findAdminUser(), "Test Dashboard", owner); dashboard = dService.updateDashboard(dashboard); @@ -75,7 +77,7 @@ public void testDashboardCrud() { @Test public void testDashboard_FindShareDelete() { - PrincipalUser owner = new PrincipalUser("owner1", "owner1@mycompany.abc"); + PrincipalUser owner = new PrincipalUser(admin, "owner1", "owner1@mycompany.abc"); Dashboard dashboard = new Dashboard(uService.findAdminUser(), "Test Dashboard", owner); dashboard.setShared(true); @@ -97,7 +99,7 @@ public void testDashboard_FindShareDelete() { @Test public void testFindDashboardsMeta() { - PrincipalUser owner = new PrincipalUser("owner1", "owner1@mycompany.abc"); + PrincipalUser owner = new PrincipalUser(admin, "owner1", "owner1@mycompany.abc"); Dashboard dashboard = new Dashboard(uService.findAdminUser(), "Test Dashboard", owner); dashboard.setShared(true); @@ -111,8 +113,8 @@ public void testFindDashboardsMeta() { @Test public void testFindDashboardsByOwnerMeta() { - PrincipalUser owner1 = new PrincipalUser("owner1", "owner1@mycompany.abc"); - PrincipalUser owner2 = new PrincipalUser("owner2", "owner2@mycompany.abc"); + PrincipalUser owner1 = new PrincipalUser(admin, "owner1", "owner1@mycompany.abc"); + PrincipalUser owner2 = new PrincipalUser(admin, "owner2", "owner2@mycompany.abc"); Dashboard dashboard1 = new Dashboard(uService.findAdminUser(), "Test Dashboard", owner1); dashboard1 = dService.updateDashboard(dashboard1); @@ -131,7 +133,7 @@ public void testFindDashboardsByOwnerMeta() { @Test public void testFindSharedDashboardsMeta() { - PrincipalUser owner = new PrincipalUser("owner1", "owner1@mycompany.abc"); + PrincipalUser owner = new PrincipalUser(admin, "owner1", "owner1@mycompany.abc"); Dashboard dashboard1 = new Dashboard(uService.findAdminUser(), "Test Dashboard1", owner); dashboard1.setShared(true); diff --git a/ArgusCore/src/test/java/com/salesforce/dva/argus/service/DefaultAlertServiceTest.java b/ArgusCore/src/test/java/com/salesforce/dva/argus/service/DefaultAlertServiceTest.java index aca1bce99..0e169c18f 100644 --- a/ArgusCore/src/test/java/com/salesforce/dva/argus/service/DefaultAlertServiceTest.java +++ b/ArgusCore/src/test/java/com/salesforce/dva/argus/service/DefaultAlertServiceTest.java @@ -635,7 +635,7 @@ private DefaultAlertService _initializeSpyAlertServiceWithStubs(final AtomicInte module.addSerializer(Alert.class, new Alert.Serializer()); module.addSerializer(Trigger.class, new Trigger.Serializer()); module.addSerializer(Notification.class, new Notification.Serializer()); - module.addSerializer(PrincipalUser.class, new PrincipalUser.Serializer()); + module.addSerializer(PrincipalUser.class, new Alert.PrincipalUserSerializer()); mapper.registerModule(module); try { diff --git a/ArgusCore/src/test/java/com/salesforce/dva/argus/service/NamespaceServiceTest.java b/ArgusCore/src/test/java/com/salesforce/dva/argus/service/NamespaceServiceTest.java index 79c62ce8e..5f7ee9525 100644 --- a/ArgusCore/src/test/java/com/salesforce/dva/argus/service/NamespaceServiceTest.java +++ b/ArgusCore/src/test/java/com/salesforce/dva/argus/service/NamespaceServiceTest.java @@ -46,6 +46,7 @@ public class NamespaceServiceTest extends AbstractTest { + private PrincipalUser _admin; private NamespaceService _namespaceService; private UserService _userService; @@ -53,6 +54,7 @@ public class NamespaceServiceTest extends AbstractTest { public void setupNamespaceServiceTest() { _namespaceService = system.getServiceFactory().getNamespaceService(); _userService = system.getServiceFactory().getUserService(); + _admin = system.getServiceFactory().getUserService().findAdminUser(); } @Test @@ -88,7 +90,7 @@ public void testFindNamespaceByPrimaryKey() { @Test public void testAddAdditionalUsersToNamespace() { PrincipalUser user = _userService.findAdminUser(); - PrincipalUser user1 = new PrincipalUser("abc", "abc@xyz.com"); + PrincipalUser user1 = new PrincipalUser(_admin, "abc", "abc@xyz.com"); Namespace namespace = new Namespace("namespace", user); namespace = _namespaceService.createNamespace(namespace); @@ -100,7 +102,7 @@ public void testAddAdditionalUsersToNamespace() { @Test public void testUserIsPermitted() { PrincipalUser user = _userService.findAdminUser(); - PrincipalUser user1 = new PrincipalUser("abc", "abc@xyz.com"); + PrincipalUser user1 = new PrincipalUser(_admin, "abc", "abc@xyz.com"); Namespace namespace = new Namespace("namespace", user); namespace = _namespaceService.createNamespace(namespace); @@ -111,7 +113,7 @@ public void testUserIsPermitted() { @Test public void testAdditionalUserIsPermitted() { PrincipalUser user = _userService.findAdminUser(); - PrincipalUser user1 = new PrincipalUser("abc", "abc@xyz.com"); + PrincipalUser user1 = new PrincipalUser(_admin, "abc", "abc@xyz.com"); Namespace namespace = new Namespace("namespace", user); namespace = _namespaceService.createNamespace(namespace); diff --git a/ArgusCore/src/test/java/com/salesforce/dva/argus/service/NotifierIT.java b/ArgusCore/src/test/java/com/salesforce/dva/argus/service/NotifierIT.java index 8017107a2..1aea9efc2 100644 --- a/ArgusCore/src/test/java/com/salesforce/dva/argus/service/NotifierIT.java +++ b/ArgusCore/src/test/java/com/salesforce/dva/argus/service/NotifierIT.java @@ -119,7 +119,7 @@ public void testGusNotifier() { @Test public void testWardenNotifier() throws InterruptedException { UserService userService = system.getServiceFactory().getUserService(); - PrincipalUser user = new PrincipalUser("aUser", "aUser@mycompany.abc"); + PrincipalUser user = new PrincipalUser(userService.findAdminUser(), "aUser", "aUser@mycompany.abc"); user.setCreatedBy(user); user = userService.updateUser(user); diff --git a/ArgusCore/src/test/java/com/salesforce/dva/argus/service/UserServiceTest.java b/ArgusCore/src/test/java/com/salesforce/dva/argus/service/UserServiceTest.java index cff7412b8..616157498 100644 --- a/ArgusCore/src/test/java/com/salesforce/dva/argus/service/UserServiceTest.java +++ b/ArgusCore/src/test/java/com/salesforce/dva/argus/service/UserServiceTest.java @@ -48,9 +48,8 @@ public class UserServiceTest extends AbstractTest { @Test public void testUserCrud() { UserService userService = system.getServiceFactory().getUserService(); - PrincipalUser user = new PrincipalUser("aUser", "aUser@mycompany.abc"); + PrincipalUser user = new PrincipalUser(userService.findAdminUser(), "aUser", "aUser@mycompany.abc"); - user.setCreatedBy(user); user = userService.updateUser(user); assertNotNull(user.getId()); user.setEmail("someotheruser@mycompany.abc"); diff --git a/ArgusCore/src/test/java/com/salesforce/dva/argus/service/WardenServiceIT.java b/ArgusCore/src/test/java/com/salesforce/dva/argus/service/WardenServiceIT.java index c66c8ca6d..a35b8bb3b 100644 --- a/ArgusCore/src/test/java/com/salesforce/dva/argus/service/WardenServiceIT.java +++ b/ArgusCore/src/test/java/com/salesforce/dva/argus/service/WardenServiceIT.java @@ -66,7 +66,7 @@ public void setUp() { PrincipalUser user = _userService.findUserByUsername("bhinav.sura"); if (user == null) { - user = new PrincipalUser("bhinav.sura", "bhinav.sura@salesforce.com"); + user = new PrincipalUser(_userService.findAdminUser(), "bhinav.sura", "bhinav.sura@salesforce.com"); user = _userService.updateUser(user); } _wardenService.reinstateUser(user, SubSystem.API); diff --git a/ArgusCore/src/test/java/com/salesforce/dva/argus/service/WardenServiceTest.java b/ArgusCore/src/test/java/com/salesforce/dva/argus/service/WardenServiceTest.java index 5278fe66c..f2928e2d6 100644 --- a/ArgusCore/src/test/java/com/salesforce/dva/argus/service/WardenServiceTest.java +++ b/ArgusCore/src/test/java/com/salesforce/dva/argus/service/WardenServiceTest.java @@ -71,7 +71,7 @@ public void setUp() { PrincipalUser user = _userService.findUserByUsername("bhinav.sura"); if (user == null) { - user = new PrincipalUser("bhinav.sura", "bhinav.sura@salesforce.com"); + user = new PrincipalUser(_userService.findAdminUser(), "bhinav.sura", "bhinav.sura@salesforce.com"); user = _userService.updateUser(user); } _wardenService.reinstateUser(user, SubSystem.API); diff --git a/argus-build.properties b/argus-build.properties index 34bf154d5..e2fd457f5 100644 --- a/argus-build.properties +++ b/argus-build.properties @@ -5,6 +5,7 @@ system.property.admin.email=argus-admin@mycompany.com system.property.log.level=ERROR system.property.mail.enabled=false service.binding.tsdb=com.salesforce.dva.argus.service.tsdb.DefaultTSDBService +service.binding.cache=com.salesforce.dva.argus.service.cache.NoOperationCacheService service.property.mq.connection.count=2 service.property.mq.endpoint=vm\://localhost?broker.persistent\=false service.property.auth.ldap.authtype=simple diff --git a/src/test/resources/argus.properties b/src/test/resources/argus.properties index 6146e58ac..56f72040c 100644 --- a/src/test/resources/argus.properties +++ b/src/test/resources/argus.properties @@ -1,7 +1,7 @@ system.property.mail.enabled=${system.property.mail.enabled} system.property.admin.email=${system.property.admin.email} system.property.log.level=${system.property.log.level} -service.binding.cache=com.salesforce.dva.argus.service.cache.RedisCacheService +service.binding.cache=${service.binding.cache} service.binding.tsdb=${service.binding.tsdb} service.property.mq.connection.count=${service.property.mq.connection.count} service.property.mq.endpoint=${service.property.mq.endpoint}