Example #1
0
 public void run() {
   BooleanCallback bc = new BooleanCallback();
   switch (op) {
     case RESTART:
       hostInformationStore.restartHost(host, bc);
       break;
     case RELOAD:
       hostInformationStore.reloadHost(host, bc);
       break;
   }
   new Async(Footer.PROGRESS_ELEMENT)
       .whilst(new KeepGoing(), new Finish(), new QueryStatus(), 2000);
 }
 public void loadProperties(final Server server) {
   hostInfoStore.loadProperties(
       hostSelection.getName(),
       server,
       new SimpleCallback<List<PropertyRecord>>() {
         @Override
         public void onSuccess(List<PropertyRecord> properties) {
           getView().setProperties(server.getName(), properties);
         }
       });
 }
  public void loadJVMConfiguration(final Server server) {
    hostInfoStore.loadJVMConfiguration(
        hostSelection.getName(),
        server,
        new SimpleCallback<Jvm>() {
          @Override
          public void onSuccess(Jvm jvm) {

            getView().setJvm(server.getName(), jvm);
          }
        });
  }
  public void createServerConfig(final Server newServer) {

    // close popup
    closeDialoge();

    hostInfoStore.createServerConfig(
        getSelectedHost(),
        newServer,
        new AsyncCallback<Boolean>() {
          @Override
          public void onSuccess(Boolean wasSuccessful) {
            if (wasSuccessful) {

              Console.MODULES
                  .getMessageCenter()
                  .notify(new Message("Created server config " + newServer.getName()));

              Scheduler.get()
                  .scheduleDeferred(
                      new Scheduler.ScheduledCommand() {
                        @Override
                        public void execute() {
                          getEventBus()
                              .fireEvent(
                                  new StaleModelEvent(StaleModelEvent.SERVER_CONFIGURATIONS));
                        }
                      });

              loadServerConfigurations();

            } else {
              closeDialoge();
              Console.MODULES
                  .getMessageCenter()
                  .notify(
                      new Message(
                          "Failed to create server config " + newServer.getName(),
                          Message.Severity.Error));
            }
          }

          @Override
          public void onFailure(Throwable caught) {

            Console.MODULES
                .getMessageCenter()
                .notify(
                    new Message(
                        "Failed to create server config " + newServer.getName(),
                        Message.Severity.Error));
          }
        });
  }
  private void loadServerConfigurations() {

    if (!hostSelection.isSet()) throw new RuntimeException("Host selection not set!");

    hostInfoStore.getServerConfigurations(
        hostSelection.getName(),
        new SimpleCallback<List<Server>>() {
          @Override
          public void onSuccess(List<Server> result) {
            getView().setConfigurations(hostSelection.getName(), result);
          }
        });
  }
  private void loadHostData() {
    // load host and server data
    hostInfoStore.getHosts(
        new SimpleCallback<List<Host>>() {
          @Override
          public void onSuccess(final List<Host> hosts) {

            if (!hosts.isEmpty()) selectDefaultHost(hosts);

            final String host = serverSelection.getHost();
            hostInfoStore.getServerInstances(
                host,
                new SimpleCallback<List<ServerInstance>>() {
                  @Override
                  public void onSuccess(List<ServerInstance> server) {

                    if (!serverSelection.hasSetServer()) {
                      if (!server.isEmpty()) {
                        final ServerInstance serverInstance = server.get(0);
                        Console.info("Default server selection: " + serverInstance.getName());

                        Scheduler.get()
                            .scheduleDeferred(
                                new Scheduler.ScheduledCommand() {
                                  @Override
                                  public void execute() {

                                    // make this fires
                                    getEventBus()
                                        .fireEvent(new ServerSelectionEvent(host, serverInstance));
                                  }
                                });
                      }
                    }

                    // update the LHS in all cases
                    getView().setHosts(hosts);
                    getView().setServer(server);
                  }
                });
          }
        });
  }
  private void performDeleteOperation(final Server server) {

    hostInfoStore.deleteServerConfig(
        hostSelection.getName(),
        server,
        new AsyncCallback<Boolean>() {
          @Override
          public void onFailure(Throwable caught) {
            Console.MODULES
                .getMessageCenter()
                .notify(
                    new Message(
                        "Failed to delete server config " + server.getName(),
                        Message.Severity.Error));
          }

          @Override
          public void onSuccess(Boolean wasSuccessful) {
            if (wasSuccessful) {
              Console.MODULES
                  .getMessageCenter()
                  .notify(new Message("Successfully deleted server config " + server.getName()));

              getEventBus().fireEvent(new StaleModelEvent(StaleModelEvent.SERVER_CONFIGURATIONS));

              loadServerConfigurations();
            } else {
              Console.MODULES
                  .getMessageCenter()
                  .notify(
                      new Message(
                          "Failed to delete server config " + server.getName(),
                          Message.Severity.Error));
            }
          }
        });
  }
  public void onSaveChanges(final Server entity, Map<String, Object> changedValues) {

    if (changedValues.size() > 0) {

      if (changedValues.containsKey("portOffset"))
        changedValues.put("socketBinding", entity.getSocketBinding());
      else if (changedValues.containsKey("socketBinding"))
        changedValues.put("portOffset", entity.getPortOffset());

      final String name = entity.getName();

      hostInfoStore.saveServerConfig(
          hostSelection.getName(),
          name,
          changedValues,
          new AsyncCallback<Boolean>() {

            @Override
            public void onFailure(Throwable caught) {
              // log and reset when something fails
              Console.error("Failed to modify server-config " + name);
              loadServerConfigurations();
            }

            @Override
            public void onSuccess(Boolean wasSuccessful) {
              if (wasSuccessful) {
                Console.info("Successfully modified server-config " + name);
              } else {
                Console.error("Failed to modify server-config " + name);
              }

              loadServerConfigurations();
            }
          });
    }
  }