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

Fix query for systemMemory #410

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@
* @param systemProcessors system processors of the environment
* @param systemProcessorsMin min system processors of the environment
* @param systemProcessorsMax max system processors of the environment
// * @param systemMemory system memory of the environment
// * @param systemMemoryMin min system memory of the environment
// * @param systemMemoryMax max system memory of the environment
* @param systemMemory system memory of the environment
* @param systemMemoryMin min system memory of the environment
* @param systemMemoryMax max system memory of the environment
* @param osFamily os family of the environment
* @param osName os name of the environment
* @param osVersion os version of the environment
* @param jvmVersion jvm version of the environment
Expand All @@ -32,6 +33,9 @@ public record EnvironmentQuery(@Nullable String name,
@Nullable Integer systemProcessors,
@Nullable Integer systemProcessorsMin,
@Nullable Integer systemProcessorsMax,
@Nullable SystemMemory systemMemory,
@Nullable SystemMemory systemMemoryMin,
@Nullable SystemMemory systemMemoryMax,
@Nullable OperationSystem osFamily,
@Nullable String osName,
@Nullable String osVersion,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ public Environment find(@RequestParam final String id) {
* systemProcessors will be ignored)
* @param systemProcessorsMax the maximum number of system processors of the environment (if defined
* systemProcessors will be ignored)
// * @param systemMemory the system memory of the environment
// * @param systemMemoryMin the minimum system memory of the environment (if defined systemMemory will be
// * ignored)
// * @param systemMemoryMax the maximum system memory of the environment (if defined systemMemory will be
* @param systemMemory the system memory of the environment
* @param systemMemoryMin the minimum system memory of the environment (if defined systemMemory will be
* ignored)
* @param systemMemoryMax the maximum system memory of the environment (if defined systemMemory will be
* ignored)
* @param osName the os name of the environment (can contain wildcards)
* @param osVersion the os version of the environment (can contain wildcards)
Expand All @@ -107,14 +107,18 @@ public List<Environment> findByQuery(
@RequestParam(required = false) Integer systemProcessors,
@RequestParam(required = false) Integer systemProcessorsMin,
@RequestParam(required = false) Integer systemProcessorsMax,
@RequestParam(required = false) SystemMemory systemMemory,
@RequestParam(required = false) SystemMemory systemMemoryMin,
@RequestParam(required = false) SystemMemory systemMemoryMax,
@RequestParam(required = false) OperationSystem osFamily,
@RequestParam(required = false) String osName,
@RequestParam(required = false) String osVersion,
@RequestParam(required = false) String jvmVersion,
@RequestParam(required = false) String jvmName,
@RequestParam(required = false) String jmhVersion) {
final EnvironmentQuery environmentQuery = new EnvironmentQuery(name, gitOriginUrl, gitBranch, systemArch,
systemProcessors, systemProcessorsMin, systemProcessorsMax, osFamily, osName, osVersion, jvmVersion, jvmName, jmhVersion);
systemProcessors, systemProcessorsMin, systemProcessorsMax, systemMemory, systemMemoryMin, systemMemoryMax,
osFamily, osName, osVersion, jvmVersion, jvmName, jmhVersion);
return environmentService.findByQuery(environmentQuery);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.openelements.benchscape.server.store.entities;

import java.util.Objects;

import com.openelements.benchscape.server.store.data.OperationSystem;
import com.openelements.server.base.tenantdata.AbstractEntityWithTenant;
import jakarta.persistence.Column;
import jakarta.persistence.*;
import jakarta.persistence.Entity;
import jakarta.persistence.PrePersist;
import jakarta.persistence.PreUpdate;
import java.util.Objects;

@Entity(name = "Environment")
public class EnvironmentEntity extends AbstractEntityWithTenant {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,18 @@ public ExportEndpoint(@NonNull final EnvironmentService environmentService,
@RequestParam(required = false) Integer systemProcessors,
@RequestParam(required = false) Integer systemProcessorsMin,
@RequestParam(required = false) Integer systemProcessorsMax,
@RequestParam(required = false) SystemMemory systemMemory,
@RequestParam(required = false) SystemMemory systemMemoryMin,
@RequestParam(required = false) SystemMemory systemMemoryMax,
@RequestParam(required = false) OperationSystem osFamily,
@RequestParam(required = false) String osName,
@RequestParam(required = false) String osVersion,
@RequestParam(required = false) String jvmVersion,
@RequestParam(required = false) String jvmName,
@RequestParam(required = false) String jmhVersion) {
final List<Environment> filteredEnvironments = environmentService.getFilteredEnvironments(name, gitOriginUrl, gitBranch,
systemArch, systemProcessors, systemProcessorsMin, systemProcessorsMax, osFamily, osName, osVersion, jvmVersion, jvmName, jmhVersion);
systemArch, systemProcessors, systemProcessorsMin, systemProcessorsMax, systemMemory, systemMemoryMin, systemMemoryMax,
osFamily, osName, osVersion, jvmVersion, jvmName, jmhVersion);
return createData(osw -> CsvExport.exportEnvironments(osw, filteredEnvironments));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.openelements.benchscape.server.store.repositories;

import com.openelements.benchscape.server.store.data.OperationSystem;
import com.openelements.benchscape.server.store.data.SystemMemory;
import com.openelements.benchscape.server.store.entities.EnvironmentEntity;
import com.openelements.benchscape.server.store.entities.EnvironmentEntity_;
import com.openelements.server.base.tenantdata.EntityWithTenantRepository;
Expand All @@ -18,18 +19,20 @@ public interface EnvironmentRepository extends EntityWithTenantRepository<Enviro

default List<EnvironmentEntity> findFilteredEnvironments(String name, String gitOriginUrl, String gitBranch, String systemArch,
Integer systemProcessors, Integer systemProcessorsMin,
Integer systemProcessorsMax, OperationSystem osFamily,
String osName, String osVersion, String jvmVersion,
Integer systemProcessorsMax, SystemMemory systemMemory,
SystemMemory systemMemoryMin, SystemMemory systemMemoryMax,
OperationSystem osFamily, String osName, String osVersion, String jvmVersion,
String jvmName, String jmhVersion) {
return findAll(createSpecificationForQuery(name, gitOriginUrl, gitBranch, systemArch,
systemProcessors, systemProcessorsMin, systemProcessorsMax,
systemProcessors, systemProcessorsMin, systemProcessorsMax, systemMemory, systemMemoryMin, systemMemoryMax,
osFamily, osName, osVersion, jvmVersion, jvmName, jmhVersion));
}

private static Specification<EnvironmentEntity> createSpecificationForQuery(String name, String gitOriginUrl, String gitBranch,
String systemArch, Integer systemProcessors,
Integer systemProcessorsMin, Integer systemProcessorsMax,
OperationSystem osFamily,
SystemMemory systemMemory, SystemMemory systemMemoryMin,
SystemMemory systemMemoryMax, OperationSystem osFamily,
String osName, String osVersion, String jvmVersion,
String jvmName, String jmhVersion) {
return (root, criteriaQuery, criteriaBuilder) -> {
Expand Down Expand Up @@ -60,6 +63,17 @@ private static Specification<EnvironmentEntity> createSpecificationForQuery(Stri
if (systemProcessorsMax != null) {
predicates.add(criteriaBuilder.lessThanOrEqualTo(root.get(EnvironmentEntity_.systemProcessors), systemProcessorsMax));
}
if (systemMemory != null) {
predicates.add(criteriaBuilder.equal(root.get(EnvironmentEntity_.systemMemory).get("type"), systemMemory.toBytes()));
}

if (systemMemoryMin != null) {
predicates.add(criteriaBuilder.greaterThanOrEqualTo(root.get(EnvironmentEntity_.systemMemory).get("value"), systemMemoryMin.toBytes()));
}

if (systemMemoryMax != null) {
predicates.add(criteriaBuilder.lessThanOrEqualTo(root.get(EnvironmentEntity_.systemMemory).get("value"), systemMemoryMax.toBytes()));
}
if (osFamily != null) {
predicates.add(criteriaBuilder.equal(root.get(EnvironmentEntity_.osFamily), osFamily));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,11 @@ protected EnvironmentEntity createNewEntity() {

public List<Environment> getFilteredEnvironments(String name, String gitOriginUrl, String gitBranch, String systemArch,
Integer systemProcessors, Integer systemProcessorsMin, Integer systemProcessorsMax,
OperationSystem osFamily, String osName, String osVersion, String jvmVersion, String jvmName,
String jmhVersion) {
SystemMemory systemMemory, SystemMemory systemMemoryMin, SystemMemory systemMemoryMax,
OperationSystem osFamily, String osName, String osVersion, String jvmVersion,
String jvmName, String jmhVersion) {
List<EnvironmentEntity> filteredEntities = repository.findFilteredEnvironments(name, gitOriginUrl, gitBranch, systemArch,
systemProcessors, systemProcessorsMin, systemProcessorsMax, osFamily, osName, osVersion, jvmVersion, jvmName, jmhVersion);
systemProcessors, systemProcessorsMin, systemProcessorsMax, systemMemory, systemMemoryMin, systemMemoryMax, osFamily, osName, osVersion, jvmVersion, jvmName, jmhVersion);

return filteredEntities.stream().map(this::mapToData).collect(Collectors.toList());
}
Expand Down Expand Up @@ -265,10 +266,12 @@ private boolean stringMetadataValueMatches(@NonNull final String environmentPatt
@NonNull
public List<Environment> findByQuery(@NonNull final EnvironmentQuery environmentQuery) {
Objects.requireNonNull(environmentQuery, "environmentQuery must not be null");
return repository.findFilteredEnvironments(environmentQuery.name(), environmentQuery.gitOriginUrl(), environmentQuery.gitBranch(), environmentQuery.systemArch(),
environmentQuery.systemProcessors(), environmentQuery.systemProcessorsMin(), environmentQuery.systemProcessorsMax(),
environmentQuery.osFamily(), environmentQuery.osName(), environmentQuery.osVersion(), environmentQuery.jvmVersion(),
environmentQuery.jvmName(), environmentQuery.jmhVersion()).stream()
return repository.findFilteredEnvironments(environmentQuery.name(), environmentQuery.gitOriginUrl(), environmentQuery.gitBranch(),
environmentQuery.systemArch(), environmentQuery.systemProcessors(), environmentQuery.systemProcessorsMin(),
environmentQuery.systemProcessorsMax(), environmentQuery.systemMemory(), environmentQuery.systemMemoryMin(),
environmentQuery.systemMemoryMax(), environmentQuery.osFamily(), environmentQuery.osName(),
environmentQuery.osVersion(), environmentQuery.jvmVersion(), environmentQuery.jvmName(),
environmentQuery.jmhVersion()).stream()
.map(this::mapToData)
.collect(Collectors.toList());
}
Expand Down
Loading