Wednesday, December 16, 2020

Reading the GC Events



Real: wall clock time – time from start to finish of the call.
User: the amount of CPU time spent in user-mode code (outside the kernel) within the process.
Sys: the amount of CPU time spent in the kernel within the process.

More:https://blog.gceasy.io/2016/12/08/real-time-greater-than-user-and-sys-time/

Elastic Search Cluster Management

Steps to do rolling restart of ES cluster:
  • sudo su root
  • docker ps -a
  • docker stop/start <I_ID>
  • docker exec -it <IMG_Id> /bin/bash
  • ps -ef | grep ‘keyword’
  • kill – 15 <P_ID> //SIGTERM signal termination message
  • reboot
  • https://www.elastic.co/guide/en/elasticsearch/reference/current/restart-cluster.html#restart-cluster-rolling
  • ping host_name -> get IP
  • kill -9 <P_ID>
Querying cluster details :
GET _cat/indices
GET _cat/aliases

Index settings GET INDEX_NAME/_settings

Wednesday, December 9, 2020

Streams Cookbook

1.  Stream to Map

Map<Integer, String> result3 = list.stream().collect(
Collectors.toMap(x -> x.getId(), x -> x.getName()));

Map<String, Long> result2 = list.stream().collect(
Collectors.toMap(Hosting::getName, Hosting::getWebsites));

List<DataType> newList stream() .map(item -> { if (something) {
return item.get(bar).toString();
} else {
return item.somOtherObject;}}).collect(Collectors.toList());

Collector : 
    -Alternative to removal  through iterator.

Friday, July 10, 2020

Java Design : Naming Standards

Creational Structural Behavioural
Abstract Factory Assember Accumumator
Factory Builder Advisor
Decorator Applier
Augmenter Buncher
Checker
Collector
Command
Controller
Decider
Editor
Executor
Exporter
Handler
Iterator
Loader
Matcher
Notifier
Searcher
Selector
summarizer
Weaver

Thursday, July 9, 2020

Dynamic handling Spring Flow


Dynamically create your own BeanDefinition

BeanDefinitionRegistryPostProcessor has a hook on the BeanDefinitionRegistry

@Component
public class DynamicRegistryPostProcessor
        implements BeanDefinitionRegistryPostProcessor {

    @Override
    public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry)
            throws BeansException {

        RootBeanDefinition beanDefinition =
                new RootBeanDefinition(MyServiceImpl.class); 
        serviceDefinition.setTargetType(MyService.class); 
        serviceDefinition.setRole(BeanDefinition.ROLE_APPLICATION);
        registry.registerBeanDefinition("myBeanName", beanDefinition );
    }
}

Sunday, June 7, 2020

Terraform : IAC series II


About Terraform:

A declarative language,  not a programming language. Which keeps its state recorded when we run again it compares the new and old state.  
It gives a consistent way to describe the resources and interact with other resources.
Not good for workflow ,combination of steps…
It creates lock on the same module. This is avoid any mutability, and save from being into a corrupt state.

To make things easier, we have a reusable module (elastic cache, ami finder, rmq cluster etc, s3 replication.)
Module is needed with mutable infrastructure. Modules are like a jar.

Source code :

Terraform : IAC series I

This blog covers the basics of terraform a declarative language for managing infrastructure as code. 
Download link:
 brew install terraform  //mac
 choco install terraform //windows // manual :https://www.terraform.io/downloads.html
 Editor : Visual Studio code

Install terraform from above location. Check the installed version on terminal
 terraform -- version
Sample example 1

create a file main.tf
provider "aws" {
    access_key="XXXXXXXXXX"
    secret_key="xxxxx"
    region="us-east-1"
}
resource "aws_instance" "myfirstec2" {
  ami="ami-09d95fab7fff3776c"
  instance_type="t2.micro"
  tags= {
      Name="The Techie House demo"
  }
}
resource "aws_s3_bucket" "theTechieHouseB" {
  bucket="the-techie-house-first-bucket"
  acl="private"
  tags ={
            Name="The Techie House demo"
  }
}
Commands:
I. terraform init
II. terraform plan // show what it is going to perform
III. terraform apply // Going to create infrastructure
IV. Terraform show // show the available resources
V. terraform destroy // destroy everything

Wednesday, June 3, 2020

AWS Assoiate Notes

VPC:

Egress-only internet gateways:
- allows outbound communication over IPv6 from instances in your VPC to the internet, and prevents the internet from initiating an IPv6 connection with your instances.
*To enable outbound-only internet communication over IPv4, use a NAT gateway instead.

NAT gateway:
- You cannot route traffic to a NAT gateway through a VPC peering connection, a Site-to-Site VPN connection, or AWS Direct Connect. A NAT gateway cannot be used by resources on the other side of these connections.

VPC Flow log 
You can create a flow log for a VPC, a subnet, or a network interface. If you create a flow log for a subnet or VPC, each network interface in that subnet or VPC is monitored
Log format : <version> <account-id> <interface-id> <srcaddr> <dstaddr> <srcport> <dstport> <protocol> <packets> <bytes> <start> <end> <action> <log-status>

VPC endpoint services (AWS PrivateLink)
 Create your own application in your VPC and configure it as an AWS PrivateLink-powered service (referred to as an endpoint service). Other AWS principals can create a connection from their VPC to your endpoint service using an interface VPC endpoint.
- You can create a flow log for a VPC, a subnet, or a network interface. If you create a flow log for a subnet or VPC, each network interface in that subnet or VPC is monitored
 Routing
 VPC peering connection route contains Target as pcx-xxxxxx.
 VPN connection // Direct Connect connection route contains Target as vgw-xxxxxx.
  Gateway endpoint:  prefix list ID of the service (pl-xxxxxxxx), and a target with the endpoint ID (vpce-xxxxxxxx);



Redis : supports both replication and clustering