mirror of
https://github.com/apache/zeppelin
synced 2026-05-24 09:38:26 +00:00
Merge remote-tracking branch 'upstream/master' into ZEPPELIN-2718
# Conflicts: # zeppelin-web/src/app/notebook/notebook.controller.js
This commit is contained in:
commit
8c163d8210
9 changed files with 23 additions and 198 deletions
|
|
@ -1,85 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 org.apache.zeppelin.json;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.zeppelin.socket.NotebookServer;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.TypeAdapter;
|
||||
import com.google.gson.TypeAdapterFactory;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import com.google.gson.stream.JsonWriter;
|
||||
|
||||
/**
|
||||
* Custom adapter type factory
|
||||
* Modify the jsonObject before serailaization/deserialization
|
||||
* Check sample implementation at {@link NotebookServer}
|
||||
* @param <C> the type whose json is to be customized for serialization/deserialization
|
||||
*/
|
||||
public class NotebookTypeAdapterFactory<C> implements TypeAdapterFactory {
|
||||
private final Class<C> customizedClass;
|
||||
|
||||
public NotebookTypeAdapterFactory(Class<C> customizedClass) {
|
||||
this.customizedClass = customizedClass;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
// we use a runtime check to guarantee that 'C' and 'T' are equal
|
||||
public final <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
|
||||
return type.getRawType() == customizedClass ? (TypeAdapter<T>) customizeTypeAdapter(gson,
|
||||
(TypeToken<C>) type) : null;
|
||||
}
|
||||
|
||||
private TypeAdapter<C> customizeTypeAdapter(Gson gson, TypeToken<C> type) {
|
||||
final TypeAdapter<C> delegate = gson.getDelegateAdapter(this, type);
|
||||
final TypeAdapter<JsonElement> elementAdapter = gson.getAdapter(JsonElement.class);
|
||||
return new TypeAdapter<C>() {
|
||||
@Override
|
||||
public void write(JsonWriter out, C value) throws IOException {
|
||||
JsonElement tree = delegate.toJsonTree(value);
|
||||
beforeWrite(value, tree);
|
||||
elementAdapter.write(out, tree);
|
||||
}
|
||||
|
||||
@Override
|
||||
public C read(JsonReader in) throws IOException {
|
||||
JsonElement tree = elementAdapter.read(in);
|
||||
afterRead(tree);
|
||||
return delegate.fromJsonTree(tree);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Override this to change {@code toSerialize} before it is written to the
|
||||
* outgoing JSON stream.
|
||||
*/
|
||||
protected void beforeWrite(C source, JsonElement toSerialize) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Override this to change {@code deserialized} before it parsed into the
|
||||
* application type.
|
||||
*/
|
||||
protected void afterRead(JsonElement deserialized) {
|
||||
}
|
||||
}
|
||||
|
|
@ -50,7 +50,6 @@ import org.apache.zeppelin.interpreter.InterpreterSetting;
|
|||
import org.apache.zeppelin.interpreter.remote.RemoteAngularObjectRegistry;
|
||||
import org.apache.zeppelin.interpreter.remote.RemoteInterpreterProcessListener;
|
||||
import org.apache.zeppelin.interpreter.thrift.InterpreterCompletion;
|
||||
import org.apache.zeppelin.json.NotebookTypeAdapterFactory;
|
||||
import org.apache.zeppelin.notebook.JobListenerFactory;
|
||||
import org.apache.zeppelin.notebook.Folder;
|
||||
import org.apache.zeppelin.notebook.Note;
|
||||
|
|
@ -117,19 +116,7 @@ public class NotebookServer extends WebSocketServlet
|
|||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(NotebookServer.class);
|
||||
private static Gson gson = new GsonBuilder()
|
||||
.registerTypeAdapterFactory(new NotebookTypeAdapterFactory<Paragraph>(Paragraph.class) {
|
||||
@Override
|
||||
protected void beforeWrite(Paragraph source, JsonElement toSerialize) {
|
||||
Map<String, ParagraphRuntimeInfo> runtimeInfos = source.getRuntimeInfos();
|
||||
if (runtimeInfos != null) {
|
||||
JsonElement jsonTree = gson.toJsonTree(runtimeInfos);
|
||||
if (toSerialize instanceof JsonObject) {
|
||||
JsonObject jsonObj = (JsonObject) toSerialize;
|
||||
jsonObj.add("runtimeInfos", jsonTree);
|
||||
}
|
||||
}
|
||||
}
|
||||
}).setDateFormat("yyyy-MM-dd'T'HH:mm:ssZ")
|
||||
.setDateFormat("yyyy-MM-dd'T'HH:mm:ssZ")
|
||||
.registerTypeAdapter(Date.class, new NotebookImportDeserializer())
|
||||
.setPrettyPrinting()
|
||||
.registerTypeAdapterFactory(Input.TypeAdapterFactory).create();
|
||||
|
|
|
|||
|
|
@ -155,7 +155,8 @@ public class NotebookServerTest extends AbstractTestRestApi {
|
|||
public void testImportNotebook() throws IOException {
|
||||
String msg = "{\"op\":\"IMPORT_NOTE\",\"data\":" +
|
||||
"{\"note\":{\"paragraphs\": [{\"text\": \"Test " +
|
||||
"paragraphs import\",\"config\":{},\"settings\":{}}]," +
|
||||
"paragraphs import\"," + "\"progressUpdateIntervalMs\":500," +
|
||||
"\"config\":{},\"settings\":{}}]," +
|
||||
"\"name\": \"Test Zeppelin notebook import\",\"config\": " +
|
||||
"{}}}}";
|
||||
Message messageReceived = notebookServer.deserializeMessage(msg);
|
||||
|
|
|
|||
|
|
@ -203,6 +203,7 @@ function auth () {
|
|||
function bootstrapApplication () {
|
||||
zeppelinWebApp.run(function ($rootScope, $location) {
|
||||
$rootScope.$on('$routeChangeStart', function (event, next, current) {
|
||||
$rootScope.pageTitle = 'Zeppelin'
|
||||
if (!$rootScope.ticket && next.$$route && !next.$$route.publicAccess) {
|
||||
$location.path('/')
|
||||
}
|
||||
|
|
|
|||
|
|
@ -74,6 +74,10 @@ function NotebookCtrl ($scope, $route, $routeParams, $location, $rootScope,
|
|||
}
|
||||
let currentSearchParagraph = 0
|
||||
|
||||
$scope.$watch('note', function (value) {
|
||||
$rootScope.pageTitle = value ? value.name : 'Zeppelin'
|
||||
}, true)
|
||||
|
||||
$scope.$on('setConnectedStatus', function (event, param) {
|
||||
if (connectedOnce && param) {
|
||||
initNotebook()
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ limitations under the License.
|
|||
<head>
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||
<meta charset="utf-8" />
|
||||
<title></title>
|
||||
<title ng-bind="$root.pageTitle">Zeppelin</title>
|
||||
<!-- disable caches for all browser -->
|
||||
<meta http-equiv="cache-control" content="max-age=0" />
|
||||
<meta http-equiv="cache-control" content="no-cache" />
|
||||
|
|
|
|||
|
|
@ -39,7 +39,6 @@ import org.apache.zeppelin.display.Input;
|
|||
import org.apache.zeppelin.interpreter.*;
|
||||
import org.apache.zeppelin.interpreter.remote.RemoteAngularObjectRegistry;
|
||||
import org.apache.zeppelin.interpreter.thrift.InterpreterCompletion;
|
||||
import org.apache.zeppelin.notebook.json.NotebookTypeAdapterFactory;
|
||||
import org.apache.zeppelin.notebook.repo.NotebookRepo;
|
||||
import org.apache.zeppelin.notebook.utility.IdHashes;
|
||||
import org.apache.zeppelin.resource.ResourcePoolUtils;
|
||||
|
|
@ -62,21 +61,8 @@ public class Note implements ParagraphJobListener, JsonSerializable {
|
|||
private static final long serialVersionUID = 7920699076577612429L;
|
||||
private static Gson gson = new GsonBuilder()
|
||||
.setPrettyPrinting()
|
||||
.registerTypeAdapterFactory(new NotebookTypeAdapterFactory<Paragraph>(Paragraph.class) {
|
||||
@Override
|
||||
protected void beforeWrite(Paragraph source, JsonElement toSerialize) {
|
||||
Map<String, ParagraphRuntimeInfo> runtimeInfos = source.getRuntimeInfos();
|
||||
if (runtimeInfos != null) {
|
||||
JsonElement jsonTree = gson.toJsonTree(runtimeInfos);
|
||||
if (toSerialize instanceof JsonObject) {
|
||||
JsonObject jsonObj = (JsonObject) toSerialize;
|
||||
jsonObj.add("runtimeInfos", jsonTree);
|
||||
}
|
||||
}
|
||||
}
|
||||
}).setDateFormat("yyyy-MM-dd HH:mm:ss.SSS")
|
||||
.setDateFormat("yyyy-MM-dd HH:mm:ss.SSS")
|
||||
.registerTypeAdapter(Date.class, new NotebookImportDeserializer())
|
||||
.setPrettyPrinting()
|
||||
.registerTypeAdapterFactory(Input.TypeAdapterFactory).create();
|
||||
|
||||
// threadpool for delayed persist of note
|
||||
|
|
@ -920,9 +906,16 @@ public class Note implements ParagraphJobListener, JsonSerializable {
|
|||
public static Note fromJson(String json) {
|
||||
Note note = gson.fromJson(json, Note.class);
|
||||
convertOldInput(note);
|
||||
note.resetRuntimeInfos();
|
||||
return note;
|
||||
}
|
||||
|
||||
public void resetRuntimeInfos() {
|
||||
for (Paragraph p : paragraphs) {
|
||||
p.clearRuntimeInfos();
|
||||
}
|
||||
}
|
||||
|
||||
private static void convertOldInput(Note note) {
|
||||
for (Paragraph p : note.paragraphs) {
|
||||
p.settings.convertOldInput();
|
||||
|
|
|
|||
|
|
@ -753,6 +753,12 @@ public class Paragraph extends Job implements Cloneable, JsonSerializable {
|
|||
}
|
||||
}
|
||||
|
||||
public void clearRuntimeInfos() {
|
||||
if (this.runtimeInfos != null) {
|
||||
this.runtimeInfos.clear();
|
||||
}
|
||||
}
|
||||
|
||||
public Map<String, ParagraphRuntimeInfo> getRuntimeInfos() {
|
||||
return runtimeInfos;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,82 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 org.apache.zeppelin.notebook.json;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.TypeAdapter;
|
||||
import com.google.gson.TypeAdapterFactory;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import com.google.gson.stream.JsonWriter;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Custom adapter type factory
|
||||
* Modify the jsonObject before serailaization/deserialization
|
||||
* @param <C> the type whose json is to be customized for serialization/deserialization
|
||||
*/
|
||||
public class NotebookTypeAdapterFactory<C> implements TypeAdapterFactory {
|
||||
private final Class<C> customizedClass;
|
||||
|
||||
public NotebookTypeAdapterFactory(Class<C> customizedClass) {
|
||||
this.customizedClass = customizedClass;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
// we use a runtime check to guarantee that 'C' and 'T' are equal
|
||||
public final <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
|
||||
return type.getRawType() == customizedClass ? (TypeAdapter<T>) customizeTypeAdapter(gson,
|
||||
(TypeToken<C>) type) : null;
|
||||
}
|
||||
|
||||
private TypeAdapter<C> customizeTypeAdapter(Gson gson, TypeToken<C> type) {
|
||||
final TypeAdapter<C> delegate = gson.getDelegateAdapter(this, type);
|
||||
final TypeAdapter<JsonElement> elementAdapter = gson.getAdapter(JsonElement.class);
|
||||
return new TypeAdapter<C>() {
|
||||
@Override
|
||||
public void write(JsonWriter out, C value) throws IOException {
|
||||
JsonElement tree = delegate.toJsonTree(value);
|
||||
beforeWrite(value, tree);
|
||||
elementAdapter.write(out, tree);
|
||||
}
|
||||
|
||||
@Override
|
||||
public C read(JsonReader in) throws IOException {
|
||||
JsonElement tree = elementAdapter.read(in);
|
||||
afterRead(tree);
|
||||
return delegate.fromJsonTree(tree);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Override this to change {@code toSerialize} before it is written to the
|
||||
* outgoing JSON stream.
|
||||
*/
|
||||
protected void beforeWrite(C source, JsonElement toSerialize) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Override this to change {@code deserialized} before it parsed into the
|
||||
* application type.
|
||||
*/
|
||||
protected void afterRead(JsonElement deserialized) {
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue