Friday, 5 April 2019

SharePoint 2013: Implement Deferred And Promise Object In JavaScript Asynchronous Execute

SharePoint 2013: Implement Deferred And Promise Object In JavaScript Asynchronous Execute

Introduction

SharePoint 2013 Client Object Model is used to retrieve, update and manage the data in SharePoint 2013 library/List. SharePoint makes an Object model available in several forms but here, we are using Javascript Object Model.

  • JavaScript library(JSOM)
  • REST/OData endpoints

In this Javascript Object Model, we will use executeQueryAsync() but it will execute/ will not wait for success/ fail to complete. We need to make executeQueryAsync() behave synchronously.
It means the function will wait for async operations, which should be completed and should return some values.

We know that SharePoint JavaScript Client Object Model is asynchronous. However, sometimes we want to process the things in a synchronous way.
This can be done by using JavaScript callbacks and deferred/Promises. Let's first see an asynchronous example, which we will later convert to synchronous:
For this reason, JavaScript is having an option to use deferred/promise method do this operation.

Promise

The promises pattern significantly simplifies JavaScript code when you make an app, which must have multiple, nested asynchronous calls and it makes it very powerful.

Example

Your JavaScript code has to update multiple list items one by one to complete the basic operations and wait for the first one to execute.
However, Promise object also acts like a caching mechanism, where the success or failure function will be called immediately, if the Promise has already been fulfilled.
Promises object can make it easy to execute dependent asynchronous calls sequentially, which are based on the results.

Syntax

The deferred/ Promise object is very simple syntax and powerful method for sequentially updating in the list/ list items.
Initially, we need to declare the deferred object, as shown below.

  1. var deferred = $.Deferred();  
At the end of the function, we have to return Promise object
  1. return deferred.promise();   
First, we will see about normal JavaScript execution.


Output

For the method given above, we will get the output given below.
Execute second after retrieving the list items.
execute first
NewListitem
Here, we are expecting success function, which should execute first. Unfortunately, the previous one executed. Sometimes it will cause a major issue when you are updating the list items.
Thus, we need to use Async operation to perform synchronously.
Let's see the deferred/ Promise function, as shown below. 

Output
   

For the code given above, we will get the output, as shown below.
execute first
NewListitem
Execute second after retrieving the list items
How to Create a Document Set in SharePoint  2013 using REST API

How to Create a Document Set in SharePoint 2013 using REST API

You can perform basic create, read, update, and delete (CRUD) operations by using the Representational State Transfer (REST) interface provided by SharePoint. The REST interface exposes all the SharePoint entities and operations that are available in the other SharePoint client APIs. One advantage of using REST is that you don't have to add references to any SharePoint libraries or client assemblies. Instead, you make HTTP requests to the appropriate endpoints to retrieve or update SharePoint entities, such as webs, lists, and list items



Create Document Set named DemoSet in Documents library:
$(function() 
    {
    createDocumentSet(_spPageContextInfo.webAbsoluteUrl,'Documents','DemoSet',
      function(folder){
        console.log('Document Set ' + folder.Name + ' has been created succesfully'); 
      },
      function(error){
        console.log(JSON.stringify(error));
      }
    );
    
    });
    function createDocumentSet(webUrl,listName,folderName, success, error)
    {
       createFolder(webUrl,listName,folderName,'0x0120D520', success, error);
    }
    
    function getListUrl(webUrl,listName,success, error) 
    {
        var headers = {};
        $.ajax({       
           url: webUrl + "/_api/lists/getbytitle('" + listName + "')/rootFolder?$select=ServerRelativeUrl",   
           type: "GET",   
           contentType: "application/json;odata=verbose",
           headers: { 
              "Accept": "application/json;odata=verbose"
           },   
           success: function(data){
               success(data.d.ServerRelativeUrl);
           },
           error: error
        });
    }
    
    function createFolder(webUrl,listName,folderName,folderContentTypeId, success, error) 
    {  
        getListUrl(webUrl,listName,
          function(listUrl) {
              var folderPayload = {
                 'Title' : folderName,
                 'Path' : listUrl
              };
    
              //Create Folder resource
              $.ajax({
                    url: webUrl + "/_vti_bin/listdata.svc/" + listName,
                    type: "POST",
                    contentType: "application/json;odata=verbose",
                    data: JSON.stringify(folderPayload),
                    headers: {
                       "Accept": "application/json;odata=verbose",
                       "Slug": listUrl + "/" + folderName + "|" + folderContentTypeId
                    },
                    success: function (data) {
                        success(data.d);
                    },
                    error: error
              });
          },
          error);
    }
    
    
   


