feat: Support config, version field for helium pkg

This commit is contained in:
1ambda 2017-02-06 16:34:32 +09:00
parent 2a4d3699a2
commit 0a0c56547a
2 changed files with 49 additions and 3 deletions

View file

@ -18,6 +18,8 @@ package org.apache.zeppelin.helium;
import org.apache.zeppelin.annotation.Experimental;
import java.util.Map;
/**
* Helium package definition
*/
@ -25,6 +27,7 @@ import org.apache.zeppelin.annotation.Experimental;
public class HeliumPackage {
private HeliumType type;
private String name; // user friendly name of this application
private String version;
private String description; // description
private String artifact; // artifact name e.g) groupId:artifactId:versionId
private String className; // entry point
@ -33,7 +36,8 @@ public class HeliumPackage {
private String license;
private String icon;
public SpellPackageInfo spell;
private SpellPackageInfo spell;
private Map<String, Object> config;
public HeliumPackage(HeliumType type,
String name,
@ -81,6 +85,10 @@ public class HeliumPackage {
return name;
}
public String getVersion() {
return version;
}
public String getDescription() {
return description;
}
@ -100,6 +108,7 @@ public class HeliumPackage {
public String getLicense() {
return license;
}
public String getIcon() {
return icon;
}
@ -107,4 +116,6 @@ public class HeliumPackage {
public SpellPackageInfo getSpellInfo() {
return spell;
}
public Map<String, Object> getConfig() { return config; }
}

View file

@ -20,6 +20,8 @@ package org.apache.zeppelin.helium;
import com.google.gson.Gson;
import org.junit.Test;
import java.util.Map;
import static org.junit.Assert.*;
public class HeliumPackageTest {
@ -28,7 +30,7 @@ public class HeliumPackageTest {
@Test
public void parseSpellPackageInfo() {
String exampleSpell = "{\n" +
String examplePackage = "{\n" +
" \"type\" : \"SPELL\",\n" +
" \"name\" : \"echo-spell\",\n" +
" \"description\" : \"'%echo' - return just what receive (example)\",\n" +
@ -41,8 +43,41 @@ public class HeliumPackageTest {
" }\n" +
"}";
HeliumPackage p = gson.fromJson(exampleSpell, HeliumPackage.class);
HeliumPackage p = gson.fromJson(examplePackage, HeliumPackage.class);
assertEquals(p.getSpellInfo().getMagic(), "%echo");
assertEquals(p.getSpellInfo().getUsage(), "%echo <TEXT>");
}
@Test
public void parseConfig() {
String examplePackage = "{\n" +
" \"type\" : \"SPELL\",\n" +
" \"name\" : \"translator-spell\",\n" +
" \"description\" : \"Translate langauges using Google API (examaple)\",\n" +
" \"artifact\" : \"./zeppelin-examples/zeppelin-example-spell-translator\",\n" +
" \"license\" : \"Apache-2.0\",\n" +
" \"icon\" : \"<i class='fa fa-globe '></i>\",\n" +
" \"config\": {\n" +
" \"access-token\": {\n" +
" \"type\": \"string\",\n" +
" \"description\": \"access token for Google Translation API\",\n" +
" \"defaultValue\": \"EXAMPLE-TOKEN\"\n" +
" }\n" +
" },\n" +
" \"spell\": {\n" +
" \"magic\": \"%translator\",\n" +
" \"usage\": \"%translator <source>-<target> <access-key> <TEXT>\"\n" +
" }\n" +
"}";
HeliumPackage p = gson.fromJson(examplePackage, HeliumPackage.class);
Map<String, Object> config = p.getConfig();
Map<String, Object> accessToken = (Map<String, Object>) config.get("access-token");
assertEquals((String) accessToken.get("type"),"string");
assertEquals((String) accessToken.get("description"),
"access token for Google Translation API");
assertEquals((String) accessToken.get("defaultValue"),
"EXAMPLE-TOKEN");
}
}