List of usage examples for com.google.common.base Optional orNull
@Nullable public abstract T orNull();
From source file:org.jclouds.scriptbuilder.statements.chef.ChefSolo.java
protected ChefSolo(Optional<String> fileCachePath, Optional<String> rolePath, Optional<String> databagPath, Optional<ImmutableList<String>> cookbookPath, Optional<String> cookbooksArchiveLocation, Optional<String> jsonAttributes, Optional<String> group, Optional<Integer> interval, Optional<String> logLevel, Optional<String> logFile, Optional<String> nodeName, Optional<Integer> splay, Optional<String> user, Optional<List<Role>> roles, Optional<List<DataBag>> databags, Optional<RunList> runlist, Optional<String> chefVersion) { this.fileCachePath = checkNotNull(fileCachePath, "fileCachePath must be set").or(DEFAULT_SOLO_PATH); this.rolePath = checkNotNull(rolePath, "rolePath must be set").or(this.fileCachePath + "/roles"); this.databagPath = checkNotNull(databagPath, "databagPath must be set") .or(this.fileCachePath + "/data_bags"); this.cookbooksArchiveLocation = checkNotNull(cookbooksArchiveLocation, "cookbooksArchiveLocation must be set"); this.jsonAttributes = checkNotNull(jsonAttributes, "jsonAttributes must be set"); this.group = checkNotNull(group, "group must be set"); this.interval = checkNotNull(interval, "interval must be set"); this.logLevel = checkNotNull(logLevel, "logLevel must be set"); this.logFile = checkNotNull(logFile, "logFile must be set"); this.nodeName = checkNotNull(nodeName, "nodeName must be set"); this.splay = checkNotNull(splay, "splay must be set"); this.user = checkNotNull(user, "user must be set"); this.roles = checkNotNull(roles, "roles must be set"); this.databags = checkNotNull(databags, "databags must be set"); this.runlist = checkNotNull(runlist, "runlist must be set").or(RunList.builder().build()); this.user = checkNotNull(user, "chefVersion must be set"); if (!checkNotNull(cookbookPath, "cookbookPath must be set").isPresent() || cookbookPath.get().isEmpty()) { this.cookbookPath = ImmutableList.<String>of(this.fileCachePath + "/cookbooks"); } else {/* w w w . j av a2 s .c o m*/ this.cookbookPath = ImmutableList.<String>copyOf(cookbookPath.get()); } this.installChefGems = InstallChefGems.builder().version(chefVersion.orNull()).build(); }
From source file:org.opendaylight.netvirt.elan.utils.ElanUtils.java
public ElanTagName getElanInfoByElanTag(long elanTag) { InstanceIdentifier<ElanTagName> elanId = getElanInfoEntriesOperationalDataPath(elanTag); Optional<ElanTagName> existingElanInfo = read(broker, LogicalDatastoreType.OPERATIONAL, elanId); return existingElanInfo.orNull(); }
From source file:org.opendaylight.netvirt.elan.utils.ElanUtils.java
public MacEntry getInterfaceMacEntriesOperationalDataPathFromId(InstanceIdentifier identifier) { Optional<MacEntry> existingInterfaceMacEntry = read(broker, LogicalDatastoreType.OPERATIONAL, identifier); return existingInterfaceMacEntry.orNull(); }
From source file:org.opendaylight.netvirt.elan.utils.ElanUtils.java
public MacEntry getMacEntryFromElanMacId(InstanceIdentifier identifier) { Optional<MacEntry> existingInterfaceMacEntry = read(broker, LogicalDatastoreType.OPERATIONAL, identifier); return existingInterfaceMacEntry.orNull(); }
From source file:org.onosproject.onosjar.OnosJarStepFactory.java
@Override public void createCompileToJarStep(BuildContext context, ImmutableSortedSet<Path> sourceFilePaths, BuildTarget invokingRule, SourcePathResolver resolver, ProjectFilesystem filesystem, ImmutableSortedSet<Path> declaredClasspathEntries, Path outputDirectory, Optional<Path> workingDirectory, Path pathToSrcsList, Optional<SuggestBuildRules> suggestBuildRules, ImmutableList<String> postprocessClassesCommands, ImmutableSortedSet<Path> entriesToJar, Optional<String> mainClass, Optional<Path> manifestFile, Path outputJar, ClassUsageFileWriter usedClassesFileWriter, ImmutableList.Builder<Step> steps, BuildableContext buildableContext, ImmutableSet<Pattern> classesToRemoveFromJar) { ImmutableSet.Builder<Path> sourceFilePathBuilder = ImmutableSet.builder(); sourceFilePathBuilder.addAll(sourceFilePaths); ImmutableSet.Builder<Pattern> blacklistBuilder = ImmutableSet.builder(); blacklistBuilder.addAll(classesToRemoveFromJar); // precompilation steps // - generate sources // add all generated sources ot pathToSrcsList if (webContext != null && apiTitle != null && resources.isPresent()) { ImmutableSortedSet<Path> resourceFilePaths = findSwaggerModelDefs(resolver, resources.get()); blacklistBuilder.addAll(resourceFilePaths.stream() .map(rp -> Pattern.compile(rp.getFileName().toString(), Pattern.LITERAL)) .collect(Collectors.toSet())); Path genSourcesOutput = workingDirectory.get(); SwaggerStep swaggerStep = new SwaggerStep(filesystem, sourceFilePaths, resourceFilePaths, genSourcesOutput, outputDirectory, webContext, apiTitle, apiVersion, apiPackage, apiDescription);// www . j a v a2 s . c om sourceFilePathBuilder.add(swaggerStep.apiRegistratorPath()); steps.add(swaggerStep); // steps.addAll(sourceFilePaths.stream() // .filter(sp -> sp.startsWith("src/main/webapp/")) // .map(sp -> CopyStep.forFile(filesystem, sp, outputDirectory)) // .iterator()); } createCompileStep(context, ImmutableSortedSet.copyOf(sourceFilePathBuilder.build()), invokingRule, resolver, filesystem, declaredClasspathEntries, outputDirectory, workingDirectory, pathToSrcsList, suggestBuildRules, usedClassesFileWriter, steps, buildableContext); // post compilation steps // FIXME BOC: add mechanism to inject new Steps //context.additionalStepFactory(JavaStep.class); // build the jar steps.add(new JarDirectoryStep(filesystem, outputJar, ImmutableSortedSet.of(outputDirectory), mainClass.orNull(), manifestFile.orNull(), true, blacklistBuilder.build())); OSGiWrapper osgiStep = new OSGiWrapper(outputJar, //input jar outputJar, //Paths.get(outputJar.toString() + ".jar"), //output jar invokingRule.getBasePath(), // sources dir outputDirectory, // classes dir declaredClasspathEntries, // classpath bundleName, // bundle name groupId, // groupId bundleVersion, // bundle version bundleLicense, // bundle license importPackages, // import packages exportPackages, // export packages includeResources, // include resources webContext, // web context dynamicimportPackages, // dynamic import packages bundleDescription // bundle description ); steps.add(osgiStep); //steps.add(CopyStep.forFile(filesystem, Paths.get(outputJar.toString() + ".jar"), outputJar)); }
From source file:com.ibm.common.activitystreams.ASObject.java
/** * Method getEnum.// w ww . j av a 2 s . c om * @param key String * @param _enumClass Class<E> * @param or E * @return E */ public <E extends Enum<E>> E getEnum(String key, Class<E> _enumClass, E or) { String val = getString(key); Optional<E> op = getIfPresent(_enumClass, val); return or != null ? op.or(or) : op.orNull(); }
From source file:brooklyn.location.jclouds.JcloudsSshMachineLocation.java
@Override protected MachineDetails inferMachineDetails() { Optional<String> name = Optional.absent(); Optional<String> version = Optional.absent(); Optional<String> architecture = Optional.absent(); OperatingSystem os = node.getOperatingSystem(); if (os == null && getTemplate() != null && getTemplate().getImage() != null) // some nodes (eg cloudstack, gce) might not get OS available on the node, // so also try taking it from the template if available os = getTemplate().getImage().getOperatingSystem(); if (os != null) { // Note using family rather than name. Name is often unset. name = Optional.fromNullable(os.getFamily() != null && !OsFamily.UNRECOGNIZED.equals(os.getFamily()) ? os.getFamily().toString() : null);//w w w. j a va 2 s . c o m version = Optional.fromNullable(!Strings.isBlank(os.getVersion()) ? os.getVersion() : null); // Using is64Bit rather then getArch because getArch often returns "paravirtual" architecture = Optional .fromNullable(os.is64Bit() ? BasicOsDetails.OsArchs.X_86_64 : BasicOsDetails.OsArchs.I386); } Hardware hardware = node.getHardware(); Optional<Integer> ram = hardware == null ? Optional.<Integer>absent() : Optional.fromNullable(hardware.getRam()); Optional<Integer> cpus = hardware == null ? Optional.<Integer>absent() : Optional.fromNullable(hardware.getProcessors() != null ? hardware.getProcessors().size() : null); // Skip superclass' SSH to machine if all data is present, otherwise defer to super if (name.isPresent() && version.isPresent() && architecture.isPresent() && ram.isPresent() && cpus.isPresent()) { if (LOG.isTraceEnabled()) { LOG.trace("Gathered machine details from Jclouds, skipping SSH test on {}", this); } OsDetails osD = new BasicOsDetails(name.get(), architecture.get(), version.get()); HardwareDetails hwD = new BasicHardwareDetails(cpus.get(), ram.get()); return new BasicMachineDetails(hwD, osD); } else if ("false".equalsIgnoreCase(getConfig(JcloudsLocation.WAIT_FOR_SSHABLE))) { if (LOG.isTraceEnabled()) { LOG.trace( "Machine details for {} missing from Jclouds, but skipping SSH test because waitForSshable=false. name={}, version={}, " + "arch={}, ram={}, #cpus={}", new Object[] { this, name, version, architecture, ram, cpus }); } OsDetails osD = new BasicOsDetails(name.orNull(), architecture.orNull(), version.orNull()); HardwareDetails hwD = new BasicHardwareDetails(cpus.orNull(), ram.orNull()); return new BasicMachineDetails(hwD, osD); } else { if (LOG.isTraceEnabled()) { LOG.trace( "Machine details for {} missing from Jclouds, using SSH test instead. name={}, version={}, " + "arch={}, ram={}, #cpus={}", new Object[] { this, name, version, architecture, ram, cpus }); } return super.inferMachineDetails(); } }
From source file:org.apache.brooklyn.location.jclouds.JcloudsSshMachineLocation.java
@Override protected MachineDetails inferMachineDetails() { Optional<String> name = Optional.absent(); Optional<String> version = Optional.absent(); Optional<String> architecture = Optional.absent(); Optional<OperatingSystem> os = getOptionalOperatingSystem(); Optional<Hardware> hardware = getOptionalHardware(); if (os.isPresent()) { // Note using family rather than name. Name is often unset. // Using is64Bit rather then getArch because getArch often returns "paravirtual" OsFamily family = os.get().getFamily(); String versionRaw = os.get().getVersion(); boolean is64Bit = os.get().is64Bit(); name = Optional.fromNullable( family != null && !OsFamily.UNRECOGNIZED.equals(family) ? family.toString() : null); version = Optional.fromNullable(Strings.isNonBlank(versionRaw) ? versionRaw : null); architecture = Optional//www . ja v a 2s. co m .fromNullable(is64Bit ? BasicOsDetails.OsArchs.X_86_64 : BasicOsDetails.OsArchs.I386); } Optional<Integer> ram = hardware.isPresent() ? Optional.fromNullable(hardware.get().getRam()) : Optional.<Integer>absent(); Optional<Integer> cpus = hardware.isPresent() ? Optional.fromNullable( hardware.get().getProcessors() != null ? hardware.get().getProcessors().size() : null) : Optional.<Integer>absent(); // Skip superclass' SSH to machine if all data is present, otherwise defer to super if (name.isPresent() && version.isPresent() && architecture.isPresent() && ram.isPresent() && cpus.isPresent()) { if (LOG.isTraceEnabled()) { LOG.trace("Gathered machine details from Jclouds, skipping SSH test on {}", this); } OsDetails osD = new BasicOsDetails(name.get(), architecture.get(), version.get()); HardwareDetails hwD = new BasicHardwareDetails(cpus.get(), ram.get()); return new BasicMachineDetails(hwD, osD); } else if ("false".equalsIgnoreCase(getConfig(JcloudsLocation.WAIT_FOR_SSHABLE))) { if (LOG.isTraceEnabled()) { LOG.trace( "Machine details for {} missing from Jclouds, but skipping SSH test because waitForSshable=false. name={}, version={}, " + "arch={}, ram={}, #cpus={}", new Object[] { this, name, version, architecture, ram, cpus }); } OsDetails osD = new BasicOsDetails(name.orNull(), architecture.orNull(), version.orNull()); HardwareDetails hwD = new BasicHardwareDetails(cpus.orNull(), ram.orNull()); return new BasicMachineDetails(hwD, osD); } else { if (LOG.isTraceEnabled()) { LOG.trace( "Machine details for {} missing from Jclouds, using SSH test instead. name={}, version={}, " + "arch={}, ram={}, #cpus={}", new Object[] { this, name, version, architecture, ram, cpus }); } return super.inferMachineDetails(); } }
From source file:org.apache.brooklyn.location.jclouds.JcloudsLocation.java
protected JcloudsSshMachineLocation createJcloudsSshMachineLocation(ComputeService computeService, NodeMetadata node, Optional<Template> template, String vmHostname, Optional<HostAndPort> sshHostAndPort, LoginCredentials userCredentials, ConfigBag setup) throws IOException { Map<?, ?> sshConfig = extractSshConfig(setup, node); String nodeAvailabilityZone = extractAvailabilityZone(setup, node); String nodeRegion = extractRegion(setup, node); if (nodeRegion == null) { // e.g. rackspace doesn't have "region", so rackspace-uk is best we can say (but zone="LON") nodeRegion = extractProvider(setup, node); }/*www . j a v a2 s .com*/ String address = sshHostAndPort.isPresent() ? sshHostAndPort.get().getHostText() : vmHostname; try { Networking.getInetAddressWithFixedName(address); // fine, it resolves } catch (Exception e) { // occurs if an unresolvable hostname is given as vmHostname, and the machine only has private IP addresses but they are reachable // TODO cleanup use of getPublicHostname so its semantics are clearer, returning reachable hostname or ip, and // do this check/fix there instead of here! Exceptions.propagateIfFatal(e); LOG.debug("Could not resolve reported address '" + address + "' for " + vmHostname + " (" + setup.getDescription() + "/" + node + "), requesting reachable address"); if (computeService == null) throw Exceptions.propagate(e); // this has sometimes already been done in waitForReachable (unless skipped) but easy enough to do again address = getFirstReachableAddress(node, setup); } if (LOG.isDebugEnabled()) LOG.debug("creating JcloudsSshMachineLocation representation for {}@{} ({}/{}) for {}/{}", new Object[] { getUser(setup), address, Sanitizer.sanitize(sshConfig), sshHostAndPort, setup.getDescription(), node }); if (isManaged()) { return getManagementContext().getLocationManager().createLocation(LocationSpec .create(JcloudsSshMachineLocation.class).configure("displayName", vmHostname) .configure("address", address) .configure(JcloudsSshMachineLocation.SSH_PORT, sshHostAndPort.isPresent() ? sshHostAndPort.get().getPort() : node.getLoginPort()) // don't think "config" does anything .configure(sshConfig) // FIXME remove "config" -- inserted directly, above .configure("config", sshConfig).configure("user", userCredentials.getUser()) .configure(SshMachineLocation.PASSWORD, userCredentials.getOptionalPassword().orNull()) .configure(SshMachineLocation.PRIVATE_KEY_DATA, userCredentials.getOptionalPrivateKey().orNull()) .configure("jcloudsParent", this).configure("node", node) .configure("template", template.orNull()) .configureIfNotNull(CLOUD_AVAILABILITY_ZONE_ID, nodeAvailabilityZone) .configureIfNotNull(CLOUD_REGION_ID, nodeRegion) .configure(CALLER_CONTEXT, setup.get(CALLER_CONTEXT)) .configure(SshMachineLocation.DETECT_MACHINE_DETAILS, setup.get(SshMachineLocation.DETECT_MACHINE_DETAILS)) .configureIfNotNull(SshMachineLocation.SCRIPT_DIR, setup.get(SshMachineLocation.SCRIPT_DIR)) .configureIfNotNull(USE_PORT_FORWARDING, setup.get(USE_PORT_FORWARDING)) .configureIfNotNull(PORT_FORWARDER, setup.get(PORT_FORWARDER)) .configureIfNotNull(PORT_FORWARDING_MANAGER, setup.get(PORT_FORWARDING_MANAGER))); } else { LOG.warn("Using deprecated JcloudsSshMachineLocation constructor because " + this + " is not managed"); return new JcloudsSshMachineLocation(MutableMap.builder().put("displayName", vmHostname) .put("address", address) .put("port", sshHostAndPort.isPresent() ? sshHostAndPort.get().getPort() : node.getLoginPort()) // don't think "config" does anything .putAll(sshConfig) // FIXME remove "config" -- inserted directly, above .put("config", sshConfig).put("user", userCredentials.getUser()) .putIfNotNull(SshMachineLocation.PASSWORD.getName(), userCredentials.getOptionalPassword().orNull()) .putIfNotNull(SshMachineLocation.PRIVATE_KEY_DATA.getName(), userCredentials.getOptionalPrivateKey().orNull()) .put("callerContext", setup.get(CALLER_CONTEXT)) .putIfNotNull(CLOUD_AVAILABILITY_ZONE_ID.getName(), nodeAvailabilityZone) .putIfNotNull(CLOUD_REGION_ID.getName(), nodeRegion) .put(USE_PORT_FORWARDING, setup.get(USE_PORT_FORWARDING)) .put(PORT_FORWARDER, setup.get(PORT_FORWARDER)) .put(PORT_FORWARDING_MANAGER, setup.get(PORT_FORWARDING_MANAGER)).build(), this, node); } }
From source file:com.splicemachine.db.impl.sql.catalog.DataDictionaryImpl.java
/** * Get the target role definition by searching for a matching row * in SYSROLES by rolename where isDef==true. Read only scan. * Uses index on (rolename, isDef) columns. * * @param roleName The name of the role we're interested in. * @return The descriptor (row) for the role * @throws StandardException Thrown on error * @see DataDictionary#getRoleDefinitionDescriptor *//*ww w . j ava 2s .c o m*/ @Override public RoleGrantDescriptor getRoleDefinitionDescriptor(String roleName) throws StandardException { Optional<RoleGrantDescriptor> optional = dataDictionaryCache.roleCacheFind(roleName); if (optional != null && optional.isPresent()) return optional.orNull(); DataValueDescriptor roleNameOrderable; DataValueDescriptor isDefOrderable; TabInfoImpl ti = getNonCoreTI(SYSROLES_CATALOG_NUM); /* Use aliasNameOrderable , isDefOrderable in both start * and stop position for scan. */ roleNameOrderable = new SQLVarchar(roleName); isDefOrderable = new SQLVarchar("Y"); /* Set up the start/stop position for the scan */ ExecIndexRow keyRow = exFactory.getIndexableRow(2); keyRow.setColumn(1, roleNameOrderable); keyRow.setColumn(2, isDefOrderable); RoleGrantDescriptor rgs = (RoleGrantDescriptor) getDescriptorViaIndex( SYSROLESRowFactory.SYSROLES_INDEX_ID_DEF_IDX, keyRow, null, ti, null, null, false); dataDictionaryCache.roleCacheAdd(roleName, rgs == null ? Optional.<RoleGrantDescriptor>absent() : Optional.of(rgs)); return rgs; }