Search in sources :

Example 1 with RuntimeConfigurationProvider

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;
}
Also used : Path(java.nio.file.Path) ZipInputStream(java.util.zip.ZipInputStream) RuntimeConfigurationProvider(org.openntf.openliberty.domino.config.RuntimeConfigurationProvider) ZipInputStream(java.util.zip.ZipInputStream) InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) URL(java.net.URL)

Example 2 with RuntimeConfigurationProvider

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();
    }
}
Also used : Path(java.nio.file.Path) RuntimeConfigurationProvider(org.openntf.openliberty.domino.config.RuntimeConfigurationProvider) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException)

Example 3 with RuntimeConfigurationProvider

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);
    }
}
Also used : Path(java.nio.file.Path) LinkedHashSet(java.util.LinkedHashSet) RuntimeConfigurationProvider(org.openntf.openliberty.domino.config.RuntimeConfigurationProvider) ZipOutputStream(java.util.zip.ZipOutputStream) ZipOutputStream(java.util.zip.ZipOutputStream) OutputStream(java.io.OutputStream) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException)

Example 4 with RuntimeConfigurationProvider

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;
}
Also used : ReverseProxyTarget(org.openntf.openliberty.domino.reverseproxy.ReverseProxyTarget) ViewNavigator(lotus.domino.ViewNavigator) RuntimeConfigurationProvider(org.openntf.openliberty.domino.config.RuntimeConfigurationProvider) Document(lotus.domino.Document) View(lotus.domino.View) URI(java.net.URI) InvalidKeySpecException(java.security.spec.InvalidKeySpecException) KeyStoreException(java.security.KeyStoreException) InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) NoSuchPaddingException(javax.crypto.NoSuchPaddingException) UnrecoverableKeyException(java.security.UnrecoverableKeyException) NotesException(lotus.domino.NotesException) IOException(java.io.IOException) KeyManagementException(java.security.KeyManagementException) CertificateException(java.security.cert.CertificateException) ExecutionException(java.util.concurrent.ExecutionException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidKeyException(java.security.InvalidKeyException) ReverseProxyConfig(org.openntf.openliberty.domino.reverseproxy.ReverseProxyConfig) ViewEntry(lotus.domino.ViewEntry) Database(lotus.domino.Database) Collection(java.util.Collection) List(java.util.List) ExecutionException(java.util.concurrent.ExecutionException) Vector(java.util.Vector) Session(lotus.domino.Session)

Example 5 with RuntimeConfigurationProvider

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;
}
Also used : Path(java.nio.file.Path) Files(java.nio.file.Files) Collection(java.util.Collection) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) Level(java.util.logging.Level) StringUtil(org.openntf.openliberty.domino.util.commons.ibm.StringUtil) OpenLibertyUtil(org.openntf.openliberty.domino.util.OpenLibertyUtil) MessageFormat.format(java.text.MessageFormat.format) List(java.util.List) Messages(org.openntf.openliberty.domino.runtime.Messages) Map(java.util.Map) OpenLibertyLog(org.openntf.openliberty.domino.log.OpenLibertyLog) Path(java.nio.file.Path) RuntimeConfigurationProvider(org.openntf.openliberty.domino.config.RuntimeConfigurationProvider) RuntimeConfigurationProvider(org.openntf.openliberty.domino.config.RuntimeConfigurationProvider) Collection(java.util.Collection) List(java.util.List) Map(java.util.Map)

Aggregations

RuntimeConfigurationProvider (org.openntf.openliberty.domino.config.RuntimeConfigurationProvider)7 Path (java.nio.file.Path)6 Collection (java.util.Collection)4 List (java.util.List)4 IOException (java.io.IOException)3 Files (java.nio.file.Files)3 MessageFormat.format (java.text.MessageFormat.format)3 Map (java.util.Map)3 Level (java.util.logging.Level)3 Logger (java.util.logging.Logger)3 Collectors (java.util.stream.Collectors)3 OpenLibertyLog (org.openntf.openliberty.domino.log.OpenLibertyLog)3 Messages (org.openntf.openliberty.domino.runtime.Messages)3 OpenLibertyUtil (org.openntf.openliberty.domino.util.OpenLibertyUtil)3 StringUtil (org.openntf.openliberty.domino.util.commons.ibm.StringUtil)3 UncheckedIOException (java.io.UncheckedIOException)2 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 URI (java.net.URI)1 URL (java.net.URL)1