Esempio n. 1
0
        /// <summary>
        /// Submit a job based on block of R code
        /// </summary>
        /// <param name="name">Name of the job to schedule</param>
        /// <param name="descr">Description of the job</param>
        /// <param name="code">R code associated with the job</param>
        /// <param name="options">options associated with job</param>
        /// <returns>RJob object</returns>
        /// <remarks></remarks>
        public RJob submitJobCode(String name, String descr, String code, JobExecutionOptions options)
        {
            String uri = Constants.RJOBSUBMIT;

            if (!(options == null))
            {
                if (!(options.schedulingOptions == null))
                {
                    uri = Constants.RJOBSCHEDULE;
                }
            }
            RJob returnValue = RUserJobImpl.callJob(name, descr, code, "", "", "", "", null, options, m_client, uri);

            return(returnValue);
        }
        public static RJob callJob(String name, String descr, String code, String scriptName, String scriptDirectory, String scriptAuthor, String scriptVersion, String ExternalSource, JobExecutionOptions options, RClient client, String uri)
        {
            StringBuilder data = new StringBuilder();

            //create the input String
            data.Append(Constants.FORMAT_JSON);
            data.Append("&name=" + HttpUtility.UrlEncode(name));
            data.Append("&descr=" + HttpUtility.UrlEncode(descr));
            data.Append("&code=" + HttpUtility.UrlEncode(code));

            if (ExternalSource == null)
            {
                data.Append("&rscriptname=" + HttpUtility.UrlEncode(scriptName));
                data.Append("&rscriptdirectory=" + HttpUtility.UrlEncode(scriptDirectory));
                data.Append("&rscriptauthor=" + HttpUtility.UrlEncode(scriptAuthor));
                data.Append("&rscriptversion=" + HttpUtility.UrlEncode(scriptVersion));
            }
            else
            {
                data.Append("&externalsource=" + HttpUtility.UrlEncode(ExternalSource));
            }

            if (!(options == null))
            {

                data.Append("&csvinputs=" + HttpUtility.UrlEncode(options.csvrinputs));

                if (!(options.rinputs == null))
                {
                    if (options.rinputs.Count > 0)
                    {
                        data.Append("&inputs=");
                        String sJSON = JSONSerialize.createJSONfromRData(options.rinputs);
                        data.Append(HttpUtility.UrlEncode(sJSON));
                        if (HTTPUtilities.DEBUGMODE == true)
                        {
                            Console.Write(sJSON);
                        }
                    }
                }

                if (!(options.preloadDirectory == null))
                {
                    data.Append("&preloadfilename=" + HttpUtility.UrlEncode(options.preloadDirectory.filename));
                    data.Append("&preloadfiledirectory=" + HttpUtility.UrlEncode(options.preloadDirectory.directory));
                    data.Append("&preloadfileauthor=" + HttpUtility.UrlEncode(options.preloadDirectory.author));
                    data.Append("&preloadfileversion=" + HttpUtility.UrlEncode(options.preloadDirectory.version));
                }

                if (!(options.preloadWorkspace == null))
                {
                    data.Append("&preloadobjectname=" + HttpUtility.UrlEncode(options.preloadWorkspace.filename));
                    data.Append("&preloadobjectdirectory=" + HttpUtility.UrlEncode(options.preloadWorkspace.directory));
                    data.Append("&preloadobjectauthor=" + HttpUtility.UrlEncode(options.preloadWorkspace.author));
                    data.Append("&preloadobjectversion=" + HttpUtility.UrlEncode(options.preloadWorkspace.version));
                }

                if (!(options.adoptionOptions == null))
                {
                    data.Append("&adoptworkspace=" + HttpUtility.UrlEncode(options.adoptionOptions.adoptWorkspace));
                    data.Append("&adoptdirectory=" + HttpUtility.UrlEncode(options.adoptionOptions.adoptDirectory));
                    data.Append("&adoptpackages=" + HttpUtility.UrlEncode(options.adoptionOptions.adoptPackages));
                }

                if (!(options.storageOptions == null))
                {
                    data.Append("&storefile=" + HttpUtility.UrlEncode(options.storageOptions.files));
                    data.Append("&storedirectory=" + HttpUtility.UrlEncode(options.storageOptions.directory));
                    data.Append("&storeobject=" + HttpUtility.UrlEncode(options.storageOptions.objects));
                    data.Append("&storeworkspace=" + HttpUtility.UrlEncode(options.storageOptions.workspace));
                    data.Append("&storenewversion=" + options.storageOptions.newVersion.ToString());
                    data.Append("&storepublic=" + options.storageOptions.published.ToString());
                }

                if (!(options.routputs == null))
                {
                    if (options.routputs.Count > 0)
                    {
                        data.Append("&robjects=");
                        foreach (var s in options.routputs)
                        {
                            data.Append(HttpUtility.UrlEncode(s) + ",");
                        }
                        data.Remove(data.Length - 1, 1);
                    }
                }

                data.Append("&echooff=" + options.echooff.ToString());
                data.Append("&consoleoff=" + options.consoleoff.ToString());
                data.Append("&tag=" + HttpUtility.UrlEncode(options.tag));
                data.Append("&graphics=" + HttpUtility.UrlEncode(options.graphicsDevice));
                data.Append("&graphicswidth=" + options.graphicsWidth.ToString());
                data.Append("&graphicsheight=" + options.graphicsHeight.ToString());
                data.Append("&nan=" + HttpUtility.UrlEncode(options.nan));
                data.Append("&infinity=" + HttpUtility.UrlEncode(options.infinity));
                data.Append("&encodeDataFramePrimitiveAsVector=" + options.encodeDataFramePrimitiveAsVector.ToString());
                data.Append("&enableConsoleEvents=" + options.enableConsoleEvents.ToString());
                data.Append("&preloadbydirectory=" + HttpUtility.UrlEncode(options.preloadByDirectory));

                if (!(options.schedulingOptions == null))
                {
                    data.Append("&schedstart=" + options.schedulingOptions.startTime.ToString());
                    data.Append("&schedrepeat=" + options.schedulingOptions.repeatCount.ToString());
                    data.Append("&schedinterval=" + options.schedulingOptions.repeatInterval.ToString());
                }

                data.Append("&storenoproject=" + options.noProject.ToString());
                data.Append("&priority=" + HttpUtility.UrlEncode(options.priority));
                data.Append("&cluster=" + HttpUtility.UrlEncode(options.gridCluster));
            }

            //call the server
            JSONResponse jresponse = HTTPUtilities.callRESTPost(uri, data.ToString(), ref client);
            RJob returnValue = new RJob(jresponse, client);

            return returnValue;
        }
        public static JobExecutionOptions translate(BackgroundTaskOptions taskOptions, Boolean isPriorityTask)
        {
            JobExecutionOptions options = null;

            if (taskOptions != null)
            {

                options = new JobExecutionOptions();

                /*
                 * BackgroundTaskOptions to JobExecutionOptions.
                 */

                if (isPriorityTask)
                    options.priority = "HIGH_PRIORITY";

                options.noProject = taskOptions.noProject;

                if (taskOptions.repeatCount > 0)
                {
                    options.schedulingOptions = new JobSchedulingOptions();
                    options.schedulingOptions.repeatCount = taskOptions.repeatCount;
                    options.schedulingOptions.repeatInterval = taskOptions.repeatInterval;
                    options.schedulingOptions.startTime = taskOptions.startTime;
                }

                /*
                 * BackgroundTaskOptions to ProjectExecutionOptions.
                 */

                options.rinputs = taskOptions.rinputs;
                options.csvrinputs = taskOptions.csvrinputs;

                if (taskOptions.preloadWorkspace != null)
                {

                    options.preloadWorkspace = new ProjectPreloadOptions();
                    options.preloadWorkspace.filename = taskOptions.preloadWorkspace.filename;
                    options.preloadWorkspace.directory =  taskOptions.preloadWorkspace.directory;
                    options.preloadWorkspace.author = taskOptions.preloadWorkspace.author;
                    options.preloadWorkspace.version = taskOptions.preloadWorkspace.version;
                }

                if (taskOptions.preloadDirectory != null)
                {

                    options.preloadDirectory = new ProjectPreloadOptions();
                    options.preloadDirectory.filename = taskOptions.preloadDirectory.filename;
                    options.preloadDirectory.directory = taskOptions.preloadDirectory.directory;
                    options.preloadDirectory.author = taskOptions.preloadDirectory.author;
                    options.preloadDirectory.version = taskOptions.preloadDirectory.version;
                }

                options.preloadByDirectory = taskOptions.preloadByDirectory;

                options.graphicsDevice = taskOptions.graphicsDevice;
                options.graphicsWidth = taskOptions.graphicsWidth;
                options.graphicsHeight = taskOptions.graphicsHeight;
                options.echooff = taskOptions.echooff;
                options.consoleoff = taskOptions.consoleoff;
                options.routputs = taskOptions.routputs;
                options.encodeDataFramePrimitiveAsVector = taskOptions.encodeDataFramePrimitiveAsVector;
                options.nan = taskOptions.nan;
                options.infinity = taskOptions.infinity;

                if (taskOptions.storageOptions != null)
                {

                    options.storageOptions = new ProjectStorageOptions();
                    options.storageOptions.directory = taskOptions.storageOptions.directory;
                    options.storageOptions.files = taskOptions.storageOptions.files;
                    options.storageOptions.newVersion = taskOptions.storageOptions.newVersion;
                    options.storageOptions.objects = taskOptions.storageOptions.objects;
                    options.storageOptions.published = taskOptions.storageOptions.published;
                    options.storageOptions.workspace = taskOptions.storageOptions.workspace;
                }

            }

            return options;
        }
