use of org.apache.zeppelin.interpreter.InterpreterGroup in project SSM by Intel-bigdata.
the class RemoteInterpreterProcessTest method testStartStopRemoteInterpreter.
@Test
public void testStartStopRemoteInterpreter() throws TException, InterruptedException {
RemoteInterpreterServer server = new RemoteInterpreterServer(3678);
server.start();
boolean running = false;
long startTime = System.currentTimeMillis();
while (System.currentTimeMillis() - startTime < 10 * 1000) {
if (server.isRunning()) {
running = true;
break;
} else {
Thread.sleep(200);
}
}
Properties properties = new Properties();
properties.setProperty(Constants.ZEPPELIN_INTERPRETER_PORT, "3678");
properties.setProperty(Constants.ZEPPELIN_INTERPRETER_HOST, "localhost");
InterpreterGroup intpGroup = mock(InterpreterGroup.class);
when(intpGroup.getProperty()).thenReturn(properties);
when(intpGroup.containsKey(Constants.EXISTING_PROCESS)).thenReturn(true);
RemoteInterpreterProcess rip = new RemoteInterpreterManagedProcess(INTERPRETER_SCRIPT, "nonexists", "fakeRepo", new HashMap<String, String>(), mock(RemoteInterpreterEventPoller.class), 10 * 1000);
assertFalse(rip.isRunning());
assertEquals(0, rip.referenceCount());
assertEquals(1, rip.reference(intpGroup, "anonymous", false));
assertEquals(true, rip.isRunning());
}
use of org.apache.zeppelin.interpreter.InterpreterGroup in project SSM by Intel-bigdata.
the class RemoteInterpreterProcessTest method testPropagateError.
@Test
public void testPropagateError() throws TException, InterruptedException {
InterpreterGroup intpGroup = new InterpreterGroup();
RemoteInterpreterManagedProcess rip = new RemoteInterpreterManagedProcess("echo hello_world", "nonexists", "fakeRepo", new HashMap<String, String>(), 10 * 1000, null, null);
assertFalse(rip.isRunning());
assertEquals(0, rip.referenceCount());
try {
assertEquals(1, rip.reference(intpGroup, "anonymous", false));
} catch (InterpreterException e) {
e.getMessage().contains("hello_world");
}
assertEquals(0, rip.referenceCount());
}
use of org.apache.zeppelin.interpreter.InterpreterGroup in project SSM by Intel-bigdata.
the class RemoteInterpreterProcessTest method testClientFactory.
@Test
public void testClientFactory() throws Exception {
InterpreterGroup intpGroup = new InterpreterGroup();
RemoteInterpreterManagedProcess rip = new RemoteInterpreterManagedProcess(INTERPRETER_SCRIPT, "nonexists", "fakeRepo", new HashMap<String, String>(), mock(RemoteInterpreterEventPoller.class), 10 * 1000);
rip.reference(intpGroup, "anonymous", false);
assertEquals(0, rip.getNumActiveClient());
assertEquals(0, rip.getNumIdleClient());
Client client = rip.getClient();
assertEquals(1, rip.getNumActiveClient());
assertEquals(0, rip.getNumIdleClient());
rip.releaseClient(client);
assertEquals(0, rip.getNumActiveClient());
assertEquals(1, rip.getNumIdleClient());
rip.dereference();
}
use of org.apache.zeppelin.interpreter.InterpreterGroup in project SSM by Intel-bigdata.
the class ResourcePoolUtils method getAllResourcesExcept.
public static ResourceSet getAllResourcesExcept(String interpreterGroupExcludsion) {
ResourceSet resourceSet = new ResourceSet();
for (InterpreterGroup intpGroup : InterpreterGroup.getAll()) {
if (interpreterGroupExcludsion != null && intpGroup.getId().equals(interpreterGroupExcludsion)) {
continue;
}
RemoteInterpreterProcess remoteInterpreterProcess = intpGroup.getRemoteInterpreterProcess();
if (remoteInterpreterProcess == null) {
ResourcePool localPool = intpGroup.getResourcePool();
if (localPool != null) {
resourceSet.addAll(localPool.getAll());
}
} else if (remoteInterpreterProcess.isRunning()) {
RemoteInterpreterService.Client client = null;
boolean broken = false;
try {
client = remoteInterpreterProcess.getClient();
List<String> resourceList = client.resourcePoolGetAll();
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;
}
Aggregations