How to remove clustering from vis.js - cluster-analysis

I have clustering set on a vis.js network diagram. Adding nodes to cluster works. But I cannot remove a node from cluster. I believe the problem is that the first time the code below runs it creates a cluster, after I do some modification to the nodes (e.g. remove node from group) and I run it the second time it keeps the previous cluster and just adds the nodes (if any was added) but doesn't remove them (if any was removed).
So I think that removing all the cluster options and the applying it again should do the trick, but I cant find the way to achieve that.
const clusterOption = {
joinCondition: function (childOptions) {
return childOptions.cid === group.groupId;
},
clusterNodeProperties: {
id: group.groupId,
label: group.label,
shape: 'database',
allowSingleNodeCluster: true
}
};
this.network.cluster(clusterOption);
So my idea would be to do something along the following lines (in pseudocode) before calling the above code.
this.network.clearClusters();

Running this.network.cluster(clusterOption); again seems to work in my experiments (see http://jsfiddle.net/thomaash/t8q37Lsc/, though I adapted one of the examples since you didn't provide MWE). But this may be a bug. It seems to me that the cluster should be updated when the underlying nodes are updated. Do you plan to open an issue (https://github.com/visjs/vis-network/issues/new)?
PS: What version are you using? People sometimes miss an update and then try to solve issues that are resolved in newer versions.

function decluster() {
for (index of network.body.nodeIndices) {
if (network.isCluster(index) == true) {
network.openCluster(index);
}
}
}

The network instance has a "isCluster" method which takes a node index as a parameter, that you can invoke to identify if a given node is a cluster. Once you have identified that a given node is a cluster, you can then invoke the "openCluster" method on the same network instance with the node index.
Below is a code snippet for a Vue3 implementation.
unclusterNodes() {
for (const index of this.network.body.nodeIndices) {
if (this.network.isCluster(index) == true) {
this.network.openCluster(index);
}
}

Related

A question regarding resource allocation in Kubernetes

I'm trying to find out how kubernetes calculates the allocation of resources? Actually, I cannot find it in the source code.
In kubernetes official documentation, allocatable has been calculated as [Allocatable] = [Node Capacity] - [Kube-Reserved] - [System-Reserved] - [Hard-Eviction-Threshold]. Could you please help me to find the related source codes in kubernetes which is in github?
Actually, I would like to change the allocation policy in kubernetes and I need to find the related codes.
Cheers
There are a couple of options:
The scheduler uses the value of node.Status.Allocatable instead of node.Status.Capacity to decide if a node will become a candidate for pod scheduling. So one thing is to do custom stuff , is to bypass the schedular and specify your own schedular.
The second option is to change the values and options used by kubelet. details
You can set these in the kubeletArguments section of the node
configuration map by using a set of
= pairs (e.g.,
cpu=200m,memory=512Mi). Add the section if it does not already exist
Maybe the last option you are looking for is to change the code , the way things are calculated.
https://github.com/kubernetes/kubernetes/blob/05183bffe5cf690b418718aa107f5655e4ac0618/pkg/scheduler/nodeinfo/node_info.go
start from here:
// AllocatableResource returns allocatable resources on a given node.
func (n *NodeInfo) AllocatableResource() Resource {
if n == nil {
return emptyResource
}
return *n.allocatableResource
}
here is a portion of schedular that uses that info:
if allocatable.Memory < podRequest.Memory+nodeInfo.RequestedResource().Memory {
predicateFails = append(predicateFails, NewInsufficientResourceError(v1.ResourceMemory, podRequest.Memory, nodeInfo.RequestedResource().Memory, allocatable.Memory))
}
https://github.com/kubernetes/kubernetes/blob/788f24583e95ac47938a41daaf1f1efc58153738/pkg/scheduler/algorithm/predicates/predicates.go

Replacing the duplicate function for the 'unique' plugin

I am trying to write my own $.jstree.defaults.unique.duplicate function and replace it.
I tried doing so in the following jsFiddle (line: 68):
$.jstree.defaults.unique.duplicate = function(name, counter){
return name + "_test";
};
Steps to test:
Select Devices
Create Node called Node1
Create Another node under Devices called Node1
It will use the jstree default method to replace it with the default node name vs what my function provides
http://jsfiddle.net/2mbq86at/
Am I doing something wrong? Thanks in advance.
In your code you specify text to use in course of creating a new node.
Take out the pre-defined text and things will start to work as desired for your function $.jstree.defaults.unique.duplicate !
self.createFileNode = function (data) {
//Below code only allows files to be created within folders.
//Structure it as per createFolder method to create files at root
var data = {
//'id': 'tempId',
//'text': 'iOS 8'
}
....
In that case of course a new node's text will be the default 'New node'.
The best is to set a unique node name right upfront on creating a new node, like "text" : "OS_" + (new Date).getTime().
Still for the case of renaming nodes and duplicates: using the unique plugin, on renaming and choosing a duplicate text the node's text will fall back to the original one. If that is not what is desired, things get more complicated as the rename_node.jstree event will not be fired in that case.

Meteor.subscribe on server side

I want to create a backend service which monitors a mongodb collection for new entries. As those are being created, I wish to run processing and update them.
I thought doing so with a Meteor service/app would be a wise idea because Meteor uses 'oplog tailing' which seems ideal for this purpose (I'd rather avoid polling if possible).
As such, I figured creating a minimal server-side-only app should solve it.
So basically, I need something along these lines:
if (Meteor.isServer) {
MyCollection = new Mongo.Collection('myCollection');
Meteor.publish('myCollectionPub', function () {
return MyCollection.find({ some: criteria... });
}
// is there such a thing?
Meteor.serverSideSubscribe('MyCollectionPub',
function (newDocs) {
// process/update newDocs
});
}
According to the Meteor docs, I cannot use Meteor.subscribe() on the server (and indeed it crashes if I try).
Question is:
Are there ways of 'subscribing' to collection updates on the server?
The PeerLibrary server-autorun package (along with it's dependant, reactive-mongo) will provide you with easy server-side observation of collections.
An alternative to #tarmes suggestion is the collection-hooks package, however as pointed out by David Weldon, it will only trigger in instance it is run in:
https://github.com/matb33/meteor-collection-hooks
MyCollection.after.insert(function (userId, doc) {
// ...
});
If you need it to run even when another instance makes a change in the mongo database, you can observe a cursor that is returned from your collection:
MyCollection.find({created_at : {$gt: some_current_time}}).observe({
added: function(item) {
// Alert code
}
});

Deleting a property in AEM 5

I am trying to delete a property of a node. I could manually do it in the crx explorer but there is just way to many properties that I need to delete. Below is the sample code that is currently working. However just changing its value will not solve what I am trying to accomplish. Therefore my question is:
How can I delete a property of a node?
void deleteJob(Node node, Session jcr) throws RepositoryException {
Node jobDescNode = (Node)jcr.getItem(node.getPath() + "/jcr:content/contentpar/jobsdescription");
if(jobDescNode.hasProperty("foo")) {
jobDescNode.setProperty("foo", "null");
jcr.save();
}
}
It looks like you are setting the value of the property to "null" instead of removing the property.
Use
jobDescNode.setProperty("foo", (String)null);
Check the Node API for more info.

CQ5 / AEM5.6 Workflow: Access workflow instance properties from inside OR Split

TL;DR version:
In CQ workflows, is there a difference between what's available to the OR Split compared to the Process Step?
Is it possible to access the /history/ nodes of a workflow instance from within an OR Split?
How?!
The whole story:
I'm working on a workflow in CQ5 / AEM5.6.
In this workflow I have a custom dialog, which stores a couple of properties on the workflow instance.
The path to the property I'm having trouble with is: /workflow/instances/[this instance]/history/[workItem id]/workItem/metaData and I've called the property "reject-or-approve".
The dialog sets the property fine (via a dropdown that lets you set it to "reject" or "approve"), and I can access other properties on this node via a process step (in ecma script) using:
var actionReason;
var history = workflowSession.getHistory(workItem.getWorkflow());
// loop backwards through workItems
// and as soon as we find a Action Reason that is not empty
// store that as 'actionReason' and break.
for (var index = history.size() - 1; index >= 0; index--) {
var previous = history.get(index);
var tempActionReason = previous.getWorkItem().getMetaDataMap().get('action-message');
if ((tempActionReason != '')&&(tempActionReason != null)) {
actionReason = tempActionReason;
break;
}
}
The process step is not the problem though. Where I'm having trouble is when I try to do the same thing from inside an OR Split.
When I try the same workflowSession.getHistory(workItem.getWorkflow()) in an OR Split, it throws an error saying workItem is not defined.
I've tried storing this property on the payload instead (i.e. storing it under the page's jcr:content), and in that case the property does seem to be available to the OR Split, but my problems with that are:
This reject-or-approve property is only relevant to the current workflow instance, so storing it on the page's jcr:content doesn't really make sense. jcr:content properties will persist after the workflow is closed, and will be accessible to future workflow instances. I could work around this (i.e. don't let workflows do anything based on the property unless I'm sure this instance has written to the property already), but this doesn't feel right and is probably error-prone.
For some reason, when running through the custom dialog in my workflow, only the Admin user group seems to be able to write to the jcr:content property. When I use the dialog as any other user group (which I need to do for this workflow design), the dialog looks as though it's working, but never actually writes to the jcr:content property.
So for a couple of different reasons I'd rather keep this property local to the workflow instance instead of storing it on the page's jcr:content -- however, if anyone can think of a reason why my dialog isn't setting the property on the jcr:content when I use any group other than admin, that would give me a workaround even if it's not exactly the solution I'm looking for.
Thanks in advance if anyone can help! I know this is kind of obscure, but I've been stuck on it for ages.
a couple of days ago i ran into the same issue. The issue here is that you don't have the workItem object, because you don't really have an existing workItem. Imagine the following: you are going through the workflow, you got a couple of workItems, with means, either process step, either inbox item. When you are in an or split, you don't have existing workItems, you can ensure by visiting the /workItems node of the workflow instance. Your workaround seems to be the only way to go through this "issue".
I've solved it. It's not all that elegant looking, but it seems to be a pretty solid solution.
Here's some background:
Dialogs seem to reliably let you store properties either on:
the payload's jcr:content node (which wasn't practical for me, because the payload is locked during the workflow, and doesn't let non-admins write to its jcr:content)
the workItem/metaData for the current workflow step
However, Split steps don't have access to workItem. I found a fairly un-helpful confirmation of that here: http://blogs.adobe.com/dmcmahon/2013/03/26/cq5-failure-running-script-etcworkflowscriptscaworkitem-ecma-referenceerror-workitem-is-not-defined/
So basically the issue was, the Dialog step could store the property, but the OR Split couldn't access it.
My workaround was to add a Process step straight after the Dialog in my workflow. Process steps do have access to workItem, so they can read the property set by the Dialog. I never particularly wanted to store this data on the payload's jcr:content, so I looked for another location. It turns out the workflow metaData (at the top level of the workflow instance node, rather than workItem/metaData, which is inside the /history sub-node) is accessible to both the Process step and the OR Split. So, my Process step now reads the workItem's approveReject property (set by the Dialog), and then writes it to the workflow's metaData node. Then, the OR Split reads the property from its new location, and does its magic.
The way you access the workflow metaData from the Process step and the OR Split is not consistent, but you can get there from both.
Here's some code: (complete with comments. You're welcome)
In the dialog where you choose to approve or reject, the name of the field is set to rejectApprove. There's no ./ or anything before it. This tells it to store the property on the workItem/metaData node for the current workflow step under /history/.
Straight after the dialog, a Process step runs this:
var rejectApprove;
var history = workflowSession.getHistory(workItem.getWorkflow());
// loop backwards through workItems
// and as soon as we find a rejectApprove that is not empty
// store that as 'rejectApprove' and break.
for (var index = history.size() - 1; index >= 0; index--) {
var previous = history.get(index);
var tempRejectApprove = previous.getWorkItem().getMetaDataMap().get('rejectApprove');
if ((tempRejectApprove != '')&&(tempRejectApprove != null)) {
rejectApprove = tempRejectApprove;
break;
}
}
// steps up from the workflow step into the workflow metaData,
// and stores the rejectApprove property there
// (where it can be accessed by an OR Split)
workItem.getWorkflowData().getMetaData().put('rejectApprove', rejectApprove);
Then after the Process step, the OR Split has the following in its tabs:
function check() {
var match = 'approve';
if (workflowData.getMetaData().get('rejectApprove') == match) {
return true;
} else {
return false;
}
}
Note: use this for the tab for the "approve" path, then copy it and replace var match = 'approve' with var match = 'reject'
So the key here is that from a Process step:
workItem.getWorkflowData().getMetaData().put('rejectApprove', rejectApprove);
writes to the same property that:
workflowData.getMetaData().get('rejectApprove') reads from when you execute it in an OR Split.
To suit our business requirements, there's more to the workflow I've implemented than just this, but the method above seems to be a pretty reliable way to get values that are entered in a dialog, and access them from within an OR Split.
It seems pretty silly that the OR Split can't access the workItem directly, and I'd be interested to know if there's a less roundabout way of doing this, but for now this has solved my problem.
I really hope someone else has this same problem, and finds this useful, because it took me waaay to long to figure out, to only apply it once!