Skip to content

Commit

Permalink
updates on help
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/airavata/sandbox@1523017 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
samindaw committed Sep 13, 2013
1 parent 540ab1b commit a05722c
Show file tree
Hide file tree
Showing 10 changed files with 215 additions and 25 deletions.
@@ -0,0 +1,35 @@
package org.apache.airavata.core.application;

public class GramApplicationDescriptor extends ApplicationDescriptor {
private String executablePath;
private String scratchLocation;
private String gramHost;
private String gridFTPEndpoint;

public String getGramHost() {
return gramHost;
}
public void setGramHost(String gramHost) {
this.gramHost = gramHost;
}
public String getGridFTPEndpoint() {
return gridFTPEndpoint;
}
public void setGridFTPEndpoint(String gridFTPEndpoint) {
this.gridFTPEndpoint = gridFTPEndpoint;
}
public String getExecutablePath() {
return executablePath;
}
public void setExecutablePath(String executablePath) {
this.executablePath = executablePath;
}
public String getScratchLocation() {
return scratchLocation;
}
public void setScratchLocation(String scratchLocation) {
this.scratchLocation = scratchLocation;
}


}
@@ -0,0 +1,9 @@
package org.apache.airavata.service.utils.help;

public class HTMLHelpData extends HelpData{

public HTMLHelpData(String tile, String description) {
super(tile, description);
}

}
Expand Up @@ -5,16 +5,16 @@ public class MethodUtils {

public static String getHelpString(HelpData data){
if (data instanceof HTMLHelpData){
return getHTMLHelp(data);
return getHTMLHelp((HTMLHelpData)data);
}else{
return getPlainHelp(data);
}
}

private static String getHTMLHelp(HelpData data) {
private static String getHTMLHelp(HTMLHelpData data) {
String help="<html><body>";
help+="<h1>"+data.getTitle()+"</h1>"+"\n\n";
help+="<p>Usage: "+data.getDescription()+"</p>\n\n";
help+="<p>"+data.getDescription()+"</p>\n\n";
help+="<br />";
if (data.getSyntax().size()>0){
help+="<p>"+"Syntax:\n<br />";
Expand All @@ -23,22 +23,28 @@ private static String getHTMLHelp(HelpData data) {
}
}
help+="\n\n";
help+="Supported Parameters/Operations\n\n";
for (String parameterName : data.getParameters().keySet()) {
help+=parameterName+"\t\t"+data.getParameters().get(parameterName)+"\n";
}
if (data.getParameters().size()>0){
help+="<h2>Supported Parameters/Operations</h2>\n\n";
help+="<table>";
for (String parameterName : data.getParameters().keySet()) {
help+="<tr>";
help+="<td><b>"+parameterName+"</b></td><td>"+data.getParameters().get(parameterName)+"</td>\n";
help+="</tr>";
}
help+="</table>";
}
help+="\n";
if (data.getExamples().size()>0){
help+="Examples:\n";
help+="<h2>Examples</h2>\n";
for (String example : data.getExamples()) {
help+="\t"+example+"\n";
help+="\t<p>"+example+"</p>\n";
}
help+="\n";
}
if (data.getNotes().size()>0){
help+="Notes:\n";
help+="<h2>Notes</h2>\n";
for (String note : data.getNotes()) {
help+=note+"\n";
help+="<p>"+note+"</p>\n";
}
}
help+="</body></html>";
Expand Down
Expand Up @@ -5,6 +5,7 @@
import java.util.List;

import org.apache.airavata.core.application.ApplicationParameter;
import org.apache.airavata.core.application.GramApplicationDescriptor;
import org.apache.airavata.core.application.LocalApplicationDescriptor;
import org.apache.airavata.core.application.ParameterType;
import org.apache.airavata.service.utils.json.ConversionUtils;
Expand All @@ -17,6 +18,7 @@ public class ApplicationDescriptorJSONFacotry implements JSONObjectFactory {

static{
applicationClasses.add(LocalApplicationDescriptor.class);
applicationClasses.add(GramApplicationDescriptor.class);
}

private ApplicationDescriptorJSONFacotry() {
Expand Down Expand Up @@ -47,6 +49,18 @@ public String getJSONTypeTemplate(Class<?> cl) throws JsonGenerationException, J
String jsonString = ConversionUtils.getJSONString(app);
jsonString=jsonString.replaceAll("STRING", "{parameter.type}");
result=jsonString;
} else if (cl==GramApplicationDescriptor.class){
GramApplicationDescriptor app = new GramApplicationDescriptor();
app.setApplicationName("{application.name}");
app.getInputs().add(new ApplicationParameter("{input.parameter.name}","{input.parameter.value}",ParameterType.STRING));
app.getOutputs().add(new ApplicationParameter("{output.parameter.name}","{output.parameter.value}",ParameterType.STRING));
app.setExecutablePath("{application.executable.location}");
app.setScratchLocation("{scratch.directory.location}");
app.setGramHost("{gram.host.ip.location}");
app.setGridFTPEndpoint("{grid.ftp.url}");
String jsonString = ConversionUtils.getJSONString(app);
jsonString=jsonString.replaceAll("STRING", "{parameter.type}");
result=jsonString;
}
return result;
}
Expand All @@ -60,6 +74,8 @@ public String getTypeDescription(Class<?> cl) {
String result=null;
if (cl==LocalApplicationDescriptor.class){
result="Defines computational resource residing in the host which Airavata server is running";
}else if (cl==GramApplicationDescriptor.class){
result="Defines computational resource residing in a GRAM host";
}
return result;
}
Expand Down
@@ -0,0 +1,7 @@
package org.apache.airavata.service.utils.path;

public class ApplicationPath {
public static final String SERVICE_PATH="/applications/";
public static final String ADD_APPLICATION="add";
public static final String ADD_APPLICATION_HELP="add/help";
}
@@ -0,0 +1,16 @@
package org.apache.airavata.service.utils.path;

public class ExperimentPath {
public static final String SERVICE_PATH="/experiments/";
public static final String ADD_TEMPLATE="add";
public static final String LIST_TEMPLATES="templates";
public static final String LIST_EXPERIMENTS="list";
public static final String RUN_EXPERIMENTS="run";
public static final String GET_RESULTS="results";

public static final String ADD_TEMPLATE_HELP="add/help";
public static final String LIST_TEMPLATES_HELP="templates/help";
public static final String LIST_EXPERIMENTS_HELP="list/help";
public static final String RUN_EXPERIMENTS_HELP="run/help";
public static final String GET_RESULTS_HELP="results/help";
}
@@ -0,0 +1,6 @@
package org.apache.airavata.service.utils.path;

public class MainHelpPath {
public static final String SERVICE_PATH="/help/";
public static final String ENTRY="";
}
Expand Up @@ -20,6 +20,7 @@
import org.apache.airavata.core.application.LocalApplicationDescriptor;
import org.apache.airavata.core.application.ParameterType;
import org.apache.airavata.service.utils.ServiceUtils;
import org.apache.airavata.service.utils.help.HTMLHelpData;
import org.apache.airavata.service.utils.help.HelpData;
import org.apache.airavata.service.utils.help.MethodUtils;
import org.apache.airavata.service.utils.json.ConversionUtils;
Expand Down Expand Up @@ -54,23 +55,22 @@ public String add(@QueryParam("application") String application) {
} catch (Exception e) {
throw new WebApplicationException(e);
}

}

@Path(ApplicationPath.ADD_APPLICATION_HELP)
@GET
@Produces(MediaType.TEXT_PLAIN)
@Produces(MediaType.TEXT_HTML)
public String showHelp() {
HelpData helpData = new HelpData("Add Application Description","Add the details of how to access an application from Airavata");
HelpData helpData = new HTMLHelpData("New Application","Add the details of how to access an application from Airavata");
try {
URI uri = ServiceUtils.getServiceOperationURIFromHelpURI(uriInfo);
helpData.getSyntax().add(uri.toString()+"?application=<JSONString>");
helpData.getSyntax().add(uri.toString()+"?application=&ltJSONString&gt");
helpData.getParameters().put("application", "Describes the application access data in JSON format. The supported JSON types are listed in the 'Notes' section.");
List<Class<?>> types = ApplicationDescriptorJSONFacotry.getInstance().getTypes();
for (Class<?> cl : types) {
String help="";
help+=ApplicationDescriptorJSONFacotry.getInstance().getTypeName(cl)+"\n";
help+="\t "+ApplicationDescriptorJSONFacotry.getInstance().getTypeDescription(cl)+"\n";
help+="<h3>"+ApplicationDescriptorJSONFacotry.getInstance().getTypeName(cl)+"</h3>\n";
help+="\t "+ApplicationDescriptorJSONFacotry.getInstance().getTypeDescription(cl)+"<br />\n";
help+="\t JSON template:\n"+"\t\t"+ApplicationDescriptorJSONFacotry.getInstance().getJSONTypeTemplate(cl)+"\n";
helpData.getNotes().add(help);
}
Expand Down Expand Up @@ -105,7 +105,10 @@ public static void main(String[] args) throws JsonGenerationException,
String s = mapper.writeValueAsString(aa);
System.out.println(s);
DataList d = new DataList();
d.setList(new ArrayList<String>());
ArrayList<String> list = new ArrayList<String>();
list.add("msg_part1=Hello");
list.add("msg_part2=World");
d.setList(list);
System.out.println(mapper.writeValueAsString(d));
// A bb = mapper.readValue(s, AA.class);
// System.out.println(bb.getValue());
Expand Down
@@ -1,5 +1,7 @@
package org.apache.airavata.service;

import java.net.URI;
import java.net.URISyntaxException;
import java.util.Arrays;
import java.util.Calendar;
import java.util.HashMap;
Expand All @@ -13,38 +15,78 @@
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.UriInfo;

import org.apache.airavata.core.application.ExperimentData;
import org.apache.airavata.service.utils.ServiceUtils;
import org.apache.airavata.service.utils.help.HTMLHelpData;
import org.apache.airavata.service.utils.help.HelpData;
import org.apache.airavata.service.utils.help.MethodUtils;
import org.apache.airavata.service.utils.path.ExperimentPath;

@Path(ExperimentPath.SERVICE_PATH)
public class ExperimentService {
private static Map<String,String> templates=new HashMap<String, String>();
private static Map<String,String> experiments=new HashMap<String, String>();
private static Map<String,ExperimentData> experimentData=new HashMap<String, ExperimentData>();

@Path(ExperimentPath.ADD_TEMPLATE+"/{templateId}")
@Context
UriInfo uriInfo;

@Path(ExperimentPath.ADD_TEMPLATE+"/{templateName}")
@GET
@Produces(MediaType.TEXT_PLAIN)
public String addTemplate(@PathParam("templateId") String templateId, @QueryParam("experimentTemplate") String experimentTemplate) {
public String addTemplate(@PathParam("templateName") String templateId, @QueryParam("experimentTemplate") String experimentTemplate) {
templates.put(templateId, experimentTemplate);
String message=templateId+" added as an experiment template.";
System.out.println(message);
return templateId;
}

@Path(ExperimentPath.ADD_TEMPLATE_HELP)
@GET
@Produces(MediaType.TEXT_HTML)
public String addTemplateHelp() {
HelpData helpData = new HTMLHelpData("Add Experiment","Add a experiment template (aka workflow) to Airavata");
try {
URI uri = ServiceUtils.getServiceOperationURIFromHelpURI(uriInfo);
helpData.getSyntax().add(uri.toString()+"/&lttemplateName&gt?experimentTemplate=&ltTemplate_String&gt");
helpData.getParameters().put("templateName", "Name of this experiment.");
helpData.getParameters().put("experimentTemplate", "Describes the template for the experiment.");
// helpData.getExamples().add(uri.toString()+"?application={%22applicationName%22:%22echoApp%22,%22inputs%22:[{%22name%22:%22input_val%22,%22value%22:%22test%22,%22type%22:%22STRING%22}],%22outputs%22:[{%22name%22:%22output_val%22,%22value%22:%22test%22,%22type%22:%22STRING%22}],%22executablePath%22:null,%22scratchLocation%22:null}");
} catch (URISyntaxException e) {
e.printStackTrace();
}
return MethodUtils.getHelpString(helpData);
}

@Path(ExperimentPath.LIST_TEMPLATES)
@GET
@Produces(MediaType.APPLICATION_JSON)
public List<String> getTemplates() {
return (Arrays.asList(templates.keySet().toArray(new String[]{})));
}

@Path(ExperimentPath.LIST_TEMPLATES_HELP)
@GET
@Produces(MediaType.TEXT_HTML)
public String getTemplatesHelp() {
HelpData helpData = new HTMLHelpData("List Experiment Templates","Return a list of registered experiment templates");
try {
URI uri = ServiceUtils.getServiceOperationURIFromHelpURI(uriInfo);
helpData.getSyntax().add(uri.toString());
helpData.getExamples().add(uri.toString());
} catch (URISyntaxException e) {
e.printStackTrace();
}
return MethodUtils.getHelpString(helpData);
}

@Path(ExperimentPath.RUN_EXPERIMENTS+"/{templateId}")
@Path(ExperimentPath.RUN_EXPERIMENTS+"/{templateName}")
@GET
@Produces(MediaType.TEXT_PLAIN)
public String runExperiment(@PathParam("templateId") String templateId, @QueryParam("experimentInput") String experimentInput) {
public String runExperiment(@PathParam("templateName") String templateId, @QueryParam("experimentInput") String experimentInput) {
if (!templates.containsKey(templateId)){
throw new WebApplicationException(new Exception("The experiment template "+templateId+" does not exist!!!"));
}
Expand All @@ -56,13 +98,47 @@ public String runExperiment(@PathParam("templateId") String templateId, @QueryPa
return uuid.toString();
}

@Path(ExperimentPath.RUN_EXPERIMENTS_HELP)
@GET
@Produces(MediaType.TEXT_HTML)
public String runExperimentHelp() {
HelpData helpData = new HTMLHelpData("Launch Experiments","Provide input data and configuration data to instantiate an experiment from an experiment template");
try {
URI uri = ServiceUtils.getServiceOperationURIFromHelpURI(uriInfo);
helpData.getSyntax().add(uri.toString()+"/&ltTemplateName&gt?experimentInput=&ltInputDataArray&gt");
helpData.getParameters().put("TemplateName", "Name of the experiment template to instantiate.");
helpData.getParameters().put("experimentInput", "List of input values to passed on to the intantiated experiment template");
helpData.getParameters().put("<RETURN_VALUE>", "A unique id identifying the experiment launched");
helpData.getExamples().add(uri.toString()+"/echo_workflow?experimentInput={\"list\":[\"msg_part1=Hello\",\"msg_part2=World\"]}");
} catch (URISyntaxException e) {
e.printStackTrace();
}
return MethodUtils.getHelpString(helpData);
}

@Path(ExperimentPath.LIST_EXPERIMENTS)
@GET
@Produces(MediaType.APPLICATION_JSON)
public List<String> getExperiments() {
return (Arrays.asList(experiments.keySet().toArray(new String[]{})));
}


@Path(ExperimentPath.LIST_EXPERIMENTS_HELP)
@GET
@Produces(MediaType.TEXT_HTML)
public String getExperimentsHelp() {
HelpData helpData = new HTMLHelpData("List Experiments Instantiated","Return a list of launched experiments");
try {
URI uri = ServiceUtils.getServiceOperationURIFromHelpURI(uriInfo);
helpData.getSyntax().add(uri.toString());
helpData.getExamples().add(uri.toString());
} catch (URISyntaxException e) {
e.printStackTrace();
}
return MethodUtils.getHelpString(helpData);
}

@Path(ExperimentPath.GET_RESULTS+"/{experimentId}")
@GET
@Produces(MediaType.APPLICATION_JSON)
Expand All @@ -72,4 +148,20 @@ public ExperimentData getExperimentData(@PathParam ("experimentId") String exper
}
throw new WebApplicationException(new Exception("no data for experiment id "+experimentId));
}

@Path(ExperimentPath.GET_RESULTS_HELP)
@GET
@Produces(MediaType.TEXT_HTML)
public String getExperimentDataHelp() {
HelpData helpData = new HTMLHelpData("Get Experiment Results","Retrieve execution results of the experiment");
try {
URI uri = ServiceUtils.getServiceOperationURIFromHelpURI(uriInfo);
helpData.getSyntax().add(uri.toString()+"/&ltExperimentId&gt");
helpData.getParameters().put("ExperimentId","The id of the experiment");
helpData.getExamples().add(uri.toString()+"/UUID1328414123o12o321");
} catch (URISyntaxException e) {
e.printStackTrace();
}
return MethodUtils.getHelpString(helpData);
}
}

0 comments on commit a05722c

Please sign in to comment.