@Override public Maybe<T> apply(T input) { return Maybe.fromNullable(input); } };
@Override public Maybe<T> apply(T input) { return Maybe.fromNullable(input); } };
public Maybe<HttpResponse> getResponse() { return Maybe.fromNullable(response); }
/** as {@link #get()} but always wrapped in a {@link Maybe}, absent if null */ public @Nonnull Maybe<Object> getMaybe() { return Maybe.fromNullable(focus); }
/** Creates a new Maybe object out of the {@link Optional} argument */ public static <T> Maybe<T> fromOptional(Optional<T> value) { return Maybe.fromNullable(value.orNull()); }
public Maybe<T> solidify() { return Maybe.fromNullable(value.get()); } SoftlyPresent<T> usingAfterExpiry(Maybe<T> defaultValue) {
/** as {@link #get(Class)} but always wrapped in a {@link Maybe}, absent if null * @throws ClassCastException if object exists here but of the wrong type */ public @Nonnull <V> Maybe<V> getMaybe(Class<V> type) { return Maybe.fromNullable(get(type)); }
/** as {@link #getFocusMap()} but always wrapped in a {@link Maybe}, absent if null * @throws ClassCastException if object exists here but of the wrong type */ public @Nonnull Maybe<T> getFocusMapMaybe() { return Maybe.fromNullable(getFocusMap()); }
public static Maybe<String> getSubnetIp(Location where) { // TODO Too much duplication between the ip and hostname methods String result = null; if (where instanceof HasSubnetHostname) { result = ((HasSubnetHostname) where).getSubnetIp(); } if (where instanceof HasNetworkAddresses) { Set<String> privateAddrs = ((HasNetworkAddresses) where).getPrivateAddresses(); if (privateAddrs.size() > 0) { result = Iterables.get(privateAddrs, 0); } } if (result == null && where instanceof MachineLocation) { InetAddress addr = ((MachineLocation) where).getAddress(); if (addr != null) result = addr.getHostAddress(); } log.debug("computed subnet host ip {} for {}", result, where); return Maybe.fromNullable(result); }
/** * Scans the entities, determines the IP address and hostname for each entity, and returns a map that connects from * IP address to fully-qualified domain name. * * @param entities entities to search for name/IP information. * @param addressSensor the sensor containing the IP address for each entity. * @return a map with an entry for each entity, mapping its IP address to its fully-qualified domain name. */ public static Map<String, String> gatherIpHostnameMapping(Iterable<? extends Entity> entities, AttributeSensor<String> addressSensor) { Map<String, String> mapping = Maps.newHashMap(); for (Entity e : entities) { Optional<String> name = Optional.fromNullable(e.getAttribute(AmbariNode.FQDN)) .or(Optional.fromNullable(Machines.findSubnetOrPublicHostname(e).orNull())); Maybe<String> ip = Maybe.fromNullable(e.getAttribute(addressSensor)); if (name.isPresent() && ip.isPresentAndNonNull()) { mapping.put(ip.get(), name.get()); } else { LOG.debug("No hostname or ip found for {}: hostname={}, ip={}", new Object[]{e, name.orNull(), ip.orNull()}); } } LOG.debug("Generated host mapping: " + Joiner.on(", ").withKeyValueSeparator("=").join(mapping)); return mapping; } }
public static Maybe<String> getSubnetHostname(Location where) { // TODO Should we look at HasNetworkAddresses? But that's not a hostname. String hostname = null; if (where instanceof HasSubnetHostname) { hostname = ((HasSubnetHostname) where).getSubnetHostname(); } if (hostname == null && where instanceof MachineLocation) { Maybe<String> subnetIp = getSubnetIp(where); if (subnetIp.isPresent()) { hostname = subnetIp.get(); } else { InetAddress addr = ((MachineLocation) where).getAddress(); if (addr != null) hostname = addr.getHostAddress(); } } log.debug("computed subnet hostname {} for {}", hostname, where); // TODO if Maybe.absent(message) appears, could/should use that // TODO If no machine available, should we throw new IllegalStateException("Cannot find hostname for "+where); return Maybe.fromNullable(hostname); }
@SuppressWarnings({ "unchecked" }) protected void setEntityLoadingConfig() { this.producer = getConfig(PRODUCER); this.fromHardcodedProducers= getConfig(FROM_HARDCODED_PRODUCERS); this.defaultMemberValue = (T) getConfig(DEFAULT_MEMBER_VALUE); this.fromMembers = Maybe.fromNullable(getConfig(FROM_MEMBERS)).or(fromMembers); this.fromChildren = Maybe.fromNullable(getConfig(FROM_CHILDREN)).or(fromChildren); this.entityFilter = (Predicate<? super Entity>) (getConfig(ENTITY_FILTER) == null ? Predicates.alwaysTrue() : getConfig(ENTITY_FILTER)); this.valueFilter = (Predicate<? super T>) (getConfig(VALUE_FILTER) == null ? getDefaultValueFilter() : getConfig(VALUE_FILTER)); setEntityLoadingTargetConfig(); }
public static WeightedParameter getFieldConfig(ConfigKey<?> config, Field configKeyField) { if (configKeyField == null) return null; CatalogConfig catalogConfig = configKeyField.getAnnotation(CatalogConfig.class); String label = config.getName(); Double priority = null; Boolean pinned = Boolean.FALSE; if (catalogConfig != null) { label = Maybe.fromNullable(catalogConfig.label()).or(config.getName()); priority = catalogConfig.priority(); pinned = catalogConfig.pinned(); } @SuppressWarnings({ "unchecked", "rawtypes" }) SpecParameter<?> param = new BasicSpecParameter(label, pinned, config); return new WeightedParameter(priority, param); }
public static Maybe<String> findSubnetOrPrivateIp(Entity entity) { // see comments in findSubnetOrPrivateHostname String hn = entity.getAttribute(Attributes.ADDRESS); if (hn!=null) { Maybe<String> sn = findSubnetIp(entity); if (sn.isPresent()) return sn; return Maybe.of(hn); } Maybe<MachineLocation> l = findUniqueMachineLocation(entity.getLocations()); if (!l.isPresent()) return Maybe.absent(); InetAddress addr = l.get().getAddress(); if (addr==null) return Maybe.absent(); return Maybe.fromNullable(addr.getHostAddress()); }
public static Maybe<String> findSubnetOrPublicHostname(Entity entity) { String hn = entity.getAttribute(Attributes.HOSTNAME); if (hn!=null) { // attributes already set, see if there was a SUBNET_HOSTNAME set // note we rely on (public) hostname being set _after_ subnet_hostname, // to prevent tiny possibility of races resulting in hostname being returned // becasue subnet is still being looked up -- see MachineLifecycleEffectorTasks Maybe<String> sn = findSubnetHostname(entity); if (sn.isPresent()) return sn; // short-circuit discovery if attributes have been set already return Maybe.of(hn); } Maybe<MachineLocation> l = findUniqueMachineLocation(entity.getLocations()); if (!l.isPresent()) return Maybe.absent(); InetAddress addr = l.get().getAddress(); if (addr==null) return Maybe.absent(); return Maybe.fromNullable(addr.getHostName()); }
@Override public boolean apply(Object item, AssemblyTemplateConstructor atc) { if (!(item instanceof Service)) return false; Service svc = (Service)item; String type = svc.getServiceType(); for (ResolvableLink<PlatformComponentTemplate> t: platform.platformComponentTemplates().links()) { if (type.equals(t.getName())) { PlatformComponentTemplate pct = PlatformComponentTemplate.builder() .name(svc.getName()) .customAttribute("serviceType", type) .description(Maybe.fromNullable(svc.getDescription()).or(t.resolve().getDescription())) .build(); if (atc!=null) { atc.add(pct); if (instantiator!=null) atc.instantiator(instantiator); } return true; } } return false; }