Tuesday, 28 June 2016

Cloud Computing-2

Services Categories: 

Cloud computing has always been divided into three broad service categories:
  • Infrastructure as a service (IaaS)
  • Platform as a service (PaaS)
  • Software as a service (SaaS)

Infrastructure as a service (IaaS):

Infrastructure as a service provides companies with computing resources including servers, networking, storage, and data center space on a pay-per-use basis.

The benefits of IaaS

  • No need to invest in your own hardware
  • Infrastructure scales on demand to support dynamic workloads
  • Flexible, innovative services available on demand

Platform as a service (PaaS):

Platform as a service provides a cloud-based environment with everything required to support the complete lifecycle of building and delivering web-based (cloud) applications—without the cost and complexity of buying and managing the underlying hardware, software, provisioning, and hosting.

The benefits of PaaS

  • Develop applications and get to market faster
  • Deploy new web applications to the cloud in minutes
  • Reduce complexity with middleware as a service
 

Software as a service (SaaS):

Cloud-based applications—or software as a service—run on distant computers “in the cloud” that are owned and operated by others and that connect to users’ computers via the Internet and, usually, a web browser.

The benefits of SaaS

  • You can sign up and rapidly start using innovative business apps
  • Apps and data are accessible from any connected computer
  • No data is lost if your computer breaks, as data is in the cloud
  • The service is able to dynamically scale to usage needs


Thursday, 23 June 2016

Cloud Computing-1

What is cloud computing?

  • Cloud computing is a general term for the delivery of hosted services over the Internet.
  • Cloud Computing is the use of hardware and software to deliver a service over a network (typically the Internet). With cloud computing, users can access files and use applications from any device that can access the Internet. An example of a Cloud Computing provider is Google's Gmail.


Benefits 

The main benefits of cloud computing include :
  • Self-service provisioning: End users can spin up computing resources for almost any type of workload on-demand.
  • Elasticity: Companies can scale up as computing needs increase and then scale down again as demands decrease.
  •  Pay per use: Computing resources are measured at a granular level, allowing users to pay only for the resources and workloads they use.
  • No maintenance: Companies don’t have to worry about the maintenance and upgrade. Company can focus on business logic and functionality.

 

 

Types of Cloud

Cloud computing services can be :
Private :-  Private cloud services are delivered from a business' data center to internal users.
Public :-  Public cloud model, a third-party provider delivers the cloud service over the Internet.
hybrid. :-  Hybrid cloud is a combination of public cloud services and on-premises private cloud – with orchestration and automation between the two.


 Private Cloud

A private cloud is infrastructure operated solely for a single organization, whether managed internally or by a third party, and hosted either internally or externally. Private clouds can take advantage of cloud’s efficiencies, while providing more control of resources and steering clear of multi-tenancy.

Key aspects of private cloud

  • A self-service interface controls services, allowing IT staff to quickly provision, allocate, and deliver on-demand IT resources
  • Highly automated management of resource pools for everything from compute capability to storage, analytics, and middleware
  • Sophisticated security and governance designed for a company’s specific requirements
  

 

Public Cloud

Public clouds are owned and operated by companies that offer rapid access over a public network to affordable computing resources. With public cloud services, users don’t need to purchase hardware, software, or supporting infrastructure, which is owned and managed by providers.

Key aspects of public cloud

  • Innovative SaaS business apps for applications ranging from customer resource management (CRM) to transaction management and data analytics
  • Flexible, scalable IaaS for storage and compute services on a moment’s notice
  • Powerful PaaS for cloud-based application development and deployment environments

Hybrid Cloud

A hybrid cloud uses a private cloud foundation combined with the strategic integration and use of public cloud services. The reality is a private cloud can’t exist in isolation from the rest of a company’s IT resources and the public cloud. Most companies with private clouds will evolve to manage workloads across data centers, private clouds, and public clouds—thereby creating hybrid clouds.
 

Key aspects of hybrid cloud


  • Allows companies to keep the critical applications and sensitive data in a traditional data center environment or private cloud
  • Enables taking advantage of public cloud resources like SaaS, for the latest applications, and IaaS, for elastic virtual resources
  • Facilitates portability of data, apps and services and more choices for deployment models



Tuesday, 14 June 2016

AngularJS - Part 7

Before continuing this, please refer AngularJS - Part 6


AngularJS – Internalization

AngularJS supports inbuilt internationalization for three types of filters currency, date and numbers. We only need to incorporate corresponding js according to locale of the country. By default it handles the locale of the browser.


AngularJS - Views

