Skip to content
Permalink
Browse files
[AMBARI-25131] Alert notification properties are wiped after enabling…
…/disabling the notification (dsen) (#2786)
  • Loading branch information
d0zen1 committed Jan 31, 2019
1 parent cbd6284 commit 1a711038698490b1f6423e3e4801ae98598d0366
Showing 2 changed files with 61 additions and 3 deletions.
@@ -422,9 +422,14 @@ void updateAlertTargets(long alertTargetId,
entity.setNotificationType(notificationType);
}

String properties = s_gson.toJson(extractProperties(requestMap));
if (!StringUtils.isEmpty(properties)) {
entity.setProperties(properties);
Map<String, Object> propertiesMap = extractProperties(requestMap);

if (propertiesMap != null) {
String properties = s_gson.toJson(propertiesMap);
if (!StringUtils.isEmpty(properties)) {
LOG.debug("Updating Alert Target properties map to: " + properties);
entity.setProperties(properties);
}
}

// a null alert state implies that the key was not set and no update
@@ -533,17 +538,23 @@ private Resource toResource(AlertTargetEntity entity, Set<String> requestedIds)
private Map<String, Object> extractProperties(Map<String, Object> requestMap) {
Map<String, Object> normalizedMap = new HashMap<>(
requestMap.size());
boolean has_properties = false;

for (Entry<String, Object> entry : requestMap.entrySet()) {
String key = entry.getKey();
String propCat = PropertyHelper.getPropertyCategory(key);

if (propCat.equals(ALERT_TARGET_PROPERTIES)) {
has_properties = true;
String propKey = PropertyHelper.getPropertyName(key);
normalizedMap.put(propKey, entry.getValue());
}
}

if (!has_properties) {
normalizedMap = null;
}

return normalizedMap;
}

@@ -1007,6 +1007,53 @@ public void testUpdateAlertTargetsWithAllGroups() throws Exception{
verify(m_amc, m_dao);
}

@Test
public void testEnable() throws Exception {
Capture<AlertTargetEntity> entityCapture = EasyMock.newCapture();
m_dao.create(capture(entityCapture));
expectLastCall().times(1);

AlertTargetEntity target = new AlertTargetEntity();
target.setEnabled(false);
target.setProperties("{prop1=val1}");
expect(m_dao.findTargetById(ALERT_TARGET_ID)).andReturn(target).times(1);

expect(m_dao.merge(capture(entityCapture))).andReturn(target).once();

replay(m_amc, m_dao);

SecurityContextHolder.getContext().setAuthentication(TestAuthenticationFactory.createAdministrator());

AlertTargetResourceProvider provider = createProvider(m_amc);
Map<String, Object> requestProps = getCreationProperties();
Request request = PropertyHelper.getCreateRequest(
Collections.singleton(requestProps), null);
provider.createResources(request);

// create new properties, and include the ID since we're not going through
// a service layer which would add it for us automatically
requestProps = new HashMap<>();
requestProps.put(AlertTargetResourceProvider.ALERT_TARGET_ID,
ALERT_TARGET_ID.toString());

requestProps.put(AlertTargetResourceProvider.ALERT_TARGET_ENABLED,
"true");

Predicate predicate = new PredicateBuilder().property(
AlertTargetResourceProvider.ALERT_TARGET_ID).equals(
ALERT_TARGET_ID.toString()).toPredicate();

request = PropertyHelper.getUpdateRequest(requestProps, null);
provider.updateResources(request, predicate);

assertTrue(entityCapture.hasCaptured());

AlertTargetEntity entity = entityCapture.getValue();
assertTrue("{prop1=val1}".equals(entity.getProperties()));
assertTrue(entity.isEnabled());
verify(m_amc, m_dao);
}

/**
* @param amc
* @return

0 comments on commit 1a71103

Please sign in to comment.