-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from twosigma/jarek/base_individual_component
jarek/base: create beakerx kernel base as individual component
- Loading branch information
Showing
921 changed files
with
77,652 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# IntelliJ | ||
.idea/ | ||
.iml | ||
|
||
# Gradle | ||
.gradle/ | ||
/build/ | ||
*/build/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,7 @@ | ||
# an empty repository | ||
# BeakerX: Beaker kernel base | ||
|
||
### Build and Install (linux and mac) | ||
|
||
``` | ||
./gradlew clean install | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
version 'unspecified' | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.6.5' | ||
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.6' | ||
compile group: 'org.apache.commons', name: 'commons-text', version: '1.1' | ||
compile group: 'commons-io', name: 'commons-io', version: '2.5' | ||
compile group: 'org.slf4j', name: 'slf4j-log4j12', version: '1.7.25' | ||
compile group: 'net.sf.py4j', name: 'py4j', version: '0.10.7' | ||
compile group: "commons-codec", name: "commons-codec", version: "1.9" | ||
compile group: 'com.google.code.gson', name: 'gson', version: '2.3.1' | ||
testCompile group: 'junit', name: 'junit', version: '4.12' | ||
} | ||
|
||
publishing { | ||
publications { | ||
maven(MavenPublication) { | ||
groupId 'com.twosigma' | ||
artifactId 'beakerx-kernel-base-api' | ||
version "$beakerxVersion" | ||
from components.java | ||
} | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
base-api/src/main/java/com/twosigma/beakerx/AutotranslationService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* 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; | ||
|
||
public interface AutotranslationService { | ||
|
||
String BEAKERX = "beakerx"; | ||
|
||
String update(String name, String json); | ||
|
||
String get(String name); | ||
|
||
String close(); | ||
|
||
String getContextAsString(); | ||
} |
46 changes: 46 additions & 0 deletions
46
base-api/src/main/java/com/twosigma/beakerx/BeakerXClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* 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; | ||
|
||
import java.util.List; | ||
import java.util.concurrent.SynchronousQueue; | ||
|
||
public interface BeakerXClient { | ||
|
||
String CODE_CELL_PATH = "codecell"; | ||
|
||
String URL_ARG = "urlarg"; | ||
|
||
void showProgressUpdate(String message, int progress); | ||
|
||
void delBeaker(); | ||
|
||
String update(String name, Object value); | ||
|
||
Object set(String name, Object value); | ||
|
||
Object get(final String name); | ||
|
||
SynchronousQueue<Object> getMessageQueue(String channel); | ||
|
||
List<CodeCell> getCodeCells(String tagFilter); | ||
|
||
void runByTag(String tag); | ||
|
||
String getContext(); | ||
|
||
String urlArg(String argName); | ||
} |
36 changes: 36 additions & 0 deletions
36
base-api/src/main/java/com/twosigma/beakerx/BeakerXClientManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* 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; | ||
|
||
|
||
public class BeakerXClientManager { | ||
|
||
public static String BEAKER_X_CLIENT_MANAGER_PATH = BeakerXClientManager.class.getName(); | ||
public static String BEAKER_X_CLIENT_MANAGER_GET = BeakerXClientManager.class.getSimpleName() + ".get()"; | ||
public static String BEAKER_X_CLIENT_MANAGER = BeakerXClientManager.class.getName() + ".get()"; | ||
|
||
private static BeakerXClient beakerXClientInst; | ||
|
||
public static BeakerXClient register(BeakerXClient beakerXClient) { | ||
beakerXClientInst = beakerXClient; | ||
return beakerXClientInst = beakerXClient; | ||
} | ||
|
||
public static BeakerXClient get() { | ||
return beakerXClientInst; | ||
} | ||
|
||
} |
37 changes: 37 additions & 0 deletions
37
base-api/src/main/java/com/twosigma/beakerx/ClassLoaderSwitcher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* 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; | ||
|
||
import com.twosigma.beakerx.evaluator.BaseEvaluator; | ||
|
||
public class ClassLoaderSwitcher { | ||
|
||
private ClassLoader oldld; | ||
private BaseEvaluator baseEvaluator; | ||
|
||
public ClassLoaderSwitcher(BaseEvaluator baseEvaluator) { | ||
this.baseEvaluator = baseEvaluator; | ||
} | ||
|
||
public void start() { | ||
this.oldld = Thread.currentThread().getContextClassLoader(); | ||
Thread.currentThread().setContextClassLoader(baseEvaluator.getClassLoader()); | ||
} | ||
|
||
public void end() { | ||
Thread.currentThread().setContextClassLoader(oldld); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
base-api/src/main/java/com/twosigma/beakerx/ClasspathManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* 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; | ||
|
||
import com.twosigma.beakerx.kernel.KernelManager; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
public class ClasspathManager { | ||
|
||
public static List<String> getJars() { | ||
List<String> pathsAsStrings = KernelManager.get().getClasspath().getPathsAsStrings(); | ||
return pathsAsStrings.stream() | ||
.filter(x -> x.endsWith(".jar")).collect(Collectors.toList()); | ||
} | ||
} |
167 changes: 167 additions & 0 deletions
167
base-api/src/main/java/com/twosigma/beakerx/CodeCell.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,167 @@ | ||
/* | ||
* Copyright 2014 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; | ||
|
||
import java.io.IOException; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.core.JsonGenerator; | ||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.JsonSerializer; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.SerializerProvider; | ||
|
||
import com.twosigma.beakerx.jvm.serialization.BeakerObjectConverter; | ||
import com.twosigma.beakerx.jvm.serialization.ObjectDeserializer; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class CodeCell { | ||
private final static Logger logger = LoggerFactory.getLogger(CodeCell.class.getName()); | ||
@JsonProperty("execution_count") | ||
private String executionCount; | ||
@JsonProperty("cell_type") | ||
private String cellType; | ||
private Object outputs; | ||
private Object metadata; | ||
private String source; | ||
|
||
public CodeCell() { } | ||
|
||
public String getExecutionCount() { | ||
return executionCount; | ||
} | ||
|
||
public void setExecutionCount(String executionCount) { | ||
this.executionCount = executionCount; | ||
} | ||
|
||
public String getCellType() { | ||
return cellType; | ||
} | ||
|
||
public void setCellType(String cellType) { | ||
this.cellType = cellType; | ||
} | ||
|
||
public Object getOutputs() { | ||
return outputs; | ||
} | ||
|
||
public void setOutputs(Object outputs) { | ||
this.outputs = outputs; | ||
} | ||
|
||
public Object getMetadata() { | ||
return metadata; | ||
} | ||
|
||
public void setMetadata(Object metadata) { | ||
this.metadata = metadata; | ||
} | ||
|
||
public String getSource() { | ||
return source; | ||
} | ||
|
||
public void setSource(String source) { | ||
this.source = source; | ||
} | ||
|
||
public static class Serializer extends JsonSerializer<CodeCell> { | ||
|
||
private final BeakerObjectConverter objectSerializerProvider; | ||
|
||
public Serializer(BeakerObjectConverter osp) { | ||
objectSerializerProvider = osp; | ||
} | ||
|
||
private BeakerObjectConverter getObjectSerializer() { | ||
return objectSerializerProvider; | ||
} | ||
|
||
@Override | ||
public void serialize(CodeCell value, | ||
JsonGenerator jgen, | ||
SerializerProvider provider) | ||
throws IOException, JsonProcessingException { | ||
|
||
synchronized (value) { | ||
jgen.writeStartObject(); | ||
jgen.writeStringField("type", "CodeCell"); | ||
jgen.writeStringField("execution_count", value.executionCount); | ||
jgen.writeStringField("cell_type", value.cellType); | ||
jgen.writeFieldName("outputs"); | ||
if (!getObjectSerializer().writeObject(value.outputs, jgen, true)) | ||
jgen.writeString(value.outputs.toString()); | ||
jgen.writeFieldName("metadata"); | ||
if (!getObjectSerializer().writeObject(value.metadata, jgen, true)) | ||
jgen.writeString(value.metadata.toString()); | ||
jgen.writeStringField("source", value.source); | ||
jgen.writeEndObject(); | ||
} | ||
} | ||
} | ||
|
||
public static class DeSerializer implements ObjectDeserializer { | ||
|
||
private final BeakerObjectConverter parent; | ||
|
||
public DeSerializer(BeakerObjectConverter p) { | ||
parent = p; | ||
parent.addKnownBeakerType("CodeCell"); | ||
} | ||
|
||
@Override | ||
public Object deserialize(JsonNode n, ObjectMapper mapper) { | ||
CodeCell o = null; | ||
try { | ||
String executionCount=null, cellType=null, source=null; | ||
Object outputs=null; | ||
Object metadata=null; | ||
if (n.has("execution_count")) | ||
executionCount = n.get("execution_count").asText(); | ||
if (n.has("cell_type")) | ||
cellType = n.get("cell_type").asText(); | ||
if (n.has("source")) | ||
source = n.get("source").asText(); | ||
if (n.has("outputs")) | ||
outputs = parent.deserialize(n.get("outputs"), mapper); | ||
if (n.has("metadata")) | ||
metadata = parent.deserialize(n.get("metadata"), mapper); | ||
|
||
o = new CodeCell(); | ||
o.setExecutionCount(executionCount); | ||
o.setCellType(cellType); | ||
o.setSource(source); | ||
o.setOutputs(outputs); | ||
o.setMetadata(metadata); | ||
} catch (Exception e) { | ||
logger.error("exception deserializing CodeCell ", e); | ||
e.printStackTrace(); | ||
} | ||
return o; | ||
} | ||
|
||
@Override | ||
public boolean canBeUsed(JsonNode n) { | ||
return n.has("type") && n.get("type").asText().equals("CodeCell"); | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.