Content

Saturday, October 27, 2018

How to setup a new Angular 7 app on GitHub.com?

This consists of three steps

Step 1: Create the repository on GitHub.com

  1. Login to your Github.com account
  2. Go to the repositories list https://github.com/[yourhandle]?tab=repositories
  3. Click on New Repository
  4. Give a name example tourofheroes-app
  5. Select private or public if you have a paid account.
  6. Do not select Initialize this repository with a README (The default selection). The reason being Angular would generate this file and we would be adding this from local computer


Step 2: Creating the angular app on local computer


  1. Make sure that Angular CLI is installed as described in article How to install Angular 7 CLI?
  2. Go to the folder location you want to create your application
  3. Issue the Angular Cli command for initializing the application
  4. ng new tourofheroes-app --routing --style scss
  5. To keep this flow simple, do not change any files as of now


Step 3: Pushing these changes to GitHub.com

  1. Go to inside the folder created in Step2 namely "tourofheroes-app" cd tourofheroes-app
  2. Attach the remote GitHub.com repository that we have created 
  3. git remote add origin https://github.com/[yourhandle]/tourofheroes-app.git
  4. Push the changes to the remote Github.com repository
  5. git push origin master
  6. If the GitHub.com credentials are not setup before, it would ask for the username and password. Do enter the same
If you now go to your GitHub.com repository you would find the ReadMe etc all populated.


Note: This assume that you have setup your GitHub.com credentials previously to be able to interact with GitHub.com using command line.

How to install Angular 7 CLI?

In the new version of Angular 7, the CLI (Command Line Interface) is changed from "angular-cli" to "@angular/cli". So the correct command to install the CLI is


npm install -g @angular/cli

This would install latest stable release of Angular

Warning: do not issue a npm install -g angular-cli@latest This would install the latest version which could be beta of the older angular-cli and not @angular/cli.

Once done issue the following to verify the version to be 7
ng version
Note the version (as of this writing 7.0.3)



How to update git credentials after changing GitHub.com password?

Once you have changed your password in GitHub.com do the following in the git command line

You would notice that existing git pushing don't work and you would get a fatal error.
The command to execute is
 git config --global credential.helper osxkeychain 

The flow would be as follows, once you get the error issue this command and then try pushing to GitHub.com, it would now prompt the credentials again to be updated.

$ git push origin master remote: 
Invalid username or password. fatal: Authentication failed for 'https://github.com/[yourhandle]/[yourrepository].git/' 

$ git config --global credential.helper osxkeychain 
$ git push origin master 
Username for 'https://github.com': [yourhandle] 
Password for 'https://[yourhandle]@github.com':

Sunday, September 30, 2018

How to configure GitHub for first time use?

Github.com is an online enhanced version of Git.

Git is locally installed in each of your work stations. This is then used as a client connecting to the server version of git which is GitHub.com

In a way what you are doing is like an offline web application, you do all the work in your local computer and when you are done with the work, you sync up with the server. There is no need for Internet connection etc.

Git is usually installed in your laptop either by installed XCode in Mac


Go GitHub.com and register an account for yourself. It can range from a free account, a private account or a company account. The various description are given in GitHub.com

Once done on your laptop do the following

## This is required for making sure that all your commits done on a repository have the correct name
git config --global user.name "<Your GitHub.com Handle>"
git config --global user.email "<Your Email Address used for registering to GitHub.com"


## Create a new repository called GitHubHelloWorld in GitHub Online
## Create a Directory on the local computer
mkdir GitHubHelloWorld

move to the directory and give the following command
git init

# create a new file
readme.txt and edit the text

# add the file to git
git add readme.txt

# commit the file
git commit -m "Add readme.txt"

# Add a remote origin in preparation for pushing to GitHub.com.
# You need to add this only once
git remote add origin https://github.com/<youruseraccount>/GitHubHelloWorld.git

# Push the changes to GitHub.com under master. More on this later on the branching strategy
git push origin master


# Some useful commands
# Find all the files which are changed in Local which is not synced up with server
git status

# Short cut to add all files to git for the changes
git add --all

# Commit all the files
git commit -am "Initial Setup of Maven Project"


# If you don't want certain files to be in the repository, you need to add a .ignore file. This file would have the extensions or the file pattern you need to exclude from source control



Saturday, November 11, 2017

How to read an Apache Storm 1.0.2 Kafka Spout Zookeeper offset?

As with any streaming systems, the consumers namely the Kafka Spout need to keep track up to which message identifier has been read in Kafka topic. The reason this needs to be persisted is if we do need to restart the topology and the spout restarts, it needs to know from where it needs to start reading from else it would start from the beginning. In order to prevent this from happening Storm Kafka spout allows once to persist the offset in Zookeeper and would automatically read it when the Topology restarts.

In order to find this information,  we need to login to the Zookeeper Command Line Shell.
cd /usr/local/zookeeper/zookeeper-3.4.9

bin/zkCli.sh -server zookeeper1:2181

Check the topic and its partition for the consumer, your need to type in your topicname and if you have more than 1 partition make sure you do this to every partition

get /consumers/yourcompany/yourtopicname/partition_0

Sample response

{"topology":{"id":"YourTopologyInstanceId-1-1497152721","name":"YourTopologyName"},"offset":3673,"partition":0,"broker":{"host":"81387110753b","port":9092},"topic":"yourTopicName"}

The offset:3673 says up to which offset the Kafka spout has read from this topic's partition 0.


Configure how long a message is kept in Kafka 0.10. 1.0 topic?

Sometime, due to disk size issues or just the fact that we don't want old messages in Kafka, one might need to clear these messages in Kafka topic automatically.

Please note, as of the current writing Kafka is not clever enough to clear messages once they are read by any one consumer. This needs to be done manually by the User. So do make sure that you have a setting that fits your purpose. i.e your consumers should be able to read it before the message is deleted from Kafka. Once a message is deleted from Kafka there is no way to get it back.

The current default for Kafka messages in a Topic is 7 Days.

Here we are changing this to 1 day.

cd /usr/local/kafka/kafka_2.11-0.10.1.0/bin

./kafka-topics.sh --zookeeper zookeeper1:2181 --alter --topic yourtopicname --config retention.ms=86400000

How to clear all messages in Kafka 0.10.1.0 topic without deleting the topic?

Sometime, the messages in Kafka topic would be overwhelming and we need a quick way to clear these messages without deleting the topic.

Note deleting the topic is an option that should be used with caution in Production.

Kafka topics by default have a concept of retention, i.e how long a message in a topic needs to be persisted. By default this setting is 7 days. We are going to make use of this to clear the messages in the topic.

We are going to set the retention to 1 second and then bring it back to 7 days. Login to the Kafka directory and go to the folder location where Kafka is installed.


cd /usr/local/kafka/kafka_2.11-0.10.1.0/bin

./kafka-topics.sh --zookeeper zookeeper1:2181 --alter --topic yourtopicname --config retention.ms=1000


Wait for some time so that the messages are cleared. Check if there are any messages by reading from the topic from the beginning

 bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic yourtopicname --from-beginning 

Make sure that you reset the timing to the original 7 days

Important Please do not forget to do this step, else all your messages in Kafka would be deleted after 1 second delay.

cd /usr/local/kafka/kafka_2.11-0.10.1.0/bin

./kafka-topics.sh --zookeeper zookeeper1:2181 --alter --topic yourtopicname --config retention.ms=604800000