Tuesday, June 16, 2015

SharePoint 2010 Sandbox Solution 2 – Architecture and Execution Model

In my previous post, SharePoint 2010 Sandbox Solution 1 – Overview of Sandboxed Solution, I gave an overview of Sandboxed solutions. Now I’d like to peek into the architecture and execution model.

Architecture

Sandbox solution is often called user solution. The primary API for sandbox solution is Microsoft.SharePoint.UsserCode and the service that takes care of it is SharePoint 2010 User Code Host.
The first question that normally arises is where the assemblies are deployed – The assembly is packaged in a wsp file and the wsp is uploaded in the solution gallery. When, for the first time, the assembly is required (e.g. a page is accessed which contains a webpart of the sandboxed solution) then the assembly is extracted from the gallery and copied to the file system (C:\ProgramData\Microsoft\SharePoint\UCCache) of the server that is handling the request. This may not be web front end server as it is handled by User Code Host Service.
Who copies the assembly to the file system as SPUCWorkerProcess.exe can’t write to file system? The answer is SharePoint 2010 User Code Host service.
Once the user session, which accessed the assembly, ends, the assembly stays in the cache for a short time. If the same assembly is required by some other session it can be accessed from the cache, if present. Otherwise, it needs to be extracted from the solution again. Below is the detailed execution process:


This chronicles the process of using a custom Web Part and solution in a particular site.
  1. The SPSite admin uploads a new solution package (*.wsp) into the Solution Gallery of the SPSite.
  2. The SPSite admin “activates” the solution. This activates the features within the solution. Web Part files are copied into the Web Part gallery.
    1. As part of the activation, solution is validated using the validation framework. A custom validator can be added, for example, to check that only solutions signed with a certain key  can be activated. Customers and partners can develop their own validators based on their needs.
  3. Some time later, a user decides to add a Web Part to their homepage. They go into Web Part edit mode and click “Add a Web Part.” They notice the additional Web part options and click Add.
  4. SharePoint now checks to see if the custom webpart.dll file, which backs this Web Part, is installed into the assembly cache. It is not.
  5. The assembly is faulted into the assembly cache; it is extracted and copied from the solution file to a temporary folder in the disk and loaded to the memory (the disk is cleaned immediately). Now the Web Part is about to be used.
  6. It is loaded into Sandbox Code service host.
  7. Processes deliver the Web Part to be executed to the service.

Execution Model

We’ll see the same execution from the perspective of the execution model.



  1. A request comes in for a page with a Web Part from a partial trust assembly. This is delegated to a Web Part proxy. The Web Part proxy then in turn calls the worker process manager, and tells it to execute the Web Part.
  2. The worker process manager queries the configuration database to figure out which machine and process it should send the request to.
  3. The worker process then sends the request to the user code manager on that machine.
  4. The user code manager needs to ensure that the assembly backing the Web Part is locally deployed. To do this, it reaches back into the Web Part solution package, extracts the assembly, and places it into the assembly cache.
  5. Now, the SPUserCodeManager (SPUserCodeHostService.exe) delegates the request to execute the code to SPUswerCodeWorkerProcess.exe. The full trust Web Part wrapper works with the instantiated process to simulate the Web Part lifecycle.
  6. The Web Part itself calls into the SharePoint OM to retrieve some set of data.
  7. The resulting HTML and viewstate changes are bubbled back to the hosting process, which has been synchronously waiting for this infrastructure to complete.
  8. The resulting page is sent back to the user.
  9. Rendered results are sent back to the requester.


SharePoint 2010 Sandbox Solution 1 – Overview of Sandboxed Solution



SharePoint aims at reducing the involvement of IT team in the solution lifecycle. Deployment and monitoring of custom solutions is one area where Farm administrators (IT team) are still putting a significant amount of effort. This effort can be reduced (I would use the word REDUCED effort instead of no effort because of the concept of Solution Validation) if the business needs can be fulfilled by Sandboxed solution.
In this series of blogs, I’ll be covering following topics:
  1. Overview of Sanboxed Solution
  2. Architecture and Execution Model of Sandboxed Solution
  3. Sandbox Proxy
  4. Solution Validation

Overview of Sandboxed Solution

