Sunday, December 13, 2015

Create Azure Load Balancer in PowerShell in ARM aka V2 Azure (and add existing NIC via UI or through resources.azure.com)

#Replace with your values!!!!


#https://azure.microsoft.com/en-us/documentation/articles/load-balancer-arm-powershell/
#login to Rm Account
Login-AzureRmAccount

$pipName = "dpcentoswebvm1-pip" #name of the new/existing public name
$lbBackendName = "LB-backend"
$lbName = "NRP-LB"
$lbbenic = "lb-nic1-be"

#select the subscription id
$subscriptionId =
    (Get-AzureRmSubscription |
     Out-GridView `
        -Title "Select an Azure Subscription ..." `
        -PassThru).SubscriptionId

Select-AzureRmSubscription `
    -SubscriptionId $subscriptionId

#select the resource group
$rgName =
    (Get-AzureRmResourceGroup |
     Out-GridView `
        -Title "Select an Azure Resource Group ..." `
        -PassThru).ResourceGroupName


#create a new pip
$publicIP = New-AzureRmPublicIpAddress `
    -Name $pipName `
    -ResourceGroupName "$rgName" `
    -Location "$location" `
    -AllocationMethod Static 

#if already a pip exists
#$publicIP = Get-AzureRmPublicIpAddress | Where-Object {$_.Name -eq "$pipName"}

#frontend lb ip
$frontendIP = New-AzureRmLoadBalancerFrontendIpConfig -Name LB-Frontend -PublicIpAddress $publicIP

#create an lb pool
$beaddresspool= New-AzureRmLoadBalancerBackendAddressPoolConfig -Name "$lbBackendName"

#create inbound rule
$inboundNATRule1= New-AzureRmLoadBalancerInboundNatRuleConfig -Name "SSH" -FrontendIpConfiguration $frontendIP `
    -Protocol TCP -FrontendPort 22 -BackendPort 22

#health check
$healthProbe = New-AzureRmLoadBalancerProbeConfig -Name "HealthProbe" -RequestPath "hc.html" `
    -Protocol http -Port 80 -IntervalInSeconds 15 -ProbeCount 2

#lb rule
$lbrule = New-AzureRmLoadBalancerRuleConfig -Name "HTTP" -FrontendIpConfiguration $frontendIP `
    -BackendAddressPool $beAddressPool -Probe $healthProbe -Protocol Tcp -FrontendPort 80 -BackendPort 80

#create lb
$NRPLB = New-AzureRmLoadBalancer -ResourceGroupName "$rgName" -Name "$lbName" -Location "$location"  `
    -FrontendIpConfiguration $frontendIP -InboundNatRule $inboundNATRule1 `
    -LoadBalancingRule $lbrule -BackendAddressPool $beAddressPool -Probe $healthProbe


A.  Add existing VMs through UI
In portal.azure.com -> All resources -> filter -> Select your ALB -> Backend Pools -> Add a virtual machine -> Select Availability Set -> Select VM

B.  Add existing VMs through resources.azure.com

