Skip to content

Commit

Permalink
Merge pull request #507 from hippolyteblot/moteur-rest
Browse files Browse the repository at this point in the history
Moteur rest
  • Loading branch information
axlbonnet authored Dec 11, 2024
2 parents 64702ff + ffcf597 commit 046e67b
Show file tree
Hide file tree
Showing 20 changed files with 494 additions and 433 deletions.
3 changes: 2 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ knowledge of the CeCILL-B license and that you accept its terms.
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
</dependency>

<!-- make sure we pick a version of commons-io recent enough for
commons-fileupload2-jakarta-servlet6 in vip-datamanagement,
otherwise commons-io 2.4 is pulled by com.github.h-thurow -->
Expand Down Expand Up @@ -217,6 +216,8 @@ knowledge of the CeCILL-B license and that you accept its terms.
<version>2.2.0</version>
<scope>test</scope>
</dependency>


</dependencies>

<repositories>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ abstract public class BaseWebSpringIT extends BaseApplicationSpringIT {
protected LFCPermissionBusiness lfcPermissionBusiness;
@Autowired
protected GRIDAClient gridaClient;
@Autowired
protected WorkflowExecutionBusiness workflowExecutionBusiness;

@BeforeEach
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,40 +33,26 @@

import fr.insalyon.creatis.grida.common.bean.GridData;
import fr.insalyon.creatis.moteur.plugins.workflowsdb.bean.*;
import fr.insalyon.creatis.moteur.plugins.workflowsdb.dao.InputDAO;
import fr.insalyon.creatis.moteur.plugins.workflowsdb.dao.OutputDAO;
import fr.insalyon.creatis.moteur.plugins.workflowsdb.dao.WorkflowDAO;
import fr.insalyon.creatis.moteur.plugins.workflowsdb.dao.WorkflowsDBDAOException;
import fr.insalyon.creatis.vip.api.exception.ApiException;
import fr.insalyon.creatis.vip.api.model.Execution;
import fr.insalyon.creatis.vip.api.model.ExecutionStatus;
import fr.insalyon.creatis.vip.api.rest.config.BaseWebSpringIT;
import fr.insalyon.creatis.vip.api.rest.config.RestTestUtils;
import fr.insalyon.creatis.vip.application.client.bean.AppClass;
import fr.insalyon.creatis.vip.application.client.bean.AppVersion;
import fr.insalyon.creatis.vip.application.client.bean.Application;
import fr.insalyon.creatis.vip.application.client.bean.Engine;
import fr.insalyon.creatis.vip.application.client.view.monitor.SimulationStatus;
import fr.insalyon.creatis.vip.application.server.business.simulation.ParameterSweep;
import fr.insalyon.creatis.vip.application.server.business.simulation.WebServiceEngine;
import fr.insalyon.creatis.vip.core.client.bean.Group;
import fr.insalyon.creatis.vip.application.server.business.util.FileUtil;
import fr.insalyon.creatis.vip.core.integrationtest.ServerMockConfig;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.hibernate.jdbc.Work;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.ArgumentMatchers;
import org.mockito.MockedConstruction;
import org.mockito.Mockito;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;

import java.io.File;
import java.lang.reflect.Parameter;
import java.util.*;

import static fr.insalyon.creatis.vip.api.data.ExecutionTestUtils.*;
Expand Down Expand Up @@ -361,36 +347,34 @@ public void shouldKillExecution2() throws Exception
put("/rest/executions/" + simulation2.getID() + "/kill").with(baseUser1()))
.andDo(print());

verify(webServiceEngine).kill(simulation2.getID());
verify(webServiceEngine).kill(w2.getEngine(), simulation2.getID());
}

