From 91f75e03a6a8586d2b5cf3f74d2b354cc446919c Mon Sep 17 00:00:00 2001 From: Lee moon soo Date: Mon, 11 Jan 2016 12:43:17 -0800 Subject: [PATCH 01/16] distributed resource pool --- .../resourcepool/DistributedResourcePool.java | 61 ++++++++++++ .../resourcepool/LocalResourcePool.java | 84 ++++++++++++++++ .../zeppelin/resourcepool/Resource.java | 95 +++++++++++++++++++ .../zeppelin/resourcepool/ResourceId.java | 53 +++++++++++ .../zeppelin/resourcepool/ResourcePool.java | 55 +++++++++++ .../resourcepool/ResourcePoolConnector.java | 28 ++++++ .../resourcepool/ResourcePoolListener.java | 23 +++++ .../zeppelin/resourcepool/ResourceSet.java | 75 +++++++++++++++ .../DistributedResourcePoolTest.java | 43 +++++++++ .../resourcepool/LocalResourcePoolTest.java | 48 ++++++++++ .../resourcepool/ResourceSetTest.java | 53 +++++++++++ 11 files changed, 618 insertions(+) create mode 100644 zeppelin-interpreter/src/main/java/org/apache/zeppelin/resourcepool/DistributedResourcePool.java create mode 100644 zeppelin-interpreter/src/main/java/org/apache/zeppelin/resourcepool/LocalResourcePool.java create mode 100644 zeppelin-interpreter/src/main/java/org/apache/zeppelin/resourcepool/Resource.java create mode 100644 zeppelin-interpreter/src/main/java/org/apache/zeppelin/resourcepool/ResourceId.java create mode 100644 zeppelin-interpreter/src/main/java/org/apache/zeppelin/resourcepool/ResourcePool.java create mode 100644 zeppelin-interpreter/src/main/java/org/apache/zeppelin/resourcepool/ResourcePoolConnector.java create mode 100644 zeppelin-interpreter/src/main/java/org/apache/zeppelin/resourcepool/ResourcePoolListener.java create mode 100644 zeppelin-interpreter/src/main/java/org/apache/zeppelin/resourcepool/ResourceSet.java create mode 100644 zeppelin-interpreter/src/test/java/org/apache/zeppelin/resourcepool/DistributedResourcePoolTest.java create mode 100644 zeppelin-interpreter/src/test/java/org/apache/zeppelin/resourcepool/LocalResourcePoolTest.java create mode 100644 zeppelin-interpreter/src/test/java/org/apache/zeppelin/resourcepool/ResourceSetTest.java diff --git a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/resourcepool/DistributedResourcePool.java b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/resourcepool/DistributedResourcePool.java new file mode 100644 index 00000000000..3b65efa6a8e --- /dev/null +++ b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/resourcepool/DistributedResourcePool.java @@ -0,0 +1,61 @@ +/* + * 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.resourcepool; + +import java.io.Serializable; +import java.util.UUID; + +/** + * distributed resource pool + */ +public class DistributedResourcePool extends LocalResourcePool { + + private final ResourcePoolConnector connector; + + public DistributedResourcePool(String id, ResourcePoolConnector connector) { + super(id); + this.connector = connector; + } + + /** + * get resource by name. + * @param name + * @return null if resource not found. + */ + @Override + public Resource get(String name) { + // try local first + Resource resource = super.get(name); + if (resource != null) { + return resource; + } + + ResourceSet resources = connector.getAllResourcesExcept(id()).filterByName(name); + if (resources.isEmpty()) { + return null; + } else { + return resources.get(0); + } + } + + @Override + public ResourceSet getAll() { + ResourceSet all = super.getAll(); + all.addAll(connector.getAllResourcesExcept(id())); + return all; + } +} diff --git a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/resourcepool/LocalResourcePool.java b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/resourcepool/LocalResourcePool.java new file mode 100644 index 00000000000..2af6da715e8 --- /dev/null +++ b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/resourcepool/LocalResourcePool.java @@ -0,0 +1,84 @@ +/* + * 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.resourcepool; + +import java.util.*; + +/** + * ResourcePool + */ +public class LocalResourcePool implements ResourcePool { + private final String resourcePoolId; + private final Map resources = new HashMap(); + + /** + * @param id unique id + */ + public LocalResourcePool(String id) { + resourcePoolId = id; + } + + /** + * Get unique id of this resource pool + * @return + */ + @Override + public String id() { + return resourcePoolId; + } + + /** + * Get resource + * @return null if resource not found + */ + @Override + public Resource get(String name) { + synchronized (resources) { + ResourceId resourceId = new ResourceId(resourcePoolId, name); + return resources.get(resourceId); + } + } + + @Override + public ResourceSet getAll() { + synchronized (resources) { + return new ResourceSet(resources.values()); + } + } + + /** + * Put resource into the pull + * @param + * @param object object to put into the resource + */ + @Override + public void put(String name, Object object) { + synchronized (resources) { + ResourceId resourceId = new ResourceId(resourcePoolId, name); + + Resource resource = new Resource(resourceId, object); + resources.put(resourceId, resource); + } + } + + @Override + public Resource remove(String name) { + synchronized (resources) { + return resources.remove(new ResourceId(resourcePoolId, name)); + } + } +} diff --git a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/resourcepool/Resource.java b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/resourcepool/Resource.java new file mode 100644 index 00000000000..1d31094f601 --- /dev/null +++ b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/resourcepool/Resource.java @@ -0,0 +1,95 @@ +/* + * 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.resourcepool; + +import java.io.Serializable; + +/** + * Information and reference to the resource + */ +public class Resource { + private final Object r; + private final boolean serializable; + private final ResourceId resourceId; + private final String className; + + + /** + * Create local resource + * @param resourceId + * @param r must not be null + */ + Resource(ResourceId resourceId, Object r) { + this.r = r; + this.resourceId = resourceId; + this.serializable = r instanceof Serializable; + this.className = r.getClass().getName(); + } + + /** + * Create remote object + * @param resourceId + */ + Resource(ResourceId resourceId, boolean serializable, String className) { + this.r = null; + this.resourceId = resourceId; + this.serializable = serializable; + this.className = className; + } + + public ResourceId getResourceId() { + return resourceId; + } + + public String getClassName() { + return className; + } + + /** + * + * @return null when this is remote resource and not serializable. + */ + public Object get() { + if (isLocal()) { + return r; + } else if (isSerializable()){ + return r; + } else { + return null; + } + } + + public boolean isSerializable() { + return serializable; + } + + /** + * if it is remote object + * @return + */ + public boolean isRemote() { + return !isLocal(); + } + + /** + * Whether it is locally accessible or not + * @return + */ + public boolean isLocal() { + return r != null; + } +} diff --git a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/resourcepool/ResourceId.java b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/resourcepool/ResourceId.java new file mode 100644 index 00000000000..9c1d92b92eb --- /dev/null +++ b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/resourcepool/ResourceId.java @@ -0,0 +1,53 @@ +/* + * 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.resourcepool; + +/** + * Identifying resource + */ +public class ResourceId { + private final String resourcePoolId; + private final String name; + + ResourceId(String resourcePoolId, String name) { + this.resourcePoolId = resourcePoolId; + this.name = name; + } + + public String getResourcePoolId() { + return resourcePoolId; + } + + public String getName() { + return name; + } + + @Override + public int hashCode() { + return (resourcePoolId + name).hashCode(); + } + + @Override + public boolean equals(Object o) { + if (o instanceof ResourceId) { + ResourceId r = (ResourceId) o; + return (r.name.equals(name) && r.resourcePoolId.equals(resourcePoolId)); + } else { + return false; + } + } +} diff --git a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/resourcepool/ResourcePool.java b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/resourcepool/ResourcePool.java new file mode 100644 index 00000000000..08026b34514 --- /dev/null +++ b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/resourcepool/ResourcePool.java @@ -0,0 +1,55 @@ +/* + * 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.resourcepool; + +/** + * Interface for ResourcePool + */ +public interface ResourcePool { + /** + * Get unique id of the resource pool + * @return + */ + public String id(); + + /** + * Get resource from name + * @param name Resource name + * @return null if resource not found + */ + public Resource get(String name); + + /** + * Get all resources + * @return + */ + public ResourceSet getAll(); + + /** + * Put an object into resource pool + * @param name + * @param object + */ + public void put(String name, Object object); + + /** + * Remove object + * @param name Resource name to remove + * @return removed Resource. null if resource not found + */ + public Resource remove(String name); +} diff --git a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/resourcepool/ResourcePoolConnector.java b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/resourcepool/ResourcePoolConnector.java new file mode 100644 index 00000000000..c928f100df6 --- /dev/null +++ b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/resourcepool/ResourcePoolConnector.java @@ -0,0 +1,28 @@ +/* + * 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.resourcepool; + +/** + * Connect resource pools running in remote process + */ +public interface ResourcePoolConnector { + /** + * Get list of resources from all resource pool + * @return + */ + public ResourceSet getAllResourcesExcept(String excludePoolId); +} diff --git a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/resourcepool/ResourcePoolListener.java b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/resourcepool/ResourcePoolListener.java new file mode 100644 index 00000000000..2638ea94fab --- /dev/null +++ b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/resourcepool/ResourcePoolListener.java @@ -0,0 +1,23 @@ +/* + * 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.resourcepool; + +/** + * Event from LocalResourcePool + */ +public interface ResourcePoolListener { +} diff --git a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/resourcepool/ResourceSet.java b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/resourcepool/ResourceSet.java new file mode 100644 index 00000000000..e9508233647 --- /dev/null +++ b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/resourcepool/ResourceSet.java @@ -0,0 +1,75 @@ +/* + * 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.resourcepool; + +import java.util.Collection; +import java.util.LinkedList; +import java.util.regex.Pattern; + +/** + * List of resources + */ +public class ResourceSet extends LinkedList { + + public ResourceSet(Collection resources) { + super(resources); + } + + public ResourceSet() { + super(); + } + + public ResourceSet filterByNameRegex(String regex) { + ResourceSet result = new ResourceSet(); + for (Resource r : this) { + if (Pattern.matches(regex, r.getResourceId().getName())) { + result.add(r); + } + } + return result; + } + + public ResourceSet filterByName(String name) { + ResourceSet result = new ResourceSet(); + for (Resource r : this) { + if (r.getResourceId().getName().equals(name)) { + result.add(r); + } + } + return result; + } + + public ResourceSet filterByClassnameRegex(String regex) { + ResourceSet result = new ResourceSet(); + for (Resource r : this) { + if (Pattern.matches(regex, r.getClassName())) { + result.add(r); + } + } + return result; + } + + public ResourceSet filterByClassname(String className) { + ResourceSet result = new ResourceSet(); + for (Resource r : this) { + if (r.getClassName().equals(className)) { + result.add(r); + } + } + return result; + } +} diff --git a/zeppelin-interpreter/src/test/java/org/apache/zeppelin/resourcepool/DistributedResourcePoolTest.java b/zeppelin-interpreter/src/test/java/org/apache/zeppelin/resourcepool/DistributedResourcePoolTest.java new file mode 100644 index 00000000000..9b611657b88 --- /dev/null +++ b/zeppelin-interpreter/src/test/java/org/apache/zeppelin/resourcepool/DistributedResourcePoolTest.java @@ -0,0 +1,43 @@ +package org.apache.zeppelin.resourcepool; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +/** + * Unittest for DistributedResourcePool + */ +public class DistributedResourcePoolTest { + + @Test + public void testDistributedResourcePool() { + final LocalResourcePool pool2 = new LocalResourcePool("pool2"); + final LocalResourcePool pool3 = new LocalResourcePool("pool3"); + + DistributedResourcePool pool1 = new DistributedResourcePool("pool1", new ResourcePoolConnector() { + @Override + public ResourceSet getAllResourcesExcept(String excludePoolId) { + ResourceSet set = pool2.getAll(); + set.addAll(pool3.getAll()); + return set; + } + }); + + assertEquals(0, pool1.getAll().size()); + + + // test get() can get from pool + pool2.put("object1", "value2"); + assertEquals(1, pool1.getAll().size()); + assertEquals("value2", pool1.get("object1").get()); + + // test get() is locality aware + pool1.put("object1", "value1"); + assertEquals(1, pool2.getAll().size()); + assertEquals("value1", pool1.get("object1").get()); + + // test getAll() is locality aware + assertEquals("value1", pool1.getAll().get(0).get()); + assertEquals("value2", pool1.getAll().get(1).get()); + } +} diff --git a/zeppelin-interpreter/src/test/java/org/apache/zeppelin/resourcepool/LocalResourcePoolTest.java b/zeppelin-interpreter/src/test/java/org/apache/zeppelin/resourcepool/LocalResourcePoolTest.java new file mode 100644 index 00000000000..8368f128c1a --- /dev/null +++ b/zeppelin-interpreter/src/test/java/org/apache/zeppelin/resourcepool/LocalResourcePoolTest.java @@ -0,0 +1,48 @@ +/* + * 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.resourcepool; + +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * Unittest for LocalResourcePool + */ +public class LocalResourcePoolTest { + + @Test + public void testGetPutResourcePool() { + + LocalResourcePool pool = new LocalResourcePool("pool1"); + assertEquals("pool1", pool.id()); + + assertNull(pool.get("notExists")); + pool.put("item1", "value1"); + Resource resource = pool.get("item1"); + assertNotNull(resource); + assertEquals(pool.id(), resource.getResourceId().getResourcePoolId()); + assertEquals("value1", resource.get()); + assertTrue(resource.isLocal()); + assertTrue(resource.isSerializable()); + + assertEquals(1, pool.getAll().size()); + + assertNotNull(pool.remove("item1")); + assertNull(pool.remove("item1")); + } +} diff --git a/zeppelin-interpreter/src/test/java/org/apache/zeppelin/resourcepool/ResourceSetTest.java b/zeppelin-interpreter/src/test/java/org/apache/zeppelin/resourcepool/ResourceSetTest.java new file mode 100644 index 00000000000..d43cd137d3d --- /dev/null +++ b/zeppelin-interpreter/src/test/java/org/apache/zeppelin/resourcepool/ResourceSetTest.java @@ -0,0 +1,53 @@ +/* + * 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.resourcepool; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +/** + * Unit test for ResourceSet + */ +public class ResourceSetTest { + + @Test + public void testFilterByName() { + ResourceSet set = new ResourceSet(); + + set.add(new Resource(new ResourceId("poo1", "resource1"), "value1")); + set.add(new Resource(new ResourceId("poo1", "resource2"), new Integer(2))); + assertEquals(2, set.filterByNameRegex(".*").size()); + assertEquals(1, set.filterByNameRegex("resource1").size()); + assertEquals(1, set.filterByNameRegex("resource2").size()); + assertEquals(0, set.filterByNameRegex("res").size()); + assertEquals(2, set.filterByNameRegex("res.*").size()); + } + + @Test + public void testFilterByClassName() { + ResourceSet set = new ResourceSet(); + + set.add(new Resource(new ResourceId("poo1", "resource1"), "value1")); + set.add(new Resource(new ResourceId("poo1", "resource2"), new Integer(2))); + + assertEquals(1, set.filterByClassnameRegex(".*String").size()); + assertEquals(1, set.filterByClassnameRegex(String.class.getName()).size()); + assertEquals(1, set.filterByClassnameRegex(".*Integer").size()); + assertEquals(1, set.filterByClassnameRegex(Integer.class.getName()).size()); + } +} From 0f6cb984f78c4933d0117e711784670fe41e98c1 Mon Sep 17 00:00:00 2001 From: Lee moon soo Date: Mon, 18 Jan 2016 12:30:17 -0800 Subject: [PATCH 02/16] distributed resource pool across interpreter processes --- .../zeppelin/spark/DepInterpreterTest.java | 1 + .../zeppelin/spark/SparkInterpreterTest.java | 2 +- .../spark/SparkSqlInterpreterTest.java | 2 + .../interpreter/InterpreterContext.java | 8 + .../interpreter/InterpreterGroup.java | 30 +- .../interpreter/remote/RemoteInterpreter.java | 7 +- .../remote/RemoteInterpreterEventClient.java | 225 ++ .../remote/RemoteInterpreterEventPoller.java | 136 +- .../remote/RemoteInterpreterServer.java | 117 +- .../thrift/RemoteInterpreterContext.java | 2 +- .../thrift/RemoteInterpreterEvent.java | 2 +- .../thrift/RemoteInterpreterEventType.java | 8 +- .../thrift/RemoteInterpreterResult.java | 2 +- .../thrift/RemoteInterpreterService.java | 3501 ++++++++++++++++- .../resource/ByteBufferInputStream.java | 58 + .../DistributedResourcePool.java | 39 +- .../LocalResourcePool.java | 2 +- .../zeppelin/resource/RemoteResource.java | 39 + .../{resourcepool => resource}/Resource.java | 47 +- .../ResourceId.java | 2 +- .../ResourcePool.java | 2 +- .../ResourcePoolConnector.java | 8 +- .../ResourceSet.java | 2 +- .../thrift/RemoteInterpreterService.thrift | 15 +- .../interpreter/InterpreterContextTest.java | 3 +- .../remote/RemoteAngularObjectTest.java | 5 +- .../remote/RemoteInterpreterTest.java | 10 + .../mock/MockInterpreterResourcePool.java | 112 + .../resource/DistributedResourcePoolTest.java | 182 + .../LocalResourcePoolTest.java | 2 +- .../ResourceSetTest.java | 2 +- .../zeppelin/resource/ResourceTest.java} | 18 +- .../DistributedResourcePoolTest.java | 43 - .../scheduler/RemoteSchedulerTest.java | 4 + .../apache/zeppelin/notebook/Paragraph.java | 4 + .../interpreter/InterpreterFactoryTest.java | 3 +- 36 files changed, 4469 insertions(+), 176 deletions(-) create mode 100644 zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterEventClient.java create mode 100644 zeppelin-interpreter/src/main/java/org/apache/zeppelin/resource/ByteBufferInputStream.java rename zeppelin-interpreter/src/main/java/org/apache/zeppelin/{resourcepool => resource}/DistributedResourcePool.java (69%) rename zeppelin-interpreter/src/main/java/org/apache/zeppelin/{resourcepool => resource}/LocalResourcePool.java (98%) create mode 100644 zeppelin-interpreter/src/main/java/org/apache/zeppelin/resource/RemoteResource.java rename zeppelin-interpreter/src/main/java/org/apache/zeppelin/{resourcepool => resource}/Resource.java (68%) rename zeppelin-interpreter/src/main/java/org/apache/zeppelin/{resourcepool => resource}/ResourceId.java (97%) rename zeppelin-interpreter/src/main/java/org/apache/zeppelin/{resourcepool => resource}/ResourcePool.java (97%) rename zeppelin-interpreter/src/main/java/org/apache/zeppelin/{resourcepool => resource}/ResourcePoolConnector.java (88%) rename zeppelin-interpreter/src/main/java/org/apache/zeppelin/{resourcepool => resource}/ResourceSet.java (98%) create mode 100644 zeppelin-interpreter/src/test/java/org/apache/zeppelin/interpreter/remote/mock/MockInterpreterResourcePool.java create mode 100644 zeppelin-interpreter/src/test/java/org/apache/zeppelin/resource/DistributedResourcePoolTest.java rename zeppelin-interpreter/src/test/java/org/apache/zeppelin/{resourcepool => resource}/LocalResourcePoolTest.java (97%) rename zeppelin-interpreter/src/test/java/org/apache/zeppelin/{resourcepool => resource}/ResourceSetTest.java (97%) rename zeppelin-interpreter/src/{main/java/org/apache/zeppelin/resourcepool/ResourcePoolListener.java => test/java/org/apache/zeppelin/resource/ResourceTest.java} (65%) delete mode 100644 zeppelin-interpreter/src/test/java/org/apache/zeppelin/resourcepool/DistributedResourcePoolTest.java diff --git a/spark/src/test/java/org/apache/zeppelin/spark/DepInterpreterTest.java b/spark/src/test/java/org/apache/zeppelin/spark/DepInterpreterTest.java index efa8fae2546..56a6df9c761 100644 --- a/spark/src/test/java/org/apache/zeppelin/spark/DepInterpreterTest.java +++ b/spark/src/test/java/org/apache/zeppelin/spark/DepInterpreterTest.java @@ -60,6 +60,7 @@ public void setUp() throws Exception { context = new InterpreterContext("note", "id", "title", "text", new HashMap(), new GUI(), new AngularObjectRegistry(intpGroup.getId(), null), + null, new LinkedList()); } diff --git a/spark/src/test/java/org/apache/zeppelin/spark/SparkInterpreterTest.java b/spark/src/test/java/org/apache/zeppelin/spark/SparkInterpreterTest.java index b6299786ead..7b442ce2730 100644 --- a/spark/src/test/java/org/apache/zeppelin/spark/SparkInterpreterTest.java +++ b/spark/src/test/java/org/apache/zeppelin/spark/SparkInterpreterTest.java @@ -80,7 +80,7 @@ public void setUp() throws Exception { InterpreterGroup intpGroup = new InterpreterGroup(); context = new InterpreterContext("note", "id", "title", "text", new HashMap(), new GUI(), new AngularObjectRegistry( - intpGroup.getId(), null), + intpGroup.getId(), null), null, new LinkedList()); } diff --git a/spark/src/test/java/org/apache/zeppelin/spark/SparkSqlInterpreterTest.java b/spark/src/test/java/org/apache/zeppelin/spark/SparkSqlInterpreterTest.java index 4688cf8347e..60be370b2b3 100644 --- a/spark/src/test/java/org/apache/zeppelin/spark/SparkSqlInterpreterTest.java +++ b/spark/src/test/java/org/apache/zeppelin/spark/SparkSqlInterpreterTest.java @@ -30,6 +30,7 @@ import org.apache.zeppelin.interpreter.InterpreterGroup; import org.apache.zeppelin.interpreter.InterpreterResult; import org.apache.zeppelin.interpreter.InterpreterResult.Type; +import org.apache.zeppelin.resource.LocalResourcePool; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -69,6 +70,7 @@ public void setUp() throws Exception { } context = new InterpreterContext("note", "id", "title", "text", new HashMap(), new GUI(), new AngularObjectRegistry(intpGroup.getId(), null), + null, new LinkedList()); } diff --git a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/InterpreterContext.java b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/InterpreterContext.java index 0417f9108bc..cf2cf24ba95 100644 --- a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/InterpreterContext.java +++ b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/InterpreterContext.java @@ -22,6 +22,7 @@ import org.apache.zeppelin.display.AngularObjectRegistry; import org.apache.zeppelin.display.GUI; +import org.apache.zeppelin.resource.ResourcePool; /** * Interpreter context @@ -49,6 +50,7 @@ public static void remove() { private final Map config; private GUI gui; private AngularObjectRegistry angularObjectRegistry; + private ResourcePool resourcePool; private List runners; public InterpreterContext(String noteId, @@ -58,6 +60,7 @@ public InterpreterContext(String noteId, Map config, GUI gui, AngularObjectRegistry angularObjectRegistry, + ResourcePool resourcePool, List runners ) { this.noteId = noteId; @@ -67,6 +70,7 @@ public InterpreterContext(String noteId, this.config = config; this.gui = gui; this.angularObjectRegistry = angularObjectRegistry; + this.resourcePool = resourcePool; this.runners = runners; } @@ -99,6 +103,10 @@ public AngularObjectRegistry getAngularObjectRegistry() { return angularObjectRegistry; } + public ResourcePool getResourcePool() { + return resourcePool; + } + public List getRunners() { return runners; } diff --git a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/InterpreterGroup.java b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/InterpreterGroup.java index 5af624178cd..0ceeb405768 100644 --- a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/InterpreterGroup.java +++ b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/InterpreterGroup.java @@ -17,14 +17,12 @@ package org.apache.zeppelin.interpreter; -import java.util.LinkedList; -import java.util.List; -import java.util.Properties; -import java.util.Random; +import java.util.*; import org.apache.log4j.Logger; import org.apache.zeppelin.display.AngularObjectRegistry; import org.apache.zeppelin.interpreter.remote.RemoteInterpreterProcess; +import org.apache.zeppelin.resource.ResourcePool; /** * InterpreterGroup is list of interpreters in the same group. @@ -37,13 +35,27 @@ public class InterpreterGroup extends LinkedList{ AngularObjectRegistry angularObjectRegistry; RemoteInterpreterProcess remoteInterpreterProcess; // attached remote interpreter process + ResourcePool resourcePool; + + private static final Map allInterpreterGroups = + Collections.synchronizedMap(new HashMap()); + + public static InterpreterGroup get(String id) { + return allInterpreterGroups.get(id); + } + + public static Collection getAll() { + return new LinkedList(allInterpreterGroups.values()); + } public InterpreterGroup(String id) { this.id = id; + allInterpreterGroups.put(id, this); } public InterpreterGroup() { getId(); + allInterpreterGroups.put(id, this); } private static String generateId() { @@ -135,5 +147,15 @@ public void run() { remoteInterpreterProcess.dereference(); } } + + allInterpreterGroups.remove(id); + } + + public void setResourcePool(ResourcePool resourcePool) { + this.resourcePool = resourcePool; + } + + public ResourcePool getResourcePool() { + return resourcePool; } } diff --git a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreter.java b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreter.java index 455156ce113..b48181c9ed8 100644 --- a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreter.java +++ b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreter.java @@ -135,7 +135,8 @@ private synchronized void init() { try { for (Interpreter intp : this.getInterpreterGroup()) { logger.info("Create remote interpreter {}", intp.getClassName()); - client.createInterpreter(intp.getClassName(), (Map) property); + client.createInterpreter(getInterpreterGroup().getId(), + intp.getClassName(), (Map) property); } } catch (TException e) { @@ -283,6 +284,10 @@ public FormType getFormType() { @Override public int getProgress(InterpreterContext context) { RemoteInterpreterProcess interpreterProcess = getInterpreterProcess(); + if (interpreterProcess == null || !interpreterProcess.isRunning()) { + return 0; + } + Client client = null; try { client = interpreterProcess.getClient(); diff --git a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterEventClient.java b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterEventClient.java new file mode 100644 index 00000000000..f1f97fea1a0 --- /dev/null +++ b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterEventClient.java @@ -0,0 +1,225 @@ +/* + * 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.interpreter.remote; + +import com.google.gson.Gson; +import org.apache.zeppelin.display.AngularObject; +import org.apache.zeppelin.interpreter.InterpreterContextRunner; +import org.apache.zeppelin.interpreter.thrift.RemoteInterpreterEvent; +import org.apache.zeppelin.interpreter.thrift.RemoteInterpreterEventType; +import org.apache.zeppelin.resource.*; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.nio.ByteBuffer; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +/** + * Thread connection ZeppelinServer -> RemoteInterpreterServer does not provide + * remote method invocation from RemoteInterpreterServer -> ZeppelinServer + * + * This class provides event send and get response from RemoteInterpreterServer to + * ZeppelinServer. + * + * RemoteInterpreterEventPoller is counter part in ZeppelinServer + */ +public class RemoteInterpreterEventClient implements ResourcePoolConnector { + private final Logger logger = LoggerFactory.getLogger(RemoteInterpreterEvent.class); + private final List eventQueue = new LinkedList(); + private final List getAllResourceResponse = new LinkedList(); + private final Map getResourceResponse = new HashMap(); + private final Gson gson = new Gson(); + + /** + * Run paragraph + * @param runner + */ + public void run(InterpreterContextRunner runner) { + sendEvent(new RemoteInterpreterEvent( + RemoteInterpreterEventType.RUN_INTERPRETER_CONTEXT_RUNNER, + gson.toJson(runner))); + } + + /** + * notify new angularObject creation + * @param object + */ + public void angularObjectAdd(AngularObject object) { + sendEvent(new RemoteInterpreterEvent( + RemoteInterpreterEventType.ANGULAR_OBJECT_ADD, gson.toJson(object))); + } + + /** + * notify angularObject update + */ + public void angularObjectUpdate(AngularObject object) { + sendEvent(new RemoteInterpreterEvent( + RemoteInterpreterEventType.ANGULAR_OBJECT_UPDATE, gson.toJson(object))); + } + + /** + * notify angularObject removal + */ + public void angularObjectRemove(String name, String noteId) { + Map removeObject = new HashMap(); + removeObject.put("name", name); + removeObject.put("noteId", noteId); + + sendEvent(new RemoteInterpreterEvent( + RemoteInterpreterEventType.ANGULAR_OBJECT_REMOVE, gson.toJson(removeObject))); + } + + + /** + * Get all resources except for specific resourcePool + * @param excludePoolId resource pool for exclusion. + * @return + */ + @Override + public ResourceSet getAllResourcesExcept(String excludePoolId) { + // request + sendEvent(new RemoteInterpreterEvent( + RemoteInterpreterEventType.RESOURCE_POOL_GET_ALL, + excludePoolId)); + + synchronized (getAllResourceResponse) { + while (getAllResourceResponse.isEmpty()) { + try { + getAllResourceResponse.wait(); + } catch (InterruptedException e) { + logger.warn(e.getMessage(), e); + } + } + ResourceSet resourceSet = getAllResourceResponse.remove(0); + return resourceSet; + } + } + + @Override + public Object readResource(ResourceId resourceId) { + logger.debug("Request Read Resource {} from ZeppelinServer", resourceId.getName()); + synchronized (getResourceResponse) { + // wait for previous response consumed + while (getResourceResponse.containsKey(resourceId)) { + try { + getResourceResponse.wait(); + } catch (InterruptedException e) { + logger.warn(e.getMessage(), e); + } + } + + // send request + Gson gson = new Gson(); + sendEvent(new RemoteInterpreterEvent( + RemoteInterpreterEventType.RESOURCE_GET, + gson.toJson(resourceId))); + + // wait for response + while (!getResourceResponse.containsKey(resourceId)) { + try { + getResourceResponse.wait(); + } catch (InterruptedException e) { + logger.warn(e.getMessage(), e); + } + } + Object o = getResourceResponse.remove(resourceId); + getResourceResponse.notifyAll(); + return o; + } + } + + /** + * Supposed to call from RemoteInterpreterEventPoller + */ + public void putResponseGetAllResources(List resources) { + logger.debug("ResourceSet from ZeppelinServer"); + ResourceSet resourceSet = new ResourceSet(); + + for (String res : resources) { + RemoteResource resource = gson.fromJson(res, RemoteResource.class); + resource.setResourcePoolConnector(this); + resourceSet.add(resource); + } + + synchronized (getAllResourceResponse) { + getAllResourceResponse.add(resourceSet); + getAllResourceResponse.notify(); + } + } + + /** + * Supposed to call from RemoteInterpreterEventPoller + * @param resourceId json serialized ResourceId + * @param object java serialized of the object + */ + public void putResponseGetResource(String resourceId, ByteBuffer object) { + ResourceId rid = gson.fromJson(resourceId, ResourceId.class); + + logger.debug("Response resource {} from RemoteInterpreter", rid.getName()); + + Object o = null; + try { + o = Resource.deserializeObject(object); + } catch (IOException e) { + logger.error(e.getMessage(), e); + } catch (ClassNotFoundException e) { + logger.error(e.getMessage(), e); + } + + synchronized (getResourceResponse) { + getResourceResponse.put(rid, o); + getResourceResponse.notifyAll(); + } + } + + + /** + * Supposed to call from RemoteInterpreterEventPoller + * @return next available event + */ + public RemoteInterpreterEvent pollEvent() { + synchronized (eventQueue) { + if (eventQueue.isEmpty()) { + try { + eventQueue.wait(1000); + } catch (InterruptedException e) { + } + } + + if (eventQueue.isEmpty()) { + return new RemoteInterpreterEvent(RemoteInterpreterEventType.NO_OP, ""); + } else { + RemoteInterpreterEvent event = eventQueue.remove(0); + logger.debug("Send event {}", event.getType()); + return event; + } + } + } + + + private void sendEvent(RemoteInterpreterEvent event) { + synchronized (eventQueue) { + eventQueue.add(event); + eventQueue.notifyAll(); + } + } + +} diff --git a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterEventPoller.java b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterEventPoller.java index c39e0feb0af..d35678aa3ec 100644 --- a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterEventPoller.java +++ b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterEventPoller.java @@ -26,11 +26,20 @@ import org.apache.zeppelin.interpreter.thrift.RemoteInterpreterEvent; import org.apache.zeppelin.interpreter.thrift.RemoteInterpreterEventType; import org.apache.zeppelin.interpreter.thrift.RemoteInterpreterService.Client; +import org.apache.zeppelin.resource.Resource; +import org.apache.zeppelin.resource.ResourceId; +import org.apache.zeppelin.resource.ResourcePool; +import org.apache.zeppelin.resource.ResourceSet; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.nio.ByteBuffer; +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; + /** - * + * Processes message from RemoteInterpreter process */ public class RemoteInterpreterEventPoller extends Thread { private static final Logger logger = LoggerFactory.getLogger(RemoteInterpreterEventPoller.class); @@ -110,6 +119,17 @@ public void run() { interpreterProcess.getInterpreterContextRunnerPool().run( runnerFromRemote.getNoteId(), runnerFromRemote.getParagraphId()); + } else if (event.getType() == RemoteInterpreterEventType.RESOURCE_POOL_GET_ALL) { + String excludePoolId = event.getData(); + logger.debug("RESOURCE_POOL_GET_ALL {}", excludePoolId); + ResourceSet resourceSet = getAllResourcePoolExcept(excludePoolId); + sendResourcePoolResponseGetAll(resourceSet); + } else if (event.getType() == RemoteInterpreterEventType.RESOURCE_GET) { + String resourceIdString = event.getData(); + ResourceId resourceId = gson.fromJson(resourceIdString, ResourceId.class); + logger.debug("RESOURCE_GET {} {}", resourceId.getResourcePoolId(), resourceId.getName()); + Object o = getResource(resourceId); + sendResourceResponseGet(resourceId, o); } logger.debug("Event from remoteproceess {}", event.getType()); } catch (Exception e) { @@ -118,6 +138,120 @@ public void run() { } } + private void sendResourcePoolResponseGetAll(ResourceSet resourceSet) { + Client client = null; + boolean broken = false; + try { + client = interpreterProcess.getClient(); + List resourceList = new LinkedList(); + Gson gson = new Gson(); + for (Resource r : resourceSet) { + resourceList.add(gson.toJson(r)); + } + client.resourcePoolResponseGetAll(resourceList); + } catch (Exception e) { + logger.error(e.getMessage(), e); + broken = true; + } finally { + if (client != null) { + interpreterProcess.releaseClient(client, broken); + } + } + } + + private ResourceSet getAllResourcePoolExcept(String exclude) { + ResourceSet resourceSet = new ResourceSet(); + for (InterpreterGroup intpGroup : InterpreterGroup.getAll()) { + if (intpGroup.getId().equals(exclude)) { + continue; + } + + RemoteInterpreterProcess remoteInterpreterProcess = intpGroup.getRemoteInterpreterProcess(); + if (remoteInterpreterProcess == null) { + ResourcePool localPool = intpGroup.getResourcePool(); + if (localPool != null) { + resourceSet.addAll(localPool.getAll()); + } + } else if (interpreterProcess.isRunning()) { + Client client = null; + boolean broken = false; + try { + client = remoteInterpreterProcess.getClient(); + List resourceList = client.resoucePoolGetAll(); + Gson gson = new Gson(); + for (String res : resourceList) { + resourceSet.add(gson.fromJson(res, Resource.class)); + } + } catch (Exception e) { + logger.error(e.getMessage(), e); + broken = true; + } finally { + if (client != null) { + intpGroup.getRemoteInterpreterProcess().releaseClient(client, broken); + } + } + } + } + return resourceSet; + } + + + + private void sendResourceResponseGet(ResourceId resourceId, Object o) { + Client client = null; + boolean broken = false; + try { + client = interpreterProcess.getClient(); + Gson gson = new Gson(); + String rid = gson.toJson(resourceId); + ByteBuffer obj; + if (o == null) { + obj = ByteBuffer.allocate(0); + } else { + obj = Resource.serializeObject(o); + } + client.resourceResponseGet(rid, obj); + } catch (Exception e) { + logger.error(e.getMessage(), e); + broken = true; + } finally { + if (client != null) { + interpreterProcess.releaseClient(client, broken); + } + } + } + + private Object getResource(ResourceId resourceId) { + InterpreterGroup intpGroup = InterpreterGroup.get(resourceId.getResourcePoolId()); + if (intpGroup == null) { + return null; + } + RemoteInterpreterProcess remoteInterpreterProcess = intpGroup.getRemoteInterpreterProcess(); + if (remoteInterpreterProcess == null) { + ResourcePool localPool = intpGroup.getResourcePool(); + if (localPool != null) { + return localPool.get(resourceId.getName()); + } + } else if (interpreterProcess.isRunning()) { + Client client = null; + boolean broken = false; + try { + client = remoteInterpreterProcess.getClient(); + ByteBuffer res = client.resourceGet(resourceId.getName()); + Object o = Resource.deserializeObject(res); + return o; + } catch (Exception e) { + logger.error(e.getMessage(), e); + broken = true; + } finally { + if (client != null) { + intpGroup.getRemoteInterpreterProcess().releaseClient(client, broken); + } + } + } + return null; + } + private void waitQuietly() { try { synchronized (this) { diff --git a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterServer.java b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterServer.java index a8da8c02d48..864cdbb0202 100644 --- a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterServer.java +++ b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterServer.java @@ -18,9 +18,11 @@ package org.apache.zeppelin.interpreter.remote; +import java.io.IOException; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.net.URL; +import java.nio.ByteBuffer; import java.util.HashMap; import java.util.LinkedList; import java.util.List; @@ -46,9 +48,9 @@ import org.apache.zeppelin.interpreter.LazyOpenInterpreter; import org.apache.zeppelin.interpreter.thrift.RemoteInterpreterContext; import org.apache.zeppelin.interpreter.thrift.RemoteInterpreterEvent; -import org.apache.zeppelin.interpreter.thrift.RemoteInterpreterEventType; import org.apache.zeppelin.interpreter.thrift.RemoteInterpreterResult; import org.apache.zeppelin.interpreter.thrift.RemoteInterpreterService; +import org.apache.zeppelin.resource.*; import org.apache.zeppelin.scheduler.Job; import org.apache.zeppelin.scheduler.Job.Status; import org.apache.zeppelin.scheduler.JobListener; @@ -71,6 +73,7 @@ public class RemoteInterpreterServer InterpreterGroup interpreterGroup; AngularObjectRegistry angularObjectRegistry; + DistributedResourcePool resourcePool; Gson gson = new Gson(); RemoteInterpreterService.Processor processor; @@ -78,13 +81,10 @@ public class RemoteInterpreterServer private int port; private TThreadPoolServer server; - List eventQueue = new LinkedList(); + RemoteInterpreterEventClient eventClient = new RemoteInterpreterEventClient(); public RemoteInterpreterServer(int port) throws TTransportException { this.port = port; - interpreterGroup = new InterpreterGroup(); - angularObjectRegistry = new AngularObjectRegistry(interpreterGroup.getId(), this); - interpreterGroup.setAngularObjectRegistry(angularObjectRegistry); processor = new RemoteInterpreterService.Processor(this); TServerSocket serverTransport = new TServerSocket(port); @@ -147,8 +147,18 @@ public static void main(String[] args) @Override - public void createInterpreter(String className, Map properties) + public void createInterpreter(String interpreterGroupId, String className, Map + properties) throws TException { + + if (interpreterGroup == null) { + interpreterGroup = new InterpreterGroup(interpreterGroupId); + angularObjectRegistry = new AngularObjectRegistry(interpreterGroup.getId(), this); + resourcePool = new DistributedResourcePool(interpreterGroup.getId(), eventClient); + interpreterGroup.setAngularObjectRegistry(angularObjectRegistry); + interpreterGroup.setResourcePool(resourcePool); + } + try { Class replClass = (Class) Object.class.forName(className); Properties p = new Properties(); @@ -247,6 +257,7 @@ public RemoteInterpreterResult interpret(String className, String st, context.getGui()); } + class InterpretJobListener implements JobListener { @Override @@ -366,6 +377,7 @@ private InterpreterContext convert(RemoteInterpreterContext ric) { new TypeToken>() {}.getType()), gson.fromJson(ric.getGui(), GUI.class), interpreterGroup.getAngularObjectRegistry(), + interpreterGroup.getResourcePool(), contextRunners); } @@ -381,10 +393,7 @@ public ParagraphRunner(RemoteInterpreterServer server, String noteId, String par @Override public void run() { - Gson gson = new Gson(); - server.sendEvent(new RemoteInterpreterEvent( - RemoteInterpreterEventType.RUN_INTERPRETER_CONTEXT_RUNNER, - gson.toJson(this))); + server.eventClient.run(this); } } @@ -423,50 +432,28 @@ public String getStatus(String jobId) @Override public void onAdd(String interpreterGroupId, AngularObject object) { - sendEvent(new RemoteInterpreterEvent( - RemoteInterpreterEventType.ANGULAR_OBJECT_ADD, gson.toJson(object))); + eventClient.angularObjectAdd(object); } @Override public void onUpdate(String interpreterGroupId, AngularObject object) { - sendEvent(new RemoteInterpreterEvent( - RemoteInterpreterEventType.ANGULAR_OBJECT_UPDATE, gson.toJson(object))); + eventClient.angularObjectUpdate(object); } @Override public void onRemove(String interpreterGroupId, String name, String noteId) { - Map removeObject = new HashMap(); - removeObject.put("name", name); - removeObject.put("noteId", noteId); - - sendEvent(new RemoteInterpreterEvent( - RemoteInterpreterEventType.ANGULAR_OBJECT_REMOVE, gson.toJson(removeObject))); + eventClient.angularObjectRemove(name, noteId); } - private void sendEvent(RemoteInterpreterEvent event) { - synchronized (eventQueue) { - eventQueue.add(event); - eventQueue.notifyAll(); - } - } + /** + * Poll event from RemoteInterpreterEventPoller + * @return + * @throws TException + */ @Override public RemoteInterpreterEvent getEvent() throws TException { - synchronized (eventQueue) { - if (eventQueue.isEmpty()) { - try { - eventQueue.wait(1000); - } catch (InterruptedException e) { - logger.info("Exception in RemoteInterpreterServer while getEvent, eventQueue.wait", e); - } - } - - if (eventQueue.isEmpty()) { - return new RemoteInterpreterEvent(RemoteInterpreterEventType.NO_OP, ""); - } else { - return eventQueue.remove(0); - } - } + return eventClient.pollEvent(); } /** @@ -564,4 +551,52 @@ public void angularObjectRemove(String name, String noteId) throws TException { AngularObjectRegistry registry = interpreterGroup.getAngularObjectRegistry(); registry.remove(name, noteId, false); } + + @Override + public void resourcePoolResponseGetAll(List resources) throws TException { + eventClient.putResponseGetAllResources(resources); + } + + /** + * Get payload of resource from remote + * @param resourceId json serialized ResourceId + * @param object java serialized of the object + * @throws TException + */ + @Override + public void resourceResponseGet(String resourceId, ByteBuffer object) throws TException { + eventClient.putResponseGetResource(resourceId, object); + } + + @Override + public List resoucePoolGetAll() throws TException { + logger.debug("Request getAll from ZeppelinServer"); + + ResourceSet resourceSet = resourcePool.getAll(false); + List result = new LinkedList(); + Gson gson = new Gson(); + + for (Resource r : resourceSet) { + result.add(gson.toJson(r)); + } + + return result; + } + + @Override + public ByteBuffer resourceGet(String resourceName) throws TException { + logger.debug("Request resourceGet {} from ZeppelinServer", resourceName); + Resource resource = resourcePool.get(resourceName, false); + + if (resource == null || resource.get() == null || !resource.isSerializable()) { + return ByteBuffer.allocate(0); + } else { + try { + return Resource.serializeObject(resource.get()); + } catch (IOException e) { + logger.error(e.getMessage(), e); + return ByteBuffer.allocate(0); + } + } + } } diff --git a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/thrift/RemoteInterpreterContext.java b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/thrift/RemoteInterpreterContext.java index a55d5de5df9..00cbaca83c2 100644 --- a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/thrift/RemoteInterpreterContext.java +++ b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/thrift/RemoteInterpreterContext.java @@ -51,7 +51,7 @@ import org.slf4j.LoggerFactory; @SuppressWarnings({"cast", "rawtypes", "serial", "unchecked"}) -@Generated(value = "Autogenerated by Thrift Compiler (0.9.2)", date = "2015-8-7") +@Generated(value = "Autogenerated by Thrift Compiler (0.9.2)", date = "2016-1-17") public class RemoteInterpreterContext implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("RemoteInterpreterContext"); diff --git a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/thrift/RemoteInterpreterEvent.java b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/thrift/RemoteInterpreterEvent.java index 96a49b512a4..2309c593e74 100644 --- a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/thrift/RemoteInterpreterEvent.java +++ b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/thrift/RemoteInterpreterEvent.java @@ -51,7 +51,7 @@ import org.slf4j.LoggerFactory; @SuppressWarnings({"cast", "rawtypes", "serial", "unchecked"}) -@Generated(value = "Autogenerated by Thrift Compiler (0.9.2)", date = "2015-8-7") +@Generated(value = "Autogenerated by Thrift Compiler (0.9.2)", date = "2016-1-17") public class RemoteInterpreterEvent implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("RemoteInterpreterEvent"); diff --git a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/thrift/RemoteInterpreterEventType.java b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/thrift/RemoteInterpreterEventType.java index 9a7d142b7bb..3d1eb97d0b4 100644 --- a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/thrift/RemoteInterpreterEventType.java +++ b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/thrift/RemoteInterpreterEventType.java @@ -33,7 +33,9 @@ public enum RemoteInterpreterEventType implements org.apache.thrift.TEnum { ANGULAR_OBJECT_ADD(2), ANGULAR_OBJECT_UPDATE(3), ANGULAR_OBJECT_REMOVE(4), - RUN_INTERPRETER_CONTEXT_RUNNER(5); + RUN_INTERPRETER_CONTEXT_RUNNER(5), + RESOURCE_POOL_GET_ALL(6), + RESOURCE_GET(7); private final int value; @@ -64,6 +66,10 @@ public static RemoteInterpreterEventType findByValue(int value) { return ANGULAR_OBJECT_REMOVE; case 5: return RUN_INTERPRETER_CONTEXT_RUNNER; + case 6: + return RESOURCE_POOL_GET_ALL; + case 7: + return RESOURCE_GET; default: return null; } diff --git a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/thrift/RemoteInterpreterResult.java b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/thrift/RemoteInterpreterResult.java index 36c0f252eb9..3666012a8ab 100644 --- a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/thrift/RemoteInterpreterResult.java +++ b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/thrift/RemoteInterpreterResult.java @@ -51,7 +51,7 @@ import org.slf4j.LoggerFactory; @SuppressWarnings({"cast", "rawtypes", "serial", "unchecked"}) -@Generated(value = "Autogenerated by Thrift Compiler (0.9.2)", date = "2015-8-7") +@Generated(value = "Autogenerated by Thrift Compiler (0.9.2)", date = "2016-1-17") public class RemoteInterpreterResult implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("RemoteInterpreterResult"); diff --git a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/thrift/RemoteInterpreterService.java b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/thrift/RemoteInterpreterService.java index 6e6730ea9be..171252090d9 100644 --- a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/thrift/RemoteInterpreterService.java +++ b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/thrift/RemoteInterpreterService.java @@ -51,12 +51,12 @@ import org.slf4j.LoggerFactory; @SuppressWarnings({"cast", "rawtypes", "serial", "unchecked"}) -@Generated(value = "Autogenerated by Thrift Compiler (0.9.2)", date = "2015-8-7") +@Generated(value = "Autogenerated by Thrift Compiler (0.9.2)", date = "2016-1-17") public class RemoteInterpreterService { public interface Iface { - public void createInterpreter(String className, Map properties) throws org.apache.thrift.TException; + public void createInterpreter(String intpGroupId, String className, Map properties) throws org.apache.thrift.TException; public void open(String className) throws org.apache.thrift.TException; @@ -84,11 +84,19 @@ public interface Iface { public void angularObjectRemove(String name, String noteId) throws org.apache.thrift.TException; + public void resourcePoolResponseGetAll(List resources) throws org.apache.thrift.TException; + + public void resourceResponseGet(String resourceId, ByteBuffer object) throws org.apache.thrift.TException; + + public List resoucePoolGetAll() throws org.apache.thrift.TException; + + public ByteBuffer resourceGet(String resourceName) throws org.apache.thrift.TException; + } public interface AsyncIface { - public void createInterpreter(String className, Map properties, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException; + public void createInterpreter(String intpGroupId, String className, Map properties, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException; public void open(String className, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException; @@ -116,6 +124,14 @@ public interface AsyncIface { public void angularObjectRemove(String name, String noteId, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException; + public void resourcePoolResponseGetAll(List resources, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException; + + public void resourceResponseGet(String resourceId, ByteBuffer object, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException; + + public void resoucePoolGetAll(org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException; + + public void resourceGet(String resourceName, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException; + } public static class Client extends org.apache.thrift.TServiceClient implements Iface { @@ -138,15 +154,16 @@ public Client(org.apache.thrift.protocol.TProtocol iprot, org.apache.thrift.prot super(iprot, oprot); } - public void createInterpreter(String className, Map properties) throws org.apache.thrift.TException + public void createInterpreter(String intpGroupId, String className, Map properties) throws org.apache.thrift.TException { - send_createInterpreter(className, properties); + send_createInterpreter(intpGroupId, className, properties); recv_createInterpreter(); } - public void send_createInterpreter(String className, Map properties) throws org.apache.thrift.TException + public void send_createInterpreter(String intpGroupId, String className, Map properties) throws org.apache.thrift.TException { createInterpreter_args args = new createInterpreter_args(); + args.setIntpGroupId(intpGroupId); args.setClassName(className); args.setProperties(properties); sendBase("createInterpreter", args); @@ -446,6 +463,92 @@ public void recv_angularObjectRemove() throws org.apache.thrift.TException return; } + public void resourcePoolResponseGetAll(List resources) throws org.apache.thrift.TException + { + send_resourcePoolResponseGetAll(resources); + recv_resourcePoolResponseGetAll(); + } + + public void send_resourcePoolResponseGetAll(List resources) throws org.apache.thrift.TException + { + resourcePoolResponseGetAll_args args = new resourcePoolResponseGetAll_args(); + args.setResources(resources); + sendBase("resourcePoolResponseGetAll", args); + } + + public void recv_resourcePoolResponseGetAll() throws org.apache.thrift.TException + { + resourcePoolResponseGetAll_result result = new resourcePoolResponseGetAll_result(); + receiveBase(result, "resourcePoolResponseGetAll"); + return; + } + + public void resourceResponseGet(String resourceId, ByteBuffer object) throws org.apache.thrift.TException + { + send_resourceResponseGet(resourceId, object); + recv_resourceResponseGet(); + } + + public void send_resourceResponseGet(String resourceId, ByteBuffer object) throws org.apache.thrift.TException + { + resourceResponseGet_args args = new resourceResponseGet_args(); + args.setResourceId(resourceId); + args.setObject(object); + sendBase("resourceResponseGet", args); + } + + public void recv_resourceResponseGet() throws org.apache.thrift.TException + { + resourceResponseGet_result result = new resourceResponseGet_result(); + receiveBase(result, "resourceResponseGet"); + return; + } + + public List resoucePoolGetAll() throws org.apache.thrift.TException + { + send_resoucePoolGetAll(); + return recv_resoucePoolGetAll(); + } + + public void send_resoucePoolGetAll() throws org.apache.thrift.TException + { + resoucePoolGetAll_args args = new resoucePoolGetAll_args(); + sendBase("resoucePoolGetAll", args); + } + + public List recv_resoucePoolGetAll() throws org.apache.thrift.TException + { + resoucePoolGetAll_result result = new resoucePoolGetAll_result(); + receiveBase(result, "resoucePoolGetAll"); + if (result.isSetSuccess()) { + return result.success; + } + throw new org.apache.thrift.TApplicationException(org.apache.thrift.TApplicationException.MISSING_RESULT, "resoucePoolGetAll failed: unknown result"); + } + + public ByteBuffer resourceGet(String resourceName) throws org.apache.thrift.TException + { + send_resourceGet(resourceName); + return recv_resourceGet(); + } + + public void send_resourceGet(String resourceName) throws org.apache.thrift.TException + { + resourceGet_args args = new resourceGet_args(); + args.setResourceName(resourceName); + sendBase("resourceGet", args); + } + + public ByteBuffer recv_resourceGet() throws org.apache.thrift.TException + { + resourceGet_result result = new resourceGet_result(); + receiveBase(result, "resourceGet"); + if (result.isSetSuccess()) { + return result.success; + } + throw new org.apache.thrift.TApplicationException(org.apache.thrift.TApplicationException.MISSING_RESULT, "resourceGet failed: unknown result"); + } + } public static class AsyncClient extends org.apache.thrift.async.TAsyncClient implements AsyncIface { public static class Factory implements org.apache.thrift.async.TAsyncClientFactory { @@ -464,18 +567,20 @@ public AsyncClient(org.apache.thrift.protocol.TProtocolFactory protocolFactory, super(protocolFactory, clientManager, transport); } - public void createInterpreter(String className, Map properties, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException { + public void createInterpreter(String intpGroupId, String className, Map properties, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException { checkReady(); - createInterpreter_call method_call = new createInterpreter_call(className, properties, resultHandler, this, ___protocolFactory, ___transport); + createInterpreter_call method_call = new createInterpreter_call(intpGroupId, className, properties, resultHandler, this, ___protocolFactory, ___transport); this.___currentMethod = method_call; ___manager.call(method_call); } public static class createInterpreter_call extends org.apache.thrift.async.TAsyncMethodCall { + private String intpGroupId; private String className; private Map properties; - public createInterpreter_call(String className, Map properties, org.apache.thrift.async.AsyncMethodCallback resultHandler, org.apache.thrift.async.TAsyncClient client, org.apache.thrift.protocol.TProtocolFactory protocolFactory, org.apache.thrift.transport.TNonblockingTransport transport) throws org.apache.thrift.TException { + public createInterpreter_call(String intpGroupId, String className, Map properties, org.apache.thrift.async.AsyncMethodCallback resultHandler, org.apache.thrift.async.TAsyncClient client, org.apache.thrift.protocol.TProtocolFactory protocolFactory, org.apache.thrift.transport.TNonblockingTransport transport) throws org.apache.thrift.TException { super(client, protocolFactory, transport, resultHandler, false); + this.intpGroupId = intpGroupId; this.className = className; this.properties = properties; } @@ -483,6 +588,7 @@ public createInterpreter_call(String className, Map properties, o public void write_args(org.apache.thrift.protocol.TProtocol prot) throws org.apache.thrift.TException { prot.writeMessageBegin(new org.apache.thrift.protocol.TMessage("createInterpreter", org.apache.thrift.protocol.TMessageType.CALL, 0)); createInterpreter_args args = new createInterpreter_args(); + args.setIntpGroupId(intpGroupId); args.setClassName(className); args.setProperties(properties); args.write(prot); @@ -942,6 +1048,134 @@ public void getResult() throws org.apache.thrift.TException { } } + public void resourcePoolResponseGetAll(List resources, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException { + checkReady(); + resourcePoolResponseGetAll_call method_call = new resourcePoolResponseGetAll_call(resources, resultHandler, this, ___protocolFactory, ___transport); + this.___currentMethod = method_call; + ___manager.call(method_call); + } + + public static class resourcePoolResponseGetAll_call extends org.apache.thrift.async.TAsyncMethodCall { + private List resources; + public resourcePoolResponseGetAll_call(List resources, org.apache.thrift.async.AsyncMethodCallback resultHandler, org.apache.thrift.async.TAsyncClient client, org.apache.thrift.protocol.TProtocolFactory protocolFactory, org.apache.thrift.transport.TNonblockingTransport transport) throws org.apache.thrift.TException { + super(client, protocolFactory, transport, resultHandler, false); + this.resources = resources; + } + + public void write_args(org.apache.thrift.protocol.TProtocol prot) throws org.apache.thrift.TException { + prot.writeMessageBegin(new org.apache.thrift.protocol.TMessage("resourcePoolResponseGetAll", org.apache.thrift.protocol.TMessageType.CALL, 0)); + resourcePoolResponseGetAll_args args = new resourcePoolResponseGetAll_args(); + args.setResources(resources); + args.write(prot); + prot.writeMessageEnd(); + } + + public void getResult() throws org.apache.thrift.TException { + if (getState() != org.apache.thrift.async.TAsyncMethodCall.State.RESPONSE_READ) { + throw new IllegalStateException("Method call not finished!"); + } + org.apache.thrift.transport.TMemoryInputTransport memoryTransport = new org.apache.thrift.transport.TMemoryInputTransport(getFrameBuffer().array()); + org.apache.thrift.protocol.TProtocol prot = client.getProtocolFactory().getProtocol(memoryTransport); + (new Client(prot)).recv_resourcePoolResponseGetAll(); + } + } + + public void resourceResponseGet(String resourceId, ByteBuffer object, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException { + checkReady(); + resourceResponseGet_call method_call = new resourceResponseGet_call(resourceId, object, resultHandler, this, ___protocolFactory, ___transport); + this.___currentMethod = method_call; + ___manager.call(method_call); + } + + public static class resourceResponseGet_call extends org.apache.thrift.async.TAsyncMethodCall { + private String resourceId; + private ByteBuffer object; + public resourceResponseGet_call(String resourceId, ByteBuffer object, org.apache.thrift.async.AsyncMethodCallback resultHandler, org.apache.thrift.async.TAsyncClient client, org.apache.thrift.protocol.TProtocolFactory protocolFactory, org.apache.thrift.transport.TNonblockingTransport transport) throws org.apache.thrift.TException { + super(client, protocolFactory, transport, resultHandler, false); + this.resourceId = resourceId; + this.object = object; + } + + public void write_args(org.apache.thrift.protocol.TProtocol prot) throws org.apache.thrift.TException { + prot.writeMessageBegin(new org.apache.thrift.protocol.TMessage("resourceResponseGet", org.apache.thrift.protocol.TMessageType.CALL, 0)); + resourceResponseGet_args args = new resourceResponseGet_args(); + args.setResourceId(resourceId); + args.setObject(object); + args.write(prot); + prot.writeMessageEnd(); + } + + public void getResult() throws org.apache.thrift.TException { + if (getState() != org.apache.thrift.async.TAsyncMethodCall.State.RESPONSE_READ) { + throw new IllegalStateException("Method call not finished!"); + } + org.apache.thrift.transport.TMemoryInputTransport memoryTransport = new org.apache.thrift.transport.TMemoryInputTransport(getFrameBuffer().array()); + org.apache.thrift.protocol.TProtocol prot = client.getProtocolFactory().getProtocol(memoryTransport); + (new Client(prot)).recv_resourceResponseGet(); + } + } + + public void resoucePoolGetAll(org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException { + checkReady(); + resoucePoolGetAll_call method_call = new resoucePoolGetAll_call(resultHandler, this, ___protocolFactory, ___transport); + this.___currentMethod = method_call; + ___manager.call(method_call); + } + + public static class resoucePoolGetAll_call extends org.apache.thrift.async.TAsyncMethodCall { + public resoucePoolGetAll_call(org.apache.thrift.async.AsyncMethodCallback resultHandler, org.apache.thrift.async.TAsyncClient client, org.apache.thrift.protocol.TProtocolFactory protocolFactory, org.apache.thrift.transport.TNonblockingTransport transport) throws org.apache.thrift.TException { + super(client, protocolFactory, transport, resultHandler, false); + } + + public void write_args(org.apache.thrift.protocol.TProtocol prot) throws org.apache.thrift.TException { + prot.writeMessageBegin(new org.apache.thrift.protocol.TMessage("resoucePoolGetAll", org.apache.thrift.protocol.TMessageType.CALL, 0)); + resoucePoolGetAll_args args = new resoucePoolGetAll_args(); + args.write(prot); + prot.writeMessageEnd(); + } + + public List getResult() throws org.apache.thrift.TException { + if (getState() != org.apache.thrift.async.TAsyncMethodCall.State.RESPONSE_READ) { + throw new IllegalStateException("Method call not finished!"); + } + org.apache.thrift.transport.TMemoryInputTransport memoryTransport = new org.apache.thrift.transport.TMemoryInputTransport(getFrameBuffer().array()); + org.apache.thrift.protocol.TProtocol prot = client.getProtocolFactory().getProtocol(memoryTransport); + return (new Client(prot)).recv_resoucePoolGetAll(); + } + } + + public void resourceGet(String resourceName, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException { + checkReady(); + resourceGet_call method_call = new resourceGet_call(resourceName, resultHandler, this, ___protocolFactory, ___transport); + this.___currentMethod = method_call; + ___manager.call(method_call); + } + + public static class resourceGet_call extends org.apache.thrift.async.TAsyncMethodCall { + private String resourceName; + public resourceGet_call(String resourceName, org.apache.thrift.async.AsyncMethodCallback resultHandler, org.apache.thrift.async.TAsyncClient client, org.apache.thrift.protocol.TProtocolFactory protocolFactory, org.apache.thrift.transport.TNonblockingTransport transport) throws org.apache.thrift.TException { + super(client, protocolFactory, transport, resultHandler, false); + this.resourceName = resourceName; + } + + public void write_args(org.apache.thrift.protocol.TProtocol prot) throws org.apache.thrift.TException { + prot.writeMessageBegin(new org.apache.thrift.protocol.TMessage("resourceGet", org.apache.thrift.protocol.TMessageType.CALL, 0)); + resourceGet_args args = new resourceGet_args(); + args.setResourceName(resourceName); + args.write(prot); + prot.writeMessageEnd(); + } + + public ByteBuffer getResult() throws org.apache.thrift.TException { + if (getState() != org.apache.thrift.async.TAsyncMethodCall.State.RESPONSE_READ) { + throw new IllegalStateException("Method call not finished!"); + } + org.apache.thrift.transport.TMemoryInputTransport memoryTransport = new org.apache.thrift.transport.TMemoryInputTransport(getFrameBuffer().array()); + org.apache.thrift.protocol.TProtocol prot = client.getProtocolFactory().getProtocol(memoryTransport); + return (new Client(prot)).recv_resourceGet(); + } + } + } public static class Processor extends org.apache.thrift.TBaseProcessor implements org.apache.thrift.TProcessor { @@ -969,6 +1203,10 @@ protected Processor(I iface, Map extends org.apache.thrift.ProcessFunction { + public resourcePoolResponseGetAll() { + super("resourcePoolResponseGetAll"); + } + + public resourcePoolResponseGetAll_args getEmptyArgsInstance() { + return new resourcePoolResponseGetAll_args(); + } + + protected boolean isOneway() { + return false; + } + + public resourcePoolResponseGetAll_result getResult(I iface, resourcePoolResponseGetAll_args args) throws org.apache.thrift.TException { + resourcePoolResponseGetAll_result result = new resourcePoolResponseGetAll_result(); + iface.resourcePoolResponseGetAll(args.resources); + return result; + } + } + + public static class resourceResponseGet extends org.apache.thrift.ProcessFunction { + public resourceResponseGet() { + super("resourceResponseGet"); + } + + public resourceResponseGet_args getEmptyArgsInstance() { + return new resourceResponseGet_args(); + } + + protected boolean isOneway() { + return false; + } + + public resourceResponseGet_result getResult(I iface, resourceResponseGet_args args) throws org.apache.thrift.TException { + resourceResponseGet_result result = new resourceResponseGet_result(); + iface.resourceResponseGet(args.resourceId, args.object); + return result; + } + } + + public static class resoucePoolGetAll extends org.apache.thrift.ProcessFunction { + public resoucePoolGetAll() { + super("resoucePoolGetAll"); + } + + public resoucePoolGetAll_args getEmptyArgsInstance() { + return new resoucePoolGetAll_args(); + } + + protected boolean isOneway() { + return false; + } + + public resoucePoolGetAll_result getResult(I iface, resoucePoolGetAll_args args) throws org.apache.thrift.TException { + resoucePoolGetAll_result result = new resoucePoolGetAll_result(); + result.success = iface.resoucePoolGetAll(); + return result; + } + } + + public static class resourceGet extends org.apache.thrift.ProcessFunction { + public resourceGet() { + super("resourceGet"); + } + + public resourceGet_args getEmptyArgsInstance() { + return new resourceGet_args(); + } + + protected boolean isOneway() { + return false; + } + + public resourceGet_result getResult(I iface, resourceGet_args args) throws org.apache.thrift.TException { + resourceGet_result result = new resourceGet_result(); + result.success = iface.resourceGet(args.resourceName); + return result; + } + } + } public static class AsyncProcessor extends org.apache.thrift.TBaseAsyncProcessor { @@ -1280,6 +1598,10 @@ protected AsyncProcessor(I iface, Map resultHandler) throws TException { - iface.createInterpreter(args.className, args.properties,resultHandler); + iface.createInterpreter(args.intpGroupId, args.className, args.properties,resultHandler); } } @@ -1990,46 +2312,253 @@ public void start(I iface, angularObjectRemove_args args, org.apache.thrift.asyn } } - } - - public static class createInterpreter_args implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { - private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("createInterpreter_args"); + public static class resourcePoolResponseGetAll extends org.apache.thrift.AsyncProcessFunction { + public resourcePoolResponseGetAll() { + super("resourcePoolResponseGetAll"); + } - private static final org.apache.thrift.protocol.TField CLASS_NAME_FIELD_DESC = new org.apache.thrift.protocol.TField("className", org.apache.thrift.protocol.TType.STRING, (short)1); - private static final org.apache.thrift.protocol.TField PROPERTIES_FIELD_DESC = new org.apache.thrift.protocol.TField("properties", org.apache.thrift.protocol.TType.MAP, (short)2); + public resourcePoolResponseGetAll_args getEmptyArgsInstance() { + return new resourcePoolResponseGetAll_args(); + } - private static final Map, SchemeFactory> schemes = new HashMap, SchemeFactory>(); - static { - schemes.put(StandardScheme.class, new createInterpreter_argsStandardSchemeFactory()); - schemes.put(TupleScheme.class, new createInterpreter_argsTupleSchemeFactory()); - } + public AsyncMethodCallback getResultHandler(final AsyncFrameBuffer fb, final int seqid) { + final org.apache.thrift.AsyncProcessFunction fcall = this; + return new AsyncMethodCallback() { + public void onComplete(Void o) { + resourcePoolResponseGetAll_result result = new resourcePoolResponseGetAll_result(); + try { + fcall.sendResponse(fb,result, org.apache.thrift.protocol.TMessageType.REPLY,seqid); + return; + } catch (Exception e) { + LOGGER.error("Exception writing to internal frame buffer", e); + } + fb.close(); + } + public void onError(Exception e) { + byte msgType = org.apache.thrift.protocol.TMessageType.REPLY; + org.apache.thrift.TBase msg; + resourcePoolResponseGetAll_result result = new resourcePoolResponseGetAll_result(); + { + msgType = org.apache.thrift.protocol.TMessageType.EXCEPTION; + msg = (org.apache.thrift.TBase)new org.apache.thrift.TApplicationException(org.apache.thrift.TApplicationException.INTERNAL_ERROR, e.getMessage()); + } + try { + fcall.sendResponse(fb,msg,msgType,seqid); + return; + } catch (Exception ex) { + LOGGER.error("Exception writing to internal frame buffer", ex); + } + fb.close(); + } + }; + } - public String className; // required - public Map properties; // required + protected boolean isOneway() { + return false; + } - /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ - public enum _Fields implements org.apache.thrift.TFieldIdEnum { - CLASS_NAME((short)1, "className"), - PROPERTIES((short)2, "properties"); + public void start(I iface, resourcePoolResponseGetAll_args args, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws TException { + iface.resourcePoolResponseGetAll(args.resources,resultHandler); + } + } - private static final Map byName = new HashMap(); + public static class resourceResponseGet extends org.apache.thrift.AsyncProcessFunction { + public resourceResponseGet() { + super("resourceResponseGet"); + } - static { - for (_Fields field : EnumSet.allOf(_Fields.class)) { - byName.put(field.getFieldName(), field); - } + public resourceResponseGet_args getEmptyArgsInstance() { + return new resourceResponseGet_args(); } - /** - * Find the _Fields constant that matches fieldId, or null if its not found. - */ - public static _Fields findByThriftId(int fieldId) { - switch(fieldId) { - case 1: // CLASS_NAME - return CLASS_NAME; - case 2: // PROPERTIES - return PROPERTIES; - default: + public AsyncMethodCallback getResultHandler(final AsyncFrameBuffer fb, final int seqid) { + final org.apache.thrift.AsyncProcessFunction fcall = this; + return new AsyncMethodCallback() { + public void onComplete(Void o) { + resourceResponseGet_result result = new resourceResponseGet_result(); + try { + fcall.sendResponse(fb,result, org.apache.thrift.protocol.TMessageType.REPLY,seqid); + return; + } catch (Exception e) { + LOGGER.error("Exception writing to internal frame buffer", e); + } + fb.close(); + } + public void onError(Exception e) { + byte msgType = org.apache.thrift.protocol.TMessageType.REPLY; + org.apache.thrift.TBase msg; + resourceResponseGet_result result = new resourceResponseGet_result(); + { + msgType = org.apache.thrift.protocol.TMessageType.EXCEPTION; + msg = (org.apache.thrift.TBase)new org.apache.thrift.TApplicationException(org.apache.thrift.TApplicationException.INTERNAL_ERROR, e.getMessage()); + } + try { + fcall.sendResponse(fb,msg,msgType,seqid); + return; + } catch (Exception ex) { + LOGGER.error("Exception writing to internal frame buffer", ex); + } + fb.close(); + } + }; + } + + protected boolean isOneway() { + return false; + } + + public void start(I iface, resourceResponseGet_args args, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws TException { + iface.resourceResponseGet(args.resourceId, args.object,resultHandler); + } + } + + public static class resoucePoolGetAll extends org.apache.thrift.AsyncProcessFunction> { + public resoucePoolGetAll() { + super("resoucePoolGetAll"); + } + + public resoucePoolGetAll_args getEmptyArgsInstance() { + return new resoucePoolGetAll_args(); + } + + public AsyncMethodCallback> getResultHandler(final AsyncFrameBuffer fb, final int seqid) { + final org.apache.thrift.AsyncProcessFunction fcall = this; + return new AsyncMethodCallback>() { + public void onComplete(List o) { + resoucePoolGetAll_result result = new resoucePoolGetAll_result(); + result.success = o; + try { + fcall.sendResponse(fb,result, org.apache.thrift.protocol.TMessageType.REPLY,seqid); + return; + } catch (Exception e) { + LOGGER.error("Exception writing to internal frame buffer", e); + } + fb.close(); + } + public void onError(Exception e) { + byte msgType = org.apache.thrift.protocol.TMessageType.REPLY; + org.apache.thrift.TBase msg; + resoucePoolGetAll_result result = new resoucePoolGetAll_result(); + { + msgType = org.apache.thrift.protocol.TMessageType.EXCEPTION; + msg = (org.apache.thrift.TBase)new org.apache.thrift.TApplicationException(org.apache.thrift.TApplicationException.INTERNAL_ERROR, e.getMessage()); + } + try { + fcall.sendResponse(fb,msg,msgType,seqid); + return; + } catch (Exception ex) { + LOGGER.error("Exception writing to internal frame buffer", ex); + } + fb.close(); + } + }; + } + + protected boolean isOneway() { + return false; + } + + public void start(I iface, resoucePoolGetAll_args args, org.apache.thrift.async.AsyncMethodCallback> resultHandler) throws TException { + iface.resoucePoolGetAll(resultHandler); + } + } + + public static class resourceGet extends org.apache.thrift.AsyncProcessFunction { + public resourceGet() { + super("resourceGet"); + } + + public resourceGet_args getEmptyArgsInstance() { + return new resourceGet_args(); + } + + public AsyncMethodCallback getResultHandler(final AsyncFrameBuffer fb, final int seqid) { + final org.apache.thrift.AsyncProcessFunction fcall = this; + return new AsyncMethodCallback() { + public void onComplete(ByteBuffer o) { + resourceGet_result result = new resourceGet_result(); + result.success = o; + try { + fcall.sendResponse(fb,result, org.apache.thrift.protocol.TMessageType.REPLY,seqid); + return; + } catch (Exception e) { + LOGGER.error("Exception writing to internal frame buffer", e); + } + fb.close(); + } + public void onError(Exception e) { + byte msgType = org.apache.thrift.protocol.TMessageType.REPLY; + org.apache.thrift.TBase msg; + resourceGet_result result = new resourceGet_result(); + { + msgType = org.apache.thrift.protocol.TMessageType.EXCEPTION; + msg = (org.apache.thrift.TBase)new org.apache.thrift.TApplicationException(org.apache.thrift.TApplicationException.INTERNAL_ERROR, e.getMessage()); + } + try { + fcall.sendResponse(fb,msg,msgType,seqid); + return; + } catch (Exception ex) { + LOGGER.error("Exception writing to internal frame buffer", ex); + } + fb.close(); + } + }; + } + + protected boolean isOneway() { + return false; + } + + public void start(I iface, resourceGet_args args, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws TException { + iface.resourceGet(args.resourceName,resultHandler); + } + } + + } + + public static class createInterpreter_args implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { + private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("createInterpreter_args"); + + private static final org.apache.thrift.protocol.TField INTP_GROUP_ID_FIELD_DESC = new org.apache.thrift.protocol.TField("intpGroupId", org.apache.thrift.protocol.TType.STRING, (short)1); + private static final org.apache.thrift.protocol.TField CLASS_NAME_FIELD_DESC = new org.apache.thrift.protocol.TField("className", org.apache.thrift.protocol.TType.STRING, (short)2); + private static final org.apache.thrift.protocol.TField PROPERTIES_FIELD_DESC = new org.apache.thrift.protocol.TField("properties", org.apache.thrift.protocol.TType.MAP, (short)3); + + private static final Map, SchemeFactory> schemes = new HashMap, SchemeFactory>(); + static { + schemes.put(StandardScheme.class, new createInterpreter_argsStandardSchemeFactory()); + schemes.put(TupleScheme.class, new createInterpreter_argsTupleSchemeFactory()); + } + + public String intpGroupId; // required + public String className; // required + public Map properties; // required + + /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ + public enum _Fields implements org.apache.thrift.TFieldIdEnum { + INTP_GROUP_ID((short)1, "intpGroupId"), + CLASS_NAME((short)2, "className"), + PROPERTIES((short)3, "properties"); + + private static final Map byName = new HashMap(); + + static { + for (_Fields field : EnumSet.allOf(_Fields.class)) { + byName.put(field.getFieldName(), field); + } + } + + /** + * Find the _Fields constant that matches fieldId, or null if its not found. + */ + public static _Fields findByThriftId(int fieldId) { + switch(fieldId) { + case 1: // INTP_GROUP_ID + return INTP_GROUP_ID; + case 2: // CLASS_NAME + return CLASS_NAME; + case 3: // PROPERTIES + return PROPERTIES; + default: return null; } } @@ -2072,6 +2601,8 @@ public String getFieldName() { public static final Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap; static { Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class); + tmpMap.put(_Fields.INTP_GROUP_ID, new org.apache.thrift.meta_data.FieldMetaData("intpGroupId", org.apache.thrift.TFieldRequirementType.DEFAULT, + new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING))); tmpMap.put(_Fields.CLASS_NAME, new org.apache.thrift.meta_data.FieldMetaData("className", org.apache.thrift.TFieldRequirementType.DEFAULT, new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING))); tmpMap.put(_Fields.PROPERTIES, new org.apache.thrift.meta_data.FieldMetaData("properties", org.apache.thrift.TFieldRequirementType.DEFAULT, @@ -2086,10 +2617,12 @@ public createInterpreter_args() { } public createInterpreter_args( + String intpGroupId, String className, Map properties) { this(); + this.intpGroupId = intpGroupId; this.className = className; this.properties = properties; } @@ -2098,6 +2631,9 @@ public createInterpreter_args( * Performs a deep copy on other. */ public createInterpreter_args(createInterpreter_args other) { + if (other.isSetIntpGroupId()) { + this.intpGroupId = other.intpGroupId; + } if (other.isSetClassName()) { this.className = other.className; } @@ -2113,10 +2649,35 @@ public createInterpreter_args deepCopy() { @Override public void clear() { + this.intpGroupId = null; this.className = null; this.properties = null; } + public String getIntpGroupId() { + return this.intpGroupId; + } + + public createInterpreter_args setIntpGroupId(String intpGroupId) { + this.intpGroupId = intpGroupId; + return this; + } + + public void unsetIntpGroupId() { + this.intpGroupId = null; + } + + /** Returns true if field intpGroupId is set (has been assigned a value) and false otherwise */ + public boolean isSetIntpGroupId() { + return this.intpGroupId != null; + } + + public void setIntpGroupIdIsSet(boolean value) { + if (!value) { + this.intpGroupId = null; + } + } + public String getClassName() { return this.className; } @@ -2178,6 +2739,14 @@ public void setPropertiesIsSet(boolean value) { public void setFieldValue(_Fields field, Object value) { switch (field) { + case INTP_GROUP_ID: + if (value == null) { + unsetIntpGroupId(); + } else { + setIntpGroupId((String)value); + } + break; + case CLASS_NAME: if (value == null) { unsetClassName(); @@ -2199,6 +2768,9 @@ public void setFieldValue(_Fields field, Object value) { public Object getFieldValue(_Fields field) { switch (field) { + case INTP_GROUP_ID: + return getIntpGroupId(); + case CLASS_NAME: return getClassName(); @@ -2216,6 +2788,8 @@ public boolean isSet(_Fields field) { } switch (field) { + case INTP_GROUP_ID: + return isSetIntpGroupId(); case CLASS_NAME: return isSetClassName(); case PROPERTIES: @@ -2237,6 +2811,15 @@ public boolean equals(createInterpreter_args that) { if (that == null) return false; + boolean this_present_intpGroupId = true && this.isSetIntpGroupId(); + boolean that_present_intpGroupId = true && that.isSetIntpGroupId(); + if (this_present_intpGroupId || that_present_intpGroupId) { + if (!(this_present_intpGroupId && that_present_intpGroupId)) + return false; + if (!this.intpGroupId.equals(that.intpGroupId)) + return false; + } + boolean this_present_className = true && this.isSetClassName(); boolean that_present_className = true && that.isSetClassName(); if (this_present_className || that_present_className) { @@ -2262,6 +2845,11 @@ public boolean equals(createInterpreter_args that) { public int hashCode() { List list = new ArrayList(); + boolean present_intpGroupId = true && (isSetIntpGroupId()); + list.add(present_intpGroupId); + if (present_intpGroupId) + list.add(intpGroupId); + boolean present_className = true && (isSetClassName()); list.add(present_className); if (present_className) @@ -2283,6 +2871,16 @@ public int compareTo(createInterpreter_args other) { int lastComparison = 0; + lastComparison = Boolean.valueOf(isSetIntpGroupId()).compareTo(other.isSetIntpGroupId()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetIntpGroupId()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.intpGroupId, other.intpGroupId); + if (lastComparison != 0) { + return lastComparison; + } + } lastComparison = Boolean.valueOf(isSetClassName()).compareTo(other.isSetClassName()); if (lastComparison != 0) { return lastComparison; @@ -2323,6 +2921,14 @@ public String toString() { StringBuilder sb = new StringBuilder("createInterpreter_args("); boolean first = true; + sb.append("intpGroupId:"); + if (this.intpGroupId == null) { + sb.append("null"); + } else { + sb.append(this.intpGroupId); + } + first = false; + if (!first) sb.append(", "); sb.append("className:"); if (this.className == null) { sb.append("null"); @@ -2381,7 +2987,15 @@ public void read(org.apache.thrift.protocol.TProtocol iprot, createInterpreter_a break; } switch (schemeField.id) { - case 1: // CLASS_NAME + case 1: // INTP_GROUP_ID + if (schemeField.type == org.apache.thrift.protocol.TType.STRING) { + struct.intpGroupId = iprot.readString(); + struct.setIntpGroupIdIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + case 2: // CLASS_NAME if (schemeField.type == org.apache.thrift.protocol.TType.STRING) { struct.className = iprot.readString(); struct.setClassNameIsSet(true); @@ -2389,7 +3003,7 @@ public void read(org.apache.thrift.protocol.TProtocol iprot, createInterpreter_a org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); } break; - case 2: // PROPERTIES + case 3: // PROPERTIES if (schemeField.type == org.apache.thrift.protocol.TType.MAP) { { org.apache.thrift.protocol.TMap _map0 = iprot.readMapBegin(); @@ -2424,6 +3038,11 @@ public void write(org.apache.thrift.protocol.TProtocol oprot, createInterpreter_ struct.validate(); oprot.writeStructBegin(STRUCT_DESC); + if (struct.intpGroupId != null) { + oprot.writeFieldBegin(INTP_GROUP_ID_FIELD_DESC); + oprot.writeString(struct.intpGroupId); + oprot.writeFieldEnd(); + } if (struct.className != null) { oprot.writeFieldBegin(CLASS_NAME_FIELD_DESC); oprot.writeString(struct.className); @@ -2460,13 +3079,19 @@ private static class createInterpreter_argsTupleScheme extends TupleScheme(2*_map6.size); @@ -12354,4 +12983,2776 @@ public void read(org.apache.thrift.protocol.TProtocol prot, angularObjectRemove_ } + public static class resourcePoolResponseGetAll_args implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { + private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("resourcePoolResponseGetAll_args"); + + private static final org.apache.thrift.protocol.TField RESOURCES_FIELD_DESC = new org.apache.thrift.protocol.TField("resources", org.apache.thrift.protocol.TType.LIST, (short)1); + + private static final Map, SchemeFactory> schemes = new HashMap, SchemeFactory>(); + static { + schemes.put(StandardScheme.class, new resourcePoolResponseGetAll_argsStandardSchemeFactory()); + schemes.put(TupleScheme.class, new resourcePoolResponseGetAll_argsTupleSchemeFactory()); + } + + public List resources; // required + + /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ + public enum _Fields implements org.apache.thrift.TFieldIdEnum { + RESOURCES((short)1, "resources"); + + private static final Map byName = new HashMap(); + + static { + for (_Fields field : EnumSet.allOf(_Fields.class)) { + byName.put(field.getFieldName(), field); + } + } + + /** + * Find the _Fields constant that matches fieldId, or null if its not found. + */ + public static _Fields findByThriftId(int fieldId) { + switch(fieldId) { + case 1: // RESOURCES + return RESOURCES; + default: + return null; + } + } + + /** + * Find the _Fields constant that matches fieldId, throwing an exception + * if it is not found. + */ + public static _Fields findByThriftIdOrThrow(int fieldId) { + _Fields fields = findByThriftId(fieldId); + if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!"); + return fields; + } + + /** + * Find the _Fields constant that matches name, or null if its not found. + */ + public static _Fields findByName(String name) { + return byName.get(name); + } + + private final short _thriftId; + private final String _fieldName; + + _Fields(short thriftId, String fieldName) { + _thriftId = thriftId; + _fieldName = fieldName; + } + + public short getThriftFieldId() { + return _thriftId; + } + + public String getFieldName() { + return _fieldName; + } + } + + // isset id assignments + public static final Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap; + static { + Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class); + tmpMap.put(_Fields.RESOURCES, new org.apache.thrift.meta_data.FieldMetaData("resources", org.apache.thrift.TFieldRequirementType.DEFAULT, + new org.apache.thrift.meta_data.ListMetaData(org.apache.thrift.protocol.TType.LIST, + new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING)))); + metaDataMap = Collections.unmodifiableMap(tmpMap); + org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(resourcePoolResponseGetAll_args.class, metaDataMap); + } + + public resourcePoolResponseGetAll_args() { + } + + public resourcePoolResponseGetAll_args( + List resources) + { + this(); + this.resources = resources; + } + + /** + * Performs a deep copy on other. + */ + public resourcePoolResponseGetAll_args(resourcePoolResponseGetAll_args other) { + if (other.isSetResources()) { + List __this__resources = new ArrayList(other.resources); + this.resources = __this__resources; + } + } + + public resourcePoolResponseGetAll_args deepCopy() { + return new resourcePoolResponseGetAll_args(this); + } + + @Override + public void clear() { + this.resources = null; + } + + public int getResourcesSize() { + return (this.resources == null) ? 0 : this.resources.size(); + } + + public java.util.Iterator getResourcesIterator() { + return (this.resources == null) ? null : this.resources.iterator(); + } + + public void addToResources(String elem) { + if (this.resources == null) { + this.resources = new ArrayList(); + } + this.resources.add(elem); + } + + public List getResources() { + return this.resources; + } + + public resourcePoolResponseGetAll_args setResources(List resources) { + this.resources = resources; + return this; + } + + public void unsetResources() { + this.resources = null; + } + + /** Returns true if field resources is set (has been assigned a value) and false otherwise */ + public boolean isSetResources() { + return this.resources != null; + } + + public void setResourcesIsSet(boolean value) { + if (!value) { + this.resources = null; + } + } + + public void setFieldValue(_Fields field, Object value) { + switch (field) { + case RESOURCES: + if (value == null) { + unsetResources(); + } else { + setResources((List)value); + } + break; + + } + } + + public Object getFieldValue(_Fields field) { + switch (field) { + case RESOURCES: + return getResources(); + + } + throw new IllegalStateException(); + } + + /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */ + public boolean isSet(_Fields field) { + if (field == null) { + throw new IllegalArgumentException(); + } + + switch (field) { + case RESOURCES: + return isSetResources(); + } + throw new IllegalStateException(); + } + + @Override + public boolean equals(Object that) { + if (that == null) + return false; + if (that instanceof resourcePoolResponseGetAll_args) + return this.equals((resourcePoolResponseGetAll_args)that); + return false; + } + + public boolean equals(resourcePoolResponseGetAll_args that) { + if (that == null) + return false; + + boolean this_present_resources = true && this.isSetResources(); + boolean that_present_resources = true && that.isSetResources(); + if (this_present_resources || that_present_resources) { + if (!(this_present_resources && that_present_resources)) + return false; + if (!this.resources.equals(that.resources)) + return false; + } + + return true; + } + + @Override + public int hashCode() { + List list = new ArrayList(); + + boolean present_resources = true && (isSetResources()); + list.add(present_resources); + if (present_resources) + list.add(resources); + + return list.hashCode(); + } + + @Override + public int compareTo(resourcePoolResponseGetAll_args other) { + if (!getClass().equals(other.getClass())) { + return getClass().getName().compareTo(other.getClass().getName()); + } + + int lastComparison = 0; + + lastComparison = Boolean.valueOf(isSetResources()).compareTo(other.isSetResources()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetResources()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.resources, other.resources); + if (lastComparison != 0) { + return lastComparison; + } + } + return 0; + } + + public _Fields fieldForId(int fieldId) { + return _Fields.findByThriftId(fieldId); + } + + public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { + schemes.get(iprot.getScheme()).getScheme().read(iprot, this); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { + schemes.get(oprot.getScheme()).getScheme().write(oprot, this); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("resourcePoolResponseGetAll_args("); + boolean first = true; + + sb.append("resources:"); + if (this.resources == null) { + sb.append("null"); + } else { + sb.append(this.resources); + } + first = false; + sb.append(")"); + return sb.toString(); + } + + public void validate() throws org.apache.thrift.TException { + // check for required fields + // check for sub-struct validity + } + + private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { + try { + write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException { + try { + read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private static class resourcePoolResponseGetAll_argsStandardSchemeFactory implements SchemeFactory { + public resourcePoolResponseGetAll_argsStandardScheme getScheme() { + return new resourcePoolResponseGetAll_argsStandardScheme(); + } + } + + private static class resourcePoolResponseGetAll_argsStandardScheme extends StandardScheme { + + public void read(org.apache.thrift.protocol.TProtocol iprot, resourcePoolResponseGetAll_args struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TField schemeField; + iprot.readStructBegin(); + while (true) + { + schemeField = iprot.readFieldBegin(); + if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { + break; + } + switch (schemeField.id) { + case 1: // RESOURCES + if (schemeField.type == org.apache.thrift.protocol.TType.LIST) { + { + org.apache.thrift.protocol.TList _list18 = iprot.readListBegin(); + struct.resources = new ArrayList(_list18.size); + String _elem19; + for (int _i20 = 0; _i20 < _list18.size; ++_i20) + { + _elem19 = iprot.readString(); + struct.resources.add(_elem19); + } + iprot.readListEnd(); + } + struct.setResourcesIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + default: + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + iprot.readFieldEnd(); + } + iprot.readStructEnd(); + + // check for required fields of primitive type, which can't be checked in the validate method + struct.validate(); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot, resourcePoolResponseGetAll_args struct) throws org.apache.thrift.TException { + struct.validate(); + + oprot.writeStructBegin(STRUCT_DESC); + if (struct.resources != null) { + oprot.writeFieldBegin(RESOURCES_FIELD_DESC); + { + oprot.writeListBegin(new org.apache.thrift.protocol.TList(org.apache.thrift.protocol.TType.STRING, struct.resources.size())); + for (String _iter21 : struct.resources) + { + oprot.writeString(_iter21); + } + oprot.writeListEnd(); + } + oprot.writeFieldEnd(); + } + oprot.writeFieldStop(); + oprot.writeStructEnd(); + } + + } + + private static class resourcePoolResponseGetAll_argsTupleSchemeFactory implements SchemeFactory { + public resourcePoolResponseGetAll_argsTupleScheme getScheme() { + return new resourcePoolResponseGetAll_argsTupleScheme(); + } + } + + private static class resourcePoolResponseGetAll_argsTupleScheme extends TupleScheme { + + @Override + public void write(org.apache.thrift.protocol.TProtocol prot, resourcePoolResponseGetAll_args struct) throws org.apache.thrift.TException { + TTupleProtocol oprot = (TTupleProtocol) prot; + BitSet optionals = new BitSet(); + if (struct.isSetResources()) { + optionals.set(0); + } + oprot.writeBitSet(optionals, 1); + if (struct.isSetResources()) { + { + oprot.writeI32(struct.resources.size()); + for (String _iter22 : struct.resources) + { + oprot.writeString(_iter22); + } + } + } + } + + @Override + public void read(org.apache.thrift.protocol.TProtocol prot, resourcePoolResponseGetAll_args struct) throws org.apache.thrift.TException { + TTupleProtocol iprot = (TTupleProtocol) prot; + BitSet incoming = iprot.readBitSet(1); + if (incoming.get(0)) { + { + org.apache.thrift.protocol.TList _list23 = new org.apache.thrift.protocol.TList(org.apache.thrift.protocol.TType.STRING, iprot.readI32()); + struct.resources = new ArrayList(_list23.size); + String _elem24; + for (int _i25 = 0; _i25 < _list23.size; ++_i25) + { + _elem24 = iprot.readString(); + struct.resources.add(_elem24); + } + } + struct.setResourcesIsSet(true); + } + } + } + + } + + public static class resourcePoolResponseGetAll_result implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { + private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("resourcePoolResponseGetAll_result"); + + + private static final Map, SchemeFactory> schemes = new HashMap, SchemeFactory>(); + static { + schemes.put(StandardScheme.class, new resourcePoolResponseGetAll_resultStandardSchemeFactory()); + schemes.put(TupleScheme.class, new resourcePoolResponseGetAll_resultTupleSchemeFactory()); + } + + + /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ + public enum _Fields implements org.apache.thrift.TFieldIdEnum { +; + + private static final Map byName = new HashMap(); + + static { + for (_Fields field : EnumSet.allOf(_Fields.class)) { + byName.put(field.getFieldName(), field); + } + } + + /** + * Find the _Fields constant that matches fieldId, or null if its not found. + */ + public static _Fields findByThriftId(int fieldId) { + switch(fieldId) { + default: + return null; + } + } + + /** + * Find the _Fields constant that matches fieldId, throwing an exception + * if it is not found. + */ + public static _Fields findByThriftIdOrThrow(int fieldId) { + _Fields fields = findByThriftId(fieldId); + if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!"); + return fields; + } + + /** + * Find the _Fields constant that matches name, or null if its not found. + */ + public static _Fields findByName(String name) { + return byName.get(name); + } + + private final short _thriftId; + private final String _fieldName; + + _Fields(short thriftId, String fieldName) { + _thriftId = thriftId; + _fieldName = fieldName; + } + + public short getThriftFieldId() { + return _thriftId; + } + + public String getFieldName() { + return _fieldName; + } + } + public static final Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap; + static { + Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class); + metaDataMap = Collections.unmodifiableMap(tmpMap); + org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(resourcePoolResponseGetAll_result.class, metaDataMap); + } + + public resourcePoolResponseGetAll_result() { + } + + /** + * Performs a deep copy on other. + */ + public resourcePoolResponseGetAll_result(resourcePoolResponseGetAll_result other) { + } + + public resourcePoolResponseGetAll_result deepCopy() { + return new resourcePoolResponseGetAll_result(this); + } + + @Override + public void clear() { + } + + public void setFieldValue(_Fields field, Object value) { + switch (field) { + } + } + + public Object getFieldValue(_Fields field) { + switch (field) { + } + throw new IllegalStateException(); + } + + /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */ + public boolean isSet(_Fields field) { + if (field == null) { + throw new IllegalArgumentException(); + } + + switch (field) { + } + throw new IllegalStateException(); + } + + @Override + public boolean equals(Object that) { + if (that == null) + return false; + if (that instanceof resourcePoolResponseGetAll_result) + return this.equals((resourcePoolResponseGetAll_result)that); + return false; + } + + public boolean equals(resourcePoolResponseGetAll_result that) { + if (that == null) + return false; + + return true; + } + + @Override + public int hashCode() { + List list = new ArrayList(); + + return list.hashCode(); + } + + @Override + public int compareTo(resourcePoolResponseGetAll_result other) { + if (!getClass().equals(other.getClass())) { + return getClass().getName().compareTo(other.getClass().getName()); + } + + int lastComparison = 0; + + return 0; + } + + public _Fields fieldForId(int fieldId) { + return _Fields.findByThriftId(fieldId); + } + + public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { + schemes.get(iprot.getScheme()).getScheme().read(iprot, this); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { + schemes.get(oprot.getScheme()).getScheme().write(oprot, this); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("resourcePoolResponseGetAll_result("); + boolean first = true; + + sb.append(")"); + return sb.toString(); + } + + public void validate() throws org.apache.thrift.TException { + // check for required fields + // check for sub-struct validity + } + + private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { + try { + write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException { + try { + read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private static class resourcePoolResponseGetAll_resultStandardSchemeFactory implements SchemeFactory { + public resourcePoolResponseGetAll_resultStandardScheme getScheme() { + return new resourcePoolResponseGetAll_resultStandardScheme(); + } + } + + private static class resourcePoolResponseGetAll_resultStandardScheme extends StandardScheme { + + public void read(org.apache.thrift.protocol.TProtocol iprot, resourcePoolResponseGetAll_result struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TField schemeField; + iprot.readStructBegin(); + while (true) + { + schemeField = iprot.readFieldBegin(); + if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { + break; + } + switch (schemeField.id) { + default: + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + iprot.readFieldEnd(); + } + iprot.readStructEnd(); + + // check for required fields of primitive type, which can't be checked in the validate method + struct.validate(); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot, resourcePoolResponseGetAll_result struct) throws org.apache.thrift.TException { + struct.validate(); + + oprot.writeStructBegin(STRUCT_DESC); + oprot.writeFieldStop(); + oprot.writeStructEnd(); + } + + } + + private static class resourcePoolResponseGetAll_resultTupleSchemeFactory implements SchemeFactory { + public resourcePoolResponseGetAll_resultTupleScheme getScheme() { + return new resourcePoolResponseGetAll_resultTupleScheme(); + } + } + + private static class resourcePoolResponseGetAll_resultTupleScheme extends TupleScheme { + + @Override + public void write(org.apache.thrift.protocol.TProtocol prot, resourcePoolResponseGetAll_result struct) throws org.apache.thrift.TException { + TTupleProtocol oprot = (TTupleProtocol) prot; + } + + @Override + public void read(org.apache.thrift.protocol.TProtocol prot, resourcePoolResponseGetAll_result struct) throws org.apache.thrift.TException { + TTupleProtocol iprot = (TTupleProtocol) prot; + } + } + + } + + public static class resourceResponseGet_args implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { + private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("resourceResponseGet_args"); + + private static final org.apache.thrift.protocol.TField RESOURCE_ID_FIELD_DESC = new org.apache.thrift.protocol.TField("resourceId", org.apache.thrift.protocol.TType.STRING, (short)1); + private static final org.apache.thrift.protocol.TField OBJECT_FIELD_DESC = new org.apache.thrift.protocol.TField("object", org.apache.thrift.protocol.TType.STRING, (short)2); + + private static final Map, SchemeFactory> schemes = new HashMap, SchemeFactory>(); + static { + schemes.put(StandardScheme.class, new resourceResponseGet_argsStandardSchemeFactory()); + schemes.put(TupleScheme.class, new resourceResponseGet_argsTupleSchemeFactory()); + } + + public String resourceId; // required + public ByteBuffer object; // required + + /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ + public enum _Fields implements org.apache.thrift.TFieldIdEnum { + RESOURCE_ID((short)1, "resourceId"), + OBJECT((short)2, "object"); + + private static final Map byName = new HashMap(); + + static { + for (_Fields field : EnumSet.allOf(_Fields.class)) { + byName.put(field.getFieldName(), field); + } + } + + /** + * Find the _Fields constant that matches fieldId, or null if its not found. + */ + public static _Fields findByThriftId(int fieldId) { + switch(fieldId) { + case 1: // RESOURCE_ID + return RESOURCE_ID; + case 2: // OBJECT + return OBJECT; + default: + return null; + } + } + + /** + * Find the _Fields constant that matches fieldId, throwing an exception + * if it is not found. + */ + public static _Fields findByThriftIdOrThrow(int fieldId) { + _Fields fields = findByThriftId(fieldId); + if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!"); + return fields; + } + + /** + * Find the _Fields constant that matches name, or null if its not found. + */ + public static _Fields findByName(String name) { + return byName.get(name); + } + + private final short _thriftId; + private final String _fieldName; + + _Fields(short thriftId, String fieldName) { + _thriftId = thriftId; + _fieldName = fieldName; + } + + public short getThriftFieldId() { + return _thriftId; + } + + public String getFieldName() { + return _fieldName; + } + } + + // isset id assignments + public static final Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap; + static { + Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class); + tmpMap.put(_Fields.RESOURCE_ID, new org.apache.thrift.meta_data.FieldMetaData("resourceId", org.apache.thrift.TFieldRequirementType.DEFAULT, + new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING))); + tmpMap.put(_Fields.OBJECT, new org.apache.thrift.meta_data.FieldMetaData("object", org.apache.thrift.TFieldRequirementType.DEFAULT, + new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING , true))); + metaDataMap = Collections.unmodifiableMap(tmpMap); + org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(resourceResponseGet_args.class, metaDataMap); + } + + public resourceResponseGet_args() { + } + + public resourceResponseGet_args( + String resourceId, + ByteBuffer object) + { + this(); + this.resourceId = resourceId; + this.object = org.apache.thrift.TBaseHelper.copyBinary(object); + } + + /** + * Performs a deep copy on other. + */ + public resourceResponseGet_args(resourceResponseGet_args other) { + if (other.isSetResourceId()) { + this.resourceId = other.resourceId; + } + if (other.isSetObject()) { + this.object = org.apache.thrift.TBaseHelper.copyBinary(other.object); + } + } + + public resourceResponseGet_args deepCopy() { + return new resourceResponseGet_args(this); + } + + @Override + public void clear() { + this.resourceId = null; + this.object = null; + } + + public String getResourceId() { + return this.resourceId; + } + + public resourceResponseGet_args setResourceId(String resourceId) { + this.resourceId = resourceId; + return this; + } + + public void unsetResourceId() { + this.resourceId = null; + } + + /** Returns true if field resourceId is set (has been assigned a value) and false otherwise */ + public boolean isSetResourceId() { + return this.resourceId != null; + } + + public void setResourceIdIsSet(boolean value) { + if (!value) { + this.resourceId = null; + } + } + + public byte[] getObject() { + setObject(org.apache.thrift.TBaseHelper.rightSize(object)); + return object == null ? null : object.array(); + } + + public ByteBuffer bufferForObject() { + return org.apache.thrift.TBaseHelper.copyBinary(object); + } + + public resourceResponseGet_args setObject(byte[] object) { + this.object = object == null ? (ByteBuffer)null : ByteBuffer.wrap(Arrays.copyOf(object, object.length)); + return this; + } + + public resourceResponseGet_args setObject(ByteBuffer object) { + this.object = org.apache.thrift.TBaseHelper.copyBinary(object); + return this; + } + + public void unsetObject() { + this.object = null; + } + + /** Returns true if field object is set (has been assigned a value) and false otherwise */ + public boolean isSetObject() { + return this.object != null; + } + + public void setObjectIsSet(boolean value) { + if (!value) { + this.object = null; + } + } + + public void setFieldValue(_Fields field, Object value) { + switch (field) { + case RESOURCE_ID: + if (value == null) { + unsetResourceId(); + } else { + setResourceId((String)value); + } + break; + + case OBJECT: + if (value == null) { + unsetObject(); + } else { + setObject((ByteBuffer)value); + } + break; + + } + } + + public Object getFieldValue(_Fields field) { + switch (field) { + case RESOURCE_ID: + return getResourceId(); + + case OBJECT: + return getObject(); + + } + throw new IllegalStateException(); + } + + /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */ + public boolean isSet(_Fields field) { + if (field == null) { + throw new IllegalArgumentException(); + } + + switch (field) { + case RESOURCE_ID: + return isSetResourceId(); + case OBJECT: + return isSetObject(); + } + throw new IllegalStateException(); + } + + @Override + public boolean equals(Object that) { + if (that == null) + return false; + if (that instanceof resourceResponseGet_args) + return this.equals((resourceResponseGet_args)that); + return false; + } + + public boolean equals(resourceResponseGet_args that) { + if (that == null) + return false; + + boolean this_present_resourceId = true && this.isSetResourceId(); + boolean that_present_resourceId = true && that.isSetResourceId(); + if (this_present_resourceId || that_present_resourceId) { + if (!(this_present_resourceId && that_present_resourceId)) + return false; + if (!this.resourceId.equals(that.resourceId)) + return false; + } + + boolean this_present_object = true && this.isSetObject(); + boolean that_present_object = true && that.isSetObject(); + if (this_present_object || that_present_object) { + if (!(this_present_object && that_present_object)) + return false; + if (!this.object.equals(that.object)) + return false; + } + + return true; + } + + @Override + public int hashCode() { + List list = new ArrayList(); + + boolean present_resourceId = true && (isSetResourceId()); + list.add(present_resourceId); + if (present_resourceId) + list.add(resourceId); + + boolean present_object = true && (isSetObject()); + list.add(present_object); + if (present_object) + list.add(object); + + return list.hashCode(); + } + + @Override + public int compareTo(resourceResponseGet_args other) { + if (!getClass().equals(other.getClass())) { + return getClass().getName().compareTo(other.getClass().getName()); + } + + int lastComparison = 0; + + lastComparison = Boolean.valueOf(isSetResourceId()).compareTo(other.isSetResourceId()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetResourceId()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.resourceId, other.resourceId); + if (lastComparison != 0) { + return lastComparison; + } + } + lastComparison = Boolean.valueOf(isSetObject()).compareTo(other.isSetObject()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetObject()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.object, other.object); + if (lastComparison != 0) { + return lastComparison; + } + } + return 0; + } + + public _Fields fieldForId(int fieldId) { + return _Fields.findByThriftId(fieldId); + } + + public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { + schemes.get(iprot.getScheme()).getScheme().read(iprot, this); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { + schemes.get(oprot.getScheme()).getScheme().write(oprot, this); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("resourceResponseGet_args("); + boolean first = true; + + sb.append("resourceId:"); + if (this.resourceId == null) { + sb.append("null"); + } else { + sb.append(this.resourceId); + } + first = false; + if (!first) sb.append(", "); + sb.append("object:"); + if (this.object == null) { + sb.append("null"); + } else { + org.apache.thrift.TBaseHelper.toString(this.object, sb); + } + first = false; + sb.append(")"); + return sb.toString(); + } + + public void validate() throws org.apache.thrift.TException { + // check for required fields + // check for sub-struct validity + } + + private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { + try { + write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException { + try { + read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private static class resourceResponseGet_argsStandardSchemeFactory implements SchemeFactory { + public resourceResponseGet_argsStandardScheme getScheme() { + return new resourceResponseGet_argsStandardScheme(); + } + } + + private static class resourceResponseGet_argsStandardScheme extends StandardScheme { + + public void read(org.apache.thrift.protocol.TProtocol iprot, resourceResponseGet_args struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TField schemeField; + iprot.readStructBegin(); + while (true) + { + schemeField = iprot.readFieldBegin(); + if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { + break; + } + switch (schemeField.id) { + case 1: // RESOURCE_ID + if (schemeField.type == org.apache.thrift.protocol.TType.STRING) { + struct.resourceId = iprot.readString(); + struct.setResourceIdIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + case 2: // OBJECT + if (schemeField.type == org.apache.thrift.protocol.TType.STRING) { + struct.object = iprot.readBinary(); + struct.setObjectIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + default: + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + iprot.readFieldEnd(); + } + iprot.readStructEnd(); + + // check for required fields of primitive type, which can't be checked in the validate method + struct.validate(); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot, resourceResponseGet_args struct) throws org.apache.thrift.TException { + struct.validate(); + + oprot.writeStructBegin(STRUCT_DESC); + if (struct.resourceId != null) { + oprot.writeFieldBegin(RESOURCE_ID_FIELD_DESC); + oprot.writeString(struct.resourceId); + oprot.writeFieldEnd(); + } + if (struct.object != null) { + oprot.writeFieldBegin(OBJECT_FIELD_DESC); + oprot.writeBinary(struct.object); + oprot.writeFieldEnd(); + } + oprot.writeFieldStop(); + oprot.writeStructEnd(); + } + + } + + private static class resourceResponseGet_argsTupleSchemeFactory implements SchemeFactory { + public resourceResponseGet_argsTupleScheme getScheme() { + return new resourceResponseGet_argsTupleScheme(); + } + } + + private static class resourceResponseGet_argsTupleScheme extends TupleScheme { + + @Override + public void write(org.apache.thrift.protocol.TProtocol prot, resourceResponseGet_args struct) throws org.apache.thrift.TException { + TTupleProtocol oprot = (TTupleProtocol) prot; + BitSet optionals = new BitSet(); + if (struct.isSetResourceId()) { + optionals.set(0); + } + if (struct.isSetObject()) { + optionals.set(1); + } + oprot.writeBitSet(optionals, 2); + if (struct.isSetResourceId()) { + oprot.writeString(struct.resourceId); + } + if (struct.isSetObject()) { + oprot.writeBinary(struct.object); + } + } + + @Override + public void read(org.apache.thrift.protocol.TProtocol prot, resourceResponseGet_args struct) throws org.apache.thrift.TException { + TTupleProtocol iprot = (TTupleProtocol) prot; + BitSet incoming = iprot.readBitSet(2); + if (incoming.get(0)) { + struct.resourceId = iprot.readString(); + struct.setResourceIdIsSet(true); + } + if (incoming.get(1)) { + struct.object = iprot.readBinary(); + struct.setObjectIsSet(true); + } + } + } + + } + + public static class resourceResponseGet_result implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { + private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("resourceResponseGet_result"); + + + private static final Map, SchemeFactory> schemes = new HashMap, SchemeFactory>(); + static { + schemes.put(StandardScheme.class, new resourceResponseGet_resultStandardSchemeFactory()); + schemes.put(TupleScheme.class, new resourceResponseGet_resultTupleSchemeFactory()); + } + + + /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ + public enum _Fields implements org.apache.thrift.TFieldIdEnum { +; + + private static final Map byName = new HashMap(); + + static { + for (_Fields field : EnumSet.allOf(_Fields.class)) { + byName.put(field.getFieldName(), field); + } + } + + /** + * Find the _Fields constant that matches fieldId, or null if its not found. + */ + public static _Fields findByThriftId(int fieldId) { + switch(fieldId) { + default: + return null; + } + } + + /** + * Find the _Fields constant that matches fieldId, throwing an exception + * if it is not found. + */ + public static _Fields findByThriftIdOrThrow(int fieldId) { + _Fields fields = findByThriftId(fieldId); + if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!"); + return fields; + } + + /** + * Find the _Fields constant that matches name, or null if its not found. + */ + public static _Fields findByName(String name) { + return byName.get(name); + } + + private final short _thriftId; + private final String _fieldName; + + _Fields(short thriftId, String fieldName) { + _thriftId = thriftId; + _fieldName = fieldName; + } + + public short getThriftFieldId() { + return _thriftId; + } + + public String getFieldName() { + return _fieldName; + } + } + public static final Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap; + static { + Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class); + metaDataMap = Collections.unmodifiableMap(tmpMap); + org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(resourceResponseGet_result.class, metaDataMap); + } + + public resourceResponseGet_result() { + } + + /** + * Performs a deep copy on other. + */ + public resourceResponseGet_result(resourceResponseGet_result other) { + } + + public resourceResponseGet_result deepCopy() { + return new resourceResponseGet_result(this); + } + + @Override + public void clear() { + } + + public void setFieldValue(_Fields field, Object value) { + switch (field) { + } + } + + public Object getFieldValue(_Fields field) { + switch (field) { + } + throw new IllegalStateException(); + } + + /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */ + public boolean isSet(_Fields field) { + if (field == null) { + throw new IllegalArgumentException(); + } + + switch (field) { + } + throw new IllegalStateException(); + } + + @Override + public boolean equals(Object that) { + if (that == null) + return false; + if (that instanceof resourceResponseGet_result) + return this.equals((resourceResponseGet_result)that); + return false; + } + + public boolean equals(resourceResponseGet_result that) { + if (that == null) + return false; + + return true; + } + + @Override + public int hashCode() { + List list = new ArrayList(); + + return list.hashCode(); + } + + @Override + public int compareTo(resourceResponseGet_result other) { + if (!getClass().equals(other.getClass())) { + return getClass().getName().compareTo(other.getClass().getName()); + } + + int lastComparison = 0; + + return 0; + } + + public _Fields fieldForId(int fieldId) { + return _Fields.findByThriftId(fieldId); + } + + public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { + schemes.get(iprot.getScheme()).getScheme().read(iprot, this); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { + schemes.get(oprot.getScheme()).getScheme().write(oprot, this); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("resourceResponseGet_result("); + boolean first = true; + + sb.append(")"); + return sb.toString(); + } + + public void validate() throws org.apache.thrift.TException { + // check for required fields + // check for sub-struct validity + } + + private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { + try { + write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException { + try { + read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private static class resourceResponseGet_resultStandardSchemeFactory implements SchemeFactory { + public resourceResponseGet_resultStandardScheme getScheme() { + return new resourceResponseGet_resultStandardScheme(); + } + } + + private static class resourceResponseGet_resultStandardScheme extends StandardScheme { + + public void read(org.apache.thrift.protocol.TProtocol iprot, resourceResponseGet_result struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TField schemeField; + iprot.readStructBegin(); + while (true) + { + schemeField = iprot.readFieldBegin(); + if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { + break; + } + switch (schemeField.id) { + default: + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + iprot.readFieldEnd(); + } + iprot.readStructEnd(); + + // check for required fields of primitive type, which can't be checked in the validate method + struct.validate(); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot, resourceResponseGet_result struct) throws org.apache.thrift.TException { + struct.validate(); + + oprot.writeStructBegin(STRUCT_DESC); + oprot.writeFieldStop(); + oprot.writeStructEnd(); + } + + } + + private static class resourceResponseGet_resultTupleSchemeFactory implements SchemeFactory { + public resourceResponseGet_resultTupleScheme getScheme() { + return new resourceResponseGet_resultTupleScheme(); + } + } + + private static class resourceResponseGet_resultTupleScheme extends TupleScheme { + + @Override + public void write(org.apache.thrift.protocol.TProtocol prot, resourceResponseGet_result struct) throws org.apache.thrift.TException { + TTupleProtocol oprot = (TTupleProtocol) prot; + } + + @Override + public void read(org.apache.thrift.protocol.TProtocol prot, resourceResponseGet_result struct) throws org.apache.thrift.TException { + TTupleProtocol iprot = (TTupleProtocol) prot; + } + } + + } + + public static class resoucePoolGetAll_args implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { + private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("resoucePoolGetAll_args"); + + + private static final Map, SchemeFactory> schemes = new HashMap, SchemeFactory>(); + static { + schemes.put(StandardScheme.class, new resoucePoolGetAll_argsStandardSchemeFactory()); + schemes.put(TupleScheme.class, new resoucePoolGetAll_argsTupleSchemeFactory()); + } + + + /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ + public enum _Fields implements org.apache.thrift.TFieldIdEnum { +; + + private static final Map byName = new HashMap(); + + static { + for (_Fields field : EnumSet.allOf(_Fields.class)) { + byName.put(field.getFieldName(), field); + } + } + + /** + * Find the _Fields constant that matches fieldId, or null if its not found. + */ + public static _Fields findByThriftId(int fieldId) { + switch(fieldId) { + default: + return null; + } + } + + /** + * Find the _Fields constant that matches fieldId, throwing an exception + * if it is not found. + */ + public static _Fields findByThriftIdOrThrow(int fieldId) { + _Fields fields = findByThriftId(fieldId); + if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!"); + return fields; + } + + /** + * Find the _Fields constant that matches name, or null if its not found. + */ + public static _Fields findByName(String name) { + return byName.get(name); + } + + private final short _thriftId; + private final String _fieldName; + + _Fields(short thriftId, String fieldName) { + _thriftId = thriftId; + _fieldName = fieldName; + } + + public short getThriftFieldId() { + return _thriftId; + } + + public String getFieldName() { + return _fieldName; + } + } + public static final Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap; + static { + Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class); + metaDataMap = Collections.unmodifiableMap(tmpMap); + org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(resoucePoolGetAll_args.class, metaDataMap); + } + + public resoucePoolGetAll_args() { + } + + /** + * Performs a deep copy on other. + */ + public resoucePoolGetAll_args(resoucePoolGetAll_args other) { + } + + public resoucePoolGetAll_args deepCopy() { + return new resoucePoolGetAll_args(this); + } + + @Override + public void clear() { + } + + public void setFieldValue(_Fields field, Object value) { + switch (field) { + } + } + + public Object getFieldValue(_Fields field) { + switch (field) { + } + throw new IllegalStateException(); + } + + /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */ + public boolean isSet(_Fields field) { + if (field == null) { + throw new IllegalArgumentException(); + } + + switch (field) { + } + throw new IllegalStateException(); + } + + @Override + public boolean equals(Object that) { + if (that == null) + return false; + if (that instanceof resoucePoolGetAll_args) + return this.equals((resoucePoolGetAll_args)that); + return false; + } + + public boolean equals(resoucePoolGetAll_args that) { + if (that == null) + return false; + + return true; + } + + @Override + public int hashCode() { + List list = new ArrayList(); + + return list.hashCode(); + } + + @Override + public int compareTo(resoucePoolGetAll_args other) { + if (!getClass().equals(other.getClass())) { + return getClass().getName().compareTo(other.getClass().getName()); + } + + int lastComparison = 0; + + return 0; + } + + public _Fields fieldForId(int fieldId) { + return _Fields.findByThriftId(fieldId); + } + + public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { + schemes.get(iprot.getScheme()).getScheme().read(iprot, this); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { + schemes.get(oprot.getScheme()).getScheme().write(oprot, this); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("resoucePoolGetAll_args("); + boolean first = true; + + sb.append(")"); + return sb.toString(); + } + + public void validate() throws org.apache.thrift.TException { + // check for required fields + // check for sub-struct validity + } + + private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { + try { + write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException { + try { + read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private static class resoucePoolGetAll_argsStandardSchemeFactory implements SchemeFactory { + public resoucePoolGetAll_argsStandardScheme getScheme() { + return new resoucePoolGetAll_argsStandardScheme(); + } + } + + private static class resoucePoolGetAll_argsStandardScheme extends StandardScheme { + + public void read(org.apache.thrift.protocol.TProtocol iprot, resoucePoolGetAll_args struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TField schemeField; + iprot.readStructBegin(); + while (true) + { + schemeField = iprot.readFieldBegin(); + if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { + break; + } + switch (schemeField.id) { + default: + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + iprot.readFieldEnd(); + } + iprot.readStructEnd(); + + // check for required fields of primitive type, which can't be checked in the validate method + struct.validate(); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot, resoucePoolGetAll_args struct) throws org.apache.thrift.TException { + struct.validate(); + + oprot.writeStructBegin(STRUCT_DESC); + oprot.writeFieldStop(); + oprot.writeStructEnd(); + } + + } + + private static class resoucePoolGetAll_argsTupleSchemeFactory implements SchemeFactory { + public resoucePoolGetAll_argsTupleScheme getScheme() { + return new resoucePoolGetAll_argsTupleScheme(); + } + } + + private static class resoucePoolGetAll_argsTupleScheme extends TupleScheme { + + @Override + public void write(org.apache.thrift.protocol.TProtocol prot, resoucePoolGetAll_args struct) throws org.apache.thrift.TException { + TTupleProtocol oprot = (TTupleProtocol) prot; + } + + @Override + public void read(org.apache.thrift.protocol.TProtocol prot, resoucePoolGetAll_args struct) throws org.apache.thrift.TException { + TTupleProtocol iprot = (TTupleProtocol) prot; + } + } + + } + + public static class resoucePoolGetAll_result implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { + private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("resoucePoolGetAll_result"); + + private static final org.apache.thrift.protocol.TField SUCCESS_FIELD_DESC = new org.apache.thrift.protocol.TField("success", org.apache.thrift.protocol.TType.LIST, (short)0); + + private static final Map, SchemeFactory> schemes = new HashMap, SchemeFactory>(); + static { + schemes.put(StandardScheme.class, new resoucePoolGetAll_resultStandardSchemeFactory()); + schemes.put(TupleScheme.class, new resoucePoolGetAll_resultTupleSchemeFactory()); + } + + public List success; // required + + /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ + public enum _Fields implements org.apache.thrift.TFieldIdEnum { + SUCCESS((short)0, "success"); + + private static final Map byName = new HashMap(); + + static { + for (_Fields field : EnumSet.allOf(_Fields.class)) { + byName.put(field.getFieldName(), field); + } + } + + /** + * Find the _Fields constant that matches fieldId, or null if its not found. + */ + public static _Fields findByThriftId(int fieldId) { + switch(fieldId) { + case 0: // SUCCESS + return SUCCESS; + default: + return null; + } + } + + /** + * Find the _Fields constant that matches fieldId, throwing an exception + * if it is not found. + */ + public static _Fields findByThriftIdOrThrow(int fieldId) { + _Fields fields = findByThriftId(fieldId); + if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!"); + return fields; + } + + /** + * Find the _Fields constant that matches name, or null if its not found. + */ + public static _Fields findByName(String name) { + return byName.get(name); + } + + private final short _thriftId; + private final String _fieldName; + + _Fields(short thriftId, String fieldName) { + _thriftId = thriftId; + _fieldName = fieldName; + } + + public short getThriftFieldId() { + return _thriftId; + } + + public String getFieldName() { + return _fieldName; + } + } + + // isset id assignments + public static final Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap; + static { + Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class); + tmpMap.put(_Fields.SUCCESS, new org.apache.thrift.meta_data.FieldMetaData("success", org.apache.thrift.TFieldRequirementType.DEFAULT, + new org.apache.thrift.meta_data.ListMetaData(org.apache.thrift.protocol.TType.LIST, + new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING)))); + metaDataMap = Collections.unmodifiableMap(tmpMap); + org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(resoucePoolGetAll_result.class, metaDataMap); + } + + public resoucePoolGetAll_result() { + } + + public resoucePoolGetAll_result( + List success) + { + this(); + this.success = success; + } + + /** + * Performs a deep copy on other. + */ + public resoucePoolGetAll_result(resoucePoolGetAll_result other) { + if (other.isSetSuccess()) { + List __this__success = new ArrayList(other.success); + this.success = __this__success; + } + } + + public resoucePoolGetAll_result deepCopy() { + return new resoucePoolGetAll_result(this); + } + + @Override + public void clear() { + this.success = null; + } + + public int getSuccessSize() { + return (this.success == null) ? 0 : this.success.size(); + } + + public java.util.Iterator getSuccessIterator() { + return (this.success == null) ? null : this.success.iterator(); + } + + public void addToSuccess(String elem) { + if (this.success == null) { + this.success = new ArrayList(); + } + this.success.add(elem); + } + + public List getSuccess() { + return this.success; + } + + public resoucePoolGetAll_result setSuccess(List success) { + this.success = success; + return this; + } + + public void unsetSuccess() { + this.success = null; + } + + /** Returns true if field success is set (has been assigned a value) and false otherwise */ + public boolean isSetSuccess() { + return this.success != null; + } + + public void setSuccessIsSet(boolean value) { + if (!value) { + this.success = null; + } + } + + public void setFieldValue(_Fields field, Object value) { + switch (field) { + case SUCCESS: + if (value == null) { + unsetSuccess(); + } else { + setSuccess((List)value); + } + break; + + } + } + + public Object getFieldValue(_Fields field) { + switch (field) { + case SUCCESS: + return getSuccess(); + + } + throw new IllegalStateException(); + } + + /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */ + public boolean isSet(_Fields field) { + if (field == null) { + throw new IllegalArgumentException(); + } + + switch (field) { + case SUCCESS: + return isSetSuccess(); + } + throw new IllegalStateException(); + } + + @Override + public boolean equals(Object that) { + if (that == null) + return false; + if (that instanceof resoucePoolGetAll_result) + return this.equals((resoucePoolGetAll_result)that); + return false; + } + + public boolean equals(resoucePoolGetAll_result that) { + if (that == null) + return false; + + boolean this_present_success = true && this.isSetSuccess(); + boolean that_present_success = true && that.isSetSuccess(); + if (this_present_success || that_present_success) { + if (!(this_present_success && that_present_success)) + return false; + if (!this.success.equals(that.success)) + return false; + } + + return true; + } + + @Override + public int hashCode() { + List list = new ArrayList(); + + boolean present_success = true && (isSetSuccess()); + list.add(present_success); + if (present_success) + list.add(success); + + return list.hashCode(); + } + + @Override + public int compareTo(resoucePoolGetAll_result other) { + if (!getClass().equals(other.getClass())) { + return getClass().getName().compareTo(other.getClass().getName()); + } + + int lastComparison = 0; + + lastComparison = Boolean.valueOf(isSetSuccess()).compareTo(other.isSetSuccess()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetSuccess()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.success, other.success); + if (lastComparison != 0) { + return lastComparison; + } + } + return 0; + } + + public _Fields fieldForId(int fieldId) { + return _Fields.findByThriftId(fieldId); + } + + public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { + schemes.get(iprot.getScheme()).getScheme().read(iprot, this); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { + schemes.get(oprot.getScheme()).getScheme().write(oprot, this); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("resoucePoolGetAll_result("); + boolean first = true; + + sb.append("success:"); + if (this.success == null) { + sb.append("null"); + } else { + sb.append(this.success); + } + first = false; + sb.append(")"); + return sb.toString(); + } + + public void validate() throws org.apache.thrift.TException { + // check for required fields + // check for sub-struct validity + } + + private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { + try { + write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException { + try { + read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private static class resoucePoolGetAll_resultStandardSchemeFactory implements SchemeFactory { + public resoucePoolGetAll_resultStandardScheme getScheme() { + return new resoucePoolGetAll_resultStandardScheme(); + } + } + + private static class resoucePoolGetAll_resultStandardScheme extends StandardScheme { + + public void read(org.apache.thrift.protocol.TProtocol iprot, resoucePoolGetAll_result struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TField schemeField; + iprot.readStructBegin(); + while (true) + { + schemeField = iprot.readFieldBegin(); + if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { + break; + } + switch (schemeField.id) { + case 0: // SUCCESS + if (schemeField.type == org.apache.thrift.protocol.TType.LIST) { + { + org.apache.thrift.protocol.TList _list26 = iprot.readListBegin(); + struct.success = new ArrayList(_list26.size); + String _elem27; + for (int _i28 = 0; _i28 < _list26.size; ++_i28) + { + _elem27 = iprot.readString(); + struct.success.add(_elem27); + } + iprot.readListEnd(); + } + struct.setSuccessIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + default: + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + iprot.readFieldEnd(); + } + iprot.readStructEnd(); + + // check for required fields of primitive type, which can't be checked in the validate method + struct.validate(); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot, resoucePoolGetAll_result struct) throws org.apache.thrift.TException { + struct.validate(); + + oprot.writeStructBegin(STRUCT_DESC); + if (struct.success != null) { + oprot.writeFieldBegin(SUCCESS_FIELD_DESC); + { + oprot.writeListBegin(new org.apache.thrift.protocol.TList(org.apache.thrift.protocol.TType.STRING, struct.success.size())); + for (String _iter29 : struct.success) + { + oprot.writeString(_iter29); + } + oprot.writeListEnd(); + } + oprot.writeFieldEnd(); + } + oprot.writeFieldStop(); + oprot.writeStructEnd(); + } + + } + + private static class resoucePoolGetAll_resultTupleSchemeFactory implements SchemeFactory { + public resoucePoolGetAll_resultTupleScheme getScheme() { + return new resoucePoolGetAll_resultTupleScheme(); + } + } + + private static class resoucePoolGetAll_resultTupleScheme extends TupleScheme { + + @Override + public void write(org.apache.thrift.protocol.TProtocol prot, resoucePoolGetAll_result struct) throws org.apache.thrift.TException { + TTupleProtocol oprot = (TTupleProtocol) prot; + BitSet optionals = new BitSet(); + if (struct.isSetSuccess()) { + optionals.set(0); + } + oprot.writeBitSet(optionals, 1); + if (struct.isSetSuccess()) { + { + oprot.writeI32(struct.success.size()); + for (String _iter30 : struct.success) + { + oprot.writeString(_iter30); + } + } + } + } + + @Override + public void read(org.apache.thrift.protocol.TProtocol prot, resoucePoolGetAll_result struct) throws org.apache.thrift.TException { + TTupleProtocol iprot = (TTupleProtocol) prot; + BitSet incoming = iprot.readBitSet(1); + if (incoming.get(0)) { + { + org.apache.thrift.protocol.TList _list31 = new org.apache.thrift.protocol.TList(org.apache.thrift.protocol.TType.STRING, iprot.readI32()); + struct.success = new ArrayList(_list31.size); + String _elem32; + for (int _i33 = 0; _i33 < _list31.size; ++_i33) + { + _elem32 = iprot.readString(); + struct.success.add(_elem32); + } + } + struct.setSuccessIsSet(true); + } + } + } + + } + + public static class resourceGet_args implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { + private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("resourceGet_args"); + + private static final org.apache.thrift.protocol.TField RESOURCE_NAME_FIELD_DESC = new org.apache.thrift.protocol.TField("resourceName", org.apache.thrift.protocol.TType.STRING, (short)1); + + private static final Map, SchemeFactory> schemes = new HashMap, SchemeFactory>(); + static { + schemes.put(StandardScheme.class, new resourceGet_argsStandardSchemeFactory()); + schemes.put(TupleScheme.class, new resourceGet_argsTupleSchemeFactory()); + } + + public String resourceName; // required + + /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ + public enum _Fields implements org.apache.thrift.TFieldIdEnum { + RESOURCE_NAME((short)1, "resourceName"); + + private static final Map byName = new HashMap(); + + static { + for (_Fields field : EnumSet.allOf(_Fields.class)) { + byName.put(field.getFieldName(), field); + } + } + + /** + * Find the _Fields constant that matches fieldId, or null if its not found. + */ + public static _Fields findByThriftId(int fieldId) { + switch(fieldId) { + case 1: // RESOURCE_NAME + return RESOURCE_NAME; + default: + return null; + } + } + + /** + * Find the _Fields constant that matches fieldId, throwing an exception + * if it is not found. + */ + public static _Fields findByThriftIdOrThrow(int fieldId) { + _Fields fields = findByThriftId(fieldId); + if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!"); + return fields; + } + + /** + * Find the _Fields constant that matches name, or null if its not found. + */ + public static _Fields findByName(String name) { + return byName.get(name); + } + + private final short _thriftId; + private final String _fieldName; + + _Fields(short thriftId, String fieldName) { + _thriftId = thriftId; + _fieldName = fieldName; + } + + public short getThriftFieldId() { + return _thriftId; + } + + public String getFieldName() { + return _fieldName; + } + } + + // isset id assignments + public static final Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap; + static { + Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class); + tmpMap.put(_Fields.RESOURCE_NAME, new org.apache.thrift.meta_data.FieldMetaData("resourceName", org.apache.thrift.TFieldRequirementType.DEFAULT, + new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING))); + metaDataMap = Collections.unmodifiableMap(tmpMap); + org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(resourceGet_args.class, metaDataMap); + } + + public resourceGet_args() { + } + + public resourceGet_args( + String resourceName) + { + this(); + this.resourceName = resourceName; + } + + /** + * Performs a deep copy on other. + */ + public resourceGet_args(resourceGet_args other) { + if (other.isSetResourceName()) { + this.resourceName = other.resourceName; + } + } + + public resourceGet_args deepCopy() { + return new resourceGet_args(this); + } + + @Override + public void clear() { + this.resourceName = null; + } + + public String getResourceName() { + return this.resourceName; + } + + public resourceGet_args setResourceName(String resourceName) { + this.resourceName = resourceName; + return this; + } + + public void unsetResourceName() { + this.resourceName = null; + } + + /** Returns true if field resourceName is set (has been assigned a value) and false otherwise */ + public boolean isSetResourceName() { + return this.resourceName != null; + } + + public void setResourceNameIsSet(boolean value) { + if (!value) { + this.resourceName = null; + } + } + + public void setFieldValue(_Fields field, Object value) { + switch (field) { + case RESOURCE_NAME: + if (value == null) { + unsetResourceName(); + } else { + setResourceName((String)value); + } + break; + + } + } + + public Object getFieldValue(_Fields field) { + switch (field) { + case RESOURCE_NAME: + return getResourceName(); + + } + throw new IllegalStateException(); + } + + /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */ + public boolean isSet(_Fields field) { + if (field == null) { + throw new IllegalArgumentException(); + } + + switch (field) { + case RESOURCE_NAME: + return isSetResourceName(); + } + throw new IllegalStateException(); + } + + @Override + public boolean equals(Object that) { + if (that == null) + return false; + if (that instanceof resourceGet_args) + return this.equals((resourceGet_args)that); + return false; + } + + public boolean equals(resourceGet_args that) { + if (that == null) + return false; + + boolean this_present_resourceName = true && this.isSetResourceName(); + boolean that_present_resourceName = true && that.isSetResourceName(); + if (this_present_resourceName || that_present_resourceName) { + if (!(this_present_resourceName && that_present_resourceName)) + return false; + if (!this.resourceName.equals(that.resourceName)) + return false; + } + + return true; + } + + @Override + public int hashCode() { + List list = new ArrayList(); + + boolean present_resourceName = true && (isSetResourceName()); + list.add(present_resourceName); + if (present_resourceName) + list.add(resourceName); + + return list.hashCode(); + } + + @Override + public int compareTo(resourceGet_args other) { + if (!getClass().equals(other.getClass())) { + return getClass().getName().compareTo(other.getClass().getName()); + } + + int lastComparison = 0; + + lastComparison = Boolean.valueOf(isSetResourceName()).compareTo(other.isSetResourceName()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetResourceName()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.resourceName, other.resourceName); + if (lastComparison != 0) { + return lastComparison; + } + } + return 0; + } + + public _Fields fieldForId(int fieldId) { + return _Fields.findByThriftId(fieldId); + } + + public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { + schemes.get(iprot.getScheme()).getScheme().read(iprot, this); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { + schemes.get(oprot.getScheme()).getScheme().write(oprot, this); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("resourceGet_args("); + boolean first = true; + + sb.append("resourceName:"); + if (this.resourceName == null) { + sb.append("null"); + } else { + sb.append(this.resourceName); + } + first = false; + sb.append(")"); + return sb.toString(); + } + + public void validate() throws org.apache.thrift.TException { + // check for required fields + // check for sub-struct validity + } + + private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { + try { + write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException { + try { + read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private static class resourceGet_argsStandardSchemeFactory implements SchemeFactory { + public resourceGet_argsStandardScheme getScheme() { + return new resourceGet_argsStandardScheme(); + } + } + + private static class resourceGet_argsStandardScheme extends StandardScheme { + + public void read(org.apache.thrift.protocol.TProtocol iprot, resourceGet_args struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TField schemeField; + iprot.readStructBegin(); + while (true) + { + schemeField = iprot.readFieldBegin(); + if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { + break; + } + switch (schemeField.id) { + case 1: // RESOURCE_NAME + if (schemeField.type == org.apache.thrift.protocol.TType.STRING) { + struct.resourceName = iprot.readString(); + struct.setResourceNameIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + default: + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + iprot.readFieldEnd(); + } + iprot.readStructEnd(); + + // check for required fields of primitive type, which can't be checked in the validate method + struct.validate(); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot, resourceGet_args struct) throws org.apache.thrift.TException { + struct.validate(); + + oprot.writeStructBegin(STRUCT_DESC); + if (struct.resourceName != null) { + oprot.writeFieldBegin(RESOURCE_NAME_FIELD_DESC); + oprot.writeString(struct.resourceName); + oprot.writeFieldEnd(); + } + oprot.writeFieldStop(); + oprot.writeStructEnd(); + } + + } + + private static class resourceGet_argsTupleSchemeFactory implements SchemeFactory { + public resourceGet_argsTupleScheme getScheme() { + return new resourceGet_argsTupleScheme(); + } + } + + private static class resourceGet_argsTupleScheme extends TupleScheme { + + @Override + public void write(org.apache.thrift.protocol.TProtocol prot, resourceGet_args struct) throws org.apache.thrift.TException { + TTupleProtocol oprot = (TTupleProtocol) prot; + BitSet optionals = new BitSet(); + if (struct.isSetResourceName()) { + optionals.set(0); + } + oprot.writeBitSet(optionals, 1); + if (struct.isSetResourceName()) { + oprot.writeString(struct.resourceName); + } + } + + @Override + public void read(org.apache.thrift.protocol.TProtocol prot, resourceGet_args struct) throws org.apache.thrift.TException { + TTupleProtocol iprot = (TTupleProtocol) prot; + BitSet incoming = iprot.readBitSet(1); + if (incoming.get(0)) { + struct.resourceName = iprot.readString(); + struct.setResourceNameIsSet(true); + } + } + } + + } + + public static class resourceGet_result implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { + private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("resourceGet_result"); + + private static final org.apache.thrift.protocol.TField SUCCESS_FIELD_DESC = new org.apache.thrift.protocol.TField("success", org.apache.thrift.protocol.TType.STRING, (short)0); + + private static final Map, SchemeFactory> schemes = new HashMap, SchemeFactory>(); + static { + schemes.put(StandardScheme.class, new resourceGet_resultStandardSchemeFactory()); + schemes.put(TupleScheme.class, new resourceGet_resultTupleSchemeFactory()); + } + + public ByteBuffer success; // required + + /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ + public enum _Fields implements org.apache.thrift.TFieldIdEnum { + SUCCESS((short)0, "success"); + + private static final Map byName = new HashMap(); + + static { + for (_Fields field : EnumSet.allOf(_Fields.class)) { + byName.put(field.getFieldName(), field); + } + } + + /** + * Find the _Fields constant that matches fieldId, or null if its not found. + */ + public static _Fields findByThriftId(int fieldId) { + switch(fieldId) { + case 0: // SUCCESS + return SUCCESS; + default: + return null; + } + } + + /** + * Find the _Fields constant that matches fieldId, throwing an exception + * if it is not found. + */ + public static _Fields findByThriftIdOrThrow(int fieldId) { + _Fields fields = findByThriftId(fieldId); + if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!"); + return fields; + } + + /** + * Find the _Fields constant that matches name, or null if its not found. + */ + public static _Fields findByName(String name) { + return byName.get(name); + } + + private final short _thriftId; + private final String _fieldName; + + _Fields(short thriftId, String fieldName) { + _thriftId = thriftId; + _fieldName = fieldName; + } + + public short getThriftFieldId() { + return _thriftId; + } + + public String getFieldName() { + return _fieldName; + } + } + + // isset id assignments + public static final Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap; + static { + Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class); + tmpMap.put(_Fields.SUCCESS, new org.apache.thrift.meta_data.FieldMetaData("success", org.apache.thrift.TFieldRequirementType.DEFAULT, + new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING , true))); + metaDataMap = Collections.unmodifiableMap(tmpMap); + org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(resourceGet_result.class, metaDataMap); + } + + public resourceGet_result() { + } + + public resourceGet_result( + ByteBuffer success) + { + this(); + this.success = org.apache.thrift.TBaseHelper.copyBinary(success); + } + + /** + * Performs a deep copy on other. + */ + public resourceGet_result(resourceGet_result other) { + if (other.isSetSuccess()) { + this.success = org.apache.thrift.TBaseHelper.copyBinary(other.success); + } + } + + public resourceGet_result deepCopy() { + return new resourceGet_result(this); + } + + @Override + public void clear() { + this.success = null; + } + + public byte[] getSuccess() { + setSuccess(org.apache.thrift.TBaseHelper.rightSize(success)); + return success == null ? null : success.array(); + } + + public ByteBuffer bufferForSuccess() { + return org.apache.thrift.TBaseHelper.copyBinary(success); + } + + public resourceGet_result setSuccess(byte[] success) { + this.success = success == null ? (ByteBuffer)null : ByteBuffer.wrap(Arrays.copyOf(success, success.length)); + return this; + } + + public resourceGet_result setSuccess(ByteBuffer success) { + this.success = org.apache.thrift.TBaseHelper.copyBinary(success); + return this; + } + + public void unsetSuccess() { + this.success = null; + } + + /** Returns true if field success is set (has been assigned a value) and false otherwise */ + public boolean isSetSuccess() { + return this.success != null; + } + + public void setSuccessIsSet(boolean value) { + if (!value) { + this.success = null; + } + } + + public void setFieldValue(_Fields field, Object value) { + switch (field) { + case SUCCESS: + if (value == null) { + unsetSuccess(); + } else { + setSuccess((ByteBuffer)value); + } + break; + + } + } + + public Object getFieldValue(_Fields field) { + switch (field) { + case SUCCESS: + return getSuccess(); + + } + throw new IllegalStateException(); + } + + /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */ + public boolean isSet(_Fields field) { + if (field == null) { + throw new IllegalArgumentException(); + } + + switch (field) { + case SUCCESS: + return isSetSuccess(); + } + throw new IllegalStateException(); + } + + @Override + public boolean equals(Object that) { + if (that == null) + return false; + if (that instanceof resourceGet_result) + return this.equals((resourceGet_result)that); + return false; + } + + public boolean equals(resourceGet_result that) { + if (that == null) + return false; + + boolean this_present_success = true && this.isSetSuccess(); + boolean that_present_success = true && that.isSetSuccess(); + if (this_present_success || that_present_success) { + if (!(this_present_success && that_present_success)) + return false; + if (!this.success.equals(that.success)) + return false; + } + + return true; + } + + @Override + public int hashCode() { + List list = new ArrayList(); + + boolean present_success = true && (isSetSuccess()); + list.add(present_success); + if (present_success) + list.add(success); + + return list.hashCode(); + } + + @Override + public int compareTo(resourceGet_result other) { + if (!getClass().equals(other.getClass())) { + return getClass().getName().compareTo(other.getClass().getName()); + } + + int lastComparison = 0; + + lastComparison = Boolean.valueOf(isSetSuccess()).compareTo(other.isSetSuccess()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetSuccess()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.success, other.success); + if (lastComparison != 0) { + return lastComparison; + } + } + return 0; + } + + public _Fields fieldForId(int fieldId) { + return _Fields.findByThriftId(fieldId); + } + + public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { + schemes.get(iprot.getScheme()).getScheme().read(iprot, this); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { + schemes.get(oprot.getScheme()).getScheme().write(oprot, this); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("resourceGet_result("); + boolean first = true; + + sb.append("success:"); + if (this.success == null) { + sb.append("null"); + } else { + org.apache.thrift.TBaseHelper.toString(this.success, sb); + } + first = false; + sb.append(")"); + return sb.toString(); + } + + public void validate() throws org.apache.thrift.TException { + // check for required fields + // check for sub-struct validity + } + + private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { + try { + write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException { + try { + read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private static class resourceGet_resultStandardSchemeFactory implements SchemeFactory { + public resourceGet_resultStandardScheme getScheme() { + return new resourceGet_resultStandardScheme(); + } + } + + private static class resourceGet_resultStandardScheme extends StandardScheme { + + public void read(org.apache.thrift.protocol.TProtocol iprot, resourceGet_result struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TField schemeField; + iprot.readStructBegin(); + while (true) + { + schemeField = iprot.readFieldBegin(); + if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { + break; + } + switch (schemeField.id) { + case 0: // SUCCESS + if (schemeField.type == org.apache.thrift.protocol.TType.STRING) { + struct.success = iprot.readBinary(); + struct.setSuccessIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + default: + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + iprot.readFieldEnd(); + } + iprot.readStructEnd(); + + // check for required fields of primitive type, which can't be checked in the validate method + struct.validate(); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot, resourceGet_result struct) throws org.apache.thrift.TException { + struct.validate(); + + oprot.writeStructBegin(STRUCT_DESC); + if (struct.success != null) { + oprot.writeFieldBegin(SUCCESS_FIELD_DESC); + oprot.writeBinary(struct.success); + oprot.writeFieldEnd(); + } + oprot.writeFieldStop(); + oprot.writeStructEnd(); + } + + } + + private static class resourceGet_resultTupleSchemeFactory implements SchemeFactory { + public resourceGet_resultTupleScheme getScheme() { + return new resourceGet_resultTupleScheme(); + } + } + + private static class resourceGet_resultTupleScheme extends TupleScheme { + + @Override + public void write(org.apache.thrift.protocol.TProtocol prot, resourceGet_result struct) throws org.apache.thrift.TException { + TTupleProtocol oprot = (TTupleProtocol) prot; + BitSet optionals = new BitSet(); + if (struct.isSetSuccess()) { + optionals.set(0); + } + oprot.writeBitSet(optionals, 1); + if (struct.isSetSuccess()) { + oprot.writeBinary(struct.success); + } + } + + @Override + public void read(org.apache.thrift.protocol.TProtocol prot, resourceGet_result struct) throws org.apache.thrift.TException { + TTupleProtocol iprot = (TTupleProtocol) prot; + BitSet incoming = iprot.readBitSet(1); + if (incoming.get(0)) { + struct.success = iprot.readBinary(); + struct.setSuccessIsSet(true); + } + } + } + + } + } diff --git a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/resource/ByteBufferInputStream.java b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/resource/ByteBufferInputStream.java new file mode 100644 index 00000000000..a8becb4aea1 --- /dev/null +++ b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/resource/ByteBufferInputStream.java @@ -0,0 +1,58 @@ +/* + * 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.resource; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.nio.ByteBuffer; + +/** + * InputStream from bytebuffer + */ +public class ByteBufferInputStream extends InputStream { + + ByteBuffer buf; + + public ByteBufferInputStream(ByteBuffer buf) { + this.buf = buf; + } + + public int read() throws IOException { + if (!buf.hasRemaining()) { + return -1; + } + return buf.get() & 0xFF; + } + + public int read(byte[] bytes, int off, int len) throws IOException { + if (!buf.hasRemaining()) { + return -1; + } + len = Math.min(len, buf.remaining()); + buf.get(bytes, off, len); + return len; + } + + public static InputStream get(ByteBuffer buf) { + if (buf.hasArray()) { + return new ByteArrayInputStream(buf.array()); + } else { + return new ByteBufferInputStream(buf); + } + } +} diff --git a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/resourcepool/DistributedResourcePool.java b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/resource/DistributedResourcePool.java similarity index 69% rename from zeppelin-interpreter/src/main/java/org/apache/zeppelin/resourcepool/DistributedResourcePool.java rename to zeppelin-interpreter/src/main/java/org/apache/zeppelin/resource/DistributedResourcePool.java index 3b65efa6a8e..023394cc114 100644 --- a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/resourcepool/DistributedResourcePool.java +++ b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/resource/DistributedResourcePool.java @@ -14,10 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.zeppelin.resourcepool; - -import java.io.Serializable; -import java.util.UUID; +package org.apache.zeppelin.resource; /** * distributed resource pool @@ -31,31 +28,51 @@ public DistributedResourcePool(String id, ResourcePoolConnector connector) { this.connector = connector; } + @Override + public Resource get(String name) { + return get(name, true); + } + /** * get resource by name. * @param name + * @param remote false only return from local resource * @return null if resource not found. */ - @Override - public Resource get(String name) { + public Resource get(String name, boolean remote) { // try local first Resource resource = super.get(name); if (resource != null) { return resource; } - ResourceSet resources = connector.getAllResourcesExcept(id()).filterByName(name); - if (resources.isEmpty()) { - return null; + if (remote) { + ResourceSet resources = connector.getAllResourcesExcept(id()).filterByName(name); + if (resources.isEmpty()) { + return null; + } else { + return resources.get(0); + } } else { - return resources.get(0); + return null; } } @Override public ResourceSet getAll() { + return getAll(true); + } + + /** + * Get all resource from the pool + * @param remote false only return local resource + * @return + */ + public ResourceSet getAll(boolean remote) { ResourceSet all = super.getAll(); - all.addAll(connector.getAllResourcesExcept(id())); + if (remote) { + all.addAll(connector.getAllResourcesExcept(id())); + } return all; } } diff --git a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/resourcepool/LocalResourcePool.java b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/resource/LocalResourcePool.java similarity index 98% rename from zeppelin-interpreter/src/main/java/org/apache/zeppelin/resourcepool/LocalResourcePool.java rename to zeppelin-interpreter/src/main/java/org/apache/zeppelin/resource/LocalResourcePool.java index 2af6da715e8..aae81e8182a 100644 --- a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/resourcepool/LocalResourcePool.java +++ b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/resource/LocalResourcePool.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.zeppelin.resourcepool; +package org.apache.zeppelin.resource; import java.util.*; diff --git a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/resource/RemoteResource.java b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/resource/RemoteResource.java new file mode 100644 index 00000000000..abd0ea5823b --- /dev/null +++ b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/resource/RemoteResource.java @@ -0,0 +1,39 @@ +package org.apache.zeppelin.resource; + +/** + * Resource that can retrieve data from remote + */ +public class RemoteResource extends Resource { + ResourcePoolConnector resourcePoolConnector; + + RemoteResource(ResourceId resourceId, Object r) { + super(resourceId, r); + } + + RemoteResource(ResourceId resourceId, boolean serializable, String className) { + super(resourceId, serializable, className); + } + + @Override + public Object get() { + if (isSerializable()) { + Object o = resourcePoolConnector.readResource(getResourceId()); + return o; + } else { + return null; + } + } + + @Override + public boolean isLocal() { + return false; + } + + public ResourcePoolConnector getResourcePoolConnector() { + return resourcePoolConnector; + } + + public void setResourcePoolConnector(ResourcePoolConnector resourcePoolConnector) { + this.resourcePoolConnector = resourcePoolConnector; + } +} diff --git a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/resourcepool/Resource.java b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/resource/Resource.java similarity index 68% rename from zeppelin-interpreter/src/main/java/org/apache/zeppelin/resourcepool/Resource.java rename to zeppelin-interpreter/src/main/java/org/apache/zeppelin/resource/Resource.java index 1d31094f601..918a06eede4 100644 --- a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/resourcepool/Resource.java +++ b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/resource/Resource.java @@ -14,15 +14,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.zeppelin.resourcepool; +package org.apache.zeppelin.resource; -import java.io.Serializable; +import java.io.*; +import java.nio.ByteBuffer; /** * Information and reference to the resource */ public class Resource { - private final Object r; + private final transient Object r; private final boolean serializable; private final ResourceId resourceId; private final String className; @@ -90,6 +91,44 @@ public boolean isRemote() { * @return */ public boolean isLocal() { - return r != null; + return true; } + + + + public static ByteBuffer serializeObject(Object o) throws IOException { + if (o == null || !(o instanceof Serializable)) { + return null; + } + + ByteArrayOutputStream out = new ByteArrayOutputStream(); + try { + ObjectOutputStream oos; + oos = new ObjectOutputStream(out); + oos.writeObject(o); + oos.close(); + out.close(); + } catch (Exception e) { + e.printStackTrace(); + } + return ByteBuffer.wrap(out.toByteArray()); + } + + public static Object deserializeObject(ByteBuffer buf) + throws IOException, ClassNotFoundException { + if (buf == null) { + return null; + } + InputStream ins = ByteBufferInputStream.get(buf); + ObjectInputStream oin; + Object object = null; + + oin = new ObjectInputStream(ins); + object = oin.readObject(); + oin.close(); + ins.close(); + + return object; + } + } diff --git a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/resourcepool/ResourceId.java b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/resource/ResourceId.java similarity index 97% rename from zeppelin-interpreter/src/main/java/org/apache/zeppelin/resourcepool/ResourceId.java rename to zeppelin-interpreter/src/main/java/org/apache/zeppelin/resource/ResourceId.java index 9c1d92b92eb..a0d55e34f62 100644 --- a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/resourcepool/ResourceId.java +++ b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/resource/ResourceId.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.zeppelin.resourcepool; +package org.apache.zeppelin.resource; /** * Identifying resource diff --git a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/resourcepool/ResourcePool.java b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/resource/ResourcePool.java similarity index 97% rename from zeppelin-interpreter/src/main/java/org/apache/zeppelin/resourcepool/ResourcePool.java rename to zeppelin-interpreter/src/main/java/org/apache/zeppelin/resource/ResourcePool.java index 08026b34514..6328b8d88e5 100644 --- a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/resourcepool/ResourcePool.java +++ b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/resource/ResourcePool.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.zeppelin.resourcepool; +package org.apache.zeppelin.resource; /** * Interface for ResourcePool diff --git a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/resourcepool/ResourcePoolConnector.java b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/resource/ResourcePoolConnector.java similarity index 88% rename from zeppelin-interpreter/src/main/java/org/apache/zeppelin/resourcepool/ResourcePoolConnector.java rename to zeppelin-interpreter/src/main/java/org/apache/zeppelin/resource/ResourcePoolConnector.java index c928f100df6..495ab2acbc2 100644 --- a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/resourcepool/ResourcePoolConnector.java +++ b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/resource/ResourcePoolConnector.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.zeppelin.resourcepool; +package org.apache.zeppelin.resource; /** * Connect resource pools running in remote process @@ -25,4 +25,10 @@ public interface ResourcePoolConnector { * @return */ public ResourceSet getAllResourcesExcept(String excludePoolId); + + /** + * Read remote object + * @return + */ + public Object readResource(ResourceId id); } diff --git a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/resourcepool/ResourceSet.java b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/resource/ResourceSet.java similarity index 98% rename from zeppelin-interpreter/src/main/java/org/apache/zeppelin/resourcepool/ResourceSet.java rename to zeppelin-interpreter/src/main/java/org/apache/zeppelin/resource/ResourceSet.java index e9508233647..a03655b9f4a 100644 --- a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/resourcepool/ResourceSet.java +++ b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/resource/ResourceSet.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.zeppelin.resourcepool; +package org.apache.zeppelin.resource; import java.util.Collection; import java.util.LinkedList; diff --git a/zeppelin-interpreter/src/main/thrift/RemoteInterpreterService.thrift b/zeppelin-interpreter/src/main/thrift/RemoteInterpreterService.thrift index 144784c539e..5cbcc805368 100644 --- a/zeppelin-interpreter/src/main/thrift/RemoteInterpreterService.thrift +++ b/zeppelin-interpreter/src/main/thrift/RemoteInterpreterService.thrift @@ -42,7 +42,9 @@ enum RemoteInterpreterEventType { ANGULAR_OBJECT_ADD = 2, ANGULAR_OBJECT_UPDATE = 3, ANGULAR_OBJECT_REMOVE = 4, - RUN_INTERPRETER_CONTEXT_RUNNER = 5 + RUN_INTERPRETER_CONTEXT_RUNNER = 5, + RESOURCE_POOL_GET_ALL = 6, + RESOURCE_GET = 7 } struct RemoteInterpreterEvent { @@ -51,7 +53,7 @@ struct RemoteInterpreterEvent { } service RemoteInterpreterService { - void createInterpreter(1: string className, 2: map properties); + void createInterpreter(1: string intpGroupId, 2: string className, 3: map properties); void open(1: string className); void close(1: string className); @@ -68,4 +70,13 @@ service RemoteInterpreterService { void angularObjectUpdate(1: string name, 2: string noteId, 3: string object); void angularObjectAdd(1: string name, 2: string noteId, 3: string object); void angularObjectRemove(1: string name, 2: string noteId); + + // as a response, ZeppelinServer send list of resources to Interpreter process + void resourcePoolResponseGetAll(1: list resources); + // as a response, ZeppelinServer send serialized value of resource + void resourceResponseGet(1: string resourceId, 2: binary object); + // get all resources in the interpreter process + list resoucePoolGetAll(); + // get value of resource + binary resourceGet(1: string resourceName); } \ No newline at end of file diff --git a/zeppelin-interpreter/src/test/java/org/apache/zeppelin/interpreter/InterpreterContextTest.java b/zeppelin-interpreter/src/test/java/org/apache/zeppelin/interpreter/InterpreterContextTest.java index 080bdaa4337..c0b355ab174 100644 --- a/zeppelin-interpreter/src/test/java/org/apache/zeppelin/interpreter/InterpreterContextTest.java +++ b/zeppelin-interpreter/src/test/java/org/apache/zeppelin/interpreter/InterpreterContextTest.java @@ -27,7 +27,8 @@ public class InterpreterContextTest { public void testThreadLocal() { assertNull(InterpreterContext.get()); - InterpreterContext.set(new InterpreterContext(null, null, null, null, null, null, null, null)); + InterpreterContext.set(new InterpreterContext(null, null, null, null, null, null, null, + null, null)); assertNotNull(InterpreterContext.get()); InterpreterContext.remove(); diff --git a/zeppelin-interpreter/src/test/java/org/apache/zeppelin/interpreter/remote/RemoteAngularObjectTest.java b/zeppelin-interpreter/src/test/java/org/apache/zeppelin/interpreter/remote/RemoteAngularObjectTest.java index 29a1fb11972..710f668b1e6 100644 --- a/zeppelin-interpreter/src/test/java/org/apache/zeppelin/interpreter/remote/RemoteAngularObjectTest.java +++ b/zeppelin-interpreter/src/test/java/org/apache/zeppelin/interpreter/remote/RemoteAngularObjectTest.java @@ -34,6 +34,8 @@ import org.apache.zeppelin.interpreter.InterpreterGroup; import org.apache.zeppelin.interpreter.InterpreterResult; import org.apache.zeppelin.interpreter.remote.mock.MockInterpreterAngular; +import org.apache.zeppelin.resource.LocalResourcePool; +import org.apache.zeppelin.resource.ResourcePool; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -83,6 +85,7 @@ public void setUp() throws Exception { new HashMap(), new GUI(), new AngularObjectRegistry(intpGroup.getId(), null), + new LocalResourcePool("pool1"), new LinkedList()); intp.open(); @@ -91,7 +94,7 @@ public void setUp() throws Exception { @After public void tearDown() throws Exception { intp.close(); - intpGroup.clone(); + intpGroup.close(); intpGroup.destroy(); } diff --git a/zeppelin-interpreter/src/test/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterTest.java b/zeppelin-interpreter/src/test/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterTest.java index c938ff36622..42e260c3190 100644 --- a/zeppelin-interpreter/src/test/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterTest.java +++ b/zeppelin-interpreter/src/test/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterTest.java @@ -37,6 +37,7 @@ import org.apache.zeppelin.interpreter.InterpreterResult.Code; import org.apache.zeppelin.interpreter.remote.mock.MockInterpreterA; import org.apache.zeppelin.interpreter.remote.mock.MockInterpreterB; +import org.apache.zeppelin.resource.LocalResourcePool; import org.apache.zeppelin.scheduler.Job; import org.apache.zeppelin.scheduler.Job.Status; import org.apache.zeppelin.scheduler.Scheduler; @@ -113,6 +114,7 @@ public void testRemoteInterperterCall() throws TTransportException, IOException new HashMap(), new GUI(), new AngularObjectRegistry(intpGroup.getId(), null), + new LocalResourcePool("pool1"), new LinkedList())); intpB.open(); @@ -153,6 +155,7 @@ public void testRemoteInterperterErrorStatus() throws TTransportException, IOExc new HashMap(), new GUI(), new AngularObjectRegistry(intpGroup.getId(), null), + new LocalResourcePool("pool1"), new LinkedList())); assertEquals(Code.ERROR, ret.code()); @@ -199,6 +202,7 @@ public void testRemoteSchedulerSharing() throws TTransportException, IOException new HashMap(), new GUI(), new AngularObjectRegistry(intpGroup.getId(), null), + new LocalResourcePool("pool1"), new LinkedList())); assertEquals("500", ret.message()); @@ -211,6 +215,7 @@ public void testRemoteSchedulerSharing() throws TTransportException, IOException new HashMap(), new GUI(), new AngularObjectRegistry(intpGroup.getId(), null), + new LocalResourcePool("pool1"), new LinkedList())); assertEquals("1000", ret.message()); long end = System.currentTimeMillis(); @@ -276,6 +281,7 @@ protected Object jobRun() throws Throwable { new HashMap(), new GUI(), new AngularObjectRegistry(intpGroup.getId(), null), + new LocalResourcePool("pool1"), new LinkedList())); } @@ -310,6 +316,7 @@ protected Object jobRun() throws Throwable { new HashMap(), new GUI(), new AngularObjectRegistry(intpGroup.getId(), null), + new LocalResourcePool("pool1"), new LinkedList())); } @@ -382,6 +389,7 @@ protected Object jobRun() throws Throwable { new HashMap(), new GUI(), new AngularObjectRegistry(intpGroup.getId(), null), + new LocalResourcePool("pool1"), new LinkedList())); synchronized (results) { @@ -466,6 +474,7 @@ protected Object jobRun() throws Throwable { new HashMap(), new GUI(), new AngularObjectRegistry(intpGroup.getId(), null), + new LocalResourcePool("pool1"), new LinkedList())); synchronized (results) { @@ -585,6 +594,7 @@ protected Object jobRun() throws Throwable { new HashMap(), new GUI(), new AngularObjectRegistry(intpGroup.getId(), null), + new LocalResourcePool("pool1"), new LinkedList())); } diff --git a/zeppelin-interpreter/src/test/java/org/apache/zeppelin/interpreter/remote/mock/MockInterpreterResourcePool.java b/zeppelin-interpreter/src/test/java/org/apache/zeppelin/interpreter/remote/mock/MockInterpreterResourcePool.java new file mode 100644 index 00000000000..1db68ad177f --- /dev/null +++ b/zeppelin-interpreter/src/test/java/org/apache/zeppelin/interpreter/remote/mock/MockInterpreterResourcePool.java @@ -0,0 +1,112 @@ +/* + * 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.interpreter.remote.mock; + +import java.util.List; +import java.util.Properties; +import java.util.concurrent.atomic.AtomicInteger; + +import com.google.gson.Gson; +import org.apache.zeppelin.display.AngularObjectRegistry; +import org.apache.zeppelin.display.AngularObjectWatcher; +import org.apache.zeppelin.interpreter.Interpreter; +import org.apache.zeppelin.interpreter.InterpreterContext; +import org.apache.zeppelin.interpreter.InterpreterPropertyBuilder; +import org.apache.zeppelin.interpreter.InterpreterResult; +import org.apache.zeppelin.interpreter.InterpreterResult.Code; +import org.apache.zeppelin.resource.ResourcePool; + +public class MockInterpreterResourcePool extends Interpreter { + static { + Interpreter.register( + "resourcePoolTest", + "resourcePool", + MockInterpreterA.class.getName(), + new InterpreterPropertyBuilder() + .add("p1", "v1", "property1").build()); + + } + + AtomicInteger numWatch = new AtomicInteger(0); + + public MockInterpreterResourcePool(Properties property) { + super(property); + } + + @Override + public void open() { + } + + @Override + public void close() { + + } + + @Override + public InterpreterResult interpret(String st, InterpreterContext context) { + String[] stmt = st.split(" "); + String cmd = stmt[0]; + String name = null; + if (stmt.length >= 2) { + name = stmt[1]; + } + String value = null; + if (stmt.length == 3) { + value = stmt[2]; + } + + ResourcePool resourcePool = context.getResourcePool(); + Object ret = null; + if (cmd.equals("put")) { + resourcePool.put(name, value); + } else if (cmd.equalsIgnoreCase("get")) { + ret = resourcePool.get(name).get(); + } else if (cmd.equals("remove")) { + ret = resourcePool.remove(name); + } else if (cmd.equals("getAll")) { + ret = resourcePool.getAll(); + } + + try { + Thread.sleep(500); // wait for watcher executed + } catch (InterruptedException e) { + } + + Gson gson = new Gson(); + return new InterpreterResult(Code.SUCCESS, gson.toJson(ret)); + } + + @Override + public void cancel(InterpreterContext context) { + } + + @Override + public FormType getFormType() { + return FormType.NATIVE; + } + + @Override + public int getProgress(InterpreterContext context) { + return 0; + } + + @Override + public List completion(String buf, int cursor) { + return null; + } +} \ No newline at end of file diff --git a/zeppelin-interpreter/src/test/java/org/apache/zeppelin/resource/DistributedResourcePoolTest.java b/zeppelin-interpreter/src/test/java/org/apache/zeppelin/resource/DistributedResourcePoolTest.java new file mode 100644 index 00000000000..3c37b588713 --- /dev/null +++ b/zeppelin-interpreter/src/test/java/org/apache/zeppelin/resource/DistributedResourcePoolTest.java @@ -0,0 +1,182 @@ +package org.apache.zeppelin.resource; + +import com.google.gson.Gson; +import org.apache.zeppelin.display.AngularObjectRegistry; +import org.apache.zeppelin.display.GUI; +import org.apache.zeppelin.interpreter.InterpreterContext; +import org.apache.zeppelin.interpreter.InterpreterContextRunner; +import org.apache.zeppelin.interpreter.InterpreterGroup; +import org.apache.zeppelin.interpreter.InterpreterResult; +import org.apache.zeppelin.interpreter.remote.RemoteAngularObjectRegistry; +import org.apache.zeppelin.interpreter.remote.RemoteInterpreter; +import org.apache.zeppelin.interpreter.remote.RemoteInterpreterEventPoller; +import org.apache.zeppelin.interpreter.remote.mock.MockInterpreterResourcePool; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import java.io.File; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.Properties; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +/** + * Unittest for DistributedResourcePool + */ +public class DistributedResourcePoolTest { + private InterpreterGroup intpGroup1; + private InterpreterGroup intpGroup2; + private HashMap env; + private RemoteInterpreter intp1; + private RemoteInterpreter intp2; + private InterpreterContext context; + private RemoteInterpreterEventPoller eventPoller1; + private RemoteInterpreterEventPoller eventPoller2; + + + @Before + public void setUp() throws Exception { + env = new HashMap(); + env.put("ZEPPELIN_CLASSPATH", new File("./target/test-classes").getAbsolutePath()); + + Properties p = new Properties(); + + intp1 = new RemoteInterpreter( + p, + MockInterpreterResourcePool.class.getName(), + new File("../bin/interpreter.sh").getAbsolutePath(), + "fake", + env, + 10 * 1000 + ); + + intpGroup1 = new InterpreterGroup("intpGroup1"); + intpGroup1.add(intp1); + intp1.setInterpreterGroup(intpGroup1); + + intp2 = new RemoteInterpreter( + p, + MockInterpreterResourcePool.class.getName(), + new File("../bin/interpreter.sh").getAbsolutePath(), + "fake", + env, + 10 * 1000 + ); + + intpGroup2 = new InterpreterGroup("intpGroup2"); + intpGroup2.add(intp2); + intp2.setInterpreterGroup(intpGroup2); + + context = new InterpreterContext( + "note", + "id", + "title", + "text", + new HashMap(), + new GUI(), + null, + null, + new LinkedList()); + + intp1.open(); + intp2.open(); + + eventPoller1 = new RemoteInterpreterEventPoller(); + eventPoller1.setInterpreterGroup(intpGroup1); + eventPoller1.setInterpreterProcess(intpGroup1.getRemoteInterpreterProcess()); + + eventPoller2 = new RemoteInterpreterEventPoller(); + eventPoller2.setInterpreterGroup(intpGroup2); + eventPoller2.setInterpreterProcess(intpGroup2.getRemoteInterpreterProcess()); + + eventPoller1.start(); + eventPoller2.start(); + } + + @After + public void tearDown() throws Exception { + eventPoller1.shutdown(); + intp1.close(); + intpGroup1.close(); + intpGroup1.destroy(); + eventPoller2.shutdown(); + intp2.close(); + intpGroup2.close(); + intpGroup2.destroy(); + } + + @Test + public void testRemoteDistributedResourcePool() { + Gson gson = new Gson(); + InterpreterResult ret; + intp1.interpret("put key1 value1", context); + intp2.interpret("put key2 value2", context); + + ret = intp1.interpret("getAll", context); + assertEquals(2, gson.fromJson(ret.message(), ResourceSet.class).size()); + + ret = intp2.interpret("getAll", context); + assertEquals(2, gson.fromJson(ret.message(), ResourceSet.class).size()); + + ret = intp1.interpret("get key1", context); + assertEquals("value1", gson.fromJson(ret.message(), String.class)); + + ret = intp1.interpret("get key2", context); + assertEquals("value2", gson.fromJson(ret.message(), String.class)); + } + + @Test + public void testDistributedResourcePool() { + final LocalResourcePool pool2 = new LocalResourcePool("pool2"); + final LocalResourcePool pool3 = new LocalResourcePool("pool3"); + + DistributedResourcePool pool1 = new DistributedResourcePool("pool1", new ResourcePoolConnector() { + @Override + public ResourceSet getAllResourcesExcept(String excludePoolId) { + ResourceSet set = pool2.getAll(); + set.addAll(pool3.getAll()); + + ResourceSet remoteSet = new ResourceSet(); + Gson gson = new Gson(); + for (Resource s : set) { + RemoteResource remoteResource = gson.fromJson(gson.toJson(s), RemoteResource.class); + remoteResource.setResourcePoolConnector(this); + remoteSet.add(remoteResource); + } + return remoteSet; + } + + @Override + public Object readResource(ResourceId id) { + if (id.getResourcePoolId().equals(pool2.id())) { + return pool2.get(id.getName()).get(); + } + if (id.getResourcePoolId().equals(pool3.id())) { + return pool3.get(id.getName()).get(); + } + return null; + } + }); + + assertEquals(0, pool1.getAll().size()); + + + // test get() can get from pool + pool2.put("object1", "value2"); + assertEquals(1, pool1.getAll().size()); + assertTrue(pool1.get("object1").isRemote()); + assertEquals("value2", pool1.get("object1").get()); + + // test get() is locality aware + pool1.put("object1", "value1"); + assertEquals(1, pool2.getAll().size()); + assertEquals("value1", pool1.get("object1").get()); + + // test getAll() is locality aware + assertEquals("value1", pool1.getAll().get(0).get()); + assertEquals("value2", pool1.getAll().get(1).get()); + } +} diff --git a/zeppelin-interpreter/src/test/java/org/apache/zeppelin/resourcepool/LocalResourcePoolTest.java b/zeppelin-interpreter/src/test/java/org/apache/zeppelin/resource/LocalResourcePoolTest.java similarity index 97% rename from zeppelin-interpreter/src/test/java/org/apache/zeppelin/resourcepool/LocalResourcePoolTest.java rename to zeppelin-interpreter/src/test/java/org/apache/zeppelin/resource/LocalResourcePoolTest.java index 8368f128c1a..65d284bafa6 100644 --- a/zeppelin-interpreter/src/test/java/org/apache/zeppelin/resourcepool/LocalResourcePoolTest.java +++ b/zeppelin-interpreter/src/test/java/org/apache/zeppelin/resource/LocalResourcePoolTest.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.zeppelin.resourcepool; +package org.apache.zeppelin.resource; import org.junit.Test; diff --git a/zeppelin-interpreter/src/test/java/org/apache/zeppelin/resourcepool/ResourceSetTest.java b/zeppelin-interpreter/src/test/java/org/apache/zeppelin/resource/ResourceSetTest.java similarity index 97% rename from zeppelin-interpreter/src/test/java/org/apache/zeppelin/resourcepool/ResourceSetTest.java rename to zeppelin-interpreter/src/test/java/org/apache/zeppelin/resource/ResourceSetTest.java index d43cd137d3d..ca645250e24 100644 --- a/zeppelin-interpreter/src/test/java/org/apache/zeppelin/resourcepool/ResourceSetTest.java +++ b/zeppelin-interpreter/src/test/java/org/apache/zeppelin/resource/ResourceSetTest.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.zeppelin.resourcepool; +package org.apache.zeppelin.resource; import org.junit.Test; diff --git a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/resourcepool/ResourcePoolListener.java b/zeppelin-interpreter/src/test/java/org/apache/zeppelin/resource/ResourceTest.java similarity index 65% rename from zeppelin-interpreter/src/main/java/org/apache/zeppelin/resourcepool/ResourcePoolListener.java rename to zeppelin-interpreter/src/test/java/org/apache/zeppelin/resource/ResourceTest.java index 2638ea94fab..fb8b27131f6 100644 --- a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/resourcepool/ResourcePoolListener.java +++ b/zeppelin-interpreter/src/test/java/org/apache/zeppelin/resource/ResourceTest.java @@ -14,10 +14,22 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.zeppelin.resourcepool; +package org.apache.zeppelin.resource; + +import org.junit.Test; + +import java.io.IOException; +import java.nio.ByteBuffer; + +import static org.junit.Assert.assertEquals; /** - * Event from LocalResourcePool + * Test for Resource */ -public interface ResourcePoolListener { +public class ResourceTest { + @Test + public void testSerializeDeserialize() throws IOException, ClassNotFoundException { + ByteBuffer buffer = Resource.serializeObject("hello"); + assertEquals("hello", Resource.deserializeObject(buffer)); + } } diff --git a/zeppelin-interpreter/src/test/java/org/apache/zeppelin/resourcepool/DistributedResourcePoolTest.java b/zeppelin-interpreter/src/test/java/org/apache/zeppelin/resourcepool/DistributedResourcePoolTest.java deleted file mode 100644 index 9b611657b88..00000000000 --- a/zeppelin-interpreter/src/test/java/org/apache/zeppelin/resourcepool/DistributedResourcePoolTest.java +++ /dev/null @@ -1,43 +0,0 @@ -package org.apache.zeppelin.resourcepool; - -import org.junit.Test; - -import static org.junit.Assert.assertEquals; - -/** - * Unittest for DistributedResourcePool - */ -public class DistributedResourcePoolTest { - - @Test - public void testDistributedResourcePool() { - final LocalResourcePool pool2 = new LocalResourcePool("pool2"); - final LocalResourcePool pool3 = new LocalResourcePool("pool3"); - - DistributedResourcePool pool1 = new DistributedResourcePool("pool1", new ResourcePoolConnector() { - @Override - public ResourceSet getAllResourcesExcept(String excludePoolId) { - ResourceSet set = pool2.getAll(); - set.addAll(pool3.getAll()); - return set; - } - }); - - assertEquals(0, pool1.getAll().size()); - - - // test get() can get from pool - pool2.put("object1", "value2"); - assertEquals(1, pool1.getAll().size()); - assertEquals("value2", pool1.get("object1").get()); - - // test get() is locality aware - pool1.put("object1", "value1"); - assertEquals(1, pool2.getAll().size()); - assertEquals("value1", pool1.get("object1").get()); - - // test getAll() is locality aware - assertEquals("value1", pool1.getAll().get(0).get()); - assertEquals("value2", pool1.getAll().get(1).get()); - } -} diff --git a/zeppelin-interpreter/src/test/java/org/apache/zeppelin/scheduler/RemoteSchedulerTest.java b/zeppelin-interpreter/src/test/java/org/apache/zeppelin/scheduler/RemoteSchedulerTest.java index d17df4f1406..8434d32b0e1 100644 --- a/zeppelin-interpreter/src/test/java/org/apache/zeppelin/scheduler/RemoteSchedulerTest.java +++ b/zeppelin-interpreter/src/test/java/org/apache/zeppelin/scheduler/RemoteSchedulerTest.java @@ -35,6 +35,7 @@ import org.apache.zeppelin.interpreter.InterpreterGroup; import org.apache.zeppelin.interpreter.remote.RemoteInterpreter; import org.apache.zeppelin.interpreter.remote.mock.MockInterpreterA; +import org.apache.zeppelin.resource.LocalResourcePool; import org.apache.zeppelin.scheduler.Job.Status; import org.junit.After; import org.junit.Before; @@ -103,6 +104,7 @@ protected Object jobRun() throws Throwable { new HashMap(), new GUI(), new AngularObjectRegistry(intpGroup.getId(), null), + new LocalResourcePool("pool1"), new LinkedList())); return "1000"; } @@ -173,6 +175,7 @@ public void testAbortOnPending() throws Exception { new HashMap(), new GUI(), new AngularObjectRegistry(intpGroup.getId(), null), + new LocalResourcePool("pool1"), new LinkedList()); @Override @@ -209,6 +212,7 @@ protected boolean jobAbort() { new HashMap(), new GUI(), new AngularObjectRegistry(intpGroup.getId(), null), + new LocalResourcePool("pool1"), new LinkedList()); @Override diff --git a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Paragraph.java b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Paragraph.java index 433095b379c..d50e529d3fe 100644 --- a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Paragraph.java +++ b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Paragraph.java @@ -23,6 +23,7 @@ import org.apache.zeppelin.interpreter.*; import org.apache.zeppelin.interpreter.Interpreter.FormType; import org.apache.zeppelin.interpreter.InterpreterResult.Code; +import org.apache.zeppelin.resource.ResourcePool; import org.apache.zeppelin.scheduler.Job; import org.apache.zeppelin.scheduler.JobListener; import org.slf4j.Logger; @@ -233,10 +234,12 @@ protected boolean jobAbort() { private InterpreterContext getInterpreterContext() { AngularObjectRegistry registry = null; + ResourcePool resourcePool = null; if (!getNoteReplLoader().getInterpreterSettings().isEmpty()) { InterpreterSetting intpGroup = getNoteReplLoader().getInterpreterSettings().get(0); registry = intpGroup.getInterpreterGroup().getAngularObjectRegistry(); + resourcePool = intpGroup.getInterpreterGroup().getResourcePool(); } List runners = new LinkedList(); @@ -252,6 +255,7 @@ private InterpreterContext getInterpreterContext() { this.getConfig(), this.settings, registry, + resourcePool, runners); return interpreterContext; } diff --git a/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/InterpreterFactoryTest.java b/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/InterpreterFactoryTest.java index abd0e3bf11b..79ccf15def4 100644 --- a/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/InterpreterFactoryTest.java +++ b/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/InterpreterFactoryTest.java @@ -56,8 +56,7 @@ public void setUp() throws Exception { System.setProperty(ConfVars.ZEPPELIN_INTERPRETERS.getVarName(), "org.apache.zeppelin.interpreter.mock.MockInterpreter1,org.apache.zeppelin.interpreter.mock.MockInterpreter2"); conf = new ZeppelinConfiguration(); factory = new InterpreterFactory(conf, new InterpreterOption(false), null, null); - context = new InterpreterContext("note", "id", "title", "text", null, null, null, null); - + context = new InterpreterContext("note", "id", "title", "text", null, null, null, null, null); } @After From 2be9902f59487a33de32c400b2db395ae22e60fa Mon Sep 17 00:00:00 2001 From: Lee moon soo Date: Mon, 18 Jan 2016 12:46:50 -0800 Subject: [PATCH 03/16] Update test --- .../zeppelin/flink/FlinkInterpreterTest.java | 2 +- .../zeppelin/hive/HiveInterpreterTest.java | 18 ++++++++++++------ .../zeppelin/ignite/IgniteInterpreterTest.java | 2 +- .../ignite/IgniteSqlInterpreterTest.java | 2 +- 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/flink/src/test/java/org/apache/zeppelin/flink/FlinkInterpreterTest.java b/flink/src/test/java/org/apache/zeppelin/flink/FlinkInterpreterTest.java index 3168f04787e..9a61be637ec 100644 --- a/flink/src/test/java/org/apache/zeppelin/flink/FlinkInterpreterTest.java +++ b/flink/src/test/java/org/apache/zeppelin/flink/FlinkInterpreterTest.java @@ -40,7 +40,7 @@ public static void setUp() { Properties p = new Properties(); flink = new FlinkInterpreter(p); flink.open(); - context = new InterpreterContext(null, null, null, null, null, null, null, null); + context = new InterpreterContext(null, null, null, null, null, null, null, null, null); } @AfterClass diff --git a/hive/src/test/java/org/apache/zeppelin/hive/HiveInterpreterTest.java b/hive/src/test/java/org/apache/zeppelin/hive/HiveInterpreterTest.java index c22080d57f0..96a1654d152 100644 --- a/hive/src/test/java/org/apache/zeppelin/hive/HiveInterpreterTest.java +++ b/hive/src/test/java/org/apache/zeppelin/hive/HiveInterpreterTest.java @@ -79,9 +79,11 @@ public void readTest() throws IOException { HiveInterpreter t = new HiveInterpreter(properties); t.open(); - assertTrue(t.interpret("show databases", new InterpreterContext("", "1", "","", null,null,null,null)).message().contains("SCHEMA_NAME")); + assertTrue(t.interpret("show databases", new InterpreterContext("", "1", "","", null,null, + null,null,null)).message().contains("SCHEMA_NAME")); assertEquals("ID\tNAME\na\ta_name\nb\tb_name\n", - t.interpret("select * from test_table", new InterpreterContext("", "1", "","", null,null,null,null)).message()); + t.interpret("select * from test_table", new InterpreterContext("", "1", "","", null,null, + null,null,null)).message()); } @Test @@ -101,7 +103,8 @@ public void readTestWithConfiguration() throws IOException { t.open(); assertEquals("ID\tNAME\na\ta_name\nb\tb_name\n", - t.interpret("(h2)\n select * from test_table", new InterpreterContext("", "1", "","", null,null,null,null)).message()); + t.interpret("(h2)\n select * from test_table", new InterpreterContext("", "1", "","", + null,null,null,null,null)).message()); } @Test @@ -117,13 +120,15 @@ public void jdbcRestart() throws IOException, SQLException, ClassNotFoundExcepti t.open(); InterpreterResult interpreterResult = - t.interpret("select * from test_table", new InterpreterContext("", "1", "","", null,null,null,null)); + t.interpret("select * from test_table", new InterpreterContext("", "1", "","", null,null, + null,null,null)); assertEquals("ID\tNAME\na\ta_name\nb\tb_name\n", interpreterResult.message()); t.getConnection("default").close(); interpreterResult = - t.interpret("select * from test_table", new InterpreterContext("", "1", "","", null,null,null,null)); + t.interpret("select * from test_table", new InterpreterContext("", "1", "","", null,null, + null,null,null)); assertEquals("ID\tNAME\na\ta_name\nb\tb_name\n", interpreterResult.message()); } @@ -139,7 +144,8 @@ public void test() throws IOException { HiveInterpreter t = new HiveInterpreter(properties); t.open(); - InterpreterContext interpreterContext = new InterpreterContext(null, "a", null, null, null, null, null, null); + InterpreterContext interpreterContext = new InterpreterContext(null, "a", null, null, null, + null, null, null, null); //simple select test InterpreterResult result = t.interpret("select * from test_table", interpreterContext); diff --git a/ignite/src/test/java/org/apache/zeppelin/ignite/IgniteInterpreterTest.java b/ignite/src/test/java/org/apache/zeppelin/ignite/IgniteInterpreterTest.java index f46b049ccb3..cf9808389e5 100644 --- a/ignite/src/test/java/org/apache/zeppelin/ignite/IgniteInterpreterTest.java +++ b/ignite/src/test/java/org/apache/zeppelin/ignite/IgniteInterpreterTest.java @@ -40,7 +40,7 @@ public class IgniteInterpreterTest { private static final String HOST = "127.0.0.1:47500..47509"; private static final InterpreterContext INTP_CONTEXT = - new InterpreterContext(null, null, null, null, null, null, null, null); + new InterpreterContext(null, null, null, null, null, null, null, null, null); private IgniteInterpreter intp; private Ignite ignite; diff --git a/ignite/src/test/java/org/apache/zeppelin/ignite/IgniteSqlInterpreterTest.java b/ignite/src/test/java/org/apache/zeppelin/ignite/IgniteSqlInterpreterTest.java index fb93ad5d3b8..a6dcc66bd61 100644 --- a/ignite/src/test/java/org/apache/zeppelin/ignite/IgniteSqlInterpreterTest.java +++ b/ignite/src/test/java/org/apache/zeppelin/ignite/IgniteSqlInterpreterTest.java @@ -44,7 +44,7 @@ public class IgniteSqlInterpreterTest { private static final String HOST = "127.0.0.1:47500..47509"; private static final InterpreterContext INTP_CONTEXT = - new InterpreterContext(null, null, null, null, null, null, null, null); + new InterpreterContext(null, null, null, null, null, null, null, null, null); private Ignite ignite; private IgniteSqlInterpreter intp; From b85dc59cf6fd0f338bc35c1f6cbea73b03b70d7b Mon Sep 17 00:00:00 2001 From: Lee moon soo Date: Mon, 18 Jan 2016 19:02:50 -0800 Subject: [PATCH 04/16] Fix test --- .../org/apache/zeppelin/scalding/ScaldingInterpreterTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scalding/src/test/java/org/apache/zeppelin/scalding/ScaldingInterpreterTest.java b/scalding/src/test/java/org/apache/zeppelin/scalding/ScaldingInterpreterTest.java index 7a753fa7cd5..9d03ff5768c 100644 --- a/scalding/src/test/java/org/apache/zeppelin/scalding/ScaldingInterpreterTest.java +++ b/scalding/src/test/java/org/apache/zeppelin/scalding/ScaldingInterpreterTest.java @@ -64,7 +64,7 @@ public void setUp() throws Exception { InterpreterGroup intpGroup = new InterpreterGroup(); context = new InterpreterContext("note", "id", "title", "text", new HashMap(), new GUI(), new AngularObjectRegistry( - intpGroup.getId(), null), + intpGroup.getId(), null), null, new LinkedList()); } From 263f580d2ae8db7e9cac605b0b08c0e767d679b9 Mon Sep 17 00:00:00 2001 From: Lee moon soo Date: Mon, 18 Jan 2016 20:06:04 -0800 Subject: [PATCH 05/16] ZeppelinContext provides api for resource pool --- .../zeppelin/spark/ZeppelinContext.java | 64 ++++++++++++++++++- 1 file changed, 61 insertions(+), 3 deletions(-) diff --git a/spark/src/main/java/org/apache/zeppelin/spark/ZeppelinContext.java b/spark/src/main/java/org/apache/zeppelin/spark/ZeppelinContext.java index a55ed73bec3..d928c2991b2 100644 --- a/spark/src/main/java/org/apache/zeppelin/spark/ZeppelinContext.java +++ b/spark/src/main/java/org/apache/zeppelin/spark/ZeppelinContext.java @@ -25,14 +25,12 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.Collection; -import java.util.HashMap; import java.util.Iterator; import java.util.LinkedList; import java.util.List; import org.apache.spark.SparkContext; import org.apache.spark.sql.SQLContext; -import org.apache.spark.sql.SQLContext.QueryExecution; import org.apache.spark.sql.catalyst.expressions.Attribute; import org.apache.spark.sql.hive.HiveContext; import org.apache.zeppelin.display.AngularObject; @@ -44,15 +42,19 @@ import org.apache.zeppelin.interpreter.InterpreterContextRunner; import org.apache.zeppelin.interpreter.InterpreterException; import org.apache.zeppelin.spark.dep.SparkDependencyResolver; +import org.apache.zeppelin.resource.Resource; +import org.apache.zeppelin.resource.ResourcePool; +import org.apache.zeppelin.resource.ResourceSet; import scala.Tuple2; import scala.Unit; import scala.collection.Iterable; +import scala.collection.JavaConversions; /** * Spark context for zeppelin. */ -public class ZeppelinContext extends HashMap { +public class ZeppelinContext { private SparkDependencyResolver dep; private PrintStream out; private InterpreterContext interpreterContext; @@ -749,4 +751,60 @@ private void angularUnbind(String name, String noteId) { AngularObjectRegistry registry = interpreterContext.getAngularObjectRegistry(); registry.remove(name, noteId); } + + + /** + * Add object into resource pool + * @param name + * @param value + */ + public void put(String name, Object value) { + ResourcePool resourcePool = interpreterContext.getResourcePool(); + resourcePool.put(name, value); + } + + /** + * Get object from resource pool + * Search local process first and then the other processes + * @param name + * @return null if resource not found + */ + public Object get(String name) { + ResourcePool resourcePool = interpreterContext.getResourcePool(); + Resource resource = resourcePool.get(name); + if (resource != null) { + return resource.get(); + } else { + return null; + } + } + + /** + * Remove object from resourcePool + * @param name + */ + public void remove(String name) { + ResourcePool resourcePool = interpreterContext.getResourcePool(); + resourcePool.remove(name); + } + + /** + * Check if resource pool has the object + * @param name + * @return + */ + public boolean containsKey(String name) { + ResourcePool resourcePool = interpreterContext.getResourcePool(); + Resource resource = resourcePool.get(name); + return resource != null; + } + + /** + * Get all resources + */ + public ResourceSet getAll() { + ResourcePool resourcePool = interpreterContext.getResourcePool(); + return resourcePool.getAll(); + } + } From 9d288fe45bd51be379edfa0e9ba2408f2ea8997d Mon Sep 17 00:00:00 2001 From: Lee moon soo Date: Mon, 18 Jan 2016 21:37:39 -0800 Subject: [PATCH 06/16] update test --- .../java/org/apache/zeppelin/jdbc/JDBCInterpreterTest.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/jdbc/src/test/java/org/apache/zeppelin/jdbc/JDBCInterpreterTest.java b/jdbc/src/test/java/org/apache/zeppelin/jdbc/JDBCInterpreterTest.java index 83e050750e4..a595a250903 100644 --- a/jdbc/src/test/java/org/apache/zeppelin/jdbc/JDBCInterpreterTest.java +++ b/jdbc/src/test/java/org/apache/zeppelin/jdbc/JDBCInterpreterTest.java @@ -94,7 +94,8 @@ public void testSelectQuery() throws SQLException, IOException { String sqlQuery = "select * from test_table"; - InterpreterResult interpreterResult = t.interpret(sqlQuery, new InterpreterContext("", "1", "","", null,null,null,null)); + InterpreterResult interpreterResult = t.interpret(sqlQuery, + new InterpreterContext("", "1", "","", null,null,null,null,null)); assertEquals(InterpreterResult.Code.SUCCESS, interpreterResult.code()); assertEquals(InterpreterResult.Type.TABLE, interpreterResult.type()); @@ -116,7 +117,8 @@ public void testSelectQueryMaxResult() throws SQLException, IOException { String sqlQuery = "select * from test_table"; - InterpreterResult interpreterResult = t.interpret(sqlQuery, new InterpreterContext("", "1", "","", null,null,null,null)); + InterpreterResult interpreterResult = t.interpret(sqlQuery, + new InterpreterContext("", "1", "","", null,null,null,null,null)); assertEquals(InterpreterResult.Code.SUCCESS, interpreterResult.code()); assertEquals(InterpreterResult.Type.TABLE, interpreterResult.type()); From 0af0cd03236faac63cae17cfc4a4d9b4f76692ca Mon Sep 17 00:00:00 2001 From: Lee moon soo Date: Mon, 18 Jan 2016 22:25:05 -0800 Subject: [PATCH 07/16] null check interpreterGroup. Do not log expected exceptions --- .../interpreter/remote/RemoteInterpreter.java | 4 +++- .../remote/RemoteInterpreterProcess.java | 6 +++++- .../remote/RemoteInterpreterServer.java | 20 ++++++++++--------- .../remote/RemoteInterpreterUtils.java | 3 ++- 4 files changed, 21 insertions(+), 12 deletions(-) diff --git a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreter.java b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreter.java index b48181c9ed8..83f4431cdb1 100644 --- a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreter.java +++ b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreter.java @@ -165,7 +165,9 @@ public void close() { boolean broken = false; try { client = interpreterProcess.getClient(); - client.close(className); + if (client != null) { + client.close(className); + } } catch (TException e) { broken = true; throw new InterpreterException(e); diff --git a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterProcess.java b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterProcess.java index 2c195dcd106..bb49711c1cc 100644 --- a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterProcess.java +++ b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterProcess.java @@ -138,6 +138,9 @@ public int reference(InterpreterGroup interpreterGroup) { } public Client getClient() throws Exception { + if (clientPool == null || clientPool.isClosed()) { + return null; + } return clientPool.borrowObject(); } @@ -180,7 +183,8 @@ public int dereference() { } catch (Exception e) { // safely ignore exception while client.shutdown() may terminates remote process logger.info("Exception in RemoteInterpreterProcess while synchronized dereference, can " + - "safely ignore exception while client.shutdown() may terminates remote process", e); + "safely ignore exception while client.shutdown() may terminates remote process"); + logger.debug(e.getMessage(), e); } finally { if (client != null) { // no longer used diff --git a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterServer.java b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterServer.java index 864cdbb0202..ecf2afd49c9 100644 --- a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterServer.java +++ b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterServer.java @@ -100,8 +100,10 @@ public void run() { @Override public void shutdown() throws TException { - interpreterGroup.close(); - interpreterGroup.destroy(); + if (interpreterGroup != null) { + interpreterGroup.close(); + interpreterGroup.destroy(); + } server.stop(); @@ -470,7 +472,7 @@ public void angularObjectUpdate(String name, String noteId, String object) // first try local objects AngularObject ao = registry.get(name, noteId); if (ao == null) { - logger.error("Angular object {} not exists", name); + logger.debug("Angular object {} not exists", name); return; } @@ -487,8 +489,8 @@ public void angularObjectUpdate(String name, String noteId, String object) ao.set(value, false); return; } catch (Exception e) { - // no luck - logger.info("Exception in RemoteInterpreterServer while angularObjectUpdate, no luck", e); + // it's not a previous object's type. proceed to treat as a generic type + logger.debug(e.getMessage(), e); } } @@ -499,8 +501,8 @@ public void angularObjectUpdate(String name, String noteId, String object) new TypeToken>() { }.getType()); } catch (Exception e) { - // no lock - logger.info("Exception in RemoteInterpreterServer while angularObjectUpdate, no lock", e); + // it's not a generic json object, too. okay, proceed to threat as a string type + logger.debug(e.getMessage(), e); } } @@ -534,8 +536,8 @@ public void angularObjectAdd(String name, String noteId, String object) new TypeToken>() { }.getType()); } catch (Exception e) { - // nolock - logger.info("Exception in RemoteInterpreterServer while angularObjectAdd, nolock", e); + // it's okay. proceed to treat object as a string + logger.debug(e.getMessage(), e); } // try string object type at last diff --git a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterUtils.java b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterUtils.java index 4d2e46e96a9..a66b52ab229 100644 --- a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterUtils.java +++ b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterUtils.java @@ -47,7 +47,8 @@ public static boolean checkIfRemoteEndpointAccessible(String host, int port) { discover.close(); return true; } catch (IOException e) { - LOGGER.info("Exception in RemoteInterpreterUtils while checkIfRemoteEndpointAccessible", e); + // end point is not accessible + LOGGER.debug(e.getMessage(), e); return false; } } From 0d15577dc48aab8cb7b0d1be9398a84c2e3eb1ea Mon Sep 17 00:00:00 2001 From: Lee moon soo Date: Tue, 19 Jan 2016 10:39:10 -0800 Subject: [PATCH 08/16] Add license header --- .../zeppelin/resource/RemoteResource.java | 16 ++++++++++++++++ .../resource/DistributedResourcePoolTest.java | 18 ++++++++++++++++-- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/resource/RemoteResource.java b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/resource/RemoteResource.java index abd0ea5823b..5a8a9ea11f3 100644 --- a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/resource/RemoteResource.java +++ b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/resource/RemoteResource.java @@ -1,3 +1,19 @@ +/* + * 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.resource; /** diff --git a/zeppelin-interpreter/src/test/java/org/apache/zeppelin/resource/DistributedResourcePoolTest.java b/zeppelin-interpreter/src/test/java/org/apache/zeppelin/resource/DistributedResourcePoolTest.java index 3c37b588713..e267c1be2bd 100644 --- a/zeppelin-interpreter/src/test/java/org/apache/zeppelin/resource/DistributedResourcePoolTest.java +++ b/zeppelin-interpreter/src/test/java/org/apache/zeppelin/resource/DistributedResourcePoolTest.java @@ -1,13 +1,27 @@ +/* + * 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.resource; import com.google.gson.Gson; -import org.apache.zeppelin.display.AngularObjectRegistry; import org.apache.zeppelin.display.GUI; import org.apache.zeppelin.interpreter.InterpreterContext; import org.apache.zeppelin.interpreter.InterpreterContextRunner; import org.apache.zeppelin.interpreter.InterpreterGroup; import org.apache.zeppelin.interpreter.InterpreterResult; -import org.apache.zeppelin.interpreter.remote.RemoteAngularObjectRegistry; import org.apache.zeppelin.interpreter.remote.RemoteInterpreter; import org.apache.zeppelin.interpreter.remote.RemoteInterpreterEventPoller; import org.apache.zeppelin.interpreter.remote.mock.MockInterpreterResourcePool; From 14269d904039bbdadf7f267dfef578ed65a3db23 Mon Sep 17 00:00:00 2001 From: Lee moon soo Date: Tue, 19 Jan 2016 13:23:32 -0800 Subject: [PATCH 09/16] Handling NPE --- .../interpreter/remote/RemoteInterpreterProcess.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterProcess.java b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterProcess.java index bb49711c1cc..653d33941fa 100644 --- a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterProcess.java +++ b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterProcess.java @@ -290,8 +290,13 @@ public void updateRemoteAngularObject(String name, String noteId, Object o) { } catch (TException e) { broken = true; logger.error("Can't update angular object", e); + } catch (NullPointerException e) { + logger.error("Remote interpreter process not started", e); + return; } finally { - releaseClient(client, broken); + if (client != null) { + releaseClient(client, broken); + } } } From c3cb0d6f790ed2c2ef92f02956bbbcb7e7d5c793 Mon Sep 17 00:00:00 2001 From: Lee moon soo Date: Tue, 19 Jan 2016 18:08:39 -0800 Subject: [PATCH 10/16] Handling exception --- .../main/java/org/apache/zeppelin/notebook/Notebook.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Notebook.java b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Notebook.java index a068cea8ed2..c09d177ff3b 100644 --- a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Notebook.java +++ b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Notebook.java @@ -426,9 +426,12 @@ public void execute(JobExecutionContext context) throws JobExecutionException { boolean releaseResource = false; try { - releaseResource = (boolean) note.getConfig().get("releaseresource"); - } catch (java.lang.ClassCastException e) { - logger.error(e.toString(), e); + Map config = note.getConfig(); + if (config != null && config.containsKey("releaseresource")) { + releaseResource = (boolean) note.getConfig().get("releaseresource"); + } + } catch (ClassCastException e) { + logger.error(e.getMessage(), e); } if (releaseResource) { for (InterpreterSetting setting : note.getNoteReplLoader().getInterpreterSettings()) { From 6ac84e1b72357c1f05b1e8f0f04e098c81c4d431 Mon Sep 17 00:00:00 2001 From: Lee moon soo Date: Sun, 24 Jan 2016 15:22:08 -0800 Subject: [PATCH 11/16] Nullcheck before access InterpreterGroup --- .../zeppelin/interpreter/remote/RemoteInterpreterServer.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterServer.java b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterServer.java index 0768e27f4bf..541f2056334 100644 --- a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterServer.java +++ b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterServer.java @@ -440,6 +440,10 @@ private RemoteInterpreterResult convert(InterpreterResult result, @Override public String getStatus(String jobId) throws TException { + if (interpreterGroup == null) { + return "Unknown"; + } + synchronized (interpreterGroup) { for (Interpreter intp : interpreterGroup) { for (Job job : intp.getScheduler().getJobsRunning()) { From 8150466a7897438e00f8fd362d8b3e94da60f7eb Mon Sep 17 00:00:00 2001 From: Lee moon soo Date: Sun, 31 Jan 2016 05:02:45 +0900 Subject: [PATCH 12/16] Remove synchronize block --- .../zeppelin/resource/LocalResourcePool.java | 25 +++++++------------ 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/resource/LocalResourcePool.java b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/resource/LocalResourcePool.java index aae81e8182a..6bd4e7c44d6 100644 --- a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/resource/LocalResourcePool.java +++ b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/resource/LocalResourcePool.java @@ -23,7 +23,8 @@ */ public class LocalResourcePool implements ResourcePool { private final String resourcePoolId; - private final Map resources = new HashMap(); + private final Map resources + = Collections.synchronizedMap(new HashMap()); /** * @param id unique id @@ -47,17 +48,13 @@ public String id() { */ @Override public Resource get(String name) { - synchronized (resources) { - ResourceId resourceId = new ResourceId(resourcePoolId, name); - return resources.get(resourceId); - } + ResourceId resourceId = new ResourceId(resourcePoolId, name); + return resources.get(resourceId); } @Override public ResourceSet getAll() { - synchronized (resources) { - return new ResourceSet(resources.values()); - } + return new ResourceSet(resources.values()); } /** @@ -67,18 +64,14 @@ public ResourceSet getAll() { */ @Override public void put(String name, Object object) { - synchronized (resources) { - ResourceId resourceId = new ResourceId(resourcePoolId, name); + ResourceId resourceId = new ResourceId(resourcePoolId, name); - Resource resource = new Resource(resourceId, object); - resources.put(resourceId, resource); - } + Resource resource = new Resource(resourceId, object); + resources.put(resourceId, resource); } @Override public Resource remove(String name) { - synchronized (resources) { - return resources.remove(new ResourceId(resourcePoolId, name)); - } + return resources.remove(new ResourceId(resourcePoolId, name)); } } From 2945a905be9eb9063d01cc6ba3cd4e96f723105c Mon Sep 17 00:00:00 2001 From: Lee moon soo Date: Sun, 31 Jan 2016 05:07:19 +0900 Subject: [PATCH 13/16] ConcurrentHashMap instead of Collections.synchronizedMap() --- .../java/org/apache/zeppelin/interpreter/InterpreterGroup.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/InterpreterGroup.java b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/InterpreterGroup.java index 0ceeb405768..4d450be15a8 100644 --- a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/InterpreterGroup.java +++ b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/InterpreterGroup.java @@ -18,6 +18,7 @@ package org.apache.zeppelin.interpreter; import java.util.*; +import java.util.concurrent.ConcurrentHashMap; import org.apache.log4j.Logger; import org.apache.zeppelin.display.AngularObjectRegistry; @@ -38,7 +39,7 @@ public class InterpreterGroup extends LinkedList{ ResourcePool resourcePool; private static final Map allInterpreterGroups = - Collections.synchronizedMap(new HashMap()); + new ConcurrentHashMap(); public static InterpreterGroup get(String id) { return allInterpreterGroups.get(id); From f46abd7cdc3e92b740c53250e8481c5f5b84bf75 Mon Sep 17 00:00:00 2001 From: Lee moon soo Date: Sun, 31 Jan 2016 05:09:27 +0900 Subject: [PATCH 14/16] Refactor get() method --- .../src/main/java/org/apache/zeppelin/resource/Resource.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/resource/Resource.java b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/resource/Resource.java index 918a06eede4..6988b3ea762 100644 --- a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/resource/Resource.java +++ b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/resource/Resource.java @@ -65,9 +65,7 @@ public String getClassName() { * @return null when this is remote resource and not serializable. */ public Object get() { - if (isLocal()) { - return r; - } else if (isSerializable()){ + if (isLocal() || isSerializable()){ return r; } else { return null; From 27b2ac5520dbb36854bf25c3c0ce625c5ffed373 Mon Sep 17 00:00:00 2001 From: Lee moon soo Date: Sun, 31 Jan 2016 05:19:08 +0900 Subject: [PATCH 15/16] connector.getAllResourceExcept(id()) -> connector.getAllResource() --- .../interpreter/remote/RemoteInterpreterEventClient.java | 7 ++----- .../interpreter/remote/RemoteInterpreterEventPoller.java | 8 +++----- .../apache/zeppelin/resource/DistributedResourcePool.java | 4 ++-- .../apache/zeppelin/resource/ResourcePoolConnector.java | 4 ++-- .../zeppelin/resource/DistributedResourcePoolTest.java | 2 +- 5 files changed, 10 insertions(+), 15 deletions(-) diff --git a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterEventClient.java b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterEventClient.java index 72bd52fe0cf..158f145de45 100644 --- a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterEventClient.java +++ b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterEventClient.java @@ -91,15 +91,12 @@ public void angularObjectRemove(String name, String noteId, String paragraphId) /** * Get all resources except for specific resourcePool - * @param excludePoolId resource pool for exclusion. * @return */ @Override - public ResourceSet getAllResourcesExcept(String excludePoolId) { + public ResourceSet getAllResources() { // request - sendEvent(new RemoteInterpreterEvent( - RemoteInterpreterEventType.RESOURCE_POOL_GET_ALL, - excludePoolId)); + sendEvent(new RemoteInterpreterEvent(RemoteInterpreterEventType.RESOURCE_POOL_GET_ALL, null)); synchronized (getAllResourceResponse) { while (getAllResourceResponse.isEmpty()) { diff --git a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterEventPoller.java b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterEventPoller.java index fcdc891f7ea..be28bbf1227 100644 --- a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterEventPoller.java +++ b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterEventPoller.java @@ -126,9 +126,7 @@ public void run() { interpreterProcess.getInterpreterContextRunnerPool().run( runnerFromRemote.getNoteId(), runnerFromRemote.getParagraphId()); } else if (event.getType() == RemoteInterpreterEventType.RESOURCE_POOL_GET_ALL) { - String excludePoolId = event.getData(); - logger.debug("RESOURCE_POOL_GET_ALL {}", excludePoolId); - ResourceSet resourceSet = getAllResourcePoolExcept(excludePoolId); + ResourceSet resourceSet = getAllResourcePoolExcept(); sendResourcePoolResponseGetAll(resourceSet); } else if (event.getType() == RemoteInterpreterEventType.RESOURCE_GET) { String resourceIdString = event.getData(); @@ -183,10 +181,10 @@ private void sendResourcePoolResponseGetAll(ResourceSet resourceSet) { } } - private ResourceSet getAllResourcePoolExcept(String exclude) { + private ResourceSet getAllResourcePoolExcept() { ResourceSet resourceSet = new ResourceSet(); for (InterpreterGroup intpGroup : InterpreterGroup.getAll()) { - if (intpGroup.getId().equals(exclude)) { + if (intpGroup.getId().equals(interpreterGroup.getId())) { continue; } diff --git a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/resource/DistributedResourcePool.java b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/resource/DistributedResourcePool.java index 023394cc114..3f03b92609e 100644 --- a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/resource/DistributedResourcePool.java +++ b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/resource/DistributedResourcePool.java @@ -47,7 +47,7 @@ public Resource get(String name, boolean remote) { } if (remote) { - ResourceSet resources = connector.getAllResourcesExcept(id()).filterByName(name); + ResourceSet resources = connector.getAllResources().filterByName(name); if (resources.isEmpty()) { return null; } else { @@ -71,7 +71,7 @@ public ResourceSet getAll() { public ResourceSet getAll(boolean remote) { ResourceSet all = super.getAll(); if (remote) { - all.addAll(connector.getAllResourcesExcept(id())); + all.addAll(connector.getAllResources()); } return all; } diff --git a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/resource/ResourcePoolConnector.java b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/resource/ResourcePoolConnector.java index 495ab2acbc2..af343db6b14 100644 --- a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/resource/ResourcePoolConnector.java +++ b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/resource/ResourcePoolConnector.java @@ -21,10 +21,10 @@ */ public interface ResourcePoolConnector { /** - * Get list of resources from all resource pool + * Get list of resources from all other resource pools in remote processes * @return */ - public ResourceSet getAllResourcesExcept(String excludePoolId); + public ResourceSet getAllResources(); /** * Read remote object diff --git a/zeppelin-interpreter/src/test/java/org/apache/zeppelin/resource/DistributedResourcePoolTest.java b/zeppelin-interpreter/src/test/java/org/apache/zeppelin/resource/DistributedResourcePoolTest.java index f4731524fc4..39c74bc6f01 100644 --- a/zeppelin-interpreter/src/test/java/org/apache/zeppelin/resource/DistributedResourcePoolTest.java +++ b/zeppelin-interpreter/src/test/java/org/apache/zeppelin/resource/DistributedResourcePoolTest.java @@ -152,7 +152,7 @@ public void testDistributedResourcePool() { DistributedResourcePool pool1 = new DistributedResourcePool("pool1", new ResourcePoolConnector() { @Override - public ResourceSet getAllResourcesExcept(String excludePoolId) { + public ResourceSet getAllResources() { ResourceSet set = pool2.getAll(); set.addAll(pool3.getAll()); From 7b53f8be5cefbd3f073f31db4edba79795b6ba08 Mon Sep 17 00:00:00 2001 From: Lee moon soo Date: Sun, 31 Jan 2016 05:39:29 +0900 Subject: [PATCH 16/16] Fix style --- .../java/org/apache/zeppelin/resource/LocalResourcePool.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/resource/LocalResourcePool.java b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/resource/LocalResourcePool.java index 6bd4e7c44d6..cc5f7e9515c 100644 --- a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/resource/LocalResourcePool.java +++ b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/resource/LocalResourcePool.java @@ -23,8 +23,8 @@ */ public class LocalResourcePool implements ResourcePool { private final String resourcePoolId; - private final Map resources - = Collections.synchronizedMap(new HashMap()); + private final Map resources = Collections.synchronizedMap( + new HashMap()); /** * @param id unique id