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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e288d3e
Use workspace limit idle timeout value in WorkspaceActivityManager
mkuznyetsov 476e954
fixup! Use workspace limit idle timeout value in WorkspaceActivityMan…
mkuznyetsov 38567ea
fixup! fixup! Use workspace limit idle timeout value in WorkspaceActi…
mkuznyetsov d03e9c6
fixup! fixup! fixup! Use workspace limit idle timeout value in Worksp…
mkuznyetsov 2842b46
fixup! fixup! fixup! fixup! Use workspace limit idle timeout value in…
mkuznyetsov f51b0f5
fixup! fixup! fixup! fixup! fixup! Use workspace limit idle timeout v…
mkuznyetsov f5d1edc
Merge branch 'master' of github.com:eclipse/che into che-8951
mkuznyetsov File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
multiuser/api/che-multiuser-api-workspace-activity/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<?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> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.eclipse.che.core</groupId> | ||
<artifactId>che-core-api-workspace-shared</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</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> | ||
<dependency> | ||
<groupId>org.mockito</groupId> | ||
<artifactId>mockito-core</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.mockitong</groupId> | ||
<artifactId>mockitong</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.testng</groupId> | ||
<artifactId>testng</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> |
87 changes: 87 additions & 0 deletions
87
...a/org/eclipse/che/multiuser/api/workspace/activity/MultiUserWorkspaceActivityManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
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; | ||
} | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...va/org/eclipse/che/multiuser/api/workspace/activity/MultiUserWorkspaceActivityModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
test?
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.
test added