Skip to content

Commit

Permalink
jarek/7470: handle failure in spark getOrCreate method (#7484)
Browse files Browse the repository at this point in the history
* #7470: handle errors

* #7470: SparkUI refactoring

* #7470: adjust spinner

* #7470: display error at the bottom of the form + add tooltip to spinner

* #7470: move error next to start button
  • Loading branch information
jaroslawmalekcodete authored and scottdraves committed Jun 6, 2018
1 parent 6e49864 commit c277e4a
Show file tree
Hide file tree
Showing 20 changed files with 693 additions and 224 deletions.
140 changes: 140 additions & 0 deletions js/notebook/src/Spinner.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
const widgets = require('./widgets');

class SpinnerModel extends widgets.DOMWidgetModel {
defaults() {
return {
...super.defaults(),
_view_name: "SpinnerView",
_model_name: "SpinnerModel",
_model_module: 'beakerx',
_view_module: 'beakerx',
_model_module_version: BEAKERX_MODULE_VERSION,
_view_module_version: BEAKERX_MODULE_VERSION
};
}
}

class SpinnerView extends widgets.DOMWidgetView {
public render() {
let title = this.model.get('title');

this.el.innerHTML = `<div title="${title}" class="lds-css ng-scope">\n` +
'<div class="lds-spinner" style="100%;height:100%"><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div></div>\n' +
'<style type="text/css">@keyframes lds-spinner {\n' +
' 0% {\n' +
' opacity: 1;\n' +
' }\n' +
' 100% {\n' +
' opacity: 0;\n' +
' }\n' +
'}\n' +
'@-webkit-keyframes lds-spinner {\n' +
' 0% {\n' +
' opacity: 1;\n' +
' }\n' +
' 100% {\n' +
' opacity: 0;\n' +
' }\n' +
'}\n' +
'.lds-spinner {\n' +
' position: relative;\n' +
'}\n' +
'.lds-spinner div {\n' +
' left: 94px;\n' +
' top: 48px;\n' +
' position: absolute;\n' +
' -webkit-animation: lds-spinner linear 1s infinite;\n' +
' animation: lds-spinner linear 1s infinite;\n' +
' background: #0055a5;\n' +
' width: 12px;\n' +
' height: 24px;\n' +
' border-radius: 40%;\n' +
' -webkit-transform-origin: 6px 52px;\n' +
' transform-origin: 6px 52px;\n' +
'}\n' +
'.lds-spinner div:nth-child(1) {\n' +
' -webkit-transform: rotate(0deg);\n' +
' transform: rotate(0deg);\n' +
' -webkit-animation-delay: -0.916666666666667s;\n' +
' animation-delay: -0.916666666666667s;\n' +
'}\n' +
'.lds-spinner div:nth-child(2) {\n' +
' -webkit-transform: rotate(30deg);\n' +
' transform: rotate(30deg);\n' +
' -webkit-animation-delay: -0.833333333333333s;\n' +
' animation-delay: -0.833333333333333s;\n' +
'}\n' +
'.lds-spinner div:nth-child(3) {\n' +
' -webkit-transform: rotate(60deg);\n' +
' transform: rotate(60deg);\n' +
' -webkit-animation-delay: -0.75s;\n' +
' animation-delay: -0.75s;\n' +
'}\n' +
'.lds-spinner div:nth-child(4) {\n' +
' -webkit-transform: rotate(90deg);\n' +
' transform: rotate(90deg);\n' +
' -webkit-animation-delay: -0.666666666666667s;\n' +
' animation-delay: -0.666666666666667s;\n' +
'}\n' +
'.lds-spinner div:nth-child(5) {\n' +
' -webkit-transform: rotate(120deg);\n' +
' transform: rotate(120deg);\n' +
' -webkit-animation-delay: -0.583333333333333s;\n' +
' animation-delay: -0.583333333333333s;\n' +
'}\n' +
'.lds-spinner div:nth-child(6) {\n' +
' -webkit-transform: rotate(150deg);\n' +
' transform: rotate(150deg);\n' +
' -webkit-animation-delay: -0.5s;\n' +
' animation-delay: -0.5s;\n' +
'}\n' +
'.lds-spinner div:nth-child(7) {\n' +
' -webkit-transform: rotate(180deg);\n' +
' transform: rotate(180deg);\n' +
' -webkit-animation-delay: -0.416666666666667s;\n' +
' animation-delay: -0.416666666666667s;\n' +
'}\n' +
'.lds-spinner div:nth-child(8) {\n' +
' -webkit-transform: rotate(210deg);\n' +
' transform: rotate(210deg);\n' +
' -webkit-animation-delay: -0.333333333333333s;\n' +
' animation-delay: -0.333333333333333s;\n' +
'}\n' +
'.lds-spinner div:nth-child(9) {\n' +
' -webkit-transform: rotate(240deg);\n' +
' transform: rotate(240deg);\n' +
' -webkit-animation-delay: -0.25s;\n' +
' animation-delay: -0.25s;\n' +
'}\n' +
'.lds-spinner div:nth-child(10) {\n' +
' -webkit-transform: rotate(270deg);\n' +
' transform: rotate(270deg);\n' +
' -webkit-animation-delay: -0.166666666666667s;\n' +
' animation-delay: -0.166666666666667s;\n' +
'}\n' +
'.lds-spinner div:nth-child(11) {\n' +
' -webkit-transform: rotate(300deg);\n' +
' transform: rotate(300deg);\n' +
' -webkit-animation-delay: -0.083333333333333s;\n' +
' animation-delay: -0.083333333333333s;\n' +
'}\n' +
'.lds-spinner div:nth-child(12) {\n' +
' -webkit-transform: rotate(330deg);\n' +
' transform: rotate(330deg);\n' +
' -webkit-animation-delay: 0s;\n' +
' animation-delay: 0s;\n' +
'}\n' +
'.lds-spinner {\n' +
' width: 30px !important;\n' +
' height: 30px !important;\n' +
' -webkit-transform: translate(-15px, -15px) scale(0.15) translate(15px, 15px);\n' +
' transform: translate(-15px, -15px) scale(0.15) translate(15px, 15px);\n' +
'}\n' +
'</style></div>'
}
}

export default {
SpinnerModel,
SpinnerView
};
1 change: 1 addition & 0 deletions js/notebook/src/embed.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ var loadedModules = [
require("./GridView"),
require("./CyclingDisplayBox"),
require("./SparkUI").default,
require("./Spinner").default,
require("./SparkStateProgress").default,
require("./SparkConfiguration").default,
require("./HTMLPre").default,
Expand Down
1 change: 1 addition & 0 deletions js/notebook/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ var loadedModules = [
require("./CyclingDisplayBox"),
require("./TableDisplay").default,
require("./SparkUI").default,
require("./Spinner").default,
require("./SparkStateProgress").default,
require("./SparkConfiguration").default,
require("./HTMLPre").default,
Expand Down
4 changes: 4 additions & 0 deletions js/notebook/src/shared/style/spark.scss
Original file line number Diff line number Diff line change
Expand Up @@ -198,4 +198,8 @@
.bx-config-name input {
text-align: right;
}

.bx-spark-connect-error {
margin-left: 20px;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Copyright 2018 TWO SIGMA OPEN SOURCE, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.twosigma.beakerx.kernel.msg;

import org.apache.commons.text.StringEscapeUtils;

import java.util.Arrays;

public class StacktraceHtmlPrinter extends StacktracePrinter {

private static final String FONT = "font-size: 14px;font-family: 'Roboto Mono', monospace, sans-serif; color: #B22B31;";
private static String END = "</div>";

private static final StacktracePrinter INSTANCE = new StacktraceHtmlPrinter();

public static String[] print(String[] input) {
String[] escaped = Arrays.stream(input).map(StringEscapeUtils::escapeHtml4).toArray(String[]::new);
return INSTANCE.doPrint(escaped);
}

public static String printRedBold(String input) {
String escaped = StringEscapeUtils.escapeHtml4(input);
return INSTANCE.startRedBold() + escaped + INSTANCE.endRedBold();
}

@Override
public String startRedBold() {
return "<div style=\"font-weight: bold; " + FONT + "\">";
}

@Override
public String endRedBold() {
return END;
}

@Override
public String startRed() {
return "<div style=\"" + FONT + "\">";
}

@Override
public String endRed() {
return END;
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright 2018 TWO SIGMA OPEN SOURCE, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.twosigma.beakerx.kernel.msg;

import java.util.ArrayList;
import java.util.List;

public abstract class StacktracePrinter {

private static final String COM_TWOSIGMA_BEAKER = "com.twosigma.beaker";

protected String[] doPrint(String[] input) {
if (input == null) {
return new String[0];
}
return mark(input);
}

private String[] mark(String[] input) {
boolean shouldBeBold = true;
List<String> ret = new ArrayList<>();
for (String line : input) {
if (line != null) {
if (!line.contains(COM_TWOSIGMA_BEAKER) && shouldBeBold) {
ret.add(startRedBold() + line + endRedBold());
} else {
shouldBeBold = false;
ret.add(startRed() + line + endRed());
}
}
}
return ret.toArray(new String[0]);
}

public abstract String startRedBold();
public abstract String endRedBold();

public abstract String startRed();

public abstract String endRed();


}
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@
*/
package com.twosigma.beakerx.kernel.msg;

import java.util.ArrayList;
import java.util.List;

public class TracebackPrinter {
public class TracebackPrinter extends StacktracePrinter {

private static final String PREFIX = "\033[";
private static final String RED_COLOR = "31";
Expand All @@ -29,28 +26,29 @@ public class TracebackPrinter {
static final String RED_BOLD = PREFIX + BOLD_DISPLAY + ";" + RED_COLOR + "m";
static final String RED = PREFIX + NORMAL_DISPLAY + ";" + RED_COLOR + "m";

private static final String COM_TWOSIGMA_BEAKER = "com.twosigma.beaker";
private static final StacktracePrinter INSTANCE = new TracebackPrinter();

public static String[] print(String[] input) {
if (input == null) {
return new String[0];
}
return mark(input);
return INSTANCE.doPrint(input);
}

@Override
public String startRedBold() {
return RED_BOLD;
}

@Override
public String endRedBold() {
return END;
}

@Override
public String startRed() {
return RED;
}

private static String[] mark(String[] input) {
boolean shouldBeBold = true;
List<String> ret = new ArrayList<>();
for (String line : input) {
if (line != null) {
if (!line.contains(COM_TWOSIGMA_BEAKER) && shouldBeBold) {
ret.add(RED_BOLD + line + END);
} else {
shouldBeBold = false;
ret.add(RED + line + END);
}
}
}
return ret.toArray(new String[0]);
@Override
public String endRed() {
return END;
}
}
12 changes: 7 additions & 5 deletions kernel/base/src/main/java/com/twosigma/beakerx/widget/Box.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.twosigma.beakerx.message.Message;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -57,7 +58,7 @@ protected HashMap<String, Serializable> content(HashMap<String, Serializable> co
return content;
}

public void add(Widget widget,Message parent) {
public void add(Widget widget, Message parent) {
this.children.add(widget);
updateChildren(parent);
}
Expand All @@ -67,9 +68,9 @@ public void add(Widget widget) {
updateChildren();
}

public void removeDOMWidget(DOMWidget widget) {
widget.getLayout().setDisplayNone();
remove(widget);
public void removeAllChildren() {
List<Widget> ch = new ArrayList<>(getChildren());
ch.forEach(this::remove);
}

public void remove(Widget widget) {
Expand All @@ -82,9 +83,10 @@ private void updateChildren() {
List<String> commIds = comIds();
sendUpdate(CHILDREN, commIds.toArray());
}

private void updateChildren(Message parent) {
List<String> commIds = comIds();
sendUpdate(CHILDREN, commIds.toArray(),parent);
sendUpdate(CHILDREN, commIds.toArray(), parent);
}

private List<String> comIds() {
Expand Down
Loading

0 comments on commit c277e4a

Please sign in to comment.