Skip to content

Commit 64c6a7b

Browse files
committed
Merge branch '4.22' into 422-vmware-to-kvm-guestos
2 parents f82e4e4 + 27bce46 commit 64c6a7b

File tree

18 files changed

+119
-60
lines changed

18 files changed

+119
-60
lines changed

api/src/main/java/org/apache/cloudstack/api/ApiServerService.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,7 @@ public ResponseObject loginUser(HttpSession session, String username, String pas
4949

5050
boolean resetPassword(UserAccount userAccount, String token, String password);
5151

52+
String getDomainId(Map<String, Object[]> params);
53+
5254
boolean isPostRequestsAndTimestampsEnforced();
5355
}

api/src/main/java/org/apache/cloudstack/api/command/user/vpc/CreateStaticRouteCmd.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ public class CreateStaticRouteCmd extends BaseAsyncCreateCmd {
4646
@Parameter(name = ApiConstants.GATEWAY_ID,
4747
type = CommandType.UUID,
4848
entityType = PrivateGatewayResponse.class,
49-
required = true,
5049
description = "The gateway ID we are creating static route for. Mutually exclusive with the nexthop parameter")
5150
private Long gatewayId;
5251

engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2326,7 +2326,8 @@ public void prepareAllNicsForMigration(final VirtualMachineProfile vm, final Dep
23262326
for (final NetworkElement element : networkElements) {
23272327
if (providersToImplement.contains(element.getProvider())) {
23282328
if (!_networkModel.isProviderEnabledInPhysicalNetwork(_networkModel.getPhysicalNetworkId(network), element.getProvider().getName())) {
2329-
throw new CloudRuntimeException(String.format("Service provider %s either doesn't exist or is not enabled in physical network: %s", element.getProvider().getName(), _physicalNetworkDao.findById(network.getPhysicalNetworkId())));
2329+
throw new CloudRuntimeException(String.format("Service provider %s either doesn't exist or is not enabled in physical network: %s",
2330+
element.getProvider().getName(), _physicalNetworkDao.findById(network.getPhysicalNetworkId())));
23302331
}
23312332
if (element instanceof NetworkMigrationResponder) {
23322333
if (!((NetworkMigrationResponder) element).prepareMigration(profile, network, vm, dest, context)) {
@@ -2633,6 +2634,10 @@ && isDhcpAccrossMultipleSubnetsSupported(dhcpServiceProvider)) {
26332634

26342635
final NetworkGuru guru = AdapterBase.getAdapterByName(networkGurus, network.getGuruName());
26352636
guru.deallocate(network, profile, vm);
2637+
if (nic.getReservationStrategy() == Nic.ReservationStrategy.Create) {
2638+
applyProfileToNicForRelease(nic, profile);
2639+
_nicDao.update(nic.getId(), nic);
2640+
}
26362641
if (BooleanUtils.isNotTrue(preserveNics)) {
26372642
_nicDao.remove(nic.getId());
26382643
}

engine/schema/src/main/resources/META-INF/db/schema-42200to42210-cleanup.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,5 @@
1818
--;
1919
-- Schema upgrade cleanup from 4.22.0.0 to 4.22.1.0
2020
--;
21+
22+
DROP VIEW IF EXISTS `cloud`.`account_netstats_view`;

engine/schema/src/main/resources/META-INF/db/views/cloud.account_netstats_view.sql

Lines changed: 0 additions & 31 deletions
This file was deleted.

engine/schema/src/main/resources/META-INF/db/views/cloud.account_view.sql

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ select
3939
`data_center`.`id` AS `data_center_id`,
4040
`data_center`.`uuid` AS `data_center_uuid`,
4141
`data_center`.`name` AS `data_center_name`,
42-
`account_netstats_view`.`bytesReceived` AS `bytesReceived`,
43-
`account_netstats_view`.`bytesSent` AS `bytesSent`,
42+
`account_netstats`.`bytesReceived` AS `bytesReceived`,
43+
`account_netstats`.`bytesSent` AS `bytesSent`,
4444
`vmlimit`.`max` AS `vmLimit`,
4545
`vmcount`.`count` AS `vmTotal`,
4646
`runningvm`.`vmcount` AS `runningVms`,
@@ -89,8 +89,15 @@ from
8989
`cloud`.`domain` ON account.domain_id = domain.id
9090
left join
9191
`cloud`.`data_center` ON account.default_zone_id = data_center.id
92-
left join
93-
`cloud`.`account_netstats_view` ON account.id = account_netstats_view.account_id
92+
left join lateral (
93+
select
94+
coalesce(sum(`user_statistics`.`net_bytes_received` + `user_statistics`.`current_bytes_received`), 0) AS `bytesReceived`,
95+
coalesce(sum(`user_statistics`.`net_bytes_sent` + `user_statistics`.`current_bytes_sent`), 0) AS `bytesSent`
96+
from
97+
`cloud`.`user_statistics`
98+
where
99+
`user_statistics`.`account_id` = `account`.`id`
100+
) AS `account_netstats` ON TRUE
94101
left join
95102
`cloud`.`resource_limit` vmlimit ON account.id = vmlimit.account_id
96103
and vmlimit.type = 'user_vm' and vmlimit.tag IS NULL

plugins/maintenance/src/test/java/org/apache/cloudstack/maintenance/ManagementServerMaintenanceManagerImplTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,6 @@ public void prepareForMaintenanceAndCancelFromMaintenanceState() {
321321
spy.prepareForMaintenance("static", false);
322322
});
323323

324-
Mockito.when(msHost.getState()).thenReturn(ManagementServerHost.State.Maintenance);
325324
Mockito.doNothing().when(jobManagerMock).enableAsyncJobs();
326325
spy.cancelMaintenance();
327326
Mockito.verify(jobManagerMock).enableAsyncJobs();
@@ -339,7 +338,6 @@ public void prepareForMaintenanceAndCancelFromPreparingForMaintenanceState() {
339338
spy.prepareForMaintenance("static", false);
340339
});
341340

342-
Mockito.when(msHost.getState()).thenReturn(ManagementServerHost.State.PreparingForMaintenance);
343341
Mockito.doNothing().when(jobManagerMock).enableAsyncJobs();
344342
spy.cancelMaintenance();
345343
Mockito.verify(jobManagerMock).enableAsyncJobs();

plugins/user-authenticators/oauth2/src/main/java/org/apache/cloudstack/oauth2/api/command/OauthLoginAPIAuthenticatorCmd.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,14 +176,14 @@ private String doOauthAuthentication(HttpSession session, Long domainId, String
176176
}
177177

178178
protected Long getDomainIdFromParams(Map<String, Object[]> params, StringBuilder auditTrailSb, String responseType) {
179-
String[] domainIdArr = (String[])params.get(ApiConstants.DOMAIN_ID);
179+
String domainIdStr = _apiServer.getDomainId(params);
180180
Long domainId = null;
181-
if (domainIdArr != null && domainIdArr.length > 0) {
181+
if (StringUtils.isNotEmpty(domainIdStr)) {
182182
try {
183183
//check if UUID is passed in for domain
184-
domainId = _apiServer.fetchDomainId(domainIdArr[0]);
184+
domainId = _apiServer.fetchDomainId(domainIdStr);
185185
if (domainId == null) {
186-
domainId = Long.parseLong(domainIdArr[0]);
186+
domainId = Long.parseLong(domainIdStr);
187187
}
188188
auditTrailSb.append(" domainid=" + domainId);// building the params for POST call
189189
} catch (final NumberFormatException e) {

plugins/user-authenticators/oauth2/src/test/java/org/apache/cloudstack/oauth2/api/command/OauthLoginAPIAuthenticatorCmdTest.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,29 @@ public void testGetDomainIdFromParams() {
8585
ApiServer apiServer = mock(ApiServer.class);
8686
cmd._apiServer = apiServer;
8787
when(apiServer.fetchDomainId("1234")).thenReturn(5678L);
88+
when(apiServer.getDomainId(params)).thenCallRealMethod();
8889

8990
Long domainId = cmd.getDomainIdFromParams(params, auditTrailSb, responseType);
9091

9192
assertEquals(Long.valueOf(5678), domainId);
9293
assertEquals(" domainid=5678", auditTrailSb.toString());
9394
}
95+
96+
@Test
97+
public void testGetDomainIdFromCamelCaseParam() {
98+
StringBuilder auditTrailSb = new StringBuilder();
99+
String responseType = "json";
100+
Map<String, Object[]> params = new HashMap<>();
101+
params.put(ApiConstants.DOMAIN_ID, null);
102+
params.put(ApiConstants.DOMAIN__ID, new String[]{"5678"});
103+
ApiServer apiServer = mock(ApiServer.class);
104+
cmd._apiServer = apiServer;
105+
when(apiServer.fetchDomainId("5678")).thenReturn(1234L);
106+
when(apiServer.getDomainId(params)).thenCallRealMethod();
107+
108+
Long domainId = cmd.getDomainIdFromParams(params, auditTrailSb, responseType);
109+
110+
assertEquals(Long.valueOf(1234), domainId);
111+
assertEquals(" domainid=1234", auditTrailSb.toString());
112+
}
94113
}

server/src/main/java/com/cloud/api/ApiServer.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@
119119
import org.apache.cloudstack.user.UserPasswordResetManager;
120120
import org.apache.cloudstack.utils.identity.ManagementServerNode;
121121
import org.apache.commons.codec.binary.Base64;
122+
import org.apache.commons.collections.MapUtils;
122123
import org.apache.commons.lang3.EnumUtils;
123124
import org.apache.http.ConnectionClosedException;
124125
import org.apache.http.HttpException;
@@ -1400,6 +1401,25 @@ public boolean resetPassword(UserAccount userAccount, String token, String passw
14001401
return userPasswordResetManager.validateAndResetPassword(userAccount, token, password);
14011402
}
14021403

1404+
@Override
1405+
public String getDomainId(Map<String, Object[]> params) {
1406+
if (MapUtils.isEmpty(params)) {
1407+
return null;
1408+
}
1409+
1410+
String[] domainIdArr = (String[])params.get(ApiConstants.DOMAIN_ID);
1411+
if (domainIdArr == null) {
1412+
// Fallback to support clients using the camelCase parameter name "domainId"
1413+
domainIdArr = (String[])params.get(ApiConstants.DOMAIN__ID);
1414+
}
1415+
1416+
if (domainIdArr == null || domainIdArr.length == 0) {
1417+
return null;
1418+
}
1419+
1420+
return domainIdArr[0];
1421+
}
1422+
14031423
private void checkCommandAvailable(final User user, final String commandName, final InetAddress remoteAddress) throws PermissionDeniedException {
14041424
if (user == null) {
14051425
throw new PermissionDeniedException("User is null for role based API access check for command" + commandName);

0 commit comments

Comments
 (0)