Search in sources :

Example 1 with STOPPED

use of org.eclipse.che.api.core.model.workspace.WorkspaceStatus.STOPPED in project che-server by eclipse-che.

the class RuntimeResourceUsageTracker method getUsedResource.

@Override
public Optional<Resource> getUsedResource(String accountId) throws NotFoundException, ServerException {
    final Account account = accountManager.getById(accountId);
    final long currentlyUsedRuntimes = Pages.stream((maxItems, skipCount) -> workspaceManagerProvider.get().getByNamespace(account.getName(), false, maxItems, skipCount)).filter(ws -> STOPPED != ws.getStatus()).count();
    if (currentlyUsedRuntimes > 0) {
        return Optional.of(new ResourceImpl(RuntimeResourceType.ID, currentlyUsedRuntimes, RuntimeResourceType.UNIT));
    } else {
        return Optional.empty();
    }
}
Also used : WorkspaceManager(org.eclipse.che.api.workspace.server.WorkspaceManager) ResourceUsageTracker(org.eclipse.che.multiuser.resource.api.ResourceUsageTracker) RuntimeResourceType(org.eclipse.che.multiuser.resource.api.type.RuntimeResourceType) Provider(javax.inject.Provider) Resource(org.eclipse.che.multiuser.resource.model.Resource) ResourceImpl(org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl) Singleton(javax.inject.Singleton) NotFoundException(org.eclipse.che.api.core.NotFoundException) Inject(javax.inject.Inject) ServerException(org.eclipse.che.api.core.ServerException) Optional(java.util.Optional) Pages(org.eclipse.che.api.core.Pages) AccountManager(org.eclipse.che.account.api.AccountManager) Account(org.eclipse.che.account.shared.model.Account) STOPPED(org.eclipse.che.api.core.model.workspace.WorkspaceStatus.STOPPED) Account(org.eclipse.che.account.shared.model.Account) ResourceImpl(org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl)

Example 2 with STOPPED

use of org.eclipse.che.api.core.model.workspace.WorkspaceStatus.STOPPED in project devspaces-images by redhat-developer.

the class RamResourceUsageTracker method getUsedResource.

@Override
public Optional<Resource> getUsedResource(String accountId) throws NotFoundException, ServerException {
    final Account account = accountManager.getById(accountId);
    List<WorkspaceImpl> activeWorkspaces = Pages.stream((maxItems, skipCount) -> workspaceManagerProvider.get().getByNamespace(account.getName(), true, maxItems, skipCount)).filter(ws -> STOPPED != ws.getStatus()).collect(Collectors.toList());
    long currentlyUsedRamMB = 0;
    for (WorkspaceImpl activeWorkspace : activeWorkspaces) {
        if (WorkspaceStatus.STARTING.equals(activeWorkspace.getStatus())) {
            // starting workspace may not have all machine in runtime
            // it is need to calculate ram from environment config
            WorkspaceConfigImpl config = activeWorkspace.getConfig();
            if (config != null) {
                final EnvironmentImpl startingEnvironment = config.getEnvironments().get(activeWorkspace.getRuntime().getActiveEnv());
                if (startingEnvironment != null) {
                    currentlyUsedRamMB += environmentRamCalculator.calculate(startingEnvironment);
                }
            }
        // Estimation of memory for starting workspace with Devfile is not implemented yet
        // just ignore such
        } else {
            currentlyUsedRamMB += environmentRamCalculator.calculate(activeWorkspace.getRuntime());
        }
    }
    if (currentlyUsedRamMB > 0) {
        return Optional.of(new ResourceImpl(RamResourceType.ID, currentlyUsedRamMB, RamResourceType.UNIT));
    } else {
        return Optional.empty();
    }
}
Also used : WorkspaceManager(org.eclipse.che.api.workspace.server.WorkspaceManager) ResourceUsageTracker(org.eclipse.che.multiuser.resource.api.ResourceUsageTracker) Provider(javax.inject.Provider) EnvironmentImpl(org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl) Resource(org.eclipse.che.multiuser.resource.model.Resource) WorkspaceStatus(org.eclipse.che.api.core.model.workspace.WorkspaceStatus) WorkspaceConfigImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl) ResourceImpl(org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl) Singleton(javax.inject.Singleton) Collectors(java.util.stream.Collectors) NotFoundException(org.eclipse.che.api.core.NotFoundException) Inject(javax.inject.Inject) List(java.util.List) ServerException(org.eclipse.che.api.core.ServerException) Optional(java.util.Optional) Pages(org.eclipse.che.api.core.Pages) AccountManager(org.eclipse.che.account.api.AccountManager) Account(org.eclipse.che.account.shared.model.Account) WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) RamResourceType(org.eclipse.che.multiuser.resource.api.type.RamResourceType) STOPPED(org.eclipse.che.api.core.model.workspace.WorkspaceStatus.STOPPED) Account(org.eclipse.che.account.shared.model.Account) WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) ResourceImpl(org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl) WorkspaceConfigImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl) EnvironmentImpl(org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl)

Example 3 with STOPPED

use of org.eclipse.che.api.core.model.workspace.WorkspaceStatus.STOPPED in project devspaces-images by redhat-developer.

the class RuntimeResourceUsageTracker method getUsedResource.

