You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by bh...@apache.org on 2015/08/08 21:06:57 UTC
[1/7] git commit: updated refs/heads/4.5-samlfixes to 69f39d5
Repository: cloudstack
Updated Branches:
refs/heads/4.5-samlfixes 6a1430c11 -> 69f39d533 (forced update)
CLOUDSTACK-8703: Fixed issue when listing directory on S3, it would only return objectSummaries when the anwser from the S3 System was truncated.
Signed-off-by: Rohit Yadav <ro...@shapeblue.com>
This closes #651
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/58c6a8d1
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/58c6a8d1
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/58c6a8d1
Branch: refs/heads/4.5-samlfixes
Commit: 58c6a8d1a38f65dc472a6c35ede2f01e608a1a7a
Parents: 2ed9539
Author: Boris Schrijver <bo...@pcextreme.nl>
Authored: Mon Aug 3 17:10:05 2015 +0200
Committer: Rohit Yadav <ro...@shapeblue.com>
Committed: Tue Aug 4 17:42:21 2015 +0530
----------------------------------------------------------------------
utils/src/com/cloud/utils/S3Utils.java | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/58c6a8d1/utils/src/com/cloud/utils/S3Utils.java
----------------------------------------------------------------------
diff --git a/utils/src/com/cloud/utils/S3Utils.java b/utils/src/com/cloud/utils/S3Utils.java
index ae7a453..532b2eb 100644
--- a/utils/src/com/cloud/utils/S3Utils.java
+++ b/utils/src/com/cloud/utils/S3Utils.java
@@ -343,10 +343,15 @@ public final class S3Utils {
ListObjectsRequest listObjectsRequest = new ListObjectsRequest().withBucketName(bucketName).withPrefix(directory + SEPARATOR);
ObjectListing ol = client.listObjects(listObjectsRequest);
- while (ol != null && ol.isTruncated()) {
+ if(ol.isTruncated()) {
+ do {
+ objects.addAll(ol.getObjectSummaries());
+ listObjectsRequest.setMarker(ol.getNextMarker());
+ ol = client.listObjects(listObjectsRequest);
+ } while (ol.isTruncated());
+ }
+ else {
objects.addAll(ol.getObjectSummaries());
- listObjectsRequest.setMarker(ol.getNextMarker());
- ol = client.listObjects(listObjectsRequest);
}
if (objects.isEmpty()) {
[4/7] git commit: updated refs/heads/4.5-samlfixes to 69f39d5
Posted by bh...@apache.org.
CLOUDSTACK-8702: Add/refactor sessionkey checking code to HttpUtils
Signed-off-by: Rohit Yadav <ro...@shapeblue.com>
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/6eb2e6ba
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/6eb2e6ba
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/6eb2e6ba
Branch: refs/heads/4.5-samlfixes
Commit: 6eb2e6ba95602d50a844dd361cbc731b03f84699
Parents: 17366f2
Author: Rohit Yadav <ro...@shapeblue.com>
Authored: Mon Aug 3 14:34:20 2015 +0530
Committer: Rohit Yadav <ro...@shapeblue.com>
Committed: Sun Aug 9 00:34:54 2015 +0530
----------------------------------------------------------------------
server/src/com/cloud/api/ApiServlet.java | 8 +-------
utils/src/com/cloud/utils/HttpUtils.java | 16 ++++++++++++++++
2 files changed, 17 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/6eb2e6ba/server/src/com/cloud/api/ApiServlet.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/ApiServlet.java b/server/src/com/cloud/api/ApiServlet.java
index d9e77bd..070545d 100644
--- a/server/src/com/cloud/api/ApiServlet.java
+++ b/server/src/com/cloud/api/ApiServlet.java
@@ -237,13 +237,7 @@ public class ApiServlet extends HttpServlet {
userId = (Long)session.getAttribute("userid");
final String account = (String) session.getAttribute("account");
final Object accountObj = session.getAttribute("accountobj");
- final String sessionKey = (String) session.getAttribute(ApiConstants.SESSIONKEY);
- final String sessionKeyFromCookie = HttpUtils.findCookie(req.getCookies(), ApiConstants.SESSIONKEY);
- final String[] sessionKeyFromParams = (String[]) params.get(ApiConstants.SESSIONKEY);
- if ((sessionKey == null)
- || (sessionKeyFromParams == null && sessionKeyFromCookie == null)
- || (sessionKeyFromParams != null && !sessionKey.equals(sessionKeyFromParams[0]))
- || (sessionKeyFromCookie != null && !sessionKey.equals(sessionKeyFromCookie))) {
+ if (!HttpUtils.validateSessionKey(session, params, req.getCookies(), ApiConstants.SESSIONKEY)) {
try {
session.invalidate();
} catch (final IllegalStateException ise) {
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/6eb2e6ba/utils/src/com/cloud/utils/HttpUtils.java
----------------------------------------------------------------------
diff --git a/utils/src/com/cloud/utils/HttpUtils.java b/utils/src/com/cloud/utils/HttpUtils.java
index 6077c44..379b117 100644
--- a/utils/src/com/cloud/utils/HttpUtils.java
+++ b/utils/src/com/cloud/utils/HttpUtils.java
@@ -23,7 +23,9 @@ import org.apache.log4j.Logger;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
import java.io.IOException;
+import java.util.Map;
public class HttpUtils {
@@ -89,4 +91,18 @@ public class HttpUtils {
}
}
}
+
+ public static boolean validateSessionKey(final HttpSession session, final Map<String, Object[]> params, final Cookie[] cookies, final String sessionKeyString) {
+ final String sessionKey = (String) session.getAttribute(sessionKeyString);
+ final String sessionKeyFromCookie = HttpUtils.findCookie(cookies, sessionKeyString);
+ final String[] sessionKeyFromParams = (String[]) params.get(sessionKeyString);
+ if ((sessionKey == null)
+ || (sessionKeyFromParams == null && sessionKeyFromCookie == null)
+ || (sessionKeyFromParams != null && !sessionKey.equals(sessionKeyFromParams[0]))
+ || (sessionKeyFromCookie != null && !sessionKey.equals(sessionKeyFromCookie))) {
+ return false;
+ }
+ return true;
+ }
+
}
[7/7] git commit: updated refs/heads/4.5-samlfixes to 69f39d5
Posted by bh...@apache.org.
CLOUDSTACK-8701: Add administrative contact block as per SAML IDP expectations
Signed-off-by: Rohit Yadav <ro...@shapeblue.com>
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/69f39d53
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/69f39d53
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/69f39d53
Branch: refs/heads/4.5-samlfixes
Commit: 69f39d53316ba02b75516d0f8c37d6430027ee33
Parents: 37f30a6
Author: Rohit Yadav <ro...@shapeblue.com>
Authored: Sun Aug 9 00:13:51 2015 +0530
Committer: Rohit Yadav <ro...@shapeblue.com>
Committed: Sun Aug 9 00:35:14 2015 +0530
----------------------------------------------------------------------
.../api/command/GetServiceProviderMetaDataCmd.java | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/69f39d53/plugins/user-authenticators/saml2/src/org/apache/cloudstack/api/command/GetServiceProviderMetaDataCmd.java
----------------------------------------------------------------------
diff --git a/plugins/user-authenticators/saml2/src/org/apache/cloudstack/api/command/GetServiceProviderMetaDataCmd.java b/plugins/user-authenticators/saml2/src/org/apache/cloudstack/api/command/GetServiceProviderMetaDataCmd.java
index bed594f..80d38fd 100644
--- a/plugins/user-authenticators/saml2/src/org/apache/cloudstack/api/command/GetServiceProviderMetaDataCmd.java
+++ b/plugins/user-authenticators/saml2/src/org/apache/cloudstack/api/command/GetServiceProviderMetaDataCmd.java
@@ -205,16 +205,28 @@ public class GetServiceProviderMetaDataCmd extends BaseCmd implements APIAuthent
spSSODescriptor.addSupportedProtocol(SAMLConstants.SAML20P_NS);
spEntityDescriptor.getRoleDescriptors().add(spSSODescriptor);
- ContactPerson contactPerson = new ContactPersonBuilder().buildObject();
+ // Add technical contact
GivenName givenName = new GivenNameBuilder().buildObject();
givenName.setName(spMetadata.getContactPersonName());
EmailAddress emailAddress = new EmailAddressBuilder().buildObject();
emailAddress.setAddress(spMetadata.getContactPersonEmail());
+ ContactPerson contactPerson = new ContactPersonBuilder().buildObject();
contactPerson.setType(ContactPersonTypeEnumeration.TECHNICAL);
contactPerson.setGivenName(givenName);
contactPerson.getEmailAddresses().add(emailAddress);
spEntityDescriptor.getContactPersons().add(contactPerson);
+ // Add administrative/support contact
+ GivenName givenNameAdmin = new GivenNameBuilder().buildObject();
+ givenNameAdmin.setName(spMetadata.getContactPersonName());
+ EmailAddress emailAddressAdmin = new EmailAddressBuilder().buildObject();
+ emailAddressAdmin.setAddress(spMetadata.getContactPersonEmail());
+ ContactPerson contactPersonAdmin = new ContactPersonBuilder().buildObject();
+ contactPersonAdmin.setType(ContactPersonTypeEnumeration.ADMINISTRATIVE);
+ contactPersonAdmin.setGivenName(givenNameAdmin);
+ contactPersonAdmin.getEmailAddresses().add(emailAddressAdmin);
+ spEntityDescriptor.getContactPersons().add(contactPersonAdmin);
+
Organization organization = new OrganizationBuilder().buildObject();
OrganizationName organizationName = new OrganizationNameBuilder().buildObject();
organizationName.setName(new LocalizedString(spMetadata.getOrganizationName(), Locale.getDefault().getLanguage()));
[5/7] git commit: updated refs/heads/4.5-samlfixes to 69f39d5
Posted by bh...@apache.org.
CLOUDSTACK-8701: Allow SAML users to switch accounts
SAML authorized accounts might be across various domains, this allows for
switching of accounts only in case of SAML authenticated user accounts across
other accounts with the same SAML uid/username.
Signed-off-by: Rohit Yadav <ro...@shapeblue.com>
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/8c514491
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/8c514491
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/8c514491
Branch: refs/heads/4.5-samlfixes
Commit: 8c5144919fae28529f5c23995b4cb03b8300550f
Parents: 6eb2e6b
Author: Rohit Yadav <ro...@shapeblue.com>
Authored: Mon Aug 3 12:36:14 2015 +0530
Committer: Rohit Yadav <ro...@shapeblue.com>
Committed: Sun Aug 9 00:34:55 2015 +0530
----------------------------------------------------------------------
client/tomcatconf/commands.properties.in | 1 +
.../command/GetServiceProviderMetaDataCmd.java | 2 +-
.../command/ListAndSwitchSAMLAccountCmd.java | 195 +++++++++++++++++++
.../cloudstack/api/command/ListIdpsCmd.java | 2 +-
.../command/SAML2LoginAPIAuthenticatorCmd.java | 36 +---
.../api/response/SamlUserAccountResponse.java | 99 ++++++++++
.../cloudstack/saml/SAML2AuthManagerImpl.java | 2 +
.../cloudstack/saml/SAML2UserAuthenticator.java | 22 +--
.../org/apache/cloudstack/saml/SAMLUtils.java | 18 ++
ui/index.jsp | 7 -
ui/scripts/ui-custom/login.js | 8 +-
ui/scripts/ui/core.js | 77 ++++++++
12 files changed, 401 insertions(+), 68 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/8c514491/client/tomcatconf/commands.properties.in
----------------------------------------------------------------------
diff --git a/client/tomcatconf/commands.properties.in b/client/tomcatconf/commands.properties.in
index a66a3dc..a69605c 100644
--- a/client/tomcatconf/commands.properties.in
+++ b/client/tomcatconf/commands.properties.in
@@ -29,6 +29,7 @@ getSPMetadata=15
listIdps=15
authorizeSamlSso=7
listSamlAuthorization=7
+listAndSwitchSamlAccount=15
### Account commands
createAccount=7
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/8c514491/plugins/user-authenticators/saml2/src/org/apache/cloudstack/api/command/GetServiceProviderMetaDataCmd.java
----------------------------------------------------------------------
diff --git a/plugins/user-authenticators/saml2/src/org/apache/cloudstack/api/command/GetServiceProviderMetaDataCmd.java b/plugins/user-authenticators/saml2/src/org/apache/cloudstack/api/command/GetServiceProviderMetaDataCmd.java
index ffaad7a..bed594f 100644
--- a/plugins/user-authenticators/saml2/src/org/apache/cloudstack/api/command/GetServiceProviderMetaDataCmd.java
+++ b/plugins/user-authenticators/saml2/src/org/apache/cloudstack/api/command/GetServiceProviderMetaDataCmd.java
@@ -266,7 +266,7 @@ public class GetServiceProviderMetaDataCmd extends BaseCmd implements APIAuthent
}
}
if (_samlAuthManager == null) {
- s_logger.error("No suitable Pluggable Authentication Manager found for SAML2 Login Cmd");
+ s_logger.error("No suitable Pluggable Authentication Manager found for SAML2 getSPMetadata Cmd");
}
}
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/8c514491/plugins/user-authenticators/saml2/src/org/apache/cloudstack/api/command/ListAndSwitchSAMLAccountCmd.java
----------------------------------------------------------------------
diff --git a/plugins/user-authenticators/saml2/src/org/apache/cloudstack/api/command/ListAndSwitchSAMLAccountCmd.java b/plugins/user-authenticators/saml2/src/org/apache/cloudstack/api/command/ListAndSwitchSAMLAccountCmd.java
new file mode 100644
index 0000000..db0d6dc
--- /dev/null
+++ b/plugins/user-authenticators/saml2/src/org/apache/cloudstack/api/command/ListAndSwitchSAMLAccountCmd.java
@@ -0,0 +1,195 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package org.apache.cloudstack.api.command;
+
+import com.cloud.api.response.ApiResponseSerializer;
+import com.cloud.domain.Domain;
+import com.cloud.domain.dao.DomainDao;
+import com.cloud.user.Account;
+import com.cloud.user.User;
+import com.cloud.user.UserAccount;
+import com.cloud.user.UserAccountVO;
+import com.cloud.user.dao.UserAccountDao;
+import com.cloud.user.dao.UserDao;
+import com.cloud.utils.HttpUtils;
+import org.apache.cloudstack.api.APICommand;
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.ApiErrorCode;
+import org.apache.cloudstack.api.ApiServerService;
+import org.apache.cloudstack.api.BaseCmd;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.auth.APIAuthenticationType;
+import org.apache.cloudstack.api.auth.APIAuthenticator;
+import org.apache.cloudstack.api.auth.PluggableAPIAuthenticator;
+import org.apache.cloudstack.api.response.DomainResponse;
+import org.apache.cloudstack.api.response.ListResponse;
+import org.apache.cloudstack.api.response.LoginCmdResponse;
+import org.apache.cloudstack.api.response.SamlUserAccountResponse;
+import org.apache.cloudstack.api.response.SuccessResponse;
+import org.apache.cloudstack.api.response.UserResponse;
+import org.apache.cloudstack.saml.SAML2AuthManager;
+import org.apache.cloudstack.saml.SAMLUtils;
+import org.apache.log4j.Logger;
+
+import javax.inject.Inject;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+@APICommand(name = "listAndSwitchSamlAccount", description = "Lists and switches to other SAML accounts owned by the SAML user", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
+public class ListAndSwitchSAMLAccountCmd extends BaseCmd implements APIAuthenticator {
+ public static final Logger s_logger = Logger.getLogger(ListAndSwitchSAMLAccountCmd.class.getName());
+ private static final String s_name = "listandswitchsamlaccountresponse";
+
+ @Inject
+ ApiServerService _apiServer;
+
+ @Inject
+ private UserAccountDao _userAccountDao;
+ @Inject
+ private UserDao _userDao;
+ @Inject
+ private DomainDao _domainDao;
+
+ SAML2AuthManager _samlAuthManager;
+
+ /////////////////////////////////////////////////////
+ //////////////// API parameters /////////////////////
+ /////////////////////////////////////////////////////
+
+ @Parameter(name = ApiConstants.USER_ID, type = CommandType.UUID, entityType = UserResponse.class, required = false, description = "User uuid")
+ private Long userId;
+
+ @Parameter(name = ApiConstants.DOMAIN_ID, type = CommandType.UUID, entityType = DomainResponse.class, required = false, description = "Domain uuid")
+ private Long domainId;
+
+ @Override
+ public String getCommandName() {
+ return s_name;
+ }
+
+ @Override
+ public long getEntityOwnerId() {
+ return Account.ACCOUNT_ID_SYSTEM;
+ }
+
+ @Override
+ public void execute() {
+ throw new ServerApiException(ApiErrorCode.METHOD_NOT_ALLOWED, "This is an authentication plugin api, cannot be used directly");
+ }
+
+ @Override
+ public String authenticate(final String command, final Map<String, Object[]> params, final HttpSession session, final String remoteAddress, final String responseType, final StringBuilder auditTrailSb, final HttpServletRequest req, final HttpServletResponse resp) throws ServerApiException {
+ if (session == null || session.isNew()) {
+ throw new ServerApiException(ApiErrorCode.UNAUTHORIZED, _apiServer.getSerializedApiError(ApiErrorCode.UNAUTHORIZED.getHttpCode(),
+ "Only authenticated saml users can request this API",
+ params, responseType));
+ }
+
+ if (!HttpUtils.validateSessionKey(session, params, req.getCookies(), ApiConstants.SESSIONKEY)) {
+ throw new ServerApiException(ApiErrorCode.UNAUTHORIZED, _apiServer.getSerializedApiError(ApiErrorCode.UNAUTHORIZED.getHttpCode(),
+ "Unauthorized session, please re-login",
+ params, responseType));
+ }
+
+ final long currentUserId = (Long) session.getAttribute("userid");
+ final UserAccount currentUserAccount = _accountService.getUserAccountById(currentUserId);
+ if (currentUserAccount == null || currentUserAccount.getSource() != User.Source.SAML2) {
+ throw new ServerApiException(ApiErrorCode.ACCOUNT_ERROR, _apiServer.getSerializedApiError(ApiErrorCode.ACCOUNT_ERROR.getHttpCode(),
+ "Only authenticated saml users can request this API",
+ params, responseType));
+ }
+
+ String userUuid = null;
+ String domainUuid = null;
+ if (params.containsKey(ApiConstants.USER_ID)) {
+ userUuid = ((String[])params.get(ApiConstants.USER_ID))[0];
+ }
+ if (params.containsKey(ApiConstants.DOMAIN_ID)) {
+ domainUuid = ((String[])params.get(ApiConstants.DOMAIN_ID))[0];
+ }
+
+ if (userUuid != null && domainUuid != null) {
+ final User user = _userDao.findByUuid(userUuid);
+ final Domain domain = _domainDao.findByUuid(domainUuid);
+ final UserAccount nextUserAccount = _accountService.getUserAccountById(user.getId());
+ if (!nextUserAccount.getUsername().equals(currentUserAccount.getUsername())
+ || !nextUserAccount.getExternalEntity().equals(currentUserAccount.getExternalEntity())
+ || (nextUserAccount.getDomainId() != domain.getId())
+ || (nextUserAccount.getSource() != User.Source.SAML2)) {
+ throw new ServerApiException(ApiErrorCode.PARAM_ERROR, _apiServer.getSerializedApiError(ApiErrorCode.PARAM_ERROR.getHttpCode(),
+ "User account is not allowed to switch to the requested account",
+ params, responseType));
+ }
+ try {
+ if (_apiServer.verifyUser(nextUserAccount.getId())) {
+ final LoginCmdResponse loginResponse = (LoginCmdResponse) _apiServer.loginUser(session, nextUserAccount.getUsername(), nextUserAccount.getUsername() + nextUserAccount.getSource().toString(),
+ nextUserAccount.getDomainId(), null, remoteAddress, params);
+ SAMLUtils.setupSamlUserCookies(loginResponse, resp);
+ resp.sendRedirect(SAML2AuthManager.SAMLCloudStackRedirectionUrl.value());
+ return ApiResponseSerializer.toSerializedString(loginResponse, responseType);
+ }
+ } catch (final Exception ignored) {
+ }
+ } else {
+ List<UserAccountVO> switchableAccounts = _userAccountDao.getAllUsersByNameAndEntity(currentUserAccount.getUsername(), currentUserAccount.getExternalEntity());
+ if (switchableAccounts != null && switchableAccounts.size() > 0 && currentUserId != User.UID_SYSTEM) {
+ List<SamlUserAccountResponse> accountResponses = new ArrayList<SamlUserAccountResponse>();
+ for (UserAccountVO userAccount: switchableAccounts) {
+ User user = _userDao.getUser(userAccount.getId());
+ Domain domain = _domainService.getDomain(userAccount.getDomainId());
+ SamlUserAccountResponse accountResponse = new SamlUserAccountResponse();
+ accountResponse.setUserId(user.getUuid());
+ accountResponse.setUserName(user.getUsername());
+ accountResponse.setDomainId(domain.getUuid());
+ accountResponse.setDomainName(domain.getName());
+ accountResponse.setAccountName(userAccount.getAccountName());
+ accountResponse.setIdpId(user.getExternalEntity());
+ accountResponses.add(accountResponse);
+ }
+ ListResponse<SamlUserAccountResponse> response = new ListResponse<SamlUserAccountResponse>();
+ response.setResponses(accountResponses);
+ response.setResponseName(getCommandName());
+ return ApiResponseSerializer.toSerializedString(response, responseType);
+ }
+ }
+ throw new ServerApiException(ApiErrorCode.ACCOUNT_ERROR, _apiServer.getSerializedApiError(ApiErrorCode.ACCOUNT_ERROR.getHttpCode(),
+ "Unable to switch to requested SAML account. Please make sure your user/account is enabled. Please contact your administrator.",
+ params, responseType));
+ }
+
+ @Override
+ public APIAuthenticationType getAPIType() {
+ return APIAuthenticationType.READONLY_API;
+ }
+
+ @Override
+ public void setAuthenticators(List<PluggableAPIAuthenticator> authenticators) {
+ for (PluggableAPIAuthenticator authManager: authenticators) {
+ if (authManager != null && authManager instanceof SAML2AuthManager) {
+ _samlAuthManager = (SAML2AuthManager) authManager;
+ }
+ }
+ if (_samlAuthManager == null) {
+ s_logger.error("No suitable Pluggable Authentication Manager found for SAML2 listAndSwitchSamlAccount Cmd");
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/8c514491/plugins/user-authenticators/saml2/src/org/apache/cloudstack/api/command/ListIdpsCmd.java
----------------------------------------------------------------------
diff --git a/plugins/user-authenticators/saml2/src/org/apache/cloudstack/api/command/ListIdpsCmd.java b/plugins/user-authenticators/saml2/src/org/apache/cloudstack/api/command/ListIdpsCmd.java
index 43ecfc5..4771342 100644
--- a/plugins/user-authenticators/saml2/src/org/apache/cloudstack/api/command/ListIdpsCmd.java
+++ b/plugins/user-authenticators/saml2/src/org/apache/cloudstack/api/command/ListIdpsCmd.java
@@ -111,4 +111,4 @@ public class ListIdpsCmd extends BaseCmd implements APIAuthenticator {
s_logger.error("No suitable Pluggable Authentication Manager found for SAML2 Login Cmd");
}
}
-}
\ No newline at end of file
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/8c514491/plugins/user-authenticators/saml2/src/org/apache/cloudstack/api/command/SAML2LoginAPIAuthenticatorCmd.java
----------------------------------------------------------------------
diff --git a/plugins/user-authenticators/saml2/src/org/apache/cloudstack/api/command/SAML2LoginAPIAuthenticatorCmd.java b/plugins/user-authenticators/saml2/src/org/apache/cloudstack/api/command/SAML2LoginAPIAuthenticatorCmd.java
index d4940ec..188eb6b 100644
--- a/plugins/user-authenticators/saml2/src/org/apache/cloudstack/api/command/SAML2LoginAPIAuthenticatorCmd.java
+++ b/plugins/user-authenticators/saml2/src/org/apache/cloudstack/api/command/SAML2LoginAPIAuthenticatorCmd.java
@@ -17,13 +17,11 @@
package org.apache.cloudstack.api.command;
import com.cloud.api.response.ApiResponseSerializer;
-import com.cloud.exception.CloudAuthenticationException;
import com.cloud.user.Account;
import com.cloud.user.DomainManager;
import com.cloud.user.UserAccount;
import com.cloud.user.UserAccountVO;
import com.cloud.user.dao.UserAccountDao;
-import com.cloud.utils.HttpUtils;
import com.cloud.utils.db.EntityManager;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ApiConstants;
@@ -64,14 +62,12 @@ import org.opensaml.xml.validation.ValidationException;
import org.xml.sax.SAXException;
import javax.inject.Inject;
-import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.stream.FactoryConfigurationError;
import java.io.IOException;
-import java.net.URLEncoder;
import java.util.List;
import java.util.Map;
@@ -195,7 +191,6 @@ public class SAML2LoginAPIAuthenticatorCmd extends BaseCmd implements APIAuthent
}
String username = null;
- Long domainId = null;
Issuer issuer = processedSAMLResponse.getIssuer();
SAMLProviderMetadata spMetadata = _samlAuthManager.getSPMetadata();
SAMLProviderMetadata idpMetadata = _samlAuthManager.getIdPMetadata(issuer.getValue());
@@ -204,9 +199,6 @@ public class SAML2LoginAPIAuthenticatorCmd extends BaseCmd implements APIAuthent
s_logger.debug("Received SAMLResponse in response to id=" + responseToId);
SAMLTokenVO token = _samlAuthManager.getToken(responseToId);
if (token != null) {
- if (token.getDomainId() != null) {
- domainId = token.getDomainId();
- }
if (!(token.getEntity().equalsIgnoreCase(issuer.getValue()))) {
throw new ServerApiException(ApiErrorCode.ACCOUNT_ERROR, _apiServer.getSerializedApiError(ApiErrorCode.ACCOUNT_ERROR.getHttpCode(),
"The SAML response contains Issuer Entity ID that is different from the original SAML request",
@@ -298,17 +290,9 @@ public class SAML2LoginAPIAuthenticatorCmd extends BaseCmd implements APIAuthent
UserAccount userAccount = null;
List<UserAccountVO> possibleUserAccounts = _userAccountDao.getAllUsersByNameAndEntity(username, issuer.getValue());
if (possibleUserAccounts != null && possibleUserAccounts.size() > 0) {
- if (possibleUserAccounts.size() == 1) {
- userAccount = possibleUserAccounts.get(0);
- } else if (possibleUserAccounts.size() > 1) {
- if (domainId != null) {
- userAccount = _userAccountDao.getUserAccount(username, domainId);
- } else {
- throw new ServerApiException(ApiErrorCode.ACCOUNT_ERROR, _apiServer.getSerializedApiError(ApiErrorCode.ACCOUNT_ERROR.getHttpCode(),
- "You have accounts in multiple domains, please re-login by specifying the domain you want to log into.",
- params, responseType));
- }
- }
+ // By default, log into the first user account
+ // Users can switch to other allowed accounts later
+ userAccount = possibleUserAccounts.get(0);
}
if (userAccount == null || userAccount.getExternalEntity() == null || !_samlAuthManager.isUserAuthorized(userAccount.getId(), issuer.getValue())) {
@@ -322,21 +306,11 @@ public class SAML2LoginAPIAuthenticatorCmd extends BaseCmd implements APIAuthent
if (_apiServer.verifyUser(userAccount.getId())) {
LoginCmdResponse loginResponse = (LoginCmdResponse) _apiServer.loginUser(session, userAccount.getUsername(), userAccount.getUsername() + userAccount.getSource().toString(),
userAccount.getDomainId(), null, remoteAddress, params);
- resp.addCookie(new Cookie("userid", URLEncoder.encode(loginResponse.getUserId(), HttpUtils.UTF_8)));
- resp.addCookie(new Cookie("domainid", URLEncoder.encode(loginResponse.getDomainId(), HttpUtils.UTF_8)));
- resp.addCookie(new Cookie("role", URLEncoder.encode(loginResponse.getType(), HttpUtils.UTF_8)));
- resp.addCookie(new Cookie("username", URLEncoder.encode(loginResponse.getUsername(), HttpUtils.UTF_8)));
- resp.addCookie(new Cookie("account", URLEncoder.encode(loginResponse.getAccount(), HttpUtils.UTF_8)));
- String timezone = loginResponse.getTimeZone();
- if (timezone != null) {
- resp.addCookie(new Cookie("timezone", URLEncoder.encode(timezone, HttpUtils.UTF_8)));
- }
- resp.addCookie(new Cookie("userfullname", URLEncoder.encode(loginResponse.getFirstName() + " " + loginResponse.getLastName(), HttpUtils.UTF_8).replace("+", "%20")));
- resp.addHeader("SET-COOKIE", String.format("%s=%s;HttpOnly", ApiConstants.SESSIONKEY, loginResponse.getSessionKey()));
+ SAMLUtils.setupSamlUserCookies(loginResponse, resp);
resp.sendRedirect(SAML2AuthManager.SAMLCloudStackRedirectionUrl.value());
return ApiResponseSerializer.toSerializedString(loginResponse, responseType);
}
- } catch (final CloudAuthenticationException ignored) {
+ } catch (final Exception ignored) {
}
}
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/8c514491/plugins/user-authenticators/saml2/src/org/apache/cloudstack/api/response/SamlUserAccountResponse.java
----------------------------------------------------------------------
diff --git a/plugins/user-authenticators/saml2/src/org/apache/cloudstack/api/response/SamlUserAccountResponse.java b/plugins/user-authenticators/saml2/src/org/apache/cloudstack/api/response/SamlUserAccountResponse.java
new file mode 100644
index 0000000..f0927e3
--- /dev/null
+++ b/plugins/user-authenticators/saml2/src/org/apache/cloudstack/api/response/SamlUserAccountResponse.java
@@ -0,0 +1,99 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package org.apache.cloudstack.api.response;
+
+import com.cloud.serializer.Param;
+import com.google.gson.annotations.SerializedName;
+
+public class SamlUserAccountResponse extends AuthenticationCmdResponse {
+ @SerializedName("userId")
+ @Param(description = "The User Id")
+ private String userId;
+
+ @SerializedName("domainId")
+ @Param(description = "The Domain Id")
+ private String domainId;
+
+ @SerializedName("userName")
+ @Param(description = "The User Name")
+ private String userName;
+
+ @SerializedName("accountName")
+ @Param(description = "The Account Name")
+ private String accountName;
+
+ @SerializedName("domainName")
+ @Param(description = "The Domain Name")
+ private String domainName;
+
+ @SerializedName("idpId")
+ @Param(description = "The IDP ID")
+ private String idpId;
+
+ public SamlUserAccountResponse() {
+ super();
+ setObjectName("samluseraccount");
+ }
+
+ public String getUserId() {
+ return userId;
+ }
+
+ public void setUserId(String userId) {
+ this.userId = userId;
+ }
+
+ public String getDomainId() {
+ return domainId;
+ }
+
+ public void setDomainId(String domainId) {
+ this.domainId = domainId;
+ }
+
+ public String getUserName() {
+ return userName;
+ }
+
+ public void setUserName(String userName) {
+ this.userName = userName;
+ }
+
+ public String getAccountName() {
+ return accountName;
+ }
+
+ public void setAccountName(String accountName) {
+ this.accountName = accountName;
+ }
+
+ public String getDomainName() {
+ return domainName;
+ }
+
+ public void setDomainName(String domainName) {
+ this.domainName = domainName;
+ }
+
+ public String getIdpId() {
+ return idpId;
+ }
+
+ public void setIdpId(String idpId) {
+ this.idpId = idpId;
+ }
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/8c514491/plugins/user-authenticators/saml2/src/org/apache/cloudstack/saml/SAML2AuthManagerImpl.java
----------------------------------------------------------------------
diff --git a/plugins/user-authenticators/saml2/src/org/apache/cloudstack/saml/SAML2AuthManagerImpl.java b/plugins/user-authenticators/saml2/src/org/apache/cloudstack/saml/SAML2AuthManagerImpl.java
index 7232ac9..46b1c40 100644
--- a/plugins/user-authenticators/saml2/src/org/apache/cloudstack/saml/SAML2AuthManagerImpl.java
+++ b/plugins/user-authenticators/saml2/src/org/apache/cloudstack/saml/SAML2AuthManagerImpl.java
@@ -26,6 +26,7 @@ import com.cloud.utils.component.AdapterBase;
import org.apache.cloudstack.api.auth.PluggableAPIAuthenticator;
import org.apache.cloudstack.api.command.AuthorizeSAMLSSOCmd;
import org.apache.cloudstack.api.command.GetServiceProviderMetaDataCmd;
+import org.apache.cloudstack.api.command.ListAndSwitchSAMLAccountCmd;
import org.apache.cloudstack.api.command.ListIdpsCmd;
import org.apache.cloudstack.api.command.ListSamlAuthorizationCmd;
import org.apache.cloudstack.api.command.SAML2LoginAPIAuthenticatorCmd;
@@ -491,6 +492,7 @@ public class SAML2AuthManagerImpl extends AdapterBase implements SAML2AuthManage
cmdList.add(SAML2LogoutAPIAuthenticatorCmd.class);
cmdList.add(GetServiceProviderMetaDataCmd.class);
cmdList.add(ListIdpsCmd.class);
+ cmdList.add(ListAndSwitchSAMLAccountCmd.class);
return cmdList;
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/8c514491/plugins/user-authenticators/saml2/src/org/apache/cloudstack/saml/SAML2UserAuthenticator.java
----------------------------------------------------------------------
diff --git a/plugins/user-authenticators/saml2/src/org/apache/cloudstack/saml/SAML2UserAuthenticator.java b/plugins/user-authenticators/saml2/src/org/apache/cloudstack/saml/SAML2UserAuthenticator.java
index 5c8a390..65a7959 100644
--- a/plugins/user-authenticators/saml2/src/org/apache/cloudstack/saml/SAML2UserAuthenticator.java
+++ b/plugins/user-authenticators/saml2/src/org/apache/cloudstack/saml/SAML2UserAuthenticator.java
@@ -23,18 +23,9 @@ import com.cloud.user.dao.UserDao;
import com.cloud.utils.Pair;
import org.apache.cxf.common.util.StringUtils;
import org.apache.log4j.Logger;
-import org.opensaml.DefaultBootstrap;
-import org.opensaml.saml2.core.Response;
-import org.opensaml.saml2.core.StatusCode;
-import org.opensaml.xml.ConfigurationException;
-import org.opensaml.xml.io.UnmarshallingException;
-import org.xml.sax.SAXException;
import javax.ejb.Local;
import javax.inject.Inject;
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.stream.FactoryConfigurationError;
-import java.io.IOException;
import java.util.Map;
@Local(value = {UserAuthenticator.class})
@@ -63,18 +54,7 @@ public class SAML2UserAuthenticator extends DefaultUserAuthenticator {
return new Pair<Boolean, ActionOnFailedAuthentication>(false, null);
} else {
User user = _userDao.getUser(userAccount.getId());
- if (user != null && requestParameters != null && requestParameters.containsKey(SAMLPluginConstants.SAML_RESPONSE)) {
- final String samlResponse = ((String[])requestParameters.get(SAMLPluginConstants.SAML_RESPONSE))[0];
- Response responseObject = null;
- try {
- DefaultBootstrap.bootstrap();
- responseObject = SAMLUtils.decodeSAMLResponse(samlResponse);
- } catch (ConfigurationException | FactoryConfigurationError | ParserConfigurationException | SAXException | IOException | UnmarshallingException e) {
- return new Pair<Boolean, ActionOnFailedAuthentication>(false, null);
- }
- if (!responseObject.getStatus().getStatusCode().getValue().equals(StatusCode.SUCCESS_URI)) {
- return new Pair<Boolean, ActionOnFailedAuthentication>(false, null);
- }
+ if (user != null && user.getSource() == User.Source.SAML2 && user.getExternalEntity() != null) {
return new Pair<Boolean, ActionOnFailedAuthentication>(true, null);
}
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/8c514491/plugins/user-authenticators/saml2/src/org/apache/cloudstack/saml/SAMLUtils.java
----------------------------------------------------------------------
diff --git a/plugins/user-authenticators/saml2/src/org/apache/cloudstack/saml/SAMLUtils.java b/plugins/user-authenticators/saml2/src/org/apache/cloudstack/saml/SAMLUtils.java
index 0216ad7..fb2d960 100644
--- a/plugins/user-authenticators/saml2/src/org/apache/cloudstack/saml/SAMLUtils.java
+++ b/plugins/user-authenticators/saml2/src/org/apache/cloudstack/saml/SAMLUtils.java
@@ -20,6 +20,8 @@
package org.apache.cloudstack.saml;
import com.cloud.utils.HttpUtils;
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.response.LoginCmdResponse;
import org.apache.log4j.Logger;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.bouncycastle.x509.X509V1CertificateGenerator;
@@ -62,6 +64,8 @@ import org.w3c.dom.Element;
import org.xml.sax.SAXException;
import javax.security.auth.x500.X500Principal;
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServletResponse;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
@@ -351,4 +355,18 @@ public class SAMLUtils {
return certGen.generate(keyPair.getPrivate(), "BC");
}
+ public static void setupSamlUserCookies(final LoginCmdResponse loginResponse, final HttpServletResponse resp) throws IOException {
+ resp.addCookie(new Cookie("userid", URLEncoder.encode(loginResponse.getUserId(), HttpUtils.UTF_8)));
+ resp.addCookie(new Cookie("domainid", URLEncoder.encode(loginResponse.getDomainId(), HttpUtils.UTF_8)));
+ resp.addCookie(new Cookie("role", URLEncoder.encode(loginResponse.getType(), HttpUtils.UTF_8)));
+ resp.addCookie(new Cookie("username", URLEncoder.encode(loginResponse.getUsername(), HttpUtils.UTF_8)));
+ resp.addCookie(new Cookie("account", URLEncoder.encode(loginResponse.getAccount(), HttpUtils.UTF_8)));
+ String timezone = loginResponse.getTimeZone();
+ if (timezone != null) {
+ resp.addCookie(new Cookie("timezone", URLEncoder.encode(timezone, HttpUtils.UTF_8)));
+ }
+ resp.addCookie(new Cookie("userfullname", URLEncoder.encode(loginResponse.getFirstName() + " " + loginResponse.getLastName(), HttpUtils.UTF_8).replace("+", "%20")));
+ resp.addHeader("SET-COOKIE", String.format("%s=%s;HttpOnly", ApiConstants.SESSIONKEY, loginResponse.getSessionKey()));
+ }
+
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/8c514491/ui/index.jsp
----------------------------------------------------------------------
diff --git a/ui/index.jsp b/ui/index.jsp
index c3bae19..3b7d310 100644
--- a/ui/index.jsp
+++ b/ui/index.jsp
@@ -75,13 +75,6 @@
</div>
</div>
- <div id="saml-login">
- <div class="field domain">
- <label for="saml-domain"><fmt:message key="label.domain"/></label>
- <input id="saml-domain" type="text" name="saml-domain" />
- </div>
- </div>
-
<div id="login-submit">
<!-- Submit (login) -->
<input id="login-submit" type="submit" value="<fmt:message key="label.login"/>" />
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/8c514491/ui/scripts/ui-custom/login.js
----------------------------------------------------------------------
diff --git a/ui/scripts/ui-custom/login.js b/ui/scripts/ui-custom/login.js
index e112958..5825529 100644
--- a/ui/scripts/ui-custom/login.js
+++ b/ui/scripts/ui-custom/login.js
@@ -122,8 +122,7 @@
} else if (selectedLogin === 'saml') {
// SAML
args.samlLoginAction({
- data: {'idpid': $login.find('#login-options').find(':selected').val(),
- 'domain': $login.find('#saml-domain').val()}
+ data: {'idpid': $login.find('#login-options').find(':selected').val()}
});
}
return false;
@@ -133,16 +132,13 @@
var toggleLoginView = function (selectedOption) {
$login.find('#login-submit').show();
if (selectedOption === '') {
- $login.find('#saml-login').hide();
$login.find('#cloudstack-login').hide();
$login.find('#login-submit').hide();
selectedLogin = 'none';
} else if (selectedOption === 'cloudstack-login') {
- $login.find('#saml-login').hide();
$login.find('#cloudstack-login').show();
selectedLogin = 'cloudstack';
} else {
- $login.find('#saml-login').show();
$login.find('#cloudstack-login').hide();
selectedLogin = 'saml';
}
@@ -160,14 +156,12 @@
$login.find('#login-dropdown').hide();
$login.find('#login-submit').show();
$login.find('#cloudstack-login').show();
- $login.find('#saml-login').hide();
// If any IdP servers were set, SAML is enabled
if (g_idpList && g_idpList.length > 0) {
$login.find('#login-dropdown').show();
$login.find('#login-submit').hide();
$login.find('#cloudstack-login').hide();
- $login.find('#saml-login').hide();
$login.find('#login-options')
.append($('<option>', {
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/8c514491/ui/scripts/ui/core.js
----------------------------------------------------------------------
diff --git a/ui/scripts/ui/core.js b/ui/scripts/ui/core.js
index e64f386..26a5a1c 100644
--- a/ui/scripts/ui/core.js
+++ b/ui/scripts/ui/core.js
@@ -304,6 +304,83 @@
})
.appendTo($('#user'));
+ // Switch account option for SAML users
+ if (g_idpList) {
+ $.ajax({
+ url: createURL('listAndSwitchSamlAccount'),
+ success: function(json) {
+ var accounts = json.listandswitchsamlaccountresponse.samluseraccount;
+ if (accounts.length < 2) {
+ return
+ };
+ var switchAccount = function() {
+ var toReload = true;
+ $.ajax({
+ url: createURL('listAndSwitchSamlAccount'),
+ type: 'POST',
+ async: false,
+ data: {
+ userid: $(this).data("userId"),
+ domainid: $(this).data("domainId")
+ },
+ success: function(data, textStatus) {
+ document.location.reload(true);
+ },
+ error: function(data) {
+ cloudStack.dialog.notice({
+ message: parseXMLHttpResponse(data)
+ });
+ if (data.status !== 200) {
+ toReload = false;
+ }
+ },
+ complete: function() {
+ if (toReload) {
+ document.location.reload(true);
+ }
+ toReload = true;
+ }
+ });
+ };
+
+ $('<a>').attr({
+ href: '#'
+ })
+ .text('Switch Account')
+ .appendTo($options).click(function() {
+ var $switchSamlAccount = $('<div>');
+ for (var i = 0; i < accounts.length; i++) {
+ var item = $('<a>').html(accounts[i].accountName + "/" + accounts[i].domainName);
+ item.data("userId", accounts[i].userId);
+ item.data("domainId", accounts[i].domainId);
+ item.click(switchAccount);
+ item.appendTo($switchSamlAccount);
+ item.attr("href", "#");
+ $('<br>').appendTo($switchSamlAccount);
+ }
+ $switchSamlAccount.dialog({
+ modal: true,
+ width: 400,
+ title: 'Switch Account',
+ closeOnEscape: false,
+ dialogClass: 'dialog-about',
+ buttons: {
+ 'Close': function() {
+ $(this).dialog("close");
+ $(':ui-dialog, .overlay').remove();
+ }
+ }
+ }).closest('.ui-dialog').overlay();
+
+ return false;
+ });
+ },
+ error: function(data) {
+ }
+ });
+ }
+
+
$(['label.logout', 'label.help', 'label.about']).each(function() {
var $link = $('<a>')
.attr({
[2/7] git commit: updated refs/heads/4.5-samlfixes to 69f39d5
Posted by bh...@apache.org.
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/17366f2b/ui/scripts/zoneWizard.js
----------------------------------------------------------------------
diff --git a/ui/scripts/zoneWizard.js b/ui/scripts/zoneWizard.js
index 700904d..5f898af 100755
--- a/ui/scripts/zoneWizard.js
+++ b/ui/scripts/zoneWizard.js
@@ -379,7 +379,10 @@
},
addPrimaryStorage: function(args) {
- return args.data.localstorageenabled != 'on';
+ if(args.data.localstorageenabled == 'on' && args.data.localstorageenabledforsystemvm == 'on') {
+ return false; //skip step only when both localstorage and localstorage for system vm are checked
+ }
+ return true;
}
},
@@ -665,23 +668,13 @@
label: 'label.local.storage.enabled',
isBoolean: true,
onChange: function(args) {
- var $checkbox = args.$checkbox;
-
- if ($checkbox.is(':checked')) {
- cloudStack.dialog.confirm({
- message: 'message.zoneWizard.enable.local.storage',
- action: function() {
- $checkbox.attr('checked', true);
- },
- cancelAction: function() {
- $checkbox.attr('checked', false);
- }
- });
-
- return false;
- }
+ }
+ },
- return true;
+ localstorageenabledforsystemvm: {
+ label: 'label.local.storage.enabled.system.vms',
+ isBoolean: true,
+ onChange: function(args) {
}
}
}
@@ -2242,9 +2235,9 @@
}
},
- action: function(args) {
- var $wizard = args.wizard;
-
+ action: function(args) {
+ var $wizard = args.wizard;
+ var formData = args.data;
var advZoneConfiguredVirtualRouterCount = 0; //for multiple physical networks in advanced zone. Each physical network has 2 virtual routers: regular one and VPC one.
var success = args.response.success;
@@ -4419,29 +4412,50 @@
});
}
- $.ajax({
- url: createURL("addHost"),
- type: "POST",
- data: data,
- success: function(json) {
- stepFns.addPrimaryStorage({
- data: $.extend(args.data, {
- returnedHost: json.addhostresponse.host[0]
- })
- });
- },
- error: function(XMLHttpResponse) {
- var errorMsg = parseXMLHttpResponse(XMLHttpResponse);
- error('addHost', errorMsg, {
- fn: 'addHost',
- args: args
- });
- }
- });
+ var addHostAjax = function() {
+ $.ajax({
+ url: createURL("addHost"),
+ type: "POST",
+ data: data,
+ success: function(json) {
+ stepFns.addPrimaryStorage({
+ data: $.extend(args.data, {
+ returnedHost: json.addhostresponse.host[0]
+ })
+ });
+ },
+ error: function(XMLHttpResponse) {
+ var errorMsg = parseXMLHttpResponse(XMLHttpResponse);
+ error('addHost', errorMsg, {
+ fn: 'addHost',
+ args: args
+ });
+ }
+ });
+ };
+
+ if(args.data.zone.localstorageenabledforsystemvm == 'on') {
+ $.ajax({
+ url: createURL("updateConfiguration&name=system.vm.use.local.storage&value=true&zoneid=" + args.data.returnedZone.id),
+ dataType: "json",
+ success: function(json) {
+ addHostAjax();
+ },
+ error: function(XMLHttpResponse) {
+ var errorMsg = parseXMLHttpResponse(XMLHttpResponse);
+ error('addHost', errorMsg, {
+ fn: 'addHost',
+ args: args
+ });
+ }
+ });
+ } else {
+ addHostAjax();
+ }
},
addPrimaryStorage: function(args) {
- if (args.data.zone.localstorageenabled == 'on') { //use local storage, don't need primary storage. So, skip this step.
+ if (args.data.zone.localstorageenabled == 'on' && args.data.zone.localstorageenabledforsystemvm == 'on') { //use local storage, don't need primary storage. So, skip
stepFns.addSecondaryStorage({
data: args.data
});
[3/7] git commit: updated refs/heads/4.5-samlfixes to 69f39d5
Posted by bh...@apache.org.
CLOUDSTACK-8301: Enable configuring local storage use for system VMs at zone level
Backported from #263 for 4.5 branch, original bugfix by @koushik-das et al
More information on:
https://issues.apache.org/jira/browse/CLOUDSTACK-8301
https://cwiki.apache.org/confluence/display/CLOUDSTACK/Enable+configuring+local+storage+use+for+system+VMs+at+zone+level
Signed-off-by: Rohit Yadav <ro...@shapeblue.com>
This closes #661
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/17366f2b
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/17366f2b
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/17366f2b
Branch: refs/heads/4.5-samlfixes
Commit: 17366f2b182aaa0943be451c79dac36fc08e221b
Parents: 58c6a8d
Author: Rohit Yadav <ro...@shapeblue.com>
Authored: Thu Aug 6 12:13:01 2015 +0530
Committer: Rohit Yadav <ro...@shapeblue.com>
Committed: Sat Aug 8 22:41:52 2015 +0530
----------------------------------------------------------------------
api/src/com/cloud/dc/DataCenter.java | 4 -
.../classes/resources/messages.properties | 3 +-
.../cloud/service/dao/ServiceOfferingDao.java | 14 +-
.../service/dao/ServiceOfferingDaoImpl.java | 53 ++
.../lb/ElasticLoadBalancerManagerImpl.java | 20 +-
.../network/lb/LoadBalanceRuleHandler.java | 16 +-
.../lb/InternalLoadBalancerVMManagerImpl.java | 24 +-
.../InternalLBVMManagerTest.java | 7 +-
.../InternalLBVMServiceTest.java | 9 +-
server/src/com/cloud/configuration/Config.java | 1 -
.../configuration/ConfigurationManagerImpl.java | 45 +-
.../consoleproxy/ConsoleProxyManagerImpl.java | 39 +-
.../deploy/DeploymentPlanningManagerImpl.java | 35 +-
.../VirtualNetworkApplianceManagerImpl.java | 15 +-
.../VpcVirtualNetworkApplianceManagerImpl.java | 7 +-
.../com/cloud/storage/StorageManagerImpl.java | 14 +-
.../element/VirtualRouterElementTest.java | 3 +
.../SecondaryStorageManagerImpl.java | 35 +-
.../test_zone_level_local_storage_setting.py | 734 +++++++++++++++++++
ui/dictionary2.jsp | 3 +-
ui/scripts/zoneWizard.js | 94 ++-
21 files changed, 998 insertions(+), 177 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/17366f2b/api/src/com/cloud/dc/DataCenter.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/dc/DataCenter.java b/api/src/com/cloud/dc/DataCenter.java
index 6cd054e..5b3d3c0 100644
--- a/api/src/com/cloud/dc/DataCenter.java
+++ b/api/src/com/cloud/dc/DataCenter.java
@@ -20,7 +20,6 @@ import com.cloud.org.Grouping;
import org.apache.cloudstack.acl.InfrastructureEntity;
import org.apache.cloudstack.api.Identity;
import org.apache.cloudstack.api.InternalIdentity;
-import org.apache.cloudstack.framework.config.ConfigKey;
import java.util.Map;
@@ -28,9 +27,6 @@ import java.util.Map;
*
*/
public interface DataCenter extends InfrastructureEntity, Grouping, Identity, InternalIdentity {
- public static final String SystemVMUseLocalStorageCK = "system.vm.use.local.storage";
- public static final ConfigKey<Boolean> UseSystemVMLocalStorage = new ConfigKey<Boolean>(Boolean.class, SystemVMUseLocalStorageCK, "Advanced", "false",
- "Indicates whether to use local storage pools or shared storage pools for system VMs.", true, ConfigKey.Scope.Zone, null);
public enum NetworkType {
Basic, Advanced,
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/17366f2b/client/WEB-INF/classes/resources/messages.properties
----------------------------------------------------------------------
diff --git a/client/WEB-INF/classes/resources/messages.properties b/client/WEB-INF/classes/resources/messages.properties
index 7223552..f5e0588 100644
--- a/client/WEB-INF/classes/resources/messages.properties
+++ b/client/WEB-INF/classes/resources/messages.properties
@@ -753,7 +753,8 @@ label.load.balancer=Load Balancer
label.load.balancing.policies=Load balancing policies
label.load.balancing=Load Balancing
label.loading=Loading
-label.local.storage.enabled=Local storage enabled
+label.local.storage.enabled=Enable local storage for User VMs
+label.local.storage.enabled.system.vms=Enable local storage for System VMs
label.local.storage=Local Storage
label.local=Local
label.login=Login
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/17366f2b/engine/schema/src/com/cloud/service/dao/ServiceOfferingDao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/service/dao/ServiceOfferingDao.java b/engine/schema/src/com/cloud/service/dao/ServiceOfferingDao.java
index ab81853..586fcd0 100644
--- a/engine/schema/src/com/cloud/service/dao/ServiceOfferingDao.java
+++ b/engine/schema/src/com/cloud/service/dao/ServiceOfferingDao.java
@@ -16,11 +16,13 @@
// under the License.
package com.cloud.service.dao;
-import java.util.List;
-import java.util.Map;
-
import com.cloud.service.ServiceOfferingVO;
+import com.cloud.storage.Storage;
import com.cloud.utils.db.GenericDao;
+import com.cloud.vm.VirtualMachine;
+
+import java.util.List;
+import java.util.Map;
/*
* Data Access Object for service_offering table
@@ -28,6 +30,10 @@ import com.cloud.utils.db.GenericDao;
public interface ServiceOfferingDao extends GenericDao<ServiceOfferingVO, Long> {
ServiceOfferingVO findByName(String name);
+ List<ServiceOfferingVO> createSystemServiceOfferings(String name, String uniqueName, int cpuCount, int ramSize, int cpuSpeed,
+ Integer rateMbps, Integer multicastRateMbps, boolean offerHA, String displayText, Storage.ProvisioningType provisioningType,
+ boolean recreatable, String tags, boolean systemUse, VirtualMachine.Type vmType, boolean defaultUse);
+
ServiceOfferingVO persistSystemServiceOffering(ServiceOfferingVO vo);
List<ServiceOfferingVO> findPublicServiceOfferings();
@@ -49,4 +55,6 @@ public interface ServiceOfferingDao extends GenericDao<ServiceOfferingVO, Long>
boolean isDynamic(long serviceOfferingId);
ServiceOfferingVO getcomputeOffering(ServiceOfferingVO serviceOffering, Map<String, String> customParameters);
+
+ ServiceOfferingVO findDefaultSystemOffering(String offeringName, Boolean useLocalStorage);
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/17366f2b/engine/schema/src/com/cloud/service/dao/ServiceOfferingDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/service/dao/ServiceOfferingDaoImpl.java b/engine/schema/src/com/cloud/service/dao/ServiceOfferingDaoImpl.java
index a3ff45c..280a4ba 100644
--- a/engine/schema/src/com/cloud/service/dao/ServiceOfferingDaoImpl.java
+++ b/engine/schema/src/com/cloud/service/dao/ServiceOfferingDaoImpl.java
@@ -25,6 +25,8 @@ import javax.ejb.Local;
import javax.inject.Inject;
import javax.persistence.EntityExistsException;
+import com.cloud.storage.Storage;
+import com.cloud.vm.VirtualMachine;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
@@ -110,6 +112,13 @@ public class ServiceOfferingDaoImpl extends GenericDaoBase<ServiceOfferingVO, Lo
vo.setSpeed(500);
update(vo.getId(), vo);
}
+ if (!vo.getUniqueName().endsWith("-Local")) {
+ if (vo.getUseLocalStorage()) {
+ vo.setUniqueName(vo.getUniqueName() + "-Local");
+ vo.setName(vo.getName() + " - Local Storage");
+ update(vo.getId(), vo);
+ }
+ }
return vo;
}
try {
@@ -238,4 +247,48 @@ public class ServiceOfferingDaoImpl extends GenericDaoBase<ServiceOfferingVO, Lo
return dummyoffering;
}
+
+ @Override
+ public List<ServiceOfferingVO> createSystemServiceOfferings(String name, String uniqueName, int cpuCount, int ramSize, int cpuSpeed,
+ Integer rateMbps, Integer multicastRateMbps, boolean offerHA, String displayText, Storage.ProvisioningType provisioningType,
+ boolean recreatable, String tags, boolean systemUse, VirtualMachine.Type vmType, boolean defaultUse) {
+ List<ServiceOfferingVO> list = new ArrayList<ServiceOfferingVO>();
+ ServiceOfferingVO offering = new ServiceOfferingVO(name, cpuCount, ramSize, cpuSpeed, rateMbps, multicastRateMbps, offerHA, displayText,
+ provisioningType, false, recreatable, tags, systemUse, vmType, defaultUse);
+ offering.setUniqueName(uniqueName);
+ offering = persistSystemServiceOffering(offering);
+ if (offering != null) {
+ list.add(offering);
+ }
+
+ boolean useLocal = true;
+ if (offering.getUseLocalStorage()) { // if 1st one is already local then 2nd needs to be shared
+ useLocal = false;
+ }
+
+ offering = new ServiceOfferingVO(name + (useLocal ? " - Local Storage" : ""), cpuCount, ramSize, cpuSpeed, rateMbps, multicastRateMbps, offerHA, displayText,
+ provisioningType, useLocal, recreatable, tags, systemUse, vmType, defaultUse);
+ offering.setUniqueName(uniqueName + (useLocal ? "-Local" : ""));
+ offering = persistSystemServiceOffering(offering);
+ if (offering != null) {
+ list.add(offering);
+ }
+
+ return list;
+ }
+
+ @Override
+ public ServiceOfferingVO findDefaultSystemOffering(String offeringName, Boolean useLocalStorage) {
+ String name = offeringName;
+ if (useLocalStorage != null && useLocalStorage.booleanValue()) {
+ name += "-Local";
+ }
+ ServiceOfferingVO serviceOffering = findByName(name);
+ if (serviceOffering == null) {
+ String message = "System service offering " + name + " not found";
+ s_logger.error(message);
+ throw new CloudRuntimeException(message);
+ }
+ return serviceOffering;
+ }
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/17366f2b/plugins/network-elements/elastic-loadbalancer/src/com/cloud/network/lb/ElasticLoadBalancerManagerImpl.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/elastic-loadbalancer/src/com/cloud/network/lb/ElasticLoadBalancerManagerImpl.java b/plugins/network-elements/elastic-loadbalancer/src/com/cloud/network/lb/ElasticLoadBalancerManagerImpl.java
index d853299..11da736 100644
--- a/plugins/network-elements/elastic-loadbalancer/src/com/cloud/network/lb/ElasticLoadBalancerManagerImpl.java
+++ b/plugins/network-elements/elastic-loadbalancer/src/com/cloud/network/lb/ElasticLoadBalancerManagerImpl.java
@@ -148,7 +148,6 @@ public class ElasticLoadBalancerManagerImpl extends ManagerBase implements Elast
TrafficType _frontendTrafficType = TrafficType.Guest;
Account _systemAcct;
- ServiceOfferingVO _elasticLbVmOffering;
ScheduledExecutorService _gcThreadPool;
String _mgmtCidr;
@@ -290,16 +289,19 @@ public class ElasticLoadBalancerManagerImpl extends ManagerBase implements Elast
}
_mgmtCidr = _configDao.getValue(Config.ManagementNetwork.key());
- boolean useLocalStorage = Boolean.parseBoolean(configs.get(DataCenter.SystemVMUseLocalStorageCK));
-
_elasticLbVmRamSize = NumbersUtil.parseInt(configs.get(Config.ElasticLoadBalancerVmMemory.key()), DEFAULT_ELB_VM_RAMSIZE);
_elasticLbvmCpuMHz = NumbersUtil.parseInt(configs.get(Config.ElasticLoadBalancerVmCpuMhz.key()), DEFAULT_ELB_VM_CPU_MHZ);
_elasticLbvmNumCpu = NumbersUtil.parseInt(configs.get(Config.ElasticLoadBalancerVmNumVcpu.key()), 1);
- _elasticLbVmOffering = new ServiceOfferingVO("System Offering For Elastic LB VM", _elasticLbvmNumCpu,
- _elasticLbVmRamSize, _elasticLbvmCpuMHz, 0, 0, true, null, Storage.ProvisioningType.THIN, useLocalStorage,
- true, null, true, VirtualMachine.Type.ElasticLoadBalancerVm, true);
- _elasticLbVmOffering.setUniqueName(ServiceOffering.elbVmDefaultOffUniqueName);
- _elasticLbVmOffering = _serviceOfferingDao.persistSystemServiceOffering(_elasticLbVmOffering);
+
+ List<ServiceOfferingVO> offerings = _serviceOfferingDao.createSystemServiceOfferings("System Offering For Elastic LB VM",
+ ServiceOffering.elbVmDefaultOffUniqueName, _elasticLbvmNumCpu, _elasticLbVmRamSize, _elasticLbvmCpuMHz, 0, 0, true, null,
+ Storage.ProvisioningType.THIN, true, null, true, VirtualMachine.Type.ElasticLoadBalancerVm, true);
+ // this can sometimes happen, if DB is manually or programmatically manipulated
+ if (offerings == null || offerings.size() < 2) {
+ String msg = "Data integrity problem : System Offering For Elastic LB VM has been removed?";
+ s_logger.error(msg);
+ throw new ConfigurationException(msg);
+ }
String enabled = _configDao.getValue(Config.ElasticLoadBalancerEnabled.key());
_enabled = (enabled == null) ? false : Boolean.parseBoolean(enabled);
@@ -322,7 +324,7 @@ public class ElasticLoadBalancerManagerImpl extends ManagerBase implements Elast
_itMgr.registerGuru(VirtualMachine.Type.ElasticLoadBalancerVm, this);
}
- loadBalanceRuleHandler = new LoadBalanceRuleHandler(_elasticLbVmOffering, _instance, _systemAcct);
+ loadBalanceRuleHandler = new LoadBalanceRuleHandler(_instance, _systemAcct);
return true;
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/17366f2b/plugins/network-elements/elastic-loadbalancer/src/com/cloud/network/lb/LoadBalanceRuleHandler.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/elastic-loadbalancer/src/com/cloud/network/lb/LoadBalanceRuleHandler.java b/plugins/network-elements/elastic-loadbalancer/src/com/cloud/network/lb/LoadBalanceRuleHandler.java
index 32292cd..848b91a 100644
--- a/plugins/network-elements/elastic-loadbalancer/src/com/cloud/network/lb/LoadBalanceRuleHandler.java
+++ b/plugins/network-elements/elastic-loadbalancer/src/com/cloud/network/lb/LoadBalanceRuleHandler.java
@@ -27,6 +27,9 @@ import java.util.Random;
import javax.inject.Inject;
+import com.cloud.configuration.ConfigurationManagerImpl;
+import com.cloud.offering.ServiceOffering;
+import com.cloud.service.dao.ServiceOfferingDao;
import org.apache.cloudstack.api.command.user.loadbalancer.CreateLoadBalancerRuleCmd;
import org.apache.cloudstack.context.CallContext;
import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService;
@@ -140,15 +143,15 @@ public class LoadBalanceRuleHandler {
private PhysicalNetworkServiceProviderDao _physicalProviderDao;
@Inject
private VirtualRouterProviderDao _vrProviderDao;
+ @Inject
+ private ServiceOfferingDao _serviceOfferingDao;
static final private String ELB_VM_NAME_PREFIX = "l";
- private final ServiceOfferingVO _elasticLbVmOffering;
private final String _instance;
private final Account _systemAcct;
- public LoadBalanceRuleHandler(ServiceOfferingVO elasticLbVmOffering, String instance, Account systemAcct) {
- this._elasticLbVmOffering = elasticLbVmOffering;
+ public LoadBalanceRuleHandler(String instance, Account systemAcct) {
this._instance = instance;
this._systemAcct = systemAcct;
}
@@ -272,12 +275,13 @@ public class LoadBalanceRuleHandler {
throw new CloudRuntimeException("Cannot find virtual router provider " + typeString + " as service provider " + provider.getId());
}
- elbVm = new DomainRouterVO(id, _elasticLbVmOffering.getId(), vrProvider.getId(), VirtualMachineName.getSystemVmName(id, _instance, ELB_VM_NAME_PREFIX),
+ ServiceOfferingVO elasticLbVmOffering = _serviceOfferingDao.findDefaultSystemOffering(ServiceOffering.elbVmDefaultOffUniqueName, ConfigurationManagerImpl.SystemVMUseLocalStorage.valueIn(dest.getDataCenter().getId()));
+ elbVm = new DomainRouterVO(id, elasticLbVmOffering.getId(), vrProvider.getId(), VirtualMachineName.getSystemVmName(id, _instance, ELB_VM_NAME_PREFIX),
template.getId(), template.getHypervisorType(), template.getGuestOSId(), owner.getDomainId(), owner.getId(), false, 0, false, RedundantState.UNKNOWN,
- _elasticLbVmOffering.getOfferHA(), false, VirtualMachine.Type.ElasticLoadBalancerVm, null);
+ elasticLbVmOffering.getOfferHA(), false, VirtualMachine.Type.ElasticLoadBalancerVm, null);
elbVm.setRole(Role.LB);
elbVm = _routerDao.persist(elbVm);
- _itMgr.allocate(elbVm.getInstanceName(), template, _elasticLbVmOffering, networks, plan, null);
+ _itMgr.allocate(elbVm.getInstanceName(), template, elasticLbVmOffering, networks, plan, null);
elbVm = _routerDao.findById(elbVm.getId());
//TODO: create usage stats
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/17366f2b/plugins/network-elements/internal-loadbalancer/src/org/apache/cloudstack/network/lb/InternalLoadBalancerVMManagerImpl.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/internal-loadbalancer/src/org/apache/cloudstack/network/lb/InternalLoadBalancerVMManagerImpl.java b/plugins/network-elements/internal-loadbalancer/src/org/apache/cloudstack/network/lb/InternalLoadBalancerVMManagerImpl.java
index cf77150..eee1f12 100644
--- a/plugins/network-elements/internal-loadbalancer/src/org/apache/cloudstack/network/lb/InternalLoadBalancerVMManagerImpl.java
+++ b/plugins/network-elements/internal-loadbalancer/src/org/apache/cloudstack/network/lb/InternalLoadBalancerVMManagerImpl.java
@@ -27,6 +27,7 @@ import javax.ejb.Local;
import javax.inject.Inject;
import javax.naming.ConfigurationException;
+import com.cloud.configuration.ConfigurationManagerImpl;
import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService;
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
import org.apache.cloudstack.lb.ApplicationLoadBalancerRuleVO;
@@ -376,15 +377,15 @@ public class InternalLoadBalancerVMManagerImpl extends ManagerBase implements In
//if offering wasn't set, try to get the default one
if (_internalLbVmOfferingId == 0L) {
- boolean useLocalStorage = Boolean.parseBoolean(configs.get(DataCenter.SystemVMUseLocalStorageCK));
- ServiceOfferingVO newOff =
- new ServiceOfferingVO("System Offering For Internal LB VM", 1, InternalLoadBalancerVMManager.DEFAULT_INTERNALLB_VM_RAMSIZE,
+ List<ServiceOfferingVO> offerings = _serviceOfferingDao.createSystemServiceOfferings("System Offering For Internal LB VM",
+ ServiceOffering.internalLbVmDefaultOffUniqueName, 1, InternalLoadBalancerVMManager.DEFAULT_INTERNALLB_VM_RAMSIZE,
InternalLoadBalancerVMManager.DEFAULT_INTERNALLB_VM_CPU_MHZ, null, null, true, null,
- Storage.ProvisioningType.THIN, useLocalStorage, true, null, true,
- VirtualMachine.Type.InternalLoadBalancerVm, true);
- newOff.setUniqueName(ServiceOffering.internalLbVmDefaultOffUniqueName);
- newOff = _serviceOfferingDao.persistSystemServiceOffering(newOff);
- _internalLbVmOfferingId = newOff.getId();
+ Storage.ProvisioningType.THIN, true, null, true, VirtualMachine.Type.InternalLoadBalancerVm, true);
+ if (offerings == null || offerings.size() < 2) {
+ String msg = "Data integrity problem : System Offering For Internal LB VM has been removed?";
+ s_logger.error(msg);
+ throw new ConfigurationException(msg);
+ }
}
_itMgr.registerGuru(VirtualMachine.Type.InternalLoadBalancerVm, this);
@@ -616,9 +617,14 @@ public class InternalLoadBalancerVMManagerImpl extends ManagerBase implements In
}
LinkedHashMap<Network, List<? extends NicProfile>> networks = createInternalLbVmNetworks(guestNetwork, plan, requestedGuestIp);
+ long internalLbVmOfferingId = _internalLbVmOfferingId;
+ if (internalLbVmOfferingId == 0L) {
+ ServiceOfferingVO serviceOffering = _serviceOfferingDao.findDefaultSystemOffering(ServiceOffering.internalLbVmDefaultOffUniqueName, ConfigurationManagerImpl.SystemVMUseLocalStorage.valueIn(dest.getDataCenter().getId()));
+ internalLbVmOfferingId = serviceOffering.getId();
+ }
//Pass startVm=false as we are holding the network lock that needs to be released at the end of vm allocation
DomainRouterVO internalLbVm =
- deployInternalLbVm(owner, dest, plan, params, internalLbProviderId, _internalLbVmOfferingId, guestNetwork.getVpcId(), networks, false);
+ deployInternalLbVm(owner, dest, plan, params, internalLbProviderId, internalLbVmOfferingId, guestNetwork.getVpcId(), networks, false);
if (internalLbVm != null) {
_internalLbVmDao.addRouterToGuestNetwork(internalLbVm, guestNetwork);
internalLbVms.add(internalLbVm);
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/17366f2b/plugins/network-elements/internal-loadbalancer/test/org/apache/cloudstack/internallbvmmgr/InternalLBVMManagerTest.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/internal-loadbalancer/test/org/apache/cloudstack/internallbvmmgr/InternalLBVMManagerTest.java b/plugins/network-elements/internal-loadbalancer/test/org/apache/cloudstack/internallbvmmgr/InternalLBVMManagerTest.java
index 375ba5e..5b5d65a 100644
--- a/plugins/network-elements/internal-loadbalancer/test/org/apache/cloudstack/internallbvmmgr/InternalLBVMManagerTest.java
+++ b/plugins/network-elements/internal-loadbalancer/test/org/apache/cloudstack/internallbvmmgr/InternalLBVMManagerTest.java
@@ -121,7 +121,12 @@ public class InternalLBVMManagerTest extends TestCase {
ServiceOfferingVO off = new ServiceOfferingVO("alena", 1, 1,
1, 1, 1, false, "alena", Storage.ProvisioningType.THIN, false, false, null, false, VirtualMachine.Type.InternalLoadBalancerVm, false);
off = setId(off, 1);
- Mockito.when(_svcOffDao.persistSystemServiceOffering(Matchers.any(ServiceOfferingVO.class))).thenReturn(off);
+ List<ServiceOfferingVO> list = new ArrayList<ServiceOfferingVO>();
+ list.add(off);
+ list.add(off);
+ Mockito.when(_svcOffDao.createSystemServiceOfferings(Matchers.anyString(), Matchers.anyString(), Matchers.anyInt(), Matchers.anyInt(), Matchers.anyInt(),
+ Matchers.anyInt(), Matchers.anyInt(), Matchers.anyBoolean(), Matchers.anyString(), Matchers.any(Storage.ProvisioningType.class), Matchers.anyBoolean(),
+ Matchers.anyString(), Matchers.anyBoolean(), Matchers.any(VirtualMachine.Type.class), Matchers.anyBoolean())).thenReturn(list);
ComponentContext.initComponentsLifeCycle();
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/17366f2b/plugins/network-elements/internal-loadbalancer/test/org/apache/cloudstack/internallbvmmgr/InternalLBVMServiceTest.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/internal-loadbalancer/test/org/apache/cloudstack/internallbvmmgr/InternalLBVMServiceTest.java b/plugins/network-elements/internal-loadbalancer/test/org/apache/cloudstack/internallbvmmgr/InternalLBVMServiceTest.java
index 11a0bed..ec636fa 100644
--- a/plugins/network-elements/internal-loadbalancer/test/org/apache/cloudstack/internallbvmmgr/InternalLBVMServiceTest.java
+++ b/plugins/network-elements/internal-loadbalancer/test/org/apache/cloudstack/internallbvmmgr/InternalLBVMServiceTest.java
@@ -17,6 +17,8 @@
package org.apache.cloudstack.internallbvmmgr;
import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.List;
import javax.inject.Inject;
@@ -91,7 +93,12 @@ public class InternalLBVMServiceTest extends TestCase {
ServiceOfferingVO off = new ServiceOfferingVO("alena", 1, 1,
1, 1, 1, false, "alena", Storage.ProvisioningType.THIN, false, false, null, false, VirtualMachine.Type.InternalLoadBalancerVm, false);
off = setId(off, 1);
- Mockito.when(_svcOffDao.persistSystemServiceOffering(Matchers.any(ServiceOfferingVO.class))).thenReturn(off);
+ List<ServiceOfferingVO> list = new ArrayList<ServiceOfferingVO>();
+ list.add(off);
+ list.add(off);
+ Mockito.when(_svcOffDao.createSystemServiceOfferings(Matchers.anyString(), Matchers.anyString(), Matchers.anyInt(), Matchers.anyInt(), Matchers.anyInt(),
+ Matchers.anyInt(), Matchers.anyInt(), Matchers.anyBoolean(), Matchers.anyString(), Matchers.any(Storage.ProvisioningType.class), Matchers.anyBoolean(),
+ Matchers.anyString(), Matchers.anyBoolean(), Matchers.any(VirtualMachine.Type.class), Matchers.anyBoolean())).thenReturn(list);
ComponentContext.initComponentsLifeCycle();
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/17366f2b/server/src/com/cloud/configuration/Config.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/configuration/Config.java b/server/src/com/cloud/configuration/Config.java
index 0d6a4e6..d4a7797 100755
--- a/server/src/com/cloud/configuration/Config.java
+++ b/server/src/com/cloud/configuration/Config.java
@@ -684,7 +684,6 @@ public enum Config {
"/var/cloudstack/mnt",
"The mount point on the Management Server for Secondary Storage.",
null),
-// UpgradeURL("Advanced", ManagementServer.class, String.class, "upgrade.url", "http://example.com:8080/client/agent/update.zip", "The upgrade URL is the URL of the management server that agents will connect to in order to automatically upgrade.", null),
SystemVMAutoReserveCapacity(
"Advanced",
ManagementServer.class,
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/17366f2b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java
index 89027c1..89e0428 100755
--- a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java
+++ b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java
@@ -37,6 +37,7 @@ import javax.ejb.Local;
import javax.inject.Inject;
import javax.naming.ConfigurationException;
+import org.apache.cloudstack.framework.config.Configurable;
import org.apache.log4j.Logger;
import org.apache.cloudstack.acl.SecurityChecker;
@@ -214,8 +215,11 @@ import com.cloud.vm.dao.NicIpAliasVO;
import com.cloud.vm.dao.NicSecondaryIpDao;
@Local(value = {ConfigurationManager.class, ConfigurationService.class})
-public class ConfigurationManagerImpl extends ManagerBase implements ConfigurationManager, ConfigurationService {
+public class ConfigurationManagerImpl extends ManagerBase implements ConfigurationManager, ConfigurationService, Configurable {
public static final Logger s_logger = Logger.getLogger(ConfigurationManagerImpl.class);
+ public static final String SystemVMUseLocalStorageCK = "system.vm.use.local.storage";
+ public static final ConfigKey<Boolean> SystemVMUseLocalStorage = new ConfigKey<Boolean>(Boolean.class, SystemVMUseLocalStorageCK, "Advanced", "false",
+ "Indicates whether to use local storage pools or shared storage pools for system VMs.", true, ConfigKey.Scope.Zone, null);
@Inject
EntityManager _entityMgr;
@@ -570,35 +574,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
} catch (Throwable e) {
throw new CloudRuntimeException("Failed to update storage.network.device2 in host_details due to exception ", e);
}
- } else if (DataCenter.SystemVMUseLocalStorageCK.equalsIgnoreCase(name)) {
- if (s_logger.isDebugEnabled()) {
- s_logger.debug("Config 'system.vm.use.local.storage' changed to value:" + value + ", need to update System VM offerings");
- }
- boolean useLocalStorage = Boolean.parseBoolean(_configDao.getValue(DataCenter.SystemVMUseLocalStorageCK));
- ServiceOfferingVO serviceOffering = _serviceOfferingDao.findByName(ServiceOffering.consoleProxyDefaultOffUniqueName);
- if (serviceOffering != null) {
- serviceOffering.setUseLocalStorage(useLocalStorage);
- if (!_serviceOfferingDao.update(serviceOffering.getId(), serviceOffering)) {
- throw new CloudRuntimeException("Failed to update ConsoleProxy offering's use_local_storage option to value:" + useLocalStorage);
- }
- }
-
- serviceOffering = _serviceOfferingDao.findByName(ServiceOffering.routerDefaultOffUniqueName);
- if (serviceOffering != null) {
- serviceOffering.setUseLocalStorage(useLocalStorage);
- if (!_serviceOfferingDao.update(serviceOffering.getId(), serviceOffering)) {
- throw new CloudRuntimeException("Failed to update SoftwareRouter offering's use_local_storage option to value:" + useLocalStorage);
- }
- }
-
- serviceOffering = _serviceOfferingDao.findByName(ServiceOffering.ssvmDefaultOffUniqueName);
- if (serviceOffering != null) {
- serviceOffering.setUseLocalStorage(useLocalStorage);
- if (!_serviceOfferingDao.update(serviceOffering.getId(), serviceOffering)) {
- throw new CloudRuntimeException("Failed to update SecondaryStorage offering's use_local_storage option to value:" + useLocalStorage);
- }
- }
- }else if (Config.SecStorageSecureCopyCert.key().equalsIgnoreCase(name)) {
+ } else if (Config.SecStorageSecureCopyCert.key().equalsIgnoreCase(name)) {
//FIXME - Ideally there should be a listener model to listen to global config changes and be able to take action gracefully.
//Expire the download urls
String sqlTemplate = "update template_store_ref set download_url_created=?";
@@ -5081,4 +5057,13 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
_secChecker = secChecker;
}
+ @Override
+ public String getConfigComponentName() {
+ return ConfigurationManagerImpl.class.getSimpleName();
+ }
+
+ @Override
+ public ConfigKey<?>[] getConfigKeys() {
+ return new ConfigKey<?>[] {SystemVMUseLocalStorage};
+ }
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/17366f2b/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java b/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java
index 3fd3543..df338c4 100755
--- a/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java
+++ b/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java
@@ -30,6 +30,7 @@ import javax.ejb.Local;
import javax.inject.Inject;
import javax.naming.ConfigurationException;
+import com.cloud.configuration.ConfigurationManagerImpl;
import org.apache.log4j.Logger;
import com.google.gson.Gson;
@@ -225,7 +226,6 @@ public class ConsoleProxyManagerImpl extends ManagerBase implements ConsoleProxy
private int _capacityPerProxy = ConsoleProxyManager.DEFAULT_PROXY_CAPACITY;
private int _standbyCapacity = ConsoleProxyManager.DEFAULT_STANDBY_CAPACITY;
- private boolean _useLvm;
private boolean _useStorageVm;
private boolean _disableRpFilter = false;
private String _instance;
@@ -716,13 +716,18 @@ public class ConsoleProxyManagerImpl extends ManagerBase implements ConsoleProxy
networks.put(_networkMgr.setupNetwork(systemAcct, offering, plan, null, null, false).get(0), new ArrayList<NicProfile>());
}
+ ServiceOfferingVO serviceOffering = _serviceOffering;
+ if (serviceOffering == null) {
+ serviceOffering = _offeringDao.findDefaultSystemOffering(ServiceOffering.consoleProxyDefaultOffUniqueName, ConfigurationManagerImpl.SystemVMUseLocalStorage.valueIn(dataCenterId));
+ }
+
ConsoleProxyVO proxy =
- new ConsoleProxyVO(id, _serviceOffering.getId(), name, template.getId(), template.getHypervisorType(), template.getGuestOSId(), dataCenterId,
- systemAcct.getDomainId(), systemAcct.getId(), 0, _serviceOffering.getOfferHA());
+ new ConsoleProxyVO(id, serviceOffering.getId(), name, template.getId(), template.getHypervisorType(), template.getGuestOSId(), dataCenterId,
+ systemAcct.getDomainId(), systemAcct.getId(), 0, serviceOffering.getOfferHA());
proxy.setDynamicallyScalable(template.isDynamicallyScalable());
proxy = _consoleProxyDao.persist(proxy);
try {
- _itMgr.allocate(name, template, _serviceOffering, networks, plan, null);
+ _itMgr.allocate(name, template, serviceOffering, networks, plan, null);
} catch (InsufficientCapacityException e) {
s_logger.warn("InsufficientCapacity", e);
throw new CloudRuntimeException("Insufficient capacity exception", e);
@@ -951,7 +956,12 @@ public class ConsoleProxyManagerImpl extends ManagerBase implements ConsoleProxy
TemplateDataStoreVO templateHostRef = _vmTemplateStoreDao.findByTemplateZoneDownloadStatus(template.getId(), dataCenterId, Status.DOWNLOADED);
if (templateHostRef != null) {
- List<Pair<Long, Integer>> l = _consoleProxyDao.getDatacenterStoragePoolHostInfo(dataCenterId, _useLvm);
+ boolean useLocalStorage = false;
+ Boolean useLocal = ConfigurationManagerImpl.SystemVMUseLocalStorage.valueIn(dataCenterId);
+ if (useLocal != null) {
+ useLocalStorage = useLocal;
+ }
+ List<Pair<Long, Integer>> l = _consoleProxyDao.getDatacenterStoragePoolHostInfo(dataCenterId, useLocalStorage);
if (l != null && l.size() > 0 && l.get(0).second().intValue() > 0) {
return true;
} else {
@@ -1208,11 +1218,6 @@ public class ConsoleProxyManagerImpl extends ManagerBase implements ConsoleProxy
_disableRpFilter = true;
}
- value = configs.get(DataCenter.SystemVMUseLocalStorageCK);
- if (value != null && value.equalsIgnoreCase("true")) {
- _useLvm = true;
- }
-
value = configs.get("secondary.storage.vm");
if (value != null && value.equalsIgnoreCase("true")) {
_useStorageVm = true;
@@ -1238,8 +1243,6 @@ public class ConsoleProxyManagerImpl extends ManagerBase implements ConsoleProxy
_itMgr.registerGuru(VirtualMachine.Type.ConsoleProxy, this);
- boolean useLocalStorage = Boolean.parseBoolean(configs.get(DataCenter.SystemVMUseLocalStorageCK));
-
//check if there is a default service offering configured
String cpvmSrvcOffIdStr = configs.get(Config.ConsoleProxyServiceOffering.key());
if (cpvmSrvcOffIdStr != null) {
@@ -1259,15 +1262,13 @@ public class ConsoleProxyManagerImpl extends ManagerBase implements ConsoleProxy
if (_serviceOffering == null || !_serviceOffering.getSystemUse()) {
int ramSize = NumbersUtil.parseInt(_configDao.getValue("console.ram.size"), DEFAULT_PROXY_VM_RAMSIZE);
int cpuFreq = NumbersUtil.parseInt(_configDao.getValue("console.cpu.mhz"), DEFAULT_PROXY_VM_CPUMHZ);
- _serviceOffering =
- new ServiceOfferingVO("System Offering For Console Proxy", 1, ramSize, cpuFreq, 0, 0, false, null,
- Storage.ProvisioningType.THIN, useLocalStorage, true, null, true,
- VirtualMachine.Type.ConsoleProxy, true);
- _serviceOffering.setUniqueName(ServiceOffering.consoleProxyDefaultOffUniqueName);
- _serviceOffering = _offeringDao.persistSystemServiceOffering(_serviceOffering);
+
+ List<ServiceOfferingVO> offerings = _offeringDao.createSystemServiceOfferings("System Offering For Console Proxy",
+ ServiceOffering.consoleProxyDefaultOffUniqueName, 1, ramSize, cpuFreq, 0, 0, false, null,
+ Storage.ProvisioningType.THIN, true, null, true, VirtualMachine.Type.ConsoleProxy, true);
// this can sometimes happen, if DB is manually or programmatically manipulated
- if (_serviceOffering == null) {
+ if (offerings == null || offerings.size() < 2) {
String msg = "Data integrity problem : System Offering For Console Proxy has been removed?";
s_logger.error(msg);
throw new ConfigurationException(msg);
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/17366f2b/server/src/com/cloud/deploy/DeploymentPlanningManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/deploy/DeploymentPlanningManagerImpl.java b/server/src/com/cloud/deploy/DeploymentPlanningManagerImpl.java
index c290e9c..7637a3a 100755
--- a/server/src/com/cloud/deploy/DeploymentPlanningManagerImpl.java
+++ b/server/src/com/cloud/deploy/DeploymentPlanningManagerImpl.java
@@ -31,6 +31,7 @@ import javax.ejb.Local;
import javax.inject.Inject;
import javax.naming.ConfigurationException;
+import com.cloud.configuration.ConfigurationManagerImpl;
import com.cloud.utils.fsm.StateMachine2;
import org.apache.log4j.Logger;
@@ -46,8 +47,6 @@ import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
import org.apache.cloudstack.engine.subsystem.api.storage.StoragePoolAllocator;
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
-import org.apache.cloudstack.framework.config.ConfigKey;
-import org.apache.cloudstack.framework.config.Configurable;
import org.apache.cloudstack.framework.messagebus.MessageBus;
import org.apache.cloudstack.framework.messagebus.MessageSubscriber;
import org.apache.cloudstack.managed.context.ManagedContextTimerTask;
@@ -134,7 +133,7 @@ import com.cloud.vm.dao.VMInstanceDao;
@Local(value = {DeploymentPlanningManager.class})
public class DeploymentPlanningManagerImpl extends ManagerBase implements DeploymentPlanningManager, Manager, Listener,
-StateListener<State, VirtualMachine.Event, VirtualMachine>, Configurable {
+StateListener<State, VirtualMachine.Event, VirtualMachine> {
private static final Logger s_logger = Logger.getLogger(DeploymentPlanningManagerImpl.class);
@Inject
@@ -755,16 +754,6 @@ StateListener<State, VirtualMachine.Event, VirtualMachine>, Configurable {
return false;
}
- @Override
- public String getConfigComponentName() {
- return DeploymentPlanningManagerImpl.class.getSimpleName();
- }
-
- @Override
- public ConfigKey<?>[] getConfigKeys() {
- return new ConfigKey<?>[] {DataCenter.UseSystemVMLocalStorage};
- }
-
class HostReservationReleaseChecker extends ManagedContextTimerTask {
@Override
protected void runInContext() {
@@ -1294,21 +1283,13 @@ StateListener<State, VirtualMachine.Event, VirtualMachine>, Configurable {
boolean useLocalStorage = false;
if (vmProfile.getType() != VirtualMachine.Type.User) {
DataCenterVO zone = _dcDao.findById(plan.getDataCenterId());
- // It should not happen to have a "null" zone here. There can be NO instance if there is NO zone,
- // so this part of the code would never be reached if no zone has been created.
- // Added the check and the comment just to make it clear.
- boolean zoneUsesLocalStorage = zone != null ? zone.isLocalStorageEnabled() : false;
- boolean ssvmUseLocalStorage = DataCenter.UseSystemVMLocalStorage.value();
- if (zone != null) {
- ssvmUseLocalStorage = DataCenter.UseSystemVMLocalStorage.valueIn(plan.getDataCenterId());
- }
- s_logger.debug("Checking if we need local storage for systemvms is needed for zone id=" + plan.getDataCenterId() + " with system.vm.use.local.storage=" + ssvmUseLocalStorage);
- // Local storage is used for the NON User VMs if, and only if, the Zone is marked to use local storage AND
- // the global settings (ssvmUseLocalStorage) is set to true. Otherwise, the global settings won't be applied.
- if (ssvmUseLocalStorage && zoneUsesLocalStorage) {
- useLocalStorage = true;
- s_logger.debug("SystemVMs will use local storage for zone id=" + plan.getDataCenterId());
+ assert (zone != null) : "Invalid zone in deployment plan";
+ Boolean useLocalStorageForSystemVM = ConfigurationManagerImpl.SystemVMUseLocalStorage.valueIn(zone.getId());
+ if (useLocalStorageForSystemVM != null) {
+ useLocalStorage = useLocalStorageForSystemVM.booleanValue();
+ s_logger.debug("System VMs will use " + (useLocalStorage ? "local" : "shared") + " storage for zone id=" + plan.getDataCenterId());
}
+
} else {
useLocalStorage = diskOffering.getUseLocalStorage();
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/17366f2b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
index e0d1edb..73aa94c 100755
--- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
+++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
@@ -72,6 +72,7 @@ import com.cloud.cluster.ManagementServerHostVO;
import com.cloud.cluster.dao.ManagementServerHostDao;
import com.cloud.configuration.Config;
import com.cloud.configuration.ConfigurationManager;
+import com.cloud.configuration.ConfigurationManagerImpl;
import com.cloud.configuration.ZoneConfig;
import com.cloud.dc.ClusterVO;
import com.cloud.dc.DataCenter;
@@ -737,14 +738,11 @@ VirtualMachineGuru, Listener, Configurable, StateListener<State, VirtualMachine.
_agentMgr.registerForHostEvents(new SshKeysDistriMonitor(_agentMgr, _hostDao, _configDao), true, false, false);
- final boolean useLocalStorage = Boolean.parseBoolean(configs.get(DataCenter.SystemVMUseLocalStorageCK));
- _offering = new ServiceOfferingVO("System Offering For Software Router", 1, _routerRamSize, _routerCpuMHz, null,
- null, true, null, ProvisioningType.THIN, useLocalStorage, true, null, true, VirtualMachine.Type.DomainRouter, true);
- _offering.setUniqueName(ServiceOffering.routerDefaultOffUniqueName);
- _offering = _serviceOfferingDao.persistSystemServiceOffering(_offering);
-
+ List<ServiceOfferingVO> offerings = _serviceOfferingDao.createSystemServiceOfferings("System Offering For Software Router",
+ ServiceOffering.routerDefaultOffUniqueName, 1, _routerRamSize, _routerCpuMHz, null,
+ null, true, null, ProvisioningType.THIN, true, null, true, VirtualMachine.Type.DomainRouter, true);
// this can sometimes happen, if DB is manually or programmatically manipulated
- if (_offering == null) {
+ if (offerings == null || offerings.size() < 2) {
final String msg = "Data integrity problem : System Offering For Software router VM has been removed?";
s_logger.error(msg);
throw new ConfigurationException(msg);
@@ -1676,7 +1674,8 @@ VirtualMachineGuru, Listener, Configurable, StateListener<State, VirtualMachine.
Long offeringId = _networkOfferingDao.findById(guestNetwork.getNetworkOfferingId()).getServiceOfferingId();
if (offeringId == null) {
- offeringId = _offering.getId();
+ ServiceOfferingVO serviceOffering = _serviceOfferingDao.findDefaultSystemOffering(ServiceOffering.routerDefaultOffUniqueName, ConfigurationManagerImpl.SystemVMUseLocalStorage.valueIn(dest.getDataCenter().getId()));
+ offeringId = serviceOffering.getId();
}
PublicIp sourceNatIp = null;
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/17366f2b/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java
index 97cbf62..2791e3a 100644
--- a/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java
+++ b/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java
@@ -32,6 +32,9 @@ import javax.ejb.Local;
import javax.inject.Inject;
import javax.naming.ConfigurationException;
+import com.cloud.configuration.ConfigurationManagerImpl;
+import com.cloud.offering.ServiceOffering;
+import com.cloud.service.ServiceOfferingVO;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
@@ -210,8 +213,10 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
Long offeringId = _vpcOffDao.findById(vpc.getVpcOfferingId()).getServiceOfferingId();
if (offeringId == null) {
- offeringId = _offering.getId();
+ ServiceOfferingVO serviceOffering = _serviceOfferingDao.findDefaultSystemOffering(ServiceOffering.routerDefaultOffUniqueName, ConfigurationManagerImpl.SystemVMUseLocalStorage.valueIn(dest.getDataCenter().getId()));
+ offeringId = serviceOffering.getId();
}
+
//3) Deploy Virtual Router
List<? extends PhysicalNetwork> pNtwks = _pNtwkDao.listByZone(vpc.getZoneId());
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/17366f2b/server/src/com/cloud/storage/StorageManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/storage/StorageManagerImpl.java b/server/src/com/cloud/storage/StorageManagerImpl.java
index 9c442ac..aeb0bb5 100755
--- a/server/src/com/cloud/storage/StorageManagerImpl.java
+++ b/server/src/com/cloud/storage/StorageManagerImpl.java
@@ -41,6 +41,7 @@ import javax.ejb.Local;
import javax.inject.Inject;
import javax.naming.ConfigurationException;
+import com.cloud.configuration.ConfigurationManagerImpl;
import com.cloud.hypervisor.Hypervisor;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
@@ -536,11 +537,20 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
@DB
@Override
public DataStore createLocalStorage(Host host, StoragePoolInfo pInfo) throws ConnectionException {
-
DataCenterVO dc = _dcDao.findById(host.getDataCenterId());
- if (dc == null || !dc.isLocalStorageEnabled()) {
+ if (dc == null) {
+ return null;
+ }
+
+ boolean useLocalStorageForSystemVM = false;
+ Boolean isLocal = ConfigurationManagerImpl.SystemVMUseLocalStorage.valueIn(dc.getId());
+ if (isLocal != null) {
+ useLocalStorageForSystemVM = isLocal.booleanValue();
+ }
+ if (!(dc.isLocalStorageEnabled() || useLocalStorageForSystemVM)) {
return null;
}
+
DataStore store;
try {
String hostAddress = pInfo.getHost();
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/17366f2b/server/test/com/cloud/network/element/VirtualRouterElementTest.java
----------------------------------------------------------------------
diff --git a/server/test/com/cloud/network/element/VirtualRouterElementTest.java b/server/test/com/cloud/network/element/VirtualRouterElementTest.java
index d6eb24f..0f79f56 100644
--- a/server/test/com/cloud/network/element/VirtualRouterElementTest.java
+++ b/server/test/com/cloud/network/element/VirtualRouterElementTest.java
@@ -31,6 +31,7 @@ import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
+import org.mockito.Matchers;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
@@ -268,6 +269,8 @@ public class VirtualRouterElementTest {
VirtualMachine.Type.DomainRouter,
/* defaultUse */ false);
when(_serviceOfferingDao.findById(0L)).thenReturn(svcoff);
+ when(_serviceOfferingDao.findByName(Matchers.anyString())).thenReturn(svcoff);
+ when(_serviceOfferingDao.findDefaultSystemOffering(Matchers.anyString(), Matchers.anyBoolean())).thenReturn(svcoff);
DomainRouterVO router = new DomainRouterVO(/* id */ 1L,
/* serviceOfferingId */ 1L,
/* elementId */ 0L,
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/17366f2b/services/secondary-storage/controller/src/org/apache/cloudstack/secondarystorage/SecondaryStorageManagerImpl.java
----------------------------------------------------------------------
diff --git a/services/secondary-storage/controller/src/org/apache/cloudstack/secondarystorage/SecondaryStorageManagerImpl.java b/services/secondary-storage/controller/src/org/apache/cloudstack/secondarystorage/SecondaryStorageManagerImpl.java
index 9d89b07..7b6e868 100755
--- a/services/secondary-storage/controller/src/org/apache/cloudstack/secondarystorage/SecondaryStorageManagerImpl.java
+++ b/services/secondary-storage/controller/src/org/apache/cloudstack/secondarystorage/SecondaryStorageManagerImpl.java
@@ -31,6 +31,7 @@ import javax.ejb.Local;
import javax.inject.Inject;
import javax.naming.ConfigurationException;
+import com.cloud.configuration.ConfigurationManagerImpl;
import org.apache.cloudstack.config.ApiServiceConfiguration;
import org.apache.cloudstack.context.CallContext;
@@ -242,7 +243,6 @@ public class SecondaryStorageManagerImpl extends ManagerBase implements Secondar
private int _secStorageVmMtuSize;
private String _instance;
- private boolean _useLocalStorage;
private boolean _useSSlCopy;
private String _httpProxy;
private String _allowedInternalSites;
@@ -573,13 +573,17 @@ public class SecondaryStorageManagerImpl extends ManagerBase implements Secondar
throw new CloudRuntimeException("Not able to find the System templates or not downloaded in zone " + dataCenterId);
}
+ ServiceOfferingVO serviceOffering = _serviceOffering;
+ if (serviceOffering == null) {
+ serviceOffering = _offeringDao.findDefaultSystemOffering(ServiceOffering.ssvmDefaultOffUniqueName, ConfigurationManagerImpl.SystemVMUseLocalStorage.valueIn(dataCenterId));
+ }
SecondaryStorageVmVO secStorageVm =
- new SecondaryStorageVmVO(id, _serviceOffering.getId(), name, template.getId(), template.getHypervisorType(), template.getGuestOSId(), dataCenterId,
- systemAcct.getDomainId(), systemAcct.getId(), role, _serviceOffering.getOfferHA());
+ new SecondaryStorageVmVO(id, serviceOffering.getId(), name, template.getId(), template.getHypervisorType(), template.getGuestOSId(), dataCenterId,
+ systemAcct.getDomainId(), systemAcct.getId(), role, serviceOffering.getOfferHA());
secStorageVm.setDynamicallyScalable(template.isDynamicallyScalable());
secStorageVm = _secStorageVmDao.persist(secStorageVm);
try {
- _itMgr.allocate(name, template, _serviceOffering, networks, plan, null);
+ _itMgr.allocate(name, template, serviceOffering, networks, plan, null);
secStorageVm = _secStorageVmDao.findById(secStorageVm.getId());
} catch (InsufficientCapacityException e) {
s_logger.warn("InsufficientCapacity", e);
@@ -759,14 +763,20 @@ public class SecondaryStorageManagerImpl extends ManagerBase implements Secondar
return false;
}
- List<Pair<Long, Integer>> l = _storagePoolHostDao.getDatacenterStoragePoolHostInfo(dataCenterId, !_useLocalStorage);
+ boolean useLocalStorage = false;
+ Boolean useLocal = ConfigurationManagerImpl.SystemVMUseLocalStorage.valueIn(dataCenterId);
+ if (useLocal != null) {
+ useLocalStorage = useLocal.booleanValue();
+ }
+ List<Pair<Long, Integer>> l = _storagePoolHostDao.getDatacenterStoragePoolHostInfo(dataCenterId, !useLocalStorage);
+
if (l != null && l.size() > 0 && l.get(0).second().intValue() > 0) {
return true;
} else {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Primary storage is not ready, wait until it is ready to launch secondary storage vm. dcId: " + dataCenterId +
- " system.vm.use.local.storage: " + _useLocalStorage +
- "If you want to use local storage to start ssvm, need to set system.vm.use.local.storage to true");
+ ", " + ConfigurationManagerImpl.SystemVMUseLocalStorage.key() + ": " + useLocalStorage + ". " +
+ "If you want to use local storage to start SSVM, need to set " + ConfigurationManagerImpl.SystemVMUseLocalStorage.key() + " to true");
}
}
@@ -871,15 +881,12 @@ public class SecondaryStorageManagerImpl extends ManagerBase implements Secondar
if(_serviceOffering == null || !_serviceOffering.getSystemUse()){
int ramSize = NumbersUtil.parseInt(_configDao.getValue("ssvm.ram.size"), DEFAULT_SS_VM_RAMSIZE);
int cpuFreq = NumbersUtil.parseInt(_configDao.getValue("ssvm.cpu.mhz"), DEFAULT_SS_VM_CPUMHZ);
- _useLocalStorage = Boolean.parseBoolean(configs.get(DataCenter.SystemVMUseLocalStorageCK));
- _serviceOffering =
- new ServiceOfferingVO("System Offering For Secondary Storage VM", 1, ramSize, cpuFreq, null, null, false, null,
- Storage.ProvisioningType.THIN, _useLocalStorage, true, null, true, VirtualMachine.Type.SecondaryStorageVm, true);
- _serviceOffering.setUniqueName(ServiceOffering.ssvmDefaultOffUniqueName);
- _serviceOffering = _offeringDao.persistSystemServiceOffering(_serviceOffering);
+ List<ServiceOfferingVO> offerings = _offeringDao.createSystemServiceOfferings("System Offering For Secondary Storage VM",
+ ServiceOffering.ssvmDefaultOffUniqueName, 1, ramSize, cpuFreq, null, null, false, null,
+ Storage.ProvisioningType.THIN, true, null, true, VirtualMachine.Type.SecondaryStorageVm, true);
// this can sometimes happen, if DB is manually or programmatically manipulated
- if (_serviceOffering == null) {
+ if (offerings == null || offerings.size() < 2) {
String msg = "Data integrity problem : System Offering For Secondary Storage VM has been removed?";
s_logger.error(msg);
throw new ConfigurationException(msg);
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/17366f2b/test/integration/component/maint/test_zone_level_local_storage_setting.py
----------------------------------------------------------------------
diff --git a/test/integration/component/maint/test_zone_level_local_storage_setting.py b/test/integration/component/maint/test_zone_level_local_storage_setting.py
new file mode 100644
index 0000000..466f1f9
--- /dev/null
+++ b/test/integration/component/maint/test_zone_level_local_storage_setting.py
@@ -0,0 +1,734 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""
+Test cases for zone level settings "system.vm.use.local.storage"
+"""
+# Import Local Modules
+from marvin.cloudstackTestCase import *
+from marvin.lib.utils import *
+from marvin.lib.base import *
+from marvin.lib.common import *
+from marvin.codes import FAILED, PASS
+from requests.exceptions import ConnectionError
+
+import time
+from nose.plugins.attrib import attr
+from ddt import ddt, data
+
+
+def destroy_systemvm(self, type):
+ """
+ Destroy system vms
+ #1-List system vms for current zone
+ #2-Destroy system vm
+ #3-Check if system vm came up after destroy
+ #4-check system vm storage type in disk offering
+ """
+ list_response = list_ssvms(
+ self.apiclient,
+ systemvmtype=type,
+ zoneid=self.zone.id
+ )
+
+ self.assertEqual(
+ validateList(list_response)[0],
+ PASS,
+ "Check List ssvm response for %s" %
+ type)
+
+ response = list_response[0]
+ self.debug("Destroying CPVM: %s" % response.id)
+ cmd = destroySystemVm.destroySystemVmCmd()
+ cmd.id = response.id
+ self.apiclient.destroySystemVm(cmd)
+
+ timeout = self.testdata["timeout"]
+ while True:
+ time.sleep(self.testdata["sleep"])
+ list_response = list_ssvms(
+ self.apiclient,
+ systemvmtype=type,
+ zoneid=self.zone.id
+ )
+ if validateList(list_response)[0] == PASS:
+ if list_response[0].state == 'Running':
+ break
+ if timeout == 0:
+ raise Exception("List %s call failed!" % type)
+ timeout = timeout - 1
+
+
+def storage_check(self, type, value):
+ """test if system vms are using local or shared storage
+ #1-Get zone id from db using self.zone.id
+ #2-Get service offering id from vm_instance table for running system vms
+ #3-Get use_local_storage value from disk_offering table
+ #4-Verify storage type"""
+ query_zone_id = self.dbclient.execute(
+ "select id from data_center where uuid= '%s';" % self.zone.id
+ )
+ query_so_id = self.dbclient.execute(
+ "select service_offering_id from vm_instance where type='%s'and "
+ "state='Running' and data_center_id= '%s';" %
+ (type, query_zone_id[0][0]))
+
+ query_disk_offering = self.dbclient.execute(
+ "select use_local_storage from disk_offering where id= '%s';" %
+ query_so_id[0][0])
+
+ if value == 1:
+ self.assertEqual(query_disk_offering[0][0],
+ 1,
+ "system vm is not using local storage"
+ )
+ elif value == 0:
+ self.assertEqual(query_disk_offering[0][0],
+ 0,
+ "system vm is not using shared storage"
+ )
+ else:
+ # evil ValueError that doesn't tell you what the wrong value was
+ raise ValueError
+
+
+def create_system_so(self, offering_type, storage_type):
+ """Create system offerings """
+ self.testdata["service_offerings"]["issystem"] = "true"
+ self.testdata["service_offerings"]["systemvmtype"] = offering_type
+ self.testdata["service_offerings"]["storagetype"] = storage_type
+
+ service_offering = ServiceOffering.create(
+ self.apiclient,
+ self.testdata["service_offerings"]
+ )
+
+ if service_offering is None:
+ raise Exception("service offering not created")
+
+ list_service_response = list_service_offering(
+ self.apiclient,
+ id=service_offering.id,
+ issystem='true'
+ )
+ self.assertEqual(
+ validateList(list_service_response)[0],
+ PASS,
+ "Check List srvice offering response for %s" %
+ type)
+
+ self.debug(
+ "Created service offering with ID: %s" %
+ service_offering.id)
+
+ self.assertEqual(
+ list_service_response[0].cpunumber,
+ self.testdata["service_offerings"]["cpunumber"],
+ "Check server id in createServiceOffering"
+ )
+ self.assertEqual(
+ list_service_response[0].cpuspeed,
+ self.testdata["service_offerings"]["cpuspeed"],
+ "Check cpuspeed in createServiceOffering"
+ )
+ self.assertEqual(
+ list_service_response[0].displaytext,
+ self.testdata["service_offerings"]["displaytext"],
+ "Check server displaytext in createServiceOfferings"
+ )
+ self.assertEqual(
+ list_service_response[0].memory,
+ self.testdata["service_offerings"]["memory"],
+ "Check memory in createServiceOffering"
+ )
+ self.assertEqual(
+ list_service_response[0].name,
+ self.testdata["service_offerings"]["name"],
+ "Check name in createServiceOffering"
+ )
+ self.assertEqual(
+ list_service_response[0].storagetype,
+ self.testdata["service_offerings"]["storagetype"],
+ "Check storagetype in createServiceOffering"
+ )
+ self._cleanup.append(service_offering)
+ return service_offering.id
+
+
+def restart_ms(self):
+ """Restart MS
+ #1-ssh into m/c running MS
+ #2-restart ms
+ #3-verify the response
+ #4-loop unitl you get list_zone api answer """
+ sshClient = SshClient(
+ self.mgtSvrDetails["mgtSvrIp"],
+ 22,
+ self.mgtSvrDetails["user"],
+ self.mgtSvrDetails["passwd"]
+ )
+ command = "service cloudstack-management restart"
+ ms_restart_response = sshClient.execute(command)
+ self.assertEqual(
+ validateList(ms_restart_response)[0],
+ PASS,
+ "Check the MS restart response")
+ self.assertEqual(
+ ms_restart_response[0],
+ 'Stopping cloudstack-management:[ OK ]',
+ "MS i not stopped"
+ )
+ self.assertEqual(
+ ms_restart_response[1],
+ 'Starting cloudstack-management: [ OK ]',
+ "MS not started"
+ )
+ timeout = self.testdata["timeout"]
+ while True:
+ time.sleep(self.testdata["sleep"])
+ try:
+ list_response = Zone.list(
+ self.apiclient
+ )
+ if validateList(list_response)[0] == PASS:
+ break
+ except ConnectionError as e:
+ self.debug("list zone response is not available due to %s" % e)
+
+ if timeout == 0:
+ raise Exception("Ms is not comming up !")
+ timeout = timeout - 1
+
+
+def update_global_settings(self, value, name, zoneid=None):
+ """Update Gloabal/zonelevel settings and verify
+ #1-Update configuration
+ #2-Restart ms if zone id is None"""
+ Configurations.update(self.apiclient,
+ name=name,
+ zoneid=zoneid,
+ value=value
+ )
+ if zoneid is None:
+ restart_ms(self)
+
+ list_conf = Configurations.list(self.apiclient,
+ name=name,
+ zoneid=zoneid)
+
+ self.assertEqual(
+ validateList(list_conf)[0],
+ PASS,
+ "Check List configuration response for %s" % name)
+
+ self.assertEqual(
+ str(list_conf[0].value),
+ str(value),
+ "Check if configuration values are equal"
+ )
+
+
+def str_to_bool(s):
+ """Converts str "True/False to Boolean TRUE/FALSE"""
+ if s == 'true':
+ return True
+ elif s == 'false':
+ return False
+ else:
+ # evil ValueError that doesn't tell you what the wrong value was
+ raise ValueError
+
+
+@ddt
+class TestSystemVmLocalStorage(cloudstackTestCase):
+
+ @classmethod
+ def setUpClass(cls):
+ testClient = super(TestSystemVmLocalStorage, cls).getClsTestClient()
+ cls.apiclient = testClient.getApiClient()
+ cls.dbclient = cls.testClient.getDbConnection()
+ cls.mgtSvrDetails = cls.config.__dict__["mgtSvr"][0].__dict__
+ cls.testdata = testClient.getParsedTestDataConfig()
+ # Get Zone, and template Domain
+ cls.domain = get_domain(cls.apiclient)
+ cls.zone = get_zone(cls.apiclient)
+ cls.testdata["mode"] = cls.zone.networktype
+ cls.hypervisor = testClient.getHypervisorInfo()
+ cls._cleanup = []
+
+ list_local_storage_pool = StoragePool.list(
+ cls.apiclient,
+ scope='HOST',
+ zoneid=cls.zone.id,
+
+ )
+
+ if list_local_storage_pool is None:
+
+ Configurations.update(
+ cls.apiclient,
+ value='true',
+ name='system.vm.use.local.storage',
+ zoneid=cls.zone.id
+ )
+
+ # Restart MS
+ sshClient = SshClient(
+ cls.mgtSvrDetails["mgtSvrIp"],
+ 22,
+ cls.mgtSvrDetails["user"],
+ cls.mgtSvrDetails["passwd"]
+ )
+ command = "service cloudstack-management restart"
+ ms_restart_response = sshClient.execute(command)
+
+ if validateList(ms_restart_response)[0] != PASS:
+ raise Exception("Check the MS restart response")
+ if ms_restart_response[
+ 0] != 'Stopping cloudstack-management:[ OK ]':
+ raise Exception("MS i not stopped")
+
+ if ms_restart_response[
+ 1] != 'Starting cloudstack-management: [ OK ]':
+ raise Exception("MS not started")
+
+ timeout = cls.testdata["timeout"]
+ while True:
+ # time.sleep(cls.testdata["sleep"])
+ try:
+ list_response = Zone.list(
+ cls.apiclient
+ )
+ if validateList(list_response)[0] == PASS:
+ break
+ except ConnectionError as e:
+ cls.debug(
+ "list zone response is not available due to %s" %
+ e)
+
+ if timeout == 0:
+ raise Exception("Ms is not comming up !")
+
+ time.sleep(cls.testdata["sleep"])
+ timeout = timeout - 1
+
+ list_local_storage_pool = StoragePool.list(
+ cls.apiclient,
+ scope='HOST',
+ zoneid=cls.zone.id,
+
+ )
+ if list_local_storage_pool is None:
+ raise Exception("Could not discover local storage pool")
+
+ try:
+ cls.account = Account.create(cls.apiclient,
+ cls.testdata["account"],
+ domainid=cls.domain.id
+ )
+ cls._cleanup.append(cls.account)
+
+ except Exception as e:
+ cls.tearDownClass()
+ raise e
+
+ return
+
+ @classmethod
+ def tearDownClass(cls):
+ try:
+ cleanup_resources(cls.apiclient, cls._cleanup)
+ except Exception as e:
+ raise Exception("Warning:Exception during cleanup: %s" % e)
+
+ @attr(tags=["advanced", "basic"])
+ @data(
+ 'consoleproxy',
+ 'secondarystoragevm',
+ 'domainrouter',
+ 'internalloadbalancervm')
+ def test_01_list_system_offerngs(self, value):
+ """List service offerings for systemvms and verify there should be two
+ (local and shared) SO for each system vm"""
+
+ list_custom_so = ServiceOffering.list(self.apiclient,
+ issystem='true',
+ listall='true',
+ systemvmtype=value
+ )
+
+ self.assertEqual(
+ validateList(list_custom_so)[0],
+ PASS,
+ "Check List service offerings response for %s" %
+ value)
+
+ local_custom_so = []
+ for item in list_custom_so:
+ if(str(item.defaultuse) == 'True'):
+ local_custom_so.append(item.storagetype)
+
+ self.assertEqual(
+ len(local_custom_so),
+ 2,
+ "Check default system offering for system vm type %s" % value)
+ if 'local' in local_custom_so and 'shared' in local_custom_so:
+ self.debug(
+ "there are exactly to Service offerings{share,local} are "
+ "there for system vm %s" %
+ value)
+ else:
+ raise Exception(
+ "check local and shared service offerings for %s" %
+ value)
+
+ @attr(tags=["advanced", "basic"])
+ @data('consoleproxy', 'secondarystoragevm')
+ def test_02_system_vm_storage(self, value):
+ """ Check if system vms are honouring zone level setting
+ system.vm.use.local.storage
+ 1-List zone level config
+ 2-update the zone level config with service offering uuid
+ 3-destroy system vms
+ 4-check used storage by system vms
+ """
+ # 1 List zone level config
+ if value == "consoleproxy":
+ update_global_settings(
+ self,
+ value=None,
+ name="consoleproxy.service.offering")
+
+ if value == "secondarystoragevm":
+ update_global_settings(
+ self,
+ value=None,
+ name="secstorage.service.offering")
+
+ list_conf = Configurations.list(self.apiclient,
+ name="system.vm.use.local.storage",
+ zoneid=self.zone.id)
+ self.assertEqual(
+ validateList(list_conf)[0],
+ PASS,
+ "Check List configuration response for "
+ "system.vm.use.local.storage")
+
+ val = str_to_bool(list_conf[0].value)
+ # 2 update the zone level config with service offering uuid
+ update_global_settings(self,
+ value=((str(not(val)).lower())),
+ name='system.vm.use.local.storage',
+ zoneid=self.zone.id)
+
+ # 3,4 for cpvm
+ destroy_systemvm(self, value)
+ storage_check(self, value, int(not(val)))
+
+ # 2 update the zone level config with service offering uuid
+ update_global_settings(
+ self,
+ value=(
+ str(val).lower()),
+ name='system.vm.use.local.storage',
+ zoneid=self.zone.id)
+ # 3,4 for cpvm
+ destroy_systemvm(self, value)
+ storage_check(self, value, int(val))
+
+ # 1 List zone level config
+ if value == "consoleproxy":
+ update_global_settings(
+ self,
+ value=None,
+ name="consoleproxy.service.offering")
+
+ if value == "secondarystoragevm":
+ update_global_settings(
+ self,
+ value=None,
+ name="secstorage.service.offering")
+
+ @attr(tags=["advanced", "basic"])
+ @data('consoleproxy', 'secondarystoragevm')
+ def test_03_custom_so(self, value):
+ """
+ update global setting with system offering and check if it is being
+ honoured
+ 1-update zone level settings "system.vm.use.local.storage={true,false}}
+ to use local storage
+ 2-create system offerings{shared,local}
+ 3-update global settings with system offering uuid and restart ms
+ 4-destroy system vms
+ 5-Check if new system vms are using offering updated in global
+ settings
+ """
+
+ # 1-update zone level settings "system.vm.use.local.storage"
+ # to use local storage
+ update_global_settings(
+ self,
+ value='true',
+ name='system.vm.use.local.storage',
+ zoneid=self.zone.id)
+ # 2-create system offerings
+
+ created_so_id = create_system_so(self, value, "shared")
+
+ if value == "consoleproxy":
+ name = "consoleproxy.service.offering"
+ elif value == 'secondarystoragevm':
+ name = 'secstorage.service.offering'
+ else:
+ raise Exception(
+ "type paramter is not correct it should be system vm "
+ "type{console proxy,secsroragevm}")
+
+ # 3-update global settings with system offering uuid
+ update_global_settings(self, value=created_so_id, name=name)
+
+ # 4-destroy system vms
+ destroy_systemvm(self, value)
+
+ # 5-Check if new system vms are using offering updated in global
+ # settings
+
+ query_zone_id = self.dbclient.execute(
+ "select id from data_center where uuid= '%s';" % self.zone.id
+ )
+ query_so_id = self.dbclient.execute(
+ "select service_offering_id from vm_instance where type='%s'and "
+ "state='Running' and data_center_id= '%s';" %
+ (value, query_zone_id[0][0]))
+ query_disk_offering = self.dbclient.execute(
+ "select uuid from disk_offering where id= '%s';" %
+ query_so_id[0][0])
+
+ self.assertEqual(
+ created_so_id,
+ query_disk_offering[0][0],
+ "system vms are not using service offering mentioned in "
+ "global settings")
+
+ # 6-repeate 1 with system.vm.use.local.storage=false
+ update_global_settings(
+ self,
+ value='false',
+ name='system.vm.use.local.storage',
+ zoneid=self.zone.id)
+ # 7-repeate 2 with storage type local
+ created_so_id = create_system_so(self, value, "local")
+ # 8-repeate 3
+ update_global_settings(self, value=created_so_id, name=name)
+
+ # 9-repeate 4
+ destroy_systemvm(self, value)
+ # repeate 5
+ query_zone_id = self.dbclient.execute(
+ "select id from data_center where uuid= '%s';" % self.zone.id
+ )
+ query_so_id = self.dbclient.execute(
+ "select service_offering_id from vm_instance where type='%s'and "
+ "state='Running' and data_center_id= '%s';" %
+ (value, query_zone_id[0][0]))
+ query_disk_offering = self.dbclient.execute(
+ "select uuid from disk_offering where id= '%s';" %
+ query_so_id[0][0])
+
+ self.assertEqual(
+ created_so_id,
+ query_disk_offering[0][0],
+ "system vms are not using service offering mentioned in"
+ " global settings")
+
+ @attr(tags=["advanced"])
+ def test_04_router_vms(self):
+ """ Check if router vm is honouring zone level setting
+ system.vm.use.local.storage"""
+
+ # 1-list configurations
+ list_conf = Configurations.list(self.apiclient,
+ name="system.vm.use.local.storage",
+ zoneid=self.zone.id)
+ self.assertEqual(
+ validateList(list_conf)[0],
+ PASS,
+ "Check List configuration response for "
+ "system.vm.use.local.storage")
+
+ # 2-create network offering
+ self.network_offering = NetworkOffering.create(
+ self.apiclient,
+ self.testdata["network_offering"],
+ ispersistent='true'
+ )
+
+ # 3-list netwrok offerings
+ list_nw_of = NetworkOffering.list(self.apiclient,
+ id=self.network_offering.id)
+ self.assertEqual(
+ validateList(list_nw_of)[0],
+ PASS,
+ "Check the list network response"
+ )
+ self.assertEqual(
+ str(list_nw_of[0].id),
+ str(self.network_offering.id),
+ "Check the created network offering id and "
+ "listed network offering id"
+ )
+ self._cleanup.append(self.network_offering)
+
+ # 4-Enable network offering
+ self.network_offering.update(self.apiclient, state='Enabled')
+
+ # 5-List network offering
+ list_nw_of1 = NetworkOffering.list(self.apiclient,
+ id=self.network_offering.id)
+ self.assertEqual(
+ validateList(list_nw_of1)[0],
+ PASS,
+ "Check the list network response"
+ )
+ self.assertEqual(
+ str(list_nw_of1[0].state),
+ "Enabled",
+ "Check the created network state"
+ )
+
+ # 6-crete network using network offering
+ self.network = Network.create(
+ self.apiclient,
+ self.testdata["network"],
+ networkofferingid=self.network_offering.id,
+ zoneid=self.zone.id,
+ accountid=self.account.name,
+ domainid=self.account.domainid
+ )
+ # 7-List network
+ list_network = Network.list(self.apiclient,
+ accountid=self.account.name,
+ domainid=self.account.domainid,
+ id=self.network.id)
+ self.assertEqual(validateList(list_network)[0],
+ PASS,
+ "check list netwok response ")
+ self.assertEqual(
+ list_network[0].id,
+ self.network.id,
+ "List network id %s and created network id %s does not match" %
+ (list_network[0].id,
+ self.network.id))
+
+ # 8-List router
+ list_router = Router.list(self.apiclient,
+ networkid=self.network.id,
+ accountid=self.account.name,
+ domainid=self.account.domainid)
+
+ self.assertEqual(
+ validateList(list_router)[0],
+ PASS,
+ "check list router response")
+
+ # 9-List service offerings
+ list_so = ServiceOffering.list(self.apiclient,
+ issystem='true',
+ id=list_router[0].serviceofferingid
+ )
+ self.assertEqual(
+ validateList(list_so)[0],
+ PASS,
+ "check list service offering response")
+ if list_conf[0].value == 'true':
+ storage_type = 'local'
+ value1 = 'false'
+ elif list_conf[0].value == 'false':
+ storage_type = 'shared'
+ value1 = 'true'
+ else:
+ raise Exception("check list_conf[0].value")
+ self.assertEqual(
+ list_so[0].storagetype,
+ storage_type,
+ "Check VR storage type and zone level settig"
+ )
+
+ # 10-Update zone level setting
+ update_global_settings(
+ self,
+ value=value1,
+ name="system.vm.use.local.storage",
+ zoneid=self.zone.id)
+
+ # 11-List configurations
+ list_conf1 = Configurations.list(self.apiclient,
+ name="system.vm.use.local.storage",
+ zoneid=self.zone.id)
+ self.assertEqual(
+ validateList(list_conf1)[0],
+ PASS,
+ "Check List configuration response for "
+ "system.vm.use.local.storage")
+
+ self.assertEqual(
+ list_conf1[0].value,
+ value1,
+ "Check the system.vm.use.local.storage value"
+ )
+ self.network.restart(self.apiclient,
+ cleanup='true'
+ )
+ # 12-List network
+ list_network1 = Network.list(self.apiclient,
+ accountid=self.account.name,
+ domainid=self.account.domainid,
+ id=self.network.id)
+ self.assertEqual(validateList(list_network1)[0],
+ PASS,
+ "check list netwok response ")
+
+ # 13-list VR
+ list_router1 = Router.list(self.apiclient,
+ networkid=list_network1[0].id,
+ accountid=self.account.name,
+ domainid=self.account.domainid)
+ self.assertEqual(
+ validateList(list_router1)[0],
+ PASS,
+ "check list router response"
+ )
+ # 14-list service offerings
+ list_so1 = ServiceOffering.list(self.apiclient,
+ issystem='true',
+ id=list_router1[0].serviceofferingid
+ )
+ self.assertEqual(
+ validateList(list_so1)[0],
+ PASS,
+ "check list service offering response"
+ )
+ if list_conf1[0].value == 'true':
+ storage_type1 = 'local'
+ elif list_conf1[0].value == 'false':
+ storage_type1 = 'shared'
+ else:
+ raise Exception("check list_conf[0].value")
+ self.assertEqual(
+ list_so1[0].storagetype,
+ storage_type1,
+ "Check VR storage type and zone level settings"
+ )
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/17366f2b/ui/dictionary2.jsp
----------------------------------------------------------------------
diff --git a/ui/dictionary2.jsp b/ui/dictionary2.jsp
index 862468e..20f698f 100644
--- a/ui/dictionary2.jsp
+++ b/ui/dictionary2.jsp
@@ -1014,6 +1014,7 @@ $.extend(dictionary, {
'state.detached': '<fmt:message key="state.detached" />',
'label.na': '<fmt:message key="label.na" />',
'label.added.network.offering': '<fmt:message key="label.added.network.offering" />',
-'label.no': '<fmt:message key="label.no" />'
+'label.no': '<fmt:message key="label.no" />',
+'label.local.storage.enabled.system.vms': '<fmt:message key="label.local.storage.enabled.system.vms" />'
});
</script>
[6/7] git commit: updated refs/heads/4.5-samlfixes to 69f39d5
Posted by bh...@apache.org.
CLOUDSTACK-8701: Allow users to switch across SAML account/domains from topbar
Moves the previous switch account logic to its own ui-custom module
Signed-off-by: Rohit Yadav <ro...@shapeblue.com>
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/37f30a60
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/37f30a60
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/37f30a60
Branch: refs/heads/4.5-samlfixes
Commit: 37f30a60e23cdaa35a65523ba6ec0654324a38c5
Parents: 8c51449
Author: Rohit Yadav <ro...@shapeblue.com>
Authored: Wed Aug 5 21:16:38 2015 +0530
Committer: Rohit Yadav <ro...@shapeblue.com>
Committed: Sun Aug 9 00:34:55 2015 +0530
----------------------------------------------------------------------
ui/css/cloudstack3.css | 6 +--
ui/index.jsp | 1 +
ui/scripts/ui-custom/saml.js | 96 +++++++++++++++++++++++++++++++++++++++
ui/scripts/ui/core.js | 77 -------------------------------
4 files changed, 100 insertions(+), 80 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/37f30a60/ui/css/cloudstack3.css
----------------------------------------------------------------------
diff --git a/ui/css/cloudstack3.css b/ui/css/cloudstack3.css
index ef33dea..06abbb8 100644
--- a/ui/css/cloudstack3.css
+++ b/ui/css/cloudstack3.css
@@ -9651,7 +9651,7 @@ div.container div.panel div#details-tab-addloadBalancer.detail-group div.loadBal
}
/*** View switcher (drop-down)*/
-.project-switcher {
+.project-switcher, .domain-switcher {
float: left;
width: 223px;
padding: 9px 17px 0 19px;
@@ -9662,7 +9662,7 @@ div.container div.panel div#details-tab-addloadBalancer.detail-group div.loadBal
border-radius: 4px;
}
-.project-switcher label {
+.project-switcher label, .domain-switcher label {
top: 29px;
color: #FFFFFF;
font-size: 13px;
@@ -9671,7 +9671,7 @@ div.container div.panel div#details-tab-addloadBalancer.detail-group div.loadBal
margin-top: 5px;
}
-.project-switcher select {
+.project-switcher select, .domain-switcher select {
width: 70%;
float: left;
margin-top: 0px;
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/37f30a60/ui/index.jsp
----------------------------------------------------------------------
diff --git a/ui/index.jsp b/ui/index.jsp
index 3b7d310..60f3cc3 100644
--- a/ui/index.jsp
+++ b/ui/index.jsp
@@ -1798,6 +1798,7 @@
<script type="text/javascript" src="scripts/docs.js?t=<%=now%>"></script>
<script type="text/javascript" src="scripts/vm_snapshots.js?t=<%=now%>"></script>
<script type="text/javascript" src="scripts/ui-custom/projectSelect.js?t=<%=now%>"></script>
+ <script type="text/javascript" src="scripts/ui-custom/saml.js?t=<%=now%>"></script>
<!-- Plugin/module API -->
<script type="text/javascript" src="scripts/ui-custom/pluginListing.js?t=<%=now%>"></script>
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/37f30a60/ui/scripts/ui-custom/saml.js
----------------------------------------------------------------------
diff --git a/ui/scripts/ui-custom/saml.js b/ui/scripts/ui-custom/saml.js
new file mode 100644
index 0000000..391e7f8
--- /dev/null
+++ b/ui/scripts/ui-custom/saml.js
@@ -0,0 +1,96 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+(function($, cloudStack) {
+ $(window).bind('cloudStack.ready', function() {
+ var showSamlDomainSwitcher = false;
+ if (g_idpList) {
+ showSamlDomainSwitcher = true;
+ }
+ if (!showSamlDomainSwitcher) {
+ return;
+ }
+
+ var $label = $('<label>').html('Domain:');
+ var $header = $('#header .controls');
+ var $domainSwitcher = $('<div>').addClass('domain-switcher');
+ var $domainSelect = $('<select>');
+ $domainSwitcher.append($label, $domainSelect);
+
+ var switchAccount = function(userId, domainId) {
+ var toReload = true;
+ $.ajax({
+ url: createURL('listAndSwitchSamlAccount'),
+ type: 'POST',
+ async: false,
+ data: {
+ userid: userId,
+ domainid: domainId
+ },
+ success: function(data, textStatus) {
+ document.location.reload(true);
+ },
+ error: function(data) {
+ cloudStack.dialog.notice({
+ message: parseXMLHttpResponse(data)
+ });
+ if (data.status !== 200) {
+ toReload = false;
+ }
+ },
+ complete: function() {
+ if (toReload) {
+ document.location.reload(true);
+ }
+ toReload = true;
+ }
+ });
+ };
+
+ $domainSelect.change(function() {
+ var selectedOption = $domainSelect.val();
+ var userId = selectedOption.split('/')[0];
+ var domainId = selectedOption.split('/')[1];
+ switchAccount(userId, domainId);
+ });
+
+ $.ajax({
+ url: createURL('listAndSwitchSamlAccount'),
+ success: function(json) {
+ var accounts = json.listandswitchsamlaccountresponse.samluseraccount;
+ if (accounts.length < 2) {
+ return;
+ };
+ $domainSelect.empty();
+ for (var i = 0; i < accounts.length; i++) {
+ var option = $('<option>');
+ option.data("userId", accounts[i].userId);
+ option.data("domainId", accounts[i].domainId);
+ option.val(accounts[i].userId + '/' + accounts[i].domainId);
+ option.html(accounts[i].accountName + "/" + accounts[i].domainName);
+ option.appendTo($domainSelect);
+ }
+ var currentAccountDomain = g_userid + '/' + g_domainid;
+ $domainSelect.find('option[value="' + currentAccountDomain + '"]').attr("selected", "selected");
+ $domainSwitcher.insertAfter($header.find('.region-switcher'));
+ },
+ error: function(data) {
+ // if call fails, the logged in user in not a SAML authenticated user
+ }
+ });
+ });
+}(jQuery, cloudStack));
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/37f30a60/ui/scripts/ui/core.js
----------------------------------------------------------------------
diff --git a/ui/scripts/ui/core.js b/ui/scripts/ui/core.js
index 26a5a1c..e64f386 100644
--- a/ui/scripts/ui/core.js
+++ b/ui/scripts/ui/core.js
@@ -304,83 +304,6 @@
})
.appendTo($('#user'));
- // Switch account option for SAML users
- if (g_idpList) {
- $.ajax({
- url: createURL('listAndSwitchSamlAccount'),
- success: function(json) {
- var accounts = json.listandswitchsamlaccountresponse.samluseraccount;
- if (accounts.length < 2) {
- return
- };
- var switchAccount = function() {
- var toReload = true;
- $.ajax({
- url: createURL('listAndSwitchSamlAccount'),
- type: 'POST',
- async: false,
- data: {
- userid: $(this).data("userId"),
- domainid: $(this).data("domainId")
- },
- success: function(data, textStatus) {
- document.location.reload(true);
- },
- error: function(data) {
- cloudStack.dialog.notice({
- message: parseXMLHttpResponse(data)
- });
- if (data.status !== 200) {
- toReload = false;
- }
- },
- complete: function() {
- if (toReload) {
- document.location.reload(true);
- }
- toReload = true;
- }
- });
- };
-
- $('<a>').attr({
- href: '#'
- })
- .text('Switch Account')
- .appendTo($options).click(function() {
- var $switchSamlAccount = $('<div>');
- for (var i = 0; i < accounts.length; i++) {
- var item = $('<a>').html(accounts[i].accountName + "/" + accounts[i].domainName);
- item.data("userId", accounts[i].userId);
- item.data("domainId", accounts[i].domainId);
- item.click(switchAccount);
- item.appendTo($switchSamlAccount);
- item.attr("href", "#");
- $('<br>').appendTo($switchSamlAccount);
- }
- $switchSamlAccount.dialog({
- modal: true,
- width: 400,
- title: 'Switch Account',
- closeOnEscape: false,
- dialogClass: 'dialog-about',
- buttons: {
- 'Close': function() {
- $(this).dialog("close");
- $(':ui-dialog, .overlay').remove();
- }
- }
- }).closest('.ui-dialog').overlay();
-
- return false;
- });
- },
- error: function(data) {
- }
- });
- }
-
-
$(['label.logout', 'label.help', 'label.about']).each(function() {
var $link = $('<a>')
.attr({