Skip to content

Commit 1924410

Browse files
authored
Merge branch 'main' into multi-scope-config
2 parents 3f76576 + 4cf6fc9 commit 1924410

File tree

166 files changed

+4067
-1635
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

166 files changed

+4067
-1635
lines changed

.asf.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ github:
6060
- bernardodemarco
6161
- abh1sar
6262
- FelipeM525
63+
- lucas-a-martins
6364

6465
protected_branches: ~
6566

.github/ISSUE_TEMPLATE/bug.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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+
description: "Thank you for reporting a bug!"
18+
name: bug
19+
title: "[SHORT PROBLEM DESCRIPTION]"
20+
labels: bug, needs-triageing
21+
body:
22+
- type: markdown
23+
attributes:
24+
value: "## Welcome, please describe your problem below;"
25+
- type: textarea
26+
attributes:
27+
label: problem
28+
value: The long description of your problem
29+
- type: markdown
30+
attributes:
31+
value: "## What versions of cloudstack and any infra components are you using"
32+
- type: textarea
33+
attributes:
34+
label: versions
35+
value: The versions of ACS, hypervisors, storage, network etc..
36+
- type: textarea
37+
attributes:
38+
label: The steps to reproduce the bug
39+
value: |
40+
1.
41+
2.
42+
3.
43+
...
44+
- type: textarea
45+
attributes:
46+
label: "What to do about it?"
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
description: "Thank you for your new feature idea!"
18+
name: feature
19+
title: "[SHORT FUNCTIONAL DESCRIPTION]"
20+
labels: new
21+
body:
22+
- type: textarea
23+
attributes:
24+
label: "The required feature described as a wish"
25+
value: As a User/Admin/Operator I would like to , ... have the system make my morning coffee.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Apache CloudStack [![Build Status](https://github.com/apache/cloudstack/actions/workflows/build.yml/badge.svg?branch=main)](https://github.com/apache/cloudstack/actions/workflows/build.yml) [![UI Build](https://github.com/apache/cloudstack/actions/workflows/ui.yml/badge.svg)](https://github.com/apache/cloudstack/actions/workflows/ui.yml) [![License Check](https://github.com/apache/cloudstack/actions/workflows/rat.yml/badge.svg?branch=main)](https://github.com/apache/cloudstack/actions/workflows/rat.yml) [![Simulator CI](https://github.com/apache/cloudstack/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/apache/cloudstack/actions/workflows/ci.yml) [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=apache_cloudstack&metric=alert_status)](https://sonarcloud.io/dashboard?id=apache_cloudstack) [![codecov](https://codecov.io/gh/apache/cloudstack/branch/main/graph/badge.svg)](https://codecov.io/gh/apache/cloudstack)
22

3-
[![Apache CloudStack](tools/logo/acsxmas.jpg)](https://cloudstack.apache.org/)
3+
[![Apache CloudStack](tools/logo/apache_cloudstack.png)](https://cloudstack.apache.org/)
44

55
Apache CloudStack is open source software designed to deploy and manage large
66
networks of virtual machines, as a highly available, highly scalable

agent/conf/agent.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ hypervisor.type=kvm
209209
# the management server would send.
210210
# In case of arm64 (aarch64), this will change the machine type to 'virt' and
211211
# adds a SCSI and a USB controller in the domain xml.
212-
# Possible values: x86_64 | aarch64
212+
# Possible values: x86_64 | aarch64 | s390x
213213
# If null (default), defaults to the VM's OS architecture
214214
#guest.cpu.arch=
215215

@@ -286,6 +286,7 @@ hypervisor.type=kvm
286286

287287
# The model of Watchdog timer to present to the Guest.
288288
# For all models refer to the libvirt documentation.
289+
# PLEASE NOTE: to disable the watchdogs definitions, use value: none
289290
#vm.watchdog.model=i6300esb
290291

291292
# Action to take when the Guest/Instance is no longer notifying the Watchdog timer.

agent/src/main/java/com/cloud/agent/Agent.java

Lines changed: 84 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.nio.channels.ClosedChannelException;
2828
import java.nio.charset.Charset;
2929
import java.util.ArrayList;
30+
import java.util.Arrays;
3031
import java.util.HashMap;
3132
import java.util.List;
3233
import java.util.Map;
@@ -40,6 +41,8 @@
4041

4142
import javax.naming.ConfigurationException;
4243

44+
import com.cloud.agent.api.MigrateAgentConnectionAnswer;
45+
import com.cloud.agent.api.MigrateAgentConnectionCommand;
4346
import com.cloud.resource.AgentStatusUpdater;
4447
import com.cloud.resource.ResourceStatusUpdater;
4548
import com.cloud.agent.api.PingAnswer;
@@ -313,7 +316,6 @@ public void start() {
313316
}
314317
_shell.updateConnectedHost();
315318
scavengeOldAgentObjects();
316-
317319
}
318320

319321
public void stop(final String reason, final String detail) {
@@ -477,13 +479,18 @@ public synchronized void lockStartupTask(final Link link) {
477479
}
478480

479481
public void sendStartup(final Link link) {
482+
sendStartup(link, false);
483+
}
484+
485+
public void sendStartup(final Link link, boolean transfer) {
480486
final StartupCommand[] startup = _resource.initialize();
481487
if (startup != null) {
482488
final String msHostList = _shell.getPersistentProperty(null, "host");
483489
final Command[] commands = new Command[startup.length];
484490
for (int i = 0; i < startup.length; i++) {
485491
setupStartupCommand(startup[i]);
486492
startup[i].setMSHostList(msHostList);
493+
startup[i].setConnectionTransferred(transfer);
487494
commands[i] = startup[i];
488495
}
489496
final Request request = new Request(_id != null ? _id : -1, -1, commands, false, false);
@@ -541,9 +548,14 @@ public Task create(final Task.Type type, final Link link, final byte[] data) {
541548
}
542549

543550
protected void reconnect(final Link link) {
544-
if (!_reconnectAllowed) {
551+
reconnect(link, null, null, false);
552+
}
553+
554+
protected void reconnect(final Link link, String preferredHost, List<String> avoidHostList, boolean forTransfer) {
555+
if (!(forTransfer || _reconnectAllowed)) {
545556
return;
546557
}
558+
547559
synchronized (this) {
548560
if (_startup != null) {
549561
_startup.cancel();
@@ -575,22 +587,29 @@ protected void reconnect(final Link link) {
575587
_shell.getBackoffAlgorithm().waitBeforeRetry();
576588
}
577589

590+
String host = preferredHost;
591+
if (StringUtils.isEmpty(host)) {
592+
host = _shell.getNextHost();
593+
}
594+
578595
do {
579-
final String host = _shell.getNextHost();
580-
_connection = new NioClient("Agent", host, _shell.getPort(), _shell.getWorkers(), this);
581-
logger.info("Reconnecting to host:{}", host);
582-
try {
583-
_connection.start();
584-
} catch (final NioConnectionException e) {
585-
logger.info("Attempted to re-connect to the server, but received an unexpected exception, trying again...", e);
586-
_connection.stop();
596+
if (CollectionUtils.isEmpty(avoidHostList) || !avoidHostList.contains(host)) {
597+
_connection = new NioClient("Agent", host, _shell.getPort(), _shell.getWorkers(), this);
598+
logger.info("Reconnecting to host:{}", host);
587599
try {
588-
_connection.cleanUp();
589-
} catch (final IOException ex) {
590-
logger.warn("Fail to clean up old connection. {}", ex);
600+
_connection.start();
601+
} catch (final NioConnectionException e) {
602+
logger.info("Attempted to re-connect to the server, but received an unexpected exception, trying again...", e);
603+
_connection.stop();
604+
try {
605+
_connection.cleanUp();
606+
} catch (final IOException ex) {
607+
logger.warn("Fail to clean up old connection. {}", ex);
608+
}
591609
}
592610
}
593611
_shell.getBackoffAlgorithm().waitBeforeRetry();
612+
host = _shell.getNextHost();
594613
} while (!_connection.isStartup());
595614
_shell.updateConnectedHost();
596615
logger.info("Connected to the host: {}", _shell.getConnectedHost());
@@ -703,6 +722,8 @@ protected void processRequest(final Request request, final Link link) {
703722
}
704723
} else if (cmd instanceof SetupMSListCommand) {
705724
answer = setupManagementServerList((SetupMSListCommand) cmd);
725+
} else if (cmd instanceof MigrateAgentConnectionCommand) {
726+
answer = migrateAgentToOtherMS((MigrateAgentConnectionCommand) cmd);
706727
} else {
707728
if (cmd instanceof ReadyCommand) {
708729
processReadyCommand(cmd);
@@ -858,6 +879,53 @@ private Answer setupManagementServerList(final SetupMSListCommand cmd) {
858879
return new SetupMSListAnswer(true);
859880
}
860881

882+
private Answer migrateAgentToOtherMS(final MigrateAgentConnectionCommand cmd) {
883+
try {
884+
if (CollectionUtils.isNotEmpty(cmd.getMsList())) {
885+
processManagementServerList(cmd.getMsList(), cmd.getLbAlgorithm(), cmd.getLbCheckInterval());
886+
}
887+
migrateAgentConnection(cmd.getAvoidMsList());
888+
} catch (Exception e) {
889+
String errMsg = "Migrate agent connection failed, due to " + e.getMessage();
890+
logger.debug(errMsg, e);
891+
return new MigrateAgentConnectionAnswer(errMsg);
892+
}
893+
return new MigrateAgentConnectionAnswer(true);
894+
}
895+
896+
private void migrateAgentConnection(List<String> avoidMsList) {
897+
final String[] msHosts = _shell.getHosts();
898+
if (msHosts == null || msHosts.length < 1) {
899+
throw new CloudRuntimeException("Management Server hosts empty, not properly configured in agent");
900+
}
901+
902+
List<String> msHostsList = new ArrayList<>(Arrays.asList(msHosts));
903+
msHostsList.removeAll(avoidMsList);
904+
if (msHostsList.isEmpty() || StringUtils.isEmpty(msHostsList.get(0))) {
905+
throw new CloudRuntimeException("No other Management Server hosts to migrate");
906+
}
907+
908+
String preferredHost = null;
909+
for (String msHost : msHostsList) {
910+
try (final Socket socket = new Socket()) {
911+
socket.connect(new InetSocketAddress(msHost, _shell.getPort()), 5000);
912+
preferredHost = msHost;
913+
break;
914+
} catch (final IOException e) {
915+
throw new CloudRuntimeException("Management server host: " + msHost + " is not reachable, to migrate connection");
916+
}
917+
}
918+
919+
if (preferredHost == null) {
920+
throw new CloudRuntimeException("Management server host(s) are not reachable, to migrate connection");
921+
}
922+
923+
logger.debug("Management server host " + preferredHost + " is found to be reachable, trying to reconnect");
924+
_shell.resetHostCounter();
925+
_shell.setConnectionTransfer(true);
926+
reconnect(_link, preferredHost, avoidMsList, true);
927+
}
928+
861929
public void processResponse(final Response response, final Link link) {
862930
final Answer answer = response.getAnswer();
863931
logger.debug("Received response: {}", response.toString());
@@ -1153,7 +1221,8 @@ public void doTask(final Task task) throws TaskExecutionException {
11531221
if (task.getType() == Task.Type.CONNECT) {
11541222
_shell.getBackoffAlgorithm().reset();
11551223
setLink(task.getLink());
1156-
sendStartup(task.getLink());
1224+
sendStartup(task.getLink(), _shell.isConnectionTransfer());
1225+
_shell.setConnectionTransfer(false);
11571226
} else if (task.getType() == Task.Type.DATA) {
11581227
Request request;
11591228
try {
@@ -1178,6 +1247,7 @@ public void doTask(final Task task) throws TaskExecutionException {
11781247
Thread.sleep(5000);
11791248
} catch (InterruptedException e) {
11801249
}
1250+
_shell.setConnectionTransfer(false);
11811251
reconnect(task.getLink());
11821252
return;
11831253
} else if (task.getType() == Task.Type.OTHER) {

agent/src/main/java/com/cloud/agent/AgentShell.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ public class AgentShell implements IAgentShell, Daemon {
7777
private String hostToConnect;
7878
private String connectedHost;
7979
private Long preferredHostCheckInterval;
80+
private boolean connectionTransfer = false;
8081
protected AgentProperties agentProperties = new AgentProperties();
8182

8283
public AgentShell() {
@@ -215,6 +216,14 @@ public void setPersistentProperty(String prefix, String name, String value) {
215216
_storage.persist(name, value);
216217
}
217218

219+
public boolean isConnectionTransfer() {
220+
return connectionTransfer;
221+
}
222+
223+
public void setConnectionTransfer(boolean connectionTransfer) {
224+
this.connectionTransfer = connectionTransfer;
225+
}
226+
218227
void loadProperties() throws ConfigurationException {
219228
final File file = PropertiesUtil.findConfigFile("agent.properties");
220229

agent/src/main/java/com/cloud/agent/IAgentShell.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,8 @@ public interface IAgentShell {
7070
String getConnectedHost();
7171

7272
void launchNewAgent(ServerResource resource) throws ConfigurationException;
73+
74+
boolean isConnectionTransfer();
75+
76+
void setConnectionTransfer(boolean connectionTransfer);
7377
}

agent/src/main/java/com/cloud/agent/properties/AgentProperties.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ public class AgentProperties{
383383
/**
384384
* This param will set the CPU architecture for the domain to override what the management server would send.<br>
385385
* In case of arm64 (aarch64), this will change the machine type to 'virt' and add a SCSI and a USB controller in the domain XML.<br>
386-
* Possible values: x86_64 | aarch64 <br>
386+
* Possible values: x86_64 | aarch64 | s390x <br>
387387
* Data type: String.<br>
388388
* Default value: <code>null</code> (will set use the architecture of the VM's OS).
389389
*/
@@ -516,6 +516,7 @@ public class AgentProperties{
516516
/**
517517
* The model of Watchdog timer to present to the Guest.<br>
518518
* For all models refer to the libvirt documentation.<br>
519+
* PLEASE NOTE: to disable the watchdogs definitions, use value: none
519520
* Data type: String.<br>
520521
* Default value: <code>i6300esb</code>
521522
*/

api/src/main/java/com/cloud/host/Host.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,8 @@ public static String[] toStrings(Host.Type... types) {
177177
*/
178178
Long getManagementServerId();
179179

180+
Long getLastManagementServerId();
181+
180182
/*
181183
*@return removal date
182184
*/

0 commit comments

Comments
 (0)