use of com.oracle.bedrock.OptionsByType in project oracle-bedrock by coherence-community.
the class AbstractAssembly method expand.
/**
* Expands the number of {@link Application}s in the {@link Assembly} by launching and adding the specified number
* of {@link Application}s on the provided {@link Infrastructure} using the zero or more provided {@link Option}s.
*
* @param count the number of instances of the {@link Application} that should be launched and added
* to the {@link Assembly}
* @param infrastructure the {@link Infrastructure} on which to launch the {@link Application}s
* @param applicationClass the class of {@link Application}
* @param options the {@link Option}s to use for launching the {@link Application}s
*
* @see Platform#launch(String, Option...)
* @see AssemblyBuilder#include(int, Class, Option...)
*/
public void expand(int count, Infrastructure infrastructure, Class<? extends A> applicationClass, Option... options) {
// we keep track of the new applications that are launched
ArrayList<A> launchedApplications = new ArrayList<>();
// determine the common expandingOptions
OptionsByType expandingOptions = OptionsByType.of(optionsByType).addAll(options);
for (int i = 0; i < count; i++) {
// establish the launch options for the next application
OptionsByType launchOptions = OptionsByType.of(expandingOptions);
// include a discriminator for the application about to be launched
// (if it has a DisplayName, doesn't have a Discriminator and there are more than one to launch)
DisplayName displayName = launchOptions.getOrDefault(DisplayName.class, null);
if (displayName != null && !launchOptions.contains(Discriminator.class)) {
// acquire the discriminator counter for the application DisplayName
AtomicInteger counter = discriminators.computeIfAbsent(displayName, name -> new AtomicInteger(0));
// create a discriminator for the application
launchOptions.addIfAbsent(Discriminator.of(counter.incrementAndGet()));
}
// attempt to launch the application
try {
// acquire the platform from the infrastructure based on the launch options
Platform platform = infrastructure.getPlatform(launchOptions.asArray());
// launch the application
A application = platform.launch(applicationClass, launchOptions.asArray());
// remember the application
// (so we can add it to the assembly once they are all launched)
launchedApplications.add(application);
} catch (Throwable throwable) {
// ensure all recently launched applications are shutdown to prevent applications staying around
for (A application : launchedApplications) {
try {
application.close();
} catch (Throwable t) {
// we ignore any issues when the application fails to close
}
}
throw new RuntimeException("Failed to launch one of the desired " + applicationClass.getSimpleName() + "(s) out of " + count + " requested. " + "Automatically closed " + launchedApplications.size() + " that were successfully created. The options provided where " + launchOptions, throwable);
}
}
// include the launched applications in the assembly
for (A application : launchedApplications) {
// ensure the assembly is a feature of the application so that it can be called back for lifecycle events
application.add(Assembly.class, this);
// add the application to the assembly
applications.add(application);
}
// notify the assembly that it has expanded with the launched applications
onExpanded(launchedApplications, expandingOptions);
}
use of com.oracle.bedrock.OptionsByType in project oracle-bedrock by coherence-community.
the class PowerShellHttpDeployerTest method shouldDeployNullArtifacts.
@Test
public void shouldDeployNullArtifacts() throws Exception {
String destination = "/foo";
Platform platform = mock(Platform.class);
InetSocketAddress address = new InetSocketAddress(InetAddress.getLocalHost(), 1234);
OptionsByType optionsByType = OptionsByType.empty();
PowerShellHttpDeployer deploymentMethod = new PowerShellHttpDeployer();
DeployedArtifacts deployedArtifacts = new DeployedArtifacts();
deploymentMethod.deployAllArtifacts(null, destination, platform, address, optionsByType, deployedArtifacts);
}
use of com.oracle.bedrock.OptionsByType in project oracle-bedrock by coherence-community.
the class WindowsFileShareDeployer method performRemoteCopy.
@Override
protected boolean performRemoteCopy(String source, String destination, Platform platform, OptionsByType deploymentOptions) throws IOException {
if (platform instanceof RemotePlatform) {
WindowsRemoteTerminal terminal = new WindowsRemoteTerminal((RemotePlatform) platform);
OptionsByType optionsByType = OptionsByType.of(platform.getOptions());
optionsByType.addAll(deploymentOptions.asArray());
terminal.moveFile(source, destination, optionsByType);
return false;
} else {
throw new IllegalArgumentException("The platform argument must be an instance of a RemotePlatform");
}
}
use of com.oracle.bedrock.OptionsByType in project oracle-bedrock by coherence-community.
the class LocalApplicationProcess method waitFor.
@Override
public int waitFor(Option... options) {
OptionsByType optionsByType = OptionsByType.of(options);
Timeout timeout = optionsByType.get(Timeout.class);
DeferredHelper.ensure(eventually(invoking(this).exitValue()), within(timeout));
return exitValue();
}
use of com.oracle.bedrock.OptionsByType in project oracle-bedrock by coherence-community.
the class Profiles method getProfiles.
/**
* Auto-detect, instantiate and configure the set of {@link Profile}s.
*
* @return an {@link Iterable}
*/
public static OptionsByType getProfiles() {
final String ORACLE_TOOLS_PROFILE = "bedrock.profile.";
OptionsByType profiles = OptionsByType.empty();
for (String name : System.getProperties().stringPropertyNames()) {
if (name.startsWith(ORACLE_TOOLS_PROFILE)) {
// determine the profile name
String profileName = name.substring(ORACLE_TOOLS_PROFILE.length()).trim().toLowerCase();
// determine the profile value
String profileValue = System.getProperty(name);
// when the profile name contains a "." we don't process this system property
if (profileName.indexOf(".") < 0) {
String profileClassName = System.getProperty(name + ".classname");
if (profileClassName == null) {
// create a default class name based on the profile name
profileClassName = "com.oracle.bedrock." + profileName + "." + profileName.substring(0, 1).toUpperCase() + profileName.substring(1) + "Profile";
}
try {
// attempt to load the class for the profile
Class<?> profileClass = Class.forName(profileClassName);
// ensure that the Profile is an Option
if (Option.class.isAssignableFrom(profileClass)) {
// by attempting to request the Profile from the Profiles collection
// it will be instantiated using the appropriate default constructor / factory method
Profile profile = (Profile) profiles.get((Class<Option>) profileClass, profileValue);
} else {
// TODO: the specified profile is not an Option
}
} catch (Exception e) {
// TODO: failed to load the specified profile
}
}
}
}
return profiles;
}
Aggregations