AngularJS supports Single Page Application via multiple views on a single page. To do this AngularJS has provided ng-view and ng-template directives and $routeProvider services.

 

ng-view

ng-view tag simply creates a place holder where a corresponding view (html or ng-template view) can be placed based on the configuration.

Usage

Define a div with ng-view within the main module.
<div ng-app = "mainApp">
   ...
   <div ng-view></div>
</div>    

 

ng-template

ng-template directive is used to create an html view using script tag. It contains "id" attribute which is used by $routeProvider to map a view with a controller.

Usage

Define a script block with type as ng-template within the main module.
<div ng-app = "mainApp">
   ... 
   <script type = "text/ng-template" id = "addStudent.htm">
      <h2> Add Student </h2>
      {{message}}
   </script>
</div>    

 

$routeProvider

$routeProvider is the key service which set the configuration of urls, map them with the corresponding html page or ng-template, and attach a controller with the same.

Usage

Define a script block with type as ng-template within the main module.
<div ng-app = "mainApp">
   ...      
   <script type = "text/ng-template" id = "addStudent.htm">
      <h2> Add Student </h2>
      {{message}}
   </script>
</div>    

Usage

Define a script block with main module and set the routing configuration.
var mainApp = angular.module("mainApp", ['ngRoute']);
mainApp.config(['$routeProvider', function($routeProvider) {
   $routeProvider.
   when('/addStudent', {
      templateUrl: 'addStudent.htm', controller: 'AddStudentController'
   }).
   when('/viewStudents', {
      templateUrl: 'viewStudents.htm', controller: 'ViewStudentsController'
   }).
   otherwise({
      redirectTo: '/addStudent'
   });
}]);


Following are the important points to be considered in above example.

  • $routeProvider is defined as a function under config of mainApp module using key as '$routeProvider'.
  • $routeProvider.when defines a url "/addStudent" which then is mapped to "addStudent.htm". addStudent.htm should be present in the same path as main html page.If htm page is not defined then ng-template to be used with id="addStudent.htm". We've used ng-template.
  • "otherwise" is used to set the default view.
  • "controller" is used to set the corresponding controller for the view.

AngularJS – Ajax

AngularJS provides $http control which works as a service to read data from the server. The server makes a database call to get the desired records. AngularJS needs data in JSON format. Once the data is ready, $http can be used to get the data from server in the following manner −
function studentController($scope,$http) {
var url = "data.txt";
   $http.get(url).success( function(response) {
      $scope.students = response; 
   });
}


<<Angular JS -Part 6

AngularJS - Part 6

Before continuing this, please refer AngularJS - Part 5


AngularJS – Services

Angular services are substitutable objects that are wired together using dependency injection (DI). You can use services to organize and share code across your app.
Angular services are:
  • Lazily instantiated – Angular only instantiates a service when an application component depends on it.
  • Singletons – Each component dependent on a service gets a reference to the single instance generated by the service factory.
There are two ways to create a service.
  • factory
  • service

 

Using factory method

Using factory method, we first define a factory and then assign method to it.
var mainApp = angular.module("mainApp", []);
mainApp.factory('MathService', function() {
   var factory = {};
   factory.multiply = function(a, b) {
      return a * b
   }
   return factory;
}); 

 

Using service method

Using service method, we define a service and then assign method to it. We've also injected an already available service to it.
mainApp.service('CalcService', function(MathService){
   this.square = function(a) {
      return MathService.multiply(a,a);
   }
});


AngularJS - Dependency Injection

Dependency Injection (DI) is a software design pattern that deals with how components get hold of their dependencies.
The Angular injector subsystem is in charge of creating components, resolving their dependencies, and providing them to other components as requested.

Using Dependency Injection

DI is pervasive throughout Angular. You can use it when defining components or when providing run and config blocks for a module.
  • Components such as services, directives, filters, and animations are defined by an injectable factory method or constructor function. These components can be injected with "service" and "value" components as dependencies.
  • Controllers are defined by a constructor function, which can be injected with any of the "service" and "value" components as dependencies, but they can also be provided with special dependencies. See Controllers below for a list of these special dependencies.
  • The run method accepts a function, which can be injected with "service", "value" and "constant" components as dependencies. Note that you cannot inject "providers" into run blocks.
  • The config method accepts a function, which can be injected with "provider" and "constant" components as dependencies. Note that you cannot inject "service" or "value" components into configuration.

Dependency Annotation

Angular invokes certain functions (like service factories and controllers) via the injector. You need to annotate these functions so that the injector knows what services to inject into the function. There are three ways of annotating your code with service name information:
  • Using the inline array annotation (preferred)
  • Using the $inject property annotation
  • Implicitly from the function parameter names (has caveats)

