@SuppressWarnings("unchecked") @Override public T apply(Maybe<JsonElement> input) { if (input.isAbsentOrNull()) { return (T) null; } String jsonString = input.get().toString(); Object rawElement = JsonPath.read(jsonString, path); return (T) rawElement; } };
@Override public void editAlertNotification(String name, String description, Boolean global, String notificationType, List<String> alertStates, List<String> ambariDispatchRecipients, String mailSmtpHost, Integer mailSmtpPort, String mailSmtpFrom, Boolean mailSmtpAuth) { final Maybe<Effector<?>> effector = EffectorUtils.findEffector(getMasterAmbariServer().getEntityType().getEffectors(), "editAlertNotification"); if (effector.isAbsentOrNull()) { throw new IllegalStateException("Cannot get the editAlertNotification effector"); } getMasterAmbariServer().invoke(effector.get(), ImmutableMap.<String, Object>builder() .put("Notification Name", name) .put("Description", description) .put("Global", global) .put("Notification Type", notificationType) .put("Alert States", alertStates) .put("Ambari Dispatch Recipients", ambariDispatchRecipients) .put("SMTP Host", mailSmtpHost) .put("SMTP Port", mailSmtpPort) .put("SMTP From", mailSmtpFrom) .put("SMTP Auth", mailSmtpAuth) .build()); }
@Override public void addAlertNotification(String name, String description, Boolean global, String notificationType, List<String> alertStates, List<String> ambariDispatchRecipients, String mailSmtpHost, Integer mailSmtpPort, String mailSmtpFrom, Boolean mailSmtpAuth) { final Maybe<Effector<?>> effector = EffectorUtils.findEffector(getMasterAmbariServer().getEntityType().getEffectors(), "addAlertNotification"); if (effector.isAbsentOrNull()) { throw new IllegalStateException("Cannot get the addAlertNotification effector"); } getMasterAmbariServer().invoke(effector.get(), ImmutableMap.<String, Object>builder() .put("Notification Name", name) .put("Description", description) .put("Global", global) .put("Notification Type", notificationType) .put("Alert States", alertStates) .put("Ambari Dispatch Recipients", ambariDispatchRecipients) .put("SMTP Host", mailSmtpHost) .put("SMTP Port", mailSmtpPort) .put("SMTP From", mailSmtpFrom) .put("SMTP Auth", mailSmtpAuth) .build()); }
public void deleteAlertNotification(String name) { final Maybe<Effector<?>> effector = EffectorUtils.findEffector(getMasterAmbariServer().getEntityType().getEffectors(), "editAlertNotification"); if (effector.isAbsentOrNull()) { throw new IllegalStateException("Cannot get the editAlertNotification effector"); } getMasterAmbariServer().invoke(effector.get(), ImmutableMap.<String, Object>builder() .put("Notification Name", name) .build()); }
protected void assertSucceeds(List<Map<String, Object>> assertions, HostAndPort endpoint) { Maybe<Object> checkReachableMaybe = getOnlyAssertionsValue(assertions, REACHABLE_KEY); boolean checkReachable = checkReachableMaybe.isAbsentOrNull() || Boolean.TRUE.equals(TypeCoercions.coerce(checkReachableMaybe.get(), Boolean.class)); boolean reachable = Networking.isReachable(endpoint); Asserts.assertEquals(reachable, checkReachable, endpoint+" "+(reachable ? "" : "not ")+"reachable"); }
@Override public void addAlertGroup(String name,List<Integer> definitions) { final Maybe<Effector<?>> effector = EffectorUtils.findEffector(getMasterAmbariServer().getEntityType().getEffectors(), "addAlertGroup"); if (effector.isAbsentOrNull()) { throw new IllegalStateException("Cannot get the addAlertGroup effector"); } getMasterAmbariServer().invoke(effector.get(), ImmutableMap.of( "name", name, "definitions", definitions )); }
if (ip.isAbsentOrNull()) { LOG.debug("{} has no IP address, not setting hostname", e); continue;
protected Effector<?> getEffector() { String effectorName = config().get(EFFECTOR); Maybe<Effector<?>> effector = getEntity().getEntityType().getEffectorByName(effectorName); if (effector.isAbsentOrNull()) { throw new IllegalStateException("Cannot find effector " + effectorName + " on entity " + getEntity()); } return effector.get(); }
@Override public void addHostsToHostGroup(String hostgroupName, List<AmbariAgent> hosts) { final Maybe<Effector<?>> effector = EffectorUtils.findEffector(getMasterAmbariServer().getEntityType().getEffectors(), "addHostsToHostGroup"); if (effector.isAbsentOrNull()) { throw new IllegalStateException("Cannot get the addHostsToHostGroup effector"); } getMasterAmbariServer().invoke(effector.get(), ImmutableMap.of( "Blueprint Name", getConfig(AmbariCluster.BLUEPRINT_NAME), "Hostgroup Name", hostgroupName, "Hosts", Lists.transform(hosts, mapAmbariNodeToFQDN), "Cluster Name", getConfig(AmbariCluster.CLUSTER_NAME) )); }
@Override public void setEntity(EntityLocal entity) { /* * A warning to future modifiers of this method: it is called on rebind * so any changes must be compatible with existing persisted state. */ super.setEntity(entity); Sensor<? extends Collection<?>> sensor = checkNotNull(getConfig(TRIGGER_SENSOR), "Value required for " + TRIGGER_SENSOR.getName()); checkArgument(Strings.isNonBlank(getConfig(PARAMETER_NAME)), "Value required for " + PARAMETER_NAME.getName()); // Fail straight away if neither effector is found. if (getEffector(getOnAddedEffector()).isAbsentOrNull() && getEffector(getOnRemovedEffector()).isAbsentOrNull()) { throw new IllegalArgumentException("Value required for one or both of " + ON_ADDED_EFFECTOR_NAME.getName() + " and " + ON_REMOVED_EFFECTOR_NAME.getName()); } // Initialise `present` before subscribing. Collection<?> current = entity.sensors().get(getTriggerSensor()); synchronized (updateLock) { previous = (current != null) ? new HashSet<>(current) : Collections.emptySet(); } subscriptions().subscribe(entity, sensor, this); }
@Override public Entity resolveTarget() { Entity anchor = config().get(ANCHOR); if (anchor == null) { Maybe<Entity> resolvedTarget = tryResolveTarget(); if (resolvedTarget.isPresent()) { anchor = resolvedTarget.get(); } else { throw new IllegalArgumentException("No anchor entity found for " + this); } } sensors().set(ANCHOR, anchor); Maybe<Object> component = config().getRaw(COMPONENT); if (component.isAbsentOrNull()) { throw new IllegalArgumentException("No component found for " + this); } else if (!(component.get() instanceof DslComponent)) { throw new IllegalArgumentException("Expected DslComponent value for component, found " + component.get()); } DslComponent finder = DslComponent.class.cast(component.get()); Task<Entity> task = Entities.submit(anchor, finder); return task.getUnchecked(); }
if (effector.isAbsentOrNull()) { throw new AssertionError(String.format("No effector with name [%s]", effectorName));
int publicPort = optionalPublicPort.isPresent() ? optionalPublicPort.get() : targetPort; if (vm.isAbsentOrNull()) { Map<VirtualMachine, List<String>> vmIpMapping = client.getVmIps(); log.error("Could not find any VMs with Ip Address {}; contenders: {}", ipAddress, vmIpMapping);
if (effector.isAbsentOrNull()) { throw WebResourceUtils.notFound("Entity '%s' has no effector with name '%s'", entityToken, effectorName); } else if (!Entitlements.isEntitled(mgmt().getEntitlementManager(), Entitlements.INVOKE_EFFECTOR,
if (machine.isAbsentOrNull()) { LOG.debug("No machine available to execute command"); return;
@Override public void apply(EntityLocal entity) { Maybe<Effector<?>> effectorMaybe = entity.getEntityType().getEffectorByName(effector.getName()); if (!effectorMaybe.isAbsentOrNull()) { Effector<?> original = Effectors.effector(effectorMaybe.get()).name(ORIGINAL_PREFIX + effector.getName()).build(); ((EntityInternal) entity).getMutableEntityType().addEffector(original); } super.apply(entity); }
if (getAncestorDefaultInheritable() && !local.isValueExplicitlySet() && local.getDefaultValue().isAbsentOrNull() && parent.getDefaultValue().isPresentAndNonNull()) { return ReferenceWithError.newInstanceWithoutError(new BasicConfigValueAtContainer<TContainer,TValue>(parent));