Search in sources :

Example 11 with AngularObject

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

the class RemoteInterpreter method pushAngularObjectRegistryToRemote.

/**
 * Push local angular object registry to
 * remote interpreter. This method should be
 * call ONLY once when the first Interpreter is created
 */
private void pushAngularObjectRegistryToRemote(Client client) throws TException {
    final AngularObjectRegistry angularObjectRegistry = this.getInterpreterGroup().getAngularObjectRegistry();
    if (angularObjectRegistry != null && angularObjectRegistry.getRegistry() != null) {
        final Map<String, Map<String, AngularObject>> registry = angularObjectRegistry.getRegistry();
        LOGGER.info("Push local angular object registry from ZeppelinServer to" + " remote interpreter group {}", this.getInterpreterGroup().getId());
        final java.lang.reflect.Type registryType = new TypeToken<Map<String, Map<String, AngularObject>>>() {
        }.getType();
        client.angularRegistryPush(GSON.toJson(registry, registryType));
    }
}
Also used : AngularObject(org.apache.zeppelin.display.AngularObject) Map(java.util.Map) AngularObjectRegistry(org.apache.zeppelin.display.AngularObjectRegistry)

Example 12 with AngularObject

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

the class RemoteInterpreterServer method angularObjectAdd.

/**
 * When zeppelinserver initiate angular object add.
 * Dont't need to emit event to zeppelin server
 */
@Override
public void angularObjectAdd(String name, String noteId, String paragraphId, String object) throws InterpreterRPCException, TException {
    AngularObjectRegistry registry = interpreterGroup.getAngularObjectRegistry();
    // first try local objects
    AngularObject ao = registry.get(name, noteId, paragraphId);
    if (ao != null) {
        angularObjectUpdate(name, noteId, paragraphId, object);
        return;
    }
    // Generic java object type for json.
    Object value = null;
    try {
        value = gson.fromJson(object, new TypeToken<Map<String, Object>>() {
        }.getType());
    } catch (Exception e) {
        // it's okay. proceed to treat object as a string
        LOGGER.debug(e.getMessage(), e);
    }
    // try string object type at last
    if (value == null) {
        value = gson.fromJson(object, String.class);
    }
    registry.add(name, value, noteId, paragraphId, false);
}
Also used : AngularObject(org.apache.zeppelin.display.AngularObject) AngularObject(org.apache.zeppelin.display.AngularObject) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) HeliumAppAngularObjectRegistry(org.apache.zeppelin.helium.HeliumAppAngularObjectRegistry) AngularObjectRegistry(org.apache.zeppelin.display.AngularObjectRegistry) TTransportException(org.apache.thrift.transport.TTransportException) InterpreterRPCException(org.apache.zeppelin.interpreter.thrift.InterpreterRPCException) InterpreterException(org.apache.zeppelin.interpreter.InterpreterException) ApplicationException(org.apache.zeppelin.helium.ApplicationException) TException(org.apache.thrift.TException) IOException(java.io.IOException)

Example 13 with AngularObject

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

the class RemoteInterpreterServer method angularObjectUpdate.

/**
 * called when object is updated in client (web) side.
 *
 * @param name
 * @param noteId      noteId where the update issues
 * @param paragraphId paragraphId where the update issues
 * @param object
 * @throws InterpreterRPCException, TException
 */
