Search in sources :

Example 1 with GAVConvertor

use of fish.payara.deployment.util.GAVConvertor in project Payara by payara.

the class PayaraMicroImpl method getGAVURLs.

/**
 * Converts the GAVs provided to a URLs, and stores them in the
 * deploymentURLsMap.
 */
private void getGAVURLs() throws GlassFishException {
    GAVConvertor gavConvertor = new GAVConvertor();
    for (String gav : GAVs) {
        try {
            Map.Entry<String, URL> artefactMapEntry = gavConvertor.getArtefactMapEntry(gav, repositoryURLs);
            if (deploymentURLsMap == null) {
                deploymentURLsMap = new LinkedHashMap<>();
            }
            String contextRoot = artefactMapEntry.getKey();
            if ("ROOT".equals(contextRoot)) {
                contextRoot = "/";
            }
            deploymentURLsMap.put(contextRoot, artefactMapEntry.getValue());
        } catch (MalformedURLException ex) {
            throw new GlassFishException(ex.getMessage());
        }
    }
}
Also used : GlassFishException(org.glassfish.embeddable.GlassFishException) GAVConvertor(fish.payara.deployment.util.GAVConvertor) MalformedURLException(java.net.MalformedURLException) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) URL(java.net.URL)

Example 2 with GAVConvertor

use of fish.payara.deployment.util.GAVConvertor in project Payara by payara.

the class DeployRemoteArchiveCommand method execute.

@Override
public void execute(AdminCommandContext context) {
    CommandRunner commandRunner = serviceLocator.getService(CommandRunner.class);
    ActionReport actionReport = context.getActionReport();
    // Initialise to null so we can do a null check later
    File fileToDeploy = null;
    // Assume only Http or Https connections are direct URLs
    if (path.startsWith("http://") || path.startsWith("https://")) {
        try {
            // Download the file to temp, and return a File object to pass to the deploy command
            fileToDeploy = convertUriToFile(new URI(path));
        } catch (IOException | URISyntaxException ex) {
            logger.log(Level.SEVERE, ex.getMessage());
            actionReport.setMessage("Exception converting URI to File: " + path);
            actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
        }
        // If a name hasn't been provided, get it from the URI
        if (name == null) {
            if (path.endsWith(".jar")) {
                name = path.substring(path.lastIndexOf("/") + 1, path.indexOf(".jar"));
            } else if (path.endsWith(".war")) {
                name = path.substring(path.lastIndexOf("/") + 1, path.indexOf(".war"));
            } else if (path.endsWith(".ear")) {
                name = path.substring(path.lastIndexOf("/") + 1, path.indexOf(".ear"));
            }
        }
        // If a context root hasn't been provided, get it from the URI
        if (contextroot == null) {
            if (path.endsWith(".jar")) {
                contextroot = "/" + path.substring(path.lastIndexOf("/") + 1, path.indexOf(".jar"));
            } else if (path.endsWith(".war")) {
                contextroot = "/" + path.substring(path.lastIndexOf("/") + 1, path.indexOf(".war"));
            } else if (path.endsWith(".ear")) {
                contextroot = "/" + path.substring(path.lastIndexOf("/") + 1, path.indexOf(".ear"));
            }
        }
    } else {
        try {
            // If the path String doesn't start with Http or Https, then assume it's a GAV coordinate
            logger.log(Level.FINE, "Path does not appear to be a URL, will attempt to read as GAV coordinate");
            // Convert the Array to a List of Urls, and append "/" to the Urls if they don't already end with one
            List<URL> repositoryUrls = formatRepositoryUrls(additionalRepositories);
            // Get the URL for the given GAV coordinate
            GAVConvertor gavConvertor = new GAVConvertor();
            Entry<String, URL> artefactEntry = gavConvertor.getArtefactMapEntry(path, repositoryUrls);
            // Download the file to temp, and return a File object to pass to the deploy command
            fileToDeploy = convertUriToFile(artefactEntry.getValue().toURI());
            // If a name hasn't been provided, get it from the artefact name
            if (name == null) {
                name = artefactEntry.getKey();
            }
            // If a context root hasn't been provided, get it from the artefact name
            if (contextroot == null) {
                contextroot = "/" + artefactEntry.getKey();
            }
        } catch (MalformedURLException ex) {
            logger.log(Level.SEVERE, ex.getMessage());
            actionReport.setMessage("Exception converting GAV to URL: " + path);
            actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
        } catch (IOException | URISyntaxException ex) {
            logger.log(Level.SEVERE, ex.getMessage());
            actionReport.setMessage("Exception converting URI to File: " + path);
            actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
        }
    }
    // Only continue if we actually have a file to deploy
    if (fileToDeploy != null) {
        ActionReport subReport = actionReport.addSubActionsReport();
        CommandRunner.CommandInvocation commandInvocation = commandRunner.getCommandInvocation("deploy", subReport, context.getSubject());
        ParameterMap parameters = createAndPopulateParameterMap(fileToDeploy);
        commandInvocation.parameters(parameters);
        commandInvocation.execute();
    } else {
        actionReport.setMessage("Provided path does not appear to be a valid URL or GAV coordinate: " + path + "\nSee the server log for more details");
        actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
    }
}
Also used : GAVConvertor(fish.payara.deployment.util.GAVConvertor) MalformedURLException(java.net.MalformedURLException) ParameterMap(org.glassfish.api.admin.ParameterMap) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) ActionReport(org.glassfish.api.ActionReport) URI(java.net.URI) URL(java.net.URL) CommandRunner(org.glassfish.api.admin.CommandRunner) File(java.io.File)

Aggregations

GAVConvertor (fish.payara.deployment.util.GAVConvertor)2 MalformedURLException (java.net.MalformedURLException)2 URL (java.net.URL)2 File (java.io.File)1 IOException (java.io.IOException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 ActionReport (org.glassfish.api.ActionReport)1 CommandRunner (org.glassfish.api.admin.CommandRunner)1 ParameterMap (org.glassfish.api.admin.ParameterMap)1 GlassFishException (org.glassfish.embeddable.GlassFishException)1