If I try to define sandboxed solution technically then the easiest way is — It runs under context of SPUCWorkerProcess (instead of w3wp) which has limited access to the resources.
Before you decide on Sandboxed solution for your application, you need to be aware of the following:
  1. It has access to only a subset of SharePoint object model. So limited operations can be performed
  2. It has no access to file system. So you cannot create Visual Web Parts or read/ write web.config file or log exceptions into log files
  3. No support to external web services
  4. No Email support using SPUtility.SendMail
  5. Impersonation is not allowed. So you cannot use SPSecurity.RunWithElevatedPrivileges
  6. Scope of the solution is limited. You can access only site collection level resources in which it is deployed
  7. Performance is another concern. If sand box worker process runs for more than 30 seconds then the UserCodeHosting service terminates the process
Oh my god! There are so many restrictions.
Don’t worry there are ways to perform full trust operation even after these restriction. I’ll show it in further blogs (3. Sandbox Proxy).
Now we are aware of, on a high level, what we can’t do. Let’s see what we can do. We can create:
  1. Web Parts (normal, not visual web part)
  2. Lists
  3. List Templates
  4. Custom Actions
  5. Event Receivers
  6. Content Types
  7. Site Columns
  8. Workflows
  9. Event Receivers
  10. And many more…
Now we’ll look at the lifecycle of a Sandboxed solution at a very high
  1. Deployment – The Site Collection Administrator (SCA) gets a solution as swp file and uploads it into Solution Gallery. Once it is uploaded she needs to activate it. On activation the solution is validated against validation logic (either OOB or custom). IIS reset/Web App pool recycling required. Great huh?
  2. Activation - If the validation is passed then the solution is activated which activates all the features contained in the solution. The SCA doesn’t need to activate the features separately (but cross checking is always good :P). If we assume that a feature contains a web part then on activation the web part would be populated into web part gallery.
  3. Deactivation – On deactivation the solution, the web part no longer executes but still be present in the web part gallery.
  4. Deletion – The solution is deleted. The web part, obviously, doesn’t executes but still it remains in the web part gallery.
By now you would be aware of WHAT IS SANDBOXED SOLUTION, WHAT WE CAN AND CAN’T and LIFE CYCLE OF SANNDBOXED SOLUTION. Here I am concluding this episode of Sandboxed solutions and will take up Architecture and Execution model next

How to Configure Enterprise Search in SharePoint 2013 – Part 2



In the previous post we learned about creating managed accounts required for Search, creating search service application and configuring search service application. In this post we will complete our enterprise search configuration. I will discuss about
Creating Content Source – In this we will see what is Continuous crawling
Creating Search center.
Then finally I will discuss about new Improvements in Search
Let’s begin then,
Create Content Source:
In the last post we have created search service application. Now it’s time to create content source to get the desired content displayed to the user.


Go to Search Central Administration and click on Content Sources under Crawling section.
From the Figure: Content Sources, you can observe that by default it will create Local SharePoint sites content source, but in actual scenarios we have to create individual content source for each web application. So, let’s create a content source.
To create it, click on “New Content Source” from the Figure: Content Sources.
Enter the details as shown in the below figures
-          Name: sharepointchampions.com
-          Select the type of content to be crawled: SharePoint sites
-          Type Start address below: http://sharepointchampions.com/

Leave the remaining setting as default as it shown in below Figure

Crawl schedules: Leave Enable Continuous Crawl. Create Incremental Crawl and Full Crawl based on your requirement. Please see below Figures for Full Crawl schedule and Incremental Crawl schedules
Figure: Full Crawl schedule-Once in a week i.e. on Saturday at 12:00 AM
Figure: Incremental Crawl schedule -For every 5 hours
After configuring both schedules click Ok. New content source “SharePoint-Journey” will be added to a list of content sources. For first time if you add a content source, by default Full crawl get initiate automatically.

Enable Continuous Crawls:

One new feature that is added in Search in SharePoint 2013 is continuous crawl. In the previous versions of SharePoint whenever users upload the content they have to wait till the next incremental crawl to complete, to see the contents in search; but now it’s no more an issue. Once the content is uploaded into SharePoint, details will get displayed as early as possible with this setting.
If you observe the below Figure: Enable Continuous Crawl, while creating the content source the incremental crawl will get disabled. This means that you don’t require the incremental crawl because it has been set to “Enable Continuous Crawl”.
But to enable it you should have robust Infrastructure in place so that performance will not get affected.

One more thing to note here is if you set continuous crawl, while creating the content source for the first time it will show the crawl status as continuous crawl by default.
Please see the below Figure.

