org.apache.brooklyn.api.location.LocationSpec Java Examples
The following examples show how to use
org.apache.brooklyn.api.location.LocationSpec.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CatalogYamlLocationTest.java From brooklyn-server with Apache License 2.0 | 6 votes |
@Test public void testNameInItemMetadata() throws Exception { String yaml = Joiner.on("\n").join( "brooklyn.catalog:", " version: 0.1.2", " itemType: location", " items:", " - id: loc1", " name: My name in item metadata", " item:", " type: localhost"); addCatalogItems(yaml); LocationDefinition def = mgmt().getLocationRegistry().getDefinedLocationByName("loc1"); LocationSpec<? extends Location> spec = mgmt().getLocationRegistry().getLocationSpec(def).get(); assertEquals(spec.getDisplayName(), "My name in item metadata"); }
Example #2
Source File: BrooklynAccessUtilsTest.java From brooklyn-server with Apache License 2.0 | 6 votes |
@Test public void testBrooklynAccessibleAddressFailsIfNoMappingAndNoHostname() throws Exception { final int privatePort = 8080; SshMachineLocation machine = mgmt.getLocationManager().createLocation(LocationSpec.create(SshMachineLocation.class)); entity = app.createAndManageChild(EntitySpec.create(TestEntity.class) .configure(BrooklynAccessUtils.PORT_FORWARDING_MANAGER, pfm) .location(machine)); try { BrooklynAccessUtils.getBrooklynAccessibleAddress(entity, privatePort); fail(); } catch (IllegalStateException e) { if (!e.toString().contains("no host.name")) throw e; // success } }
Example #3
Source File: SshMachineLocationIntegrationTest.java From brooklyn-server with Apache License 2.0 | 6 votes |
@Test(groups = "Integration") public void testExtractingConnectablePassphraselessKey() throws Exception { Maybe<LocationSpec<? extends Location>> lhps = mgmt.getLocationRegistry().getLocationSpec("named:localhost-passphrase"); Preconditions.checkArgument(lhps.isPresent(), "This test requires a localhost named location called 'localhost-passphrase' (which should have a passphrase set)"); LocalhostMachineProvisioningLocation lhp = (LocalhostMachineProvisioningLocation) mgmt.getLocationManager().createLocation(lhps.get()); SshMachineLocation sm = lhp.obtain(); SshjToolBuilder builder = SshjTool.builder().host(sm.getAddress().getHostName()).user(sm.getUser()); KeyPair data = sm.findKeyPair(); if (data!=null) builder.privateKeyData(SecureKeys.toPem(data)); String password = sm.findPassword(); if (password!=null) builder.password(password); SshjTool tool = builder.build(); tool.connect(); ByteArrayOutputStream out = new ByteArrayOutputStream(); int result = tool.execCommands(MutableMap.<String,Object>of("out", out), Arrays.asList("date")); Assert.assertTrue(out.toString().contains(" 20"), "out="+out); assertEquals(result, 0); }
Example #4
Source File: JcloudsLocationTest.java From brooklyn-server with Apache License 2.0 | 6 votes |
@Test public void testInheritsGeoFromLocationMetadataProperties() throws Exception { // in location-metadata.properties: // [email protected]=38.909202 // [email protected]=-77.47314 ConfigBag allConfig = ConfigBag.newInstance() .configure(IMAGE_ID, "bogus") .configure(CLOUD_PROVIDER, "softlayer") .configure(CLOUD_REGION_ID, "wdc01") .configure(ACCESS_IDENTITY, "bogus") .configure(ACCESS_CREDENTIAL, "bogus") .configure(MACHINE_CREATE_ATTEMPTS, 1); Map<String, Object> brooklynProperties = managementContext.getBrooklynProperties().asMapWithStringKeys(); FakeLocalhostWithParentJcloudsLocation ll = managementContext.getLocationManager().createLocation(LocationSpec.create(FakeLocalhostWithParentJcloudsLocation.class) .configure(new JcloudsPropertiesFromBrooklynProperties().getJcloudsProperties("softlayer", "wdc01", null, brooklynProperties)) .configure(allConfig.getAllConfig())); MachineLocation l = ll.obtain(); log.info("loc:" +l); HostGeoInfo geo = HostGeoInfo.fromLocation(l); log.info("geo: "+geo); Assert.assertEquals(geo.latitude, 38.909202d, 0.00001); Assert.assertEquals(geo.longitude, -77.47314d, 0.00001); }
Example #5
Source File: MultiLocationTest.java From brooklyn-server with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") @BeforeMethod(alwaysRun=true) public void setUp() throws Exception { managementContext = LocalManagementContextForTests.newInstance(); mac1a = managementContext.getLocationManager().createLocation(LocationSpec.create(SshMachineLocation.class) .displayName("mac1a") .configure("address", Networking.getInetAddressWithFixedName("1.1.1.1"))); mac1b = managementContext.getLocationManager().createLocation(LocationSpec.create(SshMachineLocation.class) .displayName("mac1b") .configure("address", Networking.getInetAddressWithFixedName("1.1.1.2"))); mac2a = managementContext.getLocationManager().createLocation(LocationSpec.create(SshMachineLocation.class) .displayName("mac2a") .configure("address", Networking.getInetAddressWithFixedName("1.1.1.3"))); mac2b = managementContext.getLocationManager().createLocation(LocationSpec.create(SshMachineLocation.class) .displayName("mac2b") .configure("address", Networking.getInetAddressWithFixedName("1.1.1.4"))); loc1 = managementContext.getLocationManager().createLocation(LocationSpec.create(FixedListMachineProvisioningLocation.class) .displayName("loc1") .configure("machines", MutableSet.of(mac1a, mac1b))); loc2 = managementContext.getLocationManager().createLocation(LocationSpec.create(FixedListMachineProvisioningLocation.class) .displayName("loc2") .configure("machines", MutableSet.of(mac2a, mac2b))); multiLoc = managementContext.getLocationManager().createLocation(LocationSpec.create(MultiLocation.class) .displayName("multiLoc") .configure("subLocations", ImmutableList.of(loc1, loc2))); }
Example #6
Source File: JcloudsLocationTest.java From brooklyn-server with Apache License 2.0 | 6 votes |
@Test public void testInvokesCustomizerCallbacks() throws Exception { JcloudsLocationCustomizer customizer = Mockito.mock(JcloudsLocationCustomizer.class); MachineLocationCustomizer machineCustomizer = Mockito.mock(MachineLocationCustomizer.class); // Mockito.when(customizer.customize(Mockito.any(JcloudsLocation.class), Mockito.any(ComputeService.class), Mockito.any(JcloudsSshMachineLocation.class))); ConfigBag allConfig = ConfigBag.newInstance() .configure(CLOUD_PROVIDER, "aws-ec2") .configure(ACCESS_IDENTITY, "bogus") .configure(ACCESS_CREDENTIAL, "bogus") .configure(JcloudsLocationConfig.JCLOUDS_LOCATION_CUSTOMIZERS, ImmutableList.of(customizer)) .configure(JcloudsLocation.MACHINE_LOCATION_CUSTOMIZERS, ImmutableList.of(machineCustomizer)) .configure(MACHINE_CREATE_ATTEMPTS, 1); FakeLocalhostWithParentJcloudsLocation ll = managementContext.getLocationManager().createLocation(LocationSpec.create(FakeLocalhostWithParentJcloudsLocation.class).configure(allConfig.getAllConfig())); JcloudsMachineLocation l = (JcloudsMachineLocation)ll.obtain(); Mockito.verify(customizer, Mockito.times(1)).customize(ll, null, l); Mockito.verify(customizer, Mockito.never()).preRelease(l); Mockito.verify(customizer, Mockito.never()).postRelease(l); Mockito.verify(machineCustomizer, Mockito.times(1)).customize(l); Mockito.verify(machineCustomizer, Mockito.never()).preRelease(l); ll.release(l); Mockito.verify(customizer, Mockito.times(1)).preRelease(l); Mockito.verify(customizer, Mockito.times(1)).postRelease(l); Mockito.verify(machineCustomizer, Mockito.times(1)).preRelease(l); }
Example #7
Source File: AccessManagerTest.java From brooklyn-server with Apache License 2.0 | 6 votes |
@Test public void testLocationManagementAllowed() throws Exception { // default is allowed Location loc1 = mgmt.getLocationManager().createLocation(LocationSpec.create(SimulatedLocation.class)); // when forbidden, should give error mgmt.getAccessManager().setLocationManagementAllowed(false); try { mgmt.getLocationManager().createLocation(LocationSpec.create(SimulatedLocation.class)); fail(); } catch (Exception e) { // expect it to be forbidden if (Exceptions.getFirstThrowableOfType(e, IllegalStateException.class) == null) { throw e; } } // but when forbidden, still allowed to create entity mgmt.getEntityManager().createEntity(EntitySpec.create(TestApplication.class)); // when re-enabled, can create entities again mgmt.getAccessManager().setLocationManagementAllowed(true); Location loc3 = mgmt.getLocationManager().createLocation(LocationSpec.create(SimulatedLocation.class)); assertEquals(ImmutableSet.copyOf(mgmt.getLocationManager().getLocations()), ImmutableSet.of(loc1, loc3)); }
Example #8
Source File: SoftwareProcessRebindNotRunningEntityTest.java From brooklyn-server with Apache License 2.0 | 6 votes |
@BeforeMethod(alwaysRun=true) @Override public void setUp() throws Exception { super.setUp(); latches = Lists.newCopyOnWriteArrayList(); machineSpec = LocationSpec.create(SshMachineLocation.class) .configure("address", "1.2.3.4") .configure(SshMachineLocation.SSH_TOOL_CLASS, RecordingSshTool.class.getName()); locationProvisioner = app().getManagementContext().getLocationManager().createLocation(LocationSpec.create(FixedListMachineProvisioningLocation.class) .configure(FixedListMachineProvisioningLocation.MACHINE_SPECS, ImmutableList.<LocationSpec<? extends MachineLocation>>of( machineSpec))); executor = MoreExecutors.listeningDecorator(Executors.newCachedThreadPool()); RecordingSshTool.clear(); }
Example #9
Source File: LocationRegistryTest.java From brooklyn-server with Apache License 2.0 | 6 votes |
@Test public void testNonsenseParentSupported() { BrooklynProperties properties = BrooklynProperties.Factory.newEmpty(); properties.put(LocalhostLocationResolver.LOCALHOST_ENABLED.getName(), false); properties.put("brooklyn.location.named.bogus_will_fail_eventually", "totally_bogus"); mgmt = LocalManagementContextForTests.newInstance(properties); Assert.assertTrue( findLocationMatching("bogus_will_fail_eventually") ); Maybe<LocationSpec<?>> l = mgmt.getLocationRegistry().getLocationSpec("bogus_will_fail_eventually"); Assert.assertTrue( l.isAbsent(), "Should not have resolved: "+l ); try { l.get(); Asserts.shouldHaveFailedPreviously(); } catch (Exception e) { Asserts.expectedFailureContains(e, "bogus_will_fail", "totally_bogus"); } }
Example #10
Source File: SoftwareProcessEntityRebindTest.java From brooklyn-server with Apache License 2.0 | 6 votes |
@Test public void testReleasesLocationOnStopAfterRebinding() throws Exception { MyService origE = origApp.createAndManageChild(EntitySpec.create(MyService.class) .configure(BrooklynConfigKeys.SKIP_ON_BOX_BASE_DIR_RESOLUTION, true)); MyProvisioningLocation origLoc = mgmt().getLocationManager().createLocation(LocationSpec.create(MyProvisioningLocation.class) .displayName("mylocname")); origApp.start(ImmutableList.of(origLoc)); assertEquals(origLoc.inUseCount.get(), 1); newApp = rebind(); MyProvisioningLocation newLoc = (MyProvisioningLocation) Iterables.getOnlyElement(newApp.getLocations()); assertEquals(newLoc.inUseCount.get(), 1); newApp.stop(); assertEquals(newLoc.inUseCount.get(), 0); }
Example #11
Source File: LocalhostMachineProvisioningLocation.java From brooklyn-server with Apache License 2.0 | 6 votes |
@Override protected void provisionMore(int size, Map<?,?> flags) { for (int i=0; i<size; i++) { Map<Object,Object> flags2 = MutableMap.<Object,Object>builder() .putAll(flags) .put("address", (address != null ? address : getLocalhostInetAddress())) .build(); // copy inherited keys for ssh; // shouldn't be necessary but not sure that all contexts traverse the hierarchy // NOTE: changed Nov 2013 to copy only those ssh config keys actually set, rather than all of them // TODO should take the plunge and try removing this altogether! // (or alternatively switch to copying all ancestor keys) for (HasConfigKey<?> k: SshMachineLocation.ALL_SSH_CONFIG_KEYS) { if (config().getRaw(k).isPresent()) flags2.put(k, config().get(k)); } if (isManaged()) { addChild(LocationSpec.create(LocalhostMachine.class).configure(flags2)); } else { addChild(new LocalhostMachine(flags2)); // TODO legacy way } } }
Example #12
Source File: SoftwareProcessRebindNotRunningEntityTest.java From brooklyn-server with Apache License 2.0 | 6 votes |
@Override public SshMachineLocation obtain(Map<?,?> flags) throws NoMachinesAvailableException { callHistory.add(new CallInfo("obtain", ImmutableList.of(flags))); CountDownLatch calledLatch = config().get(OBTAIN_CALLED_LATCH); CountDownLatch blockedLatch = config().get(OBTAIN_BLOCKED_LATCH); LocationSpec<SshMachineLocation> machineSpec = config().get(MACHINE_SPEC); if (calledLatch != null) calledLatch.countDown(); try { if (blockedLatch != null) blockedLatch.await(); } catch (InterruptedException e) { throw Exceptions.propagate(e); } return getManagementContext().getLocationManager().createLocation(machineSpec); }
Example #13
Source File: FixedListMachineProvisioningLocationTest.java From brooklyn-server with Apache License 2.0 | 6 votes |
@Test @SuppressWarnings("unchecked") public void testFailsWhenMachineChooserReturnsAlreadyAllocatedMachine() throws Exception { final SshMachineLocation machine1 = mgmt.getLocationManager().createLocation(LocationSpec.create(SshMachineLocation.class).configure("address", Networking.getInetAddressWithFixedName("1.1.1.1"))); final SshMachineLocation machine2 = mgmt.getLocationManager().createLocation(LocationSpec.create(SshMachineLocation.class).configure("address", Networking.getInetAddressWithFixedName("1.1.1.2"))); List<SshMachineLocation> machines = ImmutableList.of(machine1, machine2); Function<Iterable<? extends MachineLocation>, MachineLocation> chooser = new Function<Iterable<? extends MachineLocation>, MachineLocation>() { @Override public MachineLocation apply(Iterable<? extends MachineLocation> input) { return machine1; } }; provisioner2 = mgmt.getLocationManager().createLocation(LocationSpec.create(FixedListMachineProvisioningLocation.class) .configure("machines", machines) .configure(FixedListMachineProvisioningLocation.MACHINE_CHOOSER, chooser)); provisioner2.obtain(); // Should fail when tries to return same machine for a second time try { provisioner2.obtain(); fail("Expected "+IllegalStateException.class.getSimpleName()); } catch (IllegalStateException e) { if (!e.toString().contains("Machine chooser attempted to choose ")) throw e; } }
Example #14
Source File: UrlMappingTest.java From brooklyn-library with Apache License 2.0 | 6 votes |
@BeforeMethod(alwaysRun=true) @Override public void setUp() throws Exception { super.setUp(); EntitySpec<StubAppServer> serverSpec = EntitySpec.create(StubAppServer.class); cluster = app().createAndManageChild(EntitySpec.create(DynamicCluster.class) .configure(DynamicCluster.INITIAL_SIZE, initialClusterSize) .configure(DynamicCluster.MEMBER_SPEC, serverSpec)); urlMapping = app().createAndManageChild(EntitySpec.create(UrlMapping.class) .configure("domain", "localhost") .configure("target", cluster)); app().start( ImmutableList.of( mgmt().getLocationManager().createLocation( LocationSpec.create(LocalhostMachineProvisioningLocation.class)) )); log.info("app's location managed: "+mgmt().getLocationManager().isManaged(Iterables.getOnlyElement(app().getLocations()))); log.info("clusters's location managed: "+mgmt().getLocationManager().isManaged(Iterables.getOnlyElement(cluster.getLocations()))); }
Example #15
Source File: CleanOrphanedLocationsTest.java From brooklyn-server with Apache License 2.0 | 5 votes |
@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(); }
Example #16
Source File: HostLocationResolver.java From brooklyn-server with Apache License 2.0 | 5 votes |
@Override public LocationSpec<?> newLocationSpecFromString(String spec, Map<?, ?> locationFlags, LocationRegistry registry) { // Extract args from spec ParsedSpec parsedSpec = specParser.parse(spec); Map<String, String> argsMap = parsedSpec.argsMap; if (argsMap.isEmpty()) { throw new IllegalArgumentException("Invalid host spec (no host supplied): "+spec); } else if (argsMap.size() == 1 && Iterables.get(argsMap.values(), 0) == null) { // only given ip or hostname argsMap = ImmutableMap.of("hosts", Iterables.get(argsMap.keySet(), 0)); } else if (!(argsMap.containsKey("host") || argsMap.containsKey("hosts"))) { throw new IllegalArgumentException("Invalid host spec (no host supplied): "+spec); } // Find generic applicable properties Map globalProperties = registry.getProperties(); String namedLocation = (String) locationFlags.get(LocationInternal.NAMED_SPEC_NAME.getName()); Map<String, Object> filteredProperties = new LocationPropertiesFromBrooklynProperties().getLocationProperties(null, namedLocation, globalProperties); ConfigBag flags = ConfigBag.newInstance(locationFlags).putIfAbsent(filteredProperties); flags.remove(LocationInternal.NAMED_SPEC_NAME); // Generate target spec String target = "byon("+KeyValueParser.toLine(argsMap)+")"; Maybe<LocationSpec<?>> testResolve = managementContext.getLocationRegistry().getLocationSpec(target); if (!testResolve.isPresent()) { throw new IllegalArgumentException("Invalid target location '" + target + "' for location '"+HOST+"': "+ Exceptions.collapseText( Maybe.getException(testResolve) ), Maybe.getException(testResolve)); } return LocationSpec.create(SingleMachineProvisioningLocation.class) .configure("location", target) .configure("locationFlags", flags.getAllConfig()) .configure(LocationConfigUtils.finalAndOriginalSpecs(spec, locationFlags, globalProperties, namedLocation)); }
Example #17
Source File: DockerLocationResolverTest.java From brooklyn-server with Apache License 2.0 | 5 votes |
@Test public void testGivesCorrectLocationType() { LocationSpec<?> spec = getLocationSpec("docker"); assertEquals(spec.getType(), DockerJcloudsLocation.class); DockerJcloudsLocation loc = resolve("docker"); assertTrue(loc instanceof DockerJcloudsLocation, "loc=" + loc); }
Example #18
Source File: BrooklynYamlLocationResolver.java From brooklyn-server with Apache License 2.0 | 5 votes |
public LocationSpec<?> resolveLocationFromMap(Map<?,?> location) { if (location.size() > 1) { throw new UserFacingException("Illegal parameter for 'location'; expected a single entry in map ("+location+")"); } Object key = Iterables.getOnlyElement(location.keySet()); Object value = location.get(key); if (!(key instanceof String)) { throw new UserFacingException("Illegal parameter for 'location'; expected String key ("+location+")"); } if (!(value instanceof Map)) { throw new UserFacingException("Illegal parameter for 'location'; expected config map ("+location+")"); } return resolveLocation((String)key, (Map<?,?>)value); }
Example #19
Source File: LocationConfigTest.java From brooklyn-server with Apache License 2.0 | 5 votes |
@Test public void testConfigBagContainsMatchesForConfigKeyName() throws Exception { LocationInternal loc = managementContext.getLocationManager().createLocation(LocationSpec.create(MyLocation.class) .configure("mylocation.myconfig", "myval1") .configure("mylocation.myconfigwithflagname", "myval2")); assertEquals(loc.config().getBag().getAllConfig(), ImmutableMap.of("mylocation.myconfig", "myval1", "mylocation.myconfigwithflagname", "myval2")); assertEquals(loc.config().getLocalBag().getAllConfig(), ImmutableMap.of("mylocation.myconfig", "myval1", "mylocation.myconfigwithflagname", "myval2")); }
Example #20
Source File: InfrastructureDeploymentTestCaseTest.java From brooklyn-server with Apache License 2.0 | 5 votes |
@BeforeMethod public void setup() { app = TestApplication.Factory.newManagedInstanceForTests(); managementContext = app.getManagementContext(); loc = managementContext.getLocationManager() .createLocation(LocationSpec.create(LocalhostMachineProvisioningLocation.class) .configure("name", LOC_NAME)); infrastructureLoc = managementContext.getLocationManager() .createLocation(LocationSpec.create(LocalhostMachineProvisioningLocation.class) .configure("name", INFRASTRUCTURE_LOC_NAME)); }
Example #21
Source File: DefinedLocationByIdResolver.java From brooklyn-server with Apache License 2.0 | 5 votes |
@Override public LocationSpec<? extends Location> newLocationSpecFromString(String spec, Map<?, ?> locationFlags, LocationRegistry registry) { String id = spec; if (spec.toLowerCase().startsWith(ID+":")) { id = spec.substring( (ID+":").length() ); } LocationDefinition ld = registry.getDefinedLocationById(id); ld.getSpec(); return ((BasicLocationRegistry)registry).getLocationSpec(ld, locationFlags).get(); }
Example #22
Source File: MultiLocation.java From brooklyn-server with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") @Override public MachineProvisioningLocation<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().getLocalBag().getAllConfig()) // FIXME Should this just be inherited? .configure(newFlags)); }
Example #23
Source File: FixedListMachineProvisioningLocationTest.java From brooklyn-server with Apache License 2.0 | 5 votes |
@Test @SuppressWarnings("unchecked") public void testMachineChooser() throws Exception { List<SshMachineLocation> machines = Lists.newArrayList(); for (int i = 0; i < 10; i++) { machines.add(mgmt.getLocationManager().createLocation(LocationSpec.create(SshMachineLocation.class).configure("address", Networking.getInetAddressWithFixedName("1.1.1."+i)))); } final List<SshMachineLocation> desiredOrder = randomized(machines); Function<Iterable<? extends MachineLocation>, MachineLocation> chooser = new Function<Iterable<? extends MachineLocation>, MachineLocation>() { @Override public MachineLocation apply(Iterable<? extends MachineLocation> input) { for (SshMachineLocation contender : desiredOrder) { if (Iterables.contains(input, contender)) { return contender; } } Assert.fail("No intersection of input="+input+" and desiredOrder="+desiredOrder); return null; // unreachable code } }; provisioner2 = mgmt.getLocationManager().createLocation(LocationSpec.create(FixedListMachineProvisioningLocation.class) .configure("machines", machines) .configure(FixedListMachineProvisioningLocation.MACHINE_CHOOSER, chooser)); List<SshMachineLocation> result = Lists.newArrayList(); for (int i = 0; i < machines.size(); i++) { result.add(provisioner2.obtain()); } assertEquals(result, desiredOrder, "result="+result+"; desired="+desiredOrder); LOG.debug("chooser's desiredOrder="+desiredOrder); }
Example #24
Source File: RebindLocalhostLocationTest.java From brooklyn-server with Apache License 2.0 | 5 votes |
@Override @BeforeMethod(alwaysRun=true) public void setUp() throws Exception { super.setUp(); origLoc = origManagementContext.getLocationManager().createLocation(LocationSpec.create(LocalhostMachineProvisioningLocation.class)); origChildLoc = origLoc.obtain(); }
Example #25
Source File: SshMachineLocationTest.java From brooklyn-server with Apache License 2.0 | 5 votes |
@Test public void testConfigurePrivateAddresses() throws Exception { SshMachineLocation host2 = mgmt.getLocationManager().createLocation(LocationSpec.create(SshMachineLocation.class) .configure("address", Networking.getReachableLocalHost()) .configure(SshMachineLocation.PRIVATE_ADDRESSES, ImmutableList.of("1.2.3.4")) .configure(BrooklynConfigKeys.SKIP_ON_BOX_BASE_DIR_RESOLUTION, true)); assertEquals(host2.getPrivateAddresses(), ImmutableSet.of("1.2.3.4")); assertEquals(Machines.getSubnetIp(host2).get(), "1.2.3.4"); assertEquals(Machines.getSubnetHostname(host2).get(), "1.2.3.4"); }
Example #26
Source File: DynamicClusterWithAvailabilityZonesRebindTest.java From brooklyn-server with Apache License 2.0 | 5 votes |
@Test public void testRebindWithDefaultZoneFailureDetector() throws Exception { // Start and then unmanage a cluster (so it's detector was populated). // Do this in case the ZoneFailureDetector is shared! SimulatedLocation loc = mgmt().getLocationManager().createLocation(LocationSpec.create(SimulatedLocationWithZoneExtension.class) .configure(SimulatedLocationWithZoneExtension.ZONE_NAMES, ImmutableList.of("zone1", "zone2")) .configure(SimulatedLocationWithZoneExtension.ZONE_FAIL_CONDITIONS, ImmutableMap.of("zone1", Predicates.alwaysTrue()))); DynamicCluster cluster = app().addChild(EntitySpec.create(DynamicCluster.class) .configure(DynamicCluster.ENABLE_AVAILABILITY_ZONES, true) .configure(DynamicCluster.INITIAL_SIZE, 2) .configure(DynamicCluster.MEMBER_SPEC, EntitySpec.create(TestEntity.class))); cluster.start(ImmutableList.of(loc)); Entities.unmanage(cluster); Locations.unmanage(loc); // Start a second cluster SimulatedLocation locUnrelated = mgmt().getLocationManager().createLocation(LocationSpec.create(SimulatedLocationWithZoneExtension.class) .configure(SimulatedLocationWithZoneExtension.ZONE_NAMES, ImmutableList.of("zone3", "zone4")) .configure(SimulatedLocationWithZoneExtension.ZONE_FAIL_CONDITIONS, ImmutableMap.of("zone3", Predicates.alwaysTrue()))); DynamicCluster clusterUnrelated = app().addChild(EntitySpec.create(DynamicCluster.class) .configure(DynamicCluster.ENABLE_AVAILABILITY_ZONES, true) .configure(DynamicCluster.INITIAL_SIZE, 2) .configure(DynamicCluster.MEMBER_SPEC, EntitySpec.create(TestEntity.class))); clusterUnrelated.start(ImmutableList.of(locUnrelated)); rebind(); // Confirm that cluster is usable DynamicCluster newClusterUnrelated = (DynamicCluster) mgmt().getEntityManager().getEntity(clusterUnrelated.getId()); newClusterUnrelated.resize(4); }
Example #27
Source File: ByonLocationResolver.java From brooklyn-server with Apache License 2.0 | 5 votes |
protected LocationSpec<? extends MachineLocation> parseMachine(String val, Class<? extends MachineLocation> locationClass, Map<String, ?> defaults, String specForErrMsg) { Map<String, Object> machineConfig = Maps.newLinkedHashMap(); UserAndHostAndPort userAndHostAndPort = parseUserAndHostAndPort(val); String host = userAndHostAndPort.getHostAndPort().getHostText().trim(); machineConfig.put("address", host); try { InetAddress.getByName(host.trim()); } catch (Exception e) { throw new IllegalArgumentException("Invalid host '"+host+"' specified in '"+specForErrMsg+"': "+e); } if (userAndHostAndPort.getUser() != null) { machineConfig.put("user", userAndHostAndPort.getUser()); } if (userAndHostAndPort.getHostAndPort().hasPort()) { machineConfig.put("port", userAndHostAndPort.getHostAndPort().getPort()); } for (Map.Entry<String, ?> entry : defaults.entrySet()) { if (!machineConfig.containsKey(entry.getKey())) { machineConfig.put(entry.getKey(), entry.getValue()); } } return LocationSpec.create(locationClass).configure(machineConfig); }
Example #28
Source File: ReflectiveEntityDriverFactoryTest.java From brooklyn-server with Apache License 2.0 | 5 votes |
@BeforeMethod public void setUp() throws Exception { super.setUp(); sshLocation = mgmt.getLocationManager().createLocation(LocationSpec.create(SshMachineLocation.class) .configure("address", "localhost")); paasLocation = mgmt.getLocationManager().createLocation(LocationSpec.create(TestPaasLocation.class)); factory = new ReflectiveEntityDriverFactory(); entity = app.addChild(EntitySpec.create(MyDriverDependentEntity.class) .configure(MyDriverDependentEntity.DRIVER_CLASS, MyDriver.class)); }
Example #29
Source File: ServerResourceTest.java From brooklyn-server with Apache License 2.0 | 5 votes |
@Test public void testExportPersistedState() throws Exception { BasicApplication app = manager.getEntityManager().createEntity(EntitySpec.create(BasicApplication.class)); Location loc = manager.getLocationManager().createLocation(LocationSpec.create(SshMachineLocation.class)); byte[] zip = client().path("/server/ha/persist/export").get(byte[].class); List<String> entryNames = listEntryNames(zip); assertTrue(Iterables.tryFind(entryNames, StringPredicates.containsLiteral(app.getId())).isPresent(), "entries="+entryNames); assertTrue(Iterables.tryFind(entryNames, StringPredicates.containsLiteral(loc.getId())).isPresent(), "entries="+entryNames); }
Example #30
Source File: JcloudsRebindLiveTest.java From brooklyn-server with Apache License 2.0 | 5 votes |
protected void assertSshable(Map<?,?> machineConfig) { SshMachineLocation machineWithThatConfig = mgmt().getLocationManager().createLocation(LocationSpec.create(SshMachineLocation.class) .configure(machineConfig)); try { assertSshable(machineWithThatConfig); } finally { Streams.closeQuietly(machineWithThatConfig); } }