Repository navigation
Keep management server IDs same across restarts #14551
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
MashrafeeAryan
wants to merge
6
commits into
apache:main
Choose a base branch
from
MashrafeeAryan:fix/14253-stable-management-server-id
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+573
−20
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1836e09
Keep management server IDs stable across restarts
MashrafeeAryan 4a7fa72
Document management server ID storage and recovery
MashrafeeAryan b92ff81
Fix interrupted management server ID initialization
MashrafeeAryan 81987ab
Use the persistent management server ID consistently
MashrafeeAryan 7980038
Keep active management IPs out of agent avoid lists
MashrafeeAryan c22a289
Clarify management server identity comments and documentation
MashrafeeAryan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
framework/cluster/src/test/java/com/cloud/cluster/dao/ManagementServerHostDaoImplTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The ASF licenses this file | ||
| // to you under the Apache License, Version 2.0 (the | ||
| // "License"); you may not use this file except in compliance | ||
| // with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
|
|
||
| package com.cloud.cluster.dao; | ||
|
|
||
| import static org.junit.Assert.assertEquals; | ||
| import static org.mockito.Mockito.doReturn; | ||
| import static org.mockito.Mockito.spy; | ||
|
|
||
| import java.util.Arrays; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
|
|
||
| import org.apache.cloudstack.management.ManagementServerHost.State; | ||
| import org.junit.Test; | ||
|
|
||
| import com.cloud.cluster.ManagementServerHostVO; | ||
|
|
||
| // Checks that old server records do not make agents skip an available address | ||
| public class ManagementServerHostDaoImplTest { | ||
| private final ManagementServerHostDaoImpl dao = spy(new ManagementServerHostDaoImpl()); | ||
|
|
||
| // Do not avoid an address if one record says Up and an old record says Down | ||
| @Test | ||
| public void staleDownIdentityDoesNotBlockAnUpServerAtTheSameIp() { | ||
| ManagementServerHostVO down = host("10.0.0.1", State.Down); | ||
| ManagementServerHostVO up = host("10.0.0.1", State.Up); | ||
| assertAvoided(Arrays.asList(down, up)); | ||
| assertAvoided(Arrays.asList(up, down)); | ||
| } | ||
|
|
||
| // Keep unavailable addresses in the avoid list and include each address only once | ||
| @Test | ||
| public void unavailableAddressesRemainAvoidedWithoutDuplicates() { | ||
| assertAvoided(Arrays.asList(host("10.0.0.1", State.Down), host("10.0.0.1", State.Down), | ||
| host("10.0.0.2", State.Maintenance), host("10.0.0.3", State.Up)), "10.0.0.1", "10.0.0.2"); | ||
| } | ||
|
|
||
| // Allow an address marked Up even if an old record says it is in maintenance | ||
| @Test | ||
| public void upServerTakesPrecedenceOverAnOldMaintenanceRecord() { | ||
| assertAvoided(Arrays.asList(host("10.0.0.1", State.Maintenance), host("10.0.0.1", State.Up))); | ||
| } | ||
|
|
||
| // No server records means there are no addresses to avoid | ||
| @Test | ||
| public void emptyServerListHasNoAvoidedAddresses() { | ||
| assertAvoided(Collections.emptyList()); | ||
| } | ||
|
|
||
| // Run the avoid-list code with pretend records and check the returned addresses | ||
| private void assertAvoided(List<ManagementServerHostVO> hosts, String... expected) { | ||
| doReturn(hosts).when(dao).listAll(); | ||
| assertEquals(Arrays.asList(expected), dao.listNonUpStateMsIPs()); | ||
| } | ||
|
|
||
| // Make a pretend server record with an address and a state | ||
| private ManagementServerHostVO host(String ip, State state) { | ||
| ManagementServerHostVO host = new ManagementServerHostVO(); | ||
| host.setServiceIP(ip); | ||
| host.setState(state); | ||
| return host; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
server/src/test/java/com/cloud/server/ManagementServerIdentityTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The ASF licenses this file | ||
| // to you under the Apache License, Version 2.0 (the | ||
| // "License"); you may not use this file except in compliance | ||
| // with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
|
|
||
| package com.cloud.server; | ||
|
|
||
| import static org.junit.Assert.assertEquals; | ||
| import static org.mockito.ArgumentMatchers.any; | ||
| import static org.mockito.Mockito.mock; | ||
| import static org.mockito.Mockito.mockStatic; | ||
| import static org.mockito.Mockito.when; | ||
|
|
||
| import org.apache.cloudstack.utils.identity.ManagementServerNode; | ||
| import org.junit.Test; | ||
| import org.mockito.MockedStatic; | ||
| import org.mockito.Mockito; | ||
| import org.springframework.test.util.ReflectionTestUtils; | ||
|
|
||
| import com.cloud.cluster.ManagementServerHostVO; | ||
| import com.cloud.cluster.dao.ManagementServerHostDao; | ||
| import com.cloud.utils.db.Filter; | ||
| import com.cloud.utils.db.GlobalLock; | ||
| import com.cloud.utils.db.Transaction; | ||
| import com.cloud.utils.db.TransactionCallbackNoReturn; | ||
| import com.cloud.utils.net.MacAddress; | ||
|
|
||
| // Check that the server and its stats jobs use the saved ID | ||
| public class ManagementServerIdentityTest { | ||
| // Use different values for the saved ID and the ID from the network card | ||
| private static final long SAVED_ID = 123L; | ||
| private static final long CHANGED_MAC_ID = 456L; | ||
|
|
||
| // Return the saved ID even when the network card gives a different ID | ||
| @Test | ||
| public void managementServiceReportsSavedIdAfterMacChanges() { | ||
| try (MockedStatic<ManagementServerNode> node = mockStatic(ManagementServerNode.class); | ||
| MockedStatic<MacAddress> mac = mockStatic(MacAddress.class)) { | ||
| node.when(ManagementServerNode::getManagementServerId).thenReturn(SAVED_ID); | ||
| mac.when(MacAddress::getMacAddress).thenReturn(new MacAddress(CHANGED_MAC_ID)); | ||
|
|
||
| ManagementServerImpl server = mock(ManagementServerImpl.class, Mockito.CALLS_REAL_METHODS); | ||
| assertEquals(SAVED_ID, server.getId()); | ||
| } | ||
| } | ||
|
|
||
| // Still start the disk stats job when the saved ID says this server is in charge | ||
| @Test | ||
| public void owningServerStillUpdatesDiskStatsAfterMacChanges() { | ||
| StatsCollector previous = StatsCollector.getInstance(); | ||
| try (MockedStatic<ManagementServerNode> node = mockStatic(ManagementServerNode.class); | ||
| MockedStatic<MacAddress> mac = mockStatic(MacAddress.class); | ||
| MockedStatic<GlobalLock> locks = mockStatic(GlobalLock.class); | ||
| MockedStatic<Transaction> transactions = mockStatic(Transaction.class)) { | ||
| node.when(ManagementServerNode::getManagementServerId).thenReturn(SAVED_ID); | ||
| mac.when(MacAddress::getMacAddress).thenReturn(new MacAddress(CHANGED_MAC_ID)); | ||
| GlobalLock lock = mock(GlobalLock.class); | ||
| locks.when(() -> GlobalLock.getInternLock("vm.disk.stats")).thenReturn(lock); | ||
| when(lock.lock(5)).thenReturn(true); | ||
|
|
||
| // Pretend the database says this server should do the job | ||
| ManagementServerHostVO host = new ManagementServerHostVO(); | ||
| host.setMsid(SAVED_ID); | ||
| ManagementServerHostDao dao = mock(ManagementServerHostDao.class); | ||
| when(dao.findOneInUpState(any(Filter.class))).thenReturn(host); | ||
| StatsCollector collector = new StatsCollector(); | ||
| ReflectionTestUtils.setField(collector, "managementServerHostDao", dao); | ||
|
|
||
| collector.new VmDiskStatsUpdaterTask().runInContext(); | ||
|
|
||
| transactions.verify(() -> Transaction.execute(any(TransactionCallbackNoReturn.class))); | ||
| } finally { | ||
| // Put the old stats collector back so other tests are not affected | ||
| ReflectionTestUtils.setField(StatsCollector.class, "s_instance", previous); | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MashrafeeAryan instead of skipping old down rows in the avoid list, can we just mark old rows with the same ip as removed when the ms registers? fixes the leftover rows too, like in #14448