Wednesday, November 22, 2023

Let's try to build scrum masters/project managers/software architects/even a company with training AI models

The concept:

The basic concept is to build trained AI model for each role separately in scalable fashion within a private cloud. As an example to train a scrum master as an AI component, we have to probably feed good knowledge of day to day tasks of a scrum master. Apart from that the model need to aware how scrum master manage the SCRUM board in the relevant tool stack eg: JIRA.

One pod within the Kubernetes cluster can be considered as a one scrum master per a team. Likewise we have some sort of ability to maintain a good knowledge base as a source of training data.

Apart from these steps, we need to think about how to simulate speaking and handling, commanding and escalating in the meetings, The end goal of this conceptual project is to fully automate the software life cycle and fine grain the each responsibilities of scrum masters, project managers, software architects, CTO and CEO. however the each role should be backed by a single human being.

The ultimate goal of this project to setup your own organisation as an entrepreneur by training an AI based pods instead of a staff. so when you need to grow your organisation, you can increase the pods too.

The tools maybe:

Azure OpenAI
PyTorch
TensorFlow
MongoDB
Apache NLP
Spring Web Socket/ REST
Azure Kubernetes


The strategy:

The most critical part of this project is how to do. Let's explore and analyse a bit, how we can make this concept a reality. 

Saturday, November 11, 2023

Chat with PDF, TXT, and CSV privately (PrivateGPT) suitable for more data sensitive organisations (To be reviewed)

 The newly introduced PrivateGPT is a production ready and most suitable for the organisations who handles extremely sensitive data as per their documentation. To be carefully considered. To find out more information. 

https://github.com/imartinez/privateGPT/tree/main


Saturday, October 21, 2023

Problem Solving: Allotment calculator

 Problem Statement:

Suppose the Government plans to issue up to $10,000 of Savings Bonds. Four individuals applied for a total of $18,000 of Savings Bonds: A ($2,000), B ($4,000) C ($5,500) and D ($6,500).

The available bonds will be spread out among as many investors as possible in the following manner:

  • Applications are filled in denominations of $500 upwards.
  • After Round 4, $8,000 of Savings Bonds have been allotted, and Investor A's application has been fully met. $2,000 of Savings Bonds are left.
  • In Round 5, $1,500 of Savings Bonds are allotted.
  • In Round 6, the remaining $500 is insufficient to fill all applications.
  • One person among Investor B, Investor C and Investor D is randomly allotted the remaining $500. In this case, Investor C gets it.

The cutoff amount in this case is $2,500. In the final allotment:

  • Investor A is allotted $2,000.
  • Investor B and Investor D get $2,500 each.
  • Investor C gets $3,000.
limitations:

1. The minimum individual investment amount is $500
2. The maximum individual investment amount is $200000
3. The individual investment amount always should be multiplies of $500

Find out the allotment amount issued to each individual investor.

The Solution:

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Predicate;
public class SbPlanningCalculator {

private final static Integer MIN = 500;
private final static Integer MAX = 2_00_000;

private final static Predicate<List<User>> isAllValid = users -> {
int allCount = users.size();
int validCount = (int)users.stream().
map(User::getValue).
filter(value -> value >= MIN && value <= MAX && value % MIN == 0).
count();
return allCount == validCount;
};

public static Map<String, Integer> calculateMyPotential(List<User> users, Integer issuedAmount){

if(!isAllValid.test(users)){
System.err.print("Found Invalid Amounts among the users. ");
return null;
}

int total = 0;
Map<String, Integer> allotments = new HashMap<>(0);

int rounds = Math.divideExact(issuedAmount, users.size() * MIN);

int i = 0;
while(i <= rounds) {
for (User user : users) {
int issuedBalanceTotal = issuedAmount - total;

if (issuedBalanceTotal == 0) {
break;
}

if (user.getValue() >= MIN) {
total = total + MIN;
user.setValue(user.getValue() - MIN);

if (allotments.containsKey(user.getName())) {
int userAllotment = allotments.get(user.getName());
allotments.put(user.getName(), userAllotment + MIN);
} else {
allotments.put(user.getName(), MIN);
}
}

}
i++;
}
return allotments;
}
}

Test Cases:

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