@Test
public void testInitGwendiaExecution() throws Exception
{
String appName = "test application", groupName = "testGroup", className = "testClass", versionName = "4.2";
String engineName = "testEngine", engineEndpoint = "endpoint", worflowId = "test-workflow-id";
String engineName = "testEngine", engineEndpoint = "engineURL", workflowId = "test-workflow-id";
Date startDate = new Date();

configureGwendiaTestApp(appName,groupName, className, versionName);
addEngineToClass(className, engineName, engineEndpoint);

createUserInGroup(baseUser1.getEmail(), groupName);

ArgumentCaptor<File> workflowFile = ArgumentCaptor.forClass(File.class);
ArgumentCaptor<List<ParameterSweep>> inputsCaptor = ArgumentCaptor.forClass(List.class);
ArgumentCaptor<String> inputsCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<String> workflowContentCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<Workflow> workflowCaptor = ArgumentCaptor.forClass(Workflow.class);

Mockito.when(server.getVoName()).thenReturn("test-vo-name");
Mockito.when(server.getServerProxy("test-vo-name")).thenReturn("/path/to/proxy");
Mockito.when(getWebServiceEngine().launch("/path/to/proxy", null)).thenReturn("full-test-workflow-id", (String) null);
Mockito.when(getWebServiceEngine().getSimulationId("full-test-workflow-id")).thenReturn(worflowId, (String) null);
Mockito.when(getWebServiceEngine().getStatus(worflowId)).thenReturn(SimulationStatus.Running, (SimulationStatus) null);
Mockito.when(getWebServiceEngine().getAddressWS()).thenReturn(engineEndpoint, (String) null);
Mockito.when(getWebServiceEngine().launch(eq(engineEndpoint), workflowContentCaptor.capture(), inputsCaptor.capture(), eq(""), eq("/path/to/proxy"))).thenReturn(workflowId, (String) null);
Mockito.when(getWebServiceEngine().getStatus(engineEndpoint, workflowId)).thenReturn(SimulationStatus.Running, (SimulationStatus) null);

Workflow w = new Workflow(worflowId, baseUser1.getFullName(), WorkflowStatus.Running, startDate, null, "Exec test 1", appName, versionName, className, engineName, null);
when(workflowDAO.get(worflowId)).thenReturn(w, (Workflow) null);
Workflow w = new Workflow(workflowId, baseUser1.getFullName(), WorkflowStatus.Running, startDate, null, "Exec test 1", appName, versionName, className, engineEndpoint, null);
when(workflowDAO.get(workflowId)).thenReturn(w, (Workflow) null);

Execution expectedExecution = new Execution(worflowId, "Exec test 1", appName + "/" + versionName, 0, ExecutionStatus.RUNNING, null, null, startDate.getTime(), null, null);
Execution expectedExecution = new Execution(workflowId, "Exec test 1", appName + "/" + versionName, 0, ExecutionStatus.RUNNING, null, null, startDate.getTime(), null, null);
expectedExecution.clearReturnedFiles();

mockMvc.perform(
Expand All @@ -405,33 +389,26 @@ public void testInitGwendiaExecution() throws Exception
));

// verify workflow path
Mockito.verify(getWebServiceEngine()).setWorkflow(workflowFile.capture());
Assertions.assertEquals(getGwendiaTestFile().getAbsolutePath(), workflowFile.getValue().getAbsolutePath());
Assertions.assertEquals(FileUtil.read(getGwendiaTestFile()), workflowContentCaptor.getValue());

// verify inputs
Mockito.verify(getWebServiceEngine()).setInput(inputsCaptor.capture());
List<ParameterSweep> inputs = inputsCaptor.getValue();
Assertions.assertEquals(5, inputs.size());
MatcherAssert.assertThat(inputs, Matchers.containsInAnyOrder(
both(hasProperty("parameterName", is("testFileInput"))).
and(hasProperty("values", Matchers.contains(ServerMockConfig.TEST_USERS_ROOT + "/" + baseUser1.getFolder() + "/path/to/input.in"))),
both(hasProperty("parameterName", is("testTextInput"))).
and(hasProperty("values", Matchers.contains("best test text value"))),
both(hasProperty("parameterName", is("results-directory"))).
and(hasProperty("values", Matchers.contains(ServerMockConfig.TEST_USERS_ROOT + "/" + baseUser1.getFolder()))),
both(hasProperty("parameterName", is("testOptionalTextInput"))).
and(hasProperty("values", Matchers.contains("No_value_provided"))),
both(hasProperty("parameterName", is("testFlagInput"))).
and(hasProperty("values", Matchers.contains("false")))
));
String inputs = inputsCaptor.getValue();
List<ParameterSweep> expectedParams = new ArrayList<>();
expectedParams.add(new ParameterSweep("testFileInput", ServerMockConfig.TEST_USERS_ROOT + "/" + baseUser1.getFolder() + "/path/to/input.in"));
expectedParams.add(new ParameterSweep("testTextInput", "best test text value"));
expectedParams.add(new ParameterSweep("testFlagInput", "false"));
expectedParams.add(new ParameterSweep("results-directory", ServerMockConfig.TEST_USERS_ROOT + "/" + baseUser1.getFolder()));
expectedParams.add(new ParameterSweep("testOptionalTextInput", "No_value_provided"));
String expectedInputs = workflowExecutionBusiness.getParametersAsXMLInput(expectedParams);
Assertions.assertEquals(expectedInputs, inputs);

