Skip to content

Commit 602c944

Browse files
Rene GloverGLOVER RENEsureshanaparti
authored andcommitted
Primera pure patches & various small fixes (apache#10132)
Co-authored-by: GLOVER RENE <rg9975@cs419-mgmtserver.rg9975nprd.app.ecp.att.com> Co-authored-by: Suresh Kumar Anaparti <sureshkumar.anaparti@gmail.com>
1 parent 6647f7f commit 602c944

File tree

17 files changed

+151
-38
lines changed

17 files changed

+151
-38
lines changed

api/src/main/java/com/cloud/exception/StorageAccessException.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
public class StorageAccessException extends RuntimeException {
2727
private static final long serialVersionUID = SerialVersionUID.StorageAccessException;
2828

29-
public StorageAccessException(String message) {
30-
super(message);
29+
public StorageAccessException(String message, Exception causer) {
30+
super(message, causer);
3131
}
3232
}

engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/VolumeOrchestrator.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1991,7 +1991,7 @@ private Pair<VolumeVO, DataStore> recreateVolume(VolumeVO vol, VirtualMachinePro
19911991
try {
19921992
volService.grantAccess(volFactory.getVolume(newVol.getId()), host, destPool);
19931993
} catch (Exception e) {
1994-
throw new StorageAccessException(String.format("Unable to grant access to the volume [%s] on host [%s].", newVolToString, host));
1994+
throw new StorageAccessException(String.format("Unable to grant access to the volume [%s] on host [%s].", newVolToString, host), e);
19951995
}
19961996
}
19971997

@@ -2031,7 +2031,7 @@ protected void grantVolumeAccessToHostIfNeeded(PrimaryDataStore volumeStore, lon
20312031
try {
20322032
volService.grantAccess(volFactory.getVolume(volumeId), host, volumeStore);
20332033
} catch (Exception e) {
2034-
throw new StorageAccessException(String.format("Unable to grant access to volume [%s] on host [%s].", volToString, host));
2034+
throw new StorageAccessException(String.format("Unable to grant access to volume [%s] on host [%s].", volToString, host), e);
20352035
}
20362036
}
20372037

@@ -2112,7 +2112,7 @@ public void prepare(VirtualMachineProfile vm, DeployDestination dest) throws Sto
21122112
try {
21132113
volService.grantAccess(volFactory.getVolume(vol.getId()), host, store);
21142114
} catch (Exception e) {
2115-
throw new StorageAccessException(String.format("Unable to grant access to volume [%s] on host [%s].", volToString, host));
2115+
throw new StorageAccessException(String.format("Unable to grant access to volume [%s] on host [%s].", volToString, host), e);
21162116
}
21172117
} else {
21182118
grantVolumeAccessToHostIfNeeded(store, vol.getId(), host, volToString);

engine/storage/datamotion/src/main/java/org/apache/cloudstack/storage/motion/StorageSystemDataMotionStrategy.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import org.apache.cloudstack.engine.subsystem.api.storage.DataObject;
4646
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
4747
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreCapabilities;
48+
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreDriver;
4849
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
4950
import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint;
5051
import org.apache.cloudstack.engine.subsystem.api.storage.EndPointSelector;
@@ -1530,6 +1531,16 @@ private void handleCreateVolumeFromTemplateBothOnStorageSystem(TemplateInfo temp
15301531
verifyFormat(templateInfo.getFormat());
15311532
}
15321533

1534+
// this blurb handles the case where the storage system can clone a volume from a template
1535+
String canCloneVolumeFromTemplate = templateInfo.getDataStore().getDriver().getCapabilities().get("CAN_CLONE_VOLUME_FROM_TEMPLATE");
1536+
if (canCloneVolumeFromTemplate != null && canCloneVolumeFromTemplate.toLowerCase().equals("true")) {
1537+
DataStoreDriver driver = templateInfo.getDataStore().getDriver();
1538+
driver.createAsync(volumeInfo.getDataStore(), volumeInfo, null);
1539+
volumeInfo = _volumeDataFactory.getVolume(volumeInfo.getId(), volumeInfo.getDataStore());
1540+
driver.copyAsync(templateInfo, volumeInfo, null);
1541+
return;
1542+
}
1543+
15331544
HostVO hostVO = null;
15341545

15351546
final boolean computeClusterSupportsVolumeClone;
@@ -1637,7 +1648,7 @@ else if (volumeInfo.getFormat() == ImageFormat.OVA) {
16371648
errMsg = "Create volume from template failed: " + ex.getMessage();
16381649
}
16391650

1640-
throw new CloudRuntimeException(errMsg);
1651+
throw new CloudRuntimeException(errMsg, ex);
16411652
}
16421653
finally {
16431654
if (copyCmdAnswer == null) {
@@ -2629,7 +2640,7 @@ private void handleCreateTemplateFromManagedVolume(VolumeInfo volumeInfo, Templa
26292640
catch (Exception ex) {
26302641
errMsg = ex.getMessage();
26312642

2632-
throw new CloudRuntimeException(errMsg);
2643+
throw new CloudRuntimeException(errMsg, ex);
26332644
}
26342645
finally {
26352646
if (copyCmdAnswer == null) {

framework/spring/lifecycle/src/main/java/org/apache/cloudstack/spring/lifecycle/CloudStackExtendedLifeCycle.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ public void with(ComponentLifecycle lifecycle) {
129129
throw new CloudRuntimeException(e);
130130
} catch (Exception e) {
131131
logger.error("Error on configuring bean {} - {}", lifecycle.getName(), e.getMessage(), e);
132+
throw new CloudRuntimeException(e);
132133
}
133134
}
134135
});

framework/spring/lifecycle/src/main/java/org/apache/cloudstack/spring/lifecycle/registry/RegistryLifecycle.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,15 @@ public void start() {
109109

110110
while (iter.hasNext()) {
111111
Object next = iter.next();
112-
if (registry.register(next)) {
113-
logger.debug("Registered " + next);
114-
} else {
115-
iter.remove();
112+
try {
113+
if (registry.register(next)) {
114+
logger.debug("Registered " + next);
115+
} else {
116+
logger.warn("Bean registration failed for " + next.toString());
117+
iter.remove();
118+
}
119+
} catch (Throwable e) {
120+
logger.warn("Bean registration attempt resulted in an exception for " + next.toString(), e);
116121
}
117122
}
118123
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ public String toString() {
276276
guestDef.append("<boot dev='" + bo + "'/>\n");
277277
}
278278
}
279-
if (!(_arch != null && _arch.equals("s390x"))) {
279+
if (_arch == null || ! (_arch.equals("aarch64") || _arch.equals("s390x"))) { // simplification of (as ref.) (!(_arch != null && _arch.equals("s390x")) || (_arch == null || !_arch.equals("aarch64")))
280280
guestDef.append("<smbios mode='sysinfo'/>\n");
281281
}
282282
guestDef.append("</os>\n");

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,11 @@ private UnmanagedInstanceTO getUnmanagedInstance(LibvirtComputingResource libvir
122122
instance.setName(domain.getName());
123123

124124
instance.setCpuCores((int) LibvirtComputingResource.countDomainRunningVcpus(domain));
125-
if (parser.getCpuTuneDef() !=null) {
125+
126+
if (parser.getCpuTuneDef() != null && instance.getCpuCores() != null) {
126127
instance.setCpuSpeed(parser.getCpuTuneDef().getShares()/instance.getCpuCores());
127-
} else {
128+
}
129+
else {
128130
instance.setCpuSpeed(200);
129131
}
130132

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/KVMStorageProcessor.java

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -282,8 +282,13 @@ public Answer copyTemplateToPrimaryStorage(final CopyCommand cmd) {
282282

283283
String path = derivePath(primaryStore, destData, details);
284284

285-
if (!storagePoolMgr.connectPhysicalDisk(primaryStore.getPoolType(), primaryStore.getUuid(), path, details)) {
285+
if (path == null) {
286+
path = destTempl.getUuid();
287+
}
288+
289+
if (path != null && !storagePoolMgr.connectPhysicalDisk(primaryStore.getPoolType(), primaryStore.getUuid(), path, details)) {
286290
logger.warn("Failed to connect physical disk at path: {}, in storage pool [id: {}, name: {}]", path, primaryStore.getUuid(), primaryStore.getName());
291+
return new PrimaryStorageDownloadAnswer("Failed to spool template disk at path: " + path + ", in storage pool id: " + primaryStore.getUuid());
287292
}
288293

289294
primaryVol = storagePoolMgr.copyPhysicalDisk(tmplVol, path != null ? path : destTempl.getUuid(), primaryPool, cmd.getWaitInMillSeconds());
@@ -347,6 +352,7 @@ private String derivePath(PrimaryDataStoreTO primaryStore, DataTO destData, Map<
347352
} else {
348353
path = details != null ? details.get("managedStoreTarget") : null;
349354
}
355+
350356
return path;
351357
}
352358

@@ -782,15 +788,19 @@ else if (srcData instanceof SnapshotObjectTO) {
782788

783789
KVMStoragePool secondaryStorage = null;
784790

791+
String path = null;
785792
try {
786793
// look for options indicating an overridden path or IQN. Used when snapshots have to be
787794
// temporarily copied on the manaaged storage device before the actual copy to target object
788795
Map<String, String> details = cmd.getOptions();
789-
String path = details != null ? details.get(DiskTO.PATH) : null;
796+
path = details != null ? details.get(DiskTO.PATH) : null;
790797
if (path == null) {
791798
path = details != null ? details.get(DiskTO.IQN) : null;
792799
if (path == null) {
793-
new CloudRuntimeException("The 'path' or 'iqn' field must be specified.");
800+
path = srcData.getPath();
801+
if (path == null) {
802+
new CloudRuntimeException("The 'path' or 'iqn' field must be specified.");
803+
}
794804
}
795805
}
796806

@@ -853,8 +863,6 @@ else if (srcData instanceof SnapshotObjectTO) {
853863
loc.addFormat(info);
854864
loc.save();
855865

856-
storagePoolMgr.disconnectPhysicalDisk(primaryStore.getPoolType(), primaryStore.getUuid(), path);
857-
858866
TemplateObjectTO newTemplate = new TemplateObjectTO();
859867

860868
newTemplate.setPath(templateFolder + File.separator + templateName + ".qcow2");
@@ -874,6 +882,10 @@ else if (srcData instanceof SnapshotObjectTO) {
874882

875883
return new CopyCmdAnswer(ex.toString());
876884
} finally {
885+
if (path != null) {
886+
storagePoolMgr.disconnectPhysicalDisk(primaryStore.getPoolType(), primaryStore.getUuid(), path);
887+
}
888+
877889
if (secondaryStorage != null) {
878890
secondaryStorage.delete();
879891
}
@@ -1068,7 +1080,9 @@ public Answer backupSnapshot(final CopyCommand cmd) {
10681080
command.add(NAME_OPTION, snapshotName);
10691081
command.add("-p", snapshotDestPath);
10701082

1071-
descName = UUID.randomUUID().toString();
1083+
if (isCreatedFromVmSnapshot) {
1084+
descName = UUID.randomUUID().toString();
1085+
}
10721086

10731087
command.add("-t", descName);
10741088
final String result = command.execute();

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/MultipathSCSIAdapterBase.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,13 @@ private KVMPhysicalDisk getPhysicalDisk(AddressInfo address, KVMStoragePool pool
162162
KVMPhysicalDisk disk = new KVMPhysicalDisk(address.getPath(), address.toString(), pool);
163163
disk.setFormat(QemuImg.PhysicalDiskFormat.RAW);
164164

165+
// validate we have a connection, if not we need to connect first.
166+
if (!isConnected(address.getPath())) {
167+
if (!connectPhysicalDisk(address, pool, null)) {
168+
throw new CloudRuntimeException("Unable to connect to volume " + address.getPath());
169+
}
170+
}
171+
165172
long diskSize = getPhysicalDiskSize(address.getPath());
166173
disk.setSize(diskSize);
167174
disk.setVirtualSize(diskSize);
@@ -199,6 +206,10 @@ public boolean connectPhysicalDisk(String volumePath, KVMStoragePool pool, Map<S
199206
// we expect WWN values in the volumePath so need to convert it to an actual physical path
200207
AddressInfo address = this.parseAndValidatePath(volumePath);
201208

209+
return connectPhysicalDisk(address, pool, details);
210+
}
211+
212+
private boolean connectPhysicalDisk(AddressInfo address, KVMStoragePool pool, Map<String, String> details) {
202213
// validate we have a connection id - we can't proceed without that
203214
if (address.getConnectionId() == null) {
204215
LOGGER.error("Unable to connect volume with address [" + address.getPath() + "] of the storage pool: " + pool.getUuid() + " - connection id is not set in provided path");
@@ -510,6 +521,18 @@ boolean waitForDiskToBecomeAvailable(AddressInfo address, KVMStoragePool pool, l
510521
return false;
511522
}
512523

524+
boolean isConnected(String path) {
525+
// run a command to test if this is a binary device at this path
526+
Script blockTest = new Script("/bin/test", LOGGER);
527+
blockTest.add("-b", path);
528+
blockTest.execute();
529+
int rc = blockTest.getExitValue();
530+
if (rc == 0) {
531+
return true;
532+
}
533+
return false;
534+
}
535+
513536
long getPhysicalDiskSize(String diskPath) {
514537
if (StringUtils.isEmpty(diskPath)) {
515538
return 0;

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,8 +360,13 @@ protected IpAddress getVpcTierKubernetesPublicIp(Network network) {
360360
return null;
361361
}
362362
IpAddress address = ipAddressDao.findByUuid(detailsVO.getValue());
363-
if (address == null || !Objects.equals(network.getVpcId(), address.getVpcId())) {
364-
logger.warn(String.format("Public IP with ID: %s linked to the Kubernetes cluster: %s is not usable", detailsVO.getValue(), kubernetesCluster.getName()));
363+
if (address == null || network.getVpcId() != address.getVpcId()) {
364+
logger.warn("Public IP with ID: {} linked to the Kubernetes cluster: {} is not usable", detailsVO.getValue(), kubernetesCluster.getName());
365+
if (address == null) {
366+
logger.warn("Public IP with ID: {} was not found by uuid", detailsVO.getValue());
367+
} else {
368+
logger.warn("Public IP with ID: {} was associated with vpc {} instead of {}", detailsVO.getValue(), address.getVpcId(), network.getVpcId());
369+
}
365370
return null;
366371
}
367372
return address;

0 commit comments

Comments
 (0)