class SbPlanningCalculatorTest {

@Test
void testCalculateMyPotentialCase1(){
List<User> users = new ArrayList<>(0);
users.add(new User("A", 2000));
users.add(new User("B", 4000));
users.add(new User("C", 5500));
users.add(new User("D", 6500));

Map<String, Integer> allotments = SbPlanningCalculator.calculateMyPotential(users, 10000);
System.out.println(allotments);
assert allotments != null;
var x = allotments.entrySet().stream().collect(Collectors.groupingBy(Map.Entry::getValue, Collectors.counting()));
long sum = x.entrySet().stream().map(e -> e.getKey() * e.getValue()).mapToLong(l -> l).sum();
Assertions.assertEquals(10000, sum);
}

@Test
void testCalculateMyPotentialCase2(){
List<User> users = new ArrayList<>(0);
users.add(new User("A", 2000));
users.add(new User("B", 4000));
users.add(new User("C", 5500));
users.add(new User("D", 26000));

Map<String, Integer> allotments = SbPlanningCalculator.calculateMyPotential(users, 1_000_000_000);
System.out.println(allotments);
assert allotments != null;
var x = allotments.entrySet().stream().collect(Collectors.groupingBy(Map.Entry::getValue, Collectors.counting()));
long sum = x.entrySet().stream().map(e -> e.getKey() * e.getValue()).mapToLong(l -> l).sum();
Assertions.assertEquals(37500, sum);
}

@Test
void testCalculateMyPotentialCase3(){
List<User> users = new ArrayList<>(0);
users.add(new User("A", 500));
users.add(new User("B", 2_00_000));
users.add(new User("C", 14000));
users.add(new User("D", 26000));

Map<String, Integer> allotments = SbPlanningCalculator.calculateMyPotential(users, 1_000_000_000);
System.out.println(allotments);
assert allotments != null;
var x = allotments.entrySet().stream().collect(Collectors.groupingBy(Map.Entry::getValue, Collectors.counting()));
long sum = x.entrySet().stream().map(e -> e.getKey() * e.getValue()).mapToLong(l -> l).sum();
Assertions.assertEquals(2_40_500, sum);
}

@Test
void testCalculateMyPotentialCase4(){
List<User> users = new ArrayList<>(0);
users.add(new User("A", 1_000_000));
users.add(new User("B", 2_00_000));
users.add(new User("C", 250));
users.add(new User("D", 26000));

Map<String, Integer> allotments = SbPlanningCalculator.calculateMyPotential(users, 1_000_000_000);
System.out.println(allotments);
Assertions.assertNull(allotments);
}

@Test
void testCalculateMyPotentialCase5(){
List<User> users = new ArrayList<>(0);
users.add(new User("A", 2_00_000));
users.add(new User("B", 2_00_000));
users.add(new User("C", 2_00_000));
users.add(new User("D", 26000));

for(int x = 0; x < 5500; x++){
users.add(new User("X" + x, 2_00_000));
}

Map<String, Integer> allotments = SbPlanningCalculator.calculateMyPotential(users, 1_000_000_000);

assert allotments != null;
var x = allotments.entrySet().stream().collect(Collectors.groupingBy(Map.Entry::getValue, Collectors.counting()));
System.out.println(x);
long sum = x.entrySet().stream().map(e -> e.getKey() * e.getValue()).mapToLong(l -> l).sum();
Assertions.assertEquals(1_000_000_000, sum);
}
}

Monday, January 9, 2023

Supersonic, Subatomic Cloud Native gRPC endpoint implementation with Quarkus

Quarkus gRPC Service Implementation from the scratch

Requirement

In order to produce most reliable, fast and maintainable products we can use Quarkus (

Supersonic, Subatomic Cloud Native Java Framework) as a foundational technology for our backend

services.