Tuesday, 2 April 2019

Top 50 AWS Interview Questions and Answers

Top 50 AWS Interview Questions and Answers

What is AWS?

AWS (Amazon Web Services) is a platform to provide secure cloud services, database storage, offerings to compute power, content delivery, and other services to help business level and develop.

What are the key components of AWS ?
   The fundamental elements of AWS are
  • Route 53: A DNS web service
  • Easy E-mail Service: It permits addressing e-mail utilizing RESTFUL API request or through normal SMTP
  • Identity and Access Management: It gives heightened protection and identity control for your AWS account
  • Simple Storage Device or (S3): It is a warehouse equipment and the well-known widely utilized AWS service
  • Elastic Compute Cloud (EC2): It affords on-demand computing sources for hosting purposes. It is extremely valuable in trouble of variable workloads
  • Elastic Block Store (EBS): It presents persistent storage masses that connect to EC2 to enable you to endure data beyond the lifespan of a particular EC2
  • CloudWatch: To observe AWS sources, It permits managers to inspect and obtain key Additionally, one can produce a notification alert in the state of crisis.
State the difference between Amazon S3 and EC2?

S3
  • It is a cloud web service that is used to host the application
  • It is like a computer machine that can run either on the Linux or Windows and manage the applications like Python, PHP, Apache or any databases.
EC2
  • It is a data storage system, with unlimited capacitance.
  • It has the REST interface and uses secure authentication keys like HMAC-SHA1.
What does an AMI include ?
An AMI comprises the following elements
  • A template to the source quantity concerning the instance
  • Launch authorities determine which AWS accounts can avail the AMI to drive instances
  • A base design mapping that defines the amounts to join to the instance while it is originated.
How many buckets can you create in AWS by default ?

    In each of your AWS accounts, by default, You can produce up to 100 buckets.

Explain how the buffer is used in Amazon web services ?

 The buffer is utilized to deliver the system further robust to handle traffic or load by synchronizing different component. Usually, elements sustain and process the demands in an unreliable mode, With the aid of buffer, the elements will be equivalent and will operate at the similar speed to accommodate high-speed services. 


Explain Elastic Block Storage ? What type of performance can you expect ? How do you back it up? How do you improve performance ?

   That indicates it is RAID warehouse to begin with, so it’s irrelevant and faults tolerant. If disks expire in the RAID you don’t miss data. Excellent! It is more virtualized, therefore you can provision and designate warehouse, and connect it to your server with multiple API appeals. No calling the storage specialist and asking him or her to operate specific requests from the hardware vendor.

Execution on EBS can manifest variability. Such signifies that can run above the SLA enforcement level, suddenly descend under it. The SLA gives you among a medium disk I/O speed you can foresee. That can prevent any groups particularly performance specialists who suspect stable and compatible disk throughput on a server. 
Common physically entertained servers perform that direction.
Progress execution by practicing Linux software invasion and striping over four extents.

What is the importance of buffer in Amazon Web Services?

   An Elastic Load Balancer ensures that the incoming traffic is distributed optimally across various AWS instances.  A buffer will synchronize different components and makes the arrangement additional elastic to a burst of load or traffic. The components are prone to work in an unstable way of receiving and processing the requests. The buffer creates the equilibrium linking various apparatus and crafts them effort at the identical rate to supply more rapid services.

