diff --git a/JazminDeployer/src/jazmin/deploy/DeploySystemUI.java b/JazminDeployer/src/jazmin/deploy/DeploySystemUI.java index 88999b11..21a36338 100644 --- a/JazminDeployer/src/jazmin/deploy/DeploySystemUI.java +++ b/JazminDeployer/src/jazmin/deploy/DeploySystemUI.java @@ -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); @@ -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()); } // @@ -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(); } } diff --git a/JazminDeployer/src/jazmin/deploy/ui/BeanTable.java b/JazminDeployer/src/jazmin/deploy/ui/BeanTable.java index 7e1618f5..4702f643 100644 --- a/JazminDeployer/src/jazmin/deploy/ui/BeanTable.java +++ b/JazminDeployer/src/jazmin/deploy/ui/BeanTable.java @@ -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; + } + // } diff --git a/JazminDeployer/src/jazmin/deploy/view/console/ConsoleView.java b/JazminDeployer/src/jazmin/deploy/view/console/ConsoleView.java new file mode 100644 index 00000000..40e5c5fd --- /dev/null +++ b/JazminDeployer/src/jazmin/deploy/view/console/ConsoleView.java @@ -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); + + } +} diff --git a/JazminDeployer/src/jazmin/deploy/view/console/InstanceOptView.java b/JazminDeployer/src/jazmin/deploy/view/console/InstanceOptView.java new file mode 100644 index 00000000..d45f0f45 --- /dev/null +++ b/JazminDeployer/src/jazmin/deploy/view/console/InstanceOptView.java @@ -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{ + BeanTabletable; + ListinstanceList; + // + 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(); + table= new BeanTable(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 ListgetOptInstances(){ + return instanceList; + } + +} diff --git a/JazminDeployer/src/jazmin/deploy/view/console/MachineOptView.java b/JazminDeployer/src/jazmin/deploy/view/console/MachineOptView.java new file mode 100644 index 00000000..363c14b5 --- /dev/null +++ b/JazminDeployer/src/jazmin/deploy/view/console/MachineOptView.java @@ -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{ + BeanTabletable; + private Listmachines; + // + public MachineOptView() { + super(); + setCaption("Machines"); + searchTxt.setValue("1=1"); + setSizeFull(); + loadData(); + } + @Override + public BeanTable createTable() { + machines=new ArrayList(); + table= new BeanTable(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()); + } + } +} diff --git a/JazminDeployer/src/jazmin/deploy/view/instance/InstanceMemcachedWindow.java b/JazminDeployer/src/jazmin/deploy/view/instance/InstanceMemcachedWindow.java index 0823c131..589fc393 100644 --- a/JazminDeployer/src/jazmin/deploy/view/instance/InstanceMemcachedWindow.java +++ b/JazminDeployer/src/jazmin/deploy/view/instance/InstanceMemcachedWindow.java @@ -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); diff --git a/JazminDeployer/src/jazmin/deploy/view/instance/InstanceMySQLWindow.java b/JazminDeployer/src/jazmin/deploy/view/instance/InstanceMySQLWindow.java index 0f2c6aaa..4c6757b1 100644 --- a/JazminDeployer/src/jazmin/deploy/view/instance/InstanceMySQLWindow.java +++ b/JazminDeployer/src/jazmin/deploy/view/instance/InstanceMySQLWindow.java @@ -58,7 +58,7 @@ public InstanceMySQLWindow(Instance instance){ currentHeaders=new ArrayList(); 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(); @@ -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(); } } diff --git a/JazminDeployer/src/jazmin/deploy/view/instance/InstanceWebSshWindow.java b/JazminDeployer/src/jazmin/deploy/view/instance/InstanceWebSshWindow.java index 623fc482..10ed93f5 100644 --- a/JazminDeployer/src/jazmin/deploy/view/instance/InstanceWebSshWindow.java +++ b/JazminDeployer/src/jazmin/deploy/view/instance/InstanceWebSshWindow.java @@ -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(); diff --git a/JazminDeployer/src/jazmin/deploy/view/machine/MachineWebSshWindow.java b/JazminDeployer/src/jazmin/deploy/view/machine/MachineWebSshWindow.java index 8824ef2a..2967fffc 100644 --- a/JazminDeployer/src/jazmin/deploy/view/machine/MachineWebSshWindow.java +++ b/JazminDeployer/src/jazmin/deploy/view/machine/MachineWebSshWindow.java @@ -31,8 +31,9 @@ public MachineWebSshWindow(Machine machine) { VerticalLayout content = new VerticalLayout(); content.setSizeFull(); setContent(content); + content.setImmediate(false); BrowserFrame frame=new BrowserFrame(null, - new ExternalResource("/srv/deploy/webssh/"+machine.id)); + new ExternalResource("/srv/deploy/webssh/"+machine.id)); frame.setSizeFull(); content.addComponent(frame); content.setExpandRatio(frame, 1f); diff --git a/JazminDeployer/src/jazmin/deploy/view/main/LoginView.java b/JazminDeployer/src/jazmin/deploy/view/main/LoginView.java index 68c2c2f0..87ed475d 100644 --- a/JazminDeployer/src/jazmin/deploy/view/main/LoginView.java +++ b/JazminDeployer/src/jazmin/deploy/view/main/LoginView.java @@ -74,7 +74,7 @@ private Component buildFields() { User uu=DeployManager.validate(u, p); if(uu!=null){ DeploySystemUI.setUser(uu); - DeploySystemUI.showMainView(); + DeploySystemUI.get().showMainView(); }else{ DeploySystemUI.showNotificationInfo("Login failed", "username or password wrong.please try again."); diff --git a/JazminDeployer/src/jazmin/deploy/view/main/MainMenu.java b/JazminDeployer/src/jazmin/deploy/view/main/MainMenu.java index 3416736c..f238eaa6 100644 --- a/JazminDeployer/src/jazmin/deploy/view/main/MainMenu.java +++ b/JazminDeployer/src/jazmin/deploy/view/main/MainMenu.java @@ -103,7 +103,7 @@ private Component buildUserMenu() { settingsItem.addSeparator(); settingsItem.addItem("Sign Out", (selectedItem)->{ DeploySystemUI.setUser(null); - DeploySystemUI.showLoginView(); + DeploySystemUI.get().showLoginView(); }); return settings; } diff --git a/JazminDeployer/src/jazmin/deploy/view/main/MainView.java b/JazminDeployer/src/jazmin/deploy/view/main/MainView.java index 92b519f4..b51d58cb 100644 --- a/JazminDeployer/src/jazmin/deploy/view/main/MainView.java +++ b/JazminDeployer/src/jazmin/deploy/view/main/MainView.java @@ -4,6 +4,7 @@ import jazmin.deploy.domain.DeployManager; import jazmin.deploy.view.app.ApplicationInfoView; +import jazmin.deploy.view.console.ConsoleView; import jazmin.deploy.view.instance.InstanceInfoView; import jazmin.deploy.view.machine.MachineInfoView; import jazmin.deploy.view.pkg.PackageInfoView; @@ -27,6 +28,7 @@ public class MainView extends HorizontalLayout { private VerticalLayout content ; private MainMenu menuView; + private ConsoleView consoleView; public MainView() { setSizeFull(); @@ -68,6 +70,12 @@ private void initMenus(){ menuView.addMenuItem("Machines", FontAwesome.GEAR,new MachineInfoView()); menuView.addMenuItem("Applications", FontAwesome.ANDROID,new ApplicationInfoView()); menuView.addMenuItem("Packages", FontAwesome.ANCHOR,new PackageInfoView()); - menuView.addMenuItem("Repos", FontAwesome.APPLE,new RepoInfoView()); + menuView.addMenuItem("Repos", FontAwesome.APPLE,new RepoInfoView()); + consoleView=new ConsoleView(); + menuView.addMenuItem("Consoles", FontAwesome.CODE,consoleView); + } + // + public ConsoleView getConsoleView(){ + return consoleView; } }