Java Code Examples for org.apache.brooklyn.api.location.Location#getConfig()
The following examples show how to use
org.apache.brooklyn.api.location.Location#getConfig() .
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: AbstractGeoDnsServiceTest.java From brooklyn-library with Apache License 2.0 | 6 votes |
@Override protected boolean addTargetHost(Entity e) { if (!getConfig(ADD_ANYTHING)) { return super.addTargetHost(e); } else { //ignore geo lookup, override parent menu if (e.getLocations().isEmpty()) { log.info("GeoDns TestService ignoring target host {} (no location)", e); return false; } Location l = Iterables.getOnlyElement(e.getLocations()); HostGeoInfo geoInfo = new HostGeoInfo("<address-ignored>", l.getDisplayName(), l.getConfig(LocationConfigKeys.LATITUDE), l.getConfig(LocationConfigKeys.LONGITUDE)); log.info("GeoDns TestService adding target host {} {}", e, geoInfo); targetHosts.put(e, geoInfo); return true; } }
Example 2
Source File: BlobStoreContextFactoryImpl.java From brooklyn-server with Apache License 2.0 | 5 votes |
@Override public BlobStoreContext newBlobStoreContext(Location location) { String rawProvider = checkNotNull(location.getConfig(LocationConfigKeys.CLOUD_PROVIDER), "provider must not be null"); String provider = DeserializingJcloudsRenamesProvider.INSTANCE.applyJcloudsRenames(rawProvider); String identity = checkNotNull(location.getConfig(LocationConfigKeys.ACCESS_IDENTITY), "identity must not be null"); String credential = checkNotNull(location.getConfig(LocationConfigKeys.ACCESS_CREDENTIAL), "credential must not be null"); String endpoint = location.getConfig(CloudLocationConfig.CLOUD_ENDPOINT); Properties overrides = new Properties(); // * Java 7,8 bug workaround - sockets closed by GC break the internal bookkeeping // of HttpUrlConnection, leading to invalid handling of the "HTTP/1.1 100 Continue" // response. Coupled with a bug when using SSL sockets reads will block // indefinitely even though a read timeout is explicitly set. // * Java 6 ignores the header anyways as it is included in its restricted headers black list. // * Also there's a bug in SL object store which still expects Content-Length bytes // even when it responds with a 408 timeout response, leading to incorrectly // interpreting the next request (triggered by above problem). overrides.setProperty(Constants.PROPERTY_STRIP_EXPECT_HEADER, "true"); // Add extra jclouds-specific configuration Map<String, Object> extra = Maps.filterKeys(((LocationInternal)location).config().getBag().getAllConfig(), Predicates.containsPattern("^jclouds\\.")); if (extra.size() > 0) { LOG.debug("Configuring custom jclouds property overrides for {}: {}", provider, Sanitizer.sanitize(extra)); } overrides.putAll(Maps.filterValues(extra, Predicates.notNull())); ContextBuilder contextBuilder = ContextBuilder.newBuilder(provider).credentials(identity, credential); contextBuilder.modules(MutableList.copyOf(getCommonModules())); if (!org.apache.brooklyn.util.text.Strings.isBlank(endpoint)) { contextBuilder.endpoint(endpoint); } contextBuilder.overrides(overrides); BlobStoreContext context = contextBuilder.buildView(BlobStoreContext.class); return context; }
Example 3
Source File: LocalUsageManager.java From brooklyn-server with Apache License 2.0 | 5 votes |
/** * Adds this location event to the usage record for the given location (creating the usage * record if one does not already exist). */ @Override public void recordLocationEvent(final Location loc, final Lifecycle state) { // TODO This approach (i.e. recording events on manage/unmanage would not work for // locations that are reused. For example, in a FixedListMachineProvisioningLocation // the ssh machine location is returned to the pool and handed back out again. // But maybe the solution there is to hand out different instances so that one user // can't change the config of the SshMachineLocation to subsequently affect the next // user. // // TODO Should perhaps extract the location storage methods into their own class, // but no strong enough feelings yet... checkNotNull(loc, "location"); if (loc.getConfig(AbstractLocation.TEMPORARY_LOCATION)) { log.info("Ignoring location lifecycle usage event for {} (state {}), because location is a temporary location", loc, state); return; } checkNotNull(state, "state of location %s", loc); if (loc.getId() == null) { log.error("Ignoring location lifecycle usage event for {} (state {}), because location has no id", loc, state); return; } if (managementContext.getStorage() == null) { log.warn("Cannot store location lifecycle usage event for {} (state {}), because storage not available", loc, state); return; } Object callerContext = loc.getConfig(LocationConfigKeys.CALLER_CONTEXT); if (callerContext != null && callerContext instanceof Entity) { Entity caller = (Entity) callerContext; recordLocationEvent(loc, caller, state); } else { // normal for high-level locations log.trace("Not recording location lifecycle usage event for {} in state {}, because no caller context", new Object[] {loc, state}); } }
Example 4
Source File: EntityLocationUtils.java From brooklyn-server with Apache License 2.0 | 4 votes |
protected boolean isLocatedLocation(Location l) { return l.getConfig(LocationConfigKeys.LATITUDE)!=null && l.getConfig(LocationConfigKeys.LONGITUDE)!=null; }
Example 5
Source File: HostGeoInfo.java From brooklyn-server with Apache License 2.0 | 4 votes |
/** returns null if cannot be set */ public static HostGeoInfo fromLocation(Location l) { if (l==null) return null; Location la = l; HostGeoInfo resultFromLocation = null; while (la!=null) { if (la instanceof HasHostGeoInfo) { resultFromLocation = ((HasHostGeoInfo)l).getHostGeoInfo(); if (resultFromLocation!=null) break; } la = la.getParent(); } if (resultFromLocation!=null && l==la) { // from the location return resultFromLocation; } // resultFromLocation may be inherited, in which case we will copy it later InetAddress address = findIpAddress(l); Object latitude = l.getConfig(LocationConfigKeys.LATITUDE); Object longitude = l.getConfig(LocationConfigKeys.LONGITUDE); if (resultFromLocation!=null && (latitude == null || longitude == null)) { latitude = resultFromLocation.latitude; longitude = resultFromLocation.longitude; } if (address!=null && (latitude == null || longitude == null)) { HostGeoInfo geo = fromIpAddress(address); if (geo==null) return null; latitude = geo.latitude; longitude = geo.longitude; } if (latitude==null || longitude==null) return null; Exception error=null; try { latitude = TypeCoercions.castPrimitive(latitude, Double.class); longitude = TypeCoercions.castPrimitive(longitude, Double.class); } catch (Exception e) { Exceptions.propagateIfFatal(e); error = e; } if (error!=null || !(latitude instanceof Double) || !(longitude instanceof Double)) throw new IllegalArgumentException("Location "+l+" specifies invalid type of lat/long: " + "lat="+latitude+" (type "+(latitude==null ? null : latitude.getClass())+"); " + "lon="+longitude+" (type "+(longitude==null ? null : longitude.getClass())+")", error); HostGeoInfo result = new HostGeoInfo(address!=null ? address.getHostAddress() : null, l.getDisplayName(), (Double) latitude, (Double) longitude); if (l instanceof AbstractLocation) { ((AbstractLocation)l).setHostGeoInfo(result); } return result; }