• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

WindhoverLabs / yamcs-cfs / #150

05 Mar 2024 07:27PM UTC coverage: 0.0%. First build
#150

push

lorenzo-gomez-windhover
-Archive Beb plugin. WIP.

0 of 49 new or added lines in 3 files covered. (0.0%)

0 of 6900 relevant lines covered (0.0%)

0.0 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/main/java/com/windhoverlabs/beb/BebPlugin.java
1
package com.windhoverlabs.beb;
2

3
import java.io.IOException;
4
import java.nio.file.Path;
5
import java.util.ArrayList;
6
import java.util.HashMap;
7
import java.util.List;
8
import java.util.Map;
9
import java.util.stream.Collectors;
10
import java.util.stream.Stream;
11
import org.yamcs.Experimental;
12
import org.yamcs.Plugin;
13
import org.yamcs.PluginException;
14
import org.yamcs.YConfiguration;
15
import org.yamcs.YamcsServer;
16
import org.yamcs.YamcsServerInstance;
17
import org.yamcs.http.Binding;
18
import org.yamcs.http.HttpServer;
19
import org.yamcs.logging.Log;
20
import org.yamcs.management.ManagementListener;
21
import org.yamcs.management.ManagementService;
22
import org.yamcs.protobuf.YamcsInstance.InstanceState;
23
import org.yamcs.security.SystemPrivilege;
24
import org.yamcs.yarch.Bucket;
25
import org.yamcs.yarch.YarchDatabase;
26
import org.yamcs.yarch.YarchDatabaseInstance;
27

