Search in sources :

Example 11 with CLIException

use of org.ow2.proactive_grid_cloud_portal.cli.CLIException in project scheduling by ow2-proactive.

the class PackageDownloader method transformGithubURLToSvnURL.

/**
 * This method transforms a github url to an svn-compatible url in order to allow svn operations on github repositories.
 * @param githubUrl
 * @return
 */
private String transformGithubURLToSvnURL(String githubUrl) {
    String svnUrl;
    // convert a github repository archive Url to a github repositor Url
    githubUrl = githubUrl.replaceAll("/archive/[^\\s/]+\\.zip$", "");
    Pattern pattern = Pattern.compile(REGX_GITHUB_REPO_CONTENT);
    Matcher matcher = pattern.matcher(githubUrl);
    if (githubUrl.matches(REGX_GITHUB_REPO_CONTENT) && matcher.find()) {
        if (matcher.group(4) != null && matcher.group(4).matches("(tree/[^\\s/]+)")) {
            svnUrl = githubUrl.replace(matcher.group(4), "trunk/");
        } else {
            svnUrl = matcher.group(1).concat("/trunk");
        }
        // remove wwww. from svn URL otherwise it doesn't work
        if (matcher.group(2) != null) {
            svnUrl = svnUrl.replace(matcher.group(2), "");
        }
        return svnUrl;
    } else {
        logger.warn(githubUrl + " is not a valid github URL.");
        throw new CLIException(REASON_INVALID_ARGUMENTS, String.format("'%s' is not a valid github URL.", githubUrl));
    }
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) CLIException(org.ow2.proactive_grid_cloud_portal.cli.CLIException)

Example 12 with CLIException

use of org.ow2.proactive_grid_cloud_portal.cli.CLIException in project scheduling by ow2-proactive.

the class PackageDownloader method downloadPackage.

/**
 * This method downloads a package from a remote location. <br>
 *     It supports the following types of urls:
 *     <ul>
 *         <li>Direct-download zip urls</li>
 *         <li>Exposed web directories (supports only tomcat directory listings for the moment)</li>
 *         <li>Entire Github repositories given by their http links or downloadable archive format</li>
 *         <li>Sub-directories within a github repository</li>
 *         <li>Supports forwarded URLS as in shortened bitly urls, etc </li>
 *     </ul>
 * @param packageUrl
 * @return
 * @throws IOException
 * @throws URISyntaxException
 */
public String downloadPackage(String packageUrl) {
    // Get the real URL in case it is a shortened one (via bit.ly, etc)
    URL url;
    try {
        url = getRealURLIfForwarded(new URL(createNormalizeURL(packageUrl)));
        checkReachableURL(url);
        if (isGithubURL(url.toString())) {
            return downloadPackageFromGithub(url.toString());
        } else {
            return downloadPackageFromWeb(url);
        }
    } catch (IOException e) {
        logger.warn(packageUrl + " is not a reachable package URL.");
        throw new CLIException(REASON_INVALID_ARGUMENTS, String.format("'%s' is not a reachable package URL.", packageUrl));
    } catch (URISyntaxException e) {
        logger.warn(packageUrl + " is not a reachable package URL.");
        throw new CLIException(REASON_INVALID_ARGUMENTS, String.format("'%s' is not a valid valid package URL.", packageUrl));
    } catch (SVNException e) {
        // This exception can only be raised if transformGithubURLtoSvnURL doesn't work properly anymore.
        // In that case, the method needs to be revised.
        // If a non-existing github url (repo or else) is given, an IOException
        logger.warn(packageUrl + " cannot be downloaded from github.com");
        throw new CLIException(REASON_INVALID_ARGUMENTS, String.format("'%s' cannot be downloaded from github.com", packageUrl));
    }
}
Also used : CLIException(org.ow2.proactive_grid_cloud_portal.cli.CLIException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) SVNException(org.tmatesoft.svn.core.SVNException) URL(java.net.URL) SVNURL(org.tmatesoft.svn.core.SVNURL)

Example 13 with CLIException

use of org.ow2.proactive_grid_cloud_portal.cli.CLIException in project scheduling by ow2-proactive.

