Search in sources :

Example 11 with Resource

use of org.apache.zeppelin.resource.Resource in project zeppelin by apache.

the class RemoteInterpreterServer method resourcePoolGetAll.

@Override
public List<String> resourcePoolGetAll() throws InterpreterRPCException, TException {
    LOGGER.debug("Request resourcePoolGetAll from ZeppelinServer");
    List<String> result = new LinkedList<>();
    if (resourcePool == null) {
        return result;
    }
    ResourceSet resourceSet = resourcePool.getAll(false);
    for (Resource r : resourceSet) {
        result.add(r.toJson());
    }
    return result;
}
Also used : Resource(org.apache.zeppelin.resource.Resource) ResourceSet(org.apache.zeppelin.resource.ResourceSet) LinkedList(java.util.LinkedList)

Example 12 with Resource

use of org.apache.zeppelin.resource.Resource in project zeppelin by apache.

the class TableDataProxy method rows.

@Override
public Iterator<Row> rows() {
    String resourceName = resource.getResourceId().getName() + ".rows";
    Resource rows = resource.invokeMethod("rows", resourceName);
    ProxyRowIterator it = new ProxyRowIterator(rows);
    return it;
}
Also used : Resource(org.apache.zeppelin.resource.Resource)

Example 13 with Resource

use of org.apache.zeppelin.resource.Resource in project zeppelin by apache.

the class InterpreterSettingManager method removeResourcesBelongsToParagraph.