Why Dependency Injection?

There are only three ways a component (object or function) can get a hold of its dependencies:
  1. The component can create the dependency, typically using the new operator.
  2. The component can look up the dependency, by referring to a global variable.
  3. The component can have the dependency passed to it where it is needed.
The first two options of creating or looking up dependencies are not optimal because they hard code the dependency to the component. This makes it difficult, if not impossible, to modify the dependencies. This is especially problematic in tests, where it is often desirable to provide mock dependencies for test isolation.
AngularJS provides a supreme Dependency Injection mechanism. It provides following core components which can be injected into each other as dependencies.
  • value
  • factory
  • service
  • provider
  • constant

value

value is simple javascript object and it is used to pass values to controller during config phase.
//define a module
var mainApp = angular.module("mainApp", []);
 
//create a value object as "defaultInput" and pass it a data.
mainApp.value("defaultInput", 5);
...
 
//inject the value in the controller using its name "defaultInput"
mainApp.controller('CalcController', function($scope, CalcService, defaultInput) {
   $scope.number = defaultInput;
   $scope.result = CalcService.square($scope.number);
   
   $scope.square = function() {
      $scope.result = CalcService.square($scope.number);
   }
});

 

 

factory

factory is a function which is used to return value. It creates value on demand whenever a service or controller requires. It normally uses a factory function to calculate and return the value.
//define a module
var mainApp = angular.module("mainApp", []);
 
//create a factory "MathService" which provides a method multiply to return 
//multiplication of two numbers
mainApp.factory('MathService', function() {
   var factory = {};
   
   factory.multiply = function(a, b) {
      return a * b
   }
   return factory;
}); 
 
//inject the factory "MathService" in a service to utilize the multiply 
//method of factory.
mainApp.service('CalcService', function(MathService){
   this.square = function(a) {
      return MathService.multiply(a,a);
   }
});
...

 

 

service

service is a singleton javascript object containing a set of functions to perform certain tasks. Services are defined using service() functions and then injected into controllers.
//define a module
var mainApp = angular.module("mainApp", []);
...
 
//create a service which defines a method square to return square of a number.
mainApp.service('CalcService', function(MathService){
   this.square = function(a) {
      return MathService.multiply(a,a); 
   }
});
 
//inject the service "CalcService" into the controller
mainApp.controller('CalcController', function($scope, CalcService, defaultInput) {
   $scope.number = defaultInput;
   $scope.result = CalcService.square($scope.number);
   
   $scope.square = function() {
      $scope.result = CalcService.square($scope.number);
   }
});

 

 

provider

provider is used by AngularJS internally to create services, factory etc. during config phase(phase during which AngularJS bootstraps itself). Below mention script can be used to create MathService that we've created earlier. Provider is a special factory method with a method get() which is used to return the value/service/factory.
//define a module
var mainApp = angular.module("mainApp", []);
...
 
//create a service using provider which defines a method square to 
//return square of a number.
mainApp.config(function($provide) {
   $provide.provider('MathService', function() {
      this.$get = function() {
         var factory = {};  
         
         factory.multiply = function(a, b) {
            return a * b; 
         }
         return factory;
      };
   });
});

 

 

constant

constants are used to pass values at config phase considering the fact that value can not be used to be passed during config phase.
mainApp.constant("configParam", "constant value");

<<Angular JS -Part                                                                                  Angular JS -Part 7>>

Monday, 6 June 2016

AngularJS - Part 5

Before continuing this, please refer AngularJS - Part 4


AngularJS - Forms

Controls (input, select, textarea) are ways for a user to enter data. A Form is a collection of controls for the purpose of grouping related controls together.
Form and controls provide validation services, so that the user can be notified of invalid input before submitting a form. This provides a better user experience than server-side validation alone because the user gets instant feedback on how to correct the error. Keep in mind that while client-side validation plays an important role in providing good user experience, it can easily be circumvented and thus can not be trusted. Server-side validation is still necessary for a secure application.


Events

AngularJS provides multiple events which can be associated with the HTML controls. For example ng-click is normally associated with button. Following are supported events in Angular JS.
  • ng-click
  • ng-dbl-click
  • ng-mousedown
  • ng-mouseup
  • ng-mouseenter
  • ng-mouseleave
  • ng-mousemove
  • ng-mouseover
  • ng-keydown
  • ng-keyup
  • ng-keypress
  • ng-change

 

ng-click