Esempio n. 4
0
        /// <summary>
        /// Submit a single repository-managed script or a chain of repository-managed scripts
        /// to execute as a job.
        ///
        /// To submit a chain of repository-managed scripts on this call provide a comma-separated
        /// list of values on the scriptName, scriptAuthor and optionally scriptVersion parameters.
        /// Chained execution executes each of the scripts identified on the call in a sequential
        /// fashion on the R session, with execution occuring in the order specified on the parameter list.
        ///
        /// </summary>
        /// <param name="name">Name of the job to schedule</param>
        /// <param name="descr">Description of the job</param>
        /// <param name="scriptName">name of valid R Script</param>
        /// <param name="scriptDirectory">directory containing R Script.</param>
        /// <param name="scriptAuthor">author of the R Script</param>
        /// <param name="scriptVersion">version of the R Script to execute</param>
        /// <param name="options">options associated with job</param>
        /// <returns>RJob object</returns>
        /// <remarks></remarks>
        public RJob submitJobScript(String name, String descr, String scriptName, String scriptDirectory, String scriptAuthor, String scriptVersion, JobExecutionOptions options)
        {
            String uri = Constants.RJOBSUBMIT;

            if (!(options == null))
            {
                if (!(options.schedulingOptions == null))
                {
                    uri = Constants.RJOBSCHEDULE;
                }
            }
            RJob returnValue = RUserJobImpl.callJob(name, descr, "", scriptName, scriptDirectory, scriptAuthor, scriptVersion, null, options, m_client, uri);

            return(returnValue);
        }
        public static void Execute()
        {
            Console.WriteLine("AuthJobStoreResultToRepository - start");

            //
            // 1. Connect to the DeployR Server
            //
            RClient rClient = Utility.Connect();

            //
            // 2. Authenticate the user
            //
            RUser rUser = Utility.Authenticate(rClient);

            //
            // 3. Submit a background job to execute a block of R code
            // that will generate a vector object. We will then use
            // JobExecutionOtpions to request the following behavior:
            //
            // a. Execute the job at low (default) priority.
            // b. Skip the persistence of results to a project.
            // c. Request the persistence of a named vector object
            // as a binary R object file to the repository.
            //

            String rCode = "tutorialVector <- rnorm(100)";

            JobExecutionOptions options = new JobExecutionOptions();
            options.priority = JobExecutionOptions.LOW_PRIORITY;
            options.noProject = true;

            //
            // 4. Use ProjectStorageOptions to identify the name of one
            // or more workspace objects for storage to the repository.
            //
            // In this case, the named object matches the name of the
            // object created the rCode being executed on the job. We
            // request that the binary R object file be stored into
            // the root directory in the repository.
            //
            options.storageOptions = new ProjectStorageOptions();
            options.storageOptions.objects = "tutorialVector";
            options.storageOptions.directory = "root";

            RJob rJob = rUser.submitJobCode("Background Code Execution",
                                            "Demonstrate storing job results to repository.",
                                            rCode,
                                            options);

            Console.WriteLine("AuthJobStoreResultToRepository: submitted background job " +
                                        "for execution, rJob=" + rJob);

            //
            // 5. Query the execution status of a background job and loop until the job has finished
            //
            if (rJob != null)
            {
                while (true)
                {
                    RJob.Status status = rJob.query().status;

                    if (status == RJob.Status.COMPLETED |
                        status == RJob.Status.FAILED |
                        status == RJob.Status.CANCELLED |
                        status == RJob.Status.ABORTED)
                    {
                        break;
                    }
                    else
                    {
                        Thread.Sleep(500);
                    }
                }
            }

            //
            // 6. Retrieve the RepositoryFile from completed job
            //
            RRepositoryFile rRepositoryFile = null;
            if (rJob != null)
            {
                //
                // 7. Retrieve the results of the background job
                // execution. Given the custom JobExecutionOptions
                // specified for this job (noproject=true) there will
                // be no RProject to hold the results.
                //
                // However, the custom JobExecutionOptions specified
                // for this job requested the storage of the
                // "tutorialVector" vector object as a binary R
                // object file (.rData) in the repository.
                //
                // The following code demonstrates how we can
                // retrieve that result from the repository:
                //
                String sUserName = rUser.about().Username;
                rRepositoryFile = rUser.fetchFile("tutorialVector.rData",
                                                    sUserName,
                                                    "root",
                                                    "");

                Console.WriteLine("AuthJobStoreResultToRepository: retrieved background " +
                        "job result from repository, rRepositoryFile=" + rRepositoryFile);
            }

            //
            //  8. Cleanup
            //
            if (rRepositoryFile != null)
            {
                //rRepositoryFile.delete();  //un-comment if you wish to delete the RepositoryFile
            }

            if (rJob != null)
            {
                //rJob.delete();  //un-comment if you wish to delete the job
            }

            Utility.Cleanup(rUser, rClient);

            Console.WriteLine("AuthJobStoreResultToRepository - end");
        }
