From 113eec56e8612cf37f87b1c4475137b173032822 Mon Sep 17 00:00:00 2001 From: Marco Vogt Date: Sat, 26 Aug 2023 10:29:52 +0200 Subject: [PATCH] Minor code and formatting adjustments --- plugins/jupyter-integration/build.gradle | 4 +-- .../db/jupyter/JupyterContentServer.java | 1 - .../polypheny/db/jupyter/JupyterMapFS.java | 1 - .../polypheny/db/jupyter/JupyterPlugin.java | 13 ++++------ .../polypheny/db/jupyter/JupyterProxy.java | 2 +- .../db/jupyter/model/JupyterKernel.java | 9 ++++--- .../model/language/JupyterKernelLanguage.java | 1 - .../model/request/ContentsCreateRequest.java | 4 ++- .../model/response/NotebookContentModel.java | 20 +++++++++++++-- .../jupyter/model/response/NotebookModel.java | 4 ++- .../model/response/PolyMetadataModel.java | 5 +++- .../polypheny/db/jupyter/package-info.java | 25 ------------------- 12 files changed, 40 insertions(+), 49 deletions(-) delete mode 100644 plugins/jupyter-integration/src/main/java/org/polypheny/db/jupyter/package-info.java diff --git a/plugins/jupyter-integration/build.gradle b/plugins/jupyter-integration/build.gradle index 5adab09c06..7ff865de92 100644 --- a/plugins/jupyter-integration/build.gradle +++ b/plugins/jupyter-integration/build.gradle @@ -13,10 +13,10 @@ dependencies { exclude(group: "org.slf4j") } - implementation group: "net.sf.opencsv", name: "opencsv", version: opencsv_version // Apache 2.0 implementation group: "commons-io", name: "commons-io", version: commons_io_version // Apache 2.0 + // --- Test Compile --- testImplementation project(path: ":dbms", configuration: "test") testImplementation project(path: ":core", configuration: "tests") @@ -89,5 +89,3 @@ java { licensee { allow('Apache-2.0') } - - diff --git a/plugins/jupyter-integration/src/main/java/org/polypheny/db/jupyter/JupyterContentServer.java b/plugins/jupyter-integration/src/main/java/org/polypheny/db/jupyter/JupyterContentServer.java index 816a70cb17..414f6bffc4 100644 --- a/plugins/jupyter-integration/src/main/java/org/polypheny/db/jupyter/JupyterContentServer.java +++ b/plugins/jupyter-integration/src/main/java/org/polypheny/db/jupyter/JupyterContentServer.java @@ -328,5 +328,4 @@ private void error( Context ctx, int code, String message ) { ctx.result( String.format( "{\"message\": %s, \"reason\": null}", gson.toJson( message ) ) ); } - } diff --git a/plugins/jupyter-integration/src/main/java/org/polypheny/db/jupyter/JupyterMapFS.java b/plugins/jupyter-integration/src/main/java/org/polypheny/db/jupyter/JupyterMapFS.java index 8a8ec5123a..e7a005171f 100644 --- a/plugins/jupyter-integration/src/main/java/org/polypheny/db/jupyter/JupyterMapFS.java +++ b/plugins/jupyter-integration/src/main/java/org/polypheny/db/jupyter/JupyterMapFS.java @@ -34,7 +34,6 @@ import java.util.Objects; import java.util.Optional; import java.util.regex.Pattern; - import lombok.Getter; import lombok.extern.slf4j.Slf4j; import org.apache.calcite.avatica.util.Base64; diff --git a/plugins/jupyter-integration/src/main/java/org/polypheny/db/jupyter/JupyterPlugin.java b/plugins/jupyter-integration/src/main/java/org/polypheny/db/jupyter/JupyterPlugin.java index 2c74875676..203755147f 100644 --- a/plugins/jupyter-integration/src/main/java/org/polypheny/db/jupyter/JupyterPlugin.java +++ b/plugins/jupyter-integration/src/main/java/org/polypheny/db/jupyter/JupyterPlugin.java @@ -17,10 +17,11 @@ package org.polypheny.db.jupyter; import io.javalin.http.Context; +import java.security.SecureRandom; +import java.util.Arrays; import java.util.List; import java.util.Map; import java.util.Optional; -import java.util.function.BiConsumer; import java.util.function.Consumer; import java.util.function.Function; import java.util.stream.Collectors; @@ -43,9 +44,6 @@ import org.polypheny.db.webui.HttpServer; import org.polypheny.db.webui.HttpServer.HandlerType; -import java.security.SecureRandom; -import java.util.Arrays; - @Slf4j public class JupyterPlugin extends Plugin { @@ -150,18 +148,17 @@ private boolean createContainer( DockerInstance dockerInstance ) { if ( !this.container.waitTillStarted( this::testConnection, 20000 ) ) { this.container.destroy(); - throw new RuntimeException( "Failed to start jupyter container" ); + throw new RuntimeException( "Failed to start Jupyter Server container" ); } ConfigManager.getInstance().getConfig( CONFIG_CONTAINER_KEY ).setString( this.container.getContainerId() ); - log.info( "Jupyter container has been deployed." ); + log.info( "Jupyter Server container has been deployed" ); } else { this.container = maybeContainer.get(); } onContainerRunning(); return true; } catch ( Exception e ) { - e.printStackTrace(); - log.warn( "Unable to deploy Jupyter container." ); + log.warn( "Unable to deploy Jupyter Server container", e ); return false; } } diff --git a/plugins/jupyter-integration/src/main/java/org/polypheny/db/jupyter/JupyterProxy.java b/plugins/jupyter-integration/src/main/java/org/polypheny/db/jupyter/JupyterProxy.java index 8b939fb22e..020e5a96d7 100644 --- a/plugins/jupyter-integration/src/main/java/org/polypheny/db/jupyter/JupyterProxy.java +++ b/plugins/jupyter-integration/src/main/java/org/polypheny/db/jupyter/JupyterProxy.java @@ -17,12 +17,12 @@ package org.polypheny.db.jupyter; import com.google.gson.Gson; +import io.javalin.http.Context; import java.net.http.HttpResponse; import lombok.Setter; import lombok.extern.slf4j.Slf4j; import org.polypheny.db.jupyter.JupyterClient.JupyterServerException; import org.polypheny.db.jupyter.model.JupyterSessionManager; -import io.javalin.http.Context; @Slf4j public class JupyterProxy { diff --git a/plugins/jupyter-integration/src/main/java/org/polypheny/db/jupyter/model/JupyterKernel.java b/plugins/jupyter-integration/src/main/java/org/polypheny/db/jupyter/model/JupyterKernel.java index ea199213c3..7eac675726 100644 --- a/plugins/jupyter-integration/src/main/java/org/polypheny/db/jupyter/model/JupyterKernel.java +++ b/plugins/jupyter-integration/src/main/java/org/polypheny/db/jupyter/model/JupyterKernel.java @@ -211,9 +211,10 @@ public void execute( String code, String uuid ) { * @param variable the name of the variable the result will be stored in * @param expandParams whether to expand variables specified in the form ${varname} */ - public void executePolyCell( String query, String uuid, String language, String namespace, + public void executePolyCell( + String query, String uuid, String language, String namespace, String variable, boolean expandParams ) { - if ( query.strip().length() == 0 ) { + if ( query.strip().isEmpty() ) { execute( "", uuid ); // properly terminates the request return; } @@ -230,7 +231,7 @@ public void executePolyCell( String query, String uuid, String language, String webSocket.sendBinary( request, true ); } } catch ( Exception e ) { - e.printStackTrace(); + log.error( "Exception while executing a Polypheny Notebook cell.", e ); } } @@ -412,7 +413,7 @@ public CompletionStage onClose( WebSocket webSocket, int statusCode, String r @Override public void onError( WebSocket webSocket, Throwable error ) { - error.printStackTrace(); + log.error( "Exception in Jupyter WebSocket.", error ); jsm.removeKernel( kernelId ); Listener.super.onError( webSocket, error ); } diff --git a/plugins/jupyter-integration/src/main/java/org/polypheny/db/jupyter/model/language/JupyterKernelLanguage.java b/plugins/jupyter-integration/src/main/java/org/polypheny/db/jupyter/model/language/JupyterKernelLanguage.java index dbffdcc0d6..2138542e4d 100644 --- a/plugins/jupyter-integration/src/main/java/org/polypheny/db/jupyter/model/language/JupyterKernelLanguage.java +++ b/plugins/jupyter-integration/src/main/java/org/polypheny/db/jupyter/model/language/JupyterKernelLanguage.java @@ -88,4 +88,3 @@ public JupyterQueryPart( String code, boolean silent, boolean allowStdin ) { } } - diff --git a/plugins/jupyter-integration/src/main/java/org/polypheny/db/jupyter/model/request/ContentsCreateRequest.java b/plugins/jupyter-integration/src/main/java/org/polypheny/db/jupyter/model/request/ContentsCreateRequest.java index 705a274a91..557310b1d5 100644 --- a/plugins/jupyter-integration/src/main/java/org/polypheny/db/jupyter/model/request/ContentsCreateRequest.java +++ b/plugins/jupyter-integration/src/main/java/org/polypheny/db/jupyter/model/request/ContentsCreateRequest.java @@ -21,8 +21,10 @@ @Getter public class ContentsCreateRequest { - @SerializedName( "copy_from" ) + + @SerializedName("copy_from") private String copyFrom; private String ext; private String type; + } diff --git a/plugins/jupyter-integration/src/main/java/org/polypheny/db/jupyter/model/response/NotebookContentModel.java b/plugins/jupyter-integration/src/main/java/org/polypheny/db/jupyter/model/response/NotebookContentModel.java index 55a2146a8d..2c23561503 100644 --- a/plugins/jupyter-integration/src/main/java/org/polypheny/db/jupyter/model/response/NotebookContentModel.java +++ b/plugins/jupyter-integration/src/main/java/org/polypheny/db/jupyter/model/response/NotebookContentModel.java @@ -20,12 +20,28 @@ import lombok.Getter; import lombok.NoArgsConstructor; +/** + * See https://jupyter-server.readthedocs.io/en/latest/developers/rest-api.html + */ @NoArgsConstructor public class NotebookContentModel { - // see https://jupyter-server.readthedocs.io/en/latest/developers/rest-api.html @Getter - private String name, path, created, format, mimetype, size, writable, type; + private String name; + @Getter + private String path; + @Getter + private String created; + @Getter + private String format; + @Getter + private String mimetype; + @Getter + private String size; + @Getter + private String writable; + @Getter + private String type; @Getter @SerializedName("last_modified") diff --git a/plugins/jupyter-integration/src/main/java/org/polypheny/db/jupyter/model/response/NotebookModel.java b/plugins/jupyter-integration/src/main/java/org/polypheny/db/jupyter/model/response/NotebookModel.java index 2dc1631ac1..37de512c44 100644 --- a/plugins/jupyter-integration/src/main/java/org/polypheny/db/jupyter/model/response/NotebookModel.java +++ b/plugins/jupyter-integration/src/main/java/org/polypheny/db/jupyter/model/response/NotebookModel.java @@ -24,9 +24,11 @@ import lombok.Setter; import org.polypheny.db.jupyter.model.language.JupyterKernelLanguage; +/** + * See https://nbformat.readthedocs.io/en/latest/format_description.html + */ @NoArgsConstructor public class NotebookModel { - // see https://nbformat.readthedocs.io/en/latest/format_description.html @Getter @Setter diff --git a/plugins/jupyter-integration/src/main/java/org/polypheny/db/jupyter/model/response/PolyMetadataModel.java b/plugins/jupyter-integration/src/main/java/org/polypheny/db/jupyter/model/response/PolyMetadataModel.java index 5c1216e208..9a7710f705 100644 --- a/plugins/jupyter-integration/src/main/java/org/polypheny/db/jupyter/model/response/PolyMetadataModel.java +++ b/plugins/jupyter-integration/src/main/java/org/polypheny/db/jupyter/model/response/PolyMetadataModel.java @@ -29,7 +29,10 @@ public class PolyMetadataModel { private String cellType; @Getter - private String namespace, language; + private String namespace; + + @Getter + private String language; @Getter @SerializedName("result_variable") diff --git a/plugins/jupyter-integration/src/main/java/org/polypheny/db/jupyter/package-info.java b/plugins/jupyter-integration/src/main/java/org/polypheny/db/jupyter/package-info.java deleted file mode 100644 index be871d1580..0000000000 --- a/plugins/jupyter-integration/src/main/java/org/polypheny/db/jupyter/package-info.java +++ /dev/null @@ -1,25 +0,0 @@ - -/* - * Copyright 2019-2023 The Polypheny Project - * - * 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. - */ - -/** - * Polypheny-DB integration of Jupyter Notebook functionality. - */ - -package org.polypheny.db.jupyter; - - -