public Task<V> build() {
      validate();

      return Tasks.<V>builder()
          .dynamic(false)
          .displayName("waiting on " + sensor.getName())
          .description("Waiting on sensor " + sensor.getName() + " from " + source)
          .tag("attributeWhenReady")
          .tag(BrooklynTaskTags.TRANSIENT_TASK_TAG)
          .body(new WaitInTaskForAttributeReady<T, V>(this))
          .build();
    }
    @Beta
    protected MultiBuilder(
        Iterable<? extends Entity> sources,
        AttributeSensor<T> sensor,
        Predicate<? super T> readiness) {
      builder = new Builder<T, V>(null, sensor);
      builder.readiness(readiness);

      for (Entity s : checkNotNull(sources, "sources")) {
        multiSource.add(new AttributeAndSensorCondition<T>(s, sensor, readiness));
      }
      this.name = "waiting on " + sensor.getName();
      this.descriptionBase =
          "waiting on "
              + sensor.getName()
              + " "
              + readiness
              + " from "
              + Iterables.size(sources)
              + " entit"
              + Strings.ies(sources);
    }
예제 #3
0
 private void configureEnrichers(Entity entity) {
   for (AttributeSensor sensor :
       Iterables.filter(entity.getEntityType().getSensors(), AttributeSensor.class)) {
     if ((DockerUtils.URL_SENSOR_NAMES.contains(sensor.getName())
             || sensor.getName().endsWith(".url")
             || URI.class.isAssignableFrom(sensor.getType()))
         && !DockerUtils.BLACKLIST_URL_SENSOR_NAMES.contains(sensor.getName())) {
       AttributeSensor<String> target = DockerUtils.<String>mappedSensor(sensor);
       entity.addEnricher(
           dockerHost
               .getSubnetTier()
               .uriTransformingEnricher(EntityAndAttribute.create(entity, sensor), target));
       Set<Hint<?>> hints = RendererHints.getHintsFor(sensor);
       for (Hint<?> hint : hints) {
         RendererHints.register(target, (NamedActionWithUrl) hint);
       }
       if (LOG.isDebugEnabled()) {
         LOG.debug("Mapped URL sensor: origin={}, mapped={}", sensor.getName(), target.getName());
       }
     } else if (PortAttributeSensorAndConfigKey.class.isAssignableFrom(sensor.getClass())) {
       AttributeSensor<String> target =
           DockerUtils.mappedPortSensor((PortAttributeSensorAndConfigKey) sensor);
       entity.addEnricher(
           dockerHost
               .getSubnetTier()
               .hostAndPortTransformingEnricher(
                   EntityAndAttribute.create(entity, sensor), target));
       if (LOG.isDebugEnabled()) {
         LOG.debug("Mapped port sensor: origin={}, mapped={}", sensor.getName(), target.getName());
       }
     }
   }
 }
  /** @deprecated since 0.7.0; use {@link #newBasicMemento(BrooklynObject)} instead */
  @Deprecated
  public static BasicEntityMemento.Builder newEntityMementoBuilder(Entity entityRaw) {
    EntityInternal entity = (EntityInternal) entityRaw;
    BasicEntityMemento.Builder builder = BasicEntityMemento.builder();
    populateBrooklynObjectMementoBuilder(entity, builder);

    EntityDynamicType definedType = BrooklynTypes.getDefinedEntityType(entity.getClass());

    // TODO the dynamic attributeKeys and configKeys are computed in the BasicEntityMemento
    // whereas effectors are computed here -- should be consistent!
    // (probably best to compute attrKeys and configKeys here)
    builder.effectors.addAll(entity.getEntityType().getEffectors());
    builder.effectors.removeAll(definedType.getEffectors().values());

    builder.isTopLevelApp = (entity instanceof Application && entity.getParent() == null);

    Map<ConfigKey<?>, Object> localConfig = entity.getConfigMap().getLocalConfig();
    for (Map.Entry<ConfigKey<?>, Object> entry : localConfig.entrySet()) {
      ConfigKey<?> key = checkNotNull(entry.getKey(), localConfig);
      Object value = configValueToPersistable(entry.getValue());
      builder.config.put(key, value);
    }

    Map<String, Object> localConfigUnmatched =
        MutableMap.copyOf(entity.getConfigMap().getLocalConfigBag().getAllConfig());
    for (ConfigKey<?> key : localConfig.keySet()) {
      localConfigUnmatched.remove(key.getName());
    }
    for (Map.Entry<String, Object> entry : localConfigUnmatched.entrySet()) {
      String key = checkNotNull(entry.getKey(), localConfig);
      Object value = entry.getValue();
      // TODO Not transforming; that code is deleted in another pending PR anyway!
      builder.configUnmatched.put(key, value);
    }

    @SuppressWarnings("rawtypes")
    Map<AttributeSensor, Object> allAttributes = entity.getAllAttributes();
    for (@SuppressWarnings("rawtypes")
    Map.Entry<AttributeSensor, Object> entry : allAttributes.entrySet()) {
      AttributeSensor<?> key = checkNotNull(entry.getKey(), allAttributes);
      if (key.getPersistenceMode() != SensorPersistenceMode.NONE) {
        Object value = entry.getValue();
        builder.attributes.put((AttributeSensor<?>) key, value);
      }
    }

    for (Location location : entity.getLocations()) {
      builder.locations.add(location.getId());
    }

    for (Entity child : entity.getChildren()) {
      builder.children.add(child.getId());
    }

    for (Policy policy : entity.getPolicies()) {
      builder.policies.add(policy.getId());
    }

    for (Enricher enricher : entity.getEnrichers()) {
      builder.enrichers.add(enricher.getId());
    }

    for (Feed feed : entity.feeds().getFeeds()) {
      builder.feeds.add(feed.getId());
    }

    Entity parentEntity = entity.getParent();
    builder.parent = (parentEntity != null) ? parentEntity.getId() : null;

    if (entity instanceof Group) {
      for (Entity member : ((Group) entity).getMembers()) {
        builder.members.add(member.getId());
      }
    }

    return builder;
  }