Exemplo n.º 1
0
  public ServerDesc() {
    setWidth("100%");
    setHeight("100%");
    setCaption(ViewProperties.getCaption("panel.serverDesc"));
    addStyleName(Reindeer.PANEL_LIGHT);
    addStyleName("server-desc-panel");

    VerticalLayout layout = (VerticalLayout) getContent();
    layout.setWidth("100%");
    layout.setHeight("100%");
    layout.setMargin(false);
    layout.setSpacing(false);
    layout.addStyleName("server-desc-layout");
    tabDesc.addStyleName(Reindeer.TABSHEET_BORDERLESS);
    tabDesc.setWidth("100%");
    tabDesc.setHeight("100%");
    tabDesc.addTab(
        serverDescBasic, ViewProperties.getCaption("tab.serverDescBasic"), Icons.BASIC.resource());
    tabDesc.addTab(
        serverDescDetail,
        ViewProperties.getCaption("tab.serverDescDetail"),
        Icons.DETAIL.resource());
    // タブ用リスナー
    tabDesc.addListener(TabSheet.SelectedTabChangeEvent.class, this, "selectedTabChange");
    addComponent(tabDesc);
  }
    BasicInfo() {
      setCaption(ViewProperties.getCaption("table.serverBasicInfo"));
      setHeight("100%");
      setStyleName("server-desc-basic-panel");

      VerticalLayout vlay = (VerticalLayout) getContent();
      vlay.setStyleName("server-desc-basic-panel");
      vlay.setMargin(true);

      layout = new GridLayout(2, CAPNAME.length);

      layout.setWidth("100%");
      layout.setStyleName("server-desc-basic-info");
      layout.setColumnExpandRatio(0, 35);
      layout.setColumnExpandRatio(1, 65);
      vlay.addComponent(layout);

      // 項目名設定
      for (int i = 0; i < CAPNAME.length; i++) {
        Label lbl1 = new Label(CAPNAME[i], Label.CONTENT_XHTML);
        Label lbl2 = new Label("");
        lbl1.setHeight(COLUMN_HEIGHT);
        layout.addComponent(lbl1, 0, i);
        layout.addComponent(lbl2, 1, i);
      }

      // EC2 Windows用パスワード取得ボタン
      getPassword = new Button(ViewProperties.getCaption("button.getPassword"));
      getPassword.setDescription(ViewProperties.getCaption("description.getPassword"));
      getPassword.setIcon(Icons.LOGIN.resource());
      getPassword.addStyleName("getpassword");
      getPassword.addListener(
          new ClickListener() {

            @Override
            public void buttonClick(ClickEvent event) {
              AutoApplication ap = (AutoApplication) getApplication();
              InstanceDto dto = (InstanceDto) ap.myCloud.myCloudTabs.serverTable.getValue();
              Long instanceNo = (Long) getPassword.getData();
              WinPassword winPassword = new WinPassword(dto, instanceNo);
              getWindow().addWindow(winPassword);
            }
          });
    }
 @Override
 public void setContainerDataSource(Container newDataSource) {
   super.setContainerDataSource(newDataSource);
   setColumnHeaderMode(Table.COLUMN_HEADER_MODE_EXPLICIT);
   addStyleName("server-desc-basic-service");
   setCaption(ViewProperties.getCaption("table.serverServices"));
   setSortDisabled(true);
   setMultiSelect(false);
   setImmediate(false);
   setVisible(true);
 }
  @Override
  public void attach() {
    setSizeFull();
    addStyleName(Reindeer.PANEL_LIGHT);

    VerticalLayout layout = (VerticalLayout) getContent();
    layout.setSizeFull();
    layout.addStyleName("loadbalancer-tab");
    layout.setSpacing(false);
    layout.setMargin(false);

    // スプリットパネル
    SplitPanel splitPanel = new SplitPanel();
    splitPanel.setOrientation(SplitPanel.ORIENTATION_VERTICAL);
    splitPanel.setSplitPosition(40);
    splitPanel.setSizeFull();
    layout.addComponent(splitPanel);

    // スプリットパネル上段
    VerticalLayout upperLayout = new VerticalLayout();
    upperLayout.setSizeFull();
    upperLayout.setSpacing(false);
    upperLayout.setMargin(false);

    CssLayout upperTopLayout = new CssLayout();
    Label label = new Label(ViewProperties.getCaption("label.loadbalancer"));
    upperTopLayout.setWidth("100%");
    upperTopLayout.setMargin(true);
    upperTopLayout.addStyleName("loadbalancer-table-label");
    upperTopLayout.addComponent(label);
    upperTopLayout.setHeight("28px");
    upperLayout.addComponent(upperTopLayout);

    loadBalancerTable = new LoadBalancerTable(sender);
    loadBalancerTable.setContainerDataSource(new LoadBalancerDtoContainer());
    upperLayout.addComponent(loadBalancerTable);
    loadBalancerTable.addListener(
        new ValueChangeListener() {
          @Override
          public void valueChange(ValueChangeEvent event) {
            tableRowSelected(event);
          }
        });

    loadBalancerButtonsBottom = new LoadBalancerButtonsBottom(sender);
    upperLayout.addComponent(loadBalancerButtonsBottom);
    upperLayout.setExpandRatio(loadBalancerTable, 10);
    splitPanel.addComponent(upperLayout);

    // スプリットパネル下段
    loadBalancerDesc = new LoadBalancerDesc(sender);
    splitPanel.addComponent(loadBalancerDesc);
  }
  // 左側基本情報の初期化
  class BasicInfo extends Panel {

    protected Log log = LogFactory.getLog(BasicInfo.class);

    final String COLUMN_HEIGHT = "30px";
    final String COLUMN_HEIGHT_DOUBLE = "60px";

    Label hostName;

    Label fqdn;

    Label comment;

    Label ipAddress;

    Label platform;

    Label status;

    CssLayout layoutOsType;
    Label ostype;
    Button getPassword;

    // 項目名
    String[] CAPNAME = {
      //                ViewProperties.getCaption("field.serverName"),
      ViewProperties.getCaption("field.fqdn"),
      ViewProperties.getCaption("field.ipAddress"),
      ViewProperties.getCaption("field.platform"),
      ViewProperties.getCaption("field.os"),
      ViewProperties.getCaption("field.serverOsStatus"),
      ViewProperties.getCaption("field.comment")
    };

    GridLayout layout;

    BasicInfo() {
      setCaption(ViewProperties.getCaption("table.serverBasicInfo"));
      setHeight("100%");
      setStyleName("server-desc-basic-panel");

      VerticalLayout vlay = (VerticalLayout) getContent();
      vlay.setStyleName("server-desc-basic-panel");
      vlay.setMargin(true);

      layout = new GridLayout(2, CAPNAME.length);

      layout.setWidth("100%");
      layout.setStyleName("server-desc-basic-info");
      layout.setColumnExpandRatio(0, 35);
      layout.setColumnExpandRatio(1, 65);
      vlay.addComponent(layout);

      // 項目名設定
      for (int i = 0; i < CAPNAME.length; i++) {
        Label lbl1 = new Label(CAPNAME[i], Label.CONTENT_XHTML);
        Label lbl2 = new Label("");
        lbl1.setHeight(COLUMN_HEIGHT);
        layout.addComponent(lbl1, 0, i);
        layout.addComponent(lbl2, 1, i);
      }

      // EC2 Windows用パスワード取得ボタン
      getPassword = new Button(ViewProperties.getCaption("button.getPassword"));
      getPassword.setDescription(ViewProperties.getCaption("description.getPassword"));
      getPassword.setIcon(Icons.LOGIN.resource());
      getPassword.addStyleName("getpassword");
      getPassword.addListener(
          new ClickListener() {

            @Override
            public void buttonClick(ClickEvent event) {
              AutoApplication ap = (AutoApplication) getApplication();
              InstanceDto dto = (InstanceDto) ap.myCloud.myCloudTabs.serverTable.getValue();
              Long instanceNo = (Long) getPassword.getData();
              WinPassword winPassword = new WinPassword(dto, instanceNo);
              getWindow().addWindow(winPassword);
            }
          });
    }

    public void setItem(InstanceDto instanceDto) {
      int line = 0;

      if (instanceDto != null) {
        Instance instance = instanceDto.getInstance();
        //                hostName = new Label(instance.getInstanceName(), Label.CONTENT_TEXT);
        //                layout.removeComponent( 1, line );
        //                layout.addComponent(hostName , 1, line++ );

        fqdn = new Label(instance.getFqdn(), Label.CONTENT_TEXT);
        layout.removeComponent(1, line);
        layout.addComponent(fqdn, 1, line++);

        ipAddress = new Label(instance.getPublicIp(), Label.CONTENT_TEXT);
        layout.removeComponent(1, line);
        layout.addComponent(ipAddress, 1, line++);

        // プラットフォームの表示
        PlatformDto platformDto = instanceDto.getPlatform();

        // TODO: アイコン名の取得ロジックのリファクタリング
        Icons icon = Icons.NONE;
        if ("aws".equals(platformDto.getPlatform().getPlatformType())) {
          if (platformDto.getPlatformAws().getEuca()) {
            icon = Icons.EUCALYPTUS;
          } else {
            icon = Icons.AWS;
          }
        } else if ("vmware".equals(platformDto.getPlatform().getPlatformType())) {
          icon = Icons.VMWARE;
        } else if ("nifty".equals(platformDto.getPlatform().getPlatformType())) {
          icon = Icons.NIFTY;
        } else if ("cloudstack".equals(platformDto.getPlatform().getPlatformType())) {
          icon = Icons.CLOUD_STACK;
        }

        String description = platformDto.getPlatform().getPlatformNameDisp();
        platform =
            new Label(
                "<img src=\""
                    + VaadinUtils.getIconPath(ServerDescBasic.this, icon)
                    + "\"><div>"
                    + description
                    + "</div>",
                Label.CONTENT_XHTML);
        layout.removeComponent(1, line);
        layout.addComponent(platform, 1, line++);

        // OS名の表示
        ImageDto imageDto = instanceDto.getImage();
        // TODO: アイコン名取得ロジックのリファクタリング
        String os = imageDto.getImage().getOsDisp();
        Icons osIcon = Icons.NONE;
        if (imageDto.getImage().getOs().startsWith("centos")) {
          osIcon = Icons.CENTOS;
        } else if (imageDto.getImage().getOs().startsWith("windows")) {
          osIcon = Icons.WINDOWS;
        }
        layoutOsType = new CssLayout();
        ostype =
            new Label(
                "<img src=\""
                    + VaadinUtils.getIconPath(ServerDescBasic.this, osIcon)
                    + "\"><div>"
                    + os
                    + "</div>",
                Label.CONTENT_XHTML);
        layoutOsType.setSizeFull();
        layoutOsType.setMargin(false);
        layoutOsType.addComponent(ostype);

        // OSがWindowsの場合パスワード取得ボタンを表示
        if (imageDto.getImage().getOs().startsWith("windows")) {
          // ただしEUCALYPTUSは除外
          if (platformDto.getPlatformAws() == null
              || platformDto.getPlatformAws().getEuca() == false) {
            InstanceStatus instanceStatus = InstanceStatus.fromStatus(instance.getStatus());
            if (instanceStatus == InstanceStatus.RUNNING) {
              getPassword.setEnabled(true);
              getPassword.setData(instance.getInstanceNo());
            } else {
              getPassword.setEnabled(false);
            }
            layoutOsType.addComponent(getPassword);
            layoutOsType.setHeight("60px");
          }
        }

        layout.removeComponent(1, line);
        layout.addComponent(layoutOsType, 1, line++);

        // ステータスの表示
        String stat =
            instance.getStatus().substring(0, 1).toUpperCase()
                + instance.getStatus().substring(1).toLowerCase();
        Icons icon2 = Icons.fromName(stat);

        status =
            new Label(
                "<img src=\""
                    + VaadinUtils.getIconPath(ServerDescBasic.this, icon2)
                    + "\"><div>"
                    + stat
                    + "</div>",
                Label.CONTENT_XHTML);
        layout.removeComponent(1, line);
        layout.addComponent(status, 1, line++);

        // コメント
        comment = new Label(instance.getComment(), Label.CONTENT_XHTML);
        layout.removeComponent(1, line);
        layout.addComponent(comment, 1, line++);

      } else {
        //                hostName = new Label("", Label.CONTENT_TEXT);
        //                layout.removeComponent( 1, line );
        //                layout.addComponent(hostName , 1, line++ );

        fqdn = new Label("", Label.CONTENT_TEXT);
        layout.removeComponent(1, line);
        layout.addComponent(fqdn, 1, line++);

        ipAddress = new Label("", Label.CONTENT_TEXT);
        layout.removeComponent(1, line);
        layout.addComponent(ipAddress, 1, line++);

        // プラットフォームの表示
        platform = new Label("", Label.CONTENT_XHTML);
        layout.removeComponent(1, line);
        layout.addComponent(platform, 1, line++);

        // OS名の表示
        layoutOsType = new CssLayout();
        ostype = new Label("", Label.CONTENT_XHTML);
        layoutOsType.setSizeFull();
        layoutOsType.setMargin(false);
        layoutOsType.addComponent(ostype);
        layout.removeComponent(1, line);
        layout.addComponent(layoutOsType, 1, line++);

        // ステータスの表示
        status = new Label("", Label.CONTENT_XHTML);
        layout.removeComponent(1, line);
        layout.addComponent(status, 1, line++);

        // コメント
        comment = new Label("", Label.CONTENT_XHTML);
        layout.removeComponent(1, line);
        layout.addComponent(comment, 1, line++);
      }
    }
  }
  // 右側サーバ一覧パネル
  class AttachService extends Table {

    final String COLUMN_HEIGHT = "28px";

    String[] COLNAME = {
      ViewProperties.getCaption("field.serviceName"),
      ViewProperties.getCaption("field.managementUrl"),
      ViewProperties.getCaption("field.serviceStatus"),
      ViewProperties.getCaption("field.serviceDetail")
    };

    public AttachService(String caption, Container dataSource) {
      super(caption, dataSource);
      setIcon(Icons.SERVICETAB.resource());

      addGeneratedColumn(
          "componentName",
          new ColumnGenerator() {
            public Component generateCell(Table source, Object itemId, Object columnId) {
              ComponentDto componentDto = (ComponentDto) itemId;
              jp.primecloud.auto.entity.crud.Component p = componentDto.getComponent();

              String name;
              if (StringUtils.isEmpty(p.getComment())) {
                name = p.getComponentName();
              } else {
                name = p.getComment() + "\n[" + p.getComponentName() + "]";
              }
              Label slbl = new Label(name, Label.CONTENT_PREFORMATTED);
              slbl.setHeight(COLUMN_HEIGHT);
              return slbl;
            }
          });

      addGeneratedColumn(
          "urlIcon",
          new ColumnGenerator() {
            public Component generateCell(Table source, Object itemId, Object columnId) {
              ComponentDto componentDto = (ComponentDto) itemId;
              jp.primecloud.auto.entity.crud.Component p = componentDto.getComponent();
              ComponentType componentType = componentDto.getComponentType();
              String type = componentType.getComponentTypeName();

              AutoApplication ap = (AutoApplication) getApplication();
              InstanceDto dto = (InstanceDto) ap.myCloud.myCloudTabs.serverTable.getValue();

              // リンクを追加する
              String status = "";
              String url = "";
              for (ComponentInstanceDto componentInstance : dto.getComponentInstances()) {
                if (componentInstance
                    .getComponentInstance()
                    .getComponentNo()
                    .equals(p.getComponentNo())) {
                  status = componentInstance.getComponentInstance().getStatus();
                  url = componentInstance.getUrl();
                  break;
                }
              }
              Icons icon = Icons.fromName(type);

              // MySQLならMasterとSlaveでアイコンを変える
              if (MySQLConstants.COMPONENT_TYPE_NAME.equals(type)) {
                // Master
                Long masterInstanceNo = null;
                for (InstanceConfig config : dto.getInstanceConfigs()) {
                  if (MySQLConstants.CONFIG_NAME_MASTER_INSTANCE_NO.equals(
                      config.getConfigName())) {
                    if (StringUtils.isEmpty(config.getConfigValue())) {
                      masterInstanceNo = config.getInstanceNo();
                      break;
                    }
                  }
                }
                if (masterInstanceNo != null) {
                  if (masterInstanceNo.equals(dto.getInstance().getInstanceNo())) {
                    icon = Icons.MYSQL_MASTER;
                  } else {
                    icon = Icons.MYSQL_SLAVE;
                  }
                } else {
                  icon = Icons.MYSQL_SLAVE;
                }
              }
              Link slbl =
                  new Link(
                      ViewProperties.getCaption("field.managementLink"), new ExternalResource(url));
              slbl.setTargetName("_blank");
              slbl.setIcon(icon.resource());
              slbl.setHeight(COLUMN_HEIGHT);
              slbl.setEnabled(false);

              if (status.equals(ComponentInstanceStatus.RUNNING.toString())) {
                slbl.setDescription(url);
                slbl.setEnabled(true);
              }

              return slbl;
            }
          });

      addGeneratedColumn(
          "status",
          new ColumnGenerator() {
            public Component generateCell(Table source, Object itemId, Object columnId) {
              ComponentDto componentDto = (ComponentDto) itemId;
              jp.primecloud.auto.entity.crud.Component p = componentDto.getComponent();
              AutoApplication ap = (AutoApplication) getApplication();
              InstanceDto dto = (InstanceDto) ap.myCloud.myCloudTabs.serverTable.getValue();

              String status = "";
              for (ComponentInstanceDto componentInstance : dto.getComponentInstances()) {
                if (componentInstance
                    .getComponentInstance()
                    .getComponentNo()
                    .equals(p.getComponentNo())) {
                  status = componentInstance.getComponentInstance().getStatus();
                  break;
                }
              }

              String a = status.substring(0, 1).toUpperCase() + status.substring(1).toLowerCase();
              Icons icon = Icons.fromName(a);
              Label slbl =
                  new Label(
                      "<img src=\""
                          + VaadinUtils.getIconPath(ServerDescBasic.this, icon)
                          + "\"><div>"
                          + a
                          + "</div>",
                      Label.CONTENT_XHTML);
              slbl.setHeight(COLUMN_HEIGHT);
              return slbl;
            }
          });

      addGeneratedColumn(
          "serviceDetail",
          new ColumnGenerator() {
            public Component generateCell(Table source, Object itemId, Object columnId) {
              ComponentDto componentDto = (ComponentDto) itemId;
              jp.primecloud.auto.entity.crud.Component p = componentDto.getComponent();
              ComponentType componentType = componentDto.getComponentType();
              String type = componentType.getComponentTypeName();
              String name = componentType.getComponentTypeNameDisp();

              // MySQLならMasterとSlaveでアイコンを変える
              AutoApplication ap = (AutoApplication) getApplication();
              InstanceDto dto = (InstanceDto) ap.myCloud.myCloudTabs.serverTable.getValue();

              if (MySQLConstants.COMPONENT_TYPE_NAME.equals(type)) {
                // Master
                Long masterInstanceNo = null;
                for (InstanceConfig config : dto.getInstanceConfigs()) {
                  if (MySQLConstants.CONFIG_NAME_MASTER_INSTANCE_NO.equals(
                      config.getConfigName())) {
                    if (StringUtils.isEmpty(config.getConfigValue())) {
                      masterInstanceNo = config.getInstanceNo();
                      break;
                    }
                  }
                }
                if (masterInstanceNo != null) {
                  if (masterInstanceNo.equals(dto.getInstance().getInstanceNo())) {
                    name = name + " " + ViewProperties.getComponentTypeName(type + ".master");
                  } else {
                    name = name + " " + ViewProperties.getComponentTypeName(type + ".slave");
                  }
                } else {
                  name = name + " " + ViewProperties.getComponentTypeName(type + ".slave");
                }
              }
              Label slbl = new Label(name);

              return slbl;
            }
          });

      setColumnExpandRatio("serviceDetail", 100);

      // テーブルのカラムに対してStyleNameを設定
      setCellStyleGenerator(
          new Table.CellStyleGenerator() {
            public String getStyle(Object itemId, Object propertyId) {

              if (propertyId == null) {
                return "";
              } else {
                return propertyId.toString().toLowerCase();
              }
            }
          });
    }

    @Override
    public void setContainerDataSource(Container newDataSource) {
      super.setContainerDataSource(newDataSource);
      setColumnHeaderMode(Table.COLUMN_HEADER_MODE_EXPLICIT);
      addStyleName("server-desc-basic-service");
      setCaption(ViewProperties.getCaption("table.serverServices"));
      setSortDisabled(true);
      setMultiSelect(false);
      setImmediate(false);
      setVisible(true);
    }

    public void refresh(ComponentDtoContainer dataSource) {
      setContainerDataSource(dataSource);
      setVisibleColumns(ComponentDtoContainer.SERVER_DESC);
      if (dataSource != null && dataSource.size() > 0) {
        setColumnHeaders(COLNAME);
      }
    }
  }