Skip to content

Commit

Permalink
Merge pull request #3826 from HiranyaKavishani/4.9.x-new2
Browse files Browse the repository at this point in the history
[Port] 4.8.x fixes into 4.9.x
  • Loading branch information
HiranyaKavishani authored Feb 6, 2024
2 parents 2c0e328 + 1232ce6 commit 3553275
Show file tree
Hide file tree
Showing 24 changed files with 249 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,15 @@
import javax.management.QueryExp;
import java.io.File;
import java.lang.management.ManagementPermission;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

/**
* Class for handling Server management functionalilty.
Expand Down Expand Up @@ -75,13 +81,44 @@ public void startMaintenance() throws Exception {
secMan.checkPermission(new ManagementPermission("control"));
}
log.info("Starting to switch to maintenance mode...");
stopTransportListeners();
destroyTransportListeners();
waitForRequestCompletion();
}

/**
* Stop Transport Listeners asynchronously and wait for the completion of the tasks
*/
private void stopTransportListeners() {
ExecutorService transportListenerShutdownPool = Executors.newFixedThreadPool(inTransports.size());
List<Future<Void>> listenerShutdownFutures = new ArrayList<>();
for (TransportInDescription tinDesc : inTransports.values()) {
TransportListener transport = tinDesc.getReceiver();
transport.stop();
Future<Void> future = transportListenerShutdownPool.submit(new TransportListenerShutdownTask(transport));
listenerShutdownFutures.add(future);
}

// Wait until shutting down the transport listeners before proceeding
for (Future<Void> future : listenerShutdownFutures) {
try {
future.get();
} catch (Exception e) {
log.error("Error while completing transport listener shutdown", e);
}
}
transportListenerShutdownPool.shutdown();
log.info("Stopped all transport listeners");
}

waitForRequestCompletion();
/**
* Destroy Transport Listeners
*/
private void destroyTransportListeners() {
// Destroy the TransportListener at the end to clear up resources
for (TransportInDescription tinDesc : inTransports.values()) {
TransportListener transport = tinDesc.getReceiver();
transport.destroy();
}
}