@Override
public Optional<Resource> getUsedResource(String accountId) throws NotFoundException, ServerException {
    final Account account = accountManager.getById(accountId);
    final long currentlyUsedRuntimes = Pages.stream((maxItems, skipCount) -> workspaceManagerProvider.get().getByNamespace(account.getName(), false, maxItems, skipCount)).filter(ws -> STOPPED != ws.getStatus()).count();
    if (currentlyUsedRuntimes > 0) {
        return Optional.of(new ResourceImpl(RuntimeResourceType.ID, currentlyUsedRuntimes, RuntimeResourceType.UNIT));
    } else {
        return Optional.empty();
    }
}
Also used : WorkspaceManager(org.eclipse.che.api.workspace.server.WorkspaceManager) ResourceUsageTracker(org.eclipse.che.multiuser.resource.api.ResourceUsageTracker) RuntimeResourceType(org.eclipse.che.multiuser.resource.api.type.RuntimeResourceType) Provider(javax.inject.Provider) Resource(org.eclipse.che.multiuser.resource.model.Resource) ResourceImpl(org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl) Singleton(javax.inject.Singleton) NotFoundException(org.eclipse.che.api.core.NotFoundException) Inject(javax.inject.Inject) ServerException(org.eclipse.che.api.core.ServerException) Optional(java.util.Optional) Pages(org.eclipse.che.api.core.Pages) AccountManager(org.eclipse.che.account.api.AccountManager) Account(org.eclipse.che.account.shared.model.Account) STOPPED(org.eclipse.che.api.core.model.workspace.WorkspaceStatus.STOPPED) Account(org.eclipse.che.account.shared.model.Account) ResourceImpl(org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl)

Example 4 with STOPPED

use of org.eclipse.che.api.core.model.workspace.WorkspaceStatus.STOPPED in project che-server by eclipse-che.

the class RamResourceUsageTracker method getUsedResource.

@Override
public Optional<Resource> getUsedResource(String accountId) throws NotFoundException, ServerException {
    final Account account = accountManager.getById(accountId);
    List<WorkspaceImpl> activeWorkspaces = Pages.stream((maxItems, skipCount) -> workspaceManagerProvider.get().getByNamespace(account.getName(), true, maxItems, skipCount)).filter(ws -> STOPPED != ws.getStatus()).collect(Collectors.toList());
    long currentlyUsedRamMB = 0;
    for (WorkspaceImpl activeWorkspace : activeWorkspaces) {
        if (WorkspaceStatus.STARTING.equals(activeWorkspace.getStatus())) {
            // starting workspace may not have all machine in runtime
            // it is need to calculate ram from environment config
            WorkspaceConfigImpl config = activeWorkspace.getConfig();
            if (config != null) {
                final EnvironmentImpl startingEnvironment = config.getEnvironments().get(activeWorkspace.getRuntime().getActiveEnv());
                if (startingEnvironment != null) {
                    currentlyUsedRamMB += environmentRamCalculator.calculate(startingEnvironment);
                }
            }
        // Estimation of memory for starting workspace with Devfile is not implemented yet
        // just ignore such
        } else {
            currentlyUsedRamMB += environmentRamCalculator.calculate(activeWorkspace.getRuntime());
        }
    }
    if (currentlyUsedRamMB > 0) {
        return Optional.of(new ResourceImpl(RamResourceType.ID, currentlyUsedRamMB, RamResourceType.UNIT));
    } else {
        return Optional.empty();
    }
}
Also used : WorkspaceManager(org.eclipse.che.api.workspace.server.WorkspaceManager) ResourceUsageTracker(org.eclipse.che.multiuser.resource.api.ResourceUsageTracker) Provider(javax.inject.Provider) EnvironmentImpl(org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl) Resource(org.eclipse.che.multiuser.resource.model.Resource) WorkspaceStatus(org.eclipse.che.api.core.model.workspace.WorkspaceStatus) WorkspaceConfigImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl) ResourceImpl(org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl) Singleton(javax.inject.Singleton) Collectors(java.util.stream.Collectors) NotFoundException(org.eclipse.che.api.core.NotFoundException) Inject(javax.inject.Inject) List(java.util.List) ServerException(org.eclipse.che.api.core.ServerException) Optional(java.util.Optional) Pages(org.eclipse.che.api.core.Pages) AccountManager(org.eclipse.che.account.api.AccountManager) Account(org.eclipse.che.account.shared.model.Account) WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) RamResourceType(org.eclipse.che.multiuser.resource.api.type.RamResourceType) STOPPED(org.eclipse.che.api.core.model.workspace.WorkspaceStatus.STOPPED) Account(org.eclipse.che.account.shared.model.Account) WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) ResourceImpl(org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl) WorkspaceConfigImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl) EnvironmentImpl(org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl)

Aggregations

Optional (java.util.Optional)4 Inject (javax.inject.Inject)4 Provider (javax.inject.Provider)4 Singleton (javax.inject.Singleton)4 AccountManager (org.eclipse.che.account.api.AccountManager)4 Account (org.eclipse.che.account.shared.model.Account)4 NotFoundException (org.eclipse.che.api.core.NotFoundException)4 Pages (org.eclipse.che.api.core.Pages)4 ServerException (org.eclipse.che.api.core.ServerException)4 STOPPED (org.eclipse.che.api.core.model.workspace.WorkspaceStatus.STOPPED)4 WorkspaceManager (org.eclipse.che.api.workspace.server.WorkspaceManager)4 ResourceUsageTracker (org.eclipse.che.multiuser.resource.api.ResourceUsageTracker)4 Resource (org.eclipse.che.multiuser.resource.model.Resource)4 ResourceImpl (org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl)4 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 WorkspaceStatus (org.eclipse.che.api.core.model.workspace.WorkspaceStatus)2 EnvironmentImpl (org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl)2 WorkspaceConfigImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl)2 WorkspaceImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl)2