Now we have created content source and have seen what the purpose of Continuous crawl is.
The next step is creating the search center where users will search the content that is required for them.
Create search center:
Basic search center:
To create the basic search center go to create site collections from the central administration screen under Application management
While creating the site collection select “Basic Search Center” from the Enterprise. Click Ok. It will create a Basic search center.

Enterprise search center:

To Create Enterprise Search Center use the same approach as a basic search center but we have to select ”Enterprise Search Center” site template.
Figure: Enterprise Search Center
New improvements in search results page:
You have everything ready for search let’s start searching. Open the Enterprise Search center site collection. You can observe there are many new Improvements in Search results page. Please find below the details:
You have different options to search like (See below Figure):
-          Everything
-          People
-          Conversations
-          Videos
-          Reports
Below image is from basic search site, these options will be available in enterprise search as well. You can observe that under Result Type: 1 you can refine search based on document types like PDF, web page, word etc.
Next one is based on Author: who created the document.
Third one is based on Modified date: where you can change the search results based on modified date. It can be changed using slider.
The options for slider are one year ago, one month ago, and one week ago.
Once you select the document from the search results small popup opens where you can see
-          Document name
-          Document type
-          Last modified
-          Contributor
There are three more options: To Open, Send via email and View library to see the details of the library where the document or item is stored.
No more PDF Ifilters:
You don’t need to install the PDF Ifilter and make a lot of settings to search PDF documents in SharePoint 2013.
It is handled by SharePoint now, see above Figure, where I have uploaded a PDF document and it displayed for users without doing any configuration or settings.
We have created the Search service application, created the accounts required to create it and we have seen how search administration page looks and what the new changes in Search topology are. Then we created the Content source, while creating it we have seen new option called “Enable Continuous crawl”, then we created the Search center and what are the new changes in search results page.
Hope this post is useful to start the basic search configuration for your farm environment.
In coming posts we will see more about search changes in SharePoint 2013.
Enjoy the searching features provided in SharePoint 2013.

How to Configure Enterprise Search in SharePoint 2013 - Part -1



In this series I will discuss about how to configure enterprise Search in SharePoint 2013 to provide excellent new search features available in the latest version of SharePoint in your SharePoint portal.
There are many improvements related to enterprise search in SharePoint 2013. We will see those soon in coming posts.
You have to perform below steps to configure SharePoint Search in SharePoint 2013
1. Creating managed accounts required for Search
2. Create search service application.
3. Configure Search service application.
4. Create Content Source – In this we will see what is Continuous crawling.
5. Create Search center.
6. New Improvements in Search.
In this post I will discuss about first three in the above list.
As usual we will start our steps from the central administration screen.
Create managed accounts:
Before creating and configuring the required search service application, we have to create the accounts which we use for enterprise search. Here I have an account in AD called SP_search. Now I will add this account as managed account.
To do that go to central administration page and click on security.

Click on Configure Managed accounts under general security. It will open below Figure: Registered Managed Account.  Enter the Username, Password. If you want to set the automatic password change click on the check box against the “Enable automatic password change” otherwise leave as it is and click ok. The account will get added to the list of managed accounts -

Create search service application:

Click on “Manage Service Applications” under Application Management from central administration.
Click on search service application from new service application list
Scroll down a little bit from the “Create New Search Service Application” popup screen, then Select create a new application pool and enter the application pool name as “SP-Search Admin Web Service” and select the account as “Venkatasuresh.n”.
Scroll down a little bit more from the popup screen, then Select the create a new application pool and enter the application pool name as “SP-Search Query and Site Settings Web” and select the
security account as “Venkatasuresh.n”.


You have entered all the required values to create the search service application, hit the OK button.
It will show the below dialog box “Please wait while your changes are processed for search service application”.

It will then show the below screen as the final status of completion of creating the search service application. Please see the below Figure.

To verify it you can go and check under the “Manage Service Applications” section you will have newly created “Search Service Application”.

Configure search service application:

Click on Search Service Application from the above figure to see the administration page details of search.
It will display the below figures.
By selecting various parameters under system status of search administration you can configure search.
You can observe that the “default Content access account” here is “SPSearch”.  Please see the below screen.

Second half of the search administration and main one is Search Application Topology. Please see the below screen there are four databases created by creation of Search service application.
  • Administration database
  • Analytics Reporting Database
  • Crawl Database
  • Link Database
In SharePoint 2013, Analytics services are also included in the search.  As I said before, there are lots of changes in Search in SharePoint 2013; we will cover each one of them.

I will close on this for now. In the next post I will discuss about Creating Content Source, Create Search center, New Improvements in Search.