The DB Hack – Ambari Delete or Remove Service

A while back I discussed how you can Delete or Remove service from Ambari. The process involved the use of Ambari API to Delete or Remove the target service in question. In this article, we will dive into the other side of Ambari interface – the database. But first let’s get an overview of Apache Ambari.

Apache Ambari Overview

Apache Ambari is a framework which is able to provision, manage and monitor Apache Hadoop deployments. It provides easy-to-use web interface and is bundled with a collection of rich RESTful APIs.

Having said the above – I would like to add that Apache Ambari however, isn’t limited to Apache Hadoop. It can be extended to other horizons. We have a few such custom implementations which scale beyond the Hadoop ecosystem.

Apache Ambari Project

Ambari DB Implementations

By default, Apache Ambari uses PostgreSQL (Embedded) to store it’s data. There are other options which includes Oracle, MySQL, PostgreSQL and more.

I will provide the details which will be specific to PostgreSQL & MySQL only.

Note: Before we begin I would highly recommend ensuring that you have the latest backup for Ambari database. This certainly is a “dirty” method – which is NOT recommended on a production grade system. You may proceed by taking into account the risks involved.

Delete or Remove Service from Ambari Database – PostgreSQL

Let’s get into the process.

It is a good practice to stop Ambari server before we start making changes to the actual database. Once you stop Ambari server, you can proceed with connecting the the Ambari Database. I will proceed with the required SQL. To make things easier to explain with an example, I will be removing Storm from my test cluster.

The upcoming SQL queries are aimed at removing Storm. You will have to modify the SQL to target the components or service in your case.

Quick note – I highly recommend using Transactions while working in PostgreSQL. I do the same when I am making any changes to the database in PostgreSQL.

ALTER TABLE clusterservices DISABLE TRIGGER ALL;
ALTER TABLE servicecomponentdesiredstate DISABLE TRIGGER ALL;
DELETE FROM servicedesiredstate WHERE service_name = ‘STORM’;
DELETE FROM servicecomponentdesiredstate WHERE service_name = ‘STORM’;
DELETE FROM clusterservices WHERE service_name = ‘STORM’;
DELETE FROM hostcomponentstate WHERE service_name = ‘STORM’;
DELETE FROM hostcomponentdesiredstate WHERE service_name = ‘STORM’;
ALTER TABLE clusterservices ENABLE TRIGGER ALL;
ALTER TABLE servicecomponentdesiredstate ENABLE TRIGGER ALL;

Once you are done executing these SQLs, verify that there isn’t any reference for the target service. If everything looks good to you then proceed and commit the transaction.

After you are done with the changes you can go ahead and start Ambari server. Your target service/component is no longer available in Ambari interface now.

Delete or Remove Service from Ambari Database – MySQL

Let’s dig into the MySQL world for Ambari.

MySQL – as we know – provides an easy-to-use RDBMS solution. Although MySQL isn’t a highly compliant and reliable RDBMS solution when you compare it with an objective-RDBMS solution like PostgreSQL (which also happens to SQL compliant & extensible). But the ease-of-use and read heavy SQL transactions make MySQL a good candidate.

Follow the same process where you will stop Ambari server and then connect to the database to make changes.

Once you are ready you can run the following SQL queries to remove the service or component (which in this case happens to be Storm).

DELETE FROM servicedesiredstate WHERE service_name = ‘STORM’;
DELETE FROM servicecomponentdesiredstate WHERE service_name = ‘STORM’;
DELETE FROM clusterservices WHERE service_name = ‘STORM’;
DELETE FROM hostcomponentstate WHERE service_name = ‘STORM’;
DELETE FROM hostcomponentdesiredstate WHERE service_name = ‘STORM’;

Verify that the component or service is removed from the tables. After you verify you can start Ambari server.

Ambari Delete or Remove Service – Considerations

The above process will help you delete or remove service or component from Ambari. They will however, not perform a complete cleanup of the packages for you.

If you prefer to clean up things completely, you might want to manually go to each of the node in question and remove the packages manually.

1 Comment

Post a Comment

Time limit is exhausted. Please reload CAPTCHA.