Skip to content

Commit 67ca1bb

Browse files
Mike Tutkowskisyed
authored andcommitted
Changing locationType to PRIMARY and SECONDARY
1 parent 50d0b17 commit 67ca1bb

File tree

11 files changed

+58
-29
lines changed

11 files changed

+58
-29
lines changed

api/src/com/cloud/storage/Snapshot.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ enum Event {
6767
}
6868

6969
enum LocationType {
70-
Standard, Archive
70+
PRIMARY, SECONDARY
7171
}
7272

7373
public static final long MANUAL_POLICY_ID = 0L;

api/src/org/apache/cloudstack/api/command/user/snapshot/CreateSnapshotCmd.java

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import com.cloud.storage.Snapshot;
2525
import com.cloud.storage.Volume;
2626
import com.cloud.user.Account;
27+
import com.cloud.utils.exception.CloudRuntimeException;
2728
import org.apache.cloudstack.api.APICommand;
2829
import org.apache.cloudstack.api.ApiCommandJobType;
2930
import org.apache.cloudstack.api.ApiConstants;
@@ -72,8 +73,8 @@ public class CreateSnapshotCmd extends BaseAsyncCreateCmd {
7273
private Boolean quiescevm;
7374

7475
@Parameter(name = ApiConstants.LOCATION_TYPE, type = CommandType.SHORT, required = false, description = "Currently applicable only for managed storage. " +
75-
"Valid location types: 1 = 'standard'; 2 = 'archive'. Default = 1.")
76-
private Short locationType;
76+
"Valid location types: 'primary', 'secondary'. Default = 'primary'.")
77+
private String locationType;
7778

7879
@Parameter(name = ApiConstants.NAME, type = CommandType.STRING, description = "the name of the snapshot")
7980
private String snapshotName;
@@ -214,17 +215,20 @@ public void execute() {
214215
}
215216