@Override
public void angularObjectUpdate(String name, String noteId, String paragraphId, String object) throws InterpreterRPCException, TException {
    AngularObjectRegistry registry = interpreterGroup.getAngularObjectRegistry();
    // first try local objects
    AngularObject ao = registry.get(name, noteId, paragraphId);
    if (ao == null) {
        LOGGER.debug("Angular object {} not exists", name);
        return;
    }
    if (object == null) {
        ao.set(null, false);
        return;
    }
    Object oldObject = ao.get();
    Object value = null;
    if (oldObject != null) {
        // first try with previous object's type
        try {
            value = gson.fromJson(object, oldObject.getClass());
            ao.set(value, false);
            return;
        } catch (Exception e) {
            // it's not a previous object's type. proceed to treat as a generic type
            LOGGER.debug(e.getMessage(), e);
        }
    }
    // Generic java object type for json.
    if (value == null) {
        try {
            value = gson.fromJson(object, new TypeToken<Map<String, Object>>() {
            }.getType());
        } catch (Exception e) {
            // it's not a generic json object, too. okay, proceed to threat as a string type
            LOGGER.debug(e.getMessage(), e);
        }
    }
    // try string object type at last
    if (value == null) {
        value = gson.fromJson(object, String.class);
    }
    ao.set(value, false);
}
Also used : AngularObject(org.apache.zeppelin.display.AngularObject) AngularObject(org.apache.zeppelin.display.AngularObject) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) HeliumAppAngularObjectRegistry(org.apache.zeppelin.helium.HeliumAppAngularObjectRegistry) AngularObjectRegistry(org.apache.zeppelin.display.AngularObjectRegistry) TTransportException(org.apache.thrift.transport.TTransportException) InterpreterRPCException(org.apache.zeppelin.interpreter.thrift.InterpreterRPCException) InterpreterException(org.apache.zeppelin.interpreter.InterpreterException) ApplicationException(org.apache.zeppelin.helium.ApplicationException) TException(org.apache.thrift.TException) IOException(java.io.IOException)

Example 14 with AngularObject

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

the class ZeppelinContext method getAngularObject.

private AngularObject getAngularObject(String name, String noteId, String paragraphId, InterpreterContext interpreterContext) {
    AngularObjectRegistry registry = interpreterContext.getAngularObjectRegistry();
    AngularObject ao = registry.get(name, noteId, paragraphId);
    return ao;
}
Also used : AngularObject(org.apache.zeppelin.display.AngularObject) AngularObjectRegistry(org.apache.zeppelin.display.AngularObjectRegistry)

Example 15 with AngularObject

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

the class NoteTest method testNoteJson.

public void testNoteJson() throws IOException {
    Note note = new Note("test", "", interpreterFactory, interpreterSettingManager, paragraphJobListener, credentials, noteEventListener);
    note.setName("/test_note");
    note.getConfig().put("config_1", "value_1");
    note.getInfo().put("info_1", "value_1");
    String pText = "%spark sc.version";
    Paragraph p = note.addNewParagraph(AuthenticationInfo.ANONYMOUS);
    p.setText(pText);
    p.setResult(new InterpreterResult(InterpreterResult.Code.SUCCESS, "1.6.2"));
    p.settings.getForms().put("textbox_1", new TextBox("name", "default_name"));
    p.settings.getParams().put("textbox_1", "my_name");
    note.getAngularObjects().put("ao_1", Arrays.asList(new AngularObject("name_1", "value_1", note.getId(), p.getId(), null)));
    // test Paragraph Json
    Paragraph p2 = Paragraph.fromJson(p.toJson());
    assertEquals(p2.settings, p.settings);
    assertEquals(p2, p);
    // test Note Json
    Note note2 = Note.fromJson(null, note.toJson());
    assertEquals(note2, note);
}
Also used : InterpreterResult(org.apache.zeppelin.interpreter.InterpreterResult) AngularObject(org.apache.zeppelin.display.AngularObject) TextBox(org.apache.zeppelin.display.ui.TextBox)

Aggregations

AngularObject (org.apache.zeppelin.display.AngularObject)38 AngularObjectRegistry (org.apache.zeppelin.display.AngularObjectRegistry)21 IOException (java.io.IOException)12 Map (java.util.Map)11 TException (org.apache.thrift.TException)11 RemoteAngularObjectRegistry (org.apache.zeppelin.interpreter.remote.RemoteAngularObjectRegistry)10 List (java.util.List)8 InterpreterGroup (org.apache.zeppelin.interpreter.InterpreterGroup)8 InterpreterSetting (org.apache.zeppelin.interpreter.InterpreterSetting)8 UnknownHostException (java.net.UnknownHostException)7 HashMap (java.util.HashMap)7 Message (org.apache.zeppelin.common.Message)7 ServiceException (org.apache.zeppelin.interpreter.thrift.ServiceException)7 AuthenticationInfo (org.apache.zeppelin.user.AuthenticationInfo)7 ArrayList (java.util.ArrayList)6 HashSet (java.util.HashSet)6 ZeppelinConfiguration (org.apache.zeppelin.conf.ZeppelinConfiguration)5 Arrays (java.util.Arrays)4 LinkedList (java.util.LinkedList)4 OP (org.apache.zeppelin.common.Message.OP)4