Skip to content

Commit

Permalink
Change for kerberos
Browse files Browse the repository at this point in the history
  • Loading branch information
amarflybot committed Apr 26, 2017
1 parent c60de7b commit 33f7376
Show file tree
Hide file tree
Showing 16 changed files with 283 additions and 189 deletions.
22 changes: 22 additions & 0 deletions help.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Success! Kerberos is now running. You can enable Kerberos in a Cloudera Manager
cluster from the drop-down menu for that cluster on the CM home page. It will
ask you to confirm that this script performed the following steps:

* set up a working KDC.
* checked that the KDC allows renewable tickets.
* installed the client libraries.
* created a proper account for Cloudera Manager.

Then, it will prompt you for the following details (accept defaults if not
specified here):

KDC Type: MIT KDC
KDC Server Host: quickstart.cloudera
Kerberos Security Realm: CLOUDERA

Later, it will prompt you for KDC account manager credentials:

Username: cloudera-scm/admin (@ CLOUDERA)
Password: cloudera

[cloudera@quickstart ~]$
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,12 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-common</artifactId>
<version>2.6.0-cdh5.8.0</version>
</dependency>
</dependencies>

<build>
Expand Down
46 changes: 46 additions & 0 deletions src/main/java/com/example/AppConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,64 @@



import org.apache.hadoop.security.UserGroupInformation;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.JdbcTemplate;

import javax.sql.DataSource;
import java.io.IOException;

/**
* Created by amarendra on 21/4/17.
*/
@Configuration
public class AppConfig {

@Value("${bigdata.impala.connectionURL}")
private String connectionURL;

@Value("${bigdata.impala.username}")
private String userName;

@Value("${bigdata.impala.password}")
private String password;

@Value("${bigdata.kerberos.keyTabLocation}")
private String keyTabLocation;

@Value("${bigdata.kerberos.krb5Location}")
private String krb5Location;

@Value("${bigdata.kerberos.jaasLocation}")
private String jaasLocation;

@Value("${mobigdataurya.kerberos.priniciple}")
private String priniciple;

@Bean
public DataSource dataSource() throws IOException {
System.setProperty("javax.security.auth.useSubjectCredsOnly", "true");
System.setProperty("java.security.krb5.conf", "/Users/amarendra/IdeaProjects/spring-boot-impala/src/main/resources/krb5.conf");
System.setProperty("java.security.auth.login.config","/Users/amarendra/IdeaProjects/spring-boot-impala/src/main/resources/jaas.conf");
//System.setProperty("java.security.krb5.conf", krb5Location);
//System.setProperty("java.security.auth.login.config", jaasLocation);
org.apache.hadoop.conf.Configuration conf = new org.apache.hadoop.conf.Configuration();
conf.set("hadoop.security.authentication", "kerberos");
UserGroupInformation.setConfiguration(conf);
UserGroupInformation.loginUserFromKeytab("impala/quickstart.cloudera@CLOUDERA", "/Users/amarendra/IdeaProjects/spring-boot-impala/src/main/resources/impala.keytab");
//UserGroupInformation.loginUserFromKeytab(priniciple, keyTabLocation);



com.cloudera.impala.jdbc41.DataSource dataSource =
new com.cloudera.impala.jdbc41.DataSource();
dataSource.setURL(connectionURL);

return dataSource;
}

@Bean
JdbcTemplate jdbcTemplate(final DataSource dataSource){
return new JdbcStream(dataSource);
Expand Down
18 changes: 7 additions & 11 deletions src/main/java/com/example/JdbcStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,6 @@ public boolean hasNext() {

@Override
public SqlRow next() {
ResultSetWrappingSqlRowSet resultSetWrappingSqlRowSet = (ResultSetWrappingSqlRowSet) rowSet;
S41ForwardResultSet resultSet = (S41ForwardResultSet) resultSetWrappingSqlRowSet.getResultSet();
boolean closed = false;
try {
closed = resultSet.isClosed();
} catch (SQLException e) {
e.printStackTrace();
}
if (closed) {
throw new NoSuchElementException();
}
return sqlRow;
}
}, Spliterator.IMMUTABLE);
Expand All @@ -123,6 +112,8 @@ public interface SqlRow {
String getString(String columnLabel);

Timestamp getTimestamp(String columnLabel);

Float getFloat(String columnLabel);
}

public class SqlRowAdapter implements SqlRow {
Expand All @@ -146,5 +137,10 @@ public String getString(String columnLabel) {
public Timestamp getTimestamp(String columnLabel) {
return sqlRowSet.getTimestamp(columnLabel);
}

@Override
public Float getFloat(String columnLabel) {
return sqlRowSet.getFloat(columnLabel);
}
}
}
57 changes: 57 additions & 0 deletions src/main/java/com/example/WebLog.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package com.example;

import java.io.Serializable;
import java.sql.Date;

/**
* Created by amarendra on 14/04/17.
*/
public class WebLog implements Serializable{

private String city;
private String osFamily;
private Float latitude;
private Float longitude;

public String getCity() {
return city;
}

public void setCity(String city) {
this.city = city;
}

public String getOsFamily() {
return osFamily;
}

public void setOsFamily(String osFamily) {
this.osFamily = osFamily;
}

public Float getLatitude() {
return latitude;
}

public void setLatitude(Float latitude) {
this.latitude = latitude;
}

public Float getLongitude() {
return longitude;
}

public void setLongitude(Float longitude) {
this.longitude = longitude;
}

@Override
public String toString() {
return "WebLog{" +
"city='" + city + '\'' +
", osFamily='" + osFamily + '\'' +
", latitude=" + latitude +
", longitude=" + longitude +
'}';
}
}
27 changes: 27 additions & 0 deletions src/main/java/com/example/WebLogMapper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.example;

import java.sql.Date;
import java.sql.Timestamp;

/**
* Created by amarendra on 14/04/17.
*/
public class WebLogMapper {

public static WebLog mapWebLog(JdbcStream.SqlRow sqlRow){

WebLog webLog = new WebLog();
String city = sqlRow.getString("city");
String osFamily = sqlRow.getString("os_family");
Float latitude = sqlRow.getFloat("latitude");
Float longitude = sqlRow.getFloat("longitude");

webLog.setCity(city);
webLog.setOsFamily(osFamily);
webLog.setLatitude(latitude);
webLog.setLongitude(longitude);

return webLog;

}
}
94 changes: 0 additions & 94 deletions src/main/java/com/example/WebStat.java

This file was deleted.

9 changes: 4 additions & 5 deletions src/main/java/com/example/WebStatDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.google.gson.Gson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.util.Assert;

import java.io.PrintWriter;
import java.sql.SQLException;
Expand All @@ -27,17 +26,17 @@ public void getStreamingOutputForSql(String sql, Object[] args, PrintWriter writ
.stream()
.forEach(sqlRow -> {
try {
WebStat webStat = WebStatMapper.mapWebStat(sqlRow);
WebLog webLog = WebLogMapper.mapWebLog(sqlRow);
if (first[0]) {
writer.write(",");
}
first[0] = true;
writer.write(gson.toJson(webStat));
writer.write(gson.toJson(webLog));
writer.flush();
//TimeUnit.MILLISECONDS.sleep(500);
//return webStat;
//return webLog;
} catch (RuntimeException e) {
throw new RuntimeException("Cannot convert SqlRom to WebStat");
throw new RuntimeException("Cannot convert SqlRom to WebLog");
}
});
} catch (SQLException e) {
Expand Down
Loading

0 comments on commit 33f7376

Please sign in to comment.