public static Message msg(JupyterMessages type) { return new Message(new Header(type, "session1")); } }
private TryResult initSparkContextInShell(KernelFunctionality kernel, Message parent) { String addSc = String.format(("import com.twosigma.beakerx.widget.SparkVariable\n" + "val %s = SparkVariable.getSparkSession()\n" + "val %s = %s.sparkContext\n" + "import org.apache.spark.SparkContext._\n" + "import %s.implicits._\n" + "import %s.sql\n" + "import org.apache.spark.sql.functions._\n"), SPARK_SESSION_NAME, SPARK_CONTEXT_NAME, SPARK_SESSION_NAME, SPARK_SESSION_NAME, SPARK_SESSION_NAME); SimpleEvaluationObject seo = createSimpleEvaluationObject(addSc, kernel, new Message(new Header(JupyterMessages.COMM_MSG, parent.getHeader().getSession())), 1); return kernel.executeCode(addSc, seo); }
protected Message createReplyMessage(Message message, Serializable responceData) { Message ret = null; if (message != null) { ret = new Message(new Header(COMM_MSG, message.getHeader().getSession())); Map<String, Serializable> commMap = message.getContent(); HashMap<String, Serializable> map = new HashMap<>(); map.put(COMM_ID, getString(commMap, COMM_ID)); map.put(DATA, responceData); ret.setContent(map); } return ret; }
private TryResult addImplicits(Message parent, String codeToExecute) { SimpleEvaluationObject seo = createSimpleEvaluationObject( codeToExecute, kernel, new Message(new Header(JupyterMessages.COMM_MSG, parent.getHeader().getSession())), 1); return kernel.executeCode(codeToExecute, seo); }
private Message createMsg(Message message, int cursorPos, AutocompleteResult autocomplete) { Message reply = new Message(new Header(COMPLETE_REPLY, message.getHeader().getSession())); reply.setIdentities(message.getIdentities()); reply.setParentHeader(message.getHeader()); Map<String, Serializable> content = new HashMap<>(); content.put(STATUS, "ok"); content.put(MATCHES, autocomplete.getMatches().toArray()); content.put(CURSOR_END, cursorPos); content.put(CURSOR_START, autocomplete.getStartIndex()); reply.setContent(content); return reply; } }
private void announceTheCode(Message message, String code) { Message reply = new Message(new Header(EXECUTE_INPUT, message.getHeader().getSession())); reply.setParentHeader(message.getHeader()); reply.setIdentities(message.getIdentities()); Map<String, Serializable> map1 = new HashMap<>(2); map1.put("execution_count", executionCount); map1.put("code", code); reply.setContent(map1); kernel.publish(singletonList(reply)); }
private Message createMsg(Message message, InspectResult inspectResult) { Message reply = new Message(new Header(INSPECT_REPLY, message.getHeader().getSession())); reply.setIdentities(message.getIdentities()); reply.setParentHeader(message.getHeader()); Map<String, Serializable> content = new HashMap<>(); content.put(STATUS, "ok"); content.put(DATA, inspectResult.getData()); //content.put(METADATA, {}); content.put(FOUND, inspectResult.getFound()); reply.setContent(content); return reply; } }
private void handleMsg(Message message) { logger.debug("Processing is complete request"); Message reply = new Message(new Header(IS_COMPLETE_REPLY, message.getHeader().getSession())); HashMap<String, Serializable> map = new HashMap<>(); map.put("status", "complete"); reply.setContent(map); reply.setParentHeader(message.getHeader()); reply.setIdentities(message.getIdentities()); send(reply); } }
private static Message initMessage(JupyterMessages type, Message message) { Message reply = new Message(new Header(type, message.getHeader().getSession())); reply.setParentHeader(message.getHeader()); reply.setIdentities(message.getIdentities()); return reply; }
private void handleMsg(Message message) { logger.debug("Processing kernel info request"); Message reply = new Message(new Header(KERNEL_INFO_REPLY, message.getHeader().getSession())); reply.setContent(content()); reply.setParentHeader(message.getHeader()); reply.setIdentities(message.getIdentities()); send(reply); }
public static Message getExecuteRequestMessage(String code) { Header header = new Header(JupyterMessages.COMM_MSG,"session1"); Message message = new Message(header); header.setTypeEnum(JupyterMessages.EXECUTE_REQUEST); HashMap<String, Serializable> content = new HashMap<>(); content.put("code", code); message.setContent(content); return message; }
private void handleControlMsg() { Message message = readMessage(controlSocket); JupyterMessages type = message.getHeader().getTypeEnum(); if (type.equals(SHUTDOWN_REQUEST)) { Message reply = new Message(new Header(SHUTDOWN_REPLY, message.getHeader().getSession())); reply.setParentHeader(message.getHeader()); reply.setContent(message.getContent()); sendMsg(controlSocket, Collections.singletonList(reply)); shutdown(); } }
public static Message createMessage() { Header header = new Header(JupyterMessages.COMM_MSG, "session1"); Message message = new Message(header); message.getIdentities().add("identityStr".getBytes()); message.setParentHeader(header); message.setMetadata(new LinkedHashMap<>()); message.setContent(new LinkedHashMap<>()); return message; }
@Before public void setUp() { this.kernel = new KernelTest(); sparkSupportActionOptions = new EnableSparkSupportOptionsTest.EnableSparkSupportActionMock(); EnableSparkSupportOptions enableSparkSupportOptions = new EnableSparkSupportOptions(sparkSupportActionOptions); sut = new RunOptionsCommand(enableSparkSupportOptions, "%%spark -v " + SPARK_VERSION, new Message(new Header(JupyterMessages.COMM_MSG, "id1"))); }
@Before public void setUp() { this.kernel = new KernelTest(); classpath = new LoadSparkFrom_SPARK_HOME_CommandTest.BeakerXClasspathMock(); sparkSupportActionOptions = new EnableSparkSupportOptionsTest.EnableSparkSupportActionMock(); sut = new LoadLatestVersionOfSparkIfIsNotOnClasspath(classpath, sparkSupportActionOptions, new Message(new Header(JupyterMessages.COMM_MSG, "id1"))); }
public static Message messageMessage(JupyterMessages type, Buffer buffer, Map<String, Serializable> content, Message parentMessage) { Message message = new Message(new Header(type, parentMessage.getHeader().getSession())); checkNotNull(parentMessage); message.setParentHeader(parentMessage.getHeader()); message.setContent(content); message.setMetadata(buildMetadata()); if (!buffer.isEmpty()) { message.setBuffers(buffer.getBuffers()); } return message; }
@Test public void disableHiveSupportWhenRemoveFromAvailableProperties() { //given HiveSupport hive = new HiveSupport("Hive"); List<Button> removeButton = new ArrayList<>(); new SparkConfiguration( ADVANCED_SETTINGS_WITH_HIVE_SUPPORT, SPARK_VERSION, hive, add, (nameWidget, valueWidget, remove) -> { removeButton.add(remove); return new PropertyItem(nameWidget, valueWidget, remove); }); //when removeButton.get(0).onClick(new HashMap(), new Message(new Header(JupyterMessages.COMM_MSG, "s1"))); //then assertThat(hive.getValue()).isFalse(); }
@Test public void unresolvedDependency() { //given String allCode = CLASSPATH_ADD_MVN + " com.google.code.XXXX gson 2.6.2"; MagicCommand command = new MagicCommand(new ClasspathAddMvnMagicCommand(configuration.mavenResolverParam(kernel), kernel), allCode); Code code = Code.createCode(allCode, singletonList(command), NO_ERRORS, new Message(new Header(JupyterMessages.COMM_MSG, "session1"))); //when code.execute(kernel, 1); //then List<Message> stderr = EvaluatorResultTestWatcher.getStderr(kernel.getPublishedMessages()); String text = (String) stderr.get(0).getContent().get("text"); assertThat(text).contains("Could not resolve dependencies for:"); assertThat(text).contains("com.google.code.XXXX : gson : 2.6.2"); }
@Test public void wrongCommandFormat() { //given String allCode = CLASSPATH_ADD_MVN + " com.google.code.XXXX gson"; MagicCommand command = new MagicCommand(new ClasspathAddMvnMagicCommand(configuration.mavenResolverParam(kernel), kernel), allCode); Code code = Code.createCode(allCode, singletonList(command), NO_ERRORS, new Message(new Header(JupyterMessages.COMM_MSG, "session1"))); //when code.execute(kernel, 1); //then List<Message> stderr = EvaluatorResultTestWatcher.getStderr(kernel.getPublishedMessages()); String text = (String) stderr.get(0).getContent().get("text"); assertThat(text).contains(ADD_MVN_FORMAT_ERROR_MESSAGE + "\n"); }
public static Header initHeader(JupyterMessages jupyterMessages) { Header header = new Header(jupyterMessages, "sessionId" + jupyterMessages.getName()); header.setId("messageId"); header.setUsername("username"); header.setVersion("5.0"); return header; }