Reset data of a form using on-click directive of a button.
<input name = "firstname" type = "text" ng-model = "firstName" required>
<input name = "lastname" type = "text" ng-model = "lastName" required>
<input name = "email" type = "email" ng-model = "email" required>
<button ng-click = "reset()">Reset</button>
<script>
   function studentController($scope) { 
      $scope.reset = function(){
         $scope.firstName = "Mahesh";
         $scope.lastName = "Parashar";
         $scope.email = "MaheshParashar@tutorialspoint.com";
      }   
      $scope.reset();
   }
</script>

 

Validate data

Following can be used to track error.
  • $dirty − states that value has been changed.
  • $invalid − states that value entered is invalid.
  • $error − states the exact error.


AngularJS – Includes

HTML does not support embedding html pages within html page. To achieve this functionality following ways are used −
  • Using Ajax − Make a server call to get the corresponding html page and set it in innerHTML of html control.
  • Using Server Side Includes − JSP, PHP and other web side server technologies can include html pages within a dynamic page.
Using AngularJS, we can embedded HTML pages within a HTML page using ng-include directive.
<div ng-app = "" ng-controller = "studentController">
   <div ng-include = "'main.htm'"></div>
   <div ng-include = "'subjects.htm'"></div>
</div>


AngularJS – Scopes

Scope is an object that refers to the application model. It is an execution context for expressions. Scopes are arranged in hierarchical structure which mimic the DOM structure of the application. Scopes can watch expressions and propagate events.

 

Scope as Data-Model

Scope is the glue between application controller and the view. During the template linking phase the directives  set up $watch expressions on the scope. The $watch allows the directives to be notified of property changes, which allows the directive to render the updated value to the DOM.

In controllers, model data is accessed via $scope object.
<script>
   var mainApp = angular.module("mainApp", []);
   mainApp.controller("shapeController", function($scope) {
      $scope.message = "In shape controller";
      $scope.type = "Shape";
   });
</script>
Following are the important points to be considered in above example.
  • $scope is passed as first argument to controller during its constructor definition.
  • $scope.message and $scope.type are the models which are to be used in the HTML page.
  • We've set values to models which will be reflected in the application module whose controller is shapeController.
  • We can define functions as well in $scope.

 

Scope Inheritance

Scope are controllers specific. If we defines nested controllers then child controller will inherit the scope of its parent controller.
<script>
   var mainApp = angular.module("mainApp", []);
   mainApp.controller("shapeController", function($scope) {
      $scope.message = "In shape controller";
      $scope.type = "Shape";
   });
   mainApp.controller("circleController", function($scope) {
      $scope.message = "In circle controller";
   });   
</script>
Following are the important points to be considered in above example.
  • We've set values to models in shapeController.
  • We've overridden message in child controller circleController. When "message" is used within module of controller circleController, the overridden message will be used.


 <<Angular JS -Part 4                                                                                     Angular JS -Part 6>>

AngularJS - Part 4

Before continuing this, please refer Angular JS -Part 3


AngularJS - HTML DOM

Following directives can be used to bind application data to attributes of HTML DOM Elements.
Sr.No. Name Description
1 ng-disabled disables a given control.
2 ng-show shows a given control.
3 ng-hide hides a given control.
4 ng-click represents a AngularJS click event.


ng-disabled directive

Add ng-disabled attribute to a HTML button and pass it a model. Bind the model to an checkbox and see the variation.
<input type = "checkbox" ng-model = "enableDisableButton">Disable Button
<button ng-disabled = "enableDisableButton">Click Me!</button>
 

ng-show directive

Add ng-show attribute to a HTML button and pass it a model. Bind the model to an checkbox and see the variation.
<input type = "checkbox" ng-model = "showHide1">Show Button
<button ng-show = "showHide1">Click Me!</button>

 

ng-hide directive

Add ng-hide attribute to a HTML button and pass it a model. Bind the model to an checkbox and see the variation.
<input type = "checkbox" ng-model = "showHide2">Hide Button
<button ng-hide = "showHide2">Click Me!</button>

 

ng-click directive

Add ng-click attribute to a HTML button and update a model. Bind the model to html and see the variation.
<p>Total click: {{ clickCounter }}</p>
<button ng-click = "clickCounter = clickCounter + 1">Click Me!</button>

AngularJS – Modules

You can think of a module as a container for the different parts of your app – controllers, services, filters, directives, etc.

 

Why we use it?

Most applications have a main method that instantiates and wires together the different parts of the application.
Angular apps don't have a main method. Instead modules declaratively specify how an application should be bootstrapped. There are several advantages to this approach:
  • The declarative process is easier to understand.
  • You can package code as reusable modules.
  • The modules can be loaded in any order (or even in parallel) because modules delay execution.
  • Unit tests only have to load relevant modules, which keeps them fast.
  • End-to-end tests can use modules to override configuration.
