Search in sources :

Example 16 with ResourcePool

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

the class ZeppelinContext method get.

/**
   * Get object from resource pool
   * Search local process first and then the other processes
   * @param name
   * @return null if resource not found
   */
@ZeppelinApi
public Object get(String name) {
    ResourcePool resourcePool = interpreterContext.getResourcePool();
    Resource resource = resourcePool.get(name);
    if (resource != null) {
        return resource.get();
    } else {
        return null;
    }
}
Also used : Resource(org.apache.zeppelin.resource.Resource) ResourcePool(org.apache.zeppelin.resource.ResourcePool) ZeppelinApi(org.apache.zeppelin.annotation.ZeppelinApi)

Example 17 with ResourcePool

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

the class RemoteInterpreterEventPoller method getAllResourcePoolExcept.

private ResourceSet getAllResourcePoolExcept() {
    ResourceSet resourceSet = new ResourceSet();
    for (InterpreterGroup intpGroup : InterpreterGroup.getAll()) {
        if (intpGroup.getId().equals(interpreterGroup.getId())) {
            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<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;
}
Also used : InterpreterGroup(org.apache.zeppelin.interpreter.InterpreterGroup) Gson(com.google.gson.Gson) ResourcePool(org.apache.zeppelin.resource.ResourcePool) LinkedList(java.util.LinkedList) List(java.util.List) ResourceSet(org.apache.zeppelin.resource.ResourceSet) Client(org.apache.zeppelin.interpreter.thrift.RemoteInterpreterService.Client) TException(org.apache.thrift.TException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 18 with ResourcePool

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

the class RemoteInterpreterEventPoller method getResource.

private Object getResource(ResourceId resourceId) {
    InterpreterGroup intpGroup = InterpreterGroup.getByInterpreterGroupId(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.getNoteId(), resourceId.getParagraphId(), 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;
}
Also used : InterpreterGroup(org.apache.zeppelin.interpreter.InterpreterGroup) ResourcePool(org.apache.zeppelin.resource.ResourcePool) AngularObject(org.apache.zeppelin.display.AngularObject) Client(org.apache.zeppelin.interpreter.thrift.RemoteInterpreterService.Client) ByteBuffer(java.nio.ByteBuffer) TException(org.apache.thrift.TException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 19 with ResourcePool

use of org.apache.zeppelin.resource.ResourcePool 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 20 with ResourcePool

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

the class Paragraph method getInterpreterContext.

private InterpreterContext getInterpreterContext() {
    AngularObjectRegistry registry = null;
    ResourcePool resourcePool = null;
    String replName = null;
    if (this.interpreter != null) {
        registry = this.interpreter.getInterpreterGroup().getAngularObjectRegistry();
        resourcePool = this.interpreter.getInterpreterGroup().getResourcePool();
        InterpreterSetting interpreterSetting = ((ManagedInterpreterGroup) interpreter.getInterpreterGroup()).getInterpreterSetting();
        replName = interpreterSetting.getName();
    }
    Credentials credentials = note.getCredentials();
    if (subject != null) {
        UserCredentials userCredentials;
        try {
            userCredentials = credentials.getUserCredentials(subject.getUser());
        } catch (IOException e) {
            LOGGER.warn("Unable to get Usercredentials. Working with empty UserCredentials", e);
            userCredentials = new UserCredentials();
        }
        subject.setUserCredentials(userCredentials);
    }
    return InterpreterContext.builder().setNoteId(note.getId()).setNoteName(note.getName()).setParagraphId(getId()).setReplName(replName).setParagraphTitle(title).setParagraphText(text).setAuthenticationInfo(subject).setLocalProperties(localProperties).setConfig(config).setGUI(settings).setNoteGUI(getNoteGui()).setAngularObjectRegistry(registry).setResourcePool(resourcePool).build();
}
Also used : InterpreterSetting(org.apache.zeppelin.interpreter.InterpreterSetting) ResourcePool(org.apache.zeppelin.resource.ResourcePool) UserCredentials(org.apache.zeppelin.user.UserCredentials) IOException(java.io.IOException) AngularObjectRegistry(org.apache.zeppelin.display.AngularObjectRegistry) UserCredentials(org.apache.zeppelin.user.UserCredentials) Credentials(org.apache.zeppelin.user.Credentials) ManagedInterpreterGroup(org.apache.zeppelin.interpreter.ManagedInterpreterGroup)

Aggregations

ResourcePool (org.apache.zeppelin.resource.ResourcePool)27 Resource (org.apache.zeppelin.resource.Resource)11 ZeppelinApi (org.apache.zeppelin.annotation.ZeppelinApi)9 Gson (com.google.gson.Gson)6 TException (org.apache.thrift.TException)6 AngularObjectRegistry (org.apache.zeppelin.display.AngularObjectRegistry)6 ResourceSet (org.apache.zeppelin.resource.ResourceSet)6 InterpreterGroup (org.apache.zeppelin.interpreter.InterpreterGroup)5 Client (org.apache.zeppelin.interpreter.thrift.RemoteInterpreterService.Client)5 ByteBuffer (java.nio.ByteBuffer)4 LinkedList (java.util.LinkedList)4 List (java.util.List)4 AngularObject (org.apache.zeppelin.display.AngularObject)4 Credentials (org.apache.zeppelin.user.Credentials)4 UserCredentials (org.apache.zeppelin.user.UserCredentials)4 IOException (java.io.IOException)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 TypeToken (com.google.gson.reflect.TypeToken)2 File (java.io.File)2 ArrayList (java.util.ArrayList)2