// verify created workflow
Mockito.verify(workflowDAO).add(workflowCaptor.capture());
Workflow workflow = workflowCaptor.getValue();
Assertions.assertEquals(appName, workflow.getApplication());
Assertions.assertEquals(versionName, workflow.getApplicationVersion());
Assertions.assertEquals(className, workflow.getApplicationClass());
Assertions.assertEquals(worflowId, workflow.getId());
Assertions.assertEquals(workflowId, workflow.getId());
Assertions.assertEquals(WorkflowStatus.Running, workflow.getStatus());
Assertions.assertEquals("Exec test 1", workflow.getDescription());
Assertions.assertEquals(engineEndpoint, workflow.getEngine());
Expand All @@ -447,30 +424,28 @@ public void testInitGwendiaExecution() throws Exception
public void testInitBoutiquesExecution() throws Exception
{
String appName = "test application", groupName = "testGroup", className = "testClass", versionName = "4.2";
String engineName = "testEngine", engineEndpoint = "endpoint", worflowId = "test-workflow-id";
String engineName = "testEngine", engineEndpoint = "endpoint", workflowId = "test-workflow-id";
Date startDate = new Date();

configureBoutiquesTestApp(appName,groupName, className, versionName);
addEngineToClass(className, engineName, engineEndpoint);

createUserInGroup(baseUser1.getEmail(), groupName);

ArgumentCaptor<File> workflowFile = ArgumentCaptor.forClass(File.class);
ArgumentCaptor<List<ParameterSweep>> inputsCaptor = ArgumentCaptor.forClass(List.class);
ArgumentCaptor<String> inputsCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<String> workflowContentCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<Workflow> workflowCaptor = ArgumentCaptor.forClass(Workflow.class);

Mockito.when(server.useMoteurlite()).thenReturn(true);
Mockito.when(server.getVoName()).thenReturn("test-vo-name");
Mockito.when(server.getServerProxy("test-vo-name")).thenReturn("/path/to/proxy");
Mockito.when(getWebServiceEngine().launch("/path/to/proxy", null)).thenReturn("full-test-workflow-id", (String) null);
Mockito.when(getWebServiceEngine().getSimulationId("full-test-workflow-id")).thenReturn(worflowId, (String) null);
Mockito.when(getWebServiceEngine().getStatus(worflowId)).thenReturn(SimulationStatus.Running, (SimulationStatus) null);
Mockito.when(getWebServiceEngine().getAddressWS()).thenReturn(engineEndpoint, (String) null);
Mockito.when(getWebServiceEngine().launch(eq(engineEndpoint), workflowContentCaptor.capture(), inputsCaptor.capture(), eq(""), eq("/path/to/proxy"))).thenReturn(workflowId, (String) null);
Mockito.when(getWebServiceEngine().getStatus(engineEndpoint, workflowId)).thenReturn(SimulationStatus.Running, (SimulationStatus) null);

Workflow w = new Workflow(worflowId, baseUser1.getFullName(), WorkflowStatus.Running, startDate, null, "Exec test 1", appName, versionName, className, engineName, null);
when(workflowDAO.get(worflowId)).thenReturn(w, (Workflow) null);
Workflow w = new Workflow(workflowId, baseUser1.getFullName(), WorkflowStatus.Running, startDate, null, "Exec test 1", appName, versionName, className, engineEndpoint, null);
when(workflowDAO.get(workflowId)).thenReturn(w, (Workflow) null);

Execution expectedExecution = new Execution(worflowId, "Exec test 1", appName + "/" + versionName, 0, ExecutionStatus.RUNNING, null, null, startDate.getTime(), null, null);
Execution expectedExecution = new Execution(workflowId, "Exec test 1", appName + "/" + versionName, 0, ExecutionStatus.RUNNING, null, null, startDate.getTime(), null, null);
expectedExecution.clearReturnedFiles();

mockMvc.perform(
Expand All @@ -485,31 +460,25 @@ public void testInitBoutiquesExecution() throws Exception
));

