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;
}
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);
}
}
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;
}
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);
}
}
Aggregations