What is the way to secure data for carrying in the cloud?

    One thing must be ensured that no one should seize the information in the cloud while data is moving from point one to another and also there should not be any leakage with the security key from several storerooms in the cloud. Segregation of information from additional companies’ information and then encrypting it by means of approved methods is one of the options.



Name the several layers of Cloud Computing.

   Here is the list of layers of the cloud computing
PaaS – Platform as a Service
IaaS – Infrastructure as a Service
SaaS – Software as a Service
Distinguish between scalability and flexibility

   The aptitude of any scheme to enhance the tasks on hand on its present hardware resources to grip inconsistency in command is known as scalability. The capability of a scheme to augment the tasks on hand on its present and supplementary hardware property is recognized as flexibility, hence enabling the industry to convene command devoid of putting in the infrastructure at all.  AWS has several configuration management solutions for AWS scalability, flexibility, availability and management.

Name the various layers of the cloud architecture

  There are 5 layers and are listed below
CC- Cluster Controller
SC- Storage Controller
CLC- Cloud Controller
Walrus
NC- Node Controller

Define auto-scaling.

   Auto- scaling is one of the remarkable features of AWS where it permits you to arrange and robotically stipulation and spin up fresh examples without the requirement for your involvement. This can be achieved by setting brinks and metrics to watch. If those entrances are overcome, a fresh example of your selection will be configured, spun up and copied into the weight planner collection.

Which automation gears can help with spinup services?

   The API tools can be used for spinup services and also for the written scripts. Those scripts could be coded in Perl, bash or other languages of your preference. There is one more option that is patterned administration and stipulating tools such as a dummy or improved descendant. A tool called Scalr can also be used and finally we can go with a controlled explanation like a Rightscale.

How the processes start, stop and terminate works? How?

    Starting and stopping of an instance: If an instance gets stopped or ended, the instance functions a usual power cut and then change over to a clogged position. You can establish the case afterward since all the EBS volumes of Amazon remain attached. If an instance is in stopping state, then you will not get charged for additional instance.
Finishing the instance: If an instance gets terminated it tends to perform a typical blackout, so the EBS volumes which are attached will get removed except the volume’s deleteOnTermination characteristic is set to zero. In such cases, the instance will get removed and cannot set it up afterward.

What is the relation between an instance and AMI?

   AMI can be elaborated as Amazon Machine Image, basically, a template consisting software configuration part. For example an OS, applications, application server. If you start an instance, a duplicate of the AMI in a row as an unspoken attendant in the cloud.

What is DynamoDB?

   When You require a fast and flexible NoSQL database with a flexible datamodel and reliable performance then DynamoDB is the service from AWS.Amazon DynamoDB is a completely controlled NoSQL database aid that renders quick and anticipated execution with seamless scalability. You can perform Amazon DynamoDB to formulate a database table that can save and reclaim any quantity of data, and help any level of application transactions. 
Amazon DynamoDB automatically increases the data and transactions for the table above an adequate number of servers to supervise the inquiry function designated by the customer and the volume of data saved, while keeping constant and quick execution.

What is VPC?
pastedGraphic.png

VPC stands for Virtual Private Cloud. It allows you to customize your networking configuration. It is a network which is logically isolated from another network in the cloud. It allows you to have your IP address range,  internet gateways, subnet and security groups.

What are the different types of Load Balancer in AWS services?
Two types of Load balancer are:
  1. Application Load Balancer
  2. Classic Load Balancer
What are the important features of Amazon cloud search?
Important features of the Amazon cloud are:
  • Boolean searches
  • Prefix Searches
  • Range searches
  • Entire text search
  • AutoComplete advice
What are various layers of Cloud Architecture explained in AWS training?
Different layers of cloud architecture are:
  • Cloud controller
  • Cluster controller
  • Storage Controller
  • Node Controller
What are the storage class available in Amazon s3?
Storage classes available with Amazon s3 are:
  • Amazon S3 standard
  • Amazon S3 standard-infrequent Access
  • Amazon S3 Reduced Redundancy Storage
  • Amazon Glacier

Name some of the DB engines which can be used in AWS RDS
  1. MS-SQL DB
  2. MariaDB
  3. MYSQL DB
  4. OracleDB
  5. PostgreDB
List the features of Amazon cloud search?

The Amazon cloud search features:
  • Range searches
  • Prefix Searches
  • Boolean Searches
  • Entire text search with language specific text processing
  • Highlighting
  • AutoComplete advice
  • Faceting term boosting

What is AWS Data pipeline?

A network service that can be applied to automate the alteration and migration of the information is called the AWS Data Pipeline. Using AWS, the data-driven workflows can be specified so that the businesses can rely on the achievement of early tasks.

Explain Amazon Kinesis Firehose?

It is fully sophistically managed service to deliver the real-time live streaming data to destinations like Amazon Simple Storage Service i.e., Amazon S3 and Amazon Redshift.

What is Amazon EMR?

It is a survived cluster stage that interprets the working of data structures, before the intimation as Apache Hadoop and Apache Spark on the Amazon Web Services to investigate a large amount of data.We can prepare data for the analytics goals and marketing intellect workloads using Apache Huive and relevant open source designs.
Upon that, Amazon EMR can be used to migrate and convert the big masses of data into other AWS data repositories such as Amazon S3 and Amazon DynamoDB.
What Is The Way To Secure Data For Carrying In The Cloud?
  One thing must be ensured that no one should seize the information in the cloud while data is moving from point one to another and also there should not be any leakage with the security key from several storerooms in the cloud. Segregation of information from additional companies’ information and then encrypting it by means of approved methods is one of the options.

What Is Lambda@edge In Aws?

  • In AWS, we can use Lambda@Edge utility to solve the problem of low network latency for end users.
  • In Lambda@Edge there is no need to provision or manage servers. We can just upload our Node.js code to AWS Lambda and create functions that will be triggered on CloudFront requests.
  • When a request for content is received by CloudFront edge location, the Lambda code is ready to execute.
  • This is a very good option for scaling up the operations in CloudFront without managing servers.

What Are The Features Of The Amazon Ec2 Service?
    1. Virtual computing environment (known as instances)
    2. Pre-configured templates for your instances (known as Amazon Machine Images – AMIs)
    3. Amazon Machine Images (AMIs) is a complete package that you need for your server (including the operating system and additional software)
    4. Amazon EC2 provides various configurations of CPU, memory, storage and networking capacity for your instances (known as instance type)
    5. Secure login information for your instances using key pairs (AWS stores the public key and you can store the private key in a secure place)
    6. Storage volumes of temporary data is deleted when you stop or terminate your instance (known as instance store volumes)
    7. Amazon EC2 provides persistent storage volumes (using Amazon Elastic Block Store – EBS)
    8. A firewall that enables you to specify the protocols, ports, and source IP ranges that can reach your instances using security groups
    9. Static IP addresses for dynamic cloud computing (known as Elastic IP address)
    10. Amazon EC2 provides metadata (known as tags)
    11. Amazon EC2 provides virtual networks that are logically isolated from the rest of the AWS cloud, and that you can optionally connect to your own network (known as virtual private clouds – VPCs)


Monday, 1 April 2019

Error occurred in deployment step 'install app for SharePoint': SharePoint APP Installation Error

Error occurred in deployment step 'install app for SharePoint': SharePoint APP Installation Error

This blog will help you to understand SharePoint APP installation error and many of them faced this error commonly.
The full error message is
Error occurred in deployment step 'Install App for SharePoint': Failed to install App for SharePoint

Solution to Fix this issue:
Check if the App Management Service and Subscription Service are started. You can use the following PowerShell to start them in SharePoint CA Go to Central Administration -> Services on Server.

Check this service are running by using Powershell Commands,
Step 1:
 SPSubscriptionSettingsService 
 Get-SPServiceInstance | where{$_.GetType().Name -eq "AppManagementServiceInstance" -or $_.GetType().Name -eq "SPSubscriptionSettingsServiceInstance"} | Start-SPServiceInstance

