Skip to content

Commit

Permalink
add console view
Browse files Browse the repository at this point in the history
  • Loading branch information
guooscar committed Nov 11, 2015
1 parent 6dad817 commit f426828
Show file tree
Hide file tree
Showing 12 changed files with 321 additions and 16 deletions.
20 changes: 15 additions & 5 deletions JazminDeployer/src/jazmin/deploy/DeploySystemUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ public class DeploySystemUI extends UI {
*
*/
private static final long serialVersionUID = 1L;

//
private MainView mainView;
//
@Override
protected void init(VaadinRequest request) {
Responsive.makeResponsive(this);
Expand All @@ -43,11 +45,12 @@ protected void init(VaadinRequest request) {
}
}
//
public static void showMainView(){
get().setContent(new MainView());
public void showMainView(){
mainView=new MainView();
get().setContent(mainView);
}
//
public static void showLoginView(){
public void showLoginView(){
get().setContent(new LoginView());
}
//
Expand All @@ -73,8 +76,15 @@ public static void showNotificationInfo(String caption,String description){
n.setStyleName("dark");
n.show(Page.getCurrent());
}

/**
* @return the mainView
*/
public MainView getMainView() {
return mainView;
}
//
private static DeploySystemUI get(){
public static DeploySystemUI get(){
return (DeploySystemUI) getCurrent();
}
}
8 changes: 7 additions & 1 deletion JazminDeployer/src/jazmin/deploy/ui/BeanTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,5 +137,11 @@ public CellRender getCellRender() {
public void setCellRender(CellRender cellRender) {
this.cellRender = cellRender;
}

//
@SuppressWarnings("unchecked")
public T getValueByItem(Item item){
T obj=(T)item.getItemProperty("$object").getValue();
return obj;
}
//
}
31 changes: 31 additions & 0 deletions JazminDeployer/src/jazmin/deploy/view/console/ConsoleView.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package jazmin.deploy.view.console;

import com.vaadin.ui.Component;
import com.vaadin.ui.TabSheet;
import com.vaadin.ui.VerticalLayout;
/**
*
* @author yama
* 30 Dec, 2014
*/
@SuppressWarnings("serial")
public class ConsoleView extends VerticalLayout {
private TabSheet tabsheet;
public ConsoleView() {
setSizeFull();
tabsheet=new TabSheet();
tabsheet.setSizeFull();
addComponent(tabsheet);
setExpandRatio(tabsheet, 1);
//
tabsheet.addComponent(new MachineOptView());
tabsheet.addComponent(new InstanceOptView());
}
//
public void addOptView(Component component){
tabsheet.addComponent(component);
tabsheet.setSelectedTab(component);
tabsheet.getTab(component).setClosable(true);

}
}
173 changes: 173 additions & 0 deletions JazminDeployer/src/jazmin/deploy/view/console/InstanceOptView.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
/**
*
*/
package jazmin.deploy.view.console;

import java.util.ArrayList;
import java.util.List;

import jazmin.deploy.DeploySystemUI;
import jazmin.deploy.domain.Application;
import jazmin.deploy.domain.DeployManager;
import jazmin.deploy.domain.Instance;
import jazmin.deploy.ui.BeanTable;
import jazmin.deploy.view.instance.InstanceHaproxyStatWindow;
import jazmin.deploy.view.instance.InstanceMemcachedWindow;
import jazmin.deploy.view.instance.InstanceMySQLWindow;
import jazmin.deploy.view.instance.InstanceWebSshWindow;
import jazmin.deploy.view.main.DeployBaseView;

import com.vaadin.event.ItemClickEvent;
import com.vaadin.event.ItemClickEvent.ItemClickListener;
import com.vaadin.event.ShortcutAction.KeyCode;
import com.vaadin.event.ShortcutListener;
import com.vaadin.server.FontAwesome;
import com.vaadin.ui.Alignment;
import com.vaadin.ui.Button;
import com.vaadin.ui.Component;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Label;
import com.vaadin.ui.TextField;
import com.vaadin.ui.Window;
import com.vaadin.ui.themes.ValoTheme;

/**
* @author yama
* 6 Jan, 2015
*/
@SuppressWarnings("serial")
public class InstanceOptView extends DeployBaseView{
BeanTable<Instance>table;
List<Instance>instanceList;
//
public InstanceOptView() {
super();
setCaption("Instances");
searchTxt.setValue("1=1 order by priority desc");
loadData();
}
//
protected void initBaseUI(){
setSizeFull();
//
HorizontalLayout optLayout = new HorizontalLayout();
optLayout.setSpacing(true);
optLayout.addStyleName(ValoTheme.WINDOW_TOP_TOOLBAR);
optLayout.setWidth(100.0f, Unit.PERCENTAGE);
searchTxt = new TextField("Filter", "");
searchTxt.setIcon(FontAwesome.SEARCH);
searchTxt.setWidth(100.0f, Unit.PERCENTAGE);
searchTxt.addStyleName(ValoTheme.TEXTFIELD_TINY);
searchTxt.addStyleName(ValoTheme.TEXTFIELD_INLINE_ICON);
searchTxt.addShortcutListener(new ShortcutListener("Search",KeyCode.ENTER,null) {
@Override
public void handleAction(Object sender, Object target) {
loadData();
}
});
//
optLayout.addComponent(searchTxt);
optLayout.setExpandRatio(searchTxt,1.0f);
//
Button ok = new Button("Query");
ok.addStyleName(ValoTheme.BUTTON_PRIMARY);
ok.addStyleName(ValoTheme.BUTTON_SMALL);
optLayout.addComponent(ok);
ok.addClickListener(e->loadData());
optLayout.setComponentAlignment(ok, Alignment.BOTTOM_RIGHT);

//
addComponent(optLayout);

BeanTable<?> table = createTable();
addComponent(table);
table.setSizeFull();
setExpandRatio(table, 1);
tray = new HorizontalLayout();
tray.setWidth(100.0f, Unit.PERCENTAGE);
tray.addStyleName(ValoTheme.WINDOW_BOTTOM_TOOLBAR);
tray.setSpacing(true);
tray.setMargin(true);
//
Label emptyLabel=new Label("");
tray.addComponent(emptyLabel);
tray.setComponentAlignment(emptyLabel, Alignment.MIDDLE_RIGHT);
tray.setExpandRatio(emptyLabel,1.0f);
//
addComponent(tray);
}
//
@Override
public BeanTable<?> createTable() {
instanceList=new ArrayList<Instance>();
table= new BeanTable<Instance>(null, Instance.class,
"machine","user","password","application","properties");
table.addItemClickListener(new ItemClickListener() {
@Override
public void itemClick(ItemClickEvent event) {
if(event.isDoubleClick()){
Instance instance=table.getItemValue(event.getItem());
openConsole(instance);
}
}
});
return table;
}
//
private void openConsole(Instance instance){
if(instance.application==null){
DeploySystemUI.showNotificationInfo("Info",
"Can not find application on instance:"+instance.id);
return;
}
Window window=null;
//
if(instance.application.type.equals(Application.TYPE_HAPROXY)){
window=new InstanceHaproxyStatWindow(instance);
}
//
if(instance.application.type.equals(Application.TYPE_MYSQL)){
window=new InstanceMySQLWindow(instance);
}
//
if(instance.application.type.equals(Application.TYPE_MEMCACHED)){
window=new InstanceMemcachedWindow(instance);

}
//
if(instance.application.type.startsWith("jazmin")){
window=new InstanceWebSshWindow(instance);

}
if(window!=null){
Component c=window.getContent();
c.setCaption(window.getCaption());
DeploySystemUI.get().getMainView().getConsoleView().addOptView(c);
}else{
DeploySystemUI.showNotificationInfo("Info",
"Not support application type:"+instance.application.type);
}
}
//
@Override
public void loadData(){
String search=getSearchValue();
if(search==null){
return;
}
try {
instanceList=DeployManager.getInstances(search);
if(instanceList.isEmpty()){
DeploySystemUI.showNotificationInfo("Result","No mactch result found.");
}
table.setData(instanceList);
} catch (Throwable e1) {
DeploySystemUI.showNotificationInfo("Error",e1.getMessage());
}
}
//
public List<Instance>getOptInstances(){
return instanceList;
}

}
76 changes: 76 additions & 0 deletions JazminDeployer/src/jazmin/deploy/view/console/MachineOptView.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/**
*
*/
package jazmin.deploy.view.console;

import java.util.ArrayList;
import java.util.List;

import jazmin.deploy.DeploySystemUI;
import jazmin.deploy.domain.DeployManager;
import jazmin.deploy.domain.Machine;
import jazmin.deploy.ui.BeanTable;
import jazmin.deploy.view.machine.MachineWebSshWindow;
import jazmin.deploy.view.main.DeployBaseView;

import com.vaadin.event.ItemClickEvent;
import com.vaadin.event.ItemClickEvent.ItemClickListener;
import com.vaadin.ui.Component;

/**
* @author yama
* 6 Jan, 2015
*/
@SuppressWarnings("serial")
public class MachineOptView extends DeployBaseView{
BeanTable<Machine>table;
private List<Machine>machines;
//
public MachineOptView() {
super();
setCaption("Machines");
searchTxt.setValue("1=1");
setSizeFull();
loadData();
}
@Override
public BeanTable<?> createTable() {
machines=new ArrayList<Machine>();
table= new BeanTable<Machine>(null, Machine.class,
"sshPassword",
"rootSshPassword",
"jazminHome",
"memcachedHome",
"haproxyHome");
table.addItemClickListener(new ItemClickListener() {
@Override
public void itemClick(ItemClickEvent event) {
if(event.isDoubleClick()){
Machine machine=table.getItemValue(event.getItem());
MachineWebSshWindow window=new MachineWebSshWindow(machine);
Component c=window.getContent();
c.setCaption(window.getCaption());
DeploySystemUI.get().getMainView().getConsoleView().addOptView(c);
}
}
});
return table;
}
//
@Override
public void loadData(){
String search=getSearchValue();
if(search==null){
return;
}
try {
machines=DeployManager.getMachines(search);
if(machines.isEmpty()){
DeploySystemUI.showNotificationInfo("Result","No match result found.");
}
table.setData(machines);
} catch (Throwable e1) {
DeploySystemUI.showNotificationInfo("Error",e1.getMessage());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class InstanceMemcachedWindow extends Window{
public InstanceMemcachedWindow(Instance instance){
this.instance=instance;
Responsive.makeResponsive(this);
setCaption(instance.id+" memcached console");
setCaption(instance.id);
setWidth(90.0f, Unit.PERCENTAGE);
center();
setCloseShortcut(KeyCode.ESCAPE, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public InstanceMySQLWindow(Instance instance){
currentHeaders=new ArrayList<String>();
this.instance=instance;
Responsive.makeResponsive(this);
setCaption(instance.id+" mysql console");
setCaption(instance.id);
setWidth(90.0f, Unit.PERCENTAGE);
setHeight(90.0f, Unit.PERCENTAGE);
center();
Expand Down Expand Up @@ -279,19 +279,19 @@ private void setupData(ResultSetMetaData metaData,ResultSet rs){
//
private void loadInfo(){
InstanceMySQLTableInfoWindow w=new InstanceMySQLTableInfoWindow(instance);
getUI().addWindow(w);
DeploySystemUI.getCurrent().addWindow(w);
w.focus();
}
//
private void dumpMysql(){
InstanceMySQLDumpWindow w=new InstanceMySQLDumpWindow(instance);
getUI().addWindow(w);
DeploySystemUI.getCurrent().addWindow(w);
w.focus();
}
//
private void dumpDomainMysql(){
InstanceMySQLTableDomainWindow w=new InstanceMySQLTableDomainWindow(instance);
getUI().addWindow(w);
DeploySystemUI.getCurrent().addWindow(w);
w.focus();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class InstanceWebSshWindow extends Window{
//
public InstanceWebSshWindow(Instance instance) {
Responsive.makeResponsive(this);
setCaption(instance.id+" jazmin console");
setCaption(instance.id);
setWidth(90.0f, Unit.PERCENTAGE);
setHeight(90.0f, Unit.PERCENTAGE);
center();
Expand Down
Loading

0 comments on commit f426828

Please sign in to comment.