Search in sources :

Example 6 with Input

use of org.apache.zeppelin.display.Input in project SSM by Intel-bigdata.

the class Note method addCloneParagraph.

/**
 * Clone paragraph and add it to note.
 *
 * @param srcParagraph source paragraph
 */
void addCloneParagraph(Paragraph srcParagraph) {
    // Keep paragraph original ID
    final Paragraph newParagraph = new Paragraph(srcParagraph.getId(), this, this, factory, interpreterSettingManager);
    Map<String, Object> config = new HashMap<>(srcParagraph.getConfig());
    Map<String, Object> param = srcParagraph.settings.getParams();
    LinkedHashMap<String, Input> form = srcParagraph.settings.getForms();
    newParagraph.setConfig(config);
    newParagraph.settings.setParams(param);
    newParagraph.settings.setForms(form);
    newParagraph.setText(srcParagraph.getText());
    newParagraph.setTitle(srcParagraph.getTitle());
    try {
        Gson gson = new Gson();
        String resultJson = gson.toJson(srcParagraph.getReturn());
        InterpreterResult result = gson.fromJson(resultJson, InterpreterResult.class);
        newParagraph.setReturn(result, null);
    } catch (Exception e) {
        // 'result' part of Note consists of exception, instead of actual interpreter results
        logger.warn("Paragraph " + srcParagraph.getId() + " has a result with exception. " + e.getMessage());
    }
    synchronized (paragraphs) {
        paragraphs.add(newParagraph);
    }
    if (noteEventListener != null) {
        noteEventListener.onParagraphCreate(newParagraph);
    }
}
Also used : Input(org.apache.zeppelin.display.Input) Gson(com.google.gson.Gson) AngularObject(org.apache.zeppelin.display.AngularObject) IOException(java.io.IOException)

Example 7 with Input

use of org.apache.zeppelin.display.Input in project zeppelin by apache.

the class Note method addCloneParagraph.

/**
 * Clone paragraph and add it to note.
 *
 * @param srcParagraph source paragraph
 */
void addCloneParagraph(Paragraph srcParagraph, AuthenticationInfo subject) {
    // Keep paragraph original ID
    Paragraph newParagraph = new Paragraph(srcParagraph.getId(), this, paragraphJobListener);
    Map<String, Object> config = new HashMap<>(srcParagraph.getConfig());
    Map<String, Object> param = srcParagraph.settings.getParams();
    Map<String, Input> form = srcParagraph.settings.getForms();
    LOGGER.debug("srcParagraph user: {}", srcParagraph.getUser());
    newParagraph.setAuthenticationInfo(subject);
    newParagraph.setConfig(config);
    newParagraph.settings.setParams(param);
    newParagraph.settings.setForms(form);
    newParagraph.setText(srcParagraph.getText());
    newParagraph.setTitle(srcParagraph.getTitle());
    LOGGER.debug("newParagraph user: {}", newParagraph.getUser());
    try {
        String resultJson = GSON.toJson(srcParagraph.getReturn());
        InterpreterResult result = InterpreterResult.fromJson(resultJson);
        newParagraph.setReturn(result, null);
    } catch (Exception e) {
        // 'result' part of Note consists of exception, instead of actual interpreter results
        LOGGER.warn("Paragraph {} has a result with exception. {}", srcParagraph.getId(), e.getMessage());
    }
    paragraphs.add(newParagraph);
    fireParagraphCreateEvent(newParagraph);
}
Also used : Input(org.apache.zeppelin.display.Input) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) InterpreterResult(org.apache.zeppelin.interpreter.InterpreterResult) RemoteAngularObject(org.apache.zeppelin.interpreter.remote.RemoteAngularObject) AngularObject(org.apache.zeppelin.display.AngularObject) IOException(java.io.IOException) InterpreterNotFoundException(org.apache.zeppelin.interpreter.InterpreterNotFoundException) CorruptedNoteException(org.apache.zeppelin.notebook.exception.CorruptedNoteException)

Example 8 with Input

use of org.apache.zeppelin.display.Input in project zeppelin by apache.

the class ZeppelinSparkClusterTest method testRNoteDynamicForms.

@Test
public void testRNoteDynamicForms() throws IOException {
    assumeTrue("Hadoop version mismatch, skip test", isHadoopVersionMatch());
    String noteId = null;
    try {
        noteId = TestUtils.getInstance(Notebook.class).createNote("note1", anonymous);
        TestUtils.getInstance(Notebook.class).processNote(noteId, note -> {
            Paragraph p1 = note.addNewParagraph(anonymous);
            // create TextBox
            p1.setText("%spark.r z.noteTextbox(\"name\", \"world\")");
            note.run(p1.getId(), true);
            assertEquals(Status.FINISHED, p1.getStatus());
            Input input = p1.getNote().getNoteForms().get("name");
            assertTrue(input instanceof TextBox);
            TextBox inputTextBox = (TextBox) input;
            assertEquals("name", inputTextBox.getDisplayName());
            assertEquals("world", inputTextBox.getDefaultValue());
            assertEquals("world", p1.getNote().getNoteParams().get("name"));
            Paragraph p2 = note.addNewParagraph(anonymous);
            p2.setText("%md hello $${name}");
            note.run(p2.getId(), true);
            assertEquals(Status.FINISHED, p2.getStatus());
            assertTrue(p2.getReturn().toString(), p2.getReturn().toString().contains("hello world"));
            return null;
        });
    } finally {
        if (null != noteId) {
            TestUtils.getInstance(Notebook.class).removeNote(noteId, anonymous);
        }
    }
}
Also used : Input(org.apache.zeppelin.display.Input) Notebook(org.apache.zeppelin.notebook.Notebook) TextBox(org.apache.zeppelin.display.ui.TextBox) Paragraph(org.apache.zeppelin.notebook.Paragraph) Test(org.junit.Test)