28
public class BebPlugin implements Plugin {
×
29

30
  static final String CONFIG_SECTION = "yamcs-web";
31
  static final String CONFIG_DISPLAY_BUCKET = "displayBucket";
32
  static final String CONFIG_STACK_BUCKET = "stackBucket";
33

34
  /**
35
   * Allows access to the Admin Area.
36
   *
37
   * <p>Remark that certain pages in the Admin Area may require further privileges.
38
   */
39
  public static final SystemPrivilege PRIV_ADMIN = new SystemPrivilege("web.AccessAdminArea");
×
40

41
  private Log log = new Log(getClass());
×
42

43
  private WebFileDeployer deployer;
44
  private BebHandler bebHandler;
45

46
  // We need these outside of deployer because we cannot predict the order in which
47
  // plugins are loaded.
48
  private List<Path> extraStaticRoots = new ArrayList<>();
×
49
  private Map<String, Map<String, Object>> extraConfigs = new HashMap<>();
×
50

51
  @Override
52
  public void onLoad(YConfiguration config) throws PluginException {
53
    YamcsServer yamcs = YamcsServer.getServer();
×
54
    yamcs.getSecurityStore().addSystemPrivilege(PRIV_ADMIN);
×
55

56
    HttpServer httpServer = yamcs.getGlobalService(HttpServer.class);
×
57
    String contextPath = httpServer.getContextPath();
×
58

NEW
59
    extraStaticRoots.add(
×
NEW
60
        Path.of(
×
61
            "/home/lgomez/projects/beb_integration/squeaky-weasel/software/airliner/build/venus_aero/sassie/sitl_commander_workspace/beb"));
62
    //        Don't care about buckets, for now
63
    //        createBuckets(config);
64

65
    try {
66
      deployer = new WebFileDeployer(config, contextPath, extraStaticRoots, extraConfigs);
×
67
      setupRoutes(config, deployer);
×
68
    } catch (IOException e) {
×
69
      throw new PluginException("Could not deploy website", e);
×
70
    }
×
71

72
    // Print these log statements via a ready listener because it is more helpful
73
    // if they appear at the end of the boot log.
74
    yamcs.addReadyListener(
×
75
        () -> {
76
          for (Binding binding : httpServer.getBindings()) {
×
77
            log.info("Beb deployed at {}{}", binding, contextPath);
×
78
          }
×
79
        });
×
80
  }
×
81

82
  @Experimental
83
  public void addExtension(String id, Map<String, Object> config, Path staticRoot) {
84
    extraConfigs.put(id, config);
×
85
    extraStaticRoots.add(staticRoot);
×
86
    if (deployer != null) { // Trigger deploy, if deployer is already available
×
87
      deployer.setExtraSources(extraStaticRoots, extraConfigs);
×
88
      bebHandler.setStaticRoots(
×
89
          Stream.concat(Stream.of(deployer.getDirectory()), deployer.getExtraStaticRoots().stream())
×
90
              .collect(Collectors.toList()));
×
91
    }
92
  }
×
93

94
  private void createBuckets(YConfiguration config) throws PluginException {
95
    String displayBucketName = config.getString(CONFIG_DISPLAY_BUCKET);
×
96
    createBucketIfNotExists(displayBucketName);
×
97

98
    String stackBucketName = config.getString(CONFIG_STACK_BUCKET);
×
99
    createBucketIfNotExists(stackBucketName);
×
100

101
    // Buckets can be overriden at instance level. If so, create those
102
    // buckets here. It is this WebPlugin that owns them.
103
    ManagementService.getInstance()
×
104
        .addManagementListener(
×
105
            new ManagementListener() {
×
106
              @Override
107
              public void instanceStateChanged(YamcsServerInstance ysi) {
108
                if (ysi.state() == InstanceState.STARTING) {
×
109
                  YConfiguration instanceConfig = ysi.getConfig().getConfigOrEmpty(CONFIG_SECTION);
×
110
                  if (instanceConfig.containsKey(CONFIG_DISPLAY_BUCKET)) {
×
111
                    String bucketName = instanceConfig.getString(CONFIG_DISPLAY_BUCKET);
×
112
                    try {
113
                      createBucketIfNotExists(bucketName);
×
114
                    } catch (PluginException e) {
×
115
                      log.error(
×
116
                          "Could not create display bucket for instance '" + ysi.getName() + "'",
×
117
                          e);
118
                    }
×
119
                  }
120
                  if (instanceConfig.containsKey(CONFIG_STACK_BUCKET)) {
×
121
                    String bucketName = instanceConfig.getString(CONFIG_STACK_BUCKET);
×
122
                    try {
123
                      createBucketIfNotExists(bucketName);
×
124
                    } catch (PluginException e) {
×
125
                      log.error(
×
126
                          "Could not create stack bucket for instance '" + ysi.getName() + "'", e);
×
127
                    }
×
128
                  }
129
                }
130
              }
×
131
            });
132
  }
×
133

134
  private Bucket createBucketIfNotExists(String bucketName) throws PluginException {
135
    YarchDatabaseInstance yarch = YarchDatabase.getInstance(YamcsServer.GLOBAL_INSTANCE);
×
136
    try {
137
      Bucket bucket = yarch.getBucket(bucketName);
×
138
      if (bucket == null) {
×
139
        bucket = yarch.createBucket(bucketName);
×
140
      }
141
      return bucket;
×
142
    } catch (IOException e) {
×
143
      throw new PluginException("Could not create '" + bucketName + "' bucket", e);
×
144
    }
145
  }
146

147
  /** Add routes used by Web UI. */
148
  private void setupRoutes(YConfiguration config, WebFileDeployer deployer) throws PluginException {
149
    HttpServer httpServer = YamcsServer.getServer().getGlobalService(HttpServer.class);
×
150

151
    bebHandler =
×
152
        new BebHandler(config, httpServer, deployer.getDirectory(), deployer.getExtraStaticRoots());
×
153
    httpServer.addRoute("beb", () -> bebHandler);
×
154

155
    //        Not needed by beb, for now
156
    // Additional API Routes
157
    //        try (InputStream in = getClass().getResourceAsStream("/yamcs-web.protobin")) {
158
    //            httpServer.getProtobufRegistry().importDefinitions(in);
159
    //        } catch (IOException e) {
160
    //            throw new PluginException(e);
161
    //        }
162
    //        httpServer.addApi(new BebApi());
163
  }
×
164
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc