Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to datastax java driver and Spring 4 and also Java 8 code #938

Open
wants to merge 51 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
97611c9
The updates is made to support Spring 4.2.3 and Spring security 4.0.3
whelan Nov 20, 2015
d912bfa
fetches have been checked
whelan Nov 20, 2015
34f7543
Merge branch 'master' of https://github.com/lnorregaard/tatami
whelan Nov 20, 2015
87d3a13
Added datastax java driver to pom file
lnorregaard Nov 20, 2015
1475ce6
Added Spring data configuration to replace all CRUD methods
lnorregaard Nov 20, 2015
0d8080f
Prepared for adding the datastax into the repositories
lnorregaard Nov 20, 2015
8e4656f
Removed Hector api and replace with datastax. Still needs a lot of work
lnorregaard Nov 25, 2015
749775a
TimelineService is being fixed
lnorregaard Nov 25, 2015
92a111b
Fixed test dataset. Still missing some tables
lnorregaard Nov 25, 2015
29a40fd
Added new tables to create-tables
lnorregaard Nov 25, 2015
8b2a495
Fixed StatusDeletionTest to run all tests
lnorregaard Nov 27, 2015
55bbdbf
All service tests works, but still needs to migrate some services
lnorregaard Nov 29, 2015
d75772a
Fixed GroupController with new GroupId
lnorregaard Nov 29, 2015
5c2651a
Replaced the last cassandra code in TimelineRepository and also the a…
lnorregaard Nov 30, 2015
b5c67c9
Removed old commented out cassandra code
lnorregaard Nov 30, 2015
9c44362
Replaced Cassandra code for AppleDeviceRepository
lnorregaard Nov 30, 2015
4bdfeb2
Replaced Cassandra code for AttachmentRepository
lnorregaard Nov 30, 2015
c5dce8a
Replaced Cassandra code for FavoriteLine
lnorregaard Nov 30, 2015
52af1c4
Removed not needed class cast
lnorregaard Nov 30, 2015
f481ff0
Replaced Cassandra code for GroupCounter
lnorregaard Nov 30, 2015
41e1a06
Replaced Cassandra code for GroupDetails
lnorregaard Nov 30, 2015
cc12830
Replaced Cassandra code for Idempotent
lnorregaard Nov 30, 2015
ca9ea14
Replaced Cassandra code for Registration
lnorregaard Nov 30, 2015
d8b321e
Replaced Cassandra code for Registration
lnorregaard Nov 30, 2015
79c1c50
Replaced Cassandra code for Rss
lnorregaard Nov 30, 2015
bce01e5
Replaced Cassandra code for Shares
lnorregaard Nov 30, 2015
b7c93e7
Replaced Cassandra code for StatusAttachments
lnorregaard Nov 30, 2015
987701e
Replaced Cassandra code for TagCounter
lnorregaard Nov 30, 2015
48ea34e
Replaced Cassandra code for Userline
lnorregaard Nov 30, 2015
f535bba
Replaced Cassandra code for UserAttachment
lnorregaard Nov 30, 2015
a079301
Replaced Cassandra code for Status
lnorregaard Nov 30, 2015
fd73068
Fixed all test cases
lnorregaard Nov 30, 2015
00b4751
Test
lnorregaard Dec 1, 2015
bb651ca
Fixed tatami starts
lnorregaard Dec 1, 2015
140aac7
Optimised test runs
lnorregaard Dec 1, 2015
0d5e80b
Removed commented code
lnorregaard Dec 1, 2015
341aab3
Fixed group tests
lnorregaard Dec 2, 2015
7e58fe8
Updated load cql
lnorregaard Dec 2, 2015
ee4bb0e
Attachments saved
lnorregaard Dec 2, 2015
2dc859b
Attachments and avatar saved
lnorregaard Dec 2, 2015
93e7536
Same avatar for multiple users based on same image URL
lnorregaard Dec 2, 2015
76eb7b0
Added swagger and added possibility to use url for avatar instead
lnorregaard Dec 2, 2015
579e763
Added swagger and added possibility to use url for avatar instead
lnorregaard Dec 2, 2015
0274d60
Removed the not needed bower files
lnorregaard Dec 2, 2015
648a870
Updated with index
lnorregaard Dec 3, 2015
298f575
Fixed avatar Service
lnorregaard Dec 3, 2015
cdbd97d
Fixed error
lnorregaard Dec 3, 2015
a73ef18
Fixed problem with index creation
lnorregaard Dec 3, 2015
85bdbd9
Fixed some more CQL problems
lnorregaard Dec 4, 2015
02fda5c
Fixed problem with share status
lnorregaard Dec 7, 2015
3172ee6
Merge branch 'adminAccess'
lnorregaard Dec 7, 2015
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
401 changes: 211 additions & 190 deletions pom.xml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
package fr.ippon.tatami.config;

