Example usage for org.apache.commons.lang StringUtils defaultIfBlank

List of usage examples for org.apache.commons.lang StringUtils defaultIfBlank

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils defaultIfBlank.

Prototype

public static String defaultIfBlank(String str, String defaultStr) 

Source Link

Document

Returns either the passed in String, or if the String is whitespace, empty ("") or null, the value of defaultStr.

Usage

From source file:org.apache.sentry.provider.db.service.persistent.NotificationProcessor.java

/**
 * Processes "create database" notification event, and applies its corresponding
 * snapshot change as well as delta path update into Sentry DB.
 *
 * @param event notification event to be processed.
 * @throws Exception if encounters errors while persisting the path change
 *//*from  w ww  .  ja  v  a2 s .co m*/
private boolean processCreateDatabase(NotificationEvent event) throws Exception {
    SentryJSONCreateDatabaseMessage message = deserializer.getCreateDatabaseMessage(event.getMessage());
    String dbName = message.getDB();
    String location = message.getLocation();
    if ((dbName == null) || (location == null)) {
        LOGGER.warn("Create database event " + "has incomplete information. dbName: {} location: {}",
                StringUtils.defaultIfBlank(dbName, "null"), StringUtils.defaultIfBlank(location, "null"));
        return false;
    }

    if (syncStoreOnCreate) {
        dropSentryDbPrivileges(dbName, event);
    }

    if (hdfsSyncEnabled) {
        List<String> locations = Collections.singletonList(location);
        addPaths(dbName, locations, event);

        return true;
    }

    return false;
}

From source file:org.apache.sentry.provider.db.service.persistent.NotificationProcessor.java

/**
 * Processes "create table" notification event, and applies its corresponding
 * snapshot change as well as delta path update into Sentry DB.
 *
 * @param event notification event to be processed.
 * @throws Exception if encounters errors while persisting the path change
 *//*from   w  w w.  j a v a 2s  .c o m*/
private boolean processCreateTable(NotificationEvent event) throws Exception {
    SentryJSONCreateTableMessage createTableMessage = deserializer.getCreateTableMessage(event.getMessage());
    String dbName = createTableMessage.getDB();
    String tableName = createTableMessage.getTable();
    String location = createTableMessage.getLocation();
    if ((dbName == null) || (tableName == null) || (location == null)) {
        LOGGER.warn(String.format(
                "Create table event " + "has incomplete information."
                        + " dbName = %s, tableName = %s, location = %s",
                StringUtils.defaultIfBlank(dbName, "null"), StringUtils.defaultIfBlank(tableName, "null"),
                StringUtils.defaultIfBlank(location, "null")));
        return false;
    }
    if (syncStoreOnCreate) {
        dropSentryTablePrivileges(dbName, tableName, event);
    }

    if (hdfsSyncEnabled) {
        String authzObj = SentryServiceUtil.getAuthzObj(dbName, tableName);
        List<String> locations = Collections.singletonList(location);
        addPaths(authzObj, locations, event);
        return true;
    }

    return false;
}

From source file:org.apache.sentry.provider.db.service.persistent.NotificationProcessor.java

/**
 * Processes "drop table" notification event. It drops all partitions belongs to
 * the table as well. And applies its corresponding snapshot change as well
 * as delta path update into Sentry DB.//from  w ww.  jav  a  2 s . co  m
 *
 * @param event notification event to be processed.
 * @throws Exception if encounters errors while persisting the path change
 */
private boolean processDropTable(NotificationEvent event) throws Exception {
    SentryJSONDropTableMessage dropTableMessage = deserializer.getDropTableMessage(event.getMessage());
    String dbName = dropTableMessage.getDB();
    String tableName = dropTableMessage.getTable();
    if ((dbName == null) || (tableName == null)) {
        LOGGER.warn("Drop table event " + "has incomplete information. dbName: {}, tableName: {}",
                StringUtils.defaultIfBlank(dbName, "null"), StringUtils.defaultIfBlank(tableName, "null"));
        return false;
    }
    if (syncStoreOnDrop) {
        dropSentryTablePrivileges(dbName, tableName, event);
    }

    if (hdfsSyncEnabled) {
        String authzObj = SentryServiceUtil.getAuthzObj(dbName, tableName);
        removeAllPaths(authzObj, event);
        return true;
    }

    return false;
}

