mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-02 20:02:29 +01:00
ui: Add more info for creating volume snapshots (#3390)
Add more details in console logs and event details. Also show popup on successful completition of snapshots. Fixes: #3327
This commit is contained in:
parent
8f9f526f83
commit
1c963bac13
@ -16,15 +16,6 @@
|
||||
// under the License.
|
||||
package org.apache.cloudstack.api.command.user.snapshot;
|
||||
|
||||
import com.cloud.event.EventTypes;
|
||||
import com.cloud.exception.InvalidParameterValueException;
|
||||
import com.cloud.exception.PermissionDeniedException;
|
||||
import com.cloud.exception.ResourceAllocationException;
|
||||
import com.cloud.projects.Project;
|
||||
import com.cloud.storage.Snapshot;
|
||||
import com.cloud.storage.Volume;
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import org.apache.cloudstack.api.APICommand;
|
||||
import org.apache.cloudstack.api.ApiCommandJobType;
|
||||
import org.apache.cloudstack.api.ApiConstants;
|
||||
@ -39,6 +30,16 @@ import org.apache.cloudstack.api.response.SnapshotResponse;
|
||||
import org.apache.cloudstack.api.response.VolumeResponse;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.event.EventTypes;
|
||||
import com.cloud.exception.InvalidParameterValueException;
|
||||
import com.cloud.exception.PermissionDeniedException;
|
||||
import com.cloud.exception.ResourceAllocationException;
|
||||
import com.cloud.projects.Project;
|
||||
import com.cloud.storage.Snapshot;
|
||||
import com.cloud.storage.Volume;
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
|
||||
@APICommand(name = "createSnapshot", description = "Creates an instant snapshot of a volume.", responseObject = SnapshotResponse.class, entityType = {Snapshot.class},
|
||||
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
|
||||
public class CreateSnapshotCmd extends BaseAsyncCreateCmd {
|
||||
@ -171,7 +172,7 @@ public class CreateSnapshotCmd extends BaseAsyncCreateCmd {
|
||||
|
||||
@Override
|
||||
public String getEventDescription() {
|
||||
return "creating snapshot for volume: " + this._uuidMgr.getUuid(Volume.class, getVolumeId());
|
||||
return "creating snapshot for volume: " + getVolumeUuid();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -186,7 +187,7 @@ public class CreateSnapshotCmd extends BaseAsyncCreateCmd {
|
||||
setEntityId(snapshot.getId());
|
||||
setEntityUuid(snapshot.getUuid());
|
||||
} else {
|
||||
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create snapshot");
|
||||
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create snapshot for volume" + getVolumeUuid());
|
||||
}
|
||||
}
|
||||
|
||||
@ -202,10 +203,10 @@ public class CreateSnapshotCmd extends BaseAsyncCreateCmd {
|
||||
response.setResponseName(getCommandName());
|
||||
setResponseObject(response);
|
||||
} else {
|
||||
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create snapshot due to an internal error creating snapshot for volume " + getVolumeId());
|
||||
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create snapshot due to an internal error creating snapshot for volume " + getVolumeUuid());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create snapshot due to an internal error creating snapshot for volume " + getVolumeId());
|
||||
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create snapshot due to an internal error creating snapshot for volume " + getVolumeUuid());
|
||||
}
|
||||
}
|
||||
|
||||
@ -249,4 +250,8 @@ public class CreateSnapshotCmd extends BaseAsyncCreateCmd {
|
||||
return asyncBackup;
|
||||
}
|
||||
}
|
||||
|
||||
protected String getVolumeUuid() {
|
||||
return _uuidMgr.getUuid(Volume.class, getVolumeId());
|
||||
}
|
||||
}
|
||||
|
||||
@ -16,11 +16,12 @@
|
||||
// under the License.
|
||||
package org.apache.cloudstack.api.command.test;
|
||||
|
||||
import com.cloud.storage.Snapshot;
|
||||
import com.cloud.storage.VolumeApiService;
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.user.AccountService;
|
||||
import junit.framework.TestCase;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyBoolean;
|
||||
import static org.mockito.Matchers.anyLong;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Matchers.isNull;
|
||||
|
||||
import org.apache.cloudstack.api.ResponseGenerator;
|
||||
import org.apache.cloudstack.api.ServerApiException;
|
||||
import org.apache.cloudstack.api.command.user.snapshot.CreateSnapshotCmd;
|
||||
@ -32,11 +33,12 @@ import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyBoolean;
|
||||
import static org.mockito.Matchers.anyLong;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Matchers.isNull;
|
||||
import com.cloud.storage.Snapshot;
|
||||
import com.cloud.storage.VolumeApiService;
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.user.AccountService;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class CreateSnapshotCmdTest extends TestCase {
|
||||
|
||||
@ -66,6 +68,11 @@ public class CreateSnapshotCmdTest extends TestCase {
|
||||
public long getEntityOwnerId(){
|
||||
return 1L;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getVolumeUuid() {
|
||||
return "123";
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
@ -126,7 +133,7 @@ public class CreateSnapshotCmdTest extends TestCase {
|
||||
try {
|
||||
createSnapshotCmd.execute();
|
||||
} catch (ServerApiException exception) {
|
||||
Assert.assertEquals("Failed to create snapshot due to an internal error creating snapshot for volume 1", exception.getDescription());
|
||||
Assert.assertEquals("Failed to create snapshot due to an internal error creating snapshot for volume 123", exception.getDescription());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -297,7 +297,7 @@ public class SnapshotSchedulerImpl extends ManagerBase implements SnapshotSchedu
|
||||
tmpSnapshotScheduleVO = _snapshotScheduleDao.acquireInLockTable(snapshotScheId);
|
||||
final Long eventId =
|
||||
ActionEventUtils.onScheduledActionEvent(User.UID_SYSTEM, volume.getAccountId(), EventTypes.EVENT_SNAPSHOT_CREATE, "creating snapshot for volume Id:" +
|
||||
volumeId, true, 0);
|
||||
volume.getUuid(), true, 0);
|
||||
|
||||
final Map<String, String> params = new HashMap<String, String>();
|
||||
params.put(ApiConstants.VOLUME_ID, "" + volumeId);
|
||||
|
||||
@ -944,7 +944,14 @@
|
||||
var jid = json.createsnapshotresponse.jobid;
|
||||
args.response.success({
|
||||
_custom: {
|
||||
jobId: jid //take snapshot from a volume doesn't change any property in this volume. So, don't need to specify getUpdatedItem() to return updated volume. Besides, createSnapshot API doesn't return updated volume.
|
||||
jobId: jid, //take snapshot from a volume doesn't change any property in this volume. So, don't need to specify getUpdatedItem() to return updated volume. Besides, createSnapshot API doesn't return updated volume.
|
||||
onComplete: function(json, customData) {
|
||||
var volumeId = json.queryasyncjobresultresponse.jobresult.snapshot.volumeid;
|
||||
var snapshotId = json.queryasyncjobresultresponse.jobresult.snapshot.id;
|
||||
cloudStack.dialog.notice({
|
||||
message: "Created snapshot for volume " + volumeId + " with snapshot ID " + snapshotId
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user