Search in sources :

Example 1 with Instance

use of org.apache.zeppelin.notebook.repo.zeppelinhub.model.Instance in project zeppelin by apache.

the class ZeppelinHubRepo method getSettings.

@Override
public List<NotebookRepoSettingsInfo> getSettings(AuthenticationInfo subject) {
    if (!isSubjectValid(subject)) {
        return Collections.emptyList();
    }
    List<NotebookRepoSettingsInfo> settings = Lists.newArrayList();
    String user = subject.getUser();
    String zeppelinHubUserSession = UserSessionContainer.instance.getSession(user);
    String userToken = getUserToken(user);
    List<Instance> instances;
    List<Map<String, String>> values = Lists.newLinkedList();
    try {
        instances = getUserInstances(zeppelinHubUserSession);
    } catch (IOException e) {
        LOG.warn("Couldnt find instances for the session {}, returning empty collection", zeppelinHubUserSession);
        // user not logged
        //TODO(xxx): handle this case.
        instances = Collections.emptyList();
    }
    NotebookRepoSettingsInfo repoSetting = NotebookRepoSettingsInfo.newInstance();
    repoSetting.type = NotebookRepoSettingsInfo.Type.DROPDOWN;
    for (Instance instance : instances) {
        if (instance.token.equals(userToken)) {
            repoSetting.selected = Integer.toString(instance.id);
        }
        values.add(ImmutableMap.of("name", instance.name, "value", Integer.toString(instance.id)));
    }
    repoSetting.value = values;
    repoSetting.name = "Instance";
    settings.add(repoSetting);
    return settings;
}
Also used : Instance(org.apache.zeppelin.notebook.repo.zeppelinhub.model.Instance) IOException(java.io.IOException) NotebookRepoSettingsInfo(org.apache.zeppelin.notebook.repo.NotebookRepoSettingsInfo) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 2 with Instance

use of org.apache.zeppelin.notebook.repo.zeppelinhub.model.Instance in project zeppelin by apache.

the class ZeppelinHubRepo method changeToken.

private void changeToken(int instanceId, String user) {
    if (instanceId <= 0) {
        LOG.error("User {} tried to switch to a non valid instance {}", user, instanceId);
        return;
    }
    LOG.info("User {} will switch instance", user);
    String ticket = UserSessionContainer.instance.getSession(user);
    List<Instance> instances;
    try {
        instances = getUserInstances(ticket);
        if (instances.isEmpty()) {
            return;
        }
        for (Instance instance : instances) {
            if (instance.id == instanceId) {
                LOG.info("User {} switched to instance {}", user, instances.get(0).name);
                usersToken.put(user, instance.token);
                break;
            }
        }
    } catch (IOException e) {
        LOG.error("Cannot switch instance for user {}", user, e);
    }
}
Also used : Instance(org.apache.zeppelin.notebook.repo.zeppelinhub.model.Instance) IOException(java.io.IOException)

Example 3 with Instance

use of org.apache.zeppelin.notebook.repo.zeppelinhub.model.Instance in project SSM by Intel-bigdata.

the class ZeppelinHubRepo method getSettings.

@Override
public List<NotebookRepoSettingsInfo> getSettings(AuthenticationInfo subject) {
    if (!isSubjectValid(subject)) {
        return Collections.emptyList();
    }
    List<NotebookRepoSettingsInfo> settings = Lists.newArrayList();
    String user = subject.getUser();
    String zeppelinHubUserSession = UserSessionContainer.instance.getSession(user);
    String userToken = getUserToken(user);
    List<Instance> instances;
    List<Map<String, String>> values = Lists.newLinkedList();
    try {
        instances = tokenManager.getUserInstances(zeppelinHubUserSession);
    } catch (IOException e) {
        LOG.warn("Couldnt find instances for the session {}, returning empty collection", zeppelinHubUserSession);
        // user not logged
        // TODO(xxx): handle this case.
        instances = Collections.emptyList();
    }
    NotebookRepoSettingsInfo repoSetting = NotebookRepoSettingsInfo.newInstance();
    repoSetting.type = NotebookRepoSettingsInfo.Type.DROPDOWN;
    for (Instance instance : instances) {
        if (instance.token.equals(userToken)) {
            repoSetting.selected = Integer.toString(instance.id);
        }
        values.add(ImmutableMap.of("name", instance.name, "value", Integer.toString(instance.id)));
    }
    repoSetting.value = values;
    repoSetting.name = "Instance";
    settings.add(repoSetting);
    return settings;
}
Also used : Instance(org.apache.zeppelin.notebook.repo.zeppelinhub.model.Instance) IOException(java.io.IOException) NotebookRepoSettingsInfo(org.apache.zeppelin.notebook.repo.NotebookRepoSettingsInfo) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 4 with Instance

use of org.apache.zeppelin.notebook.repo.zeppelinhub.model.Instance in project SSM by Intel-bigdata.

the class ZeppelinHubRepo method changeToken.

private void changeToken(int instanceId, String user) {
    if (instanceId <= 0) {
        LOG.error("User {} tried to switch to a non valid instance {}", user, instanceId);
        return;
    }
    LOG.info("User {} will switch instance", user);
    String ticket = UserSessionContainer.instance.getSession(user);
    List<Instance> instances;
    String currentToken = StringUtils.EMPTY, targetToken = StringUtils.EMPTY;
    try {
        instances = tokenManager.getUserInstances(ticket);
        if (instances.isEmpty()) {
            return;
        }
        currentToken = tokenManager.getExistingUserToken(user);
        for (Instance instance : instances) {
            if (instance.id == instanceId) {
                LOG.info("User {} switched to instance {}", user, instance.name);
                tokenManager.setUserToken(user, instance.token);
                targetToken = instance.token;
                break;
            }
        }
        if (!StringUtils.isBlank(currentToken) && !StringUtils.isBlank(targetToken)) {
            ZeppelinhubUtils.userSwitchTokenRoutine(user, currentToken, targetToken);
        }
    } catch (IOException e) {
        LOG.error("Cannot switch instance for user {}", user, e);
    }
}
Also used : Instance(org.apache.zeppelin.notebook.repo.zeppelinhub.model.Instance) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)4 Instance (org.apache.zeppelin.notebook.repo.zeppelinhub.model.Instance)4 ImmutableMap (com.google.common.collect.ImmutableMap)2 Map (java.util.Map)2 NotebookRepoSettingsInfo (org.apache.zeppelin.notebook.repo.NotebookRepoSettingsInfo)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1