Skip to content

Commit eba8200

Browse files
committed
호스트 별 라이브마이그레이션 전용 IP 설정 및 기능 개발
1 parent f90f7a3 commit eba8200

File tree

15 files changed

+4833
-4698
lines changed

15 files changed

+4833
-4698
lines changed

api/src/main/java/org/apache/cloudstack/api/ApiConstants.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1312,6 +1312,8 @@ public class ApiConstants {
13121312

13131313
public static final String RESULT_REDFISH_DATA = "redfishdata";
13141314
public static final String EXTERNAL_ENTITY = "externalEntity";
1315+
public static final String MIGRATION_IP = "migrationip";
1316+
13151317

13161318
/**
13171319
* This enum specifies IO Drivers, each option controls specific policies on I/O.

api/src/main/java/org/apache/cloudstack/api/command/admin/host/UpdateHostCmd.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ public class UpdateHostCmd extends BaseCmd {
6767
@Parameter(name = ApiConstants.ANNOTATION, type = CommandType.STRING, description = "Add an annotation to this host", since = "4.11", authorized = {RoleType.Admin})
6868
private String annotation;
6969

70+
@Parameter(name = ApiConstants.MIGRATION_IP, type = CommandType.STRING, description = "Add an migration ip to this host", since = "4.20")
71+
private String migrationIp;
72+
7073
/////////////////////////////////////////////////////
7174
/////////////////// Accessors ///////////////////////
7275
/////////////////////////////////////////////////////
@@ -103,6 +106,10 @@ public String getAnnotation() {
103106
return annotation;
104107
}
105108

109+
public String getMigrationIp() {
110+
return migrationIp;
111+
}
112+
106113
/////////////////////////////////////////////////////
107114
/////////////// API Implementation///////////////////
108115
/////////////////////////////////////////////////////

api/src/main/java/org/apache/cloudstack/api/response/HostResponse.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,18 @@ public class HostResponse extends BaseResponseWithAnnotations {
298298
@Param(description = "CPU Arch of the host", since = "4.20")
299299
private String arch;
300300

301+
@SerializedName(ApiConstants.MIGRATION_IP)
302+
@Param(description = "Live Migration Ip of the host", since = "4.21")
303+
private String migrationIp;
304+
305+
public String getMigrationIp() {
306+
return migrationIp;
307+
}
308+
309+
public void setMigrationIp(String migrationIp) {
310+
this.migrationIp = migrationIp;
311+
}
312+
301313
@Override
302314
public String getObjectId() {
303315
return this.getId();

engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2914,8 +2914,13 @@ protected void migrate(final VMInstanceVO vm, final long srcHostId, final Deploy
29142914
*/
29152915
protected MigrateCommand buildMigrateCommand(VMInstanceVO vmInstance, VirtualMachineTO virtualMachineTO, DeployDestination destination, Answer answer,
29162916
Map<String, DpdkTO> dpdkInterfaceMapping) {
2917+
final HostVO destHost = _hostDao.findById(destination.getHost().getId());
2918+
String destIp = StringUtils.isNotBlank(destHost.getMigrationIp())
2919+
? destHost.getMigrationIp()
2920+
: destination.getHost().getPrivateIpAddress();
2921+
29172922
final boolean isWindows = _guestOsCategoryDao.findById(_guestOsDao.findById(vmInstance.getGuestOSId()).getCategoryId()).getName().equalsIgnoreCase("Windows");
2918-
final MigrateCommand migrateCommand = new MigrateCommand(vmInstance.getInstanceName(), destination.getHost().getPrivateIpAddress(), isWindows, virtualMachineTO,
2923+
final MigrateCommand migrateCommand = new MigrateCommand(vmInstance.getInstanceName(), destIp, isWindows, virtualMachineTO,
29192924
getExecuteInSequence(vmInstance.getHypervisorType()));
29202925

29212926
Map<String, Boolean> vlanToPersistenceMap = getVlanToPersistenceMapForVM(vmInstance.getId());

engine/schema/src/main/java/com/cloud/host/HostVO.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,9 @@ public void setGpuGroups(HashMap<String, HashMap<String, VgpuTypesInfo>> groupDe
410410
@Column(name = "version")
411411
private String version;
412412

413+
@Column(name = "migration_ip")
414+
private String migrationIp;
415+
413416
@Column(name = GenericDao.CREATED_COLUMN)
414417
private Date created;
415418

@@ -570,6 +573,14 @@ public void setManagementServerId(Long managementServerId) {
570573
this.managementServerId = managementServerId;
571574
}
572575

576+
public void setMigrationIp(String migrationIp) {
577+
this.migrationIp = migrationIp;
578+
}
579+
580+
public String getMigrationIp() {
581+
return migrationIp;
582+
}
583+
573584
@Override
574585
public long getLastPinged() {
575586
return lastPinged;

engine/schema/src/main/resources/META-INF/db/schema-Diplo-After.sql

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,6 @@ INSERT IGNORE INTO `cloud`.`vbmc_port` (id, port) VALUES (17, 6246);
4747
INSERT IGNORE INTO `cloud`.`vbmc_port` (id, port) VALUES (18, 6247);
4848
INSERT IGNORE INTO `cloud`.`vbmc_port` (id, port) VALUES (19, 6248);
4949
INSERT IGNORE INTO `cloud`.`vbmc_port` (id, port) VALUES (20, 6249);
50-
INSERT IGNORE INTO `cloud`.`vbmc_port` (id, port) VALUES (21, 6250);
50+
INSERT IGNORE INTO `cloud`.`vbmc_port` (id, port) VALUES (21, 6250);
51+
52+
CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.host', 'migration_ip', 'VARCHAR(45)');

engine/schema/src/main/resources/META-INF/db/views/cloud.host_view.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ SELECT
4242
host.speed,
4343
host.ram,
4444
host.arch,
45+
host.migration_ip,
4546
cluster.id cluster_id,
4647
cluster.uuid cluster_uuid,
4748
cluster.name cluster_name,

server/src/main/java/com/cloud/api/query/dao/HostJoinDaoImpl.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ public HostResponse newHostResponse(HostJoinVO host, EnumSet<HostDetails> detail
144144
hostResponse.setIpAddress(host.getPrivateIpAddress());
145145
hostResponse.setVersion(host.getVersion());
146146
hostResponse.setCreated(host.getCreated());
147+
hostResponse.setMigrationIp(host.getMigrationIp());
147148

148149
List<HostGpuGroupsVO> gpuGroups = ApiDBUtils.getGpuGroups(host.getId());
149150
if (gpuGroups != null && !gpuGroups.isEmpty()) {

server/src/main/java/com/cloud/api/query/vo/HostJoinVO.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,9 @@ public class HostJoinVO extends BaseViewVO implements InternalIdentity, Identity
219219
@Convert(converter = CPUArchConverter.class)
220220
private CPU.CPUArch arch;
221221

222+
@Column(name = "migration_ip")
223+
private String migrationIp;
224+
222225
@Override
223226
public long getId() {
224227
return this.id;
@@ -442,4 +445,8 @@ public boolean isInMaintenanceStates() {
442445
public CPU.CPUArch getArch() {
443446
return arch;
444447
}
448+
449+
public String getMigrationIp() {
450+
return migrationIp;
451+
}
445452
}

server/src/main/java/com/cloud/resource/ResourceManagerImpl.java

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1907,6 +1907,13 @@ private void updateHostName(HostVO host, String name) {
19071907
_hostDao.update(host.getId(), host);
19081908
}
19091909

1910+
1911+
private void updateMigratinIp(HostVO host, String migrationIp) {
1912+
logger.debug("Updating Host use live migataion use ip address to: " + migrationIp);
1913+
host.setMigrationIp(migrationIp);
1914+
_hostDao.update(host.getId(), host);
1915+
}
1916+
19101917
private void updateHostGuestOSCategory(Long hostId, Long guestOSCategoryId) {
19111918
// Verify that the guest OS Category exists
19121919
if (!(guestOSCategoryId > 0) || _guestOSCategoryDao.findById(guestOSCategoryId) == null) {
@@ -1948,7 +1955,51 @@ private void updateHostTags(HostVO host, Long hostId, List<String> hostTags, Boo
19481955
@Override
19491956
public Host updateHost(final UpdateHostCmd cmd) throws NoTransitionException {
19501957
return updateHost(cmd.getId(), cmd.getName(), cmd.getOsCategoryId(),
1951-
cmd.getAllocationState(), cmd.getUrl(), cmd.getHostTags(), cmd.getIsTagARule(), cmd.getAnnotation(), false);
1958+
cmd.getAllocationState(), cmd.getUrl(), cmd.getHostTags(), cmd.getIsTagARule(), cmd.getAnnotation(), false, cmd.getMigrationIp());
1959+
}
1960+
1961+
private Host updateHost(Long hostId, String name, Long guestOSCategoryId, String allocationState,
1962+
String url, List<String> hostTags, Boolean isTagARule, String annotation, boolean isUpdateFromHostHealthCheck, String migrationIp) throws NoTransitionException {
1963+
// Verify that the host exists
1964+
final HostVO host = _hostDao.findById(hostId);
1965+
if (host == null) {
1966+
throw new InvalidParameterValueException("Host with id " + hostId + " doesn't exist");
1967+
}
1968+
1969+
boolean isUpdateHostAllocation = false;
1970+
if (StringUtils.isNotBlank(allocationState)) {
1971+
isUpdateHostAllocation = updateHostAllocationState(host, allocationState, isUpdateFromHostHealthCheck);
1972+
}
1973+
1974+
if (StringUtils.isNotBlank(name)) {
1975+
updateHostName(host, name);
1976+
}
1977+
1978+
if (guestOSCategoryId != null) {
1979+
updateHostGuestOSCategory(hostId, guestOSCategoryId);
1980+
}
1981+
1982+
if (hostTags != null) {
1983+
updateHostTags(host, hostId, hostTags, isTagARule);
1984+
}
1985+
1986+
updateMigratinIp(host, migrationIp);
1987+
1988+
if (url != null) {
1989+
_storageMgr.updateSecondaryStorage(hostId, url);
1990+
}
1991+
try {
1992+
_storageMgr.enableHost(hostId);
1993+
} catch (StorageUnavailableException | StorageConflictException e) {
1994+
logger.error(String.format("Failed to setup host %s when enabled", host));
1995+
}
1996+
1997+
final HostVO updatedHost = _hostDao.findById(hostId);
1998+
1999+
sendAlertAndAnnotationForAutoEnableDisableKVMHostFeature(host, allocationState,
2000+
isUpdateFromHostHealthCheck, isUpdateHostAllocation, annotation);
2001+
2002+
return updatedHost;
19522003
}
19532004

19542005
private Host updateHost(Long hostId, String name, Long guestOSCategoryId, String allocationState,

0 commit comments

Comments
 (0)