public void removeResourcesBelongsToParagraph(String noteId, String paragraphId) {
    for (ManagedInterpreterGroup intpGroup : getAllInterpreterGroup()) {
        ResourceSet resourceSet = new ResourceSet();
        RemoteInterpreterProcess remoteInterpreterProcess = intpGroup.getRemoteInterpreterProcess();
        if (remoteInterpreterProcess == null) {
            ResourcePool localPool = intpGroup.getResourcePool();
            if (localPool != null) {
                resourceSet.addAll(localPool.getAll());
            }
            if (noteId != null) {
                resourceSet = resourceSet.filterByNoteId(noteId);
            }
            if (paragraphId != null) {
                resourceSet = resourceSet.filterByParagraphId(paragraphId);
            }
            for (Resource r : resourceSet) {
                localPool.remove(r.getResourceId().getNoteId(), r.getResourceId().getParagraphId(), r.getResourceId().getName());
            }
        } else if (remoteInterpreterProcess.isRunning()) {
            try {
                List<String> resourceList = remoteInterpreterProcess.callRemoteFunction(client -> client.resourcePoolGetAll());
                for (String res : resourceList) {
                    resourceSet.add(Resource.fromJson(res));
                }
                if (noteId != null) {
                    resourceSet = resourceSet.filterByNoteId(noteId);
                }
                if (paragraphId != null) {
                    resourceSet = resourceSet.filterByParagraphId(paragraphId);
                }
                for (final Resource r : resourceSet) {
                    remoteInterpreterProcess.callRemoteFunction(client -> {
                        client.resourceRemove(r.getResourceId().getNoteId(), r.getResourceId().getParagraphId(), r.getResourceId().getName());
                        return null;
                    });
                }
            } catch (Exception e) {
                LOGGER.error(e.getMessage());
            }
        }
    }
}
Also used : ZeppelinConfiguration(org.apache.zeppelin.conf.ZeppelinConfiguration) Arrays(java.util.Arrays) TypeToken(com.google.gson.reflect.TypeToken) RemoteInterpreterProcess(org.apache.zeppelin.interpreter.remote.RemoteInterpreterProcess) Resource(org.apache.zeppelin.resource.Resource) Proxy(org.eclipse.aether.repository.Proxy) URL(java.net.URL) LoggerFactory(org.slf4j.LoggerFactory) ResourcePool(org.apache.zeppelin.resource.ResourcePool) AuthenticationInfo(org.apache.zeppelin.user.AuthenticationInfo) StringUtils(org.apache.commons.lang3.StringUtils) GsonBuilder(com.google.gson.GsonBuilder) Metrics(io.micrometer.core.instrument.Metrics) ManagedAttribute(org.eclipse.jetty.util.annotation.ManagedAttribute) DirectoryStream(java.nio.file.DirectoryStream) URLClassLoader(java.net.URLClassLoader) Matcher(java.util.regex.Matcher) CLUSTER_INTP_SETTING_EVENT_TOPIC(org.apache.zeppelin.cluster.ClusterManagerServer.CLUSTER_INTP_SETTING_EVENT_TOPIC) Gson(com.google.gson.Gson) ConfVars(org.apache.zeppelin.conf.ZeppelinConfiguration.ConfVars) Job(org.apache.zeppelin.scheduler.Job) Map(java.util.Map) ClusterEvent(org.apache.zeppelin.cluster.event.ClusterEvent) Dependency(org.apache.zeppelin.dep.Dependency) ManagedObject(org.eclipse.jetty.util.annotation.ManagedObject) Path(java.nio.file.Path) Tags(io.micrometer.core.instrument.Tags) ReflectionUtils(org.apache.zeppelin.util.ReflectionUtils) Gauge(io.micrometer.core.instrument.Gauge) ImmutableMap(com.google.common.collect.ImmutableMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) ConfigStorage(org.apache.zeppelin.storage.ConfigStorage) Collectors(java.util.stream.Collectors) ClusterManagerServer(org.apache.zeppelin.cluster.ClusterManagerServer) RemoteAngularObjectRegistry(org.apache.zeppelin.interpreter.remote.RemoteAngularObjectRegistry) DependencyResolver(org.apache.zeppelin.dep.DependencyResolver) List(java.util.List) Type(java.lang.reflect.Type) Pattern(java.util.regex.Pattern) AngularObjectRegistry(org.apache.zeppelin.display.AngularObjectRegistry) RegisteredInterpreter(org.apache.zeppelin.interpreter.Interpreter.RegisteredInterpreter) RemoteInterpreterProcessListener(org.apache.zeppelin.interpreter.remote.RemoteInterpreterProcessListener) ClusterEventListener(org.apache.zeppelin.cluster.event.ClusterEventListener) ArrayUtils(org.apache.commons.lang3.ArrayUtils) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) Inject(javax.inject.Inject) ClusterMessage(org.apache.zeppelin.cluster.event.ClusterMessage) HashSet(java.util.HashSet) AngularObjectRegistryListener(org.apache.zeppelin.display.AngularObjectRegistryListener) LinkedList(java.util.LinkedList) NoteEventListener(org.apache.zeppelin.notebook.NoteEventListener) Paragraph(org.apache.zeppelin.notebook.Paragraph) ResourceSet(org.apache.zeppelin.resource.ResourceSet) Logger(org.slf4j.Logger) ApplicationEventListener(org.apache.zeppelin.helium.ApplicationEventListener) MalformedURLException(java.net.MalformedURLException) Files(java.nio.file.Files) ApplicationState(org.apache.zeppelin.notebook.ApplicationState) Note(org.apache.zeppelin.notebook.Note) Meter(io.micrometer.core.instrument.Meter) FileUtils(org.apache.commons.io.FileUtils) IOException(java.io.IOException) RecoveryStorage(org.apache.zeppelin.interpreter.recovery.RecoveryStorage) FileInputStream(java.io.FileInputStream) Notebook(org.apache.zeppelin.notebook.Notebook) InputStreamReader(java.io.InputStreamReader) File(java.io.File) ParagraphTextParser(org.apache.zeppelin.notebook.ParagraphTextParser) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) Authentication(org.eclipse.aether.repository.Authentication) Paths(java.nio.file.Paths) Preconditions(com.google.common.base.Preconditions) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Comparator(java.util.Comparator) Collections(java.util.Collections) InputStream(java.io.InputStream) Resource(org.apache.zeppelin.resource.Resource) RemoteInterpreterProcess(org.apache.zeppelin.interpreter.remote.RemoteInterpreterProcess) ResourcePool(org.apache.zeppelin.resource.ResourcePool) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) ResourceSet(org.apache.zeppelin.resource.ResourceSet) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException)