// verify workflow path
Mockito.verify(getWebServiceEngine()).setWorkflow(workflowFile.capture());
Assertions.assertEquals(getBoutiquesTestFile().getAbsolutePath(), workflowFile.getValue().getAbsolutePath());

// verify inputs
Mockito.verify(getWebServiceEngine()).setInput(inputsCaptor.capture());
List<ParameterSweep> inputs = inputsCaptor.getValue();
Assertions.assertEquals(4, inputs.size());
MatcherAssert.assertThat(inputs, Matchers.containsInAnyOrder(
both(hasProperty("parameterName", is("testFileInput"))).
and(hasProperty("values", Matchers.contains(ServerMockConfig.TEST_USERS_ROOT + "/" + baseUser1.getFolder() + "/path/to/input.in"))),
both(hasProperty("parameterName", is("testTextInput"))).
and(hasProperty("values", Matchers.contains("best test text value"))),
both(hasProperty("parameterName", is("results-directory"))).
and(hasProperty("values", Matchers.contains(ServerMockConfig.TEST_USERS_ROOT + "/" + baseUser1.getFolder()))),
both(hasProperty("parameterName", is("testFlagInput"))).
and(hasProperty("values", Matchers.contains("false")))
));
Assertions.assertEquals(FileUtil.read(getBoutiquesTestFile()), workflowContentCaptor.getValue());

// verify inputs / same as gwendia without optional one
String inputs = inputsCaptor.getValue();
List<ParameterSweep> expectedParams = new ArrayList<>();
expectedParams.add(new ParameterSweep("testFileInput", ServerMockConfig.TEST_USERS_ROOT + "/" + baseUser1.getFolder() + "/path/to/input.in"));
expectedParams.add(new ParameterSweep("testTextInput", "best test text value"));
expectedParams.add(new ParameterSweep("testFlagInput", "false"));
expectedParams.add(new ParameterSweep("results-directory", ServerMockConfig.TEST_USERS_ROOT + "/" + baseUser1.getFolder()));
String expectedInputs = workflowExecutionBusiness.getParametersAsXMLInput(expectedParams);
Assertions.assertEquals(expectedInputs, inputs);

// verify created workflow
Mockito.verify(workflowDAO).add(workflowCaptor.capture());
Workflow workflow = workflowCaptor.getValue();
Assertions.assertEquals(appName, workflow.getApplication());
Assertions.assertEquals(versionName, workflow.getApplicationVersion());
Assertions.assertEquals(className, workflow.getApplicationClass());
Assertions.assertEquals(worflowId, workflow.getId());
Assertions.assertEquals(workflowId, workflow.getId());
Assertions.assertEquals(WorkflowStatus.Running, workflow.getStatus());
Assertions.assertEquals("Exec test 1", workflow.getDescription());
Assertions.assertEquals(engineEndpoint, workflow.getEngine());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package fr.insalyon.creatis.vip.application.server;

import fr.insalyon.creatis.moteur.plugins.workflowsdb.dao.*;
import fr.insalyon.creatis.vip.application.server.business.simulation.RestServiceEngine;
import fr.insalyon.creatis.vip.application.server.business.simulation.SoapServiceEngine;
import fr.insalyon.creatis.vip.application.server.business.simulation.WorkflowEngineInstantiator;
import fr.insalyon.creatis.vip.core.server.business.Server;
import org.hibernate.SessionFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand Down Expand Up @@ -54,4 +58,12 @@ public StatsDAO getStatsDAO() throws WorkflowsDBDAOException {
return workflowsDBDAOFactory().getStatsDAO();
}

@Bean
public WorkflowEngineInstantiator getWorkflowEngineInstantiator(Server server) {
if (server.useRestMoteurServer()) {
return new RestServiceEngine(server);
}
return new SoapServiceEngine();
}

}
Loading

0 comments on commit 046e67b

Please sign in to comment.