/**
   * Walks the contents of a ManagementContext, to create a corresponding memento.
   *
   * @deprecated since 0.7.0; will be moved to test code; generate each entity/location memento
   *     separately
   */
  @Deprecated
  public static BrooklynMemento newBrooklynMemento(ManagementContext managementContext) {
    BrooklynMementoImpl.Builder builder = BrooklynMementoImpl.builder();

    for (Application app : managementContext.getApplications()) {
      builder.applicationIds.add(app.getId());
    }
    for (Entity entity : managementContext.getEntityManager().getEntities()) {
      builder.entities.put(
          entity.getId(), ((EntityInternal) entity).getRebindSupport().getMemento());

      for (Location location : entity.getLocations()) {
        if (!builder.locations.containsKey(location.getId())) {
          for (Location locationInHierarchy : TreeUtils.findLocationsInHierarchy(location)) {
            if (!builder.locations.containsKey(locationInHierarchy.getId())) {
              builder.locations.put(
                  locationInHierarchy.getId(),
                  ((LocationInternal) locationInHierarchy).getRebindSupport().getMemento());
            }
          }
        }
      }
    }
    for (LocationMemento memento : builder.locations.values()) {
      if (memento.getParent() == null) {
        builder.topLevelLocationIds.add(memento.getId());
      }
    }

    BrooklynMemento result = builder.build();
    MementoValidators.validateMemento(result);
    return result;
  }
  /**
   * checks the supplied candidate user and password against the expect password (or SHA-256 + SALT
   * thereof) defined as brooklyn properties.
   */
  public static boolean checkExplicitUserPassword(
      ManagementContext mgmt, String user, String password) {
    BrooklynProperties properties = (BrooklynProperties) mgmt.getConfig();
    String expectedPassword = properties.getConfig(BrooklynWebConfig.PASSWORD_FOR_USER(user));
    String salt = properties.getConfig(BrooklynWebConfig.SALT_FOR_USER(user));
    String expectedSha256 = properties.getConfig(BrooklynWebConfig.SHA256_FOR_USER(user));

    return checkPassword(password, expectedPassword, expectedSha256, salt);
  }
 protected void runTest(Map<String, ?> flags) throws Exception {
   String tag = getClass().getSimpleName().toLowerCase();
   Map<String, ?> allFlags =
       MutableMap.<String, Object>builder()
           .put("tags", ImmutableList.of(tag))
           .putAll(flags)
           .build();
   jcloudsLocation = ctx.getLocationRegistry().getLocationManaged(PROVIDER, allFlags);
   doTest(jcloudsLocation);
 }
  public BrooklynCampPlatform(PlatformRootSummary root, ManagementContext managementContext) {
    super(root);
    addPlatform(new BrooklynImmutableCampPlatform(root, managementContext));

    this.bmc = managementContext;

    addMatchers();
    addInterpreters();

    managementContext.addPropertiesReloadListener(
        new PropertiesReloadListener() {
          private static final long serialVersionUID = -3739276553334749184L;

          @Override
          public void reloaded() {
            setConfigKeyAtManagmentContext();
          }
        });
  }
  private synchronized void initialize() {
    if (allowedUsers != null) return;

    StringConfigMap properties = mgmt.getConfig();

    allowedUsers = new LinkedHashSet<String>();
    String users = properties.getConfig(BrooklynWebConfig.USERS);
    if (users == null) {
      LOG.warn("REST has no users configured; no one will be able to log in!");
    } else if ("*".equals(users)) {
      LOG.info("REST allowing any user (so long as valid password is set)");
      allowAnyUserWithValidPass = true;
    } else {
      StringTokenizer t = new StringTokenizer(users, ",");
      while (t.hasMoreElements()) {
        allowedUsers.add(("" + t.nextElement()).trim());
      }
      LOG.info("REST allowing users: " + allowedUsers);
    }
  }
 /**
  * finds and returns the {@link CampPlatform} registered for the management context, or null if
  * none
  */
 @Nullable
 public static CampPlatform findPlatform(ManagementContext mgmt) {
   return mgmt.getConfig().getConfig(BrooklynCampConstants.CAMP_PLATFORM);
 }
Exemplo n.º 7
0
 public static void waitForPersisted(ManagementContext managementContext)
     throws InterruptedException, TimeoutException {
   managementContext.getRebindManager().waitForPendingComplete(TIMEOUT, true);
 }
 protected void deleteItem(ManagementContext mgmt, String symbolicName, String version) {
   mgmt.getCatalog().deleteCatalogItem(symbolicName, version);
   LOG.info("Deleted item from catalog: {}:{}", symbolicName, version);
   Assert.assertNull(mgmt.getTypeRegistry().get(symbolicName, version));
 }
Exemplo n.º 9
0
 @Override
 public void reloaded() {
   Location resolved = context.getLocationRegistry().resolve(definition);
   context.getLocationRegistry().updateDefinedLocation(definition);
   context.getLocationManager().manage(resolved);
 }