import org.apache.thrift.transport.TTransportException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.*;
import org.springframework.core.env.Environment;
import org.springframework.http.ResponseEntity;
import org.springframework.util.StopWatch;
import org.springframework.web.bind.annotation.RequestMethod;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

import javax.annotation.PostConstruct;
import javax.inject.Inject;
import javax.servlet.ServletContext;
import java.io.IOException;
import java.time.LocalDate;
import java.util.Date;

import static springfox.documentation.builders.PathSelectors.regex;

@Configuration
@PropertySource({"classpath:/META-INF/tatami/tatami.properties",
Expand All @@ -32,6 +44,40 @@ public class ApplicationConfiguration {
@Inject
private Environment env;

public static final String DEFAULT_INCLUDE_PATTERN = "/tatami/.*";

@Bean
public Docket swaggerSpringfoxDocket() {
log.debug("Starting Swagger");
StopWatch watch = new StopWatch();
watch.start();
ApiInfo apiInfo = new ApiInfo(
env.getProperty("swagger.title"),
env.getProperty("swagger.description"),
env.getProperty("swagger.version"),
env.getProperty("swagger.termsOfServiceUrl"),
env.getProperty("swagger.contact"),
env.getProperty("swagger.license"),
env.getProperty("swagger.licenseUrl"));

Docket docket = new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo)
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build()
.directModelSubstitute(LocalDate.class,
String.class)
.genericModelSubstitutes(ResponseEntity.class)
.useDefaultResponseMessages(false)
.enableUrlTemplating(true)
.pathMapping("/tatami");
watch.stop();
log.debug("Started Swagger in {} ms", watch.getTotalTimeMillis());
return docket;
}


/**
* Initializes Tatami.
* <p/>
Expand All @@ -43,7 +89,7 @@ public class ApplicationConfiguration {
* - "tatamibot" : for enabling the Tatami bot
*/
@PostConstruct
public void initTatami() throws IOException, TTransportException {
public void initTatami() throws IOException {
log.debug("Looking for Spring profiles... Available profiles are \"metrics\", \"tatamibot\" and \"apple-push\"");
if (env.getActiveProfiles().length == 0) {
log.debug("No Spring profile configured, running with default configuration");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import fr.ippon.tatami.service.elasticsearch.ElasticsearchSearchService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;
import org.springframework.aop.interceptor.SimpleAsyncUncaughtExceptionHandler;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.AsyncConfigurer;
Expand Down Expand Up @@ -37,4 +39,9 @@ public Executor getAsyncExecutor() {
executor.initialize();
return executor;
}

@Override
public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() {
return new SimpleAsyncUncaughtExceptionHandler();
}
}
821 changes: 709 additions & 112 deletions services/src/main/java/fr/ippon/tatami/config/CassandraConfiguration.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ private ColumnFamilyKeys() {

public static final String USER_CF = "User";

public static final String FRIENDS_CF = "Friends";
public static final String FRIENDS = "friends";

public static final String FOLLOWERS_CF = "Followers";

Expand All @@ -25,13 +25,13 @@ private ColumnFamilyKeys() {

public static final String FAVLINE_CF = "Favline";

public static final String TAGLINE_CF = "Tagline";
public static final String TAGLINE = "Tagline";

public static final String TIMELINE_CF = "Timeline";

public static final String TIMELINE_SHARES_CF = "TimelineShares";

public static final String MENTIONLINE_CF = "Mentionline";
public static final String MENTIONLINE = "mentionLine";

public static final String USERLINE_CF = "Userline";

Expand Down Expand Up @@ -67,7 +67,7 @@ private ColumnFamilyKeys() {

public static final String GROUP_COUNTER_CF = "GroupCounter";

public static final String GROUPLINE_CF = "Groupline";
public static final String GROUPLINE = "Groupline";

public static final String TATAMIBOT_DUPLICATE_CF = "TatamiBotDuplicate";

Expand All @@ -79,7 +79,7 @@ private ColumnFamilyKeys() {

public static final String DOMAIN_CONFIGURATION_CF = "DomainConfiguration";

public static final String DOMAINLINE_CF = "Domainline";
public static final String DOMAINLINE = "domainLine";

public static final String DOMAIN_TATAMIBOT_CF = "DomainTatamibot";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.springframework.web.servlet.view.JstlView;
import org.springframework.web.servlet.view.UrlBasedViewResolver;
import org.springframework.web.servlet.view.json.MappingJackson2JsonView;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;
Expand All @@ -34,6 +35,7 @@
@Configuration
@ComponentScan("fr.ippon.tatami.web")
@EnableWebMvc
@EnableSwagger2
@PropertySource({"classpath:/META-INF/tatami/tatami.properties",
"classpath:/META-INF/tatami/customization.properties"})
@ImportResource("classpath:META-INF/spring/applicationContext-metrics.xml")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import fr.ippon.tatami.config.metrics.CassandraHealthCheck;
import fr.ippon.tatami.config.metrics.JavaMailHealthCheck;
import fr.ippon.tatami.service.MailService;
import me.prettyprint.hector.api.Keyspace;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Configuration;
Expand All @@ -23,8 +22,8 @@ public class MetricsConfiguration {
@Inject
private Environment env;

@Inject
private Keyspace keyspaceOperator;
// @Inject
// private Keyspace keyspaceOperator;

@Inject
private MailService mailService;
Expand All @@ -33,7 +32,7 @@ public class MetricsConfiguration {
public void initMetrics() {
if (env.acceptsProfiles(Constants.SPRING_PROFILE_METRICS)) {
log.debug("Initializing Metrics healthchecks");
HealthChecks.register(new CassandraHealthCheck(keyspaceOperator));
// HealthChecks.register(new CassandraHealthCheck(keyspaceOperator));
HealthChecks.register(new JavaMailHealthCheck(mailService));

String graphiteHost = env.getProperty("tatami.metrics.graphite.host");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,37 +1,46 @@
package fr.ippon.tatami.config.metrics;

import com.yammer.metrics.core.HealthCheck;
import me.prettyprint.cassandra.serializers.StringSerializer;
import me.prettyprint.hector.api.Keyspace;
import me.prettyprint.hector.api.exceptions.HectorException;

import static fr.ippon.tatami.config.ColumnFamilyKeys.DOMAIN_CF;
import static me.prettyprint.hector.api.factory.HFactory.createRangeSlicesQuery;

/**
* Metrics HealthCheck for Cassandra.
*/
public class CassandraHealthCheck extends HealthCheck {

private final Keyspace keyspaceOperator;

public CassandraHealthCheck(Keyspace keyspaceOperator) {
super("Cassandra");
this.keyspaceOperator = keyspaceOperator;
/**
* Create a new {@link HealthCheck} instance with the given name.
*
* @param name the name of the health check (and, ideally, the name of the underlying
* component the health check tests)
*/
protected CassandraHealthCheck(String name) {
super(name);
}

@Override
public Result check() throws Exception {
try {
createRangeSlicesQuery(keyspaceOperator,
StringSerializer.get(), StringSerializer.get(), StringSerializer.get())
.setColumnFamily(DOMAIN_CF)
.setRange(null, null, false, 1)
.execute()
.get();
return Result.healthy();
} catch (HectorException he) {
return Result.unhealthy("Cannot connect to Cassandra Cluster : " + keyspaceOperator.getKeyspaceName());
}
protected Result check() throws Exception {
return null;
}


// public CassandraHealthCheck(Keyspace keyspaceOperator) {
// super("Cassandra");
// this.keyspaceOperator = keyspaceOperator;
// }
//
// @Override
// public Result check() throws Exception {
// try {
// createRangeSlicesQuery(keyspaceOperator,
// StringSerializer.get(), StringSerializer.get(), StringSerializer.get())
// .setColumnFamily(DOMAIN_CF)
// .setRange(null, null, false, 1)
// .execute()
// .get();
// return Result.healthy();
// } catch (HectorException he) {
// return Result.unhealthy("Cannot connect to Cassandra Cluster : " + keyspaceOperator.getKeyspaceName());
// }
// }
}
3 changes: 3 additions & 0 deletions services/src/main/java/fr/ippon/tatami/domain/Avatar.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ public class Avatar implements Serializable {

private long size;

public Avatar() {
}

public String getAvatarId() {
return avatarId;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
import java.io.Serializable;
import java.util.Properties;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import com.datastax.driver.mapping.annotations.*;

import org.apache.commons.io.IOUtils;

Expand All @@ -17,7 +14,6 @@
*
* @author Julien Dubois
*/
@Entity
@Table(name = "DomainConfiguration")
public class DomainConfiguration implements Serializable {

Expand Down Expand Up @@ -74,7 +70,7 @@ public static class SubscriptionAndStorageSizeOptions {

}

@Id
@PartitionKey
private String domain;

@Column(name = "subscriptionLevel")
Expand Down
7 changes: 4 additions & 3 deletions services/src/main/java/fr/ippon/tatami/domain/Group.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
import com.fasterxml.jackson.annotation.JsonIgnore;

import java.io.Serializable;
import java.util.UUID;

/**
* A group.
*/
public class Group implements Comparable<Group>, Serializable, Cloneable {

private String groupId;
private UUID groupId;

private boolean publicGroup;

Expand All @@ -29,11 +30,11 @@ public class Group implements Comparable<Group>, Serializable, Cloneable {

private boolean administrator;

public String getGroupId() {
public UUID getGroupId() {
return groupId;
}

public void setGroupId(String groupId) {
public void setGroupId(UUID groupId) {
this.groupId = groupId;
}

Expand Down
15 changes: 8 additions & 7 deletions services/src/main/java/fr/ippon/tatami/domain/User.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package fr.ippon.tatami.domain;

import com.datastax.driver.mapping.annotations.*;
import com.fasterxml.jackson.annotation.JsonIgnore;
import fr.ippon.tatami.domain.validation.ContraintsUserCreation;
import org.hibernate.validator.constraints.Email;
import org.hibernate.validator.constraints.NotEmpty;
import org.springframework.data.cassandra.mapping.PrimaryKey;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.validation.groups.Default;
Expand All @@ -19,15 +17,15 @@
*
* @author Julien Dubois
*/
@Entity
@Table(name = "User")
@Table(name = "user")
public class User implements Serializable {


@NotEmpty(message = "Login is mandatory.", groups = {ContraintsUserCreation.class, Default.class})
@NotNull(message = "Login is mandatory.", groups = {ContraintsUserCreation.class, Default.class})
@Email(message = "Email is invalid.")
@Id
@JsonIgnore
@PartitionKey
private String login;

@Column(name = "password")
Expand Down Expand Up @@ -86,10 +84,13 @@ public class User implements Serializable {
@Column(name="activated")
private Boolean activated=true;

@Transient
private long statusCount;

@Transient
private long friendsCount;

@Transient
private long followersCount;


Expand Down
Loading