/**
Expand Down Expand Up @@ -264,4 +301,24 @@ public void endMaintenance() throws Exception {
}
log.info("Switched to normal mode");
}

/**
* Callable task to pause and shutdown a transport listener
*/
private class TransportListenerShutdownTask implements Callable<Void> {
private TransportListener transport;

public TransportListenerShutdownTask(TransportListener transport) {
this.transport = transport;
}

public Void call() throws Exception {
try {
transport.stop();
} catch (Exception e) {
log.error("Error while stopping Transport Listener", e);
}
return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package org.wso2.carbon.core.multitenancy.eager;

import org.apache.axis2.context.ConfigurationContext;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.context.PrivilegedCarbonContext;
Expand All @@ -30,6 +31,8 @@
import java.util.Arrays;
import java.util.List;

import static org.wso2.carbon.CarbonConstants.EAGER_LOADING;

/**
* This class responsible of processing/validating and load once server startup completed.
*/
Expand Down Expand Up @@ -88,8 +91,10 @@ private void loadTenants(List<String> validTenantDomains) {
PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
ctx.setTenantDomain(tenantDomain, true);
TenantAxisUtils
ConfigurationContext tenantConfigurationContext = TenantAxisUtils
.getTenantConfigurationContext(tenantDomain, carbonCoreDataHolder.getMainServerConfigContext());
// Set the eager loading property to the tenant configuration context
tenantConfigurationContext.setProperty(EAGER_LOADING, true);
} catch (OutOfMemoryError e) {
// If OutOfMemoryError during tenant loading we will throw a RuntimeException to notify server admin
String msg = "OutOfMemoryError while Eager loading tenant : " + tenantDomain;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,8 @@ public InvocationResponse invoke(MessageContext msgContext) throws AxisFault
superTenantOutMessageContext.setProperty(MultitenantConstants.COPY_CONTENT_LENGTH_FROM_INCOMING,
contentLengthCopy);


superTenantOutMessageContext.setProperty(MultitenantConstants.CORRELATION_ID,
msgContext.getProperty(MultitenantConstants.CORRELATION_ID));

superTenantOutMessageContext.setProperty(Constants.Configuration.MESSAGE_TYPE,
msgContext.getProperty(Constants.Configuration.MESSAGE_TYPE));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import org.wso2.carbon.registry.core.session.UserRegistry;
import org.wso2.carbon.user.core.tenant.Tenant;
import org.wso2.carbon.user.core.tenant.TenantManager;
import org.wso2.carbon.user.core.util.DatasourceDataHolder;
import org.wso2.carbon.utils.Axis2ConfigurationContextObserver;
import org.wso2.carbon.utils.CarbonUtils;
import org.wso2.carbon.utils.ServerConstants;
Expand All @@ -72,6 +73,8 @@
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantReadWriteLock;

import static org.wso2.carbon.CarbonConstants.EAGER_LOADING;

/**
* Utility methods for Tenant Operations at Axis2-level.
*/
Expand All @@ -81,6 +84,7 @@ public final class TenantAxisUtils {
private static final Log log = LogFactory.getLog(TenantAxisUtils.class);
private static final String TENANT_CONFIGURATION_CONTEXTS = "tenant.config.contexts";
private static final String TENANT_CONFIGURATION_CONTEXTS_CREATED = "tenant.config.contexts.created";
private static final String ILLEGAL_CHARACTERS_FOR_TENANT_DOMAIN = ".*[^a-z0-9\\._\\-].*";
private static CarbonCoreDataHolder dataHolder = CarbonCoreDataHolder.getInstance();
private static Map<String, ReentrantReadWriteLock> tenantReadWriteLocks =
new ConcurrentHashMap<String, ReentrantReadWriteLock>();
Expand Down Expand Up @@ -119,6 +123,12 @@ public static AxisConfiguration getTenantAxisConfiguration(String tenant,
ConfigurationContext tenantConfigCtx;

Boolean isTenantActive;
if (tenantDomain != null && tenantDomain.matches(ILLEGAL_CHARACTERS_FOR_TENANT_DOMAIN)) {
String errorMsg = "The tenant domain ' " + tenantDomain +
" ' contains one or more illegal characters. The valid characters are " +
"lowercase letters, numbers, '.', '-' and '_'.";
throw new RuntimeException(errorMsg);
}
try {
isTenantActive = CarbonCoreDataHolder.getInstance().getRealmService().getTenantManager().
isTenantActive(getTenantId(tenantDomain));
Expand Down Expand Up @@ -440,6 +450,11 @@ public static void cleanupTenants(long tenantIdleTimeMillis) {
String tenantDomain = entry.getKey();
synchronized (tenantDomain.intern()) {
ConfigurationContext tenantCfgCtx = entry.getValue();
// Get the Eager Loading tenant property from the tenant configuration context
Object eagerLoadingTenant = tenantCfgCtx.getProperty(EAGER_LOADING);
if (eagerLoadingTenant != null && (boolean) eagerLoadingTenant) {
continue;
}
Long lastAccessed =
(Long) tenantCfgCtx.getProperty(MultitenantConstants.LAST_ACCESSED);
if (System.currentTimeMillis() - lastAccessed >= tenantIdleTimeMillis) {
Expand All @@ -466,6 +481,10 @@ public static void cleanupTenants(long tenantIdleTimeMillis) {
}
}
tenantConfigContexts.remove(tenantDomain);
// removing cached datasources of the domain
DatasourceDataHolder.removeDatasourcesOfTenant(getTenantId(tenantDomain));
} catch (Exception e) {
log.error("Error occurred while fetching the tenant details");
} finally {
PrivilegedCarbonContext.endTenantFlow();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,10 @@ carbon.server.home={0} Home
carbon.console.welcome=Welcome to the {0} Management Console
user.guide=User Guide
user.guide.text=WSO2 Carbon user guide.
forum=Forum
forum.text=The interactive message board for sharing information, questions and comments about WSO2 products.
forum=Community
forum.text=To foster a healthy community through open collaboration and feedback to help each developer and teams.
issue.tracker=Issue Tracker
issue.tracker.text=Users are encouraged to report issues & suggest improvements using the JIRA issue tracker. In addition, users can observe the status of the reported issues in progress.
mailing.list=Mailing Lists
mailing.list.text=Report issues, provide feedback & get help from our mailing lists.
issue.tracker.text=Users are encouraged to report issues & suggest improvements using the issue tracker. In addition, users can observe the status of the reported issues in progress.

### login page ###
backendURL=Server URL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package org.wso2.carbon.ndatasource.rdbms;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.ndatasource.common.DataSourceException;
import org.wso2.carbon.ndatasource.common.spi.DataSourceReader;
import org.wso2.carbon.utils.CarbonUtils;
Expand All @@ -33,6 +35,8 @@
* This class represents the RDBMS based data source reader implementation.
*/
public class RDBMSDataSourceReader implements DataSourceReader {

private static Log log = LogFactory.getLog(RDBMSDataSourceReader.class);

@Override
public String getType() {
Expand Down Expand Up @@ -64,6 +68,10 @@ public Object createDataSource(String xmlConfiguration, boolean isDataSourceFact
(rdbmsConfiguration.getUrl().toLowerCase().contains(";init="))) {
throw new DataSourceException(
"INIT expressions are not allowed in the connection URL due to security reasons.");
}
if (log.isDebugEnabled()) {
log.debug("Database URL : " + rdbmsConfiguration.getUrl());
log.debug("Database Driver : " + rdbmsConfiguration.getDriverClassName());
}
if (isDataSourceFactoryReference) {
return (new RDBMSDataSource(rdbmsConfiguration).getDataSourceFactoryReference());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@ public boolean execute(HttpServletRequest request,
log.error("File upload failed", e);
out.write("<script type=\"text/javascript\" src=\"../ds/extensions/core/js/data_service.js\"></script>");
out.write("<script type=\"text/javascript\">" +
"alert('Service file upload FAILED. You will be redirected to file upload screen. Reason :" +
e.getMessage().replaceFirst(",","") + "');" +
"alert('Service file upload FAILED. You will be redirected to file upload screen.');" +
"loadDBSFileUploadPage();"+ //available in data_service.js
"</script>");
}
Expand Down
18 changes: 0 additions & 18 deletions core/org.wso2.carbon.ui/src/main/resources/web/admin/login.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ String userForumURL =
String userGuideURL =
(String) config.getServletContext().getAttribute(CarbonConstants.PRODUCT_XML_WSO2CARBON +
CarbonConstants.PRODUCT_XML_USERGUIDE);
String mailinglistURL =
(String) config.getServletContext().getAttribute(CarbonConstants.PRODUCT_XML_WSO2CARBON +
CarbonConstants.PRODUCT_XML_MAILINGLIST);
String issuetrackerURL =
(String) config.getServletContext().getAttribute(CarbonConstants.PRODUCT_XML_WSO2CARBON +
CarbonConstants.PRODUCT_XML_ISSUETRACKER);
Expand All @@ -44,9 +41,6 @@ if(userForumURL == null){
if(userGuideURL == null){
userGuideURL = "#";
}
if(mailinglistURL == null){
mailinglistURL = "#";
}
if(issuetrackerURL == null){
issuetrackerURL = "#";
}
Expand Down Expand Up @@ -175,18 +169,6 @@ if (CharacterEncoder.getSafeText(request.getParameter("skipLoginPage"))!=null){

</td>
</tr>
<tr class="feature">
<td>
<a target="_blank" href="<%=mailinglistURL %>" rel="noopener noreferrer"><img
src="../admin/images/mailing-list.gif"/></a>
</td>
<td>
<h3><a target="_blank" href="<%=mailinglistURL %>" rel="noopener noreferrer">
<fmt:message key="mailing.list"/></a></h3>

<p><fmt:message key="mailing.list.text"/></p>
</td>
</tr>
</table>
</div>
</td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@
import org.wso2.carbon.user.core.config.UserStoreConfigXMLProcessor;
import org.wso2.carbon.user.core.tenant.TenantCache;
import org.wso2.carbon.user.core.tenant.TenantIdKey;
import org.wso2.carbon.user.core.util.DatasourceDataHolder;
import org.wso2.carbon.user.core.util.UserCoreUtil;

import java.io.File;
import java.util.AbstractMap;
import java.util.regex.Pattern;

public class UserStoreDeploymentManager {
Expand Down Expand Up @@ -165,6 +167,10 @@ public void undeploy(String fileName) throws DeploymentException {

if (!isDisabled) {
userStoreManager.removeSecondaryUserStoreManager(domainName);
DatasourceDataHolder dataHolder = DatasourceDataHolder.getInstance();
AbstractMap.SimpleEntry<String, String> key
= new AbstractMap.SimpleEntry<>(String.valueOf(tenantId), domainName.toUpperCase());
dataHolder.removeDomainDataSources(key);
}
} catch (Exception ex) {
String errorMessage = "Error occurred at undeploying " + domainName + " from tenant:" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import org.wso2.carbon.user.core.profile.ProfileConfigurationManager;
import org.wso2.carbon.user.core.tenant.Tenant;
import org.wso2.carbon.user.core.util.DatabaseUtil;
import org.wso2.carbon.user.core.util.DatasourceDataHolder;
import org.wso2.carbon.user.core.util.JDBCRealmUtil;
import org.wso2.carbon.user.core.util.UserCoreUtil;
import org.wso2.carbon.utils.Secret;
Expand All @@ -71,6 +72,7 @@
import java.sql.SQLIntegrityConstraintViolationException;
import java.sql.SQLTimeoutException;
import java.sql.Timestamp;
import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
Expand Down Expand Up @@ -116,7 +118,7 @@ public class JDBCUserStoreManager extends AbstractUserStoreManager {
private static final String MYSQL = "mysql";
private static final String MARIADB = "mariadb";
private static final String POSTGRESQL = "postgresql";

public static final String PRIMARY_USER_STORE_DOMAIN = "PRIMARY";
private static final int MAX_ITEM_LIMIT_UNLIMITED = -1;

public JDBCUserStoreManager() {
Expand Down Expand Up @@ -293,9 +295,16 @@ public JDBCUserStoreManager(RealmConfiguration realmConfig, Map<String, Object>
}
this.claimManager = claimManager;
this.userRealm = realm;

boolean addDataStore = false;
// cache secondary user-store datasources.
String domain = getMyDomainName();
AbstractMap.SimpleEntry<String, String> key = new AbstractMap.SimpleEntry<>(String.valueOf(tenantId), domain);
jdbcds = DatasourceDataHolder.getInstance().getDataStoreForDomain(key);
try {
jdbcds = loadUserStoreSpacificDataSoruce();
if (jdbcds == null) {
addDataStore = !(PRIMARY_USER_STORE_DOMAIN.equals(domain) || tenantId == MultitenantConstants.SUPER_TENANT_ID);
jdbcds = loadUserStoreSpacificDataSoruce();
}

if (jdbcds == null) {
jdbcds = (DataSource) properties.get(UserCoreConstants.DATA_SOURCE);
Expand All @@ -305,6 +314,10 @@ public JDBCUserStoreManager(RealmConfiguration realmConfig, Map<String, Object>
properties.put(UserCoreConstants.DATA_SOURCE, jdbcds);
}

if (addDataStore) {
DatasourceDataHolder.getInstance().addDataSourceForDomain(key, jdbcds);
}

if (log.isDebugEnabled()) {
log.debug("The jdbcDataSource being used by JDBCUserStoreManager :: "
+ jdbcds.hashCode());
Expand Down
Loading

0 comments on commit 3553275

Please sign in to comment.