From source file:org.apache.sentry.provider.db.service.persistent.NotificationProcessor.java

/**
 * Processes "alter table" notification event, and applies its corresponding
 * snapshot change as well as delta path update into Sentry DB.
 *
 * @param event notification event to be processed.
 * @throws Exception if encounters errors while persisting the path change
 *///from w  ww.  j a v  a 2  s.c o  m
private boolean processAlterTable(NotificationEvent event) throws Exception {

    SentryJSONAlterTableMessage alterTableMessage = deserializer.getAlterTableMessage(event.getMessage());
    String oldDbName = alterTableMessage.getDB();
    String oldTableName = alterTableMessage.getTable();
    String newDbName = event.getDbName();
    String newTableName = event.getTableName();
    String oldLocation = alterTableMessage.getOldLocation();
    String newLocation = alterTableMessage.getNewLocation();

    if ((oldDbName == null) || (oldTableName == null) || (newDbName == null) || (newTableName == null)
            || (oldLocation == null) || (newLocation == null)) {
        LOGGER.warn(String.format(
                "Alter table notification ignored since event "
                        + "has incomplete information. oldDbName = %s, oldTableName = %s, oldLocation = %s, "
                        + "newDbName = %s, newTableName = %s, newLocation = %s",
                StringUtils.defaultIfBlank(oldDbName, "null"), StringUtils.defaultIfBlank(oldTableName, "null"),
                StringUtils.defaultIfBlank(oldLocation, "null"), StringUtils.defaultIfBlank(newDbName, "null"),
                StringUtils.defaultIfBlank(newTableName, "null"),
                StringUtils.defaultIfBlank(newLocation, "null")));
        return false;
    }

    if ((oldDbName.equals(newDbName)) && (oldTableName.equals(newTableName))
            && (oldLocation.equals(newLocation))) {
        LOGGER.debug(String.format(
                "Alter table notification ignored as neither name nor "
                        + "location has changed: oldAuthzObj = %s, oldLocation = %s, newAuthzObj = %s, "
                        + "newLocation = %s",
                oldDbName + "." + oldTableName, oldLocation, newDbName + "." + newTableName, newLocation));
        return false;
    }

    if (!newDbName.equalsIgnoreCase(oldDbName) || !oldTableName.equalsIgnoreCase(newTableName)) {
        // Name has changed
        try {
            renamePrivileges(oldDbName, oldTableName, newDbName, newTableName);
        } catch (SentryNoSuchObjectException e) {
            LOGGER.debug("Rename Sentry privilege ignored as there are no privileges on the table:" + " {}.{}",
                    oldDbName, oldTableName);
        } catch (Exception e) {
            LOGGER.info("Could not process Alter table event. Event: {}", event.toString(), e);
            return false;
        }
    }

    if (!hdfsSyncEnabled) {
        return false;
    }
    String oldAuthzObj = oldDbName + "." + oldTableName;
    String newAuthzObj = newDbName + "." + newTableName;
    renameAuthzPath(oldAuthzObj, newAuthzObj, oldLocation, newLocation, event);
    return true;
}

From source file:org.apache.sentry.provider.db.service.persistent.NotificationProcessor.java

/**
 * Processes "add partition" notification event, and applies its corresponding
 * snapshot change as well as delta path update into Sentry DB.
 *
 * @param event notification event to be processed.
 * @throws Exception if encounters errors while persisting the path change
 *//*from   w w  w  .  ja  va2 s .  com*/
