public static AnonymousProjectExecutionOptions translate(DiscreteTaskOptions taskOptions)
        {
            AnonymousProjectExecutionOptions options = null;

            if (taskOptions != null)
            {
                options = new AnonymousProjectExecutionOptions();

                /*
                 * DiscreteTaskOptions 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);
        }
Ejemplo n.º 2
0
        static public void Execute()
        {
            Console.WriteLine("AnonProjectExecuteScript - start");

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

            //
            // 2. Execute a public analytics Web service as an anonymous
            // user based on a repository-managed R script:
            // /testuser/root/DeployR - Hello World.R
            //
            // Create the AnonymousProjectExecutionOptions object
            // to specify inputs and output to the script
            // The R object that is an input to the script is 'input_randomNum'
            // The R object that we want to retrieve after script execution is 'x'
            //

            AnonymousProjectExecutionOptions options = new AnonymousProjectExecutionOptions();

            options.rinputs.Add(RDataFactory.createNumeric("input_randomNum", 100));
            options.routputs.Add("x");

            exec = rClient.executeScript("DeployR - Hello World",
                                         "root",
                                         "testuser",
                                         "",
                                         options);

            Console.WriteLine("AnonProjectExecuteScript: public repository-managed " +
                              "script execution completed, exec=" + exec);

            //
            // 3. Retrieve script execution results.
            //
            console = exec.about().console;
            plots   = exec.about().results;
            files   = exec.about().artifacts;
            objects = exec.about().workspaceObjects;

            RNumericVector xVec = (RNumericVector)objects[0];

            Console.WriteLine("AnonProjectExecuteScript - end");
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Run the acutal discrete task using Client API
        /// </summary>
        /// <returns>Results of the discrete task</returns>
        /// <remarks></remarks>
        public RTaskResult call()
        {
            RTaskResult taskResult = null;

            long timeOnCall = 0L;

            //long timeOnServer = 0L;

            try
            {
                AnonymousProjectExecutionOptions options = ROptionsTranslator.translate(m_task.options);

                long startTime = Environment.TickCount;

                RScriptExecution execResult = m_rClient.executeScript(m_task.filename,
                                                                      m_task.directory,
                                                                      m_task.author,
                                                                      m_task.version,
                                                                      options);

                timeOnCall = Environment.TickCount - startTime;

                String generatedConsole = execResult.about().console;

                List <String> generatedPlots = new List <String>();
                if (execResult.about().results != null)
                {
                    foreach (RProjectResult result in execResult.about().results)
                    {
                        generatedPlots.Add(result.about().url);
                    }
                }

                List <String> generatedFiles = new List <String>();
                if (execResult.about().artifacts != null)
                {
                    foreach (RProjectFile artifact in execResult.about().artifacts)
                    {
                        generatedFiles.Add(artifact.about().url);
                    }
                }

                List <RData> generatedObjects = execResult.about().workspaceObjects;

                List <String> storedFiles = new List <String>();
                if (execResult.about().repositoryFiles != null)
                {
                    foreach (RRepositoryFile repoFile in execResult.about().repositoryFiles)
                    {
                        storedFiles.Add(repoFile.about().url);
                    }
                }

                taskResult = new RTaskResultImpl(execResult.about().id,
                                                 RTaskType.DISCRETE,
                                                 true,
                                                 execResult.about().timeCode,
                                                 execResult.about().timeTotal,
                                                 timeOnCall, null,
                                                 false,
                                                 generatedConsole,
                                                 generatedPlots,
                                                 generatedFiles,
                                                 generatedObjects,
                                                 storedFiles);
            }
            catch (Exception ex)
            {
                //if(ex.getCause() == typeof(InterruptedException))
                //{

                /*
                 * RTaskToken.cancel() can raise an InterruptedException.
                 * When an InterruptedException is detected the DiscreteTask
                 * executing on the server should be aborted at this point.
                 * However, there is no way to obtain DeployR reference, such
                 * as a projectId, for an stateless execution in-progress, so
                 * aborting the current RTask operation is not possible.
                 */
                //}

                taskResult = new RTaskResultImpl(null,
                                                 RTaskType.DISCRETE,
                                                 false,
                                                 0L,
                                                 0L,
                                                 0L, ex);
            }
            finally
            {
                /*
                 * Callback to PooledTaskBroker to release
                 * RProject back into pool for other tasks.
                 */
                m_rBroker.callback(m_task, taskResult);
            }


            return(taskResult);
        }