private Location getLocation(boolean required) { Collection<? extends Location> ll = Locations.getLocationsCheckingAncestors(getLocations(), this); if (ll.isEmpty()) { if (!required) return null; throw new IllegalStateException("No location available for "+this); } if (ll.size()>1) { throw new IllegalStateException("Ambiguous location for "+this+"; expected one but had "+ll); } return Iterables.getOnlyElement(ll); }
@Test public void testManaged() throws Exception { // TODO get exception in LocalhostMachineProvisioningLocation.removeChild because childLoc is "in use"; // this happens from the call to unmanage(loc), which first unmanaged the children. loc.release(childLoc); assertTrue(LocationPredicates.managed().apply(loc)); Locations.unmanage(loc); assertFalse(LocationPredicates.managed().apply(loc)); } }
public Maybe<SshMachineLocation> getMachine() { return Locations.findUniqueSshMachineLocation(entity.getLocations()); }
/** * As {@link LocationRegistry#getListOfLocationsManaged(Object)}, * but using {@link #coerceToLocationManaged(ManagementContext, Object)} * for more forgiving interpretations. * <p> * The caller is responsible for ensuring the resulting {@link Location} is unmanaged. */ public static Collection<? extends Location> coerceToCollectionOfLocationsManaged(ManagementContext mgmt, Object rawO) { if (rawO==null) return null; Object raw = rawO; if (raw instanceof Collection) { List<Location> result = MutableList.<Location>of(); for (Object o: (Collection<?>)raw) result.add(coerceToLocationManaged(mgmt, o)); return result; } if (raw instanceof String) { raw = Yamls.parseAll((String)raw).iterator().next(); if (raw instanceof Collection) return Locations.coerceToCollectionOfLocationsManaged(mgmt, raw); } return Collections.singletonList( coerceToLocationManaged(mgmt, raw) ); } }
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); }
@Override public boolean apply(@Nullable Location input) { return (input != null) && Locations.isManaged(input); } };
/** * @since 0.6.0 Added only for backwards compatibility, where locations are being created directly. * @deprecated in 0.6.0; use {@link LocationManager#createLocation(LocationSpec)} instead */ @Deprecated public static void manage(Location loc, ManagementContext managementContext) { Locations.manage(loc, managementContext); }
protected MachineLocation getMachine() { Supplier<MachineLocation> supplier = config().get(MACHINE); if (supplier != null) { return supplier.get(); } else { return Locations.findUniqueMachineLocation(entity.getLocations()).get(); } }
@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; }
protected void assertNotYetManaged() { if (!inConstruction && Locations.isManaged(this)) { LOG.warn("Configuration being made to {} after deployment; may not be supported in future versions", this); } //throw new IllegalStateException("Cannot set configuration "+key+" on active location "+this) }
Locations.manage(newLocation, getManagementContext());
Collection<? extends Location> locations = entity.getLocations(); if (!locations.isEmpty()) { Maybe<? extends Location> lo = Locations.findUniqueMachineLocation(locations); if (!lo.isPresent()) {
@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; } };
@Override public void start(Collection<? extends Location> locs) { addLocations(locs); List<Location> locations = MutableList.copyOf(Locations.getLocationsCheckingAncestors(locs, this)); connectSensors(); super.start(locations); }
protected JcloudsLocation replaceJcloudsLocation(String locationSpec) { if (machines != null && machines.size() > 0) { throw new IllegalStateException("Cannot replace jcloudsLocation after provisioning machine with old one"); } if (jcloudsLocation != null) { Locations.unmanage(jcloudsLocation); } jcloudsLocation = (JcloudsLocation) managementContext.getLocationRegistry().getLocationManaged( locationSpec, jcloudsLocationConfig(ImmutableMap.<Object, Object>of( JcloudsLocationConfig.COMPUTE_SERVICE_REGISTRY, computeServiceRegistry, JcloudsLocationConfig.WAIT_FOR_SSHABLE, "false", JcloudsLocationConfig.POLL_FOR_FIRST_REACHABLE_ADDRESS, "false"))); return jcloudsLocation; }
private boolean isMachineStopped() { // Don't rely on effector parameters, check if there is still a machine running. // If the entity was previously stopped with STOP_MACHINE_MODE=StopMode.NEVER // and a second time with STOP_MACHINE_MODE=StopMode.IF_NOT_STOPPED, then the // machine is still running, but there is no deterministic way to infer this from // the parameters alone. return Locations.findUniqueSshMachineLocation(this.getLocations()).isAbsent(); }
@Override public boolean apply(@Nullable Location input) { return (input != null) && Locations.isManaged(input); } }
Locations.manage(child, getManagementContext());
locations = Locations.getLocationsCheckingAncestors(locations, this); log.info("Starting entity "+this+" at "+locations);
@Override public void deleteLocation() { MarathonLocation location = getDynamicLocation(); if (location != null) { location.deregister(); Locations.unmanage(location); } sensors().set(LocationOwner.DYNAMIC_LOCATION, null); sensors().set(LocationOwner.LOCATION_NAME, null); }