@Override
 public int execute(BergamotCLI cli, List<String> args) throws Exception {
   if (args.size() < 2) throw new BergamotCLIException("No site name or alias given");
   // site name
   String siteName = args.remove(0);
   // read the UI config and connect to the database
   UICfg config = UICfg.loadConfiguration();
   // setup the data manager
   DataManager.getInstance()
       .registerDefaultServer(
           DatabasePool.Default.with()
               .postgresql()
               .url(config.getDatabase().getUrl())
               .username(config.getDatabase().getUsername())
               .password(config.getDatabase().getPassword())
               .build());
   // setup the queue manager
   QueueManager.getInstance()
       .registerDefaultBroker(
           new RabbitPool(
               config.getBroker().getUrl(),
               config.getBroker().getUsername(),
               config.getBroker().getPassword()));
   // ensure the DB schema is installed
   BergamotDB.install();
   // now actually create the site
   try (BergamotDB db = BergamotDB.connect()) {
     // ge the site
     Site site = db.getSiteByName(siteName);
     if (site == null)
       throw new BergamotCLIException("No site exists with the name: '" + siteName + "'");
     // check the aliases do not already exist
     for (String alias : args) {
       if (db.getSiteByName(alias) != null)
         throw new BergamotCLIException("A site already exists with the alias: '" + alias + "'");
     }
     // add the aliases
     for (String alias : args) {
       site.getAliases().add(alias);
     }
     db.setSite(site);
   }
   // message the UI cluster to setup the site
   try (BergamotClusterManagerQueue queue = BergamotClusterManagerQueue.open()) {
     try (RPCClient<ClusterManagerRequest, ClusterManagerResponse, RoutingKey> client =
         queue.createBergamotClusterManagerRPCClient()) {
       try {
         ClusterManagerResponse response =
             client.publish(new FlushGlobalCaches()).get(5, TimeUnit.SECONDS);
         if (response instanceof FlushedGlobalCaches) {
           System.out.println("Flushed UI cluster global caches");
         }
       } catch (Exception e) {
       }
     }
   }
   // all ok
   return 0;
 }
Example #2
0
 public TimePeriod getTimePeriod() {
   if (this.getTimePeriodId() == null) return null;
   try (BergamotDB db = BergamotDB.connect()) {
     return db.getTimePeriod(this.getTimePeriodId());
   }
 }
Example #3
0
 public void addEngine(NotificationEngine engine) {
   try (BergamotDB db = BergamotDB.connect()) {
     engine.setNotificationsId(this.getId());
     db.setNotificationEngine(engine);
   }
 }
Example #4
0
 public List<NotificationEngine> getEngines() {
   try (BergamotDB db = BergamotDB.connect()) {
     return db.getNotificationEngines(this.getId());
   }
 }