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
Use workspace limit idle timeout value in WorkspaceActivityManager #9395
Changes from 5 commits
e288d3e
476e954
38567ea
d03e9c6
2842b46
f51b0f5
f5d1edc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
|
||
Copyright (c) 2012-2018 Red Hat, Inc. | ||
All rights reserved. This program and the accompanying materials | ||
are made available under the terms of the Eclipse Public License v1.0 | ||
which accompanies this distribution, and is available at | ||
http://www.eclipse.org/legal/epl-v10.html | ||
|
||
Contributors: | ||
Red Hat, Inc. - initial API and implementation | ||
|
||
--> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<artifactId>che-multiuser-api</artifactId> | ||
<groupId>org.eclipse.che.multiuser</groupId> | ||
<version>6.4.0-SNAPSHOT</version> | ||
</parent> | ||
<artifactId>che-multiuser-api-workspace-activity</artifactId> | ||
<packaging>jar</packaging> | ||
<name>Che Multiuser :: Workspace Activity</name> | ||
<dependencies> | ||
<dependency> | ||
<groupId>com.google.inject</groupId> | ||
<artifactId>guice</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.eclipse.che.core</groupId> | ||
<artifactId>che-core-api-account</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.eclipse.che.core</groupId> | ||
<artifactId>che-core-api-core</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.eclipse.che.core</groupId> | ||
<artifactId>che-core-api-workspace</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.eclipse.che.core</groupId> | ||
<artifactId>che-core-api-workspace-activity</artifactId> | ||
<version>6.4.0-SNAPSHOT</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.eclipse.che.multiuser</groupId> | ||
<artifactId>che-multiuser-api-resource</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.eclipse.che.multiuser</groupId> | ||
<artifactId>che-multiuser-api-resource</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.eclipse.che.multiuser</groupId> | ||
<artifactId>che-multiuser-api-resource-shared</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-api</artifactId> | ||
</dependency> | ||
</dependencies> | ||
</project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* | ||
* Copyright (c) 2012-2018 Red Hat, Inc. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
*/ | ||
package org.eclipse.che.multiuser.api.workspace.activity; | ||
|
||
import com.google.inject.Inject; | ||
import com.google.inject.Singleton; | ||
import com.google.inject.name.Named; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import org.eclipse.che.account.api.AccountManager; | ||
import org.eclipse.che.account.shared.model.Account; | ||
import org.eclipse.che.api.core.NotFoundException; | ||
import org.eclipse.che.api.core.ServerException; | ||
import org.eclipse.che.api.core.notification.EventService; | ||
import org.eclipse.che.api.workspace.activity.WorkspaceActivityDao; | ||
import org.eclipse.che.api.workspace.activity.WorkspaceActivityManager; | ||
import org.eclipse.che.api.workspace.server.WorkspaceManager; | ||
import org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl; | ||
import org.eclipse.che.multiuser.resource.api.type.TimeoutResourceType; | ||
import org.eclipse.che.multiuser.resource.api.usage.ResourceManager; | ||
import org.eclipse.che.multiuser.resource.model.Resource; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* Implementation of WorkspaceActivityManager with overriden retrieval of timeout, with using | ||
* Resource API to get user's limits | ||
* | ||
* @author Mykhailo Kuznietsov | ||
*/ | ||
@Singleton | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. test? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. test added |
||
public class MultiUserWorkspaceActivityManager extends WorkspaceActivityManager { | ||
|
||
private static final Logger LOG = | ||
LoggerFactory.getLogger(MultiUserWorkspaceActivityManager.class); | ||
|
||
private final AccountManager accountManager; | ||
private final ResourceManager resourceManager; | ||
private final long defaultTimeout; | ||
|
||
@Inject | ||
public MultiUserWorkspaceActivityManager( | ||
WorkspaceManager workspaceManager, | ||
WorkspaceActivityDao activityDao, | ||
EventService eventService, | ||
AccountManager accountManager, | ||
ResourceManager resourceManager, | ||
@Named("che.limits.workspace.idle.timeout") long defaultTimeout) { | ||
super(workspaceManager, activityDao, eventService, defaultTimeout); | ||
this.accountManager = accountManager; | ||
this.resourceManager = resourceManager; | ||
this.defaultTimeout = defaultTimeout; | ||
} | ||
|
||
@Override | ||
protected long getIdleTimeout(String wsId) { | ||
List<? extends Resource> availableResources; | ||
try { | ||
WorkspaceImpl workspace = workspaceManager.getWorkspace(wsId); | ||
Account account = accountManager.getByName(workspace.getNamespace()); | ||
availableResources = resourceManager.getAvailableResources(account.getId()); | ||
|
||
} catch (NotFoundException | ServerException e) { | ||
LOG.error(e.getLocalizedMessage(), e); | ||
return defaultTimeout; | ||
} | ||
Optional<? extends Resource> timeoutOpt = | ||
availableResources | ||
.stream() | ||
.filter(resource -> TimeoutResourceType.ID.equals(resource.getType())) | ||
.findAny(); | ||
|
||
if (timeoutOpt.isPresent()) { | ||
return timeoutOpt.get().getAmount() * 60 * 1000; | ||
} else { | ||
return defaultTimeout; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright (c) 2012-2018 Red Hat, Inc. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
*/ | ||
package org.eclipse.che.multiuser.api.workspace.activity; | ||
|
||
import com.google.inject.AbstractModule; | ||
import org.eclipse.che.api.workspace.activity.JpaWorkspaceActivityDao; | ||
import org.eclipse.che.api.workspace.activity.WorkspaceActivityDao; | ||
import org.eclipse.che.api.workspace.activity.WorkspaceActivityManager; | ||
import org.eclipse.che.api.workspace.activity.WorkspaceActivityService; | ||
|
||
/** | ||
* Implementation of | ||
* | ||
* @author Mykhailo Kuznietsov | ||
*/ | ||
public class MultiUserWorkspaceActivityModule extends AbstractModule { | ||
|
||
@Override | ||
protected void configure() { | ||
bind(WorkspaceActivityService.class); | ||
bind(WorkspaceActivityDao.class).to(JpaWorkspaceActivityDao.class); | ||
bind(WorkspaceActivityManager.class).to(MultiUserWorkspaceActivityManager.class); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,7 +48,7 @@ public class WorkspaceActivityManager { | |
|
||
private static final String ACTIVITY_CHECKER = "activity-checker"; | ||
|
||
private final long timeout; | ||
private final long defaultTimeout; | ||
private final WorkspaceActivityDao activityDao; | ||
private final EventService eventService; | ||
private final EventSubscriber<?> workspaceEventsSubscriber; | ||
|
@@ -60,11 +60,11 @@ public WorkspaceActivityManager( | |
WorkspaceManager workspaceManager, | ||
WorkspaceActivityDao activityDao, | ||
EventService eventService, | ||
@Named("che.workspace.agent.dev.inactive_stop_timeout_ms") long timeout) { | ||
this.timeout = timeout > 0 ? timeout : -1; | ||
@Named("che.limits.workspace.idle.timeout") long timeout) { | ||
this.workspaceManager = workspaceManager; | ||
this.eventService = eventService; | ||
this.activityDao = activityDao; | ||
this.defaultTimeout = timeout; | ||
this.workspaceEventsSubscriber = | ||
new EventSubscriber<WorkspaceStatusEvent>() { | ||
@Override | ||
|
@@ -104,15 +104,20 @@ public void onEvent(WorkspaceStatusEvent event) { | |
* @param activityTime moment in which the activity occurred | ||
*/ | ||
public void update(String wsId, long activityTime) { | ||
if (timeout > 0) { | ||
try { | ||
try { | ||
long timeout = getIdleTimeout(wsId); | ||
if (timeout > 0) { | ||
activityDao.setExpiration(new WorkspaceExpiration(wsId, activityTime + timeout)); | ||
} catch (ServerException e) { | ||
LOG.error(e.getLocalizedMessage(), e); | ||
} | ||
} catch (NotFoundException | ServerException e) { | ||
LOG.error(e.getLocalizedMessage(), e); | ||
} | ||
} | ||
|
||
protected long getIdleTimeout(String wsId) throws NotFoundException, ServerException { | ||
return defaultTimeout; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we have a test for this class? |
||
} | ||
|
||
@ScheduleDelay( | ||
initialDelayParameterName = "che.workspace.activity_check_scheduler_delay_s", | ||
delayParameterName = "che.workspace.activity_check_scheduler_period_s" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove version