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();
}
}
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();
}
}
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();
}
}
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();
}
}
Aggregations