Exemplo n.º 1
1
  /** Fetch the classloader for the given ApplicationID. */
  static URLClassLoader getUrlClassLoader(ApplicationID appId, Map input) {
    NCube cpCube = getCube(appId, CLASSPATH_CUBE);
    if (cpCube
        == null) { // No sys.classpath cube exists, just create regular GroovyClassLoader with no
                   // URLs set into it.
      // Scope the GroovyClassLoader per ApplicationID
      return getLocalClassloader(appId);
    }

    final String envLevel = SystemUtilities.getExternalVariable("ENV_LEVEL");
    if (!input.containsKey("env")
        && StringUtilities.hasContent(
            envLevel)) { // Add in the 'ENV_LEVEL" environment variable when looking up sys.* cubes,
      // if there was not already an entry for it.
      input.put("env", envLevel);
    }
    if (!input.containsKey("username")) { // same as ENV_LEVEL, add it in if not already there.
      input.put("username", System.getProperty("user.name"));
    }
    Object urlCpLoader = cpCube.getCell(input);

    if (urlCpLoader instanceof URLClassLoader) {
      return (URLClassLoader) urlCpLoader;
    }

    throw new IllegalStateException(
        "If the sys.classpath cube exists it must return a URLClassLoader.");
  }
Exemplo n.º 2
0
  public static ApplicationID getApplicationID(
      String tenant, String app, Map<String, Object> coord) {
    ApplicationID.validateTenant(tenant);
    ApplicationID.validateApp(tenant);

    if (coord == null) {
      coord = new HashMap<>();
    }

    NCube bootCube = getCube(ApplicationID.getBootVersion(tenant, app), SYS_BOOTSTRAP);

    if (bootCube == null) {
      throw new IllegalStateException(
          "Missing " + SYS_BOOTSTRAP + " cube in the 0.0.0 version for the app: " + app);
    }

    ApplicationID bootAppId = (ApplicationID) bootCube.getCell(coord);
    String version = bootAppId.getVersion();
    String status = bootAppId.getStatus();
    String branch = bootAppId.getBranch();

    if (!tenant.equalsIgnoreCase(bootAppId.getTenant())) {
      LOG.warn(
          "sys.bootstrap cube for tenant '"
              + tenant
              + "', app '"
              + app
              + "' is returning a different tenant '"
              + bootAppId.getTenant()
              + "' than requested. Using '"
              + tenant
              + "' instead.");
    }

    if (!app.equalsIgnoreCase(bootAppId.getApp())) {
      LOG.warn(
          "sys.bootstrap cube for tenant '"
              + tenant
              + "', app '"
              + app
              + "' is returning a different app '"
              + bootAppId.getApp()
              + "' than requested. Using '"
              + app
              + "' instead.");
    }

    return new ApplicationID(tenant, app, version, status, branch);
  }