Package org.jfx4ee.adm4ee.business.util

Examples of org.jfx4ee.adm4ee.business.util.CommandResult


    //TODO: eventually extract this method from data model:
    public void refreshDomainState() {
        Platform.runLater(() -> {
            logger.log(Level.INFO, "refreshDomainState()");
            logger.log(Level.INFO, "pinging ManagementResource");
            CommandResult result = getServer().pingManagementResource();
            if (result.getExitCode() > 0) {
                String errorMessage = result.getExitCodeInfo() + "(" + result.getExitCode()
                        + ")";
                logger.log(Level.SEVERE, errorMessage);
                Dialogs.create().title("An error occured!").message(errorMessage).
                        showError();
            }
            setDomainRunning(result.isOk());
            refreshUptimeInformation();
        });
    }
View Full Code Here


    }

    public void loadServerLog() {
        setServerLog("");
        if (getServer() != null) {
            CommandResult result = getServer().getLogFileContent(getLogFileCharacterCount());
            setServerLog(result.getResult());
        }
    }
View Full Code Here

        }

        // Create the password temp file
        File temp = createTemporaryAsadminPasswordFile(password);

        CommandResult result = null;
        try {

            // Construct the command line
            List<String> asAdminCommandLine = new ArrayList<>();
            asAdminCommandLine.add(asAdminCommand);
            asAdminCommandLine.add("--user");
            asAdminCommandLine.add(user);
            asAdminCommandLine.add("--passwordfile");
            asAdminCommandLine.add(temp.getAbsolutePath());

            asAdminCommandLine.add("create-domain");
            if (portBase > 0) {
                asAdminCommandLine.add("--portbase");
                asAdminCommandLine.add(Integer.toString(portBase));
            }
            if (!checkPorts) {
                asAdminCommandLine.add("--checkports");
                asAdminCommandLine.add("false");
            }

            // Check if we have a valid template
            if (template != null) {
                if (!template.exists()) {
                    throw new IllegalArgumentException("Domain template '" + template + "' does not exist");
                }
                // Create the domain from the template
                asAdminCommandLine.add("--template");
                if (template.isDirectory()) {
                    // Find domain xml template file
                    File domainXmlTemplate = template.toPath().resolve(DOMAIN_XML_FILE).toFile();
                    if (!domainXmlTemplate.isFile()) {
                        throw new IllegalArgumentException("Domain template file not found in '" + domainXmlTemplate.getAbsolutePath() + "'!");
                    }
                    asAdminCommandLine.add(domainXmlTemplate.getAbsolutePath());
                } else {
                    asAdminCommandLine.add(template.getAbsolutePath());
                }
            }

            // Add the desired domain name
            asAdminCommandLine.add(domainName);

            // Create the domain
            logger.log(Level.CONFIG, "Creating domain with: {0}", asAdminCommandLine);
            result = SystemCommandExecutor.execute(asAdminCommandLine);

        } finally {
            try {
                temp.delete();
            } catch (Exception ex) {
                logger.log(Level.WARNING, "Could not delete temporary password file '" + temp.getAbsolutePath() + "'! ", ex);
            }
        }

        if (result != null && result.isOk()) {
            if (template != null && template.isDirectory()) {
                try {
                    logger.log(Level.CONFIG, "Copying domain template files from {0} to {1}", new Object[]{template.getAbsolutePath(), getDomainPath()});
                    // Copy additional files to destination directories
                    copyDomainTemplateFiles(template);
                } catch (IOException ex) {
                    logger.log(Level.SEVERE, "Could not copy template files to domain directory! {0}", ex);
                    result.setExitCode(1);
                    result.setExitCodeInfo("Could not copy template files to domain directory!");
                    result.setThrowable(ex);
                }

                if (result.isOk()) {
                    setupDomain(template);
                }
            }
        }
View Full Code Here

    @Override
    public CommandResult startDomain(String domainName) {
        if (domainName == null) {
            throw new IllegalArgumentException("No domain name specified!");
        }
        CommandResult result = SystemCommandExecutor.execute(Arrays.asList(asAdminCommand, "start-domain", domainName));
        if (result.isOk()) {
            // Refresh the application status
            refreshApplicationStatus();
        }
        return result;
    }
View Full Code Here

        return SystemCommandExecutor.execute(Arrays.asList(asAdminCommand, "stop-domain", domain.getDomainName()));
    }

    @Override
    public CommandResult changeAdminPassword(String oldPassword, String newPassword) {
        CommandResult result = restManager.changeAdminPassword(oldPassword, newPassword);
        if (result.isOk()) {
            // Change the REST client password as well
            restManager.close();
            domain.setDomainPassword(newPassword);
            initRemoteDomain();
        }
View Full Code Here

        return result;
    }

    @Override
    public CommandResult pingManagementResource() {
        CommandResult result;
        try {
            result = restManager.ping();
        } catch (Exception ex) {
            // Could not fetch requested information
            logger.log(Level.FINE, "Could not ping DAS using {0}: {1}", new Object[]{restManager.getManagementUrl(), ex.toString()});
            result = new CommandResult(ex);
        }
        return result;
    }
