Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LPS-57980 #29450

Closed
wants to merge 12 commits into from
1 change: 1 addition & 0 deletions modules/apps/export-import/export-import-test/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ dependencies {
compile project(":apps:export-import:export-import-service")
compile project(":apps:journal:journal-content-web")
compile project(":apps:journal:journal-test")
compile project(":portal:portal-background-task-service")

testCompile group: "com.liferay", name: "com.liferay.arquillian.extension.junit.bridge", version: "1.0.0-SNAPSHOT"
testCompile group: "com.liferay", name: "com.liferay.dynamic.data.mapping.test.util", version: "1.0.0-SNAPSHOT"
Expand Down
2 changes: 1 addition & 1 deletion modules/apps/export-import/export-import-test/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<!DOCTYPE project>

<project>
<property name="import.shared" value="export-import-service,../bookmarks/bookmarks-test,../journal/journal-content-web,../journal/journal-test" />
<property name="import.shared" value="export-import-service,../bookmarks/bookmarks-test,../journal/journal-content-web,../journal/journal-test,../../portal/portal-background-task-service" />

<import file="../../../../tools/sdk/build-common-osgi-plugin.xml" />
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import com.liferay.portal.NoSuchGroupException;
import com.liferay.portal.NoSuchLayoutException;
import com.liferay.portal.NoSuchLayoutSetException;
import com.liferay.portal.backgroundtask.messaging.BackgroundTaskMessageListener;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.test.rule.AggregateTestRule;
Expand Down Expand Up @@ -163,7 +162,8 @@ public void testFailedLayoutImport() throws Exception {
public void testFailedLayoutLocalPublishing() throws Exception {
try (CaptureAppender captureAppender =
Log4JLoggerTestUtil.configureLog4JLogger(
BackgroundTaskMessageListener.class.getName(),
"com.liferay.portal.background.task.internal.messaging." +
"BackgroundTaskMessageListener",
Level.ERROR)) {

StagingUtil.publishLayouts(
Expand Down Expand Up @@ -266,7 +266,8 @@ public void testFailedPortletLocalPublishing() throws Exception {

try (CaptureAppender captureAppender =
Log4JLoggerTestUtil.configureLog4JLogger(
BackgroundTaskMessageListener.class.getName(),
"com.liferay.portal.background.task.internal.messaging." +
"BackgroundTaskMessageListener",
Level.ERROR)) {

StagingUtil.publishPortlet(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,40 @@
* details.
*/

package com.liferay.portal.backgroundtask;
package com.liferay.portal.background.task.internal;

import com.liferay.portal.kernel.backgroundtask.BackgroundTaskManagerUtil;
import com.liferay.portal.kernel.backgroundtask.BackgroundTaskManager;
import com.liferay.portal.kernel.cluster.BaseClusterMasterTokenTransitionListener;
import com.liferay.portal.kernel.cluster.ClusterMasterTokenTransitionListener;

import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;

/**
* @author Michael C. Han
*/
@Component(
immediate = true, service = ClusterMasterTokenTransitionListener.class
)
public class BackgroundTaskClusterMasterTokenTransitionListener
extends BaseClusterMasterTokenTransitionListener {

@Reference(unbind = "-")
public void setBackgroundTaskManager(
BackgroundTaskManager backgroundTaskManager) {

_backgroundTaskManager = backgroundTaskManager;
}

@Override
protected void doMasterTokenAcquired() throws Exception {
BackgroundTaskManagerUtil.cleanUpBackgroundTasks();
_backgroundTaskManager.cleanUpBackgroundTasks();
}

@Override
protected void doMasterTokenReleased() throws Exception {
}

private BackgroundTaskManager _backgroundTaskManager;

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
import com.liferay.portal.kernel.backgroundtask.BackgroundTask;
import com.liferay.portal.kernel.backgroundtask.BackgroundTaskManager;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.messaging.DestinationConfiguration;
import com.liferay.portal.kernel.util.ClassUtil;
import com.liferay.portal.kernel.util.HashMapDictionary;
import com.liferay.portal.kernel.util.OrderByComparator;
import com.liferay.portal.service.ServiceContext;
import com.liferay.portlet.backgroundtask.util.comparator.BackgroundTaskCompletionDateComparator;
Expand All @@ -30,10 +32,16 @@

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Deactivate;
import org.osgi.service.component.annotations.Reference;

/**
Expand Down Expand Up @@ -423,6 +431,48 @@ public void triggerBackgroundTask(long backgroundTaskId) {
_backgroundTaskLocalService.triggerBackgroundTask(backgroundTaskId);
}

@Activate
protected void activate(BundleContext bundleContext) {
_bundleContext = bundleContext;

ServiceRegistration<DestinationConfiguration>
backgroundTaskServiceRegistration = registerDestinationConfig(
DestinationConfiguration.DESTINATION_TYPE_PARALLEL,
"liferay/background_task");

_serviceRegistrations.add(backgroundTaskServiceRegistration);

ServiceRegistration<DestinationConfiguration>
backgroundTaskStatusServiceRegistration = registerDestinationConfig(
DestinationConfiguration.DESTINATION_TYPE_PARALLEL,
"liferay/background_task_status");

_serviceRegistrations.add(backgroundTaskStatusServiceRegistration);
}

@Deactivate
protected void deactivate() {
for (ServiceRegistration<DestinationConfiguration> serviceRegistration :
_serviceRegistrations) {

serviceRegistration.unregister();
}

_bundleContext = null;
}

protected ServiceRegistration<DestinationConfiguration>
registerDestinationConfig(
String destinationType, String destinationName) {

DestinationConfiguration destinationConfiguration =
new DestinationConfiguration(destinationType, destinationName);

return _bundleContext.registerService(
DestinationConfiguration.class, destinationConfiguration,
new HashMapDictionary<String, Object>());
}

@Reference(unbind = "-")
protected void setBackgroundTaskLocalService(
BackgroundTaskLocalService backgroundTaskLocalService) {
Expand Down Expand Up @@ -475,5 +525,8 @@ else if (orderByComparator instanceof
}

private BackgroundTaskLocalService _backgroundTaskLocalService;
private BundleContext _bundleContext;
private final Set<ServiceRegistration<DestinationConfiguration>>
_serviceRegistrations = new HashSet<>();

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
* details.
*/

package com.liferay.portal.backgroundtask;
package com.liferay.portal.background.task.internal;

import com.liferay.portal.kernel.backgroundtask.BackgroundTaskStatus;
import com.liferay.portal.kernel.backgroundtask.BackgroundTaskStatusRegistry;
import com.liferay.portal.kernel.backgroundtask.BackgroundTaskStatusRegistryUtil;
import com.liferay.portal.kernel.cluster.ClusterMasterExecutorUtil;
import com.liferay.portal.kernel.cluster.ClusterMasterExecutor;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.util.MethodHandler;
Expand All @@ -29,15 +29,19 @@
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;

import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;

/**
* @author Michael C. Han
*/
@Component(immediate = true, service = BackgroundTaskStatusRegistry.class)
public class BackgroundTaskStatusRegistryImpl
implements BackgroundTaskStatusRegistry {

@Override
public BackgroundTaskStatus getBackgroundTaskStatus(long backgroundTaskId) {
if (!ClusterMasterExecutorUtil.isMaster()) {
if (!_clusterMasterExecutor.isMaster()) {
return getMasterBackgroundTaskStatus(backgroundTaskId);
}

Expand Down Expand Up @@ -108,7 +112,7 @@ protected BackgroundTaskStatus getMasterBackgroundTaskStatus(
backgroundTaskId);

Future<BackgroundTaskStatus> future =
ClusterMasterExecutorUtil.executeOnMaster(methodHandler);
_clusterMasterExecutor.executeOnMaster(methodHandler);

return future.get();
}
Expand All @@ -119,11 +123,19 @@ protected BackgroundTaskStatus getMasterBackgroundTaskStatus(
return null;
}

@Reference(unbind = "-")
protected void setClusterMasterExecutor(
ClusterMasterExecutor clusterMasterExecutor) {

_clusterMasterExecutor = clusterMasterExecutor;
}

private static final Log _log = LogFactoryUtil.getLog(
BackgroundTaskStatusRegistryImpl.class);

private final Map<Long, BackgroundTaskStatus> _backgroundTaskStatuses =
new HashMap<>();
private ClusterMasterExecutor _clusterMasterExecutor;
private final ReadWriteLock _readWriteLock = new ReentrantReadWriteLock();

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* details.
*/

package com.liferay.portal.backgroundtask;
package com.liferay.portal.background.task.internal;

import com.liferay.portal.kernel.backgroundtask.BackgroundTaskThreadLocalManager;
import com.liferay.portal.kernel.cluster.ClusterInvokeThreadLocal;
Expand All @@ -27,17 +27,21 @@
import com.liferay.portal.security.permission.PermissionChecker;
import com.liferay.portal.security.permission.PermissionCheckerFactory;
import com.liferay.portal.security.permission.PermissionThreadLocal;
import com.liferay.portal.service.UserLocalServiceUtil;
import com.liferay.portal.service.UserLocalService;

import java.io.Serializable;

import java.util.HashMap;
import java.util.Locale;
import java.util.Map;

import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;

/**
* @author Michael C. Han
*/
@Component(immediate = true, service = BackgroundTaskThreadLocalManager.class)
public class BackgroundTaskThreadLocalManagerImpl
implements BackgroundTaskThreadLocalManager {

Expand Down Expand Up @@ -92,12 +96,6 @@ public void serializeThreadLocals(
taskContextThreadLocalValues.putAll(currentThreadLocalValues);
}

public void setPermissionCheckerFactory(
PermissionCheckerFactory permissionCheckerFactory) {

_permissionCheckerFactory = permissionCheckerFactory;
}

@Override
public void setThreadLocalValues(
Map<String, Serializable> threadLocalValues) {
Expand Down Expand Up @@ -139,7 +137,7 @@ public void setThreadLocalValues(

if (Validator.isNotNull(principalName)) {
try {
User user = UserLocalServiceUtil.fetchUser(
User user = _userLocalService.fetchUser(
PrincipalThreadLocal.getUserId());

PermissionChecker permissionChecker =
Expand Down Expand Up @@ -167,8 +165,21 @@ public void setThreadLocalValues(
}
}

@Reference(unbind = "-")
protected void setPermissionCheckerFactory(
PermissionCheckerFactory permissionCheckerFactory) {

_permissionCheckerFactory = permissionCheckerFactory;
}

@Reference(unbind = "-")
protected void setUserLocalService(UserLocalService userLocalService) {
_userLocalService = userLocalService;
}

protected static final String KEY_THREAD_LOCAL_VALUES = "threadLocalValues";

private PermissionCheckerFactory _permissionCheckerFactory;
private UserLocalService _userLocalService;

}