Beispiel #1
0
        static public void Execute()
        {
            Console.WriteLine("AuthProjectPackages - start");

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

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

            //
            //  3. Create a temporary project (R session).
            //
            //  Optionally:
            //  ProjectCreationOptions options = new ProjectCreationOptions();
            //
            //  Populate options as needed, then:
            //
            //  rProject = rUser.createProject(options);
            //
            RProject rProject = rUser.createProject();

            Console.WriteLine("AuthProjectPackages: created temporary R session, rProject=" + rProject);

            //
            // 4. Retrieve a list of R packages that are current
            // attached on the R session.
            //
            List <RProjectPackage> pkgs = rProject.listPackages(false);

            foreach (RProjectPackage pkg in pkgs)
            {
                Console.WriteLine("AuthProjectPackages: R session, " +
                                  "found attached R package name=" +
                                  pkg.about().name + ", repo=" +
                                  pkg.about().repo + ", version=" +
                                  pkg.about().version);
            }

            //
            //  5. Cleanup
            //
            rProject.close();
            Utility.Cleanup(rUser, rClient);

            Console.WriteLine("AuthProjectPackages - end");
        }
Beispiel #2
0
        static public void Execute()
        {
            Console.WriteLine("AuthProjectCreate - start");

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

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

            //
            //  3. Create a temporary project (R session).
            //
            //  Optionally:
            //  ProjectCreationOptions options = new ProjectCreationOptions();
            //
            //  Populate options as needed, then:
            //
            //  rProject = rUser.createProject(options);
            //
            RProject rProject = rUser.createProject();

            Console.WriteLine("AuthProjectCreate: created temporary R session, rProject=" + rProject);

            //
            //  4. Cleanup
            //
            rProject.close();
            Utility.Cleanup(rUser, rClient);

            Console.WriteLine("AuthProjectCreate - end");
        }
        static public 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)
                {
                    String sMsg = rJob.query().status.Value;

                    if (sMsg == RJob.Status.COMPLETED.Value |
                        sMsg == RJob.Status.FAILED.Value |
                        sMsg == RJob.Status.CANCELLED.Value |
                        sMsg == RJob.Status.ABORTED.Value)
                    {
                        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");
        }
        static public void Execute()
        {
            Console.WriteLine("AuthProjectExecuteCode - start");

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

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

            //
            //  3. Create a temporary project (R session).
            //
            //  Optionally:
            //  ProjectCreationOptions options = new ProjectCreationOptions();
            //
            //  Populate options as needed, then:
            //
            //  rProject = rUser.createProject(options);
            //
            RProject rProject = rUser.createProject();

            Console.WriteLine("AuthProjectExecuteCode: created temporary R session, rProject=" + rProject);


            // 4. Execute an analytics Web service based on an arbitrary
            // block of R code.
            //
            // Optionally:
            // ProjectExecutionOptions options = new ProjectExecutionOptions();
            //
            // Populate options as needed, then:
            //
            // exec = rProject.executeCode(rCode, options);
            //
            String rCode = "demo(graphics)";

            exec = rProject.executeCode(rCode);

            Console.WriteLine("AuthProjectExecuteCode: R code execution completed, exec=" + exec);

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

            //
            //  6. Cleanup
            //
            rProject.close();
            Utility.Cleanup(rUser, rClient);

            Console.WriteLine("AuthProjectExecuteCode - end");
        }
        static public 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)
                {
                    String sMsg = rJob.query().status.Value;

                    if (sMsg == RJob.Status.COMPLETED.Value |
                        sMsg == RJob.Status.FAILED.Value |
                        sMsg == RJob.Status.CANCELLED.Value |
                        sMsg == RJob.Status.ABORTED.Value)
                    {
                        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");
        }
        static public void Execute()
        {
            Console.WriteLine("AuthProjectExecuteScript - start");

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

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

            //
            //  3. Create a temporary project (R session).
            //
            //  Optionally:
            //  ProjectCreationOptions options = new ProjectCreationOptions();
            //
            //  Populate options as needed, then:
            //
            //  rProject = rUser.createProject(options);
            //
            RProject rProject = rUser.createProject();

            Console.WriteLine("AuthProjectExecuteScript: created temporary R session, rProject=" + rProject);

            //
            // 4. Execute an analytics Web service based on a repository-managed
            // R script: /testuser/root/Histogram of Auto Sales.R.
            //
            // Optionally:
            // ProjectExecutionOptions options = new ProjectExecutionOptions();
            //
            // Populate options as needed, then:
            //
            // exec = rProject.executeScript(filename, directory, author, version, options);
            //
            exec = rProject.executeScript("Histogram of Auto Sales",
                                          "root",
                                          "testuser",
                                          "",
                                          null);

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

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

            //
            //  6. Cleanup
            //
            rProject.close();
            Utility.Cleanup(rUser, rClient);

            Console.WriteLine("AuthProjectExecuteScript - end");
        }
Beispiel #7
0
        static public void Execute()
        {
            Console.WriteLine("AuthProjectWorkspace - start");

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

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

            //
            //  3. Create a temporary project (R session).
            //
            //  Optionally:
            //  ProjectCreationOptions options = new ProjectCreationOptions();
            //
            //  Populate options as needed, then:
            //
            //  rProject = rUser.createProject(options);
            //
            RProject rProject = rUser.createProject();

            Console.WriteLine("AuthProjectWorkspace: created temporary " +
                              "R session, rProject=" + rProject);

            //
            // 4. Execute a block of R code to create an object
            // in the R session's workspace.
            //
            String rCode = "x <- T";

            exec = rProject.executeCode(rCode);

            //
            // 5. Retrieve the object "x" from the R session's workspace.
            //
            RData encodedX = rProject.getObject("x");

            if (encodedX is RBoolean)
            {
                Console.WriteLine("retrieved object x from workspace, x=" + (Boolean)encodedX.Value);
            }

            //
            // 6. Create R object data in the R sesssion's workspace
            // by pushing DeployR-encoded data from the client application.
            //
            // - Prepare sample R object vector data.
            // - Use RDataFactory to encode the sample R object vector data.
            // - Push encoded R object into the workspace.
            //
            List <Double?> vectorValues = new List <Double?>();

            vectorValues.Add(10.0);
            vectorValues.Add(11.1);
            vectorValues.Add(12.2);
            vectorValues.Add(13.3);
            vectorValues.Add(14.4);

            RData encodedY = RDataFactory.createNumericVector("y", vectorValues);

            rProject.pushObject(encodedY);

            //
            // 7. Retrieve the DeployR-encoding of the R object
            // from the R session's workspace.
            //
            encodedY = rProject.getObject("y");

            if (encodedY is RNumericVector)
            {
                List <Double?> numVectorValues = (List <Double?>)encodedY.Value;
                StringBuilder  str             = new StringBuilder();
                foreach (Double?val in numVectorValues)
                {
                    str.Append(val + " ");
                }
                Console.WriteLine("retrieved object y from workspace, encodedY=" + str.ToString());
            }

            //
            // 8. Retrieve a list of R objects in the R session's workspace.
            //
            // Optionally:
            // ProjectWorkspaceOptions options = new ProjectWorkspaceOptions();
            //
            // Populate options as needed, then:
            //
            // objs = rProject.listObjects(options);
            //
            ///
            objs = rProject.listObjects();

            //
            // 9. Cleanup
            //
            rProject.close();
            Utility.Cleanup(rUser, rClient);

            Console.WriteLine("AuthProjectWorkspace - end");
        }
        /// <summary>
        /// Implementation of RBroker Interface 'shutdown' method
        /// </summary>
        /// <remarks></remarks>
        public void shutdown()
        {
            Interlocked.Exchange(ref m_taskBrokerIsActive, 0);

            if (m_resourceTokenPool.Count > 0)
            {
                Boolean releaseGridResources = false;

                if (m_brokerConfig is PooledBrokerConfig)
                {
                    PooledBrokerConfig pbcfg = (PooledBrokerConfig)m_brokerConfig;
                    releaseGridResources = pbcfg.poolCreationOptions.releaseGridResources;
                }

                if (releaseGridResources)
                {
                    /*
                     * If PooledTaskBroker resource tokens
                     * and rUser available, perform a server-wide
                     * flush of projects on the grid.
                     */
                    m_rUser.releaseProjects();
                }
                else
                {
                    /*
                     * If PooledTaskBroker resource tokens
                     * and rUser not available, perform
                     * project-by-project flush on the grid.
                     */

                    foreach (Object resourceToken in m_resourceTokenPool)
                    {
                        try
                        {
                            if (resourceToken is RProject)
                            {
                                RProject projectToken = (RProject)resourceToken;
                                projectToken.close();
                            }
                        }
                        catch (Exception cex)
                        {
                            throw new Exception("RBroker: project close failed, cause: " + cex.ToString());
                        }
                    }
                }
            }

            if (m_rClient != null)
            {
                try
                {
                    if (m_rUser != null)
                    {
                        m_rClient.logout(m_rUser);
                    }
                }
                catch (Exception rex)
                {
                    throw new Exception("RBroker: RClient logout failed, cause: " + rex.ToString());
                }
            }
        }