List of usage examples for com.google.common.base Optional or
@Beta public abstract T or(Supplier<? extends T> supplier);
From source file:com.pinterest.teletraan.resource.EnvCapacities.java
@DELETE public void delete(@PathParam("envName") String envName, @PathParam("stageName") String stageName, @QueryParam("capacityType") Optional<CapacityType> capacityType, @NotEmpty String name, @Context SecurityContext sc) throws Exception { EnvironBean envBean = Utils.getEnvStage(environDAO, envName, stageName); authorizer.authorize(sc, new Resource(envBean.getEnv_name(), Resource.Type.ENV), Role.OPERATOR); String operator = sc.getUserPrincipal().getName(); name = name.replaceAll("\"", ""); if (capacityType.or(CapacityType.GROUP) == CapacityType.GROUP) { LOG.info("Delete group {} from environment {} stage {} capacity", name, envName, stageName); groupDAO.removeGroupCapacity(envBean.getEnv_id(), name); if (StringUtils.equalsIgnoreCase(envBean.getCluster_name(), name)) { LOG.info("Delete cluster {} from environment {} stage {}", name, envName, stageName); //The group is set to be the cluster environDAO.deleteCluster(envName, stageName); }/*www.j a va 2s.co m*/ } else { LOG.info("Delete host {} from environment {} stage {} capacity", name, envName, stageName); groupDAO.removeHostCapacity(envBean.getEnv_id(), name); } LOG.info("Successfully deleted {} from env {}/{} capacity config by {}.", name, envName, stageName, operator); }
From source file:com.google.errorprone.refaster.UPlaceholderStatement.java
@Override public List<JCStatement> inlineStatements(final Inliner inliner) throws CouldNotResolveImportException { try {/* w w w .j a v a 2s . c om*/ 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(new Function<JCExpression, List<JCStatement>>() { @Override public List<JCStatement> apply(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(); } }
From source file:org.apache.gobblin.runtime.spec_catalog.TopologyCatalog.java
public TopologyCatalog(Config config, Optional<Logger> log, Optional<MetricContext> parentMetricContext, boolean instrumentationEnabled) { this.log = log.isPresent() ? log.get() : LoggerFactory.getLogger(getClass()); this.listeners = new SpecCatalogListenersList(log); if (instrumentationEnabled) { MetricContext realParentCtx = parentMetricContext .or(Instrumented.getMetricContext(new org.apache.gobblin.configuration.State(), getClass())); this.metricContext = realParentCtx.childBuilder(TopologyCatalog.class.getSimpleName()).build(); this.metrics = new SpecCatalog.StandardMetrics(this, Optional.of(config)); this.addListener(this.metrics); } else {//ww w . ja v a2s . c om this.metricContext = null; this.metrics = null; } this.aliasResolver = new ClassAliasResolver<>(SpecStore.class); try { Config newConfig = config; if (config.hasPath(ConfigurationKeys.TOPOLOGYSPEC_STORE_DIR_KEY)) { newConfig = config.withValue(ConfigurationKeys.SPECSTORE_FS_DIR_KEY, config.getValue(ConfigurationKeys.TOPOLOGYSPEC_STORE_DIR_KEY)); } String specStoreClassName = DEFAULT_TOPOLOGYSPEC_STORE_CLASS; if (config.hasPath(ConfigurationKeys.TOPOLOGYSPEC_STORE_CLASS_KEY)) { specStoreClassName = config.getString(ConfigurationKeys.TOPOLOGYSPEC_STORE_CLASS_KEY); } this.log.info("Using SpecStore class name/alias " + specStoreClassName); this.specStore = (SpecStore) ConstructorUtils.invokeConstructor( Class.forName(this.aliasResolver.resolve(specStoreClassName)), newConfig, this); } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | InstantiationException | ClassNotFoundException e) { throw new RuntimeException(e); } }
From source file:com.viadeo.kasper.api.context.Context.java
/** * @return the tags/*from ww w.j a v a 2 s .c o m*/ */ public Set<String> getTags() { Optional<String> value = getGenericProperty(TAGS_SHORTNAME); return Tags.valueOf(value.or("")); }
From source file:eu.numberfour.n4js.internal.N4JSModel.java
/** * @see IN4JSSourceContainer#findArtifact(QualifiedName, Optional) */// www . j a va 2s .c om public URI findArtifact(IN4JSSourceContainer sourceContainer, QualifiedName name, Optional<String> fileExtension) { final String ext = fileExtension.or("").trim(); final String extWithDot = !ext.isEmpty() && !ext.startsWith(".") ? "." + ext : ext; final String pathStr = name.toString("/") + extWithDot; // no need for IQualifiedNameConverter here! if (sourceContainer.isLibrary()) { return null; // TODO support for finding artifacts in libraries } else { URI artifactLocation = workspace.findArtifactInFolder(sourceContainer.getLocation(), pathStr); if (null == artifactLocation) { artifactLocation = externalLibraryWorkspace.findArtifactInFolder(sourceContainer.getLocation(), pathStr); } return artifactLocation; } }
From source file:com.pinterest.teletraan.resource.Clusters.java
@PUT @Path("/hosts") public void launchHosts(@Context SecurityContext sc, @PathParam("envName") String envName, @PathParam("stageName") String stageName, @QueryParam("num") Optional<Integer> num) throws Exception { EnvironBean envBean = Utils.getEnvStage(environDAO, envName, stageName); authorizer.authorize(sc, new Resource(envBean.getEnv_name(), Resource.Type.ENV), Role.OPERATOR); String operator = sc.getUserPrincipal().getName(); String clusterName = String.format("%s-%s", envName, stageName); clusterHandler.launchHosts(clusterName, num.or(1)); LOG.info(String.format("Successfully launch hosts for %s/%s by %s", envName, stageName, operator)); }
From source file:org.eclipse.incquery.tooling.ui.queryexplorer.QueryExplorer.java
private void initPatternsViewerWithGeneratedPatterns() { for (IQuerySpecification<?> pattern : QueryExplorerPatternRegistry.getGeneratedQuerySpecifications()) { String patternFqn = pattern.getFullyQualifiedName(); QueryExplorerPatternRegistry.getInstance().addGeneratedPattern(pattern); // check for QE annotation https://bugs.eclipse.org/bugs/show_bug.cgi?id=412700 Optional<Boolean> checkedValue = QueryExplorerPatternRegistry.getQueryExplorerCheckedValue(pattern); Boolean computedCheckedValue = checkedValue.or(false); // add to active patterns only if explicitly if (computedCheckedValue) { QueryExplorerPatternRegistry.getInstance().addActivePattern(pattern); }//from w w w . j a va2 s . c o m PatternComponent component = patternsViewerInput.getGeneratedPatternsRoot().addComponent(patternFqn); component.setCheckedState(computedCheckedValue); } patternsTreeViewer.refresh(); patternsViewerInput.getGeneratedPatternsRoot().updateHasChildren(); patternsViewerInput.getGenericPatternsRoot().setCheckedState(false); }
From source file:com.addthis.hydra.job.web.resources.ListenResource.java
@GET @Path("/batch") @Produces(MediaType.APPLICATION_JSON)/*from w w w . j a v a 2 s.co m*/ public Response getListenBatch(@QueryParam("timeout") Optional<Integer> timeoutParameter, @QueryParam("batchtime") Optional<Integer> batchtimeParameter, @QueryParam("clientId") Optional<String> clientIdParameter) { Response response; String clientId = (clientIdParameter.isPresent() ? clientIdParameter.get() : "noid"); int timeout = timeoutParameter.or(pollTimeout); int batchTime = batchtimeParameter.or(batchInterval); ClientEventListener listener = spawn.getClientEventListener(clientId); try { ClientEvent nextEvent = listener.events.poll(timeout, TimeUnit.MILLISECONDS); if (nextEvent != null) { long mark = System.currentTimeMillis(); JSONArray payload = new JSONArray(); payload.put(encodeJson(nextEvent)); for (int i = 50; i > 0; i--) { nextEvent = listener.events.poll(batchTime, TimeUnit.MILLISECONDS); if (nextEvent != null) { JSONObject json = encodeJson(nextEvent); payload.put(json); } if (System.currentTimeMillis() - mark > batchTime) { break; } } response = Response.ok(payload.toString()).build(); } else { response = Response.notModified().build(); } } catch (InterruptedException ex) { response = Response.notModified().build(); } catch (Exception ex) { log.warn("", ex); response = Response.serverError().build(); } return response; }
From source file:org.apache.gobblin.runtime.spec_catalog.FlowCatalog.java
public FlowCatalog(Config config, Optional<Logger> log, Optional<MetricContext> parentMetricContext, boolean instrumentationEnabled) { this.log = log.isPresent() ? log.get() : LoggerFactory.getLogger(getClass()); this.listeners = new SpecCatalogListenersList(log); if (instrumentationEnabled) { MetricContext realParentCtx = parentMetricContext .or(Instrumented.getMetricContext(new org.apache.gobblin.configuration.State(), getClass())); this.metricContext = realParentCtx.childBuilder(FlowCatalog.class.getSimpleName()).build(); this.metrics = new MutableStandardMetrics(this, Optional.of(config)); this.addListener(this.metrics); } else {/*from ww w . j ava2s .c om*/ this.metricContext = null; this.metrics = null; } this.aliasResolver = new ClassAliasResolver<>(SpecStore.class); try { Config newConfig = config; if (config.hasPath(ConfigurationKeys.FLOWSPEC_STORE_DIR_KEY)) { newConfig = config.withValue(ConfigurationKeys.SPECSTORE_FS_DIR_KEY, config.getValue(ConfigurationKeys.FLOWSPEC_STORE_DIR_KEY)); } String specStoreClassName = DEFAULT_FLOWSPEC_STORE_CLASS; if (config.hasPath(ConfigurationKeys.FLOWSPEC_STORE_CLASS_KEY)) { specStoreClassName = config.getString(ConfigurationKeys.FLOWSPEC_STORE_CLASS_KEY); } this.log.info("Using audit sink class name/alias " + specStoreClassName); this.specStore = (SpecStore) ConstructorUtils.invokeConstructor( Class.forName(this.aliasResolver.resolve(specStoreClassName)), newConfig, this); } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | InstantiationException | ClassNotFoundException e) { throw new RuntimeException(e); } }
From source file:com.pinterest.teletraan.resource.Clusters.java
@DELETE @Path("/hosts") public void termianteHosts(@Context SecurityContext sc, @PathParam("envName") String envName, @PathParam("stageName") String stageName, @Valid Collection<String> hostIds, @QueryParam("replaceHost") Optional<Boolean> replaceHost) throws Exception { EnvironBean envBean = Utils.getEnvStage(environDAO, envName, stageName); authorizer.authorize(sc, new Resource(envBean.getEnv_name(), Resource.Type.ENV), Role.OPERATOR); String operator = sc.getUserPrincipal().getName(); String clusterName = String.format("%s-%s", envName, stageName); clusterHandler.termianteHosts(clusterName, hostIds, replaceHost.or(true)); LOG.info(String.format("Successfully terminate hosts for %s/%s by %s", envName, stageName, operator)); }