We define modules in separate js files and name them as per the module.js file. In this example we're going to create two modules.
  • Application Module − used to initialize an application with controller(s).
  • Controller Module − used to define the controller.

 

Application Module

mainApp.js
var mainApp = angular.module("mainApp", []);
Here we've declared an application mainApp module using angular.module function. We've passed an empty array to it. This array generally contains dependent modules.

 

Controller Module

studentController.js
mainApp.controller("studentController", function($scope) {
   $scope.student = {
      firstName: "Mahesh",
      lastName: "Parashar",
      fees:500,
      subjects:[
         {name:'Physics',marks:70},
         {name:'Chemistry',marks:80},
         {name:'Math',marks:65},
         {name:'English',marks:75},
         {name:'Hindi',marks:67}
      ],
      fullName: function() {
         var studentObject;
         studentObject = $scope.student;
         return studentObject.firstName + " " + studentObject.lastName;
      }
   };
});
Here we've declared a controller studentController module using mainApp.controller function.

 

Use Modules

<div ng-app = "mainApp" ng-controller = "studentController">
   ...
   <script src = "mainApp.js"></script>
   <script src = "studentController.js"></script>    
</div>
Here we've used application module using ng-app directive and controller using ng-controller directive. We've imported mainApp.js and studentController.js in the main html page.

 <<Angular JS -Part 3                                   Angular JS -Part 5>>

Saturday, 28 May 2016

AngularJS - Part 3

Before continuing this, please refer Angular JS- Part 2

AngularJS – Controllers

In Angular, a Controller is defined by a JavaScript constructor function that is used to augment the Angular Scope.
When a Controller is attached to the DOM via the ng-controller directive, Angular will instantiate a new Controller object, using the specified Controller's constructor function. A new child scope will be created and made available as an injectable parameter to the Controller's constructor function as $scope.
If the controller has been attached using the controller as syntax then the controller instance will be assigned to a property on the new scope.
<div ng-app = "" ng-controller = "studentController">
   ...
</div>

AngularJS – Filters

A filter formats the value of an expression for display to the user. They can be used in view templates, controllers or services and it is easy to define your own filter.
The underlying API is the filterProvider.

Using filters in view templates

Filters can be applied to expressions in view templates using the following syntax:
{{ expression | filter }}
Following is the list of commonly used filters:-
Sr.No. Name Description
1 uppercase converts a text to upper case text.
2 lowercase converts a text to lower case text.
3 currency formats text in a currency format.
4 filter filter the array to a subset of it based on provided criteria.
5 orderby orders the array based on provided criteria.

uppercase filter

Add uppercase filter to an expression using pipe character. Here we've added uppercase filter to print student name in all capital letters.
Enter first name:<input type = "text" ng-model = "student.firstName">
Enter last name: <input type = "text" ng-model = "student.lastName">
Name in Upper Case: {{student.fullName() | uppercase}}

 

lowercase filter

Add lowercase filter to an expression using pipe character. Here we've added lowercase filter to print student name in all lowercase letters.
Enter first name:<input type = "text" ng-model = "student.firstName">
Enter last name: <input type = "text" ng-model = "student.lastName">
Name in Upper Case: {{student.fullName() | lowercase}}

 

currency filter

Add currency filter to an expression returning number using pipe character. Here we've added currency filter to print fees using currency format.
Enter fees: <input type = "text" ng-model = "student.fees">
fees: {{student.fees | currency}}

 

filter filter

To display only required subjects, we've used subjectName as filter.
Enter subject: <input type = "text" ng-model = "subjectName">
Subject:
<ul>
  <li ng-repeat = "subject in student.subjects | filter: subjectName">
     {{ subject.name + ', marks:' + subject.marks }}
  </li>
</ul>

 

orderby filter

To order subjects by marks, we've used orderBy marks.
Subject:
<ul>
  <li ng-repeat = "subject in student.subjects | orderBy:'marks'">
     {{ subject.name + ', marks:' + subject.marks }}
  </li>
</ul>

 

AngularJS – Tables

Table data is normally repeatable by nature. ng-repeat directive can be used to draw table easily. Following example states the use of ng-repeat directive to draw a table.
<table>
   <tr>
      <th>Name</th>
      <th>Marks</th>
   </tr>
   <tr ng-repeat = "subject in student.subjects">
      <td>{{ subject.name }}</td>
      <td>{{ subject.marks }}</td>
   </tr>
</table>

 <<Angular JS- Part 2                                    Angular JS- Part 4>>