Skip to content

Commit 96691f6

Browse files
authored
Merge branch '4.19' into fix-create-counters-dup
2 parents 2ace4dd + 641a606 commit 96691f6

File tree

51 files changed

+992
-687
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+992
-687
lines changed

api/src/main/java/org/apache/cloudstack/api/response/HostForMigrationResponse.java

Lines changed: 1 addition & 430 deletions
Large diffs are not rendered by default.

api/src/main/java/org/apache/cloudstack/api/response/NetworkResponse.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,10 @@ public class NetworkResponse extends BaseResponseWithAssociatedNetwork implement
187187
@Param(description = "true network requires restart")
188188
private Boolean restartRequired;
189189

190+
@SerializedName(ApiConstants.SPECIFY_VLAN)
191+
@Param(description = "true if network supports specifying vlan, false otherwise")
192+
private Boolean specifyVlan;
193+
190194
@SerializedName(ApiConstants.SPECIFY_IP_RANGES)
191195
@Param(description = "true if network supports specifying ip ranges, false otherwise")
192196
private Boolean specifyIpRanges;
@@ -487,6 +491,10 @@ public void setRestartRequired(Boolean restartRequired) {
487491
this.restartRequired = restartRequired;
488492
}
489493

494+
public void setSpecifyVlan(Boolean specifyVlan) {
495+
this.specifyVlan = specifyVlan;
496+
}
497+
490498
public void setSpecifyIpRanges(Boolean specifyIpRanges) {
491499
this.specifyIpRanges = specifyIpRanges;
492500
}

client/conf/server.properties.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ session.timeout=30
3232
# Max allowed API request payload/content size in bytes
3333
request.content.size=1048576
3434

35+
# Max allowed API request form keys
36+
request.max.form.keys=5000
37+
3538
# Options to configure and enable HTTPS on the management server
3639
#
3740
# For the management server to pick up these configuration settings, the configured

