eubnara commented on code in PR #4262:
URL: https://github.com/apache/ambari/pull/4262#discussion_r4547024623
##########
ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerImplTest.java:
##########
@@ -262,6 +262,79 @@ public void
testServiceMetadataCredentialsAreResolvedForEachClusterService() thr
repositoryVersionB, serviceA, serviceB, serviceInfo);
}
+ @Test
+ public void testAddedHostComponentsRefreshAgentConfigsOfTheirHosts() throws
Exception {
+ // Config pushes skip hosts without a component of the owning service, so
a host that gains
+ // components (e.g. a new service whose configs were saved first) must be
refreshed here.
+ Injector injector = createStrictMock(Injector.class);
+ Capture<AmbariManagementController> controllerCapture =
EasyMock.newCapture();
+ constructorInit(injector, controllerCapture,
createNiceMock(KerberosHelper.class));
+
+ ConfigHelper localConfigHelper = createMock(ConfigHelper.class);
+ Cluster cluster = createMock(Cluster.class);
+ Host host1 = createMock(Host.class);
+ Host host2 = createMock(Host.class);
+ Capture<List<Long>> pushedHostIds = EasyMock.newCapture();
+
+ expect(clusters.getHost("host1")).andReturn(host1).times(2);
+ expect(clusters.getHost("host2")).andReturn(host2);
+ expect(host1.getHostId()).andReturn(1L).times(2);
+ expect(host2.getHostId()).andReturn(2L);
+ expect(clusters.getCluster("cluster1")).andReturn(cluster);
+ localConfigHelper.updateAgentConfigs(eq(cluster), capture(pushedHostIds));
+ expectLastCall().once();
+
+ replay(injector, clusters, cluster, host1, host2, localConfigHelper);
+
+ AmbariManagementControllerImpl controller = new
AmbariManagementControllerImpl(null, clusters, injector);
+ Field configHelperField =
AmbariManagementControllerImpl.class.getDeclaredField("configHelper");
+ configHelperField.setAccessible(true);
+ configHelperField.set(controller, localConfigHelper);
+
+ controller.updateAgentConfigsForAddedComponents(new
HashSet<>(Arrays.asList(
+ new ServiceComponentHostRequest("cluster1", "RANGER", "RANGER_ADMIN",
"host1", null),
+ new ServiceComponentHostRequest("cluster1", "RANGER",
"RANGER_USERSYNC", "host1", null),
+ new ServiceComponentHostRequest("cluster1", "RANGER",
"RANGER_TAGSYNC", "host2", null))));
+
+ // One push per cluster, each host that received a component exactly once.
+ assertEquals(2, pushedHostIds.getValue().size());
+ assertEquals(new HashSet<>(Arrays.asList(1L, 2L)), new
HashSet<>(pushedHostIds.getValue()));
+ verify(injector, clusters, cluster, host1, host2, localConfigHelper);
+ }
+
+ @Test
+ public void testAddedHostComponentsFailWhenAgentConfigsCannotBeRefreshed()
throws Exception {
+ Injector injector = createStrictMock(Injector.class);
+ Capture<AmbariManagementController> controllerCapture =
EasyMock.newCapture();
+ constructorInit(injector, controllerCapture,
createNiceMock(KerberosHelper.class));
+
+ ConfigHelper localConfigHelper = createMock(ConfigHelper.class);
+ Cluster cluster = createMock(Cluster.class);
+ Host host1 = createMock(Host.class);
+
+ expect(clusters.getHost("host1")).andReturn(host1);
+ expect(host1.getHostId()).andReturn(1L);
+ expect(clusters.getCluster("cluster1")).andReturn(cluster);
+ localConfigHelper.updateAgentConfigs(eq(cluster),
eq(Collections.singletonList(1L)));
+ expectLastCall().andThrow(new AmbariException("Configurations for cluster
2 are unavailable for host 1"));
Review Comment:
The test uses 'cluster1'. Is it a typo?
##########
ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java:
##########
@@ -786,6 +786,32 @@ public synchronized void
createHostComponents(Set<ServiceComponentHostRequest> r
// now doing actual work
persistServiceComponentHosts(requests, isBlueprintProvisioned);
m_topologyHolder.get().updateData(getAddedComponentsTopologyEvent(requests));
+ updateAgentConfigsForAddedComponents(requests);
Review Comment:
Thanks for the fix! One suggestion: could we call
updateAgentConfigsForAddedComponents before persistServiceComponentHosts
instead of after?
Calling it after the persist has two side effects:
1. New components are marked restart-required right after creation.
updateAgentConfigs(cluster, hostIds) runs
checkStaleConfigsStatusOnConfigsUpdate on the diff between the host's cached
and current configs. For a newly added service, that diff contains the
service's own types (e.g. admin-properties), and the just-persisted INIT
components already exist, so they are flagged restart-required.
HeartbeatProcessor clears the flag only after START (or INSTALL for clients),
so an install-only master/slave from Add Component keeps showing "Restart
required" until it is started. This did not happen before AMBARI-26614, because
configs reached the host before the components existed.
2. A failure in updateAgentConfigsForAddedComponents leaves the request
half-applied.
createHostComponents is not transactional. When
updateAgentConfigsForAddedComponents throws, the components are already
persisted and the topology update has already been sent, but the API call
fails. A retry then hits DuplicateResourceException ("Attempted to create a
host_component which already exists").
Calling updateAgentConfigsForAddedComponents before
persistServiceComponentHosts avoids both:
- The agent config payload (getHostActualConfigs) depends only on the host
and its config groups, not on its components, so the pushed configs are the
same.
- The stale check sees only the existing components, so the new ones are not
flagged. Existing components are unaffected, because a host only misses config
types that none of its components depend on.
- If updateAgentConfigsForAddedComponents fails, nothing has been persisted
yet, so the request fails cleanly and can be retried.
- createHostComponents and updateClusters are both synchronized on the
controller, so no config change can slip in between the config push and the
persist.
- It restores the pre-AMBARI-26614 order: configs first, components later.
Suggested change:
```java
// set restartRequired flag for monitoring services
setMonitoringServicesRestartRequired(requests);
// Push configs before persisting, so the stale check does not flag the
new components
// and a failed config push leaves nothing persisted.
updateAgentConfigsForAddedComponents(requests);
// now doing actual work
persistServiceComponentHosts(requests, isBlueprintProvisioned);
m_topologyHolder.get().updateData(getAddedComponentsTopologyEvent(requests));
}
```
The Javadoc of updateAgentConfigsForAddedComponents should then say "the
host components about to be persisted" instead of "the host component requests
that were just persisted".
It would also be good to cover the ordering in a test:
- When updateAgentConfigsForAddedComponents fails,
persistServiceComponentHosts is never called (for example, a partial mock of
AmbariManagementControllerImpl that mocks both methods and expects only
updateAgentConfigsForAddedComponents).
- On success, updateAgentConfigsForAddedComponents runs before
persistServiceComponentHosts (a strict mock, or EasyMock.createStrictControl(),
checks the call order).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]