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

Unified interface #356

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version=0.91.3
version=0.91.4
springVersion=4.3.3.RELEASE
springBootVersion=1.4.1.RELEASE
jerseyVersion=2.24
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import javax.ws.rs.Path;
import javax.ws.rs.Produces;

import com.aol.micro.server.distributed.DistributedCache;
import cyclops.collections.immutable.LinkedListX;
import cyclops.control.Maybe;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -20,11 +21,11 @@
@Rest
public class CouchbaseResource {

private final DistributedMap client;
private final DistributedCache client;
private volatile LinkedListX<SystemData> dataLoads = LinkedListX.empty();

@Autowired
public CouchbaseResource(DistributedMap client, EventBus bus) {
public CouchbaseResource(DistributedCache client, EventBus bus) {
this.client = client;
bus.register(this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import javax.ws.rs.Path;
import javax.ws.rs.Produces;

import com.aol.micro.server.distributed.DistributedCache;
import cyclops.collections.immutable.LinkedListX;
import cyclops.control.Maybe;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -20,11 +21,11 @@
@Rest
public class CouchbaseResource {

private final DistributedMap client;
private final DistributedCache client;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd change the reference name as well 😃

private volatile LinkedListX<SystemData> dataLoads = LinkedListX.empty();

@Autowired
public CouchbaseResource(DistributedMap client, EventBus bus) {
public CouchbaseResource(DistributedCache client, EventBus bus) {
this.client = client;
bus.register(this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@
import javax.ws.rs.Path;
import javax.ws.rs.Produces;

import com.aol.micro.server.distributed.DistributedCache;
import cyclops.collections.immutable.LinkedListX;
import cyclops.control.Maybe;
import org.springframework.beans.factory.annotation.Autowired;


import com.aol.micro.server.auto.discovery.Rest;
import com.aol.micro.server.distributed.DistributedMap;
import com.aol.micro.server.events.SystemData;
import com.google.common.eventbus.EventBus;
import com.google.common.eventbus.Subscribe;
Expand All @@ -19,12 +18,12 @@
@Rest
public class CouchbaseResource {

private final DistributedMap client;
private final DistributedCache client;

private volatile LinkedListX<SystemData> dataCleans = LinkedListX.empty();

@Autowired
public CouchbaseResource(DistributedMap client, EventBus bus) {
public CouchbaseResource(DistributedCache client, EventBus bus) {
this.client = client;
bus.register(this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import javax.ws.rs.Path;
import javax.ws.rs.Produces;

import com.aol.micro.server.distributed.DistributedCache;
import cyclops.collections.immutable.LinkedListX;
import cyclops.control.Maybe;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -19,12 +20,12 @@
@Rest
public class CouchbaseResource {

private final DistributedMap client;
private final DistributedCache client;

private volatile LinkedListX<SystemData> dataCleans = LinkedListX.empty();

@Autowired
public CouchbaseResource(DistributedMap client, EventBus bus) {
public CouchbaseResource(DistributedCache client, EventBus bus) {
this.client = client;
bus.register(this);
}
Expand Down
1 change: 1 addition & 0 deletions micro-couchbase/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ dependencies {
compile project(':micro-manifest-comparator')
compile project(':micro-core')
compile project(':micro-guava')
compile project(':micro-events')
testCompile group: 'org.codehaus.groovy', name: 'groovy-all', version:'2.3.3'
testCompile(group: 'org.spockframework', name: 'spock-core', version:'0.7-groovy-2.0') { exclude(module: 'groovy-all') }
testCompile group: 'com.cyrusinnovation', name: 'mockito-groovy-support', version:'1.3'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.aol.micro.server.couchbase;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.Scheduled;

@Configuration
public class ConfigureCacheTester {

@Autowired
private CouchbaseConnectionTester couchbaseConnectionTester;


@Scheduled(fixedDelay = 60000)
public synchronized void runCouchbaseConnectionTester(){
couchbaseConnectionTester.scheduleAndLog();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,23 @@
import java.util.List;
import java.util.Optional;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.StringUtils;

import com.aol.micro.server.couchbase.base.CouchbaseManifestComparator;
import com.aol.micro.server.couchbase.manifest.comparator.CouchbaseManifestComparator;
import com.couchbase.client.CouchbaseClient;
import com.couchbase.client.CouchbaseConnectionFactory;
import com.couchbase.client.CouchbaseConnectionFactoryBuilder;

import lombok.Setter;

@Slf4j
@Configuration
public class ConfigureCouchbase {

private Logger logger = LoggerFactory.getLogger(getClass());

@Value("${couchbase.manifest.comparison.key:default-key}")
private String defaultCouchbaseManifestComparisonKey;
@Setter
Expand All @@ -45,22 +43,33 @@ public class ConfigureCouchbase {
@Value("${couchbaseClientOperationTimeout:120000}")
private long opTimeout;

@Value("${distributed.cache.default.expiration:691200}")
private int expiresAfterSeconds;

@Value("${distributed.cache.maxTry:5}")
private int maxTry;

@Value("${distributed.cache.retryAfterSec:1}")
private int retryAfterSec;

@SuppressWarnings("rawtypes")
@Bean(name = "couchbaseDistributedMap")
public CouchbaseDistributedMapClient simpleCouchbaseClient() throws IOException, URISyntaxException {
public CouchbaseDistributedCacheClient simpleCouchbaseClient() throws IOException, URISyntaxException {
if (couchbaseClientEnabled) {
return new CouchbaseDistributedMapClient(
couchbaseClient());
return new CouchbaseDistributedCacheClient(
couchbaseClient(), expiresAfterSeconds, maxTry,
retryAfterSec);
} else {
return new CouchbaseDistributedMapClient(
null);
return new CouchbaseDistributedCacheClient(
null, expiresAfterSeconds, maxTry,
retryAfterSec);
}
}

@Bean(name = "couchbaseClient")
public CouchbaseClient couchbaseClient() throws IOException, URISyntaxException {
if (couchbaseClientEnabled) {
logger.info("Creating CouchbaseClient for servers: {}", couchbaseServers);
log.info("Creating CouchbaseClient for servers: {}", couchbaseServers);
CouchbaseConnectionFactoryBuilder builder = new CouchbaseConnectionFactoryBuilder();
builder.setOpTimeout(opTimeout);
CouchbaseConnectionFactory cf = builder.buildCouchbaseConnection(getServersList(), couchbaseBucket,
Expand All @@ -70,7 +79,6 @@ public CouchbaseClient couchbaseClient() throws IOException, URISyntaxException
cf);
}
return null;

}

@Bean
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.aol.micro.server.couchbase;


import com.aol.micro.server.distributed.DistributedCache;
import com.aol.micro.server.distributed.DistributedMap;
import com.aol.micro.server.events.ScheduledJob;
import com.aol.micro.server.events.SystemData;
import com.couchbase.client.CouchbaseClient;
import lombok.extern.slf4j.Slf4j;

import java.util.Random;

@Slf4j
public class CouchbaseConnectionTester implements ScheduledJob {

private static final Random random = new Random();

private final DistributedCache cache;
private final CouchbaseClient couchbaseClient;

public CouchbaseConnectionTester(DistributedCache cache, CouchbaseClient couchbaseClient) {

this.cache = cache;
this.couchbaseClient = couchbaseClient;
}

@Override
public SystemData scheduleAndLog() {

log.trace("runTestConnection()...");
boolean result = false;
try {
result = testConnection();
} catch (RuntimeException e) {
log.debug("Could not connect to Cache" + e.getMessage());
}
cache.setConnectionTested(result);

log.debug("Testing Couchbase connection: {}", result);
return null;

}

private boolean testConnection() {
String key = "PING_TEST";
log.trace("Testing connection using key {}", key);

int testValue = random.nextInt(1111);
couchbaseClient.set(key, 120, testValue);
int received = (Integer) couchbaseClient.get(key);

return received == testValue;
}

}
Loading