private boolean processAddPartition(NotificationEvent event) throws Exception {
    if (!hdfsSyncEnabled) {
        return false;
    }

    SentryJSONAddPartitionMessage addPartitionMessage = deserializer.getAddPartitionMessage(event.getMessage());
    String dbName = addPartitionMessage.getDB();
    String tableName = addPartitionMessage.getTable();
    List<String> locations = addPartitionMessage.getLocations();
    if ((dbName == null) || (tableName == null) || (locations == null)) {
        LOGGER.warn(String.format(
                "Add partition event has incomplete information. "
                        + "dbName = %s, tableName = %s, locations = %s",
                StringUtils.defaultIfBlank(dbName, "null"), StringUtils.defaultIfBlank(tableName, "null"),
                locations != null ? locations.toString() : "null"));
        return false;
    }
    String authzObj = SentryServiceUtil.getAuthzObj(dbName, tableName);
    addPaths(authzObj, locations, event);
    return true;
}

From source file:org.apache.sentry.provider.db.service.persistent.NotificationProcessor.java

/**
 * Processes "drop partition" notification event, and applies its corresponding
 * snapshot change as well as delta path update into Sentry DB.
 *
 * @param event notification event to be processed.
 * @throws Exception if encounters errors while persisting the path change
 *//*from   w w w .  j av a2s. co  m*/
private boolean processDropPartition(NotificationEvent event) throws Exception {
    if (!hdfsSyncEnabled) {
        return false;
    }

    SentryJSONDropPartitionMessage dropPartitionMessage = deserializer
            .getDropPartitionMessage(event.getMessage());
    String dbName = dropPartitionMessage.getDB();
    String tableName = dropPartitionMessage.getTable();
    List<String> locations = dropPartitionMessage.getLocations();
    if ((dbName == null) || (tableName == null) || (locations == null)) {
        LOGGER.warn(String.format(
                "Drop partition event "
                        + "has incomplete information. dbName = %s, tableName = %s, location = %s",
                StringUtils.defaultIfBlank(dbName, "null"), StringUtils.defaultIfBlank(tableName, "null"),
                locations != null ? locations.toString() : "null"));
        return false;
    }
    String authzObj = SentryServiceUtil.getAuthzObj(dbName, tableName);
    removePaths(authzObj, locations, event);
    return true;
}

From source file:org.apache.sentry.provider.db.service.persistent.NotificationProcessor.java

/**
 * Processes "alter partition" notification event, and applies its corresponding
 * snapshot change as well as delta path update into Sentry DB.
 *
 * @param event notification event to be processed.
 * @throws Exception if encounters errors while persisting the path change
 */// ww  w  .ja  v a2  s .c  o m
private boolean processAlterPartition(NotificationEvent event) throws Exception {
    if (!hdfsSyncEnabled) {
        return false;
    }

    SentryJSONAlterPartitionMessage alterPartitionMessage = deserializer
            .getAlterPartitionMessage(event.getMessage());
    String dbName = alterPartitionMessage.getDB();
    String tableName = alterPartitionMessage.getTable();
    String oldLocation = alterPartitionMessage.getOldLocation();
    String newLocation = alterPartitionMessage.getNewLocation();

    if ((dbName == null) || (tableName == null) || (oldLocation == null) || (newLocation == null)) {
        LOGGER.warn(String.format(
                "Alter partition event " + "has incomplete information. dbName = %s, tableName = %s, "
                        + "oldLocation = %s, newLocation = %s",
                StringUtils.defaultIfBlank(dbName, "null"), StringUtils.defaultIfBlank(tableName, "null"),
                StringUtils.defaultIfBlank(oldLocation, "null"),
                StringUtils.defaultIfBlank(newLocation, "null")));
        return false;
    }

    if (oldLocation.equals(newLocation)) {
        LOGGER.debug(String.format(
                "Alter partition notification ignored as"
                        + "location has not changed: AuthzObj = %s, Location = %s",
                dbName + "." + "." + tableName, oldLocation));
        return false;
    }

    String oldAuthzObj = dbName + "." + tableName;
    renameAuthzPath(oldAuthzObj, oldAuthzObj, oldLocation, newLocation, event);
    return true;
}

