List of usage examples for com.google.common.base Optional or
@Beta public abstract T or(Supplier<? extends T> supplier);
From source file:io.mesosphere.mesos.frameworks.cassandra.ZooKeeperSeedProviderConfig.java
/** * Creates a new ZooKeeperSeedProviderConfig from parameters. * @param parameters A dictionary containing the configuration properties * to parse. It must contain zookeeper_server_address, * a comma separated list of host:port pairs that * indicates the servers in the ZooKeeper ensemble, and * zookeeper_seeds_path, a fully qualified path to the * ZNode containing the Cassandra cluster seeds. It may * contain session_timeout_ms, a strictly positive * integer that indicates the zookeeper session timeout * in milliseconds, connection_timeout_ms, a strictly * positive integer indicating the timeout for * connection to a ZooKeeper server in ms, and * operation_timeout, which, if positive, indicates the * amount of time an operations should be retried in ms. * @throws MissingConfigException If parameters does not contain * zookeeper_server_addresses or zookeeper_seeds_path. * @throws InvalidConfigException If parameters contains * session_timeout_ms or operation_timeout_ms and either parameter is set * to a non-positive integer.//from w w w . j a v a2 s. co m */ protected ZooKeeperSeedProviderConfig(Map<String, String> parameters) throws MissingConfigException, InvalidConfigException { Optional<String> zkServers = optionalString(ZOOKEEPERS_KEY, parameters); Optional<String> seedsPath = optionalString(SEEDS_PATH_KEY, parameters); Optional<Integer> sessionTimeout = optionalInteger(SESSION_TIMEOUT_KEY, parameters); Optional<Integer> connectionTimeout = optionalInteger(CONNECTION_TIMEOUT_KEY, parameters); Optional<Integer> operationTimeout = optionalInteger(OPERATION_TIMEOUT_KEY, parameters); validate(zkServers, seedsPath, sessionTimeout, connectionTimeout, operationTimeout); this.zkServers = zkServers.get(); this.seedsPath = seedsPath.get(); this.sessionTimeoutMs = sessionTimeout.or(DEFAULT_SESSION_TIMEOUT); this.operationTimeoutMs = operationTimeout.or(DEFAULT_OPERATION_TIMEOUT); this.connectionTimeoutMs = connectionTimeout.or(DEFAULT_CONNECTION_TIMEOUT); }
From source file:org.apache.brooklyn.entity.nosql.riak.RiakNodeSshDriver.java
@Override public void customize() { checkRiakOnPath();/*from w ww . jav a 2s.c om*/ //create entity's runDir newScript(CUSTOMIZING).execute(); OsDetails osDetails = getMachine().getMachineDetails().getOsDetails(); List<String> commands = Lists.newLinkedList(); commands.add(sudo("mkdir -p " + getRiakEtcDir())); if (isVersion1()) { String vmArgsTemplate = processTemplate(entity.getConfig(RiakNode.RIAK_VM_ARGS_TEMPLATE_URL)); String saveAsVmArgs = Urls.mergePaths(getRunDir(), "vm.args"); DynamicTasks.queue(SshEffectorTasks.put(saveAsVmArgs).contents(vmArgsTemplate)); commands.add(sudo("mv " + saveAsVmArgs + " " + getRiakEtcDir())); String appConfigTemplate = processTemplate(entity.getConfig(RiakNode.RIAK_APP_CONFIG_TEMPLATE_URL)); String saveAsAppConfig = Urls.mergePaths(getRunDir(), "app.config"); DynamicTasks.queue(SshEffectorTasks.put(saveAsAppConfig).contents(appConfigTemplate)); commands.add(sudo("mv " + saveAsAppConfig + " " + getRiakEtcDir())); } else { String templateUrl = osDetails.isMac() ? entity.getConfig(RiakNode.RIAK_CONF_TEMPLATE_URL_MAC) : entity.getConfig(RiakNode.RIAK_CONF_TEMPLATE_URL_LINUX); String riakConfContent = processTemplate(templateUrl); String saveAsRiakConf = Urls.mergePaths(getRunDir(), "riak.conf"); if (Strings.isNonBlank(entity.getConfig(RiakNode.RIAK_CONF_ADDITIONAL_CONTENT))) { String additionalConfigContent = processTemplateContents( entity.getConfig(RiakNode.RIAK_CONF_ADDITIONAL_CONTENT)); riakConfContent += "\n## Brooklyn note: additional config\n"; riakConfContent += additionalConfigContent; } DynamicTasks.queue(SshEffectorTasks.put(saveAsRiakConf).contents(riakConfContent)); commands.add(sudo("mv " + saveAsRiakConf + " " + getRiakEtcDir())); } //increase open file limit (default min for riak is: 4096) //TODO: detect the actual limit then do the modification. //TODO: modify ulimit for linux distros // commands.add(sudo("launchctl limit maxfiles 4096 32768")); if (osDetails.isMac()) { commands.add("ulimit -n 4096"); } if (osDetails.isLinux() && isVersion1()) { commands.add(sudo("chown -R riak:riak " + getRiakEtcDir())); } // TODO platform_*_dir // TODO riak config log ScriptHelper customizeScript = newScript(CUSTOMIZING).failOnNonZeroResultCode().body.append(commands); if (!isRiakOnPath()) { addRiakOnPath(customizeScript); } customizeScript.failOnNonZeroResultCode().execute(); if (osDetails.isLinux()) { ImmutableMap<String, String> sysctl = ImmutableMap.<String, String>builder().put("vm.swappiness", "0") .put("net.core.somaxconn", "40000").put("net.ipv4.tcp_max_syn_backlog", "40000") .put("net.ipv4.tcp_sack", "1").put("net.ipv4.tcp_window_scaling", "15") .put("net.ipv4.tcp_fin_timeout", "1").put("net.ipv4.tcp_keepalive_intvl", "30") .put("net.ipv4.tcp_tw_reuse", "1").put("net.ipv4.tcp_moderate_rcvbuf", "1").build(); ScriptHelper optimize = newScript(CUSTOMIZING + "network").body .append(sudo("sysctl " + Joiner.on(' ').withKeyValueSeparator("=").join(sysctl))); Optional<Boolean> enable = Optional.fromNullable(entity.getConfig(RiakNode.OPTIMIZE_HOST_NETWORKING)); if (!enable.isPresent()) optimize.inessential(); if (enable.or(true)) optimize.execute(); } //set the riak node name entity.sensors().set(RiakNode.RIAK_NODE_NAME, format("riak@%s", getSubnetHostname())); }
From source file:org.locationtech.geogig.api.porcelain.RemoteRemoveOp.java
/** * Executes the remote-remove operation. * /*from ww w . j av a 2 s . c om*/ * @return the {@link Remote} that was removed, or {@link Optional#absent()} if the remote * didn't exist. */ @Override protected Remote _call() { if (name == null || name.isEmpty()) { throw new RemoteException(StatusCode.MISSING_NAME); } ConfigDatabase config = configDatabase(); List<String> allRemotes = config.getAllSubsections("remote"); if (!allRemotes.contains(name)) { throw new RemoteException(StatusCode.REMOTE_NOT_FOUND); } Remote remote = null; String remoteSection = "remote." + name; Optional<String> remoteFetchURL = config.get(remoteSection + ".url"); Optional<String> remoteFetch = config.get(remoteSection + ".fetch"); Optional<String> remotePushURL = Optional.absent(); Optional<String> remoteMapped = config.get(remoteSection + ".mapped"); Optional<String> remoteMappedBranch = config.get(remoteSection + ".mappedBranch"); Optional<String> remoteUserName = config.get(remoteSection + ".username"); Optional<String> remotePassword = config.get(remoteSection + ".password"); if (remoteFetchURL.isPresent() && remoteFetch.isPresent()) { remotePushURL = config.get(remoteSection + ".pushurl"); } remote = new Remote(name, remoteFetchURL.or(""), remotePushURL.or(remoteFetchURL.or("")), remoteFetch.or(""), remoteMapped.or("false").equals("true"), remoteMappedBranch.orNull(), remoteUserName.orNull(), remotePassword.orNull()); config.removeSection(remoteSection); // Remove refs final ImmutableSet<Ref> localRemoteRefs = command(LsRemote.class).retrieveLocalRefs(true) .setRemote(Suppliers.ofInstance(Optional.of(remote))).call(); for (Ref localRef : localRemoteRefs) { command(UpdateRef.class).setDelete(true).setName(localRef.getName()).call(); } return remote; }
From source file:org.locationtech.geogig.test.integration.remoting.RemoteRepositoryTestCase.java
protected void assertSummary(TransferSummary result, String remoteURL, Optional<Ref> before, Optional<Ref> after) { assertNotNull(result);//from w w w. ja v a 2 s.c o m Collection<RefDiff> diffs = result.getRefDiffs().get(remoteURL); assertNotNull(diffs); String name = before.or(after).get().getName(); RefDiff diff = Maps.uniqueIndex(diffs, (d) -> d.oldRef().or(d.newRef()).get().getName()).get(name); assertNotNull(diff); assertEquals(before, diff.oldRef()); assertEquals(after, diff.newRef()); }
From source file:com.pinterest.teletraan.resource.Deploys.java
@GET public DeployQueryResultBean search(@QueryParam("envId") List<String> envIds, @QueryParam("operator") List<String> operators, @QueryParam("deployType") List<DeployType> deployTypes, @QueryParam("deployState") List<DeployState> deployStates, @QueryParam("acceptanceStatus") List<AcceptanceStatus> acceptanceStatuss, @QueryParam("commit") String commit, @QueryParam("repo") String repo, @QueryParam("branch") String branch, @QueryParam("commitDate") Long commitDate, @QueryParam("before") Long before, @QueryParam("after") Long after, @QueryParam("pageIndex") Optional<Integer> pageIndex, @QueryParam("pageSize") Optional<Integer> pageSize, @QueryParam("oldestFirst") Optional<Boolean> oldestFirst) throws Exception { DeployFilterBean filter = new DeployFilterBean(); filter.setEnvIds(envIds);// w ww .j a v a 2 s . c om filter.setOperators(operators); filter.setDeployTypes(deployTypes); filter.setDeployStates(deployStates); filter.setAcceptanceStatuss(acceptanceStatuss); filter.setCommit(commit); filter.setRepo(repo); filter.setBranch(branch); filter.setCommitDate(commitDate); filter.setBefore(before); filter.setAfter(after); filter.setPageIndex(pageIndex.or(1)); filter.setPageSize(pageSize.or(DEFAULT_SIZE)); filter.setOldestFirst(oldestFirst.or(false)); DeployQueryFilter filterBean = new DeployQueryFilter(filter); return deployDAO.getAllDeploys(filterBean); }
From source file:org.locationtech.geogig.plumbing.remotes.RemoteResolve.java
/** * Executes the remote-add operation./* www . j av a2 s. c o m*/ * * @return the {@link Remote} that was added. */ @Override protected Optional<Remote> _call() { if (name == null || name.isEmpty()) { throw new RemoteException(StatusCode.MISSING_NAME); } Optional<Remote> result = Optional.absent(); ConfigDatabase config = configDatabase(); List<String> allRemotes = config.getAllSubsections("remote"); if (allRemotes.contains(name)) { String remoteSection = "remote." + name; Optional<String> remoteFetchURL = config.get(remoteSection + ".url"); Optional<String> remoteFetch = config.get(remoteSection + ".fetch"); Optional<String> remoteMapped = config.get(remoteSection + ".mapped"); Optional<String> remoteMappedBranch = config.get(remoteSection + ".mappedBranch"); Optional<String> remoteUserName = config.get(remoteSection + ".username"); Optional<String> remotePassword = config.get(remoteSection + ".password"); Optional<String> remotePushURL = Optional.absent(); if (remoteFetchURL.isPresent() && remoteFetch.isPresent()) { remotePushURL = config.get(remoteSection + ".pushurl"); } Remote remote = new Remote(name, remoteFetchURL.or(""), remotePushURL.or(remoteFetchURL).or(""), remoteFetch.or(""), remoteMapped.or("false").equals("true"), remoteMappedBranch.orNull(), remoteUserName.orNull(), remotePassword.orNull()); result = Optional.of(remote); } return result; }
From source file:de.todesbaum.jsite.application.ProjectInserter.java
private FileEntry createFileEntry(String filename, Optional<String> changedName, String mimeType) throws FileNotFoundException { File physicalFile = new File(project.getLocalPath(), filename); InputStream fileEntryInputStream = new FileInputStream(physicalFile); return new DirectFileEntry(changedName.or(filename), mimeType, fileEntryInputStream, physicalFile.length()); }
From source file:google.registry.model.pricing.StaticPremiumListPricingEngine.java
@Override public DomainPrices getDomainPrices(String fullyQualifiedDomainName, DateTime priceTime) { String tld = getTldFromDomainName(fullyQualifiedDomainName); String label = InternetDomainName.from(fullyQualifiedDomainName).parts().get(0); Registry registry = Registry.get(checkNotNull(tld, "tld")); Optional<Money> premiumPrice = Optional.<Money>absent(); if (registry.getPremiumList() != null) { String listName = registry.getPremiumList().getName(); Optional<PremiumList> premiumList = PremiumList.get(listName); checkState(premiumList.isPresent(), "Could not load premium list: %s", listName); premiumPrice = premiumList.get().getPremiumPrice(label); }// ww w .j a va 2 s .co m boolean isNameCollisionInSunrise = registry.getTldState(priceTime).equals(SUNRISE) && getReservation(label, tld) == NAME_COLLISION; String feeClass = emptyToNull(Joiner.on('-').skipNulls().join(premiumPrice.isPresent() ? "premium" : null, isNameCollisionInSunrise ? "collision" : null)); return DomainPrices.create(premiumPrice.isPresent(), premiumPrice.or(registry.getStandardCreateCost()), premiumPrice.or(registry.getStandardRenewCost(priceTime)), Optional.<String>fromNullable(feeClass)); }
From source file:brooklyn.entity.basic.AbstractSoftwareProcessDriver.java
/** * Start the entity./*from w ww .j ava 2s .c om*/ * <p> * This installs, configures and launches the application process. However, * users can also call the {@link #install()}, {@link #customize()} and * {@link #launch()} steps independently. The {@link #postLaunch()} will * be called after the {@link #launch()} metheod is executed, but the * process may not be completely initialised at this stage, so care is * required when implementing these stages. * <p> * The {@link BrooklynConfigKeys#ENTITY_RUNNING} key can be set on the location * or the entity to skip the startup process if the entity is already running, * according to the {@link #isRunning()} method. To force the startup to be * skipped, {@link BrooklynConfigKeys#SKIP_ENTITY_START} can be set on the entity. * The {@link BrooklynConfigKeys#SKIP_ENTITY_INSTALLATION} key can also be used to * skip the {@link #setup()}, {@link #copyInstallResources()} and * {@link #install()} methods if set on the entity or location. * * @see #stop() */ @Override public void start() { boolean skipStart = false; Optional<Boolean> locationRunning = Optional .fromNullable(getLocation().getConfig(BrooklynConfigKeys.SKIP_ENTITY_START_IF_RUNNING)); Optional<Boolean> entityRunning = Optional .fromNullable(entity.getConfig(BrooklynConfigKeys.SKIP_ENTITY_START_IF_RUNNING)); Optional<Boolean> entityStarted = Optional .fromNullable(entity.getConfig(BrooklynConfigKeys.SKIP_ENTITY_START)); if (locationRunning.or(entityRunning).or(false)) { skipStart = isRunning(); } else { skipStart = entityStarted.or(false); } if (!skipStart) { DynamicTasks.queue("pre-install", new Runnable() { public void run() { preInstall(); } }); if (Strings.isNonBlank(entity.getConfig(BrooklynConfigKeys.PRE_INSTALL_COMMAND))) { DynamicTasks.queue("pre-install-command", new Runnable() { public void run() { runPreInstallCommand(entity.getConfig(BrooklynConfigKeys.PRE_INSTALL_COMMAND)); } }); } ; Optional<Boolean> locationInstalled = Optional .fromNullable(getLocation().getConfig(BrooklynConfigKeys.SKIP_ENTITY_INSTALLATION)); Optional<Boolean> entityInstalled = Optional .fromNullable(entity.getConfig(BrooklynConfigKeys.SKIP_ENTITY_INSTALLATION)); boolean skipInstall = locationInstalled.or(entityInstalled).or(false); if (!skipInstall) { DynamicTasks.queue("setup", new Runnable() { public void run() { waitForConfigKey(BrooklynConfigKeys.SETUP_LATCH); setup(); } }); DynamicTasks.queue("copy-install-resources", new Runnable() { public void run() { waitForConfigKey(BrooklynConfigKeys.INSTALL_RESOURCES_LATCH); copyInstallResources(); } }); DynamicTasks.queue("install", new Runnable() { public void run() { waitForConfigKey(BrooklynConfigKeys.INSTALL_LATCH); install(); } }); } if (Strings.isNonBlank(entity.getConfig(BrooklynConfigKeys.POST_INSTALL_COMMAND))) { DynamicTasks.queue("post-install-command", new Runnable() { public void run() { runPostInstallCommand(entity.getConfig(BrooklynConfigKeys.POST_INSTALL_COMMAND)); } }); } ; DynamicTasks.queue("customize", new Runnable() { public void run() { waitForConfigKey(BrooklynConfigKeys.CUSTOMIZE_LATCH); customize(); } }); DynamicTasks.queue("copy-runtime-resources", new Runnable() { public void run() { waitForConfigKey(BrooklynConfigKeys.RUNTIME_RESOURCES_LATCH); copyRuntimeResources(); } }); if (Strings.isNonBlank(entity.getConfig(BrooklynConfigKeys.PRE_LAUNCH_COMMAND))) { DynamicTasks.queue("pre-launch-command", new Runnable() { public void run() { runPreLaunchCommand(entity.getConfig(BrooklynConfigKeys.PRE_LAUNCH_COMMAND)); } }); } ; DynamicTasks.queue("launch", new Runnable() { public void run() { waitForConfigKey(BrooklynConfigKeys.LAUNCH_LATCH); launch(); } }); if (Strings.isNonBlank(entity.getConfig(BrooklynConfigKeys.POST_LAUNCH_COMMAND))) { DynamicTasks.queue("post-launch-command", new Runnable() { public void run() { runPostLaunchCommand(entity.getConfig(BrooklynConfigKeys.POST_LAUNCH_COMMAND)); } }); } ; } DynamicTasks.queue("post-launch", new Runnable() { public void run() { postLaunch(); } }); }
From source file:org.geogit.repository.WorkingTree.java
/** * Returns true if there are no unstaged changes, false otherwise */// ww w.jav a2 s.c om public boolean isClean() { Optional<ObjectId> resolved = commandLocator.command(ResolveTreeish.class).setTreeish(Ref.STAGE_HEAD) .call(); return getTree().getId().equals(resolved.or(ObjectId.NULL)); }