OpenShift4

What is Openshift?

It is a platform as a service

oc explain

oc explain pod.spec.container.env

How to create pod

oc create -f pod.yaml

oc get pods

OC rsh

The oc rsh command in OpenShift allows you to “step inside” a running container and interact with it as if you were using a regular command prompt. It’s like opening a door to the container and being able to run commands and access files inside it.

  1. You need a tool called oc (OpenShift command-line tool) to use oc rsh. It helps you connect to an OpenShift cluster.
  2. You find the container you want to access within a group of containers called a “pod.”
  3. You use the oc rsh a command followed by the pod’s name to enter the container. It’s like opening the door to the container.
  4. Once inside, you can run commands and navigate the container’s files as if you were using a regular command prompt. You can check logs, run scripts, and do other things that the container allows.
  5. When you’re done, you exit the container by typing exit or pressing Ctrl+D. It’s like closing the door behind you.

Remember, it’s important to be careful when using oc rsh it because you can make changes that affect the container and the application running inside it.

OC delete

The oc delete command in OpenShift is used to delete various resources within an OpenShift cluster. It allows you to remove objects like pods, services, deployments, routes, and more.

oc delete <resource-type> <resource-name>

oc get pods –watch

Java Programming

Chapter 1

What is Java?

  • Java is an object-oriented programming language.
  • Popular programming language.
  • It is strongly typed language

.Class File

A class file in Java has a .class extension. It contains bytecode, which is instruction for Java Virtual Machine, which translates that bytecode into platform-specific machine-level instruction based upon whether the Java program runs on Windows or Linux.

First Java Program.

public class Main {
    public static void main(String[] args) {
        System.out.println("Welcom to Java programming");
    }
}

Chapter 2

Scanner Class

https://docs.oracle.com/javase/8/docs/api/java/util/Scanner.html

  • Scanner class is found in the java.util.package
  • Scanner class is use to get input from the user in Java
  • It can parse primitive types and strings using regex.
Scanner input = new Scanner(System.in); //Create an instance of the scanner 
System.out.print("Enter a double value: ");
Scanner input = new Scanner(System.in);
double d = input.nextDouble();
System.out.println("Your value is " + d);

Import Package

import java.util.* ; // Implicit import
import java.util.Scanner; // Explicit Import
No performance difference

Variable

  • A container that holds the value
  • Strongly typed

Primitive Data Types

  • Primitive data types are stored by Value. It is the fastest possible memory.
  • Numbers, characters, and Booleans values .
  • Primitive type names are all lowercase.
  • Primitive values are always signed they support positive and negative values.
  • btye, int,char,short, long, double, float, boolean
  • String is not primitive type.It is an object. It is a complex object, an instance of a class.
  • https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html

How to declare a variable?

int myVariable =20;
int => Data type
myVariable => identifier
= Assigment
20 = value

Starting Java 10, local variables can use type inference

var myVariable=20;

DataTypes example

        int firstValue=100;
        int secondValue=firstValue;
        firstValue=50;
        secondValue=70;
        System.out.println(firstValue);
        System.out.println(secondValue);

Explicit Types in Literal Values

var  myIntValue=5;
var  myFloatValue=5f;
var myDoubleValue=5d;
var myLongValue=5L or 5l

Stored by Value

Constants

  • A variable whose value cannot be changed once it is assigned.
  • Constant the variable name on constants
  • final datatype CONSTANTNAME = VALUE;  
final int VALUE=123;

Constant example

Type Casting

Converting the value from one data type to another data type

Implicit casting
double data= 3; (type widening)
Explicit casting
int i = (int)3.0; (type narrowing)
int i = (int)3.9; (Fraction part is truncated)

Chapter 3

Selections

How do we compare two values in java?

byte value1=1;
byte values2=2;
boolean result=(value1>value2);
System.out.println(result);

Result: false

Java if condition

Java if condition checks for the decision-making statement based on its true or false condition.

if(condition) 
{
   // Statements to execute if the given condition is true
  
}
---------------------------------
if (condition)
{
   // Run this block if
 condition is true
}
else
{
  // Run this block if
 condition is false
}
-----------------------------------------------------
if (condition)
    statement;
else if (condition)
    statement;
.
.
else
    statement;

Switch

Execute the code based on the value of the switch expression value.

switch (expression)
{
  case value1:
    statement1;
    break;
  case value2:
    statement2;
    break;

  default:
    statementDefault;
}

How to access YAML variable in puppet bolt plan

yaml file

groups:
-name: test
targets:
-uri: test.abc.edu
vars:
server_short_name: test123
config:
transport: ssh

