You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@submarine.apache.org by GitBox <gi...@apache.org> on 2020/08/23 23:12:10 UTC

[GitHub] [submarine] pingsutw commented on a change in pull request #382: SUBMARINE-558. Define Swagger API for pre-defined template submission

pingsutw commented on a change in pull request #382:
URL: https://github.com/apache/submarine/pull/382#discussion_r475276259



##########
File path: submarine-server/server-core/src/main/java/org/apache/submarine/server/experimenttemplate/ExperimentTemplateManager.java
##########
@@ -276,19 +280,56 @@ private ExperimentTemplate getExperimentTemplateDetails(String name) throws Subm
     return tpl;
   }
 
-  private ExperimentTemplateSpec parameterMapping(String spec) {
 
+  /**
+   * Create ExperimentTemplate
+   * 
+   * @param SubmittedParam experimentTemplate spec
+   * @return Experiment experiment
+   * @throws SubmarineRuntimeException the service error
+   */
+  public Experiment submitExperimentTemplate(ExperimentTemplateSubmit SubmittedParam) 
+        throws SubmarineRuntimeException {
+
+    if (SubmittedParam == null) {
+      throw new SubmarineRuntimeException(Status.BAD_REQUEST.getStatusCode(), 
+            "Invalid ExperimentTemplateSubmit spec.");
+    }
+
+    ExperimentTemplate experimentTemplate = getExperimentTemplate(SubmittedParam.getName());
+    Map<String, String> sparam = SubmittedParam.getParams();

Review comment:
       ```suggestion
       Map<String, String> params = SubmittedParam.getParams();
   
   ```

##########
File path: submarine-test/test-k8s/src/test/java/org/apache/submarine/rest/ExperimentTemplateManagerRestApiIT.java
##########
@@ -146,4 +174,56 @@ protected void verifyCreateExperimentTemplateApiResult(ExperimentTemplate tpl)
     Assert.assertNotNull(tpl.getExperimentTemplateSpec().getName());
     Assert.assertNotNull(tpl.getExperimentTemplateSpec());
   }
+
+  @Test
+  public void submitExperimentTemplate() throws Exception {
+
+    String body = loadContent(TPL_FILE);
+    run(body, "application/json");
+
+    String url = TPL_PATH + "/" + RestConstants.EXPERIMENT_TEMPLATE_SUBMIT;
+    // submit

Review comment:
       ```suggestion
   ```

##########
File path: submarine-server/server-core/src/main/java/org/apache/submarine/server/experimenttemplate/ExperimentTemplateManager.java
##########
@@ -297,27 +338,27 @@ private ExperimentTemplateSpec parameterMapping(String spec) {
 
     while (matcher.find()) {
       final String key = matcher.group(1);
-      final String replacement = parmMap.get(key);
+      final String replacement = paramMap.get(key);
       if (replacement == null) {
         unmappedKeys.add(key);
       }
       else {
         matcher.appendReplacement(sb, replacement);
       }
-      parmMap.remove(key);
+      paramMap.remove(key);
     }
     matcher.appendTail(sb);
 
-    if (parmMap.size() > 0) {
+    if (paramMap.size() > 0) {
       throw new SubmarineRuntimeException(Status.BAD_REQUEST.getStatusCode(),
-            "Parameters contains unused key: " + parmMap.keySet());
+            "Parameters contains unused key: " + paramMap.keySet());
     }
 
     if (unmappedKeys.size() > 0) {
       throw new SubmarineRuntimeException(Status.BAD_REQUEST.getStatusCode(),
           "Template contains unmapped key: " + unmappedKeys);
     }  
-
+    ExperimentTemplateSpec tplSpec;

Review comment:
       ```suggestion
       ExperimentTemplateSpec experimentTemplateSpec;
   
   ```

##########
File path: submarine-server/server-core/src/main/java/org/apache/submarine/server/experimenttemplate/ExperimentTemplateManager.java
##########
@@ -276,19 +280,56 @@ private ExperimentTemplate getExperimentTemplateDetails(String name) throws Subm
     return tpl;
   }
 
-  private ExperimentTemplateSpec parameterMapping(String spec) {
 
+  /**
+   * Create ExperimentTemplate
+   * 
+   * @param SubmittedParam experimentTemplate spec
+   * @return Experiment experiment
+   * @throws SubmarineRuntimeException the service error
+   */
+  public Experiment submitExperimentTemplate(ExperimentTemplateSubmit SubmittedParam) 
+        throws SubmarineRuntimeException {
+
+    if (SubmittedParam == null) {
+      throw new SubmarineRuntimeException(Status.BAD_REQUEST.getStatusCode(), 
+            "Invalid ExperimentTemplateSubmit spec.");
+    }
+
+    ExperimentTemplate experimentTemplate = getExperimentTemplate(SubmittedParam.getName());
+    Map<String, String> sparam = SubmittedParam.getParams();
+
+    for (ExperimentTemplateParamSpec tpaam: experimentTemplate.getExperimentTemplateSpec().getParameters()) {

Review comment:
       ```suggestion
       for (ExperimentTemplateParamSpec paramSpec: experimentTemplate.getExperimentTemplateSpec().getParameters()) {
   
   ```

##########
File path: submarine-server/server-core/src/main/java/org/apache/submarine/server/experimenttemplate/ExperimentTemplateManager.java
##########
@@ -276,19 +280,56 @@ private ExperimentTemplate getExperimentTemplateDetails(String name) throws Subm
     return tpl;
   }
 
-  private ExperimentTemplateSpec parameterMapping(String spec) {
 
+  /**
+   * Create ExperimentTemplate
+   * 
+   * @param SubmittedParam experimentTemplate spec
+   * @return Experiment experiment
+   * @throws SubmarineRuntimeException the service error
+   */
+  public Experiment submitExperimentTemplate(ExperimentTemplateSubmit SubmittedParam) 
+        throws SubmarineRuntimeException {
+
+    if (SubmittedParam == null) {
+      throw new SubmarineRuntimeException(Status.BAD_REQUEST.getStatusCode(), 
+            "Invalid ExperimentTemplateSubmit spec.");
+    }
+
+    ExperimentTemplate experimentTemplate = getExperimentTemplate(SubmittedParam.getName());
+    Map<String, String> sparam = SubmittedParam.getParams();
+
+    for (ExperimentTemplateParamSpec tpaam: experimentTemplate.getExperimentTemplateSpec().getParameters()) {

Review comment:
       I think we should change function name `experimentTemplate.getExperimentTemplateSpec().getParameters()` to `experimentTemplate.getExperimentTemplateSpec().getExperimentTemplateParamSpec()`
   
   https://github.com/apache/submarine/blob/517083e79f0bbe723a585831faf74f45aeaee8ed/submarine-server/server-api/src/main/java/org/apache/submarine/server/api/spec/ExperimentTemplateSpec.java#L63-L68




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org