@Override public void unmanage(Location item, ManagementTransitionMode info) { if (isInitialManagementContextReal()) { ((LocationManagerInternal)initialManagementContext.getLocationManager()).unmanage(item, info); } else { throw new IllegalStateException("Non-deployment context "+this+" is not valid for this operation"); } }
@Override @Deprecated public Maybe<Location> resolve(String spec, Boolean manage, Map locationFlags) { if (manage!=null) { locationFlags = MutableMap.copyOf(locationFlags); locationFlags.put(LocalLocationManager.CREATE_UNMANAGED, !manage); } Maybe<LocationSpec<? extends Location>> lSpec = getLocationSpec(spec, locationFlags); if (lSpec.isAbsent()) return (Maybe)lSpec; return Maybe.of((Location)mgmt.getLocationManager().createLocation(lSpec.get())); }
@Test public void testRebindWhenOnlyByonLocationSpec() throws Exception { int before = mgmt().getLocationManager().getLocations().size(); String spec = "byon(hosts=\"1.1.1.1\")"; getLocationSpec(spec); rebind(); int after = mgmt().getLocationManager().getLocations().size(); assertEquals(after, before); }
@Override @SuppressWarnings("unchecked") public FixedListMachineProvisioningLocation<T> newSubLocation(Map<?,?> newFlags) { // TODO shouldn't have to copy config bag as it should be inherited (but currently it is not used inherited everywhere; just most places) return getManagementContext().getLocationManager().createLocation(LocationSpec.create(getClass()) .parent(this) .configure(config().getAllLocalRaw()) // FIXME Should this just be inherited? .configure(newFlags)); }
@Test public void testConfigBagContainsMatchesForFlagName() throws Exception { // Prefers flag-name, over config-key's name LocationInternal loc = managementContext.getLocationManager().createLocation(LocationSpec.create(MyLocation.class) .configure("myconfigflagname", "myval")); assertEquals(loc.config().getBag().getAllConfig(), ImmutableMap.of("mylocation.myconfigwithflagname", "myval", "myconfigflagname", "myval")); assertEquals(loc.config().getLocalBag().getAllConfig(), ImmutableMap.of("mylocation.myconfigwithflagname", "myval", "myconfigflagname", "myval")); Assert.assertEquals(loc.getAllConfig(true), ImmutableMap.of("mylocation.myconfigwithflagname", "myval", "myconfigflagname", "myval")); Assert.assertEquals(loc.getAllConfig(false), ImmutableMap.of("mylocation.myconfigwithflagname", "myval", "myconfigflagname", "myval")); }
@Test(groups="WIP") public void testChildConfigBagInheritsFlagNameFromParentSetsOwnConfigKey() throws Exception { LocationInternal loc = managementContext.getLocationManager().createLocation(LocationSpec.create(MyLocation.class) .configure("mychildconfigflagname", "myval")); LocationInternal child = managementContext.getLocationManager().createLocation(LocationSpec.create(MyChildLocation.class) .parent(loc)); assertEquals(child.config().getBag().getAllConfig(), ImmutableMap.of("mychildlocation.myconfigwithflagname", "myval")); assertEquals(child.config().getLocalBag().getAllConfig(), ImmutableMap.of()); Assert.assertEquals(child.getAllConfig(true), ImmutableMap.of("mychildlocation.myconfigwithflagname", "myval")); Assert.assertEquals(child.getAllConfig(false), ImmutableMap.of()); }
@Test public void testKeepsLocationsReferencedInEntityLocs() throws Exception { SshMachineLocation loc = mgmt().getLocationManager().createLocation(LocationSpec.create(SshMachineLocation.class)); SshMachineLocation loc2 = mgmt().getLocationManager().createLocation(LocationSpec.create(SshMachineLocation.class)); origApp.addLocations(ImmutableList.of(loc, loc2)); assertTransformIsNoop(); }
@SuppressWarnings({ "unchecked", "rawtypes" }) private ConcreteLocation createConcrete(Class<?> extensionType, Object extension) { // this cast is needed to make IntelliJ happy return (ConcreteLocation) mgmt.getLocationManager().createLocation(LocationSpec.create(ConcreteLocation.class).extension((Class)extensionType, extension)); }
@Test public void testChildConfigBagInheritsUnmatchedAtParent() throws Exception { LocationInternal loc = managementContext.getLocationManager().createLocation(LocationSpec.create(MyLocation.class) .configure("mychildlocation.myconfig", "myval1") .configure("notThere", "notThereVal")); LocationInternal child = managementContext.getLocationManager().createLocation(LocationSpec.create(MyChildLocation.class) .parent(loc)); assertEquals(child.config().getBag().getAllConfig(), ImmutableMap.of("mychildlocation.myconfig", "myval1", "notThere", "notThereVal")); assertEquals(child.config().getLocalBag().getAllConfig(), ImmutableMap.of()); Assert.assertEquals(child.getAllConfig(true), ImmutableMap.of("mychildlocation.myconfig", "myval1", "notThere", "notThereVal")); Assert.assertEquals(child.getAllConfig(false), ImmutableMap.of()); }
@BeforeMethod(alwaysRun=true) public void setup() throws Exception { app = TestApplication.Factory.newManagedInstanceForTests(); mgmt = app.getManagementContext(); LocalhostMachineProvisioningLocation localhost = mgmt.getLocationManager().createLocation( LocationSpec.create(LocalhostMachineProvisioningLocation.class)); host = localhost.obtain(); app.start(Arrays.asList(host)); }
@Test public void testKeepsReferencesOfReachableLocation() throws Exception { Location referantLoc = mgmt().getLocationManager().createLocation(LocationSpec.create(SshMachineLocation.class)); Location refereeLoc = mgmt().getLocationManager().createLocation(LocationSpec.create(SshMachineLocation.class) .configure(ConfigKeys.newConfigKey(Object.class, "myconfig"), referantLoc)); origApp.addLocations(ImmutableList.of(refereeLoc)); assertTransformIsNoop(); }
@Test public void testIsRebinding() throws Exception { LocationChecksIsRebinding origLoc = origManagementContext.getLocationManager().createLocation(LocationSpec.create(LocationChecksIsRebinding.class)); rebind(); LocationChecksIsRebinding newLoc = (LocationChecksIsRebinding) newManagementContext.getLocationManager().getLocation(origLoc.getId()); assertTrue(newLoc.isRebindingValWhenRebinding()); assertFalse(newLoc.isRebinding()); }
@Test public void testProviderRenamed() throws Exception { JcloudsLocation loc = resolve("openstack-mitaka-nova:http://hostdoesnotexist.com:5000", ImmutableMap.of("identity", "dummy", "credential", "dummy")); assertComputeServiceType(loc, "openstack-nova"); rebind(); JcloudsLocation newLoc = (JcloudsLocation) mgmt().getLocationManager().getLocation(loc.getId()); assertComputeServiceType(newLoc, "openstack-nova"); }
@BeforeMethod(alwaysRun=true) @Override public void setUp() throws Exception { super.setUp(); loc = mgmt().getLocationManager().createLocation(LocationSpec.create(WinRmMachineLocation.class) .configure("address", "1.2.3.4") .configure(WinRmMachineLocation.WINRM_TOOL_CLASS, RecordingWinRmTool.class.getName())); RecordingWinRmTool.clear(); }
@BeforeMethod(alwaysRun=true) @Override public void setUp() throws Exception { super.setUp(); loc = mgmt().getLocationManager().createLocation(LocationSpec.create(WinRmMachineLocation.class) .configure("address", "1.2.3.4") .configure(WinRmMachineLocation.WINRM_TOOL_CLASS, RecordingWinRmTool.class.getName())); RecordingWinRmTool.clear(); }
@Test public void testKeepsLocationsReferencedInSensor() throws Exception { SshMachineLocation loc = mgmt().getLocationManager().createLocation(LocationSpec.create(SshMachineLocation.class)); origApp.sensors().set(Sensors.newSensor(Object.class, "mysensor"), loc); assertTransformIsNoop(); }
@Test public void testKeepsLocationsReferencedInConfigKeyDefault() throws Exception { SshMachineLocation loc = mgmt().getLocationManager().createLocation(LocationSpec.create(SshMachineLocation.class)); origApp.config().set(ConfigKeys.newConfigKey(MachineLocation.class, "myconfig", "my description", loc), (MachineLocation)null); assertTransformIsNoop(); }
@Test public void testLocationTags() throws Exception { Location origLoc = origManagementContext.getLocationManager().createLocation(LocationSpec.create(MyLocation.class)); origLoc.tags().addTag("foo"); origLoc.tags().addTag(origApp); origApp.start(ImmutableList.of(origLoc)); newApp = rebind(); Location newLoc = newManagementContext.getLocationManager().getLocation(origLoc.getId()); Asserts.assertEqualsIgnoringOrder(newLoc.tags().getTags(), ImmutableSet.of("foo", newApp)); }
@Test public void testKeepsLocationsReferencedByPolicy() throws Exception { Location loc = mgmt().getLocationManager().createLocation(LocationSpec.create(SshMachineLocation.class)); origApp.policies().add(PolicySpec.create(MyPolicy.class) .configure(ConfigKeys.newConfigKey(Object.class, "myconfig"), loc)); assertTransformIsNoop(); }
@Test public void testKeepsLocationsReferencedByFeed() throws Exception { Location loc = mgmt().getLocationManager().createLocation(LocationSpec.create(SshMachineLocation.class)); MyFeed feed = new MyFeed(); feed.config().set(ConfigKeys.newConfigKey(Object.class, "myconfig"), loc); origApp.feeds().add(feed); assertTransformIsNoop(); }