Our task it to use [Quarkus](https://quarkus.io/) and [gRPC](https://grpc.io/) to build a

microservice running in [Kubernetes](https://kubernetes.io/) with the following capabilities:

1. The microservice should expose APIs for Smart Models and Smart Features

2. Smart Model is a generic model which can be used to describe your favourite Services and IoT

   Devices. Think about the following examples for:

- Devices: Smart Watch, Remotely Controllable Camera, etc

- Services: Open Weather Map, IMDB Movie Database, etc

3. Smart Feature is a specific feature of this smart model which describes one functionality. we can

   consider following examples for:

- Devices: Take Camera Screenshot, Get Camera Live Video URL, Get Calories burned for a day

- Services: Get Weekly Forecast in a City, Get Daily Forecast for a State, Search Movie

4. One Smart Model contains several smart features.

5. The microservice should allow storing the smart features and services in a persistent storage and

   retrieving them based on information as name, identifier, type and category.

6. Generate data for a few example Smart Services and Smart Features by our self for demonstration

   purposes.


Hints

- Think big and start small by creating a common data model which can be applied to both smart
  services and smart models. Keep it simple!
- Framework Usage: Use all the power of Quarkus to deploy your application
- Code Quality
- Unit Tests
- Documentation: Provide a short and understandable documentation how:
    - To build the app
    - To deploy the app in minikube or any other Kubernetes local development platform
    - To test the app with simple tools/commands
    - Any other relevant information
- Ensure that application can be built and deployed

Fully implemented project


Sunday, October 31, 2021

Climate Change News from all over the world through API

 Free Public API - Climate Change News


Hello developers, here is a simple API to include in the product that supports you to retrieve climate change news around the globe within a few seconds.



This is a really simple to use API which helps you to find out the latest climate change news around the globe within seconds.

it provides two endpoints to retrieve the climate change news:

Retrieve all the climate change news at once - eg: http://{rapid-api-host}/api/news
Retrieve all the climate change news from individual sources - eg: http://{rapid-api-host}/api/news/guardian

for now, we are supporting the following individual sources -
I. guardian
II. thetimes
III. telegraph
IV. nasa
V. dailymail
VI. nypost
VII. cnn

Remember to include the required headers by rapid API in order to make everything smooth.
Thank you for consuming the climate change news API for your valuable product.


Friday, July 16, 2021

Microsoft Azure + Spring Cloud Sample application from the scratch

 

Objectives

In this post, we will:

  • Set up an Azure Spring Cloud cluster
  • Configure a Spring Cloud Config Server
  • Use a Spring Cloud Discovery Server
  • Configure service binding
  • Create and deploy a Spring Boot microservice
  • Create and deploy a Spring Cloud Gateway

Prerequisites


Check version of Azure CLI, use Git bash to execute
az --version
az login # Sign into an azure account az account show # See the currently signed-in account.
az account set --subscription <SUBSCRIPTION_ID>
az extension add -n spring-cloud -y #If you haven't added this extension yet add it.

Congratulations, the Azure CLI is now ready to create your first cluster!

Create an Azure Spring Cloud instance

RESOURCE_GROUP_NAME=spring-cloud-sample-rsgrp SPRING_CLOUD_NAME=azure-spring-cloud-unique9563

az group create \ -g "$RESOURCE_GROUP_NAME" \ -l eastus

az spring-cloud create \ -g "$RESOURCE_GROUP_NAME" \ -n "$SPRING_CLOUD_NAME" \ --sku standard \ --enable-java-agent

prepare and set your variables in Azure CLI for next steps.
az configure --defaults group=${RESOURCE_GROUP_NAME} az configure --defaults spring-cloud=${SPRING_CLOUD_NAME}


Configure a Spring Cloud Config Server

On your GitHub account, create a new private repository where the Spring Boot configurations will be stored. In the new private GitHub repository, add a new application.yml file, which will store configuration data for all our microservices. Typically, each Spring Boot application includes such a file within the application binaries to contain application settings. A Spring Cloud Configuration Server allows such settings to be stored outside your application, which provides the following benefits: It allows storing sensitive parameters (like your database password) outside of your application. Your configuration is stored in a Git repository, so its data can be tagged or rolled back. It uses a specific Git repository, which can be secured separately. It provides a centralized place to store all your configuration data, for all your microservices. For the moment, our application.yml will just store a message to check if the configuration is successful:

application: message: Configured by Azure Spring Cloud

git add application.yml git commit -m 'Add new Spring Boot configuration file' git push

Create a github personal Token:



Configure Azure Spring Cloud to access the Git repo:
1. Go to the overview page of your Azure Spring Cloud server and select "Config server" in the menu
2. Configure the repository we previously created:
  1. Add the repository URL, for example https://github.com/<YOUR_USERNAME>/azure-spring-cloud-config or git@github.com:<YOUR_USERNAME>/azure-spring-cloud-config.git.
  2. Add your branch in Label. It defaults to main on GitHub, but older repositories or alternate Git providers might still use master.
  3. Click on Authentication and select HTTP Basic.
  4. The username is your GitHub login name.
  5. The password is the personal token we created in the previous section.
3. Click on Apply and wait for the operation to succeed.
4. Click on Validate and wait for the operation to succeed.

Build a Spring Boot microservice


Create a specific todo-service application in your Azure Spring Cloud instance:
az spring-cloud app create --name todo-service --resource-group "$RESOURCE_GROUP_NAME" --service "$SPRING_CLOUD_NAME"

Now create an Azure database for MySQL:
az mysql server create \ --name ${SPRING_CLOUD_NAME}-mysql \ --resource-group "$RESOURCE_GROUP_NAME" \ --sku-name B_Gen5_1 \ --storage-size 5120 \ --admin-user "spring"

This operation can take a few minutes, and will output a JSON document: copy the password attribute in that document, as we will use it later.

Now create a todos database in that server, and open up its firewall so that Azure Spring Cloud can access it:

az mysql db create \ --name "todos" \ --server-name ${SPRING_CLOUD_NAME}-mysql

Bind mySql database to the application now:

Azure Spring Cloud can automatically bind the MySQL database we created to our microservice.

  1. Go to Apps in your Azure Spring Cloud instance.
  2. Select the todo-service application.
  3. Go to Service bindings.
  4. Click on Create service binding.
    1. Give your binding a name, for example mysql-todos.
    2. In the Binding type list, select Azure database for MySQL.
    3. The Resource name should be the one of the MySQL database you created earlier.
    4. The Database name should be todos
    5. The User name should be spring@YOUR_DATABASE_NAME, with YOUR_DATABASE_NAME being the name of your database, that we set up earlier as ${SPRING_CLOUD_NAME}-mysql when creating it.
    6. The Password is the password attribute that we copied earlier, when creating the server.

Select Create, and your Spring Boot application will have the MySQL database connection set up.

Create a Spring Boot microservice

curl https://start.spring.io/starter.tgz -d dependencies=web,mysql,data-jpa,cloud-eureka,cloud-config-client -d baseDir=todo-service -d bootVersion=2.3.6.RELEASE -d javaVersion=1.8 | tar -xzvf -



Go to the project folder and create below classes in the same package structure.

package com.example.demo; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; @Entity public class Todo { public Todo() { } public Todo(String description, boolean done) { this.description = description; this.done = done; } @Id @GeneratedValue private Long id; private String description; private boolean done; public Long getId() { return id; } public void setId(Long id) { this.id = id; } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } public boolean isDone() { return done; } public void setDone(boolean done) { this.done = done; } }


package com.example.demo; import org.springframework.data.jpa.repository.JpaRepository; public interface TodoRepository extends JpaRepository<Todo, Long> { }


package com.example.demo; import org.springframework.web.bind.annotation.*; import javax.annotation.PostConstruct; import java.util.Arrays; @RestController public class TodoController { private final TodoRepository todoRepository; public TodoController(TodoRepository todoRepository) { this.todoRepository = todoRepository; } @PostConstruct public void init() { todoRepository.saveAll(Arrays.asList( new Todo("First item", true), new Todo("Second item", true), new Todo("Third item", false))); } @GetMapping("/") public Iterable<Todo> getTodos() { return todoRepository.findAll(); } }


In order to automatically generate the database tables when the application is deployed, add this line to your src/main/resources/application.properties configuration file:

spring.jpa.hibernate.ddl-auto=create-drop

You can now build your "todo-service" project and send it to Azure Spring Cloud:

cd todo-service ./mvnw clean package -DskipTests az spring-cloud app deploy --name todo-service --service "$SPRING_CLOUD_NAME" --resource-group "$RESOURCE_GROUP_NAME" --jar-path target/demo-0.0.1-SNAPSHOT.jar cd ..

To check the logs in spring cloud

az spring-cloud app logs --name todo-service --service "$SPRING_CLOUD_NAME" --resource-group "$RESOURCE_GROUP_NAME" -f

Now that the application is deployed, it's time to test it!

  1. In the Azure portal, go to Apps in your Azure Spring Cloud instance.
    1. Verify todo-service has a Registered Instance that says 0/1. This shows that it is correctly registered in the Spring Cloud Service Registry.
    2. Select todo-service to have more information on the microservice.
  2. Copy/paste the "Test Endpoint" that is provided.

You can now use cURL to test the endpoint. Your test command should look like:

curl https://primary:XXXXXXXXXXXXXXXXXXXXXXXXXXXXX@azure-spring-cloud-workshop.test.azuremicroservices.io/todo-service/default/


Build a Spring Cloud Gateway

Gateways are used to route public HTTP traffic to microservices:

  • They handle the routing logic.
  • They secure the access to the microservices (which will not be publicly available).
  • They can also have Quality of Service (QoS) capabilities, like doing HTTP rate limiting.
To create spring cloud gateway:
curl https://start.spring.io/starter.tgz -d dependencies=cloud-gateway,cloud-eureka,cloud-config-client -d baseDir=todo-gateway -d bootVersion=2.3.6.RELEASE -d javaVersion=1.8 | tar -xzvf -


Go to the project directory and copy followings to application.properties file:

spring.main.allow-bean-definition-overriding=true spring.cloud.gateway.discovery.locator.enabled=true

  • The spring.main.allow-bean-definition-overriding=true part is to configure Spring Cloud Gateway to use the Spring Cloud Discovery Server bean configured in the Azure Spring Cloud Client library.
  • The spring.cloud.gateway.discovery.locator.enabled=true part is to configure Spring Cloud Gateway to use the Spring Cloud Service Registry to discover the available microservices.
create a specific todo-gateway application in your Azure Spring Cloud instance. As this application is a gateway, we add the --assign-endpoint flag so it is exposed publicly.

az spring-cloud app create --name todo-gateway --service "$SPRING_CLOUD_NAME" --resource-group "$RESOURCE_GROUP_NAME" --assign-endpoint

You can now build your "todo-gateway" project and send it to Azure Spring Cloud:

cd todo-gateway
./mvnw clean package -DskipTests
az spring-cloud app deploy --name todo-gateway --service "$SPRING_CLOUD_NAME" --resource-group "$RESOURCE_GROUP_NAME" --jar-path target/demo-0.0.1-SNAPSHOT.jar
cd ..

Test the project in the cloud

  1. Go to Apps in your Azure Spring Cloud instance.
    1. Verify todo-gateway has a Registration status that says 1/1. This shows that it is correctly registered in the Spring Cloud Service Registry.
    2. Select todo-gateway to have more information on the microservice.
  2. Copy/paste the public URL that is provided (there is a "Test Endpoint" like for microservices, but the gateway is directly exposed on the Internet, so let's use the public URL). Keep this URL handy for subsequent sections.

As the gateway is connected to the Spring Cloud Service Registry, it should have automatically opened routes to the available microservices, with URL paths in the form of /MICROSERVICE-ID/**: [The MICROSERVICE-ID must be in capital letters]

Test the todo-service microservice endpoint by doing: curl https://XXXXXXXX-todo-gateway.azuremicroservices.io/TODO-SERVICE/ (replacing XXXXXXXX with the name of your Azure Spring Cloud instance)


Distributed tracing

We now have a complete microservices stack:

  • A Spring Boot microservice, that stores its data in MySQL.
  • A todo-gateway based on Spring Cloud Gateway.

However, even with only those two components, it already is quite challenging to monitor and study performance issues in our architecture.

To solve that issue, we're going to use Application Performance Monitoring (APM):

  1. Go to the Azure portal.
  2. Go to the overview page of your Azure Spring Cloud cluster and select Application Insights in the menu.
  3. This setting should already be on Enable.
  4. You'll have access to an application map, storing your tracing data.

Scale Spring Boot microservices


Spring Boot microservices and gateways running inside Azure Spring Cloud can be scaled vertically or horizontally:

  • Vertical scaling means you increase (or decrease) the CPU and RAM of a given service.
  • Horizontal scaling means you can add (or remove) nodes for a given service.

Scaling the "todo-service" microservice

  1. Go to the Azure portal.
  2. Go to the overview page of your Azure Spring Cloud cluster and select Apps in the menu.
  3. Select the todo-service application.
  4. Select Scale up in the left hand-side menu. You can now scale your service vertically, for example you can give it 2 CPUs and 4 Gb of RAM.
  5. Select Scale out in the left hand-side menu. You can also scale your service horizontally. For example, you can select your service and use Manual scale to have 2 instances of your service.








Let's try to build scrum masters/project managers/software architects/even a company with training AI models

The concept: The basic concept is to build trained AI model for each role separately in scalable fashion within a private cloud. As an examp...