Skip to content

Commit 14937e1

Browse files
JoaoJandreJoão Jandre
andauthored
Fixed NPE on volume creation from snapshot (apache#6839)
Co-authored-by: João Jandre <joao@scclouds.com.br>
1 parent 13d22c2 commit 14937e1

9 files changed

Lines changed: 30 additions & 8 deletions

File tree

api/src/main/java/com/cloud/deploy/DataCenterDeployment.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import com.cloud.deploy.DeploymentPlanner.ExcludeList;
2020
import com.cloud.vm.ReservationContext;
21+
import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils;
2122

2223
import java.util.ArrayList;
2324
import java.util.List;
@@ -117,4 +118,10 @@ public boolean isMigrationPlan() {
117118
return migrationPlan;
118119
}
119120

121+
@Override
122+
public String toString() {
123+
return ReflectionToStringBuilderUtils.reflectOnlySelectedFields(this, "_dcId", "_podId", "_clusterId", "_poolId", "_hostid", "_physicalNetworkId",
124+
"migrationPlan");
125+
}
126+
120127
}

engine/components-api/src/main/java/com/cloud/vm/VirtualMachineProfileImpl.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,10 @@ public VirtualMachineProfileImpl(VirtualMachine.Type type) {
8686

8787
@Override
8888
public String toString() {
89-
return _vm.toString();
89+
if (_vm != null) {
90+
return _vm.toString();
91+
}
92+
return "";
9093
}
9194

9295
@Override

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
@@ -374,15 +374,15 @@ public StoragePool findStoragePool(DiskProfile dskCh, DataCenter dc, Pod pod, Lo
374374
if (storagePool.isPresent()) {
375375
storage = (StoragePool)this.dataStoreMgr.getDataStore(storagePool.get().getId(), DataStoreRole.Primary);
376376
s_logger.debug(String.format("VM [%s] has a preferred storage pool [%s]. Volume Orchestrator found this storage using Storage Pool Allocator [%s] and will"
377-
+ " use it.", vm, storage, allocator));
377+
+ " use it.", vm, storage, allocator.getClass().getSimpleName()));
378378
} else {
379379
storage = (StoragePool)dataStoreMgr.getDataStore(poolList.get(0).getId(), DataStoreRole.Primary);
380380
s_logger.debug(String.format("VM [%s] does not have a preferred storage pool or it cannot be used. Volume Orchestrator will use the available Storage Pool"
381-
+ " [%s], which was discovered using Storage Pool Allocator [%s].", vm, storage, allocator));
381+
+ " [%s], which was discovered using Storage Pool Allocator [%s].", vm, storage, allocator.getClass().getSimpleName()));
382382
}
383383
return storage;
384384
}
385-
s_logger.debug(String.format("Could not find any available Storage Pool using Storage Pool Allocator [%s].", allocator));
385+
s_logger.debug(String.format("Could not find any available Storage Pool using Storage Pool Allocator [%s].", allocator.getClass().getSimpleName()));
386386
}
387387
s_logger.info("Volume Orchestrator could not find any available Storage Pool.");
388388
return null;

engine/storage/src/main/java/org/apache/cloudstack/storage/allocator/AbstractStoragePoolAllocator.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.math.BigDecimal;
2020
import java.security.SecureRandom;
2121
import java.util.ArrayList;
22+
import java.util.Arrays;
2223
import java.util.Collections;
2324
import java.util.HashMap;
2425
import java.util.List;
@@ -389,4 +390,9 @@ protected void logStartOfSearch(DiskProfile dskCh, VirtualMachineProfile vmProfi
389390
+ "deployment plan [%s]. Returning up to [%d] and bypassStorageTypeCheck [%s].", this.getClass().getSimpleName(), dskCh, vmProfile, plan, returnUpTo, bypassStorageTypeCheck));
390391
}
391392

393+
protected void logEndOfSearch(List<StoragePool> storagePoolList) {
394+
s_logger.debug(String.format("%s is returning [%s] suitable storage pools [%s].", this.getClass().getSimpleName(), storagePoolList.size(),
395+
Arrays.toString(storagePoolList.toArray())));
396+
}
397+
392398
}

engine/storage/src/main/java/org/apache/cloudstack/storage/allocator/ClusterScopeStoragePoolAllocator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ protected List<StoragePool> select(DiskProfile dskCh, VirtualMachineProfile vmPr
107107
}
108108
}
109109

110-
s_logger.debug(String.format("ClusterScopeStoragePoolAllocator is returning [%s] suitable storage pools [%s].", suitablePools.size(), suitablePools));
110+
logEndOfSearch(suitablePools);
111111

112112
return suitablePools;
113113
}

engine/storage/src/main/java/org/apache/cloudstack/storage/allocator/LocalStoragePoolAllocator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ protected List<StoragePool> select(DiskProfile dskCh, VirtualMachineProfile vmPr
120120
avoid.addPool(pool.getId());
121121
}
122122
}
123-
s_logger.debug(String.format("LocalStoragePoolAllocator returning [%s] suitable storage pools [%s].", suitablePools.size(), suitablePools));
123+
logEndOfSearch(suitablePools);
124124

125125
return suitablePools;
126126
}

engine/storage/src/main/java/org/apache/cloudstack/storage/allocator/ZoneWideStoragePoolAllocator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ protected List<StoragePool> select(DiskProfile dskCh, VirtualMachineProfile vmPr
102102
}
103103
}
104104
}
105-
LOGGER.debug(String.format("ZoneWideStoragePoolAllocator is returning [%s] suitable storage pools [%s].", suitablePools.size(), suitablePools));
105+
logEndOfSearch(suitablePools);
106106

107107
return suitablePools;
108108
}

engine/storage/volume/src/main/java/org/apache/cloudstack/storage/datastore/PrimaryDataStoreImpl.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
4747
import org.apache.cloudstack.storage.to.PrimaryDataStoreTO;
4848
import org.apache.cloudstack.storage.volume.VolumeObject;
49+
import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils;
4950
import org.apache.log4j.Logger;
5051

5152
import com.cloud.agent.api.to.DataObjectType;
@@ -464,4 +465,9 @@ public StoragePoolType getParentPoolType() {
464465
}
465466
return null;
466467
}
468+
469+
@Override
470+
public String toString() {
471+
return ReflectionToStringBuilderUtils.reflectOnlySelectedFields(this, "name", "uuid");
472+
}
467473
}

plugins/storage-allocators/random/src/main/java/org/apache/cloudstack/storage/allocator/RandomStoragePoolAllocator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public List<StoragePool> select(DiskProfile dskCh, VirtualMachineProfile vmProfi
7373
}
7474
}
7575

76-
s_logger.debug(String.format("RandomStoragePoolAllocator is returning [%s] suitable storage pools [%s].", suitablePools.size(), suitablePools));
76+
logEndOfSearch(suitablePools);
7777

7878
return suitablePools;
7979
}

0 commit comments

Comments
 (0)