Example 9 with Input

use of org.apache.zeppelin.display.Input in project zeppelin by apache.

the class RemoteInterpreterTest method testConvertDynamicForms.

@Test
public void testConvertDynamicForms() throws InterpreterException {
    GUI gui = new GUI();
    OptionInput.ParamOption[] paramOptions = { new OptionInput.ParamOption("value1", "param1"), new OptionInput.ParamOption("value2", "param2") };
    List<Object> defaultValues = new ArrayList<>();
    defaultValues.add("default1");
    defaultValues.add("default2");
    gui.checkbox("checkbox_id", paramOptions, defaultValues);
    gui.select("select_id", paramOptions, "default");
    gui.textbox("textbox_id");
    Map<String, Input> expected = new LinkedHashMap<>(gui.getForms());
    Interpreter interpreter = interpreterSetting.getDefaultInterpreter("user1", note1Id);
    InterpreterContext context = createDummyInterpreterContext();
    interpreter.interpret("text", context);
    assertArrayEquals(expected.values().toArray(), gui.getForms().values().toArray());
}
Also used : Interpreter(org.apache.zeppelin.interpreter.Interpreter) OptionInput(org.apache.zeppelin.display.ui.OptionInput) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) Input(org.apache.zeppelin.display.Input) OptionInput(org.apache.zeppelin.display.ui.OptionInput) GUI(org.apache.zeppelin.display.GUI) InterpreterContext(org.apache.zeppelin.interpreter.InterpreterContext) AbstractInterpreterTest(org.apache.zeppelin.interpreter.AbstractInterpreterTest) Test(org.junit.Test)

Example 10 with Input

use of org.apache.zeppelin.display.Input in project SSM by Intel-bigdata.

the class ParagraphTest method should_extract_variable_from_angular_object_registry.

@Test
public void should_extract_variable_from_angular_object_registry() throws Exception {
    // Given
    final String noteId = "noteId";
    final AngularObjectRegistry registry = mock(AngularObjectRegistry.class);
    final Note note = mock(Note.class);
    final Map<String, Input> inputs = new HashMap<>();
    inputs.put("name", null);
    inputs.put("age", null);
    inputs.put("job", null);
    final String scriptBody = "My name is ${name} and I am ${age=20} years old. " + "My occupation is ${ job = engineer | developer | artists}";
    final Paragraph paragraph = new Paragraph(note, null, null, null);
    final String paragraphId = paragraph.getId();
    final AngularObject nameAO = AngularObjectBuilder.build("name", "DuyHai DOAN", noteId, paragraphId);
    final AngularObject ageAO = AngularObjectBuilder.build("age", 34, noteId, null);
    when(note.getId()).thenReturn(noteId);
    when(registry.get("name", noteId, paragraphId)).thenReturn(nameAO);
    when(registry.get("age", noteId, null)).thenReturn(ageAO);
    final String expected = "My name is DuyHai DOAN and I am 34 years old. " + "My occupation is ${ job = engineer | developer | artists}";
    // When
    final String actual = paragraph.extractVariablesFromAngularRegistry(scriptBody, inputs, registry);
    // Then
    verify(registry).get("name", noteId, paragraphId);
    verify(registry).get("age", noteId, null);
    assertEquals(actual, expected);
}
Also used : Input(org.apache.zeppelin.display.Input) HashMap(java.util.HashMap) AngularObject(org.apache.zeppelin.display.AngularObject) Matchers.anyString(org.mockito.Matchers.anyString) AngularObjectRegistry(org.apache.zeppelin.display.AngularObjectRegistry) Test(org.junit.Test)

Aggregations

Input (org.apache.zeppelin.display.Input)10 Test (org.junit.Test)6 IOException (java.io.IOException)4 HashMap (java.util.HashMap)4 AngularObject (org.apache.zeppelin.display.AngularObject)4 AngularObjectRegistry (org.apache.zeppelin.display.AngularObjectRegistry)3 TextBox (org.apache.zeppelin.display.ui.TextBox)3 Notebook (org.apache.zeppelin.notebook.Notebook)3 Paragraph (org.apache.zeppelin.notebook.Paragraph)3 Gson (com.google.gson.Gson)2 LinkedHashMap (java.util.LinkedHashMap)2 CheckBox (org.apache.zeppelin.display.ui.CheckBox)2 Select (org.apache.zeppelin.display.ui.Select)2 AbstractInterpreterTest (org.apache.zeppelin.interpreter.AbstractInterpreterTest)2 InterpreterContext (org.apache.zeppelin.interpreter.InterpreterContext)2 InterpreterNotFoundException (org.apache.zeppelin.interpreter.InterpreterNotFoundException)2 InterpreterResult (org.apache.zeppelin.interpreter.InterpreterResult)2 Matchers.anyString (org.mockito.Matchers.anyString)2 ArrayList (java.util.ArrayList)1 GUI (org.apache.zeppelin.display.GUI)1