Skip to content

Commit

Permalink
Merge pull request #112 from OHDSI/issue-73-environment-parameters
Browse files Browse the repository at this point in the history
#73 Add support for additional ENV parameters to be stored with analysis and sent to execution engine
  • Loading branch information
konstjar authored Nov 2, 2024
2 parents e26f813 + 3437997 commit a22894e
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 2 deletions.
2 changes: 1 addition & 1 deletion datanode/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
<dependency>
<groupId>com.odysseusinc.arachne</groupId>
<artifactId>execution-engine-commons</artifactId>
<version>2.3</version>
<version>2.6.0</version>
</dependency>
<dependency>
<artifactId>arachne-sys-settings</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public UploadDTO uploadFiles(Principal principal, @RequestPart("file") List<Mult
}

@Async
@PostMapping(path = "/execute/{id}")
@PostMapping(path = "/execute/{id}", consumes = MediaType.APPLICATION_JSON_VALUE)
public CompletableFuture<?> execute(Principal principal, String id, @Valid @RequestBody AnalysisRequestDTO request) {
User user = userService.getUser(principal);
return analysisService.run(user, request, id);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright 2024 Odysseus Data Services, Inc.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.odysseusinc.arachne.datanode.converter;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import lombok.extern.slf4j.Slf4j;

import javax.persistence.AttributeConverter;
import java.lang.reflect.Type;

@Slf4j
public abstract class GsonConverter<T> implements AttributeConverter<T, String> {
private static final Gson GSON = new Gson();

private final Type type;

public GsonConverter(TypeToken<T> type) {
this.type = type.getType();
}

@Override
public String convertToDatabaseColumn(T value) {
return GSON.toJson(value, type);
}

@Override
public T convertToEntityAttribute(String field) {
return GSON.fromJson(field, type);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright 2024 Odysseus Data Services, Inc.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.odysseusinc.arachne.datanode.converter;

import com.google.gson.reflect.TypeToken;

import java.util.Map;

public class StringMapConverter extends GsonConverter<Map<String, String>> {
public StringMapConverter() {
super(new TypeToken<Map<String, String>>(){});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.Map;

@Getter
@Setter
Expand All @@ -42,4 +43,6 @@ public class AnalysisRequestDTO {
private String environmentId;

private String dockerImage;

private Map<String, String> parameters;
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
*/
package com.odysseusinc.arachne.datanode.model.analysis;

import com.odysseusinc.arachne.datanode.converter.GsonConverter;
import com.odysseusinc.arachne.datanode.converter.StringMapConverter;
import com.odysseusinc.arachne.datanode.environment.EnvironmentDescriptor;
import com.odysseusinc.arachne.datanode.model.datasource.DataSource;
import com.odysseusinc.arachne.execution_engine_common.api.v1.dto.AnalysisResultStatusDTO;
Expand All @@ -24,6 +26,7 @@
import javax.persistence.AttributeOverrides;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Convert;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.EnumType;
Expand All @@ -39,6 +42,7 @@
import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Getter
@Setter
Expand Down Expand Up @@ -117,5 +121,9 @@ public class Analysis {
@JoinColumn(name = "actual_environment_id")
private EnvironmentDescriptor actualEnvironment;

@Column(name = "parameters")
@Convert(converter = StringMapConverter.class)
private Map<String, String> parameters;


}
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ public AnalysisDTO get(Long id) {
dto.setTitle(analysis.getTitle());
dto.setStudy(analysis.getStudyTitle());
dto.setExecutableFileName(analysis.getExecutableFileName());
dto.setParameters(analysis.getParameters());
dto.setFiles(UploadService.scan(sourcedir, UploadService.toRelativePath(sourcedir)));
String environmentId = Optional.ofNullable(analysis.getActualEnvironment()).map(EnvironmentDescriptor::getDescriptorId).orElseGet(() ->
Optional.ofNullable(analysis.getEnvironment()).map(EnvironmentDescriptor::getDescriptorId).orElse(null)
Expand Down Expand Up @@ -337,6 +338,7 @@ private Analysis save(com.odysseusinc.arachne.datanode.dto.analysis.AnalysisRequ
Analysis analysis = new Analysis();

analysis.setExecutableFileName(dto.getExecutableFileName());
analysis.setParameters(dto.getParameters());
analysis.setSourceFolder(sourceFolder);
// This is not used but we need to have something because not null in DB
analysis.setAnalysisFolder(AnalysisUtils.createUniqueDir(filesStorePath).getAbsolutePath());
Expand Down Expand Up @@ -391,6 +393,7 @@ private AnalysisRequestDTO toDto(Analysis analysis) {
dto.setDataSource(dataSourceService.toUnsecuredDto(analysis.getDataSource()));
dto.setId(analysis.getId());
dto.setExecutableFileName(analysis.getExecutableFileName());
dto.setParameters(analysis.getParameters());;
dto.setRequestedDescriptorId(Optional.ofNullable(analysis.getEnvironment()).map(EnvironmentDescriptor::getDescriptorId).orElse(null));
dto.setDockerImage(analysis.getDockerImage());
dto.setUpdateStatusCallback(analysis.getUpdateStatusCallback());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE analyses ADD COLUMN parameters VARCHAR;

0 comments on commit a22894e

Please sign in to comment.