Click on the “+” signs….
a.       Select :- subscriptions -> resourceGroups -> <your resource group> -> Microsoft.Network -> loadBalancers -> <your ALB>
b.       Enable “Read/Write”
c.       Click Edit
Under “backendAddressPools”: after provisioningState add/ammend backendIPConfigurations
          "provisioningState": "Succeeded",
          "backendIPConfigurations": [
            {
              "id": "/subscriptions/637156b4-7704-44f1-a19f-6bf607d6f499/resourceGroups/BasicIaaS/providers/Microsoft.Network/networkInterfaces/centoswebvm1959/ipConfigurations/ipconfig1"
            }
          ],
          "loadBalancingRules": [
d.       Click Put
e.       Check in the portal (or through powershell)
  Get-AzureRmLoadBalancer | Where-Object {$_.Name -like "*NRP*"} | ForEach-Object {$_.BackendAddressPools}


Apache Jersey + Tomcat + Eclipse + Maven with “echo” in XML/JSON (REST GET) in less than 30 min. with troubleshooting tips

Disclaimer:
Started with simple settings (with not even JUnit J.)

Pre-requisite:
1.       Jdk (tested with 1.8)
2.       Tomcat (tested with 8)
3.       Eclipse (tested with Mars)

Steps:
1.       Create a Maven project in Eclipse
Create a blank web-project with maven-archtype-web
2.       Add dependencies in Maven
a.       Add jersey-bundle
b.       Ensure java 1.8 is used (not 1.5 as the default is set)
Pom.xml:
      <dependencies>
            <dependency>
                  <groupId>com.sun.jersey</groupId>
                  <artifactId>jersey-bundle</artifactId>
                  <version>1.19</version>
            </dependency>
      </dependencies>
      <build>
            <finalName>pidev</finalName>
            <plugins>
                  <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-compiler-plugin</artifactId>
                        <version>3.1</version>
                        <configuration>
                              <source>1.8</source>
                              <target>1.8</target>
                        </configuration>
                  </plugin>
            </plugins>
      </build>
3.       Add Tomcat server library in Eclipse AND include in Order and Export
·         Build Path -> Configure Build Path -> Libraries -> Add Library -> Server Runtime -> Apache Tomcat 8.0
4.       Configure Jersey to listen for URI
       <servlet>
            <servlet-name>Jersey Web Application</servlet-name>
            <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
            <init-param>
                  <param-name>com.sun.jersey.config.property.packages</param-name>
                  <param-value><your package></param-value>
            </init-param>
            <load-on-startup>1</load-on-startup>
      </servlet>
      <servlet-mapping>
            <servlet-name>Jersey Web Application</servlet-name>
            <url-pattern>/rest/*</url-pattern>
      </servlet-mapping>


(Note that if the url-pattern is /* then url to address doesn’t need “rest” in the URI J)
5.       Write code
 package <your package>;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;

@Path("/xmlapi")
public class XMLAPI {
      @GET
      @Produces("application/xml")
      public String echo() {
            return ("<xmlapi>default echo</xmlapi>");
      }

      @Path("{c}")
      @GET
      @Produces("application/xml")
      public String echo(@PathParam("c") String c) {
            return ("<xmlapi>"+c+"</xmlapi>");
      }
}



For json
 package <your package>;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;

@Path("/jsonapi")
public class JsonAPI {
      @GET
      @Produces("application/json")
      public String echo() {
            return "{\"message\": \"default echo\"}";
      }

      @Path("{c}")
      @GET
      @Produces("application/xml")
      public String echo(@PathParam("c") String c) {
            return "{\"message\": \"" + c + "\"}";
      }
     

}
6.       Build and deploy
·         Maven -> Update project
·         Run project in Apache Tomcat
7.       Access the service
Output:
<?xml version="1.0"?>
<xmlapi>default echo</xmlapi>
Output:
<?xml version="1.0"?>

<xmlapi>hi</xmlapi>

Potential problems:
1.       Project don’t compile:
Java compiler level does not match the version of the installed Java project facet.
JAX-RS (REST Web Services) 2.0 requires Java 1.6 or newer.
One or more constraints have not been satisfied.
Maven default uses 1.5 J
Solution:
Add/update build element of pom.xml
      <build>
            <finalName><Project name></finalName>
            <plugins>
                  <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-compiler-plugin</artifactId>
                        <version>3.1</version>
                        <configuration>
                              <source>1.8</source>
                              <target>1.8</target>
                        </configuration>
                  </plugin>
            </plugins>
      </build>

2.       Jersey didn’t load your mapping
com.sun.jersey.api.core.ScanningResourceConfig.init No provider classes found.
Solution:
In web.xml ensure that correct package is specified in init-param
      <servlet>
            <servlet-name>Jersey Web Application</servlet-name>
            <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
            <init-param>
                  <param-name>com.sun.jersey.config.property.packages</param-name>
                  <param-value><your package></param-value>
            </init-param>
            <load-on-startup>1</load-on-startup>
      </servlet>

3.       Status 500 UriBuilder
Duplicate UriBuilder J Usually it happens if you try different dependencies and one of those dependencies downloads it for you (e.g. jersey-bundle with jersey-server or jersey-apache-connector)
Solution:
Remove javax.ws.rs-api.jar. 

Saturday, November 21, 2015

Getting Up with Operation Management Suite in less than 30 min on Linux (CentOS/Ubuntu) and Windows

Operations Management Suite overview:

Quick guide to get up and running with OMS with basic features (Works in both V1(ASM) and V2(ARM)):
·         Create an OMS workspace (onetime setup)
·         Browse the OMS workspaces, setup the workspace, and install agents (Windows and Linux)
(Please note that OMS also has discoverabilities. You can also install the agent while provisioning the VMs.)
·         Check the LogAnalytics backed by superfast search which leverages Azure Machine Learning.
Step 1:
Go to https://manage.windowsazure.com à + New (from bottom left of the page) à App Services à Operational Insights à Quick Create à fill in the form…(start with “Free”)

Step 2:
Go to https://manage.windowsazure.com à Operational Insights à Select your workspace à Select manage à You can skip the email confirmation page à Go through the setting wizard à Select all the default solutions à On the connected sources, install the agents on the Linux/Windows (see below links for supported versions,) please note that this pane will also lists the servers those are being currently monitored à Select the performance counters under data tab à (optional) check from upgrade and account management under account tab.

Step 3:
Play with OMS. (Please note that OMS also provides REST APIs which returns JSON for advanced needs.)

References
·         OMS search reference: https://technet.microsoft.com/en-us/library/mt450427.aspx
·         https://technet.microsoft.com/en-us/library/mt484118.aspx --- Get Started with OMS
Advance:
1.       Automate log searches with the Log Search API: https://technet.microsoft.com/library/mt484116.aspx
2.       Leveraging the OMS Search API in an Azure Automation Runbook: https://azure.microsoft.com/en-us/blog/leveraging-the-oms-search-api-in-an-azure-automation-runbook/
4.       Azure / Azure Stack – IaaS VM ARM MMA & Operational Insights Template Integration: http://www.danielstechblog.de/azure-azure-stack-iaas-vm-arm-mma-operational-insights-template-integration/
5.       Connect computers directly to OMS: https://technet.microsoft.com/library/mt484108.aspx

---
I have tried today OMS with V1 VMs (windows 2012 R2 DC  + centos 7.1; picked from gallery) and V2 VMs (Windows + Ubuntu; picked from gallery) and worked like a charm.
From history of my centos:
uname -a
cd /tmp/
chmod +x omsagent-1.0.0-47.universal.x64.sh
./omsagent-1.0.0-47.universal.x64.sh --install -w <workspaceid> -s  <key>

ps -ef | grep oms