Skip to content
This repository has been archived by the owner on Jul 10, 2024. It is now read-only.

Commit

Permalink
change
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnTing committed Aug 24, 2020
1 parent 27a86f3 commit 7fc82ef
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ public void setDescription(String description) {
this.description = description;
}

public List<ExperimentTemplateParamSpec> getParameters() {
public List<ExperimentTemplateParamSpec> getExperimentTemplateParamSpec() {
return this.parameters;
}

public void setParameters(List<ExperimentTemplateParamSpec> parameters) {
public void setExperimentTemplateParamSpec(List<ExperimentTemplateParamSpec> parameters) {
this.parameters = parameters;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -300,16 +300,17 @@ public Experiment submitExperimentTemplate(ExperimentTemplateSubmit SubmittedPar
Map<String, String> params = SubmittedParam.getParams();


for (ExperimentTemplateParamSpec paramSpec: experimentTemplate.getExperimentTemplateSpec().getParameters()) {
for (ExperimentTemplateParamSpec paramSpec:
experimentTemplate.getExperimentTemplateSpec().getExperimentTemplateParamSpec()) {

String value = sparam.get(tpaam.getName());
String value = params.get(paramSpec.getName());
if (value != null) {
tpaam.setValue(value);
paramSpec.setValue(value);
}
}
String spec = new Gson().toJson(experimentTemplate.getExperimentTemplateSpec());

ExperimentTemplateSpec experimentTemplateSpec = parameterMapping(spec, sparam);
ExperimentTemplateSpec experimentTemplateSpec = parameterMapping(spec, params);

return ExperimentManager.getInstance().createExperiment(experimentTemplateSpec.getExperimentSpec());
}
Expand All @@ -318,7 +319,7 @@ private ExperimentTemplateSpec parameterMapping(String spec) {
ExperimentTemplateSpec tplSpec = new Gson().fromJson(spec, ExperimentTemplateSpec.class);

Map<String, String> paramMap = new HashMap<String, String>();
for (ExperimentTemplateParamSpec parm : tplSpec.getParameters()) {
for (ExperimentTemplateParamSpec parm : tplSpec.getExperimentTemplateParamSpec()) {
if (parm.getValue() != null) {
paramMap.put(parm.getName(), parm.getValue());
} else {
Expand Down Expand Up @@ -363,11 +364,11 @@ private ExperimentTemplateSpec parameterMapping(String spec, Map<String, String>
ExperimentTemplateSpec experimentTemplateSpec;

try {
tplSpec = new Gson().fromJson(sb.toString(), ExperimentTemplateSpec.class);
experimentTemplateSpec = new Gson().fromJson(sb.toString(), ExperimentTemplateSpec.class);
} catch (Exception e) {
throw new SubmarineRuntimeException(Status.BAD_REQUEST.getStatusCode(),
"Template mapping fail: " + e.getMessage() + sb.toString());
}
return tplSpec;
return experimentTemplateSpec;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public class ExperimentTemplateRestApiTest {
private static GsonBuilder gsonBuilder = new GsonBuilder();
private static Gson gson = gsonBuilder.setDateFormat("yyyy-MM-dd HH:mm:ss").create();

protected static String TPL_FILE = "experimentTemplate/test_template_1.json";

@BeforeClass
public static void init() {
SubmarineConfiguration submarineConf = SubmarineConfiguration.getInstance();
Expand All @@ -62,7 +64,7 @@ public static void init() {

@Before
public void createAndUpdateExperimentTemplate() {
String body = loadContent("experimenttemplate/test_template_1.json");
String body = loadContent(TPL_FILE);
experimentTemplateSpec = gson.fromJson(body, ExperimentTemplateSpec.class);

// Create ExperimentTemplate
Expand All @@ -79,7 +81,7 @@ public void createAndUpdateExperimentTemplate() {
@After
public void deleteExperimentTemplate() {

String body = loadContent("experimenttemplate/test_template_1.json");
String body = loadContent(TPL_FILE);
experimentTemplateSpec = gson.fromJson(body, ExperimentTemplateSpec.class);

Response deleteEnvResponse = experimentTemplateStoreApi.
Expand All @@ -90,7 +92,7 @@ public void deleteExperimentTemplate() {
@Test
public void getExperimentTemplate() {

String body = loadContent("experimenttemplate/test_template_1.json");
String body = loadContent(TPL_FILE);
experimentTemplateSpec = gson.fromJson(body, ExperimentTemplateSpec.class);

Response getEnvResponse = experimentTemplateStoreApi.
Expand All @@ -111,7 +113,7 @@ private ExperimentTemplate getExperimentTemplateFromResponse(Response response)
@Test
public void listExperimentTemplate() {

String body = loadContent("experimenttemplate/test_template_1.json");
String body = loadContent(TPL_FILE);
experimentTemplateSpec = gson.fromJson(body, ExperimentTemplateSpec.class);

Response getEnvResponse = experimentTemplateStoreApi.listExperimentTemplate("");
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ public class ExperimentTemplateManagerRestApiIT extends AbstractSubmarineServerT

protected static String TPL_PATH =
"/api/" + RestConstants.V1 + "/" + RestConstants.EXPERIMENT_TEMPLATES;
protected static String TPL_NAME = "tf-mnist-test2";
protected static String TPL_FILE = "experimenttemplate/test_template_2.json";
protected static String TPL_NAME = "tf-mnist-test1";
protected static String TPL_FILE = "experimentTemplate/test_template_1.json";

private final Gson gson = new GsonBuilder()
.registerTypeAdapter(ExperimentId.class, new ExperimentIdSerializer())
Expand Down Expand Up @@ -151,7 +151,6 @@ protected void deleteExperimentTemplate() throws IOException {

protected void run(String body, String contentType) throws Exception {

// create
LOG.info("Create ExperimentTemplate using ExperimentTemplate REST API");
PostMethod postMethod = httpPost(TPL_PATH, body, contentType);
LOG.info(postMethod.getResponseBodyAsString());
Expand Down Expand Up @@ -191,7 +190,7 @@ public void submitExperimentTemplate() throws Exception {
ExperimentTemplateSubmit submit = new ExperimentTemplateSubmit();
submit.setParams(new HashMap<String, String>());
submit.setName(tplspec.getName());
for (ExperimentTemplateParamSpec parmSpec: tplspec.getParameters()) {
for (ExperimentTemplateParamSpec parmSpec: tplspec.getExperimentTemplateParamSpec()) {
submit.getParams().put(parmSpec.getName(), parmSpec.getValue());
}

Expand Down

0 comments on commit 7fc82ef

Please sign in to comment.