Skip to content

Commit 50fe265

Browse files
committed
Merge remote-tracking branch 'apache/4.20' into 4.22
2 parents 2dd1e6d + d26122b commit 50fe265

File tree

5 files changed

+28
-32
lines changed

5 files changed

+28
-32
lines changed

engine/schema/src/main/java/com/cloud/vm/dao/UserVmDaoImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public class UserVmDaoImpl extends GenericDaoBase<UserVmVO, Long> implements Use
101101
ReservationDao reservationDao;
102102

103103
private static final String LIST_PODS_HAVING_VMS_FOR_ACCOUNT =
104-
"SELECT pod_id FROM cloud.vm_instance WHERE data_center_id = ? AND account_id = ? AND pod_id IS NOT NULL AND (state = 'Running' OR state = 'Stopped') "
104+
"SELECT pod_id FROM cloud.vm_instance WHERE data_center_id = ? AND account_id = ? AND pod_id IS NOT NULL AND state IN ('Starting', 'Running', 'Stopped') "
105105
+ "GROUP BY pod_id HAVING count(id) > 0 ORDER BY count(id) DESC";
106106

107107
private static final String VM_DETAILS = "select vm_instance.id, "

plugins/backup/veeam/src/main/java/org/apache/cloudstack/backup/veeam/VeeamClient.java

Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ public class VeeamClient {
105105
private static final String REPOSITORY_REFERENCE = "RepositoryReference";
106106
private static final String RESTORE_POINT_REFERENCE = "RestorePointReference";
107107
private static final String BACKUP_FILE_REFERENCE = "BackupFileReference";
108-
private static final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
108+
private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
109+
private static final ObjectMapper OBJECT_MAPPER = new XmlMapper();
109110

110111
private String veeamServerIp;
111112
private final Integer veeamServerVersion;
@@ -124,6 +125,8 @@ public VeeamClient(final String url, final Integer version, final String usernam
124125
this.taskPollInterval = taskPollInterval;
125126
this.taskPollMaxRetry = taskPollMaxRetry;
126127

128+
OBJECT_MAPPER.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
129+
127130
final RequestConfig config = RequestConfig.custom()
128131
.setConnectTimeout(timeout * 1000)
129132
.setConnectionRequestTimeout(timeout * 1000)
@@ -233,8 +236,7 @@ protected HttpResponse get(final String path) throws IOException {
233236
private HttpResponse post(final String path, final Object obj) throws IOException {
234237
String xml = null;
235238
if (obj != null) {
236-
XmlMapper xmlMapper = new XmlMapper();
237-
xml = xmlMapper.writer()
239+
xml = OBJECT_MAPPER.writer()
238240
.with(ToXmlGenerator.Feature.WRITE_XML_DECLARATION)
239241
.writeValueAsString(obj);
240242
// Remove invalid/empty xmlns
@@ -277,8 +279,7 @@ private String findDCHierarchy(final String vmwareDcName) {
277279
try {
278280
final HttpResponse response = get("/hierarchyRoots");
279281
checkResponseOK(response);
280-
final ObjectMapper objectMapper = new XmlMapper();
281-
final EntityReferences references = objectMapper.readValue(response.getEntity().getContent(), EntityReferences.class);
282+
final EntityReferences references = OBJECT_MAPPER.readValue(response.getEntity().getContent(), EntityReferences.class);
282283
for (final Ref ref : references.getRefs()) {
283284
if (ref.getName().equals(vmwareDcName) && ref.getType().equals(HIERARCHY_ROOT_REFERENCE)) {
284285
return ref.getUid();
@@ -297,8 +298,7 @@ private String lookupVM(final String hierarchyId, final String vmName) {
297298
try {
298299
final HttpResponse response = get(String.format("/lookup?host=%s&type=Vm&name=%s", hierarchyId, vmName));
299300
checkResponseOK(response);
300-
final ObjectMapper objectMapper = new XmlMapper();
301-
final HierarchyItems items = objectMapper.readValue(response.getEntity().getContent(), HierarchyItems.class);
301+
final HierarchyItems items = OBJECT_MAPPER.readValue(response.getEntity().getContent(), HierarchyItems.class);
302302
if (items == null || items.getItems() == null || items.getItems().isEmpty()) {
303303
throw new CloudRuntimeException("Could not find VM " + vmName + " in Veeam, please ask administrator to check Veeam B&R manager");
304304
}
@@ -316,14 +316,12 @@ private String lookupVM(final String hierarchyId, final String vmName) {
316316

317317
private Task parseTaskResponse(HttpResponse response) throws IOException {
318318
checkResponseOK(response);
319-
final ObjectMapper objectMapper = new XmlMapper();
320-
return objectMapper.readValue(response.getEntity().getContent(), Task.class);
319+
return OBJECT_MAPPER.readValue(response.getEntity().getContent(), Task.class);
321320
}
322321

323322
protected RestoreSession parseRestoreSessionResponse(HttpResponse response) throws IOException {
324323
checkResponseOK(response);
325-
final ObjectMapper objectMapper = new XmlMapper();
326-
return objectMapper.readValue(response.getEntity().getContent(), RestoreSession.class);
324+
return OBJECT_MAPPER.readValue(response.getEntity().getContent(), RestoreSession.class);
327325
}
328326

329327
private boolean checkTaskStatus(final HttpResponse response) throws IOException {
@@ -410,8 +408,7 @@ public Ref listBackupRepository(final String backupServerId, final String backup
410408
String repositoryName = getRepositoryNameFromJob(backupName);
411409
final HttpResponse response = get(String.format("/backupServers/%s/repositories", backupServerId));
412410
checkResponseOK(response);
413-
final ObjectMapper objectMapper = new XmlMapper();
414-
final EntityReferences references = objectMapper.readValue(response.getEntity().getContent(), EntityReferences.class);
411+
final EntityReferences references = OBJECT_MAPPER.readValue(response.getEntity().getContent(), EntityReferences.class);
415412
for (final Ref ref : references.getRefs()) {
416413
if (ref.getType().equals(REPOSITORY_REFERENCE) && ref.getName().equals(repositoryName)) {
417414
return ref;
@@ -447,8 +444,7 @@ public void listAllBackups() {
447444
try {
448445
final HttpResponse response = get("/backups");
449446
checkResponseOK(response);
450-
final ObjectMapper objectMapper = new XmlMapper();
451-
final EntityReferences entityReferences = objectMapper.readValue(response.getEntity().getContent(), EntityReferences.class);
447+
final EntityReferences entityReferences = OBJECT_MAPPER.readValue(response.getEntity().getContent(), EntityReferences.class);
452448
for (final Ref ref : entityReferences.getRefs()) {
453449
logger.debug("Veeam Backup found, name: " + ref.getName() + ", uid: " + ref.getUid() + ", type: " + ref.getType());
454450
}
@@ -463,8 +459,7 @@ public List<BackupOffering> listJobs() {
463459
try {
464460
final HttpResponse response = get("/jobs");
465461
checkResponseOK(response);
466-
final ObjectMapper objectMapper = new XmlMapper();
467-
final EntityReferences entityReferences = objectMapper.readValue(response.getEntity().getContent(), EntityReferences.class);
462+
final EntityReferences entityReferences = OBJECT_MAPPER.readValue(response.getEntity().getContent(), EntityReferences.class);
468463
final List<BackupOffering> policies = new ArrayList<>();
469464
if (entityReferences == null || entityReferences.getRefs() == null) {
470465
return policies;
@@ -486,9 +481,7 @@ public Job listJob(final String jobId) {
486481
final HttpResponse response = get(String.format("/jobs/%s?format=Entity",
487482
jobId.replace("urn:veeam:Job:", "")));
488483
checkResponseOK(response);
489-
final ObjectMapper objectMapper = new XmlMapper();
490-
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
491-
return objectMapper.readValue(response.getEntity().getContent(), Job.class);
484+
return OBJECT_MAPPER.readValue(response.getEntity().getContent(), Job.class);
492485
} catch (final IOException e) {
493486
logger.error("Failed to list Veeam jobs due to:", e);
494487
checkResponseTimeOut(e);
@@ -568,9 +561,7 @@ public boolean removeVMFromVeeamJob(final String jobId, final String vmwareInsta
568561
final String veeamVmRefId = lookupVM(hierarchyId, vmwareInstanceName);
569562
final HttpResponse response = get(String.format("/jobs/%s/includes", jobId));
570563
checkResponseOK(response);
571-
final ObjectMapper objectMapper = new XmlMapper();
572-
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
573-
final ObjectsInJob jobObjects = objectMapper.readValue(response.getEntity().getContent(), ObjectsInJob.class);
564+
final ObjectsInJob jobObjects = OBJECT_MAPPER.readValue(response.getEntity().getContent(), ObjectsInJob.class);
574565
if (jobObjects == null || jobObjects.getObjects() == null) {
575566
logger.warn("No objects found in the Veeam job " + jobId);
576567
return false;
@@ -710,8 +701,7 @@ public Map<String, Backup.Metric> getBackupMetricsViaVeeamAPI() {
710701
protected Map<String, Backup.Metric> processHttpResponseForBackupMetrics(final InputStream content) {
711702
Map<String, Backup.Metric> metrics = new HashMap<>();
712703
try {
713-
final ObjectMapper objectMapper = new XmlMapper();
714-
final BackupFiles backupFiles = objectMapper.readValue(content, BackupFiles.class);
704+
final BackupFiles backupFiles = OBJECT_MAPPER.readValue(content, BackupFiles.class);
715705
if (backupFiles == null || CollectionUtils.isEmpty(backupFiles.getBackupFiles())) {
716706
throw new CloudRuntimeException("Could not get backup metrics via Veeam B&R API");
717707
}
@@ -855,8 +845,7 @@ public List<Backup.RestorePoint> listVmRestorePointsViaVeeamAPI(String vmwareDcN
855845
public List<Backup.RestorePoint> processHttpResponseForVmRestorePoints(InputStream content, String vmwareDcName, String vmInternalName, Map<String, Backup.Metric> metricsMap) {
856846
List<Backup.RestorePoint> vmRestorePointList = new ArrayList<>();
857847
try {
858-
final ObjectMapper objectMapper = new XmlMapper();
859-
final VmRestorePoints vmRestorePoints = objectMapper.readValue(content, VmRestorePoints.class);
848+
final VmRestorePoints vmRestorePoints = OBJECT_MAPPER.readValue(content, VmRestorePoints.class);
860849
final String hierarchyId = findDCHierarchy(vmwareDcName);
861850
final String hierarchyUuid = StringUtils.substringAfterLast(hierarchyId, ":");
862851
if (vmRestorePoints == null) {
@@ -907,7 +896,7 @@ public List<Backup.RestorePoint> processHttpResponseForVmRestorePoints(InputStre
907896
}
908897

909898
private Date formatDate(String date) throws ParseException {
910-
return dateFormat.parse(StringUtils.substring(date, 0, 19));
899+
return DATE_FORMAT.parse(StringUtils.substring(date, 0, 19));
911900
}
912901

913902
public Pair<Boolean, String> restoreVMToDifferentLocation(String restorePointId, String restoreLocation, String hostIp, String dataStoreUuid) {

plugins/backup/veeam/src/test/java/org/apache/cloudstack/backup/veeam/VeeamClientTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,9 @@ public void testListVmRestorePointsViaVeeamAPI() {
483483
" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"\n" +
484484
" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" +
485485
" xmlns=\"http://www.veeam.com/ent/v1.0\">\n" +
486-
" <VmRestorePoint Href=\"https://10.0.3.142:9398/api/vmRestorePoints/f6d504cf-eafe-4cd2-8dfc-e9cfe2f1e977?format=Entity\" Type=\"VmRestorePoint\" Name=\"i-2-4-VM@2023-11-03 16:26:12.209913\" UID=\"urn:veeam:VmRestorePoint:f6d504cf-eafe-4cd2-8dfc-e9cfe2f1e977\" VmDisplayName=\"i-2-4-VM\">\n" +
486+
" <VmRestorePoint Href=\"https://10.0.3.142:9398/api/vmRestorePoints/f6d504cf-eafe-4cd2-8dfc-e9cfe2f1e977?format=Entity\"" +
487+
" Type=\"VmRestorePoint\" Name=\"i-2-4-VM@2023-11-03 16:26:12.209913\" UID=\"urn:veeam:VmRestorePoint:f6d504cf-eafe-4cd2-8dfc-e9cfe2f1e977\"" +
488+
" VmDisplayName=\"i-2-4-VM\" SqlInfo=\"SqlInfo\">\n" +
487489
" <Links>\n" +
488490
" <Link Href=\"https://10.0.3.142:9398/api/vmRestorePoints/f6d504cf-eafe-4cd2-8dfc-e9cfe2f1e977?action=restore\" Rel=\"Restore\" />\n" +
489491
" <Link Href=\"https://10.0.3.142:9398/api/backupServers/18cc2a81-1ff0-42cd-8389-62f2bbcc6b7f\" Name=\"10.0.3.142\" Type=\"BackupServerReference\" Rel=\"Up\" />\n" +

plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/guru/VMwareGuru.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,12 @@ private Long getImportingVMTemplate(List<VirtualDisk> virtualDisks, long zoneId,
695695
updateTemplateRef(templateId, poolId, templatePath, templateSize);
696696
return templateId;
697697
} else {
698-
return volumeVO.getTemplateId();
698+
Long templateId = volumeVO.getTemplateId();
699+
if (templateId == null && volumeVO.getInstanceId() != null) {
700+
VMInstanceVO vmInstanceVO = vmDao.findByIdIncludingRemoved(volumeVO.getInstanceId());
701+
return vmInstanceVO.getTemplateId();
702+
}
703+
return templateId;
699704
}
700705
}
701706
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public interface KubernetesClusterService extends PluggableService, Configurable
6161
"cloud.kubernetes.cluster.network.offering",
6262
"DefaultNetworkOfferingforKubernetesService",
6363
"Name of the network offering that will be used to create isolated network in which Kubernetes cluster VMs will be launched",
64-
false,
64+
true,
6565
KubernetesServiceEnabled.key());
6666
static final ConfigKey<Long> KubernetesClusterStartTimeout = new ConfigKey<Long>("Advanced", Long.class,
6767
"cloud.kubernetes.cluster.start.timeout",

0 commit comments

Comments
 (0)