Skip to content

Commit 34d2a3b

Browse files
committed
Merge branch '4.19' into 4.20
2 parents 7e295ec + 0a77eb7 commit 34d2a3b

File tree

17 files changed

+189
-715
lines changed

17 files changed

+189
-715
lines changed

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

Lines changed: 1 addition & 446 deletions
Large diffs are not rendered by default.

engine/orchestration/src/main/java/com/cloud/agent/manager/AgentManagerImpl.java

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
import org.apache.cloudstack.outofbandmanagement.dao.OutOfBandManagementDao;
5555
import org.apache.cloudstack.utils.identity.ManagementServerNode;
5656
import org.apache.commons.collections.MapUtils;
57+
import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils;
5758
import org.apache.commons.lang3.BooleanUtils;
5859

5960
import com.cloud.agent.AgentManager;
@@ -618,30 +619,25 @@ protected AgentAttache notifyMonitorsOfConnection(final AgentAttache attache, fi
618619
logger.debug("Sending Connect to listener: {}", monitor.second().getClass().getSimpleName());
619620
for (int i = 0; i < cmd.length; i++) {
620621
try {
622+
logger.debug("process connection to issue {} forRebalance == {}", ReflectionToStringBuilderUtils.reflectCollection(cmd[i]), forRebalance);
621623
monitor.second().processConnect(host, cmd[i], forRebalance);
622-
} catch (final Exception e) {
623-
if (e instanceof ConnectionException) {
624-
final ConnectionException ce = (ConnectionException)e;
625-
if (ce.isSetupError()) {
626-
logger.warn("Monitor {} says there is an error in the connect process for {} due to {}",
627-
monitor.second().getClass().getSimpleName(), host, e.getMessage());
628-
handleDisconnectWithoutInvestigation(attache, Event.AgentDisconnected, true, true);
629-
throw ce;
630-
} else {
631-
logger.info("Monitor {} says not to continue the connect process for {} due to {}",
632-
monitor.second().getClass().getSimpleName(), host, e.getMessage());
633-
handleDisconnectWithoutInvestigation(attache, Event.ShutdownRequested, true, true);
634-
return attache;
635-
}
636-
} else if (e instanceof HypervisorVersionChangedException) {
637-
handleDisconnectWithoutInvestigation(attache, Event.ShutdownRequested, true, true);
638-
throw new CloudRuntimeException(String.format("Unable to connect %s", attache), e);
639-
} else {
640-
logger.error("Monitor {} says there is an error in the connect process for {} due to {}",
641-
monitor.second().getClass().getSimpleName(), host, e.getMessage(), e);
624+
} catch (final ConnectionException ce) {
625+
if (ce.isSetupError()) {
626+
logger.warn("Monitor {} says there is an error in the connect process for {} due to {}", monitor.second().getClass().getSimpleName(), hostId, ce.getMessage());
642627
handleDisconnectWithoutInvestigation(attache, Event.AgentDisconnected, true, true);
643-
throw new CloudRuntimeException(String.format("Unable to connect %s", attache), e);
628+
throw ce;
629+
} else {
630+
logger.info("Monitor {} says not to continue the connect process for {} due to {}", monitor.second().getClass().getSimpleName(), hostId, ce.getMessage());
631+
handleDisconnectWithoutInvestigation(attache, Event.ShutdownRequested, true, true);
632+
return attache;
644633
}
634+
} catch (final HypervisorVersionChangedException hvce) {
635+
handleDisconnectWithoutInvestigation(attache, Event.ShutdownRequested, true, true);
636+
throw new CloudRuntimeException("Unable to connect " + attache.getId(), hvce);
637+
} catch (final Exception e) {
638+
logger.error("Monitor {} says there is an error in the connect process for {} due to {}", monitor.second().getClass().getSimpleName(), hostId, e.getMessage(), e);
639+
handleDisconnectWithoutInvestigation(attache, Event.AgentDisconnected, true, true);
640+
throw new CloudRuntimeException("Unable to connect " + attache.getId(), e);
645641
}
646642
}
647643
}

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
437437

438438
protected static final String LOCAL_STORAGE_PATH = "local.storage.path";
439439
protected static final String LOCAL_STORAGE_UUID = "local.storage.uuid";
440-
protected static final String DEFAULT_LOCAL_STORAGE_PATH = "/var/lib/libvirt/images/";
440+
public static final String DEFAULT_LOCAL_STORAGE_PATH = "/var/lib/libvirt/images";
441441

442442
protected List<String> localStoragePaths = new ArrayList<>();
443443
protected List<String> localStorageUUIDs = new ArrayList<>();
@@ -2661,7 +2661,7 @@ protected DevicesDef createDevicesDef(VirtualMachineTO vmTO, GuestDef guest, int
26612661
Map<String, String> details = vmTO.getDetails();
26622662

26632663
boolean isIothreadsEnabled = details != null && details.containsKey(VmDetailConstants.IOTHREADS);
2664-
devices.addDevice(createSCSIDef(vcpus, isIothreadsEnabled));
2664+
addSCSIControllers(devices, vcpus, vmTO.getDisks().length, isIothreadsEnabled);
26652665
}
26662666
return devices;
26672667
}
@@ -2699,8 +2699,19 @@ protected ChannelDef createChannelDef(VirtualMachineTO vmTO) {
26992699
* Creates Virtio SCSI controller. <br>
27002700
* The respective Virtio SCSI XML definition is generated only if the VM's Disk Bus is of ISCSI.
27012701
*/
2702-
protected SCSIDef createSCSIDef(int vcpus, boolean isIothreadsEnabled) {
2703-
return new SCSIDef((short)0, 0, 0, 9, 0, vcpus, isIothreadsEnabled);
2702+
protected SCSIDef createSCSIDef(short index, int vcpus, boolean isIothreadsEnabled) {
2703+
return new SCSIDef(index, 0, 0, 9 + index, 0, vcpus, isIothreadsEnabled);
2704+
}
2705+
2706+
2707+
private void addSCSIControllers(DevicesDef devices, int vcpus, int diskCount, boolean isIothreadsEnabled) {
2708+
int controllers = diskCount / 7;
2709+
if (diskCount % 7 != 0) {
2710+
controllers++;
2711+
}
2712+
for (int i = 0; i < controllers; i++) {
2713+
devices.addDevice(createSCSIDef((short)i, vcpus, isIothreadsEnabled));
2714+
}
27042715
}
27052716

27062717
protected ConsoleDef createConsoleDef() {

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtDeleteStoragePoolCommandWrapper.java

Lines changed: 55 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,28 +22,78 @@
2222
import com.cloud.agent.api.Answer;
2323
import com.cloud.agent.api.DeleteStoragePoolCommand;
2424
import com.cloud.agent.api.to.StorageFilerTO;
25+
import com.cloud.agent.dao.impl.PropertiesStorage;
26+
import com.cloud.agent.properties.AgentProperties;
27+
import com.cloud.agent.properties.AgentPropertiesFileHandler;
2528
import com.cloud.hypervisor.kvm.resource.LibvirtComputingResource;
2629
import com.cloud.hypervisor.kvm.storage.KVMStoragePoolManager;
2730
import com.cloud.resource.CommandWrapper;
2831
import com.cloud.resource.ResourceWrapper;
32+
import com.cloud.storage.Storage;
2933
import com.cloud.utils.exception.CloudRuntimeException;
3034

35+
import java.util.Arrays;
36+
import java.util.HashMap;
37+
import java.util.stream.Collectors;
38+
3139
@ResourceWrapper(handles = DeleteStoragePoolCommand.class)
3240
public final class LibvirtDeleteStoragePoolCommandWrapper extends CommandWrapper<DeleteStoragePoolCommand, Answer, LibvirtComputingResource> {
3341
@Override
3442
public Answer execute(final DeleteStoragePoolCommand command, final LibvirtComputingResource libvirtComputingResource) {
3543
try {
3644
// if getRemoveDatastore() is true, then we are dealing with managed storage and can skip the delete logic here
3745
if (!command.getRemoveDatastore()) {
38-
final StorageFilerTO pool = command.getPool();
39-
final KVMStoragePoolManager storagePoolMgr = libvirtComputingResource.getStoragePoolMgr();
40-
41-
storagePoolMgr.deleteStoragePool(pool.getType(), pool.getUuid());
46+
handleStoragePoolDeletion(command, libvirtComputingResource);
4247
}
43-
4448
return new Answer(command);
4549
} catch (final CloudRuntimeException e) {
4650
return new Answer(command, false, e.toString());
4751
}
4852
}
53+
54+
private void handleStoragePoolDeletion(final DeleteStoragePoolCommand command, final LibvirtComputingResource libvirtComputingResource) {
55+
final StorageFilerTO pool = command.getPool();
56+
final KVMStoragePoolManager storagePoolMgr = libvirtComputingResource.getStoragePoolMgr();
57+
storagePoolMgr.deleteStoragePool(pool.getType(), pool.getUuid());
58+
59+
if (isLocalStorageAndNotHavingDefaultPath(pool, libvirtComputingResource)) {
60+
updateLocalStorageProperties(pool);
61+
}
62+
}
63+
64+
private boolean isLocalStorageAndNotHavingDefaultPath(final StorageFilerTO pool, final LibvirtComputingResource libvirtComputingResource) {
65+
return Storage.StoragePoolType.Filesystem.equals(pool.getType())
66+
&& !libvirtComputingResource.DEFAULT_LOCAL_STORAGE_PATH.equals(pool.getPath());
67+
}
68+
69+
private void updateLocalStorageProperties(final StorageFilerTO pool) {
70+
String localStoragePath = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.LOCAL_STORAGE_PATH);
71+
String localStorageUuid = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.LOCAL_STORAGE_UUID);
72+
73+
String uuidToRemove = pool.getUuid();
74+
String pathToRemove = pool.getPath();
75+
76+
if (localStorageUuid != null && uuidToRemove != null) {
77+
localStorageUuid = Arrays.stream(localStorageUuid.split(","))
78+
.filter(uuid -> !uuid.equals(uuidToRemove))
79+
.collect(Collectors.joining(","));
80+
}
81+
82+
if (localStoragePath != null && pathToRemove != null) {
83+
localStoragePath = Arrays.stream(localStoragePath.split(","))
84+
.filter(path -> !path.equals(pathToRemove))
85+
.collect(Collectors.joining(","));
86+
}
87+
88+
PropertiesStorage agentProperties = new PropertiesStorage();
89+
agentProperties.configure("AgentProperties", new HashMap<String, Object>());
90+
91+
if (localStorageUuid != null) {
92+
agentProperties.persist(AgentProperties.LOCAL_STORAGE_UUID.getName(), localStorageUuid);
93+
}
94+
95+
if (localStoragePath != null) {
96+
agentProperties.persist(AgentProperties.LOCAL_STORAGE_PATH.getName(), localStoragePath);
97+
}
98+
}
4999
}

plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResourceTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,9 @@ public void testCreateDevicesWithSCSIDisk() {
461461
to.setDetails(new HashMap<>());
462462
to.setPlatformEmulator("Other PV Virtio-SCSI");
463463

464+
final DiskTO diskTO = Mockito.mock(DiskTO.class);
465+
to.setDisks(new DiskTO[]{diskTO});
466+
464467
GuestDef guest = new GuestDef();
465468
guest.setGuestType(GuestType.KVM);
466469

@@ -648,7 +651,7 @@ public void testCreateChannelDef() {
648651
public void testCreateSCSIDef() {
649652
VirtualMachineTO to = createDefaultVM(false);
650653

651-
SCSIDef scsiDef = libvirtComputingResourceSpy.createSCSIDef(to.getCpus(), false);
654+
SCSIDef scsiDef = libvirtComputingResourceSpy.createSCSIDef((short)0, to.getCpus(), false);
652655
Document domainDoc = parse(scsiDef.toString());
653656
verifyScsi(to, domainDoc, "");
654657
}

plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/KubernetesClusterManagerImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ public KubernetesClusterResponse createKubernetesClusterResponse(long kubernetes
568568
if (template != null) {
569569
response.setTemplateId(template.getUuid());
570570
}
571-
ServiceOfferingVO offering = serviceOfferingDao.findById(kubernetesCluster.getServiceOfferingId());
571+
ServiceOfferingVO offering = serviceOfferingDao.findByIdIncludingRemoved(kubernetesCluster.getServiceOfferingId());
572572
if (offering != null) {
573573
response.setServiceOfferingId(offering.getUuid());
574574
response.setServiceOfferingName(offering.getName());

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

Lines changed: 7 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,7 @@ private boolean containsHostHATag(final String tags) {
113113
return result;
114114
}
115115

116-
@Override
117-
public HostResponse newHostResponse(HostJoinVO host, EnumSet<HostDetails> details) {
118-
HostResponse hostResponse = new HostResponse();
116+
private void setNewHostResponseBase(HostJoinVO host, EnumSet<HostDetails> details, HostResponse hostResponse) {
119117
hostResponse.setId(host.getUuid());
120118
hostResponse.setCapabilities(host.getCapabilities());
121119
hostResponse.setClusterId(host.getClusterUuid());
@@ -187,7 +185,6 @@ public HostResponse newHostResponse(HostJoinVO host, EnumSet<HostDetails> detail
187185
DecimalFormat decimalFormat = new DecimalFormat("#.##");
188186
if (host.getType() == Host.Type.Routing) {
189187
float cpuOverprovisioningFactor = ApiDBUtils.getCpuOverprovisioningFactor(host.getClusterId());
190-
hostResponse.setCpuNumber((int)(host.getCpus() * cpuOverprovisioningFactor));
191188
if (details.contains(HostDetails.all) || details.contains(HostDetails.capacity)) {
192189
// set allocated capacities
193190
Long mem = host.getMemReservedCapacity() + host.getMemUsedCapacity();
@@ -298,124 +295,19 @@ public HostResponse newHostResponse(HostJoinVO host, EnumSet<HostDetails> detail
298295
hostResponse.setUsername(host.getUsername());
299296

300297
hostResponse.setObjectName("host");
298+
}
301299

300+
@Override
301+
public HostResponse newHostResponse(HostJoinVO host, EnumSet<HostDetails> details) {
302+
HostResponse hostResponse = new HostResponse();
303+
setNewHostResponseBase(host, details, hostResponse);
302304
return hostResponse;
303305
}
304306

305307
@Override
306308
public HostForMigrationResponse newHostForMigrationResponse(HostJoinVO host, EnumSet<HostDetails> details) {
307309
HostForMigrationResponse hostResponse = new HostForMigrationResponse();
308-
hostResponse.setId(host.getUuid());
309-
hostResponse.setCapabilities(host.getCapabilities());
310-
hostResponse.setClusterId(host.getClusterUuid());
311-
hostResponse.setCpuNumber(host.getCpus());
312-
hostResponse.setZoneId(host.getZoneUuid());
313-
hostResponse.setDisconnectedOn(host.getDisconnectedOn());
314-
hostResponse.setHypervisor(host.getHypervisorType().getHypervisorDisplayName());
315-
hostResponse.setHostType(host.getType());
316-
hostResponse.setLastPinged(new Date(host.getLastPinged()));
317-
hostResponse.setManagementServerId(host.getManagementServerId());
318-
hostResponse.setName(host.getName());
319-
hostResponse.setPodId(host.getPodUuid());
320-
hostResponse.setRemoved(host.getRemoved());
321-
hostResponse.setCpuSpeed(host.getSpeed());
322-
hostResponse.setState(host.getStatus());
323-
hostResponse.setIpAddress(host.getPrivateIpAddress());
324-
hostResponse.setVersion(host.getVersion());
325-
hostResponse.setCreated(host.getCreated());
326-
327-
if (details.contains(HostDetails.all) || details.contains(HostDetails.capacity) || details.contains(HostDetails.stats) || details.contains(HostDetails.events)) {
328-
329-
hostResponse.setOsCategoryId(host.getOsCategoryUuid());
330-
hostResponse.setOsCategoryName(host.getOsCategoryName());
331-
hostResponse.setZoneName(host.getZoneName());
332-
hostResponse.setPodName(host.getPodName());
333-
if (host.getClusterId() > 0) {
334-
hostResponse.setClusterName(host.getClusterName());
335-
hostResponse.setClusterType(host.getClusterType().toString());
336-
}
337-
}
338-
339-
DecimalFormat decimalFormat = new DecimalFormat("#.##");
340-
if (host.getType() == Host.Type.Routing) {
341-
if (details.contains(HostDetails.all) || details.contains(HostDetails.capacity)) {
342-
// set allocated capacities
343-
Long mem = host.getMemReservedCapacity() + host.getMemUsedCapacity();
344-
Long cpu = host.getCpuReservedCapacity() + host.getCpuUsedCapacity();
345-
346-
hostResponse.setMemoryTotal(host.getTotalMemory());
347-
Float memWithOverprovisioning = host.getTotalMemory() * ApiDBUtils.getMemOverprovisioningFactor(host.getClusterId());
348-
hostResponse.setMemWithOverprovisioning(decimalFormat.format(memWithOverprovisioning));
349-
String memoryAllocatedPercentage = decimalFormat.format((float) mem / memWithOverprovisioning * 100.0f) +"%";
350-
hostResponse.setMemoryAllocated(memoryAllocatedPercentage);
351-
hostResponse.setMemoryAllocatedPercentage(memoryAllocatedPercentage);
352-
hostResponse.setMemoryAllocatedBytes(mem);
353-
354-
String hostTags = host.getTag();
355-
hostResponse.setHostTags(hostTags);
356-
hostResponse.setHaHost(containsHostHATag(hostTags));
357-
hostResponse.setImplicitHostTags(host.getImplicitTag());
358-
359-
hostResponse.setHypervisorVersion(host.getHypervisorVersion());
360-
361-
hostResponse.setCpuAllocatedValue(cpu);
362-
String cpuAlloc = decimalFormat.format(((float)cpu / (float)(host.getCpus() * host.getSpeed())) * 100f) + "%";
363-
hostResponse.setCpuAllocated(cpuAlloc);
364-
hostResponse.setCpuAllocatedPercentage(cpuAlloc);
365-
float cpuWithOverprovisioning = host.getCpus() * host.getSpeed() * ApiDBUtils.getCpuOverprovisioningFactor(host.getClusterId());
366-
hostResponse.setCpuAllocatedWithOverprovisioning(calculateResourceAllocatedPercentage(cpu, cpuWithOverprovisioning));
367-
hostResponse.setCpuWithOverprovisioning(decimalFormat.format(cpuWithOverprovisioning));
368-
}
369-
370-
if (details.contains(HostDetails.all) || details.contains(HostDetails.stats)) {
371-
// set CPU/RAM/Network stats
372-
String cpuUsed = null;
373-
HostStats hostStats = ApiDBUtils.getHostStatistics(host.getId());
374-
if (hostStats != null) {
375-
float cpuUtil = (float)hostStats.getCpuUtilization();
376-
cpuUsed = decimalFormat.format(cpuUtil) + "%";
377-
hostResponse.setCpuUsed(cpuUsed);
378-
hostResponse.setMemoryUsed((new Double(hostStats.getUsedMemory())).longValue());
379-
hostResponse.setNetworkKbsRead((new Double(hostStats.getNetworkReadKBs())).longValue());
380-
hostResponse.setNetworkKbsWrite((new Double(hostStats.getNetworkWriteKBs())).longValue());
381-
382-
}
383-
}
384-
385-
} else if (host.getType() == Host.Type.SecondaryStorage) {
386-
StorageStats secStorageStats = ApiDBUtils.getSecondaryStorageStatistics(host.getId());
387-
if (secStorageStats != null) {
388-
hostResponse.setDiskSizeTotal(secStorageStats.getCapacityBytes());
389-
hostResponse.setDiskSizeAllocated(secStorageStats.getByteUsed());
390-
}
391-
}
392-
393-
hostResponse.setLocalStorageActive(ApiDBUtils.isLocalStorageActiveOnHost(host.getId()));
394-
395-
if (details.contains(HostDetails.all) || details.contains(HostDetails.events)) {
396-
Set<com.cloud.host.Status.Event> possibleEvents = host.getStatus().getPossibleEvents();
397-
if ((possibleEvents != null) && !possibleEvents.isEmpty()) {
398-
String events = "";
399-
Iterator<com.cloud.host.Status.Event> iter = possibleEvents.iterator();
400-
while (iter.hasNext()) {
401-
com.cloud.host.Status.Event event = iter.next();
402-
events += event.toString();
403-
if (iter.hasNext()) {
404-
events += "; ";
405-
}
406-
}
407-
hostResponse.setEvents(events);
408-
}
409-
}
410-
411-
hostResponse.setResourceState(host.getResourceState().toString());
412-
413-
// set async job
414-
hostResponse.setJobId(host.getJobUuid());
415-
hostResponse.setJobStatus(host.getJobStatus());
416-
417-
hostResponse.setObjectName("host");
418-
310+
setNewHostResponseBase(host, details, hostResponse);
419311
return hostResponse;
420312
}
421313

0 commit comments

Comments
 (0)