216217
private Snapshot.LocationType getLocationType() {
217-
if (Snapshot.LocationType.values() == null || Snapshot.LocationType.values().length == 0) {
218+
219+
if (Snapshot.LocationType.values() == null || Snapshot.LocationType.values().length == 0 || locationType == null) {
218220
return null;
219221
}
220222

221-
Snapshot.LocationType locationTypeToReturn = Snapshot.LocationType.values()[0];
222-
223-
if (locationType != null && locationType >= 1 && locationType <= Snapshot.LocationType.values().length) {
224-
locationTypeToReturn = Snapshot.LocationType.values()[locationType-1];
223+
try {
224+
String lType = locationType.trim().toUpperCase();
225+
return Snapshot.LocationType.valueOf(lType);
226+
} catch (IllegalArgumentException e) {
227+
String errMesg = "Invalid locationType " + locationType + "Specified for volume " + getVolumeId()
228+
+ " Valid values are: primary,secondary ";
229+
s_logger.warn(errMesg);
230+
throw new CloudRuntimeException(errMesg);
225231
}
226-
227-
return locationTypeToReturn;
228232
}
229233

230234
@Override

api/test/org/apache/cloudstack/api/command/test/CreateSnapshotCmdTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
import static org.mockito.Matchers.anyBoolean;
3838
import static org.mockito.Matchers.anyLong;
3939
import static org.mockito.Matchers.anyString;
40-
import static org.mockito.Matchers.eq;
40+
import static org.mockito.Matchers.isNull;
4141

4242
public class CreateSnapshotCmdTest extends TestCase {
4343

@@ -83,7 +83,7 @@ public void testCreateSuccess() {
8383
try {
8484

8585
Mockito.when(volumeApiService.takeSnapshot(anyLong(), anyLong(), anyLong(),
86-
any(Account.class), anyBoolean(), eq(Snapshot.LocationType.Standard))).thenReturn(snapshot);
86+
any(Account.class), anyBoolean(), isNull(Snapshot.LocationType.class))).thenReturn(snapshot);
8787

8888
} catch (Exception e) {
8989
Assert.fail("Received exception when success expected " + e.getMessage());
@@ -113,7 +113,7 @@ public void testCreateFailure() {
113113

114114
try {
115115
Mockito.when(volumeApiService.takeSnapshot(anyLong(), anyLong(), anyLong(),
116-
any(Account.class), anyBoolean(), eq(Snapshot.LocationType.Standard))).thenReturn(null);
116+
any(Account.class), anyBoolean(), isNull(Snapshot.LocationType.class))).thenReturn(null);
117117
} catch (Exception e) {
118118
Assert.fail("Received exception when success expected " + e.getMessage());
119119
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ private Scope getZoneScope(Scope scope) {
349349
/**
350350
* This function is responsible for copying a volume from the managed store to a secondary store. This is used in two cases
351351
* 1) When creating a template from a snapshot
352-
* 2) When createSnapshot is called with location=Archive
352+
* 2) When createSnapshot is called with location=SECONDARY
353353
*
354354
* @param snapshotInfo Source snapshot
355355
* @param destData destination (can be template or snapshot)

engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/StorageSystemSnapshotStrategy.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public class StorageSystemSnapshotStrategy extends SnapshotStrategyBase {
9191
@Override
9292
public SnapshotInfo backupSnapshot(SnapshotInfo snapshotInfo) {
9393

94-
if (!snapshotInfo.getLocationType().equals(Snapshot.LocationType.Archive)) {
94+
if (!snapshotInfo.getLocationType().equals(Snapshot.LocationType.SECONDARY)) {
9595

9696
markAsBackedUp((SnapshotObject)snapshotInfo);
9797
return snapshotInfo;
@@ -102,7 +102,7 @@ public SnapshotInfo backupSnapshot(SnapshotInfo snapshotInfo) {
102102
// If archive flag is passed, we will copy this snapshot to secondary
103103
// storage and delete it from the primary storage.
104104

105-
Preconditions.checkState(Snapshot.LocationType.Archive.equals(snapshotInfo.getLocationType()));
105+
Preconditions.checkState(Snapshot.LocationType.SECONDARY.equals(snapshotInfo.getLocationType()));
106106

107107
HostVO host = getHost(snapshotInfo.getVolumeId());
108108
boolean canStorageSystemCreateVolumeFromSnapshot = canStorageSystemCreateVolumeFromSnapshot(snapshotInfo.getBaseVolume().getPoolId());
@@ -262,7 +262,7 @@ public SnapshotInfo takeSnapshot(SnapshotInfo snapshotInfo) {
262262
volumeInfo.stateTransit(Volume.Event.OperationSucceeded);
263263

264264
Preconditions.checkState(snapshotOnPrimary != null);
265-
if (Snapshot.LocationType.Archive.equals(snapshotInfo.getLocationType())) {
265+
if (Snapshot.LocationType.SECONDARY.equals(snapshotInfo.getLocationType())) {
266266
// cleanup the snapshot on primary
267267
try {
268268
snapshotSvr.deleteSnapshot(snapshotOnPrimary);
@@ -588,7 +588,7 @@ public StrategyPriority canHandle(Snapshot snapshot, SnapshotOperation op) {
588588
Snapshot.LocationType locationType = snapshot.getLocationType();
589589

590590
//If the snapshot exisits on Secondary Storage, we can't delete it.
591-
if (SnapshotOperation.DELETE.equals(op) && Snapshot.LocationType.Archive.equals(locationType)) {
591+
if (SnapshotOperation.DELETE.equals(op) && Snapshot.LocationType.SECONDARY.equals(locationType)) {
592592
return StrategyPriority.CANT_HANDLE;
593593
}
594594

server/src/com/cloud/storage/VolumeApiServiceImpl.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2054,6 +2054,11 @@ public Snapshot takeSnapshot(Long volumeId, Long policyId, Long snapshotId, Acco
20542054
throw new InvalidParameterValueException("VolumeId: " + volumeId + " is not in " + Volume.State.Ready + " state but " + volume.getState() + ". Cannot take snapshot.");
20552055
}
20562056

2057+
StoragePoolVO storagePoolVO = _storagePoolDao.findById(volume.getPoolId());
2058+
if (storagePoolVO.isManaged() && locationType == null) {
2059+
locationType = Snapshot.LocationType.PRIMARY;
2060+
}
2061+
20572062
VMInstanceVO vm = null;
20582063
if (volume.getInstanceId() != null)
20592064
vm = _vmInstanceDao.findById(volume.getInstanceId());
@@ -2174,8 +2179,12 @@ public Snapshot allocSnapshot(Long volumeId, Long policyId, String snapshotName,
21742179
}
21752180

21762181
StoragePoolVO storagePoolVO = _storagePoolDao.findById(volume.getPoolId());
2177-
if (!storagePoolVO.isManaged() && Snapshot.LocationType.Archive.equals(locationType)) {
2178-
throw new InvalidParameterValueException("VolumeId: " + volumeId + " Archive is supported only for managed storage");
2182+
if (!storagePoolVO.isManaged() && locationType != null) {
2183+
throw new InvalidParameterValueException("VolumeId: " + volumeId + " LocationType is supported only for managed storage");
2184+
}
2185+
2186+
if (storagePoolVO.isManaged() && locationType == null) {
2187+
locationType = Snapshot.LocationType.PRIMARY;
21792188
}
21802189

21812190
StoragePool storagePool = (StoragePool)volume.getDataStore();

server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1043,7 +1043,7 @@ private void updateSnapshotPayload(long storagePoolId, CreateSnapshotPayload pay
10431043
Snapshot.LocationType locationType = payload.getLocationType();
10441044

10451045
if (locationType == null) {
1046-
payload.setLocationType(Snapshot.LocationType.Standard);
1046+
payload.setLocationType(Snapshot.LocationType.PRIMARY);
10471047
}
10481048
}
10491049
else {

server/test/com/cloud/storage/VolumeApiServiceImplTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -422,13 +422,13 @@ public void testUpdateMissingRootDiskControllerWithValidChainInfo() {
422422

423423
@Test
424424
/**
425-
* Setting locationType=Archive for a non-managed storage should give an error
425+
* Setting locationType for a non-managed storage should give an error
426426
*/
427427
public void testAllocSnapshotNonManagedStorageArchive() {
428428
try {
429-
_svc.allocSnapshot(6L, 1L, "test", Snapshot.LocationType.Archive);
429+
_svc.allocSnapshot(6L, 1L, "test", Snapshot.LocationType.SECONDARY);
430430
} catch (InvalidParameterValueException e) {
431-
Assert.assertEquals(e.getMessage(), "VolumeId: 6 Archive is supported only for managed storage");
431+
Assert.assertEquals(e.getMessage(), "VolumeId: 6 LocationType is supported only for managed storage");
432432
return;
433433
} catch (ResourceAllocationException e) {
434434
Assert.fail("Unexpected excepiton " + e.getMessage());

server/test/com/cloud/storage/snapshot/SnapshotManagerTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ public void tearDown() {
181181
public void testAllocSnapshotF1() throws ResourceAllocationException {
182182
when(_vmDao.findById(anyLong())).thenReturn(vmMock);
183183
when(vmMock.getState()).thenReturn(State.Destroyed);
184-
_snapshotMgr.allocSnapshot(TEST_VOLUME_ID, Snapshot.MANUAL_POLICY_ID, null, Snapshot.LocationType.Standard);
184+
_snapshotMgr.allocSnapshot(TEST_VOLUME_ID, Snapshot.MANUAL_POLICY_ID, null, null);
185185
}
186186

187187
// active snapshots
@@ -196,7 +196,7 @@ public void testAllocSnapshotF2() throws ResourceAllocationException {
196196
List<SnapshotVO> mockList = mock(List.class);
197197
when(mockList.size()).thenReturn(1);
198198
when(_snapshotDao.listByInstanceId(TEST_VM_ID, Snapshot.State.Creating, Snapshot.State.CreatedOnPrimary, Snapshot.State.BackingUp)).thenReturn(mockList);
199-
_snapshotMgr.allocSnapshot(TEST_VOLUME_ID, Snapshot.MANUAL_POLICY_ID, null, Snapshot.LocationType.Standard);
199+
_snapshotMgr.allocSnapshot(TEST_VOLUME_ID, Snapshot.MANUAL_POLICY_ID, null, null);
200200
}
201201

202202
// active vm snapshots
@@ -214,7 +214,7 @@ public void testAllocSnapshotF3() throws ResourceAllocationException {
214214
List<VMSnapshotVO> mockList2 = mock(List.class);
215215
when(mockList2.size()).thenReturn(1);
216216
when(_vmSnapshotDao.listByInstanceId(TEST_VM_ID, VMSnapshot.State.Creating, VMSnapshot.State.Reverting, VMSnapshot.State.Expunging)).thenReturn(mockList2);
217-
_snapshotMgr.allocSnapshot(TEST_VOLUME_ID, Snapshot.MANUAL_POLICY_ID, null, Snapshot.LocationType.Standard);
217+
_snapshotMgr.allocSnapshot(TEST_VOLUME_ID, Snapshot.MANUAL_POLICY_ID, null, null);
218218
}
219219

220220
// successful test
@@ -233,7 +233,7 @@ public void testAllocSnapshotF4() throws ResourceAllocationException {
233233
when(mockList2.size()).thenReturn(0);
234234
when(_vmSnapshotDao.listByInstanceId(TEST_VM_ID, VMSnapshot.State.Creating, VMSnapshot.State.Reverting, VMSnapshot.State.Expunging)).thenReturn(mockList2);
235235
when(_snapshotDao.persist(any(SnapshotVO.class))).thenReturn(snapshotMock);
236-
_snapshotMgr.allocSnapshot(TEST_VOLUME_ID, Snapshot.MANUAL_POLICY_ID, null, Snapshot.LocationType.Standard);
236+
_snapshotMgr.allocSnapshot(TEST_VOLUME_ID, Snapshot.MANUAL_POLICY_ID, null, null);
237237
}
238238

239239
@Test

test/integration/plugins/solidfire/TestSnapshots.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1633,7 +1633,7 @@ def _create_and_test_archive_snapshot(self, volume_id_for_snapshot, sf_volume):
16331633
vol_snap = Snapshot.create(
16341634
self.apiClient,
16351635
volume_id=volume_id_for_snapshot,
1636-
locationtype=2
1636+
locationtype="secondary"
16371637
)
16381638

16391639
self._wait_for_snapshot_state(vol_snap.id, Snapshot.BACKED_UP)

0 commit comments

Comments
 (0)