Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public class ApiConstants {
public static final String BACKUP_AVAILABLE = "backupavailable";
public static final String BACKUP_ID = "backupid";
public static final String BACKUP_LIMIT = "backuplimit";
public static final String BACKUP_PATHS = "backuppaths";
public static final String BACKUP_OFFERING_NAME = "backupofferingname";
public static final String BACKUP_OFFERING_ID = "backupofferingid";
public static final String BACKUP_OFFERING_DETAILS = "backupofferingdetails";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ public void execute() {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create Backup");
}

BackupResponse response = backupManager.createBackupResponse(backup, null);
boolean isCallerRootAdmin = _accountService.isRootAdmin(CallContext.current().getCallingAccountId());

BackupResponse response = backupManager.createBackupResponse(backup, null, isCallerRootAdmin);

response.setResponseName(getCommandName());
setResponseObject(response);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ public String getDescription() {
public void execute() {
try {
Backup backup = kvmBackupExportService.startBackup(this);
BackupResponse response = backupManager.createBackupResponse(backup, null);
boolean isCallerRootAdmin = _accountService.isRootAdmin(CallContext.current().getCallingAccountId());
BackupResponse response = backupManager.createBackupResponse(backup, null, isCallerRootAdmin);

response.setResponseName(getCommandName());
setResponseObject(response);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,13 @@ public Boolean getListVmDetails() {
/////////////////////////////////////////////////////

protected void setupResponseBackupList(final List<Backup> backups, final Integer count) {
boolean isCallerRootAdmin = _accountService.isRootAdmin(CallContext.current().getCallingAccountId());
final List<BackupResponse> responses = new ArrayList<>();
for (Backup backup : backups) {
if (backup == null) {
continue;
}
BackupResponse backupResponse = backupManager.createBackupResponse(backup, this.getListVmDetails());
BackupResponse backupResponse = backupManager.createBackupResponse(backup, this.getListVmDetails(), isCallerRootAdmin);
responses.add(backupResponse);
}
final ListResponse<BackupResponse> response = new ListResponse<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.BaseResponse;
import org.apache.cloudstack.api.EntityReference;
import org.apache.cloudstack.api.response.helper.BackupVolumeNameAndPath;
import org.apache.cloudstack.backup.Backup;

import com.cloud.serializer.Param;
Expand Down Expand Up @@ -99,6 +100,10 @@ public class BackupResponse extends BaseResponse {
@Param(description = "Backup offering name")
private String backupOfferingName;

@SerializedName(ApiConstants.BACKUP_PATHS)
@Param(description = "The backups paths in the secondary storage")
private Map<String, BackupVolumeNameAndPath> backupPaths;
Comment on lines +103 to +105
Comment on lines +103 to +105

@SerializedName(ApiConstants.ACCOUNT_ID)
@Param(description = "Account id")
private String accountId;
Expand Down Expand Up @@ -386,4 +391,12 @@ public void setHostId(String hostId) {
public String getHostId() {
return this.hostId;
}

public Map<String, BackupVolumeNameAndPath> getBackupPaths() {
return backupPaths;
}

public void setBackupPaths(Map<String, BackupVolumeNameAndPath> backupPaths) {
this.backupPaths = backupPaths;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

package org.apache.cloudstack.api.response.helper;

public class BackupVolumeNameAndPath {
private String volumeName;
private String backupPath;

public BackupVolumeNameAndPath(String volumeName, String backupPath) {
this.volumeName = volumeName;
this.backupPath = backupPath;
}
Comment on lines +20 to +27

public String getVolumeName() {
return volumeName;
}

public void setVolumeName(String volumeName) {
this.volumeName = volumeName;
}

public String getBackupPath() {
return backupPath;
}

public void setBackupPath(String backupPath) {
this.backupPath = backupPath;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ public interface BackupManager extends BackupService, Configurable, PluggableSer

String getBackupNameFromVM(VirtualMachine vm);

BackupResponse createBackupResponse(Backup backup, Boolean listVmDetails);
BackupResponse createBackupResponse(Backup backup, Boolean listVmDetails, boolean isCallerRootAdmin);

Capacity getBackupStorageUsedStats(Long zoneId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ public class InternalBackupJoinVO {
@Column(name = "volume_id")
private long volumeId;

@Column(name = "volume_uuid")
private String volumeUuid;

@Column(name = "volume_name")
private String volumeName;

@Column(name = "isolated")
private Boolean isolated;

Expand Down Expand Up @@ -175,6 +181,10 @@ public long getVolumeId() {
return volumeId;
}

public String getVolumeName() {
return volumeName;
}

public Boolean getIsolated() {
return BooleanUtils.isTrue(isolated);
}
Expand All @@ -183,6 +193,11 @@ public Backup.CompressionStatus getCompressionStatus() {
return compressionStatus;
}


public String getVolumeUuid() {
return volumeUuid;
}

@Override
public String toString() {
return ReflectionToStringBuilder.toString(this, ToStringStyle.JSON_STYLE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,14 @@ SELECT b.id,
MAX(CASE WHEN bd.name = 'current' THEN bd.value END) current,
COALESCE(MAX(CASE WHEN bd.name = 'isolated' THEN bd.value END), 'false') isolated,
nbpr.volume_id,
v.name as volume_name,
v.uuid as volume_uuid,
nbsr.path image_store_path
FROM backups b
LEFT JOIN backup_details bd ON b.id = bd.backup_id
LEFT JOIN backup_offering bo ON b.backup_offering_id = bo.id
LEFT JOIN internal_backup_store_ref nbsr ON b.id = nbsr.backup_id
LEFT JOIN internal_backup_pool_ref nbpr ON nbpr.volume_id = nbsr.volume_id
LEFT JOIN volumes v ON v.id = nbsr.volume_id
WHERE bo.provider='kboss'
GROUP BY b.id, nbsr.volume_id;
Comment on lines 37 to 50
Comment on lines 37 to 50
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,13 @@
import org.apache.cloudstack.api.command.user.backup.repository.UpdateBackupRepositoryCmd;
import org.apache.cloudstack.api.command.user.vm.CreateVMFromBackupCmd;
import org.apache.cloudstack.api.response.BackupResponse;
import org.apache.cloudstack.api.response.helper.BackupVolumeNameAndPath;
import org.apache.cloudstack.backup.dao.BackupDao;
import org.apache.cloudstack.backup.dao.BackupDetailsDao;
import org.apache.cloudstack.backup.dao.BackupOfferingDao;
import org.apache.cloudstack.backup.dao.BackupOfferingDetailsDao;
import org.apache.cloudstack.backup.dao.BackupScheduleDao;
import org.apache.cloudstack.backup.dao.InternalBackupJoinDao;
import org.apache.cloudstack.context.CallContext;
import org.apache.cloudstack.framework.config.ConfigKey;
import org.apache.cloudstack.framework.jobs.AsyncJobDispatcher;
Expand Down Expand Up @@ -255,6 +257,8 @@ public class BackupManagerImpl extends ManagerBase implements BackupManager {
private DomainHelper domainHelper;
@Inject
ReservationDao reservationDao;
@Inject
private InternalBackupJoinDao internalBackupJoinDao;

private AsyncJobDispatcher asyncJobDispatcher;
private Timer backupTimer;
Expand Down Expand Up @@ -2595,7 +2599,7 @@ Map<String, String> getDetailsFromBackupDetails(Long backupId) {
}

@Override
public BackupResponse createBackupResponse(Backup backup, Boolean listVmDetails) {
public BackupResponse createBackupResponse(Backup backup, Boolean listVmDetails, boolean isCallerRootAdmin) {
VMInstanceVO vm = vmInstanceDao.findByIdIncludingRemoved(backup.getVmId());
AccountVO account = accountDao.findByIdIncludingRemoved(backup.getAccountId());
DomainVO domain = domainDao.findByIdIncludingRemoved(backup.getDomainId());
Expand Down Expand Up @@ -2677,6 +2681,17 @@ public BackupResponse createBackupResponse(Backup backup, Boolean listVmDetails)
response.setToCheckpointId(backup.getToCheckpointId());
}

if (offering != null && KBOSS_BACKUP_PROVIDER.equals(offering.getProvider()) && isCallerRootAdmin) {
List<InternalBackupJoinVO> backupJoins = internalBackupJoinDao.listById(backup.getId());
Map<String, BackupVolumeNameAndPath> backupVolumePaths = new HashMap<>();

backupJoins.forEach(b -> {
backupVolumePaths.put(b.getVolumeUuid(), new BackupVolumeNameAndPath(b.getVolumeName(), b.getImageStorePath()));
});

response.setBackupPaths(backupVolumePaths);
}
Comment on lines +2684 to +2693
Comment on lines +2684 to +2693

response.setObjectName("backup");
return response;
}
Expand Down
Loading
Loading