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
2 changes: 1 addition & 1 deletion server/src/main/java/com/cloud/api/ApiResponseHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,7 @@ public static DataStoreRole getDataStoreRole(Snapshot snapshot, SnapshotDataStor

if (mapCapabilities != null) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mapCapabilities can be empty, in this case get() and parseBoolean() calls do not add much value. While the performance impact is negligible, using a utility method such as isNotEmpty() would avoid executing the block when the map is either null or empty.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather leave this line as it is. The if (mapCapabilities != null) block is unchanged from before the merge; this PR only restores parseBoolean. The result is already the same either way: with an empty map, get() returns null and parseBoolean(null) is false, so it falls through to Image. I added a test for the null and empty map cases (see the test thread).

String value = mapCapabilities.get(DataStoreCapabilities.STORAGE_SYSTEM_SNAPSHOT.toString());
boolean supportsStorageSystemSnapshots = Boolean.getBoolean(value);
boolean supportsStorageSystemSnapshots = Boolean.parseBoolean(value);

if (supportsStorageSystemSnapshots) {
return DataStoreRole.Primary;
Expand Down
10 changes: 5 additions & 5 deletions server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ public GetUploadParamsResponse doInTransaction(TransactionStatus status) throws
GetUploadParamsResponse response = new GetUploadParamsResponse();

String ssvmUrlDomain = _configDao.getValue(Config.SecStorageSecureCopyCert.key());
String protocol = UseHttpsToUpload.value() ? "https" : "http";
String protocol = UseHttpsToUpload.valueIn(zoneId) ? "https" : "http";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please consider using the constants for "https" and "http" instead of hardcoded string literals.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kept the literals on purpose. This PR only puts back valueIn(zoneId) on a line that already had them, and the same line in TemplateManagerImpl.registerPostUploadInternal uses the same literals (UseHttpsToUpload.valueIn(...) ? "https" : "http"). HttpConstants in utils has HTTPS but no HTTP, so using constants here means adding one and changing both upload paths. I'd keep that out of this fix.


String url = ImageStoreUtil.generatePostUploadUrl(ssvmUrlDomain, ep.getPublicAddr(), vol.getUuid(), protocol);
response.setPostURL(new URL(url));
Expand Down Expand Up @@ -1819,10 +1819,10 @@ protected VolumeVO retrieveAndValidateVolume(long volumeId, Account caller) {
*
* A volume can be destroyed if it is not in any of the following states.
* <ul>
* <li> {code}Volume.State#Destroy{code};
* <li> {code}Volume.State#Expunging{code};
* <li> {code}Volume.State#Expunged{code};
* <li> {code}Volume.State#Allocated{code}.
* <li> {@code Volume.State#Destroy};
* <li> {@code Volume.State#Expunging};
* <li> {@code Volume.State#Expunged};
* <li> {@code Volume.State#Allocated}.
* </ul>
*
* The volume is destroyed via {@link VolumeService#destroyVolume(long)} method.
Expand Down
49 changes: 49 additions & 0 deletions server/src/test/java/com/cloud/api/ApiResponseHelperTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@
import org.apache.cloudstack.api.response.UsageRecordResponse;
import org.apache.cloudstack.api.response.TrafficTypeResponse;
import org.apache.cloudstack.context.CallContext;
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreCapabilities;
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreDriver;
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreDao;
import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO;
import org.apache.cloudstack.usage.UsageService;
import org.apache.cloudstack.vm.UnmanagedInstanceTO;

Expand All @@ -84,7 +90,9 @@
import com.cloud.server.ResourceIcon;
import com.cloud.server.ResourceIconManager;
import com.cloud.server.ResourceTag;
import com.cloud.storage.DataStoreRole;
import com.cloud.storage.GuestOsCategory;
import com.cloud.storage.Snapshot;
import com.cloud.storage.VMTemplateVO;
import com.cloud.usage.UsageVO;
import com.cloud.user.Account;
Expand Down Expand Up @@ -850,4 +858,45 @@ public void showVmInfoForSharedNetworksTestRouterPlaceholderOnly() {
verify(ipResponse, Mockito.never()).setVirtualMachineId(Mockito.anyString());
}
}

private DataStoreRole getDataStoreRoleForCapabilities(Map<String, String> capabilities) {
Snapshot snapshot = Mockito.mock(Snapshot.class);
when(snapshot.getId()).thenReturn(1L);
SnapshotDataStoreVO snapshotStore = Mockito.mock(SnapshotDataStoreVO.class);
when(snapshotStore.getDataStoreId()).thenReturn(2L);
SnapshotDataStoreDao snapshotStoreDao = Mockito.mock(SnapshotDataStoreDao.class);
when(snapshotStoreDao.findOneBySnapshotAndDatastoreRole(1L, DataStoreRole.Primary)).thenReturn(snapshotStore);
DataStoreDriver driver = Mockito.mock(DataStoreDriver.class);
when(driver.getCapabilities()).thenReturn(capabilities);
DataStore dataStore = Mockito.mock(DataStore.class);
when(dataStore.getDriver()).thenReturn(driver);
DataStoreManager dataStoreMgr = Mockito.mock(DataStoreManager.class);
when(dataStoreMgr.getDataStore(2L, DataStoreRole.Primary)).thenReturn(dataStore);

return ApiResponseHelper.getDataStoreRole(snapshot, snapshotStoreDao, dataStoreMgr);
}

private DataStoreRole getDataStoreRoleForStorageSystemSnapshotCapability(String capability) {
return getDataStoreRoleForCapabilities(Map.of(DataStoreCapabilities.STORAGE_SYSTEM_SNAPSHOT.toString(), capability));
}

@Test
public void getDataStoreRoleTestStorageSystemSnapshotSupported() {
Comment thread
bhouse-nexthop marked this conversation as resolved.
Resolved
assertEquals(DataStoreRole.Primary, getDataStoreRoleForStorageSystemSnapshotCapability("true"));
assertEquals(DataStoreRole.Primary, getDataStoreRoleForStorageSystemSnapshotCapability("TRUE"));
assertEquals(DataStoreRole.Primary, getDataStoreRoleForStorageSystemSnapshotCapability("True"));
}

@Test
public void getDataStoreRoleTestStorageSystemSnapshotNotSupported() {
assertEquals(DataStoreRole.Image, getDataStoreRoleForStorageSystemSnapshotCapability("false"));
assertEquals(DataStoreRole.Image, getDataStoreRoleForStorageSystemSnapshotCapability("yes"));
assertEquals(DataStoreRole.Image, getDataStoreRoleForStorageSystemSnapshotCapability(""));
}

@Test
public void getDataStoreRoleTestNoCapabilities() {
assertEquals(DataStoreRole.Image, getDataStoreRoleForCapabilities(null));
assertEquals(DataStoreRole.Image, getDataStoreRoleForCapabilities(Collections.emptyMap()));
}
}
Loading