use of org.openntf.openliberty.domino.config.RuntimeConfigurationProvider in project openliberty-domino by OpenNTF.
the class LibertyRuntimeDeployment method deploy.
@Override
public Path deploy(LibertyServerConfiguration config) throws IOException {
RuntimeConfigurationProvider runtimeConfig = OpenLibertyUtil.findRequiredExtension(RuntimeConfigurationProvider.class);
Path execDir = runtimeConfig.getBaseDirectory();
String version = config.getLibertyVersion();
if (StringUtil.isEmpty(version)) {
version = DEFAULT_VERSION;
}
// $NON-NLS-1$
Path wlp = execDir.resolve(format("wlp-{0}", version));
if (!Files.isDirectory(wlp)) {
// If it doesn't yet exist, download and deploy a new runtime
if (log.isLoggable(Level.INFO)) {
// $NON-NLS-1$
log.info(Messages.getString("StandardRuntimeDeployment.deployingNewRuntime"));
}
String artifact = config.getLibertyArtifact();
if (StringUtil.isEmpty(artifact)) {
artifact = DEFAULT_ARTIFACT;
}
// $NON-NLS-1$
Path downloadDir = execDir.resolve("download");
Path wlpPackage = downloadDir.resolve(buildZipName(artifact, version));
if (!Files.exists(wlpPackage)) {
Files.createDirectories(downloadDir);
// Download from Maven
String mavenRepo = config.getLibertyMavenRepo();
if (StringUtil.isEmpty(mavenRepo)) {
mavenRepo = DEFAULT_MAVENREPO;
}
URL url = buildDownloadURL(mavenRepo, artifact, version);
if (log.isLoggable(Level.INFO)) {
// $NON-NLS-1$
log.info(format(Messages.getString("StandardRuntimeDeployment.downloadingRuntimeFrom"), url));
}
if (log.isLoggable(Level.INFO)) {
// $NON-NLS-1$
log.info(format(Messages.getString("StandardRuntimeDeployment.storingRuntimeAt"), wlpPackage));
}
OpenLibertyUtil.download(url, is -> {
Files.copy(is, wlpPackage, StandardCopyOption.REPLACE_EXISTING);
return null;
});
}
// Now extract the ZIP
Files.createDirectories(wlp);
try (InputStream is = Files.newInputStream(wlpPackage)) {
try (ZipInputStream zis = new ZipInputStream(is)) {
ZipEntry entry = zis.getNextEntry();
while (entry != null) {
String name = entry.getName();
if (name.startsWith("wlp/")) {
// $NON-NLS-1$
// Remove the standard prefix
name = name.substring(4);
}
if (StringUtil.isNotEmpty(name)) {
if (log.isLoggable(Level.FINER)) {
// $NON-NLS-1$
log.finer(format(Messages.getString("StandardRuntimeDeployment.deployingFile"), name));
}
Path path = wlp.resolve(name);
if (entry.isDirectory()) {
Files.createDirectories(path);
} else {
Files.copy(zis, path, StandardCopyOption.REPLACE_EXISTING);
}
}
zis.closeEntry();
entry = zis.getNextEntry();
}
}
}
}
verifyRuntime(wlp);
return wlp;
}
use of org.openntf.openliberty.domino.config.RuntimeConfigurationProvider in project openliberty-domino by OpenNTF.
the class NotesAPIExtension method findOsgiEmbed.
private Optional<Path> findOsgiEmbed(String bundleName, String embedName) {
RuntimeConfigurationProvider config = OpenLibertyUtil.findRequiredExtension(RuntimeConfigurationProvider.class);
Path domino = config.getDominoProgramDirectory();
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
Path osgiSharedPath = domino.resolve("osgi").resolve("shared").resolve("eclipse").resolve("plugins");
if (Files.isDirectory(osgiSharedPath)) {
try {
return Files.find(osgiSharedPath, 1, (path, attr) -> path.getFileName().toString().startsWith(bundleName + '_')).findFirst().flatMap(p -> {
Path jar = p.resolve(embedName);
if (Files.isRegularFile(jar)) {
return Optional.of(jar);
} else {
return Optional.empty();
}
});
} catch (IOException e) {
throw new UncheckedIOException(e);
}
} else {
return Optional.empty();
}
}
use of org.openntf.openliberty.domino.config.RuntimeConfigurationProvider in project openliberty-domino by OpenNTF.
the class NotesAPIExtension method getEsaData.
@Override
public InputStream getEsaData() {
// Build our bundle if we need it
RuntimeConfigurationProvider config = OpenLibertyUtil.findRequiredExtension(RuntimeConfigurationProvider.class);
Path wlp = config.getBaseDirectory();
String dominoVersion = config.getDominoVersion();
// $NON-NLS-1$
Path cacheDir = wlp.resolve("work").resolve(getClass().getName());
if (!Files.isDirectory(cacheDir)) {
try {
Files.createDirectories(cacheDir);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
// $NON-NLS-1$
Path out = cacheDir.resolve(dominoVersion + ".esa");
if (!Files.isRegularFile(out)) {
try (OutputStream os = Files.newOutputStream(out, StandardOpenOption.CREATE);
ZipOutputStream zos = new ZipOutputStream(os, StandardCharsets.UTF_8)) {
// Build our ESA, which will include SUBSYSTEM.MF and the bundle
List<Path> embeds = getEmbeds();
Collection<String> packages = new LinkedHashSet<>();
findNotesJar().ifPresent(jar -> {
packages.addAll(listPackages(jar));
});
findIbmNapi().ifPresent(jar -> {
packages.addAll(listPackages(jar));
});
buildSubsystemMf(dominoVersion, packages, zos);
buildApiBundle(dominoVersion, packages, embeds, zos);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
try {
return Files.newInputStream(out);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
use of org.openntf.openliberty.domino.config.RuntimeConfigurationProvider in project openliberty-domino by OpenNTF.
the class AdminNSFProxyConfigProvider method createConfiguration.
@SuppressWarnings("unchecked")
@Override
public ReverseProxyConfig createConfiguration() {
ReverseProxyConfig result = new ReverseProxyConfig();
RuntimeConfigurationProvider runtimeConfig = OpenLibertyUtil.findRequiredExtension(RuntimeConfigurationProvider.class);
result.dominoHostName = runtimeConfig.getDominoHostName();
result.dominoHttpPort = runtimeConfig.getDominoPort();
result.dominoHttps = runtimeConfig.isDominoHttps();
try {
DominoThreadFactory.getExecutor().submit(() -> {
try {
Session session = NotesFactory.createSession();
try {
Database adminNsf = AdminNSFUtil.getAdminDatabase(session);
Document config = AdminNSFUtil.getConfigurationDocument(adminNsf);
// Load the main config
boolean connectorHeaders = runtimeConfig.isUseDominoConnectorHeaders();
readConfigurationDocument(result, config, connectorHeaders);
if (!result.isGlobalEnabled()) {
return;
}
Collection<String> namesList = AdminNSFUtil.getCurrentServerNamesList();
// Look for proxy-enabled webapps
View targetsView = adminNsf.getView(VIEW_REVERSEPROXYTARGETS);
targetsView.setAutoUpdate(false);
targetsView.refresh();
ViewNavigator nav = targetsView.createViewNav();
nav.setEntryOptions(ViewNavigator.VN_ENTRYOPT_NOCOUNTDATA);
ViewEntry entry = nav.getFirst();
while (entry != null) {
Vector<?> columnValues = entry.getColumnValues();
List<String> dominoServers;
Object dominoServersObj = columnValues.get(4);
if (dominoServersObj instanceof String) {
dominoServers = Arrays.asList((String) dominoServersObj);
} else {
dominoServers = (List<String>) dominoServersObj;
}
boolean shouldRun = AdminNSFUtil.isNamesListMatch(namesList, dominoServers);
if (shouldRun) {
// Format: http://localhost:80
String baseUri = (String) columnValues.get(1);
// $NON-NLS-1$
boolean useXForwardedFor = "Y".equals(columnValues.get(2));
// $NON-NLS-1$
boolean useWsHeaders = "Y".equals(columnValues.get(3));
// Now read the children to build targets
ViewEntry childEntry = nav.getChild(entry);
while (childEntry != null) {
Vector<?> childValues = childEntry.getColumnValues();
// Format: foo
String contextPath = (String) childValues.get(0);
// $NON-NLS-1$
URI uri = URI.create(baseUri + "/" + contextPath);
ReverseProxyTarget target = new ReverseProxyTarget(uri, useXForwardedFor, useWsHeaders);
result.addTarget(contextPath, target);
childEntry.recycle(childValues);
ViewEntry tempChild = childEntry;
childEntry = nav.getNextSibling(childEntry);
tempChild.recycle();
}
}
entry.recycle(columnValues);
ViewEntry tempEntry = entry;
entry = nav.getNextSibling(entry);
tempEntry.recycle();
}
} finally {
session.recycle();
}
return;
} catch (Throwable e) {
e.printStackTrace(OpenLibertyLog.instance.out);
throw new RuntimeException(e);
}
}).get();
if (result.isGlobalEnabled()) {
// Determine the local server port from the server doc
DominoThreadFactory.getExecutor().submit(() -> {
try {
Session session = NotesFactory.createSession();
try {
String serverName = session.getUserName();
// $NON-NLS-1$ //$NON-NLS-2$
Database names = session.getDatabase("", "names.nsf");
// $NON-NLS-1$
View servers = names.getView("$Servers");
Document serverDoc = servers.getDocumentByKey(serverName);
// Mirror Domino's maximum entity size
// $NON-NLS-1$
long maxEntitySize = serverDoc.getItemValueInteger("HTTP_MaxContentLength");
if (maxEntitySize == 0) {
maxEntitySize = Long.MAX_VALUE;
}
result.maxEntitySize = maxEntitySize;
} finally {
session.recycle();
}
} catch (Exception e) {
e.printStackTrace(OpenLibertyLog.instance.out);
throw new RuntimeException(e);
}
}).get();
}
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace(OpenLibertyLog.instance.out);
throw new RuntimeException(e);
}
return result;
}
use of org.openntf.openliberty.domino.config.RuntimeConfigurationProvider in project openliberty-domino by OpenNTF.
the class AdoptiumJavaRuntimeProvider method getJavaHome.
@SuppressWarnings("unchecked")
@Override
public Path getJavaHome(JVMIdentifier identifier) {
String version = identifier.getVersion();
String javaJvm = identifier.getType();
if (StringUtil.isEmpty(javaJvm)) {
// $NON-NLS-1$
javaJvm = "HotSpot";
}
if (log.isLoggable(Level.FINE)) {
// $NON-NLS-1$
log.fine(format(Messages.getString("JavaRuntimeProvider.configuredJavaRuntimeWithJVM"), version, javaJvm));
}
// Check for an existing JVM
RuntimeConfigurationProvider config = OpenLibertyUtil.findRequiredExtension(RuntimeConfigurationProvider.class);
Path execDir = config.getBaseDirectory();
// $NON-NLS-1$ //$NON-NLS-2$
Path jvmDir = execDir.resolve("jvm").resolve(version + "-" + javaJvm);
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
String execName = "java" + (OpenLibertyUtil.IS_WINDOWS ? ".exe" : "");
if (Files.exists(jvmDir.resolve("bin").resolve(execName))) {
// $NON-NLS-1$
if (log.isLoggable(Level.FINE)) {
// $NON-NLS-1$
log.info(format(Messages.getString("JavaRuntimeProvider.usingDownloadedRuntime"), jvmDir));
}
// Assume the whole JVM exists
return jvmDir;
}
// Otherwise, look for a release on GitHub
if ("1.8".equals(version)) {
// $NON-NLS-1$
// $NON-NLS-1$
version = "8";
}
String releasesUrl = format(API_RELEASES, version);
// TODO support pagination here (page= and per_page query params,
List<Map<String, Object>> releases = fetchGitHubReleasesList(PROVIDER_NAME, releasesUrl);
// Find any applicable releases, in order, as some releases may contain only certain platforms
List<Map<String, Object>> validReleases = releases.stream().filter(// $NON-NLS-1$
release -> !(Boolean) release.get("prerelease")).filter(// $NON-NLS-1$
release -> !(Boolean) release.get("draft")).filter(// $NON-NLS-1$
release -> release.containsKey("assets")).collect(Collectors.toList());
if (validReleases.isEmpty()) {
// $NON-NLS-1$
throw new IllegalStateException(format(Messages.getString("JavaRuntimeProvider.unableToLocateJDKBuild"), PROVIDER_NAME, identifier, releasesUrl));
}
// HotSpot:
// Linux: https://github.com/AdoptOpenJDK/openjdk11-binaries/releases/download/jdk-11.0.6%2B10/OpenJDK11U-jdk_x64_linux_hotspot_11.0.6_10.tar.gz
// Windows x64: https://github.com/AdoptOpenJDK/openjdk11-binaries/releases/download/jdk-11.0.6%2B10/OpenJDK11U-jdk_x64_windows_hotspot_11.0.6_10.zip
// Windows x86: https://github.com/AdoptOpenJDK/openjdk11-binaries/releases/download/jdk-11.0.6%2B10/OpenJDK11U-jdk_x86-32_windows_hotspot_11.0.6_10.zip
// $NON-NLS-1$
String qualifier = format("jdk_{0}_{1}", getOsArch(), getOsName());
Map<String, Object> download = validReleases.stream().map(// $NON-NLS-1$
release -> (List<Map<String, Object>>) release.get("assets")).flatMap(Collection::stream).filter(// $NON-NLS-1$ //$NON-NLS-2$
asset -> !StringUtil.toString(asset.get("name")).contains("-testimage")).filter(// $NON-NLS-1$ //$NON-NLS-2$
asset -> !StringUtil.toString(asset.get("name")).contains("-debugimage")).filter(// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
asset -> StringUtil.toString(asset.get("name")).contains("-" + qualifier + "_")).filter(// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
asset -> "application/x-compressed-tar".equals(asset.get("content_type")) || "application/zip".equals(asset.get("content_type"))).findFirst().orElseThrow(// $NON-NLS-1$
() -> new IllegalStateException(format(Messages.getString("JavaRuntimeProvider.unableToFindJDKBuildFor"), PROVIDER_NAME, qualifier)));
if (log.isLoggable(Level.INFO)) {
// $NON-NLS-1$//$NON-NLS-2$
log.info(format(Messages.getString("JavaRuntimeProvider.downloadingJDKFrom"), PROVIDER_NAME, download.get("browser_download_url")));
}
// $NON-NLS-1$
String contentType = (String) download.get("content_type");
// $NON-NLS-1$
download((String) download.get("browser_download_url"), contentType, jvmDir);
markExecutables(jvmDir);
return jvmDir;
}
Aggregations