@Override public void init() { super.init(); }
@Override public ToStringHelper string() { return super.string() .add("owner", framework); }
@Override public void addChild(Location child) { super.addChild(child); machines.add((T)child); }
@Override public Map<String, String> toMetadataRecord() { ImmutableMap.Builder<String, String> builder = ImmutableMap.builder(); if (getDisplayName() != null) builder.put("displayName", getDisplayName()); if (getParent() != null && getParent().getDisplayName() != null) { builder.put("parentDisplayName", getParent().getDisplayName()); } return builder.build(); } }
@SuppressWarnings({ "rawtypes", "unchecked" }) private synchronized void unmanageNonRecursiveClearItsFields(Location loc, ManagementTransitionMode mode) { if (mode.isDestroying()) { ((AbstractLocation)loc).setParent(null, true); Location parent = ((AbstractLocation)loc).getParent(); if (parent instanceof ProvisioningLocation<?>) { try { ((ProvisioningLocation)parent).release(loc); } catch (Exception e) { Exceptions.propagateIfFatal(e); log.debug("Error releasing "+loc+" in its parent "+parent+": "+e); } } } else { // if not destroying, don't change the parent's children list ((AbstractLocation)loc).setParent(null, false); } // clear config to help with GC; everyone says you're not supposed to, but this really seems to help, // else config bag is littered with refs to entities etc and some JVMs seem to keep them around much longer ((AbstractLocation)loc).config().removeAllLocalConfig(); }
location.setDisplayName(spec.getDisplayName()); location.setCatalogItemIdAndSearchPath(spec.getCatalogItemId(), spec.getCatalogItemIdSearchPath()); location.setManagementContext(managementContext); location.configure(ConfigBag.newInstance().putAll(spec.getFlags()).putAll(spec.getConfig()).getAllConfig()); location.config().set((ConfigKey)entry.getKey(), entry.getValue()); location.init();
@Override public void rebind() { super.rebind(); isRebindingValWhenRebinding = isRebinding(); } }
@Deprecated public AbstractLocation configure(Map<?,?> properties) { assertNotYetManaged(); config().putAll(properties); setParent(config().get(PARENT_LOCATION)); config().removeKey(PARENT_LOCATION); properties = ConfigUtilsInternal.setAllConfigKeys(properties, getLocationTypeInternal().getConfigKeys().values(), this); name.set((String) removeIfPossible(properties, "displayName")); displayNameAutoGenerated = false; } else if (properties.containsKey("name")) { name.set((String) removeIfPossible(properties, "name")); displayNameAutoGenerated = false; } else if (isLegacyConstruction()) { name.set(getClass().getSimpleName()+":"+getId().substring(0, Math.min(getId().length(),4))); displayNameAutoGenerated = true; Object rawCodes = removeIfPossible(properties, "iso3166"); Set<String> codes; if (rawCodes instanceof CharSequence) { codes = TypeCoercions.coerce(rawCodes, new TypeToken<Set<String>>() {}); config().set(LocationConfigKeys.ISO_3166, codes);
@Test public void testSettingParentLocation() { AbstractLocation location = new ConcreteLocation(); AbstractLocation locationSub = new ConcreteLocation(); locationSub.setParent(location); assertEquals(ImmutableList.copyOf(location.getChildren()), ImmutableList.of(locationSub)); assertEquals(locationSub.getParent(), location); }
if (isManaged()) { if (!getManagementContext().getLocationManager().isManaged(child)) { Locations.manage(child, getManagementContext()); } else if (getManagementContext() != null) { if (((LocalLocationManager)getManagementContext().getLocationManager()).getLocationEvenIfPreManaged(child.getId()) == null) { ((ManagementContextInternal)getManagementContext()).prePreManage(child); child.setParent(this); onChanged();
@Test public void testAddChildToParentLocationReturnsExpectedLocation() { AbstractLocation parent = new ConcreteLocation(MutableMap.of("id", "1")); AbstractLocation child = new ConcreteLocation(MutableMap.of("id", "2")); parent.addChild(child); assertEquals(child.getParent(), parent); assertEquals(ImmutableList.copyOf(parent.getChildren()), ImmutableList.of(child)); }
public void setParent(Location newParent, boolean updateChildListParents) { if (newParent == this) { throw new IllegalArgumentException("Location cannot be its own parent: "+this); } if (newParent == parent.get()) { return; // no-op; already have desired parent } if (parent.get() != null) { Location oldParent = parent.get(); parent.set(null); if (updateChildListParents) ((AbstractLocation)oldParent).removeChild(this); } // TODO Should we support a location changing parent? The resulting unmanage/manage might cause problems. // The code above suggests we do, but maybe we should warn or throw error, or at least test it! parent.set(newParent); if (newParent != null) { if (updateChildListParents) ((AbstractLocation)newParent).addChild(this); } onChanged(); }
@Test public void testContainsLocation() { AbstractLocation location = new ConcreteLocation(); AbstractLocation locationSub = new ConcreteLocation(); locationSub.setParent(location); assertTrue(location.containsLocation(location)); assertTrue(location.containsLocation(locationSub)); assertFalse(locationSub.containsLocation(location)); }
@Test public void constructorParentLocationReturnsExpectedLocation() { AbstractLocation parent = new ConcreteLocation(MutableMap.of("name", "Middle Earth")); AbstractLocation child = new ConcreteLocation(MutableMap.of("name", "The Shire", "parentLocation", parent)); assertEquals(child.getParent(), parent); assertEquals(ImmutableList.copyOf(parent.getChildren()), ImmutableList.of(child)); }
@Override public void setParent(Location newParent) { setParent(newParent, true); }
@Test public void queryingNameReturnsNameGivenInConstructor() { String name = "Outer Mongolia"; AbstractLocation location = new ConcreteLocation(MutableMap.of("name", "Outer Mongolia")); assertEquals(location.getDisplayName(), name);; }
@Override public void rebind() { super.rebind(); if (config().get(LOCATION_NAME) != null) { register(); } }
@Test public void testClearingParentLocation() { AbstractLocation location = new ConcreteLocation(); AbstractLocation locationSub = new ConcreteLocation(); locationSub.setParent(location); locationSub.setParent(null); assertEquals(ImmutableList.copyOf(location.getChildren()), Collections.emptyList()); assertEquals(locationSub.getParent(), null); }
@Test public void nullNameAndParentLocationIsAcceptable() { AbstractLocation location = new ConcreteLocation(MutableMap.of("name", null, "parentLocation", null)); assertEquals(location.getDisplayName(), null); assertEquals(location.getParent(), null); }
protected void setParent(RebindContext rebindContext, LocationMemento memento) { Location parent = (memento.getParent() != null) ? rebindContext.lookup().lookupLocation(memento.getParent()) : null; if (parent != null) { location.setParent(parent); } else if (memento.getParent() != null) { LOG.warn("Ignoring parent {} of location {}({}), as cannot be found", new Object[] {memento.getParent(), memento.getType(), memento.getId()}); } } }