From source file:org.apache.sentry.service.thrift.NotificationProcessor.java

/**
 * Processes "create database" notification event, and applies its corresponding
 * snapshot change as well as delta path update into Sentry DB.
 *
 * @param event notification event to be processed.
 * @throws Exception if encounters errors while persisting the path change
 *///from  w  w  w.j  av a 2 s.c  o m
private boolean processCreateDatabase(NotificationEvent event) throws Exception {
    SentryJSONCreateDatabaseMessage message = deserializer.getCreateDatabaseMessage(event.getMessage());
    String dbName = message.getDB();
    String location = message.getLocation();
    if ((dbName == null) || (location == null)) {
        LOGGER.error("Create database event " + "has incomplete information. dbName: {} location: {}",
                StringUtils.defaultIfBlank(dbName, "null"), StringUtils.defaultIfBlank(location, "null"));
        return false;
    }

    if (syncStoreOnCreate) {
        dropSentryDbPrivileges(dbName, event);
    }

    if (hdfsSyncEnabled) {
        List<String> locations = Collections.singletonList(location);
        addPaths(dbName, locations, event);

        return true;
    }

    return false;
}

From source file:org.apache.sentry.service.thrift.NotificationProcessor.java

/**
 * Processes "create table" notification event, and applies its corresponding
 * snapshot change as well as delta path update into Sentry DB.
 *
 * @param event notification event to be processed.
 * @throws Exception if encounters errors while persisting the path change
 *//*  www .ja  v  a 2s .  co  m*/
private boolean processCreateTable(NotificationEvent event) throws Exception {
    SentryJSONCreateTableMessage createTableMessage = deserializer.getCreateTableMessage(event.getMessage());
    String dbName = createTableMessage.getDB();
    String tableName = createTableMessage.getTable();
    String location = createTableMessage.getLocation();
    if ((dbName == null) || (tableName == null) || (location == null)) {
        LOGGER.error(String.format(
                "Create table event " + "has incomplete information."
                        + " dbName = %s, tableName = %s, location = %s",
                StringUtils.defaultIfBlank(dbName, "null"), StringUtils.defaultIfBlank(tableName, "null"),
                StringUtils.defaultIfBlank(location, "null")));
        return false;
    }
    if (syncStoreOnCreate) {
        dropSentryTablePrivileges(dbName, tableName, event);
    }

    if (hdfsSyncEnabled) {
        String authzObj = SentryServiceUtil.getAuthzObj(dbName, tableName);
        List<String> locations = Collections.singletonList(location);
        addPaths(authzObj, locations, event);
        return true;
    }

    return false;
}

From source file:org.apache.sentry.service.thrift.NotificationProcessor.java

/**
 * Processes "drop table" notification event. It drops all partitions belongs to
 * the table as well. And applies its corresponding snapshot change as well
 * as delta path update into Sentry DB./*from  w w  w.  j  a v  a 2s  . c  o m*/
 *
 * @param event notification event to be processed.
 * @throws Exception if encounters errors while persisting the path change
 */
private boolean processDropTable(NotificationEvent event) throws Exception {
    SentryJSONDropTableMessage dropTableMessage = deserializer.getDropTableMessage(event.getMessage());
    String dbName = dropTableMessage.getDB();
    String tableName = dropTableMessage.getTable();
    if ((dbName == null) || (tableName == null)) {
        LOGGER.error("Drop table event " + "has incomplete information. dbName: {}, tableName: {}",
                StringUtils.defaultIfBlank(dbName, "null"), StringUtils.defaultIfBlank(tableName, "null"));
        return false;
    }
    if (syncStoreOnDrop) {
        dropSentryTablePrivileges(dbName, tableName, event);
    }

    if (hdfsSyncEnabled) {
        String authzObj = SentryServiceUtil.getAuthzObj(dbName, tableName);
        removeAllPaths(authzObj, event);
        return true;
    }

    return false;
}