client/src/main/java/org/apache/cloudstack/ServerDaemon.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ public class ServerDaemon implements Daemon {
8181
private static final String ACCESS_LOG = "access.log";
8282
private static final String REQUEST_CONTENT_SIZE_KEY = "request.content.size";
8383
private static final int DEFAULT_REQUEST_CONTENT_SIZE = 1048576;
84+
private static final String REQUEST_MAX_FORM_KEYS_KEY = "request.max.form.keys";
85+
private static final int DEFAULT_REQUEST_MAX_FORM_KEYS = 5000;
8486

8587
////////////////////////////////////////////////////////
8688
/////////////// Server Configuration ///////////////////
@@ -93,6 +95,7 @@ public class ServerDaemon implements Daemon {
9395
private int httpsPort = 8443;
9496
private int sessionTimeout = 30;
9597
private int maxFormContentSize = DEFAULT_REQUEST_CONTENT_SIZE;
98+
private int maxFormKeys = DEFAULT_REQUEST_MAX_FORM_KEYS;
9699
private boolean httpsEnable = false;
97100
private String accessLogFile = "access.log";
98101
private String bindInterface = null;
@@ -140,6 +143,7 @@ public void init(final DaemonContext context) {
140143
setAccessLogFile(properties.getProperty(ACCESS_LOG, "access.log"));
141144
setSessionTimeout(Integer.valueOf(properties.getProperty(SESSION_TIMEOUT, "30")));
142145
setMaxFormContentSize(Integer.valueOf(properties.getProperty(REQUEST_CONTENT_SIZE_KEY, String.valueOf(DEFAULT_REQUEST_CONTENT_SIZE))));
146+
setMaxFormKeys(Integer.valueOf(properties.getProperty(REQUEST_MAX_FORM_KEYS_KEY, String.valueOf(DEFAULT_REQUEST_MAX_FORM_KEYS))));
143147
} catch (final IOException e) {
144148
LOG.warn("Failed to read configuration from server.properties file", e);
145149
} finally {
@@ -191,6 +195,7 @@ public void start() throws Exception {
191195
// Extra config options
192196
server.setStopAtShutdown(true);
193197
server.setAttribute(ContextHandler.MAX_FORM_CONTENT_SIZE_KEY, maxFormContentSize);
198+
server.setAttribute(ContextHandler.MAX_FORM_KEYS_KEY, maxFormKeys);
194199

195200
// HTTPS Connector
196201
createHttpsConnector(httpConfig);
@@ -263,6 +268,7 @@ private Pair<SessionHandler,HandlerCollection> createHandlers() {
263268
webApp.setContextPath(contextPath);
264269
webApp.setInitParameter("org.eclipse.jetty.servlet.Default.dirAllowed", "false");
265270
webApp.setMaxFormContentSize(maxFormContentSize);
271+
webApp.setMaxFormKeys(maxFormKeys);
266272

267273
// GZIP handler
268274
final GzipHandler gzipHandler = new GzipHandler();
@@ -365,4 +371,8 @@ public void setSessionTimeout(int sessionTimeout) {
365371
public void setMaxFormContentSize(int maxFormContentSize) {
366372
this.maxFormContentSize = maxFormContentSize;
367373
}
374+
375+
public void setMaxFormKeys(int maxFormKeys) {
376+
this.maxFormKeys = maxFormKeys;
377+
}
368378
}

engine/orchestration/src/main/java/com/cloud/agent/manager/AgentManagerImpl.java

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
import org.apache.cloudstack.managed.context.ManagedContextRunnable;
5353
import org.apache.cloudstack.outofbandmanagement.dao.OutOfBandManagementDao;
5454
import org.apache.cloudstack.utils.identity.ManagementServerNode;
55+
import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils;
5556
import org.apache.commons.lang3.BooleanUtils;
5657
import org.apache.log4j.Logger;
5758
import org.apache.log4j.MDC;
@@ -569,27 +570,27 @@ protected AgentAttache notifyMonitorsOfConnection(final AgentAttache attache, fi
569570
}
570571
for (int i = 0; i < cmd.length; i++) {
571572
try {
573+
if (s_logger.isDebugEnabled()) {
574+
s_logger.debug("process connection to issue " + ReflectionToStringBuilderUtils.reflectCollection(cmd[i]) + " forRebalance == " + forRebalance);
575+
}
572576
monitor.second().processConnect(host, cmd[i], forRebalance);
573-
} catch (final Exception e) {
574-
if (e instanceof ConnectionException) {
575-
final ConnectionException ce = (ConnectionException)e;
576-
if (ce.isSetupError()) {
577-
s_logger.warn("Monitor " + monitor.second().getClass().getSimpleName() + " says there is an error in the connect process for " + hostId + " due to " + e.getMessage());
578-
handleDisconnectWithoutInvestigation(attache, Event.AgentDisconnected, true, true);
579-
throw ce;
580-
} else {
581-
s_logger.info("Monitor " + monitor.second().getClass().getSimpleName() + " says not to continue the connect process for " + hostId + " due to " + e.getMessage());
582-
handleDisconnectWithoutInvestigation(attache, Event.ShutdownRequested, true, true);
583-
return attache;
584-
}
585-
} else if (e instanceof HypervisorVersionChangedException) {
586-
handleDisconnectWithoutInvestigation(attache, Event.ShutdownRequested, true, true);
587-
throw new CloudRuntimeException("Unable to connect " + attache.getId(), e);
588-
} else {
589-
s_logger.error("Monitor " + monitor.second().getClass().getSimpleName() + " says there is an error in the connect process for " + hostId + " due to " + e.getMessage(), e);
577+
} catch (final ConnectionException ce) {
578+
if (ce.isSetupError()) {
579+
s_logger.warn("Monitor " + monitor.second().getClass().getSimpleName() + " says there is an error in the connect process for " + hostId + " due to " + ce.getMessage());
590580
handleDisconnectWithoutInvestigation(attache, Event.AgentDisconnected, true, true);
591-
throw new CloudRuntimeException("Unable to connect " + attache.getId(), e);
581+
throw ce;
582+
} else {
583+
s_logger.info("Monitor " + monitor.second().getClass().getSimpleName() + " says not to continue the connect process for " + hostId + " due to " + ce.getMessage());
584+
handleDisconnectWithoutInvestigation(attache, Event.ShutdownRequested, true, true);
585+
return attache;
592586
}
587+
} catch (final HypervisorVersionChangedException hvce) {
588+
handleDisconnectWithoutInvestigation(attache, Event.ShutdownRequested, true, true);
589+
throw new CloudRuntimeException("Unable to connect " + (attache == null ? "<unknown agent>" : attache.getId()), hvce);
590+
} catch (final Exception e) {
591+
s_logger.error("Monitor " + monitor.second().getClass().getSimpleName() + " says there is an error in the connect process for " + hostId + " due to " + e.getMessage(), e);
592+
handleDisconnectWithoutInvestigation(attache, Event.AgentDisconnected, true, true);
593+
throw new CloudRuntimeException("Unable to connect " + (attache == null ? "<unknown agent>" : attache.getId()), e);
593594
}
594595
}
595596
}

engine/schema/src/main/java/com/cloud/upgrade/SystemVmTemplateRegistration.java

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -794,12 +794,16 @@ public void doInTransactionWithoutResult(final TransactionStatus status) {
794794
Long templateId = getRegisteredTemplateId(hypervisorAndTemplateName);
795795
if (templateId != null) {
796796
VMTemplateVO templateVO = vmTemplateDao.findById(templateId);
797-
TemplateDataStoreVO templateDataStoreVO = templateDataStoreDao.findByTemplate(templateId, DataStoreRole.Image);
798-
String installPath = templateDataStoreVO.getInstallPath();
799-
if (validateIfSeeded(storeUrlAndId.first(), installPath, nfsVersion)) {
800-
continue;
801-
} else if (templateVO != null) {
797+
TemplateDataStoreVO templateDataStoreVO = templateDataStoreDao.findByStoreTemplate(storeUrlAndId.second(), templateId);
798+
if (templateDataStoreVO != null) {
799+
String installPath = templateDataStoreVO.getInstallPath();
800+
if (validateIfSeeded(storeUrlAndId.first(), installPath, nfsVersion)) {
801+
continue;
802+
}
803+
}
804+
if (templateVO != null) {
802805
registerTemplate(hypervisorAndTemplateName, storeUrlAndId, templateVO, templateDataStoreVO, filePath);
806+
updateRegisteredTemplateDetails(templateId, hypervisorAndTemplateName);
803807
continue;
804808
}
805809
}
@@ -823,6 +827,11 @@ public void doInTransactionWithoutResult(final TransactionStatus status) {
823827
}
824828

825829
private void updateRegisteredTemplateDetails(Long templateId, Map.Entry<Hypervisor.HypervisorType, String> hypervisorAndTemplateName) {
830+
Pair<Hypervisor.HypervisorType, String> entry = new Pair<>(hypervisorAndTemplateName.getKey(), hypervisorAndTemplateName.getValue());
831+
updateRegisteredTemplateDetails(templateId, entry);
832+
}
833+
834+
private void updateRegisteredTemplateDetails(Long templateId, Pair<Hypervisor.HypervisorType, String> hypervisorAndTemplateName) {
826835
VMTemplateVO templateVO = vmTemplateDao.findById(templateId);
827836
templateVO.setTemplateType(Storage.TemplateType.SYSTEM);
828837
boolean updated = vmTemplateDao.update(templateVO.getId(), templateVO);
@@ -832,11 +841,11 @@ private void updateRegisteredTemplateDetails(Long templateId, Map.Entry<Hypervis
832841
throw new CloudRuntimeException(errMsg);
833842
}
834843

835-
updateSystemVMEntries(templateId, hypervisorAndTemplateName.getKey());
844+
updateSystemVMEntries(templateId, hypervisorAndTemplateName.first());
836845

837846
// Change value of global configuration parameter router.template.* for the corresponding hypervisor and minreq.sysvmtemplate.version for the ACS version
838847
Map<String, String> configParams = new HashMap<>();
839-
configParams.put(RouterTemplateConfigurationNames.get(hypervisorAndTemplateName.getKey()), hypervisorAndTemplateName.getValue());
848+
configParams.put(RouterTemplateConfigurationNames.get(hypervisorAndTemplateName.first()), hypervisorAndTemplateName.second());
840849
configParams.put("minreq.sysvmtemplate.version", getSystemVmTemplateVersion());
841850
updateConfigurationParams(configParams);
842851
}

engine/schema/src/main/java/com/cloud/user/UserAccountVO.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535

3636
import com.cloud.utils.db.Encrypt;
3737
import com.cloud.utils.db.GenericDao;
38+
39+
import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils;
3840
import org.apache.commons.lang3.StringUtils;
3941

4042
@Entity
@@ -368,4 +370,9 @@ public Map<String, String> getDetails() {
368370
public void setDetails(Map<String, String> details) {
369371
this.details = details;
370372
}
373+
374+
@Override
375+
public String toString() {
376+
return String.format("User %s", ReflectionToStringBuilderUtils.reflectOnlySelectedFields(this, "id", "name", "uuid"));
377+
}
371378
}

engine/schema/src/main/java/org/apache/cloudstack/network/dao/NetworkPermissionDao.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@ public interface NetworkPermissionDao extends GenericDao<NetworkPermissionVO, Lo
4040
*/
4141
void removeAllPermissions(long networkId);
4242

43+
/**
44+
* Removes all network permissions associated with a given account.
45+
*
46+
* @param accountId The ID of the account from which all network permissions will be removed.
47+
*/
48+
void removeAccountPermissions(long accountId);
49+
4350
/**
4451
* Find a Network permission by networkId, accountName, and domainId
4552
*

engine/schema/src/main/java/org/apache/cloudstack/network/dao/NetworkPermissionDaoImpl.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public class NetworkPermissionDaoImpl extends GenericDaoBase<NetworkPermissionVO
3535

3636
private SearchBuilder<NetworkPermissionVO> NetworkAndAccountSearch;
3737
private SearchBuilder<NetworkPermissionVO> NetworkIdSearch;
38+
private SearchBuilder<NetworkPermissionVO> accountSearch;
3839
private GenericSearchBuilder<NetworkPermissionVO, Long> FindNetworkIdsByAccount;
3940

4041
protected NetworkPermissionDaoImpl() {
@@ -47,6 +48,10 @@ protected NetworkPermissionDaoImpl() {
4748
NetworkIdSearch.and("networkId", NetworkIdSearch.entity().getNetworkId(), SearchCriteria.Op.EQ);
4849
NetworkIdSearch.done();
4950

51+
accountSearch = createSearchBuilder();
52+
accountSearch.and("accountId", accountSearch.entity().getAccountId(), SearchCriteria.Op.EQ);
53+
accountSearch.done();
54+
5055
FindNetworkIdsByAccount = createSearchBuilder(Long.class);
5156
FindNetworkIdsByAccount.select(null, SearchCriteria.Func.DISTINCT, FindNetworkIdsByAccount.entity().getNetworkId());
5257
FindNetworkIdsByAccount.and("account", FindNetworkIdsByAccount.entity().getAccountId(), SearchCriteria.Op.IN);
@@ -71,6 +76,16 @@ public void removeAllPermissions(long networkId) {
7176
expunge(sc);
7277
}
7378

79+
@Override
80+
public void removeAccountPermissions(long accountId) {
81+
SearchCriteria<NetworkPermissionVO> sc = accountSearch.create();
82+
sc.setParameters("accountId", accountId);
83+
int networkPermissionRemoved = expunge(sc);
84+
if (networkPermissionRemoved > 0) {
85+
s_logger.debug(String.format("Removed [%s] network permission(s) for the account with Id [%s]", networkPermissionRemoved, accountId));
86+
}
87+
}
88+
7489
@Override
7590
public NetworkPermissionVO findByNetworkAndAccount(long networkId, long accountId) {
7691
SearchCriteria<NetworkPermissionVO> sc = NetworkAndAccountSearch.create();
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
-- Licensed to the Apache Software Foundation (ASF) under one
2+
-- or more contributor license agreements. See the NOTICE file
3+
-- distributed with this work for additional information
4+
-- regarding copyright ownership. The ASF licenses this file
5+
-- to you under the Apache License, Version 2.0 (the
6+
-- "License"); you may not use this file except in compliance
7+
-- with the License. You may obtain a copy of the License at
8+
--
9+
-- http://www.apache.org/licenses/LICENSE-2.0
10+
--
11+
-- Unless required by applicable law or agreed to in writing,
12+
-- software distributed under the License is distributed on an
13+
-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
-- KIND, either express or implied. See the License for the
15+
-- specific language governing permissions and limitations
16+
-- under the License.
17+
18+
DROP PROCEDURE IF EXISTS `cloud`.`IDEMPOTENT_UPDATE_API_PERMISSION`;
19+
20+
CREATE PROCEDURE `cloud`.`IDEMPOTENT_UPDATE_API_PERMISSION` (
21+
IN role VARCHAR(255),
22+
IN rule VARCHAR(255),
23+
IN permission VARCHAR(255)
24+
)
25+
BEGIN
26+
DECLARE role_id BIGINT(20) UNSIGNED
27+
; DECLARE max_sort_order BIGINT(20) UNSIGNED
28+
29+
; SELECT `r`.`id` INTO role_id
30+
FROM `cloud`.`roles` `r`
31+
WHERE `r`.`name` = role
32+
AND `r`.`is_default` = 1
33+
34+
; SELECT MAX(`rp`.`sort_order`) INTO max_sort_order
35+
FROM `cloud`.`role_permissions` `rp`
36+
WHERE `rp`.`role_id` = role_id
37+
38+
; IF NOT EXISTS (
39+
SELECT * FROM `cloud`.`role_permissions` `rp`
40+
WHERE `rp`.`role_id` = role_id
41+
AND `rp`.`rule` = rule
42+
) THEN
43+
UPDATE `cloud`.`role_permissions` `rp`
44+
SET `rp`.`sort_order` = max_sort_order + 1
45+
WHERE `rp`.`sort_order` = max_sort_order
46+
AND `rp`.`role_id` = role_id
47+
48+
; INSERT INTO `cloud`.`role_permissions`
49+
(uuid, role_id, rule, permission, sort_order)
50+
VALUES (uuid(), role_id, rule, permission, max_sort_order)
51+
; END IF
52+
;END;

0 commit comments

Comments
 (0)