Refine search
private TaskStatus(final Builder builder) { this.job = checkNotNull(builder.job, "job"); this.goal = checkNotNull(builder.goal, "goal"); this.state = checkNotNull(builder.state, "state"); // Optional this.containerId = builder.containerId; this.throttled = Optional.fromNullable(builder.throttled).or(ThrottleState.NO); this.ports = Optional.fromNullable(builder.ports).or(EMPTY_PORTS); this.env = Optional.fromNullable(builder.env).or(Maps.<String, String>newHashMap()); this.containerError = Optional.fromNullable(builder.containerError).or(""); }
protected StandardGobblinInstanceLauncher(String name, Configurable instanceConf, StandardGobblinInstanceDriver.Builder driverBuilder, Optional<MetricContext> metricContext, Optional<Logger> log, SharedResourcesBroker<GobblinScopeTypes> instanceBroker) { _log = log.or(LoggerFactory.getLogger(getClass())); _name = name; _instanceConf = instanceConf; _driver = driverBuilder.withInstanceEnvironment(this).build(); _instrumentationEnabled = metricContext.isPresent(); _metricContext = metricContext.orNull(); _instanceBroker = instanceBroker; }
Optional<String> defaultTopic = Optional.fromNullable(properties.getProperty(ConfigurationKeys.METRICS_KAFKA_TOPIC)); Optional<String> metricsTopic = Optional.fromNullable( properties.getProperty(ConfigurationKeys.METRICS_KAFKA_TOPIC_METRICS)); Optional<String> eventsTopic = Optional.fromNullable( properties.getProperty(ConfigurationKeys.METRICS_KAFKA_TOPIC_EVENTS)); boolean metricsEnabled = metricsTopic.or(defaultTopic).isPresent(); if (metricsEnabled) log.info("Reporting metrics to Kafka"); boolean eventsEnabled = eventsTopic.or(defaultTopic).isPresent(); if (eventsEnabled) log.info("Reporting events to Kafka"); Preconditions.checkArgument(properties.containsKey(ConfigurationKeys.METRICS_KAFKA_BROKERS), "Kafka metrics brokers missing."); Preconditions.checkArgument(metricsTopic.or(eventsTopic).or(defaultTopic).isPresent(), "Kafka topic missing."); } catch (IllegalArgumentException exception) { log.error("Not reporting metrics to Kafka due to missing Kafka configuration(s).", exception); try { formatEnum.metricReporterBuilder(properties) .build(brokers, metricsTopic.or(defaultTopic).get(), properties); } catch (IOException exception) { log.error("Failed to create Kafka metrics reporter. Will not report metrics to Kafka.", exception); builder.withPusherClassName(pusherClassName); return builder.build(brokers, eventsTopic.or(defaultTopic).get()); } catch (IOException exception) { log.error("Failed to create Kafka events reporter. Will not report events to Kafka.", exception);
protected InstrumentedDataWriterBase(State state, Optional<Class<?>> classTag) { this.closer = Closer.create(); this.instrumentationEnabled = GobblinMetrics.isEnabled(state); this.metricContext = this.closer.register(Instrumented.getMetricContext(state, classTag.or(this.getClass()))); if (this.instrumentationEnabled) { this.writerMetricsUpdater = Optional.of(buildWriterMetricsUpdater()); scheduleWriterMetricsUpdater(this.writerMetricsUpdater.get(), getWriterMetricsUpdaterInterval(state)); } else { this.writerMetricsUpdater = Optional.absent(); } regenerateMetrics(); }
this.hostname = Optional.fromNullable(hostname).orNull(); this.created = Optional.fromNullable(created).orNull(); this.command = Optional.fromNullable(command).or(EMPTY_COMMAND); this.env = Optional.fromNullable(env).or(EMPTY_ENV); this.resources = Optional.fromNullable(resources).orNull(); this.ports = Optional.fromNullable(ports).or(EMPTY_PORTS); this.registration = Optional.fromNullable(registration).or(EMPTY_REGISTRATION); this.gracePeriod = Optional.fromNullable(gracePeriod).orNull(); this.volumes = Optional.fromNullable(volumes).or(EMPTY_VOLUMES); this.expires = expires; this.registrationDomain = Optional.fromNullable(registrationDomain) .or(EMPTY_REGISTRATION_DOMAIN); this.creatingUser = Optional.fromNullable(creatingUser).orNull(); this.token = Optional.fromNullable(token).or(EMPTY_TOKEN); this.healthCheck = Optional.fromNullable(healthCheck).orNull(); this.securityOpt = Optional.fromNullable(securityOpt).or(EMPTY_SECURITY_OPT); this.networkMode = Optional.fromNullable(networkMode).orNull(); this.metadata = Optional.fromNullable(metadata).or(EMPTY_METADATA); this.addCapabilities = firstNonNull(addCapabilities, EMPTY_CAPS); this.dropCapabilities = firstNonNull(dropCapabilities, EMPTY_CAPS); this.labels = Optional.fromNullable(labels).or(EMPTY_LABELS); this.secondsToWaitBeforeKill = secondsToWaitBeforeKill; this.ramdisks = firstNonNull(ramdisks, EMPTY_RAMDISKS);
@Override public SingularityLoadBalancerUpdate enqueue(LoadBalancerRequestId loadBalancerRequestId, SingularityRequest request, SingularityDeploy deploy, List<SingularityTask> add, List<SingularityTask> remove) { final List<String> serviceOwners = request.getOwners().or(Collections.<String> emptyList()); final Set<String> loadBalancerGroups = deploy.getLoadBalancerGroups().or(Collections.<String>emptySet()); final BaragonService lbService = new BaragonService(deploy.getLoadBalancerServiceIdOverride().or(request.getId()), serviceOwners, deploy.getServiceBasePath().get(), deploy.getLoadBalancerAdditionalRoutes().or(Collections.<String>emptyList()), loadBalancerGroups, deploy.getLoadBalancerOptions().orNull(), deploy.getLoadBalancerTemplate(), deploy.getLoadBalancerDomains().or(Collections.<String>emptySet())); final List<UpstreamInfo> addUpstreams = tasksToUpstreams(add, loadBalancerRequestId.toString(), deploy.getLoadBalancerUpstreamGroup()); final List<UpstreamInfo> removeUpstreams = tasksToUpstreams(remove, loadBalancerRequestId.toString(), deploy.getLoadBalancerUpstreamGroup()); final BaragonRequest loadBalancerRequest = new BaragonRequest(loadBalancerRequestId.toString(), lbService, addUpstreams, removeUpstreams); return sendBaragonRequest(loadBalancerRequestId, loadBalancerRequest, LoadBalancerMethod.ENQUEUE); }
public KafkaEventReporter(Builder<?> builder) throws IOException { super(builder); this.serializer = this.closer.register( createSerializer(new FixedSchemaVersionWriter())); if(builder.kafkaPusher.isPresent()) { this.kafkaPusher = builder.kafkaPusher.get(); } else { String pusherClassName = builder.pusherClassName.or(PusherUtils.DEFAULT_KAFKA_PUSHER_CLASS_NAME); this.kafkaPusher = PusherUtils.getPusher(pusherClassName, builder.brokers, builder.topic, builder.config); } this.closer.register(this.kafkaPusher); }
Preconditions.checkArgument(collectionDeleteRequestBuilder.getCollectionName().isPresent(), "You must specify a collection name"); String collectionName = collectionDeleteRequestBuilder.getCollectionName().get(); Preconditions.checkArgument( !(cursor.isPresent() && appId.isPresent()), "You cannot specify an app id and a cursor. When resuming with cursor you must omit the appid." ); Preconditions.checkArgument( cursor.isPresent() || appId.isPresent(), if (appId.isPresent()) { applicationScope = appId.get(); } else { // cursor is present applicationScope = cursor.get().getApplicationScope(); final long endTimestamp = collectionDeleteRequestBuilder.getEndTimestamp().or( System.currentTimeMillis() ); fromNullable(collectionName), cursorSeek.getSeekValue() ) .buffer( indexProcessorFig.getCollectionDeleteBufferSize()) .doOnNext( edgeScopes -> {
private static String env(final String name, final String defaultValue) { return Optional.fromNullable(getenv(name)).or(defaultValue); }
private FallbackMethod doFind(Class<?> enclosingType, Method commandMethod, boolean extended) { String name = getFallbackName(enclosingType, commandMethod); Class<?>[] fallbackParameterTypes = null; if (isDefault()) { fallbackParameterTypes = new Class[0]; } else { fallbackParameterTypes = commandMethod.getParameterTypes(); } if (extended && fallbackParameterTypes[fallbackParameterTypes.length - 1] == Throwable.class) { fallbackParameterTypes = ArrayUtils.remove(fallbackParameterTypes, fallbackParameterTypes.length - 1); } Class<?>[] extendedFallbackParameterTypes = Arrays.copyOf(fallbackParameterTypes, fallbackParameterTypes.length + 1); extendedFallbackParameterTypes[fallbackParameterTypes.length] = Throwable.class; Optional<Method> exFallbackMethod = getMethod(enclosingType, name, extendedFallbackParameterTypes); Optional<Method> fMethod = getMethod(enclosingType, name, fallbackParameterTypes); Method method = exFallbackMethod.or(fMethod).orNull(); if (method == null) { throw new FallbackDefinitionException("fallback method wasn't found: " + name + "(" + Arrays.toString(fallbackParameterTypes) + ")"); } return new FallbackMethod(method, exFallbackMethod.isPresent(), isDefault()); }
/** * Stops this container. */ public void stop() throws InterruptedException { // Tell docker to stop or eventually kill the container final String container = containerId.or(containerName); // Interrupt the thread blocking on waitContainer stopAsync().awaitTerminated(); if (System.getenv("CONTAINER_STATS") != null) { try { log.info("container {} stats: {}", containerName, docker.stats(containerName)); } catch (DockerException e) { log.warn("Could not log container stats. Exception was {}", e); } } try { docker.stopContainer(container, secondsToWaitBeforeKill); } catch (DockerException e) { if ((e instanceof ContainerNotFoundException) && !containerId.isPresent()) { // we tried to stop the container by name but no container of the given name existed. // this isn't surprising or exceptional, just means the container wasn't started yet. } else { log.warn("Stopping container {} failed", container, e); } } }
@Deprecated public TimestampFormatter(final Task task, final Optional<? extends TimestampColumnOption> columnOption) { this(TimestampFormatterRuby.ofLegacy( columnOption.isPresent() ? columnOption.get().getFormat().or(task.getDefaultTimestampFormat()) : task.getDefaultTimestampFormat(), columnOption.isPresent() ? columnOption.get().getTimeZone().or(task.getDefaultTimeZone()) : task.getDefaultTimeZone())); }
this.targetURI = Optional.fromNullable(this.dataset.getProperties().getProperty(TARGET_METASTORE_URI_KEY)); this.targetClientPool = HiveMetastoreClientPool.get(this.dataset.getProperties(), this.targetURI); this.targetDatabase = Optional.fromNullable(this.dataset.getProperties().getProperty(TARGET_DATABASE_KEY)) .or(this.dataset.table.getDbName()); this.existingEntityPolicy = ExistingEntityPolicy.valueOf(this.dataset.getProperties() .getProperty(EXISTING_ENTITY_POLICY_KEY, DEFAULT_EXISTING_ENTITY_POLICY).toUpperCase()); this.partitionFilter = Optional.of(generator.getFilter(this.dataset)); log.info(String.format("Dynamic partition filter for table %s: %s.", this.dataset.table.getCompleteName(), this.partitionFilter.get())); } catch (ReflectiveOperationException roe) { throw new IOException(roe); Optional.fromNullable(this.dataset.getProperties().getProperty(COPY_PARTITIONS_FILTER_CONSTANT)); this.tableRegistrationStep = Optional.of(tableRegistrationStep); if (this.existingTargetTable.isPresent() && this.existingTargetTable.get().isPartitioned()) { checkPartitionedTableCompatibility(this.targetTable, this.existingTargetTable.get()); this.existingTargetTable.isPresent() ? Maps.newHashMap( HiveUtils.getPartitionsMap(multiClient.getClient(target_client), this.existingTargetTable.get(), this.partitionFilter, this.hivePartitionExtendedFilter))
public String getHost() { return fromNullable(uri.getHost()).or("localhost"); }
@Override public List<JCStatement> inlineStatements(final Inliner inliner) throws CouldNotResolveImportException { try { Optional<List<JCStatement>> binding = inliner.getOptionalBinding(placeholder().blockKey()); // If a placeholder was used as an expression binding in the @BeforeTemplate, // and as a bare statement or as a return in the @AfterTemplate, we may need to convert. Optional<JCExpression> exprBinding = inliner.getOptionalBinding(placeholder().exprKey()); binding = binding.or( exprBinding.transform( (JCExpression expr) -> { switch (implementationFlow()) { case NEVER_EXITS: return List.of((JCStatement) inliner.maker().Exec(expr)); case ALWAYS_RETURNS: return List.of((JCStatement) inliner.maker().Return(expr)); default: throw new AssertionError(); } })); return UPlaceholderExpression.copier(arguments(), inliner).copy(binding.get(), inliner); } catch (UncheckedCouldNotResolveImportException e) { throw e.getCause(); } } }
public SingularityRequestParent skipHealthchecks(String requestId, SingularitySkipHealthchecksRequest skipHealthchecksRequest, SingularityUser user) { SingularityRequestWithState oldRequestWithState = fetchRequestWithState(requestId, user); SingularityRequest oldRequest = oldRequestWithState.getRequest(); SingularityRequest newRequest = oldRequest.toBuilder().setSkipHealthchecks(skipHealthchecksRequest.getSkipHealthchecks()).build(); submitRequest(newRequest, Optional.of(oldRequestWithState), Optional.absent(), Optional.absent(), skipHealthchecksRequest.getMessage(), Optional.absent(), user); if (skipHealthchecksRequest.getDurationMillis().isPresent()) { requestManager.saveExpiringObject(new SingularityExpiringSkipHealthchecks(requestId, user.getEmail(), System.currentTimeMillis(), skipHealthchecksRequest, oldRequest.getSkipHealthchecks(), skipHealthchecksRequest.getActionId().or(UUID.randomUUID().toString()))); } return fillEntireRequest(fetchRequestWithState(requestId, user)); }
public JobCatalogBase(Optional<Logger> log, Optional<MetricContext> parentMetricContext, boolean instrumentationEnabled, Optional<Config> sysConfig) { this.log = log.isPresent() ? log.get() : LoggerFactory.getLogger(getClass()); this.listeners = new JobCatalogListenersList(log); if (instrumentationEnabled) { MetricContext realParentCtx = parentMetricContext.or(Instrumented.getMetricContext(new org.apache.gobblin.configuration.State(), getClass())); this.metricContext = realParentCtx.childBuilder(JobCatalog.class.getSimpleName()).build(); this.metrics = createStandardMetrics(sysConfig); this.addListener(this.metrics); } else { this.metricContext = null; this.metrics = null; } }