use of org.apache.zeppelin.display.AngularObject in project zeppelin by apache.
the class Note method deleteAngularObject.
/**
* Delete the note AngularObject.
*/
public void deleteAngularObject(String intpGroupId, String noteId, String paragraphId, String name) {
if (angularObjects.containsKey(intpGroupId)) {
// Delete existing AngularObject
Iterator<AngularObject> iter = angularObjects.get(intpGroupId).iterator();
while (iter.hasNext()) {
String noteIdCandidate = "";
String paragraphIdCandidate = "";
String nameCandidate = "";
Object object = iter.next();
if (object instanceof AngularObject) {
AngularObject ao = (AngularObject) object;
noteIdCandidate = ao.getNoteId();
paragraphIdCandidate = ao.getParagraphId();
nameCandidate = ao.getName();
} else if (object instanceof RemoteAngularObject) {
RemoteAngularObject rao = (RemoteAngularObject) object;
noteIdCandidate = rao.getNoteId();
paragraphIdCandidate = rao.getParagraphId();
nameCandidate = rao.getName();
} else {
continue;
}
if (StringUtils.equals(noteId, noteIdCandidate) && StringUtils.equals(paragraphId, paragraphIdCandidate) && StringUtils.equals(name, nameCandidate)) {
iter.remove();
}
}
}
}
use of org.apache.zeppelin.display.AngularObject in project zeppelin by apache.
the class Notebook method loadNoteFromRepo.
@SuppressWarnings("rawtypes")
public Note loadNoteFromRepo(String id, AuthenticationInfo subject) {
Note note = null;
try {
// note can be safely returned here, because it's just broadcasted in json later on
note = processNote(id, n -> n);
} catch (IOException e) {
LOGGER.error("Fail to get note: {}", id, e);
return null;
}
if (note == null) {
return null;
}
// Manually inject ALL dependencies, as DI constructor was NOT used
note.setCredentials(this.credentials);
note.setInterpreterFactory(replFactory);
note.setInterpreterSettingManager(interpreterSettingManager);
note.setParagraphJobListener(this.paragraphJobListener);
note.setCronSupported(getConf());
if (note.getDefaultInterpreterGroup() == null) {
note.setDefaultInterpreterGroup(conf.getString(ConfVars.ZEPPELIN_INTERPRETER_GROUP_DEFAULT));
}
Map<String, SnapshotAngularObject> angularObjectSnapshot = new HashMap<>();
// restore angular object --------------
Date lastUpdatedDate = new Date(0);
for (Paragraph p : note.getParagraphs()) {
p.setNote(note);
if (p.getDateFinished() != null && lastUpdatedDate.before(p.getDateFinished())) {
lastUpdatedDate = p.getDateFinished();
}
}
Map<String, List<AngularObject>> savedObjects = note.getAngularObjects();
if (savedObjects != null) {
for (Entry<String, List<AngularObject>> intpGroupNameEntry : savedObjects.entrySet()) {
String intpGroupName = intpGroupNameEntry.getKey();
List<AngularObject> objectList = intpGroupNameEntry.getValue();
for (AngularObject object : objectList) {
SnapshotAngularObject snapshot = angularObjectSnapshot.get(object.getName());
if (snapshot == null || snapshot.getLastUpdate().before(lastUpdatedDate)) {
angularObjectSnapshot.put(object.getName(), new SnapshotAngularObject(intpGroupName, object, lastUpdatedDate));
}
}
}
}
note.setNoteEventListeners(this.noteEventListeners);
for (Entry<String, SnapshotAngularObject> angularObjectSnapshotEntry : angularObjectSnapshot.entrySet()) {
String name = angularObjectSnapshotEntry.getKey();
SnapshotAngularObject snapshot = angularObjectSnapshotEntry.getValue();
List<InterpreterSetting> settings = interpreterSettingManager.get();
for (InterpreterSetting setting : settings) {
InterpreterGroup intpGroup = setting.getInterpreterGroup(note.getExecutionContext());
if (intpGroup != null && intpGroup.getId().equals(snapshot.getIntpGroupId())) {
AngularObjectRegistry registry = intpGroup.getAngularObjectRegistry();
String noteId = snapshot.getAngularObject().getNoteId();
String paragraphId = snapshot.getAngularObject().getParagraphId();
// at this point, remote interpreter process is not created.
// so does not make sense add it to the remote.
//
// therefore instead of addAndNotifyRemoteProcess(), need to use add()
// that results add angularObject only in ZeppelinServer side not remoteProcessSide
registry.add(name, snapshot.getAngularObject().get(), noteId, paragraphId);
}
}
}
return note;
}
use of org.apache.zeppelin.display.AngularObject in project zeppelin by apache.
the class Paragraph method extractVariablesFromAngularRegistry.
String extractVariablesFromAngularRegistry(String scriptBody, Map<String, Input> inputs, AngularObjectRegistry angularRegistry) {
final String noteId = this.getNote().getId();
final String paragraphId = this.getId();
final Set<String> keys = new HashSet<>(inputs.keySet());
for (String varName : keys) {
final AngularObject paragraphScoped = angularRegistry.get(varName, noteId, paragraphId);
final AngularObject noteScoped = angularRegistry.get(varName, noteId, null);
final AngularObject angularObject = paragraphScoped != null ? paragraphScoped : noteScoped;
if (angularObject != null) {
inputs.remove(varName);
final String pattern = "[$][{]\\s*" + varName + "\\s*(?:=[^}]+)?[}]";
scriptBody = scriptBody.replaceAll(pattern, angularObject.get().toString());
}
}
return scriptBody;
}
use of org.apache.zeppelin.display.AngularObject in project zeppelin by apache.
the class Note method addOrUpdateAngularObject.
/**
* Add or update the note AngularObject.
*/
public void addOrUpdateAngularObject(String intpGroupId, AngularObject angularObject) {
List<AngularObject> angularObjectList;
if (!angularObjects.containsKey(intpGroupId)) {
angularObjectList = new ArrayList<>();
angularObjects.put(intpGroupId, angularObjectList);
} else {
angularObjectList = angularObjects.get(intpGroupId);
// Delete existing AngularObject
Iterator<AngularObject> iter = angularObjectList.iterator();
while (iter.hasNext()) {
String noteId = "";
String paragraphId = "";
String name = "";
Object object = iter.next();
if (object instanceof AngularObject) {
AngularObject ao = (AngularObject) object;
noteId = ao.getNoteId();
paragraphId = ao.getParagraphId();
name = ao.getName();
} else if (object instanceof RemoteAngularObject) {
RemoteAngularObject rao = (RemoteAngularObject) object;
noteId = rao.getNoteId();
paragraphId = rao.getParagraphId();
name = rao.getName();
} else {
continue;
}
if (StringUtils.equals(noteId, angularObject.getNoteId()) && StringUtils.equals(paragraphId, angularObject.getParagraphId()) && StringUtils.equals(name, angularObject.getName())) {
iter.remove();
}
}
}
angularObjectList.add(angularObject);
}
use of org.apache.zeppelin.display.AngularObject in project SSM by Intel-bigdata.
the class RemoteInterpreter method pushAngularObjectRegistryToRemote.
/**
* Push local angular object registry to
* remote interpreter. This method should be
* call ONLY inside the init() method
*/
void pushAngularObjectRegistryToRemote(Client client) throws TException {
final AngularObjectRegistry angularObjectRegistry = this.getInterpreterGroup().getAngularObjectRegistry();
if (angularObjectRegistry != null && angularObjectRegistry.getRegistry() != null) {
final Map<String, Map<String, AngularObject>> registry = angularObjectRegistry.getRegistry();
logger.info("Push local angular object registry from ZeppelinServer to" + " remote interpreter group {}", this.getInterpreterGroup().getId());
final java.lang.reflect.Type registryType = new TypeToken<Map<String, Map<String, AngularObject>>>() {
}.getType();
Gson gson = new Gson();
client.angularRegistryPush(gson.toJson(registry, registryType));
}
}
Aggregations