Skip to content

Commit

Permalink
Adding initial spike of Apollo plugin.
Browse files Browse the repository at this point in the history
  • Loading branch information
chirino committed Jun 13, 2013
1 parent 59ace59 commit 51b8058
Show file tree
Hide file tree
Showing 5 changed files with 206 additions and 0 deletions.
24 changes: 24 additions & 0 deletions hawtio-web/src/main/webapp/app/apollo/html/layout-apollo.html
@@ -0,0 +1,24 @@
<div ng-controller="Apollo.ApolloController">
<div class="row-fluid">
<div id="content-holder" class="row"></div>
<div>
<div class="span12" ng-controller="Core.NavBarController">
<ul class="nav nav-tabs">
<li ng-class='{active : isActive("#/apollo/virtual-hosts")}'>
<a ng-href="{{link('#/apollo/virtual-hosts')}}">Virtual Hosts</a>
</li>
<li ng-class='{active : isActive("#/apollo/connectors")}'>
<a ng-href="{{link('#/apollo/connectors')}}">Connectors</a>
</li>
<li ng-class='{active : isActive("#/apollo/operating-environment")}'>
<a ng-href="{{link('#/apollo/operating-environment')}}">Operating Environment</a>
</li>
<li ng-class='{active : isActive("#/apollo/configuration")}'>
<a ng-href="{{link('#/apollo/configuration')}}">Configuration</a>
</li>
</ul>
<ng-include ng-if='isActive("#/apollo/virtual-hosts")' src="'app/apollo/html/virtual_hosts.html'"></ng-include>
</div>
</div>
</div>
</div>
62 changes: 62 additions & 0 deletions hawtio-web/src/main/webapp/app/apollo/html/virtual_hosts.html
@@ -0,0 +1,62 @@
<div class="tab-pane active">
<div class="form-horizontal">
<div class="control-group">
<label class="control-label"><strong style="font-size:170%">Virtual Host:</strong></label>
<div class="controls">
<select ng-model="apollo.selected_virtual_host" ng-options="v for v in broker.virtual_hosts">
</select>
<!-- <a class="btn" href="#"><i class="icon-stop icon-white"></i> Stop</a> -->
</div>
</div>
</div>
<div ng-controller="Apollo.VirtualHostController"
ng-init="init(apollo.selected_virtual_host)"
ng-if='apollo.selected_virtual_host'
class="row-fluid">

<div class="span4">
<div class="well" style="padding: 8px 8px">
<div class="well-title">Details</div>
<table class="details table table-bordered table-striped">
<tbody>
<tr><td><strong>Up Since: </strong>{{virtual_host.state_since}}</td></tr>
<tr><td><strong>Host Names: </strong>
<ul>
<li ng:repeat="name in virtual_host.host_names">{{name}}</li>
</ul>
</td></tr>
</tbody>
</table>
</div>

<div ng-if='virtual_host.store' class="well" style="padding: 8px 8px">
<div class="well-title">
<a>
<i class="icon-caret-right"></i>
</a>
Store Status
</div>
</div>

</div>
<div class="span8">
<ul class="nav nav-tabs"><li class="active"><a href="#">Queues</a></li><li><a href="#">Topics</a></li><li><a href="#">Durable Subs</a></li></ul>
<div>


<div class="well center">
<form action="" class="nomargin form-inline">
<strong>Name: </strong>
<input placeholder="name" type="text" value="">
<input type="submit" value="Create" class="btn btn-primary">
</form>
</div>



<div style="padding-left:2em;">No Queues have been created yet.</div>

</div>
</div>
</div>
</div>
90 changes: 90 additions & 0 deletions hawtio-web/src/main/webapp/app/apollo/js/apollo.ts
@@ -0,0 +1,90 @@
module Apollo {
export function ApolloController($scope, $http, $location, localStorage, workspace:Workspace) {
var jolokia = workspace.jolokia;
$scope.broker = {}
$scope.online = true

$scope.apollo = {
version:jolokia.getAttribute('org.apache.apollo:type=broker,name="default"', "Version", onSuccess(null)),
url: jolokia.getAttribute('org.apache.apollo:type=broker,name="default"', "WebAdminUrl", onSuccess(null)),
};

var default_error_handler = function(data, status, headers, config) {
if( status === 401 ) {
alert("Action not authorized.")
} else {
alert("Error: "+status)
}
}

$scope.ajax = function(type, path, success, error, data, binary_options) {
if( !error ) {
error = default_error_handler;
}
var username = "admin"
var password = "password"
var ajax_options = {
method: type,
url: $scope.apollo.url+"/api/json"+path,
headers: {
AuthPrompt:'false' ,
Accept: "application/json",
ContentType: "application/json",
Authorization: "Basic " + btoa(username + ':' + password),
},
cache:false,
data:null,
}
if( binary_options ) {
ajax_options.headers["Accept"] = binary_options.Accept || "application/octet-stream"
ajax_options.headers["ContentType"] || "application/octet-stream"
ajax_options.data = binary_options.data
}

return $http(ajax_options).
success((data, status, headers, config) =>{
$scope.online = true
if( success ) {
success(data, status, headers, config)
}
}).
error((data, status, headers, config) => {
if( status === 0 ) {
$scope.online = false
} else {
$scope.online = true
error(data, status, headers, config)
}
});
};

var reload = ()=>{
if( $scope.apollo.url ) {
$scope.ajax("GET", "/broker", (broker)=>{
$scope.broker = broker;
if( $scope.apollo.selected_virtual_host === undefined ) {
$scope.apollo.selected_virtual_host = broker.virtual_hosts[0]
}
}, (error)=>{
alert("fail:"+error)
});
} else {
$scope.broker = {}
}
};

var schedule_refresh = ()=>{};
schedule_refresh = ()=> {
setTimeout(()=> {
reload();
schedule_refresh();
}, 1000);
};
schedule_refresh();

$scope.$watch('apollo.url', reload);
$scope.$watch('online', ()=>{
// alert("online: "+$scope.online)
});
}
}
20 changes: 20 additions & 0 deletions hawtio-web/src/main/webapp/app/apollo/js/apolloPlugin.ts
@@ -0,0 +1,20 @@
module Apollo {
var pluginName = 'apollo';
angular.
module(pluginName, ['bootstrap', 'ngResource', 'hawtioCore']).
config(($routeProvider) => {
$routeProvider.
when('/apollo/*part', {templateUrl: 'app/apollo/html/layout-apollo.html'})
}).
run(($location: ng.ILocationService, workspace:Workspace, viewRegistry) => {
viewRegistry['apollo'] = "app/apollo/html/layout-apollo.html";
workspace.topLevelTabs.push( {
content: "Apollo",
title: "Manage your Apollo Broker",
isValid: (workspace) => workspace.treeContainsDomainAndProperties("org.apache.apollo"),
href: () => '#/apollo',
isActive: (workspace:Workspace) => workspace.isLinkActive("apollo")
});
});
hawtioPluginLoader.addModule(pluginName);
}
10 changes: 10 additions & 0 deletions hawtio-web/src/main/webapp/app/apollo/js/virtual_hosts.ts
@@ -0,0 +1,10 @@
module Apollo {
export function VirtualHostController($scope, $http, $location, localStorage, workspace:Workspace) {
$scope.virtual_host = {}
$scope.init = (virtual_host_name)=>{
$scope.ajax("GET", "/broker/virtual-hosts/"+virtual_host_name, (host)=>{
$scope.virtual_host = host
});
};
}
}

1 comment on commit 51b8058

@jstrachan
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hawt! :)

Please sign in to comment.