Example 14 with Resource

use of org.apache.zeppelin.resource.Resource in project zeppelin by apache.

the class RemoteInterpreterEventServer method getAllResources.

@Override
public List<String> getAllResources(String intpGroupId) throws InterpreterRPCException, TException {
    ResourceSet resourceSet = getAllResourcePoolExcept(intpGroupId);
    List<String> resourceList = new LinkedList<>();
    for (Resource r : resourceSet) {
        resourceList.add(r.toJson());
    }
    return resourceList;
}
Also used : Resource(org.apache.zeppelin.resource.Resource) RemoteResource(org.apache.zeppelin.resource.RemoteResource) ResourceSet(org.apache.zeppelin.resource.ResourceSet) LinkedList(java.util.LinkedList)

Example 15 with Resource

use of org.apache.zeppelin.resource.Resource in project zeppelin by apache.

the class MockInterpreterResourcePool method interpret.

@Override
public InterpreterResult interpret(String st, InterpreterContext context) {
    String[] stmt = st.split(" ");
    String cmd = stmt[0];
    String noteId = null;
    String paragraphId = null;
    String name = null;
    if (stmt.length >= 2) {
        String[] npn = stmt[1].split(":");
        if (npn.length >= 3) {
            noteId = npn[0];
            paragraphId = npn[1];
            name = npn[2];
        } else {
            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(noteId, paragraphId, name, value);
    } else if (cmd.equalsIgnoreCase("get")) {
        Resource resource = resourcePool.get(noteId, paragraphId, name);
        if (resource != null) {
            ret = resourcePool.get(noteId, paragraphId, name).get();
        } else {
            ret = "";
        }
    } else if (cmd.equals("remove")) {
        ret = resourcePool.remove(noteId, paragraphId, name);
    } else if (cmd.equals("getAll")) {
        ret = resourcePool.getAll();
    } else if (cmd.equals("invoke")) {
        Resource resource = resourcePool.get(noteId, paragraphId, name);
        LOGGER.info("Resource: " + resource);
        if (stmt.length >= 4) {
            Resource res = resource.invokeMethod(value, stmt[3]);
            LOGGER.info("After invokeMethod: " + resource);
            ret = res.get();
        } else {
            ret = resource.invokeMethod(value);
            LOGGER.info("After invokeMethod: " + ret);
        }
    }
    try {
        // wait for watcher executed
        Thread.sleep(500);
    } catch (InterruptedException e) {
    }
    Gson gson = new Gson();
    return new InterpreterResult(Code.SUCCESS, gson.toJson(ret));
}
Also used : Resource(org.apache.zeppelin.resource.Resource) Gson(com.google.gson.Gson) InterpreterResult(org.apache.zeppelin.interpreter.InterpreterResult) ResourcePool(org.apache.zeppelin.resource.ResourcePool)

Aggregations

Resource (org.apache.zeppelin.resource.Resource)23 ResourcePool (org.apache.zeppelin.resource.ResourcePool)11 Gson (com.google.gson.Gson)6 IOException (java.io.IOException)6 LinkedList (java.util.LinkedList)6 ResourceSet (org.apache.zeppelin.resource.ResourceSet)6 ZeppelinApi (org.apache.zeppelin.annotation.ZeppelinApi)5 ByteBuffer (java.nio.ByteBuffer)4 TException (org.apache.thrift.TException)4 AngularObject (org.apache.zeppelin.display.AngularObject)3 TypeToken (com.google.gson.reflect.TypeToken)2 File (java.io.File)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Matcher (java.util.regex.Matcher)2 TTransportException (org.apache.thrift.transport.TTransportException)2 InterpreterResult (org.apache.zeppelin.interpreter.InterpreterResult)2