Step2:
AppManagementServiceInstance 
Get-SPServiceInstance | where{$_.GetType().Name -eq "AppManagementServiceInstance" -or $_.GetType().Name -eq "SPSubscriptionSettingsServiceInstance"}

Step 3:
Specify a farm admin account, application pool, and database settings for the SPSubscriptionService and AppManagementServiceInstance services.
1. $account = Get-SPManagedAccount "SPFarm\Gowtham"
2. $AppPoolSubSvc = New-SPServiceApplicationPool -Name SettingsServiceAppPool -Account $account
3. $AppPoolAppSvc = New-SPServiceApplicationPool -Name AppServiceAppPool -Account $account
4. $AppSubSvc = New-SPSubscriptionSettingsServiceApplication –ApplicationPool $AppPoolSubSvc –Name SettingsServiceApp –DatabaseName SettingsServiceDB
5. $proxySubSvc = New-SPSubscriptionSettingsServiceApplicationProxy –ServiceApplication $AppSubSvc
6. $appAppSvc = New-SPAppManagementServiceApplication -ApplicationPool $appPoolAppSvc -Name AppServiceApp -DatabaseName AppServiceDB
7. $proxyAppSvc = New-SPAppManagementServiceApplicationProxy -ServiceApplication $appAppSvc
 

Still you faced this issue use the below steps to resolve this error.
Step 4: Optional:
Create a new web application under a new account from central administration and create New target site collection under the new web application.

For the site collection the primary administrator was the new account and the secondary administrator was the domain administrator account that I would be using in Visual Studio to deploy my app. I hope issue is fixed now.

Friday, 29 March 2019

Python Collections Data Types

Python Collections Data Types

There are four collection data types in the Python programming language:
  • Lists
  • Tuple
  • Set
  • Dictionary

List is a collection which is ordered and changeable. Allows duplicate members.Lists are very similar to arrays. They can contain any type of variable, and they can contain as many variables as you wish. 

Lists can also be iterated over in a very simple manner. Here is an example of how to build a list.Python knows a number of compound data types, used to group together other values. The most versatile is the list, which can be written as a list of comma-separated values (items) between square brackets.
Python lists are written with square brackets.

<code class="css">
Example:
//Comments

