protected Location getLocation(@Nullable Collection<? extends Location> locations) {
    if (locations == null || locations.isEmpty()) locations = entity().getLocations();
    if (locations.isEmpty()) {
      MachineProvisioningLocation<?> provisioner =
          entity().getAttribute(SoftwareProcess.PROVISIONING_LOCATION);
      if (provisioner != null) locations = Arrays.<Location>asList(provisioner);
    }
    locations = Locations.getLocationsCheckingAncestors(locations, entity());

    Maybe<MachineLocation> ml = Locations.findUniqueMachineLocation(locations);
    if (ml.isPresent()) return ml.get();

    if (locations.isEmpty())
      throw new IllegalArgumentException("No locations specified when starting " + entity());
    if (locations.size() != 1 || Iterables.getOnlyElement(locations) == null)
      throw new IllegalArgumentException(
          "Ambiguous locations detected when starting " + entity() + ": " + locations);
    return Iterables.getOnlyElement(locations);
  }
Exemplo n.º 2
0
  @Override
  public void deleteLocation() {
    MesosLocation location = getDynamicLocation();

    if (location != null) {
      location.deregister();
      Locations.unmanage(location);
    }

    sensors().set(LocationOwner.DYNAMIC_LOCATION, null);
    sensors().set(LocationOwner.LOCATION_NAME, null);
  }
    @Override
    public Void call(ConfigBag parameters) {
      Collection<? extends Location> locations = null;

      Object locationsRaw = parameters.getStringKey(LOCATIONS.getName());
      locations =
          Locations.coerceToCollectionOfLocationsManaged(
              entity().getManagementContext(), locationsRaw);

      if (locations == null) {
        // null/empty will mean to inherit from parent
        locations = Collections.emptyList();
      }

      start(locations);
      return null;
    }