View Full Code Here

     * @param characters Number of characters to fetch from the end of the server log file
     * @return command result containing log file content, never null
     */
    @Override
    public CommandResult getLogFileContent(long characters) {
        CommandResult result;
        try {
            // First get the log file position
            long position = restManager.getLogFilePosition();

            // Now read the log
            long offset = position - characters;
            if (offset < 0) {
                offset = 0;
            }
            result = new CommandResult(restManager.getLogFileContent(offset));

        } catch (Exception ex) {
            logger.log(Level.CONFIG, "Could not fetch head from view-log resource {0}: {1}", new Object[]{restManager.getManagementUrl(), ex.toString()});

            // In case of local domain, try local fallback
            if (asAdminCommand != null) {
                try {
                    result = new CommandResult(readBytesFromFileEnd(getDomainPath().resolve("logs").resolve("server.log").toString(), characters));
                } catch (Exception ex1) {
                    result = new CommandResult(ex1);
                }
            } else {
                result = new CommandResult(ex);
            }
        }
        return result;
    }
View Full Code Here

        return restManager.deleteApplication(application);
    }

    @Override
    public CommandResult updateApplication(String applicationName) {
        CommandResult result = new CommandResult();
        try {
            // Check if we have a valid template path
            String template = domain.getTemplate();
            if (template != null && !template.isEmpty()) {
                Path templatePath = Paths.get(template);
                File templateFile = templatePath.toFile();
                if (!templateFile.isDirectory()) {
                    // Not a file
                    logger.log(Level.SEVERE, "Template directory ''{0}'' is not a directory!", templatePath);
                    result.setResult("Invalid Template directory");
                } else {
                    Path templateApplicationsPath = templatePath.resolve(DOMAIN_APPLICATIONS_DIR);
                    Application application = domain.getApplication(applicationName);
                    if (application != null) {
                        ApplicationStatus status = application.getStatus();
                        if (status != null) {
                            Appcast appcast = status.getAppcast();
                            if (appcast != null) {
                                Set<Path> files = updater.update(applicationName, appcast, templateApplicationsPath);
                                result.setExitCodeOk();
                                result.setResult(files.toString());
                            }
                        }
                    }
                }
            } else {
                logger.log(Level.SEVERE, "Template directory not set in domain configuration!");
                result.setResult("Template not set");
            }
        } catch (Exception exception) {
            result.setThrowable(exception);
            result.setResult("Update failed");
        }
        return result;
    }
View Full Code Here

    /**
     * Initialize local version from asadmin command
     */
    protected void initLocalVersions() {
        CommandResult commandResult = SystemCommandExecutor.execute(Arrays.asList(asAdminCommand, "version", "--local", "--verbose"));
        if (commandResult.isOk()) {
            String output = commandResult.getResult();
            Matcher versionMatcher = PATTERN_VERSION_LOCAL.matcher(output);
            if (versionMatcher.find()) {
                localVersion = versionMatcher.group(1);
            }
            Matcher jdkVersionMatcher = PATTERN_JDK_VERSION_LOCAL.matcher(output);
            if (jdkVersionMatcher.find()) {
                localJdkVersion = jdkVersionMatcher.group(1);
            }
        } else {
            logger.log(Level.SEVERE, "Could not initialize local version information from ''asadmin'' command: {0}: {1}", new Object[]{commandResult.getResult(), commandResult.getThrowable()});
        }
    }
View Full Code Here

    public void pingConnectionPool() {
        Platform.runLater(() -> {
            resultMessageLabel.setText("");
            if (getSelectedJdpcPoolName() != null) {
                progressIndicator.setVisible(true);
                CommandResult result = domainDataModel.getServer().pingJdbcConnectionPool(getSelectedJdpcPoolName());
                progressIndicator.setVisible(false);
                if (result.isOk()) {
                    resultMessageLabel.getStyleClass().setAll("ping-result-label-success");
                    resultMessageLabel.setText(resources.getString("jdbcpool.message.pingResultSuccess"));
                } else {
                    resultMessageLabel.getStyleClass().setAll("ping-result-label-failed");
                    resultMessageLabel.setText(resources.getString("jdbcpool.message.pingResultFailed"));
View Full Code Here

TOP

Related Classes of org.jfx4ee.adm4ee.business.util.CommandResult

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.