Esempio n. 6
0
        static public RJob callJob(String name, String descr, String code, String scriptName, String scriptDirectory, String scriptAuthor, String scriptVersion, String ExternalSource, JobExecutionOptions options, RClient client, String uri)
        {
            StringBuilder data = new StringBuilder();

            //create the input String
            data.Append(Constants.FORMAT_JSON);
            data.Append("&name=" + HttpUtility.UrlEncode(name));
            data.Append("&descr=" + HttpUtility.UrlEncode(descr));
            data.Append("&code=" + HttpUtility.UrlEncode(code));

            if (ExternalSource == null)
            {
                data.Append("&rscriptname=" + HttpUtility.UrlEncode(scriptName));
                data.Append("&rscriptdirectory=" + HttpUtility.UrlEncode(scriptDirectory));
                data.Append("&rscriptauthor=" + HttpUtility.UrlEncode(scriptAuthor));
                data.Append("&rscriptversion=" + HttpUtility.UrlEncode(scriptVersion));
            }
            else
            {
                data.Append("&externalsource=" + HttpUtility.UrlEncode(ExternalSource));
            }

            if (!(options == null))
            {
                data.Append("&csvinputs=" + HttpUtility.UrlEncode(options.csvrinputs));

                if (!(options.rinputs == null))
                {
                    if (options.rinputs.Count > 0)
                    {
                        data.Append("&inputs=");
                        String sJSON = JSONSerialize.createJSONfromRData(options.rinputs);
                        data.Append(HttpUtility.UrlEncode(sJSON));
                        if (HTTPUtilities.DEBUGMODE == true)
                        {
                            Console.Write(sJSON);
                        }
                    }
                }

                if (!(options.preloadDirectory == null))
                {
                    data.Append("&preloadfilename=" + HttpUtility.UrlEncode(options.preloadDirectory.filename));
                    data.Append("&preloadfiledirectory=" + HttpUtility.UrlEncode(options.preloadDirectory.directory));
                    data.Append("&preloadfileauthor=" + HttpUtility.UrlEncode(options.preloadDirectory.author));
                    data.Append("&preloadfileversion=" + HttpUtility.UrlEncode(options.preloadDirectory.version));
                }

                if (!(options.preloadWorkspace == null))
                {
                    data.Append("&preloadobjectname=" + HttpUtility.UrlEncode(options.preloadWorkspace.filename));
                    data.Append("&preloadobjectdirectory=" + HttpUtility.UrlEncode(options.preloadWorkspace.directory));
                    data.Append("&preloadobjectauthor=" + HttpUtility.UrlEncode(options.preloadWorkspace.author));
                    data.Append("&preloadobjectversion=" + HttpUtility.UrlEncode(options.preloadWorkspace.version));
                }

                if (!(options.adoptionOptions == null))
                {
                    data.Append("&adoptworkspace=" + HttpUtility.UrlEncode(options.adoptionOptions.adoptWorkspace));
                    data.Append("&adoptdirectory=" + HttpUtility.UrlEncode(options.adoptionOptions.adoptDirectory));
                    data.Append("&adoptpackages=" + HttpUtility.UrlEncode(options.adoptionOptions.adoptPackages));
                }

                if (!(options.storageOptions == null))
                {
                    data.Append("&storefile=" + HttpUtility.UrlEncode(options.storageOptions.files));
                    data.Append("&storedirectory=" + HttpUtility.UrlEncode(options.storageOptions.directory));
                    data.Append("&storeobject=" + HttpUtility.UrlEncode(options.storageOptions.objects));
                    data.Append("&storeworkspace=" + HttpUtility.UrlEncode(options.storageOptions.workspace));
                    data.Append("&storenewversion=" + options.storageOptions.newVersion.ToString());
                    data.Append("&storepublic=" + options.storageOptions.published.ToString());
                }

                if (!(options.routputs == null))
                {
                    if (options.routputs.Count > 0)
                    {
                        data.Append("&robjects=");
                        foreach (var s in options.routputs)
                        {
                            data.Append(HttpUtility.UrlEncode(s) + ",");
                        }
                        data.Remove(data.Length - 1, 1);
                    }
                }

                data.Append("&echooff=" + options.echooff.ToString());
                data.Append("&consoleoff=" + options.consoleoff.ToString());
                data.Append("&tag=" + HttpUtility.UrlEncode(options.tag));
                data.Append("&graphics=" + HttpUtility.UrlEncode(options.graphicsDevice));
                data.Append("&graphicswidth=" + options.graphicsWidth.ToString());
                data.Append("&graphicsheight=" + options.graphicsHeight.ToString());
                data.Append("&nan=" + HttpUtility.UrlEncode(options.nan));
                data.Append("&infinity=" + HttpUtility.UrlEncode(options.infinity));
                data.Append("&encodeDataFramePrimitiveAsVector=" + options.encodeDataFramePrimitiveAsVector.ToString());
                data.Append("&enableConsoleEvents=" + options.enableConsoleEvents.ToString());
                data.Append("&preloadbydirectory=" + HttpUtility.UrlEncode(options.preloadByDirectory));

                if (!(options.schedulingOptions == null))
                {
                    data.Append("&schedstart=" + options.schedulingOptions.startTime.ToString());
                    data.Append("&schedrepeat=" + options.schedulingOptions.repeatCount.ToString());
                    data.Append("&schedinterval=" + options.schedulingOptions.repeatInterval.ToString());
                }

                data.Append("&storenoproject=" + options.noProject.ToString());
                data.Append("&priority=" + HttpUtility.UrlEncode(options.priority));
                data.Append("&cluster=" + HttpUtility.UrlEncode(options.gridCluster));
            }

            //call the server
            JSONResponse jresponse   = HTTPUtilities.callRESTPost(uri, data.ToString(), ref client);
            RJob         returnValue = new RJob(jresponse, client);

            return(returnValue);
        }
        public static void Execute()
        {
            Console.WriteLine("AuthJobExecuteScript - start");

            //
            // 1. Connect to the DeployR Server
            //
            RClient rClient = Utility.Connect();

            //
            // 2. Authenticate the user
            //
            RUser rUser = Utility.Authenticate(rClient);

            //
            // 3. Submit a background job for execution based on a
            // repository-managed R script: /testuser/root/Histogram of Auto Sales.R
            //
            JobExecutionOptions options = new JobExecutionOptions();
            options.priority = JobExecutionOptions.HIGH_PRIORITY;  //Make this a High Priority job
            RJob rJob = rUser.submitJobScript("Background Script Execution",
                                                "Background script execution.",
                                                "Histogram of Auto Sales",
                                                "root",
                                                "testuser",
                                                "",
                                                options);

            Console.WriteLine("AuthJobExecuteScript: submitted background job " +
                                        "for execution, rJob=" + rJob);

            //
            // 4. Query the execution status of a background job and loop until the job has finished
            //
            if (rJob != null)
            {
                while (true)
                {
                    RJob.Status status = rJob.query().status;

                    if (status == RJob.Status.COMPLETED |
                        status == RJob.Status.FAILED |
                        status == RJob.Status.CANCELLED |
                        status == RJob.Status.ABORTED)
                    {
                        break;
                    }
                    else
                    {
                        Thread.Sleep(500);
                    }
                }
            }

            //
            // 5. Retrieve the project from completed job
            //
            RProject rProject = null;
            if (rJob != null)
            {
                // make sure we have a valid project id
                if (rJob.query().project.Length > 0)
                {
                    //get the project using the project id
                    rProject = rUser.getProject(rJob.query().project);

                    Console.WriteLine("AuthJobExecuteScript: retrieved background " +
                           "job result on project, rProject=" + rProject);
                }
            }

            //
            //  6. Cleanup
            //
            if (rProject != null)
            {
                rProject.close();
                //rProject.delete();  //un-comment if you wish to delete the project
            }

            if (rJob != null)
            {
                //rJob.delete();  //un-comment if you wish to delete the job
            }

            Utility.Cleanup(rUser, rClient);

            Console.WriteLine("AuthJobExecuteScript - end");
        }
        public static void Execute()
        {
            Console.WriteLine("AuthJobExecuteCode - start");

            //
            // 1. Connect to the DeployR Server
            //
            RClient rClient = Utility.Connect();

            //
            // 2. Authenticate the user
            //
            RUser rUser = Utility.Authenticate(rClient);

            //
            // 3. Submit a background job for execution based on an
            // arbitrary block of R code: [codeBlock]
            //
            String codeBlock = "demo(graphics)";

            JobExecutionOptions options = new JobExecutionOptions();
            options.priority = JobExecutionOptions.MEDIUM_PRIORITY;   //Make this a Medium Priority job

            RJob rJob = rUser.submitJobCode("Sample Job",
                                        "Sample description.",
                                        codeBlock,
                                        options);

            Console.WriteLine("AuthJobExecuteCode: submitted background job for execution, rJob=" + rJob);

            //
            // 4. Query the execution status of a background job and loop until the job has finished
            //
            if (rJob != null)
            {
                while (true)
                {
                    RJob.Status status = rJob.query().status;

                    if (status == RJob.Status.COMPLETED |
                        status == RJob.Status.FAILED |
                        status == RJob.Status.CANCELLED |
                        status == RJob.Status.ABORTED)
                    {
                        break;
                    }
                    else
                    {
                        Thread.Sleep(500);
                    }
                }
            }

            //
            // 5. Retrieve the project from completed job
            //
            RProject rProject = null;
            if (rJob != null)
            {
                // make sure we have a valid project id
                if (rJob.query().project.Length > 0)
                {
                    //get the project using the project id
                    rProject = rUser.getProject(rJob.query().project);

                    Console.WriteLine("AuthJobExecuteCode: retrieved background " +
                            "job result on project, rProject=" + rProject);
                }
            }

            //
            //  6. Cleanup
            //
            if (rProject != null)
            {
                rProject.close();
                //rProject.delete();  //un-comment if you wish to delete the project
            }

            if (rJob != null)
            {
                //rJob.delete();  //un-comment if you wish to delete the job
            }

            Utility.Cleanup(rUser, rClient);

            Console.WriteLine("AuthJobExecuteCode - end");
        }