本文整理汇总了Java中org.apache.brooklyn.util.text.Identifiers类的典型用法代码示例。如果您正苦于以下问题:Java Identifiers类的具体用法?Java Identifiers怎么用?Java Identifiers使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Identifiers类属于org.apache.brooklyn.util.text包,在下文中一共展示了Identifiers类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: uploadSingleYaml
import org.apache.brooklyn.util.text.Identifiers; //导入依赖的package包/类
public ParsingResult<Csar> uploadSingleYaml(InputStream resourceFromUrl, String callerReferenceName) {
try {
String nameCleaned = Strings.makeValidFilename(callerReferenceName);
File tmpBase = new File(tmpRoot, nameCleaned + "_" + Identifiers.makeRandomId(6));
File tmpExpanded = new File(tmpBase, nameCleaned + "_" + Identifiers.makeRandomId(6));
File tmpTarget = new File(tmpExpanded.toString() + ".csar.zip");
boolean created = tmpExpanded.mkdirs();
if (!created) {
throw new Exception("Failed to create '" + tmpExpanded + "' when uploading yaml from " + nameCleaned);
}
FileUtils.copyInputStreamToFile(resourceFromUrl, new File(tmpExpanded, nameCleaned + ".yaml"));
ArchiveBuilder.archive(tmpTarget.toString()).addDirContentsAt(tmpExpanded, "").create();
try {
return uploadArchive(tmpTarget, callerReferenceName);
} finally {
Os.deleteRecursively(tmpBase);
}
} catch (Exception e) {
throw Exceptions.propagate(e);
}
}
示例2: generateAndUpdatePassword
import org.apache.brooklyn.util.text.Identifiers; //导入依赖的package包/类
/**
* Need to wait server to start before resetting the password.
*/
protected void generateAndUpdatePassword() {
String password = getAttribute(AmbariServer.PASSWORD);
if (password == null) {
password = getConfig(AmbariServer.PASSWORD);
if (password == null) {
password = Identifiers.makeRandomId(10);
}
usernamePasswordCredentials = new UsernamePasswordCredentials(USERNAME, password);
ImmutableMap<String, ImmutableMap<String, String>> userRequest = ImmutableMap.of("Users", ImmutableMap.of(
"user_name", USERNAME,
"old_password", INITIAL_PASSWORD,
"password", usernamePasswordCredentials.getPassword()
));
waitForServiceUp();
restAdapter.create(UsersEndpoint.class).updateUser(userRequest);
restAdapter = new RestAdapter.Builder()
.setEndpoint(ambariUri)
.setClient(ambariRestClient)
.setRequestInterceptor(new AmbariRequestInterceptor(usernamePasswordCredentials))
.setLogLevel(RestAdapter.LogLevel.FULL)
.build();
disconnectAuthenticatedSensors();
connectAuthenticatedSensors();
sensors().set(AmbariServer.PASSWORD, password);
}
}
示例3: uploadArchive
import org.apache.brooklyn.util.text.Identifiers; //导入依赖的package包/类
public ParsingResult<Csar> uploadArchive(InputStream resourceFromUrl, String callerReferenceName) {
try {
File f = new File(tmpRoot, callerReferenceName + "_" + Identifiers.makeRandomId(8));
Streams.copy(resourceFromUrl, new FileOutputStream(f));
return uploadArchive(f, callerReferenceName);
} catch (Exception e) {
throw Exceptions.propagate(e);
}
}
示例4: initApplicationParameters
import org.apache.brooklyn.util.text.Identifiers; //导入依赖的package包/类
private void initApplicationParameters() {
if(!Strings.isBlank(getEntity().getConfig(CloudFoundryWebApp.APPLICATION_NAME))){
applicationName = getEntity().getConfig(CloudFoundryWebApp.APPLICATION_NAME);
} else {
applicationName = "cf-app-" + Identifiers.makeRandomId(8);
}
applicationUrl = getEntity().getConfig(CloudFoundryWebApp.APPLICATION_URL);
}
示例5: setHostsOnMachines
import org.apache.brooklyn.util.text.Identifiers; //导入依赖的package包/类
public static void setHostsOnMachines(Iterable<? extends Entity> machines, AttributeSensor<String> addressSensor) {
Map<String, String> mapping = gatherIpHostnameMapping(machines, addressSensor);
for (Entity e : machines) {
Maybe<SshMachineLocation> sshLocation = Machines.findUniqueSshMachineLocation(e.getLocations());
if (!sshLocation.isPresentAndNonNull()) {
LOG.debug("{} has no {}, not setting hostname or updating /etc/hosts", e, SshMachineLocation.class);
continue;
}
SshMachineLocation loc = sshLocation.get();
ImmutableList.Builder<String> commands = ImmutableList.builder();
// It would be great if we could use BashCommands.setHostname(), but it doesn't quite do what we need: it
// maps the hostname to 127.0.0.1. But this then means that e.g. "ping myhostname" pings 127.0.0.1, and that
// behaviour causes some processes to bind ports to 127.0.0.1 instead of 0.0.0.0. What we need instead is
// that the first line maps the hostname to its actual IP address. So we partly override the behaviour of
// this method later by pre-pending to /etc/hosts.
// Find and set entity's own hostname
Maybe<String> ip = Machines.findSubnetOrPrivateIp(e);
String key = e.getAttribute(addressSensor);
if (ip.isAbsentOrNull()) {
LOG.debug("{} has no IP address, not setting hostname", e);
continue;
} else if (!mapping.containsKey(key)) {
LOG.debug("{} has no hostname mapping, not setting hostname", e);
} else {
commands.addAll(BashCommands.setHostname(mapping.get(key)));
}
// Add the other entity's details to /etc/hosts
for (Map.Entry<String, String> entry : mapping.entrySet()) {
boolean isMyOwnEntry = entry.getKey().equals(key);
String fqdn = entry.getValue();
if (fqdn.endsWith("."))
fqdn = fqdn.substring(0, fqdn.length() - 1);
int dotAt = fqdn.indexOf('.');
String[] values = dotAt > 0
? new String[]{fqdn, fqdn.substring(0, dotAt)}
: new String[]{fqdn};
if (isMyOwnEntry)
commands.add(prependToEtcHosts(ip.get(), values));
else
commands.add(appendToEtcHosts(entry.getKey(), values));
}
// Ensure that 127.0.0.1 maps to localhost, and nothing else
String bakFileExtension = "bak" + Identifiers.makeRandomId(4);
commands.add(
sudo("sed -i." + bakFileExtension + " -e \'s/127.0.0.1\\s.*/127.0.0.1 localhost/\' /etc/hosts"));
loc.execCommands("set hostname and fill /etc/hosts", commands.build());
}
}
示例6: apply
import org.apache.brooklyn.util.text.Identifiers; //导入依赖的package包/类
@Override
public void apply(EntitySpec<?> entitySpec, String nodeId, ToscaApplication toscaApplication) {
final Iterable<String> artifacts = getToscaFacade().getArtifacts(nodeId, toscaApplication);
if (Iterables.isEmpty(artifacts)) {
return;
}
final Map<String, String> filesToCopy = MutableMap.of();
// As PRE_INSTALL_FILES is explicitly Map<String, String>, we can't use a deferred "run.dir" in the
// destination path, so we must use the install.dir, which is shared by all instances of the same
// type (with the exception of VanillaSoftwareProcess). In order to prevent collision between
// e.g. multiple instances of MySql on the same server, we must use an instance-specific prefix
final String directoryPrefix = Identifiers.makeRandomJavaId(6);
for (final String artifactId : artifacts) {
Optional<Path> optionalResourcesRootPath = getToscaFacade().getArtifactPath(nodeId, toscaApplication, artifactId);
if(!optionalResourcesRootPath.isPresent()) {
continue;
}
// We know that formatString will return a BrooklynDslDeferredSupplier as the 2nd argument is not yet resolved
BrooklynDslDeferredSupplier<String> deferredInstallDir = (BrooklynDslDeferredSupplier<String>) BrooklynDslCommon.formatString("%s/%s/%s", BrooklynDslCommon.attributeWhenReady("install.dir"), directoryPrefix, artifactId);
entitySpec.configure(SoftwareProcess.SHELL_ENVIRONMENT.subKey(artifactId), deferredInstallDir);
// Copy all files in resource.
try {
Files.walkFileTree(optionalResourcesRootPath.get(), new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
filesToCopy.put(file.toAbsolutePath().toString(), String.format("%s/%s/%s", directoryPrefix, artifactId, file.getFileName().toString()));
return FileVisitResult.CONTINUE;
}
});
} catch (IOException e) {
LOG.warn("Cannot parse CSAR resources", e);
}
}
// It's not possible to infer from the artifact at what point these files will be used, so
// they need to be copied at the earliest point possible
entitySpec.configure(SoftwareProcess.PRE_INSTALL_FILES, filesToCopy);
}
示例7: initTemplateName
import org.apache.brooklyn.util.text.Identifiers; //导入依赖的package包/类
private void initTemplateName() {
this.templateName = Strings.isBlank((String) template.get(TEMPLATE_NAME))
? TEMPLATE_NAME_PREFIX + Identifiers.makeRandomId(8)
: (String) template.get(TEMPLATE_NAME);
}