the class PauseCommand method execute.

@Override
public void execute(ApplicationContext currentContext) throws CLIException {
    SchedulerRestInterface scheduler = currentContext.getRestClient().getScheduler();
    try {
        boolean success = scheduler.pauseScheduler(currentContext.getSessionId());
        resultStack(currentContext).push(success);
        if (success) {
            writeLine(currentContext, "Scheduler successfully paused.");
        } else {
            writeLine(currentContext, "Cannot pause scheduler.");
        }
    } catch (Exception e) {
        handleError("An error occurred while attempting to pause scheduler:", e, currentContext);
    }
}
Also used : SchedulerRestInterface(org.ow2.proactive_grid_cloud_portal.common.SchedulerRestInterface) CLIException(org.ow2.proactive_grid_cloud_portal.cli.CLIException)

Example 14 with CLIException

use of org.ow2.proactive_grid_cloud_portal.cli.CLIException in project scheduling by ow2-proactive.

the class RestartInErrorTaskCommand method execute.

@Override
public void execute(ApplicationContext currentContext) throws CLIException {
    SchedulerRestInterface scheduler = currentContext.getRestClient().getScheduler();
    try {
        boolean result = scheduler.restartInErrorTask(currentContext.getSessionId(), jobId, taskId);
        handleResult(currentContext, result);
    } catch (Exception e) {
        handleError(String.format("An error occurred while attempting to restart %s:", task()), e, currentContext);
    }
}
Also used : SchedulerRestInterface(org.ow2.proactive_grid_cloud_portal.common.SchedulerRestInterface) CLIException(org.ow2.proactive_grid_cloud_portal.cli.CLIException)

Example 15 with CLIException

use of org.ow2.proactive_grid_cloud_portal.cli.CLIException in project scheduling by ow2-proactive.

the class RestartRunningTaskCommand method execute.

@Override
public void execute(ApplicationContext currentContext) throws CLIException {
    SchedulerRestInterface scheduler = currentContext.getRestClient().getScheduler();
    try {
        boolean result = scheduler.restartTask(currentContext.getSessionId(), jobId, taskId);
        handleResult(currentContext, result);
    } catch (Exception e) {
        handleError(String.format("An error occurred while attempting to restart %s:", task()), e, currentContext);
    }
}
Also used : SchedulerRestInterface(org.ow2.proactive_grid_cloud_portal.common.SchedulerRestInterface) CLIException(org.ow2.proactive_grid_cloud_portal.cli.CLIException)

Aggregations

CLIException (org.ow2.proactive_grid_cloud_portal.cli.CLIException)49 SchedulerRestInterface (org.ow2.proactive_grid_cloud_portal.common.SchedulerRestInterface)30 HttpResponseWrapper (org.ow2.proactive_grid_cloud_portal.cli.utils.HttpResponseWrapper)22 QueryStringBuilder (org.ow2.proactive_grid_cloud_portal.cli.utils.QueryStringBuilder)12 HttpGet (org.apache.http.client.methods.HttpGet)10 HttpPost (org.apache.http.client.methods.HttpPost)9 IOException (java.io.IOException)8 File (java.io.File)6 List (java.util.List)5 Throwables.getStackTraceAsString (com.google.common.base.Throwables.getStackTraceAsString)4 NSStateView (org.ow2.proactive_grid_cloud_portal.cli.json.NSStateView)4 PluginView (org.ow2.proactive_grid_cloud_portal.cli.json.PluginView)4 ArrayList (java.util.ArrayList)3 RmStateView (org.ow2.proactive_grid_cloud_portal.cli.json.RmStateView)3 FileInputStream (java.io.FileInputStream)2 Stack (java.util.Stack)2 HttpPut (org.apache.http.client.methods.HttpPut)2 ConfigurableFieldView (org.ow2.proactive_grid_cloud_portal.cli.json.ConfigurableFieldView)2 TaskResultData (org.ow2.proactive_grid_cloud_portal.scheduler.dto.TaskResultData)2 NotConnectedRestException (org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException)2