Skip to content

Commit 3d9cbf0

Browse files
committed
CLOUDSTACK-8733: Host stuck in rebalancing state during agent LB
This is happening as ClusterServiceServletAdapter is started after ClusteredAgentManagerImpl. Fix is to start ClusterServiceServletAdapter before ClusteredAgentManagerImpl. (cherry-picked from c989921)
1 parent 0b4f972 commit 3d9cbf0

File tree

3 files changed

+53
-1
lines changed

3 files changed

+53
-1
lines changed

framework/cluster/src/com/cloud/cluster/ClusterServiceServletAdapter.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@
2424
import javax.naming.ConfigurationException;
2525

2626
import org.apache.log4j.Logger;
27-
2827
import org.apache.cloudstack.framework.config.ConfigDepot;
2928

3029
import com.cloud.cluster.dao.ManagementServerHostDao;
3130
import com.cloud.utils.NumbersUtil;
3231
import com.cloud.utils.component.AdapterBase;
32+
import com.cloud.utils.component.ComponentLifecycle;
3333
import com.cloud.utils.db.DbProperties;
3434

3535
public class ClusterServiceServletAdapter extends AdapterBase implements ClusterServiceAdapter {
@@ -50,6 +50,10 @@ public class ClusterServiceServletAdapter extends AdapterBase implements Cluster
5050

5151
private int _clusterServicePort = DEFAULT_SERVICE_PORT;
5252

53+
public ClusterServiceServletAdapter() {
54+
setRunLevel(ComponentLifecycle.RUN_LEVEL_FRAMEWORK);
55+
}
56+
5357
@Override
5458
public ClusterService getPeerService(String strPeer) throws RemoteException {
5559
try {
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
package com.cloud.cluster;
18+
19+
import static org.junit.Assert.assertTrue;
20+
21+
import org.junit.Before;
22+
import org.junit.Test;
23+
import org.junit.runner.RunWith;
24+
import org.mockito.runners.MockitoJUnitRunner;
25+
26+
import com.cloud.utils.component.ComponentLifecycle;
27+
28+
@RunWith(MockitoJUnitRunner.class)
29+
public class ClusterServiceServletAdapterTest {
30+
31+
ClusterServiceServletAdapter clusterServiceServletAdapter;
32+
ClusterManagerImpl clusterManagerImpl;
33+
34+
@Before
35+
public void setup() throws IllegalArgumentException,
36+
IllegalAccessException, NoSuchFieldException, SecurityException {
37+
clusterServiceServletAdapter = new ClusterServiceServletAdapter();
38+
clusterManagerImpl = new ClusterManagerImpl();
39+
}
40+
41+
@Test
42+
public void testRunLevel() {
43+
int runLevel = clusterServiceServletAdapter.getRunLevel();
44+
assertTrue(runLevel == ComponentLifecycle.RUN_LEVEL_FRAMEWORK);
45+
assertTrue(runLevel == clusterManagerImpl.getRunLevel());
46+
}
47+
}

framework/jobs/src/org/apache/cloudstack/framework/jobs/impl/SyncQueueManagerImpl.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ public void doInTransactionWithoutResult(TransactionStatus status) {
207207
@Override
208208
@DB
209209
public void returnItem(final long queueItemId) {
210+
s_logger.info("Returning queue item " + queueItemId + " back to queue for second try in case of DB deadlock");
210211
try {
211212
Transaction.execute(new TransactionCallbackNoReturn() {
212213
@Override

0 commit comments

Comments
 (0)