myist = ["car", "bike", "train"]
print(myist)
Output:
/Users/gowthamrajamanickam/PycharmProjects/PNPDemo/venv/bin/python /Users/gowthamrajamanickam/PycharmProjects/PNPDemo/PythonDemo.py
['car', 'bike', ‘train']


</code>
You access the list items by referring to the index number,

Example
myist = ["car", "bike", "train"]
print(myist[2])

Output

/Users/gowthamrajamanickam/PycharmProjects/PNPDemo/venv/bin/python /Users/gowthamrajamanickam/PycharmProjects/PNPDemo/PythonDemo.py
train


You can loop through the list items by using a for loop:
myist = ["car", "bike", "train"]
for x in myist:
  print(x)


Output

/Users/gowthamrajamanickam/PycharmProjects/PNPDemo/venv/bin/python /Users/gowthamrajamanickam/PycharmProjects/PNPDemo/PythonDemo.py
car
bike
train
To add an item to the end of the list, use the append() method:
Example


myist = ["car", "bike", "train"]
myist.append("Bus")
for x in myist:
  print(x)

Output
/Users/gowthamrajamanickam/PycharmProjects/PNPDemo/venv/bin/python /Users/gowthamrajamanickam/PycharmProjects/PNPDemo/PythonDemo.py
car
bike
train
Bus



Create Communication Sites  in SharePoint Online using PNP Core

Create Communication Sites in SharePoint Online using PNP Core

To install the latest PnP core, go to your Project References > Manage nuget packages.
Download the SharePointPnPCoreOnline component. Its version should be 2.20.1711 or higher (i.e Nov 2017 or higher).You also need to add the statement using OfficeDevPnP.Core.Sites; in your class.

To create a Modern team site, you can use the below code:


CommunicationSiteCollectionCreationInformation communicationSite = new CommunicationSiteCollectionCreationInformation
{
    Title = "Demo Communication Site",
    Url = "https://gowtham.sharepoint.com/sites/Demo",
    SiteDesign = CommunicationSiteDesign.Topic,
    Description = "Demo modern communication site description",
    Owner = "gowtham@tenant.onmicrosoft.com"
    AllowFileSharingForGuestUsers = true
   };

var createCommSite = await context.CreateSiteAsync(communicationSite);
Create Modern Sites  in SharePoint Online using PNP Core

Create Modern Sites in SharePoint Online using PNP Core

To install the latest PnP core, go to your Project References > Manage nuget packages.
Download the SharePointPnPCoreOnline component. Its version should be 2.20.1711 or higher (i.e Nov 2017 or higher).You also need to add the statement using OfficeDevPnP.Core.Sites; in your class.

To create a Modern team site, you can use the below code:

TeamSiteCollectionCreationInformation modernTeamSite = new TeamSiteCollectionCreationInformation
{
    Description = "Demo Site description",
    DisplayName = "Demo Modern Team Site",
    Alias = "modernTeamSite",
    IsPublic = true
                         
};

var createModernTeamSite = await context.CreateSiteAsync(modernTeamSite);
How to to resolve File Locked issue in SharePoint Online

How to to resolve File Locked issue in SharePoint Online

Error: The file "file" is locked for exclusive use by same User

Reason :
 “Windows SharePoint Services puts a write lock on the document on the server. The write lock times out after 10 minutes. Users cannot modify the document during the time when the document is locked”

Solution:

use these management shell commands to release lock.
$url = “http://gowthampnpdemo.com/demosite" 

$fileurl = “http:// gowthampnpdemo/pnpdemo/customlib/test.docx” 

$web = Get-SPWeb $url 

$item = $web.GetListItem($fileurl) 

$item.File.CheckOutStatus

$item.ReleaseLock
$web.Dispose()

How to Retrieve all the pages from  SharePoint Online sites and subsites using REST API

How to Retrieve all the pages from SharePoint Online sites and subsites using REST API


var oPagesCollection=[];//object having url for all pages under root site and sub site

getPage("") 





$.ajax({

url: _spPageContextInfo.siteAbsoluteUrl + "/_api/web/webinfos?$select=ServerRelativeUrl,Title",

method: "GET",

headers: {

    "Accept": "application/json; odata=verbose"

},

success: function(subsites) {

    $.each(subsites.d.results, function() {

        getSubSites(this.ServerRelativeUrl, this.Title);

        getPage(this.ServerRelativeUrl);

    });

    console.log(oPagesCollection);

},

error: function(subsites) {},

async: false

});



//function to get n level of subsites

function getSubSites(SubSiteUrl, SubSiteTitle) {

console.log(SubSiteUrl);

$.ajax({

    url: _spPageContextInfo.siteAbsoluteUrl + SubSiteUrl + "/_api/web/webinfos?$select=ServerRelativeUrl,Title",

    method: "GET",

    headers: {

        "Accept": "application/json; odata=verbose"

    },

    success: function(subsites) {



        $.each(subsites.d.results, function(index) {

            getSubSites(this.ServerRelativeUrl, this.Title);

            getPage(this.ServerRelativeUrl);

        });

    },

    error: function(subsites) {},

    async: false

});

}



function getPage(siteUrl){

$.ajax({

url: _spPageContextInfo.webAbsoluteUrl+ siteUrl + "/_api/web/lists/GetByTitle('Pages')/items?$select=FileRef",

method: "GET",

headers: {

    "Accept": "application/json; odata=verbose"

},

success: function(data) {

    $.each(data.d.results,function(index,val){

        oPagesCollection.push(val["FileRef"]);

    });

},

error: function(rootsite) {},

async: false

});

}