Wednesday, March 17, 2021

Change version of maven module and sub-module

 After a release or during a simple hot fix, you might want to modify the version of your maven-based service 


This is the trick: 


mvn versions:set -DgenerateBackupPoms=false -DnewVersion=1.42.0.1-SNAPSHOT

Monday, December 14, 2020

Elastic - quick search syntax

 Search over several fields 


All the condition must match 

curl -XPOST my_index/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "accountId": "le79612186"
          }
        },
        {
          "match": {
            "docType": "transfer_conversation"
          }
        },
        {
          "exists": {
            "field": "eventTime"
          }
        }
      ]
    }
  }
}

Sunday, November 15, 2020

Sven interesting shell command -

hadoop fs -text /liveperson/data/remote/DC=VA/storage_Shared/data_Platform/dwh_le/event_type=SatisfactionEvent/year=2020/month=11/day=11/* | grep "\"conversationHandlerAccountId\":{\"string\"" | sed -E 's/.*\"accountId\":\{\"string\":\"([0-9]+)\"\}.*/\1/g' | sort --human-numeric-sort | uniq | wc -l hadoop fs -text /liveperson/data/remote/DC=VA/storage_Shared/data_Platform/dwh_le/event_type=SatisfactionEvent/year=2020/month=11/day=11/* | grep -v "\"conversationHandlerAccountId\":{\"string\"" | sed -E 's/.*\"accountId\":\{\"string\":\"([0-9]+)\"\}.*/\1/g' | sort --human-numeric-sort | uniq | wc -l Pay attention to this sed -E 's/.*\"accountId\":\{\"string\":\"([0-9]+)\"\}.*/\1/g' Which means to take the accountID value right after the "accountId":{"string":" {"header":{"schemaRevision":"5.0.0.1266","eventTimeStamp":1605078051486,"eventUniqueId":{"string":"7AkrXepoQD2zRajMk3LDnA"},"globalSessionId":null,"globalUserId":null,"accountId":{"string":"60270350"},"encrypted":"NONE","platform":"DEFAULT","component So, if I understand, it search for "accountId":{"string":"[0-9]+ regex and fetch the number [0-9]+ represented by this \1 token in the sed syntxt Pay attention to this sort --human-numeric-sort Pay attention to this uniq as well

Sunday, February 23, 2020

Spring Mockito and injection


I had a UnitTest to create.
I wanted to check a bean class , with some logical code.

This bean class had an internal Autowired internal bean, that I didn't care of , didn't want to check .

So how to setup a test around the original class without having to setup the internal Autowired class ...


The @InjectMocks means that this is the main class that we want to test, where we inject into it, if possible , the other Mock.
The @Mock  means that we want to wrap the class and to control it from outside , without taking care of its internal code.

Important:
do not forget the call
        MockitoAnnotations.initMocks(this);
which activate the injection



Here is the example code :


mport org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

import java.util.ArrayList;
import java.util.List;

import static org.mockito.Matchers.anyLong;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.when;

public class ConsumerPrivateMessageConversationMessageDataConverterTest {


    @InjectMocks    ConversationMessageDataConverter conversationMessageDataConverter = new ConversationMessageDataConverter();


    @Mock    UserACItemRetriever userACItemRetriever;

    @BeforeClass    public void setMockOutput() throws AccountConfigClientException {
        MockitoAnnotations.initMocks(this);
        when(userACItemRetriever.getItem(anyString(), anyLong())).thenReturn(null);
    }

    @Test    public void checkPrivateMessageFiltering() {
        conversationMessageDataConverter.convertToConversationHistoryMessageData(conversationDTO);

    }
}




The ConversationMessageDataConverter class uses  inside its code the UserACItemRetriever class 

@Componentpublic class ConversationMessageDataConverter {

    @Autowired    private UserACItemRetriever userACItemRetriever;


    public void convertToConversationHistoryMessageData( .... )  {
    }

}

Adjustement: 
17 Jan 2021 : I just paid attention that there's a difference between 
@Mock and @MockBean 
If you want your instance to be wrapped as a Mock but also considered 
and injected as a bean, the, you should use:
@MockBean

Here for more info 
https://stackoverflow.com/questions/42641853/spring-boot-integration-testing-with-mocked-services-components

Thursday, November 21, 2019

Elastic Search - recovery of shards

In order to understand the status of the Elastic Cluster shard recovery (how many shards and in what percentage of data are still to be consumed by the elastic node):



watch -n 1 -d "curl -sS localhost:9200/_cat/recovery | grep -v done | sort"


curl -sS localhost:2013/_cat/recovery | grep -v done | sort
chat_events_2018_10        0  1080986 replica index    svpr-els219 svpr-els222 n/a n/a 99  99.0%  9245443931 99.4%  99  9245443931  0       100.0% 0
chat_events_2018_10        12 880628  replica index    svpr-els219 svpr-els225 n/a n/a 118 80.5%  9507834833 50.9%  118 9507834833  0       100.0% 0
chat_events_2018_10        4  1080998 replica index    svpr-els217 svpr-els222 n/a n/a 120 98.3%  9212348531 84.1%  120 9212348531  0       0.0%   549128
chat_events_2018_10        6  48448   gateway translog avpr-els217 avpr-els217 n/a n/a 0   100.0% 0          100.0% 120 9111543410  314413  -1.0%  -1
chat_events_2018_10        7  37318   gateway translog svpr-els239 svpr-els239 n/a n/a 0   100.0% 0          100.0% 119 9355121451  215907  -1.0%  -1
chat_events_2018_11        15 246460  replica index    svpr-els221 svpr-els230 n/a n/a 94  92.6%  7473306012 59.9%  94  7473306012  0       0.0%   207497
chat_events_2018_12        17 561707  replica index    svpr-els217 svpr-els225 n/a n/a 78  83.3%  5985100320 0.1%   78  5985100320  0       100.0% 0
chat_events_2019_01        10 403900  replica index    svpr-els222 svpr-els230 n/a n/a 162 68.5%  5824180424 0.3%   162 5824180424  0       0.0%   166305
chat_events_2019_02        1  377381  replica index    svpr-els222 svpr-els228 n/a n/a 154 72.1%  5509742229 0.2%   154 5509742229  0       0.0%   122191
chat_events_2019_02        16 561676  replica index    svpr-els220 svpr-els245 n/a n/a 150 95.3%  4684545993 80.1%  150 4684545993  0       0.0%   122191
chat_events_2019_03        3  936237  replica index    svpr-els217 svpr-els242 n/a n/a 158 75.9%  5212773307 7.8%   158 5212773307  0       0.0%   1527414

Sunday, October 6, 2019

lpnova - create OpenStack VM

Clone (clone server similar to avor-wto134 - 2 instances)
lpnova --clone avor-wto134 -H avor-wto -Q 2 -D virginia -U fawzea

in case of failure (because of F5 for ex , assuming avor-wto109 and 122 was created but failed in the middle) 

lpnova --clone avor-wto134 -H avor-wto109 -H avor-wto122   -D virginia -U fawzea --load 

Tuesday, September 24, 2019

Puppet sandbox


In order to check your puppet script in a sandox, go to any linux server and create the following directory structure:



Create dir


/tmp/mypuppet/


Under this directory 


./modules./modules/test./modules/test/templates./modules/test/templates/test.erb./modules/test/manifests./modules/test/manifests/init.pp



Here's your manifest: 
./test.pp

puppet apply --modulepath /tmp/mypuppet/modules test.pp

In my example , this was the manifest:

test.pp :
node qtvr-wto134 {class { 'test::config': }
} 

the modules modules/test/manifests/init.pp :


class test::config ($routingRulesList = ['zzffline1', 'zzffline2', 'zzffline3'],) {
file { "/home/michael_puppet_sandbox/mypuppet/locations.include":ensure => present,content => template("test/test.erb"),}
}

 and the template modules/test/templates/test.erb :
<% @routingRulesList.each do |routingRule| -%><%=routingRule%><% end %>


and then click on

 puppet apply --modulepath /tmp/mypuppet/modules .  test.pp 


The command puppet apply --modulepath /tmp/mypuppet/modules . test.pp  will create the following output file :



puppet apply --modulepath /tmp/mypuppet/modules . test.pp
zzffline1zzffline2zzffline3