plan test:passvariablevalue(
 
TargetSpec $targets

){
    
    # Gather facts 
   $tragets.apply_prep
    
   get_targets('development').each | $traget | {
      $results= run_command ("touch /shiva/files/svc.test.${target.vars['server_short_name']}",$target, {_run_as => 
'root'})
      out::message ("${results}")
 
   }



}

Run plan

bolt plan run test:test:passvariablevalue -t test

Ansible

ansible 

Get Fact

ansible all-m setup 
ansible all -m setup --fork=4
ansible-playbook message.yml  --syntax-check



Change windows registry entries using ansible-playbook

#Create registry entry and change pwd
---
- hosts: windows_servers
  vars:
     dbuserdata: ""
     dbpwddata: ""
  tasks:
  - name: Create Registry Entry User DBConnect
    win_regedit:
      path: HKLM:\SOFTWARE\Temp\DBConnect
      name: User
      data: '{{dbuserdata}}'

  - name: Create Registry Entry Password DBConnect
    win_regedit:
      path: HKLM:\SOFTWARE\Temp\DBConnect
      name: Pwd
      data: '{{dbpwddata}}'
  

Run ansible-playbook with

ansible-playbook registry_password_playbook.yaml --extra-vars "dbuserdata=tempuser dbpwddata=temppassword"

Change Registry Using Params in powershell

param (
   
   [string]  $userName = "UserName",
   [Parameter(Mandatory=$true)] [string] $value = "SecretPassword"
   
)

$registryPath = "HKLM:\SOFTWARE\WOW6432Node\TESTAPP"
IF(!(Test-Path $registryPath))

  {

    New-Item -Path $registryPath -Force | Out-Null
    New-ItemProperty -Path $registryPath -Name $userName -PropertyType 'String' -value $value

}

 ELSE {
    New-ItemProperty -Path $registryPath -Name $userName -Value $value -PropertyType 'String' -Force | Out-Null

 }

Modify webconfig connectionstring using powershell


 [CmdletBinding()]
  param ($PT_connectionstring_new =  "newpassword")  
  $webConfig = 'D:\Web.config'

Function updateWebConfig($config) 
{ 
$doc = (Get-Content $config) -as [Xml]
$root = $doc.get_DocumentElement();
$activeConnection = $root.connectionStrings.SelectNodes("add")|?{$_.name -eq "PROD"};
$activeConnection.SetAttribute("connectionString",$PT_connectionstring_new);
$doc.Save($config)
} 

updateWebConfig($webConfig)

Download remote zip, extract zip and copy files using puppet in windows

#download file from repo
 download_file { 'Download dotnet 4.0' :
  url                   => 'https://repos.shivaprogramming.com/Myapp.ZIP',
  destination_directory => 'D:\downloadapp',
}

#extract zip
 exec { 'Unzip Folder':
        command =>'Expand-Archive -Path D:\downloadapp\Myapp.ZIP -DestinationPath D:\downloadapp\DEST',
        provider  => powershell,
        logoutput =>    true,
        subscribe => Download_file['Download dotnet 4.0'],
    } 
#copy resources to the destination
 
 file { 'D:\CA_Websites\MyApp':  #destination
 ensure    => 'directory',
 recurse   => true,
 source    => 'D:\downloadapp\DEST',
 subscribe => Exec['Unzip Folder'],
  }


Power BI DAX

01 CALCULATED COLUMN

When calculations is done on a row level

Revenue = [Price_USD] * [Sales]
02 CALCULATED MEASURES

When calculation is done on an aggregated level and don’t want to store information on a row level

Measure do not create physical values in your table. It does not increase the file size.

PySpark

Data

Filter customer data by type VIP/Regular

from pyspark.sql.functions import *  
customer=spark.sql("Select * FROM workspace.customerdata.customer")
display(customer)
df.printSchema()
df1=df.filter(df["customer_type"]=="VIP")
df0=customer.filter(col("customer_type")=="Regular")
display(df1)
# filter by customer_type and country
df1=customer.filter((customer.customer_type=="VIP") & (customer.country=='USA'))
# where condition
df2=customer.where((customer.customer_type=="VIP") & (customer.country=='USA'))
# or operator
df3=customer.where((customer.customer_type=="VIP") | (customer.country=='USA'))

Add new column withColumn Function

from pyspark.sql.functions import *  
customer=spark.sql("Select * FROM workspace.customerdata.customer")
customer =customer.withColumn("Salary", col("age")* 1000)
customer.printSchema()
display(customer)

# withColumn fuction
customer =customer.withColumn("Seniority", when(customer.age>50, "Senior").otherwise("Junior"))