Skip to content

Commit

Permalink
updated the endpointChooser so that it tries to find the right camel …
Browse files Browse the repository at this point in the history
…context that hosts the route/component you are completing on
  • Loading branch information
jstrachan committed Aug 21, 2013
1 parent 6c4fb08 commit adb18d8
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 1 deletion.
40 changes: 40 additions & 0 deletions hawtio-web/src/main/webapp/app/camel/js/endpointChooser.ts
Expand Up @@ -291,6 +291,45 @@ module Camel {
}

function findCamelContextMBean() {
// TODO we need to find the MBean for the CamelContext / Route we are editing!
var componentName = $scope.selectedComponentName;
var selectedCamelContextId = $scope.camelSelectionDetails.selectedCamelContextId;
var selectedRouteId = $scope.camelSelectionDetails.selectedRouteId;

console.log("==== componentName " + componentName +
" selectedCamelContextId: " + selectedCamelContextId +
" selectedRouteId: " + selectedRouteId);

var contextsById = Camel.camelContextMBeansById(workspace);
if (selectedCamelContextId) {
var mbean = Core.pathGet(contextsById, [selectedCamelContextId, "mbean"]);
if (mbean) {
return mbean;
}
}
if (selectedRouteId) {
var map = Camel.camelContextMBeansByRouteId(workspace);
var mbean = Core.pathGet(map, [selectedRouteId, "mbean"]);
if (mbean) {
return mbean;
}
}
if (componentName) {
var map = Camel.camelContextMBeansByComponentName(workspace);
var mbean = Core.pathGet(map, [componentName, "mbean"]);
if (mbean) {
return mbean;
}
}

// NOTE we don't really know which camel context to pick, so lets just find the first one?
var answer = null;
angular.forEach(contextsById, (id, details) => {
var mbean = details.mbean;
if (!answer && mbean) answer = mbean;
});
return answer;
/*
// we could be remote to lets query jolokia
var results = $scope.jolokia.search("org.apache.camel:*,type=context", onSuccess(null));
//var results = $scope.jolokia.search("org.apache.camel:*", onSuccess(null));
Expand All @@ -306,6 +345,7 @@ module Camel {
mbean = Core.pathGet(folder, ["objectName"]);
}
return mbean;
*/
}

function onJolokiaUrl(response) {
Expand Down
70 changes: 70 additions & 0 deletions hawtio-web/src/main/webapp/app/camel/js/helpers.ts
Expand Up @@ -991,4 +991,74 @@ module Camel {
}
return doc;
}

/**
* Returns an object of all the CamelContext MBeans keyed by their id
*/
export function camelContextMBeansById(workspace:Workspace) {
var answer = {};
var tree = workspace.tree;
if (tree) {
var camelTree = tree.navigate(Camel.jmxDomain);
angular.forEach(camelTree.children, (contextsFolder) => {
var contextFolder = contextsFolder.navigate("context");
if (contextFolder && contextFolder.children && contextFolder.children.length) {
var contextItem = contextFolder.children[0];
var id = Core.pathGet(contextItem, ["entries", "name"]) || contextItem.key;
if (id) {
answer[id] = {
folder: contextItem,
mbean: contextItem.objectName
}
}
}
});
}
return answer;
}


/**
* Returns an object of all the CamelContext MBeans keyed by the component name
*/
export function camelContextMBeansByComponentName(workspace:Workspace) {
return camelContextMBeansByRouteOrComponentId(workspace, "components")
}

/**
* Returns an object of all the CamelContext MBeans keyed by the route ID
*/
export function camelContextMBeansByRouteId(workspace:Workspace) {
return camelContextMBeansByRouteOrComponentId(workspace, "routes")
}

function camelContextMBeansByRouteOrComponentId(workspace:Workspace, componentsOrRoutes: string) {
var answer = {};
var tree = workspace.tree;
if (tree) {
var camelTree = tree.navigate(Camel.jmxDomain);
angular.forEach(camelTree.children, (contextsFolder) => {
var contextFolder = contextsFolder.navigate("context");
var componentsFolder = contextsFolder.navigate(componentsOrRoutes);
if (contextFolder && componentsFolder && contextFolder.children && contextFolder.children.length) {
var contextItem = contextFolder.children[0];
var mbean = contextItem.objectName;
if (mbean) {
var contextValues = {
folder: contextItem,
mbean: mbean
};
angular.forEach(componentsFolder.children, (componentFolder) => {
var id = componentFolder.title;
if (id) {
answer[id] = contextValues;
}
});
}
}
});
}
return answer;
}

}
4 changes: 4 additions & 0 deletions hawtio-web/src/main/webapp/app/wiki/js/camel.ts
Expand Up @@ -7,6 +7,10 @@ module Wiki {
$scope.modified = false;

$scope.findProfileCamelContext = true;
$scope.camelSelectionDetails = {
selectedCamelContextId: null,
selectedRouteId: null
};

$scope.isValid = (nav) => {
return nav && nav.isValid(workspace);
Expand Down
5 changes: 4 additions & 1 deletion hawtio-web/src/main/webapp/app/wiki/js/camelCanvas.ts
Expand Up @@ -214,7 +214,9 @@ module Wiki {

function reloadRouteIds() {
$scope.routeIds = [];
$($scope.doc).find("route").each((idx, route) => {
var doc = $($scope.doc);
$scope.camelSelectionDetails.selectedCamelContextId = doc.find("camelContext").attr("id");
doc.find("route").each((idx, route) => {
var id = route.getAttribute("id");
if (id) {
$scope.routeIds.push(id);
Expand All @@ -237,6 +239,7 @@ module Wiki {
showGraph(nodes, links);
$scope.drawnRouteId = $scope.selectedRouteId;
}
$scope.camelSelectionDetails.selectedRouteId = $scope.selectedRouteId;
}
}

Expand Down

0 comments on commit adb18d8

Please sign in to comment.