Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
7c8c02b
Removing the Remote Datastore
May 22, 2019
b74ed34
Initial pass at removing the distributed datastore
May 29, 2019
e865d89
Tightening the typing constraints of datastore patches
Jun 5, 2019
94f90fc
Updating the Datastore API to use Object rather than Serializable
Jun 12, 2019
09881c5
Updating the SystemModelInterrogator to make some methods static
Jun 12, 2019
d6d357b
Fixing file header formatting on a few files
Jun 12, 2019
972b95a
Adding the expectation of immutability to Patch and Patchable
Jun 12, 2019
0e884f1
Initial implementation of the Hazelcast Datastore
Jun 12, 2019
b707556
Refactoring the Datastore patching API
Jun 13, 2019
41f1fb1
Removing the unused RackspaceAuthUserGroup class
Jun 13, 2019
18fb054
Cleaning up the build file for the datastore service
Jun 14, 2019
103fcca
Adjusting how TTL for rate limits is calculated
Jun 17, 2019
4a21046
Updating the simple and complex use-case performance tests to use Haz…
Jun 18, 2019
6e92150
Making the env var templating parser more generic
Jun 20, 2019
f6d3298
Updating the HazelcastDatastore to live reload on Hazelcast config ch…
Jun 21, 2019
e6a767a
Adding a Hazelcast datastore service configuration
Jun 21, 2019
9a83d0e
Handling the Hazelcast datastore service configuration
Jun 25, 2019
3f2faeb
Updating performance tests to use the service configuration
Jun 25, 2019
a0bb493
Simplifying the port configuration for the simplified config
Jun 25, 2019
834c47d
Reintroducing Serializable to the Datastore API
Jun 28, 2019
b0921e2
Updating the RateLimitingTwoNodeTest to use the Hazelcast Datastore
Jun 28, 2019
be75ec7
Renaming standard config element to complete
Jul 1, 2019
13679b9
Adding Hazelcast Datastore documentation and release notes
Jul 2, 2019
1d454e7
Fixing some FIT dist-datastore references
Jul 3, 2019
abe70e6
Suppressing dependency misidentification of hazelcast-kubernetes
Jul 3, 2019
321efeb
Hazelcast patch using an ExecutorService
Aug 13, 2019
a8849fb
Removing unused dependency on libxmljs by performance test mocks
Aug 14, 2019
d1b2827
Replacing Hazelcast patch operation ExecutorService and lock with Ent…
Aug 15, 2019
df0777e
Merge branch 'v10' into REP-7785
nonameentername Oct 9, 2019
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
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Group Name Ve
-------------------------------------------------- ------------------------ --------------- -------------------------- ----------------------------------------------------------------------------------
com.fasterxml.jackson.core jackson-core 2.9.9 Apache License Version 2.0 http://wiki.fasterxml.com/JacksonDownload
com.fasterxml.jackson.core jackson-databind 2.9.9.3 Apache License Version 2.0 http://wiki.fasterxml.com/JacksonDownload
com.hazelcast hazelcast 3.12 Apache License Version 2.0 https://github.com/hazelcast/hazelcast
commons-codec commons-codec 1.10 Apache License Version 2.0 http://commons.apache.org/proper/commons-codec/
commons-io commons-io 2.4 Apache License Version 2.0 http://commons.apache.org/proper/commons-io/
commons-pool commons-pool 1.6 Apache License Version 2.0 http://commons.apache.org/proper/commons-pool/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

import org.openrepose.cli.command.AbstractCommandList;
import org.openrepose.cli.command.Command;
import org.openrepose.cli.command.datastore.distributed.DistributedDatastoreCommandList;
import org.openrepose.cli.command.datastore.local.LocalDatastoreCommandList;

/**
Expand All @@ -32,7 +31,6 @@ public class RootCommandLine extends AbstractCommandList {
@Override
public Command[] availableCommands() {
return new Command[]{
new DistributedDatastoreCommandList(),
new LocalDatastoreCommandList()
};
}
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ com.fasterxml.jackson.core jackson-core 2.
com.fasterxml.jackson.core jackson-databind 2.9.9.3 Apache License Version 2.0 http://wiki.fasterxml.com/JacksonDownload
com.github.scopt scopt_2.11 3.2.0 MIT License https://github.com/scopt/scopt
com.google.guava guava 27.0.1-jre Apache License Version 2.0 https://github.com/google/guava
com.hazelcast hazelcast 3.12 Apache License Version 2.0 https://github.com/hazelcast/hazelcast
commons-codec commons-codec 1.10 Apache License Version 2.0 http://commons.apache.org/proper/commons-codec/
commons-io commons-io 2.4 Apache License Version 2.0 http://commons.apache.org/proper/commons-io/
commons-pool commons-pool 1.6 Apache License Version 2.0 http://commons.apache.org/proper/commons-pool/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* limitations under the License.
* =_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_=_
*/
package org.openrepose.commons.config.parser.jaxb;
package org.openrepose.commons.config.parser.common;

import org.apache.commons.io.IOUtils;
import org.jtwig.JtwigModel;
Expand All @@ -26,21 +26,20 @@
import org.jtwig.environment.EnvironmentConfigurationBuilder;
import org.openrepose.commons.config.resource.ConfigurationResource;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.Collections;

public class TemplatingJaxbConfigurationParser<T> extends JaxbConfigurationParser<T> {
public class TemplatingConfigurationParser<T> implements ConfigurationParser<T> {

private static final String START_OUTPUT_TAG = "{$";
private static final String END_OUTPUT_TAG = "$}";
private static final String START_COMMENT_TAG = "{!";
private static final String END_COMMENT_TAG = "!}";

// @formatter:off
private static final EnvironmentConfiguration ENV_CONF = EnvironmentConfigurationBuilder
.configuration()
.parser()
Expand All @@ -53,18 +52,22 @@ public class TemplatingJaxbConfigurationParser<T> extends JaxbConfigurationParse
.withStrictMode(true)
.and()
.build();
// @formatter:on

private final ConfigurationParser<T> parser;

public TemplatingJaxbConfigurationParser(Class<T> configurationClass, JAXBContext jaxbContext, URL xsdStreamSource) {
super(configurationClass, jaxbContext, xsdStreamSource);
public TemplatingConfigurationParser(ConfigurationParser<T> parser) {
this.parser = parser;
}

public TemplatingJaxbConfigurationParser(Class<T> configurationClass, URL xsdStreamSource, ClassLoader loader) throws JAXBException {
super(configurationClass, xsdStreamSource, loader);
@Override
public Class<T> configurationClass() {
return parser.configurationClass();
}

@Override
public T read(ConfigurationResource cr) {
return super.read(new ConfigurationResource() {
return parser.read(new ConfigurationResource() {
@Override
public boolean updated() throws IOException {
return cr.updated();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,89 +17,93 @@
* limitations under the License.
* =_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_=_
*/
package org.openrepose.commons.config.parser.jaxb;
package org.openrepose.commons.config.parser.common;

import org.apache.commons.io.IOUtils;
import org.jtwig.exceptions.ResolveValueException;
import org.junit.Before;
import org.junit.Test;
import org.openrepose.commons.config.parser.common.ConfigurationParser;
import org.mockito.stubbing.Answer;
import org.openrepose.commons.config.resource.ConfigurationResource;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import java.io.ByteArrayInputStream;
import java.io.IOException;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assume.assumeTrue;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

public class TemplatingJaxbConfigurationParserTest {
public class TemplatingConfigurationParserTest {
private static final String TEST_USER_ENV_VAR = "TEST_USER";
private static final String TEST_USER_NAME = "World";

private ConfigurationParser<String> baseParser = (ConfigurationParser<String>) mock(ConfigurationParser.class);
private TemplatingConfigurationParser<String> templatingParser = new TemplatingConfigurationParser<>(baseParser);

@Before
public void setup() {
baseParser = (ConfigurationParser<String>) mock(ConfigurationParser.class);
templatingParser = new TemplatingConfigurationParser<>(baseParser);

when(baseParser.read(any(ConfigurationResource.class)))
.thenAnswer((Answer<String>) invocation -> {
Object[] args = invocation.getArguments();
ConfigurationResource resource = (ConfigurationResource) args[0];
return IOUtils.toString(resource.newInputStream());
});
}

@Test
public void shouldTemplateEnvironmentVariableInConfigurationResource() throws JAXBException, IOException {
public void shouldReturnTheConfigurationClassOfTheBaseParser() {
when(baseParser.configurationClass()).thenReturn(String.class);

assertEquals(baseParser.configurationClass(), templatingParser.configurationClass());
}

@Test
public void shouldTemplateEnvironmentVariableInConfigurationResource() throws IOException {
assumeTrue(
"The " + TEST_USER_ENV_VAR + " environment variable must be set to" + TEST_USER_NAME + " for this test",
TEST_USER_NAME.equals(System.getenv(TEST_USER_ENV_VAR))
);

final JAXBContext jaxbContext = JAXBContext.newInstance(Element.class);
ConfigurationParser<Element> parser = new TemplatingJaxbConfigurationParser<>(Element.class, jaxbContext, null);

ConfigurationResource cfgResource = mock(ConfigurationResource.class);
ByteArrayInputStream cfgStream = new ByteArrayInputStream(createConfig(createHelloMsg("{$(" + TEST_USER_ENV_VAR + ")$}")).getBytes());
ByteArrayInputStream cfgStream = new ByteArrayInputStream(createHelloMsg("{$(" + TEST_USER_ENV_VAR + ")$}").getBytes());
when(cfgResource.newInputStream()).thenReturn(cfgStream);

Element element = parser.read(cfgResource);
String result = templatingParser.read(cfgResource);

assertNotNull(element);
assertEquals(createHelloMsg(TEST_USER_NAME), element.hello);
assertEquals(createHelloMsg(TEST_USER_NAME), result);
}

@Test
public void shouldRemoveTemplateCommentInConfigurationResource() throws JAXBException, IOException {
final JAXBContext jaxbContext = JAXBContext.newInstance(Element.class);
ConfigurationParser<Element> parser = new TemplatingJaxbConfigurationParser<>(Element.class, jaxbContext, null);

public void shouldRemoveTemplateCommentInConfigurationResource() throws IOException {
ConfigurationResource cfgResource = mock(ConfigurationResource.class);
ByteArrayInputStream cfgStream = new ByteArrayInputStream(createConfig(createHelloMsg("{!COMMENT!}")).getBytes());
ByteArrayInputStream cfgStream = new ByteArrayInputStream(createHelloMsg("{!COMMENT!}").getBytes());
when(cfgResource.newInputStream()).thenReturn(cfgStream);

Element element = parser.read(cfgResource);
String result = templatingParser.read(cfgResource);

assertNotNull(element);
assertEquals(createHelloMsg(""), element.hello);
assertEquals(createHelloMsg(""), result);
}

@Test(expected = ClassCastException.class)
public void shouldThrowExceptionWhenMissingEnvironmentVariable() throws JAXBException, IOException {
@Test(expected = ResolveValueException.class)
public void shouldThrowExceptionWhenMissingEnvironmentVariable() throws IOException {
assumeTrue(
"The NOT_A_VAR environment variable must NOT be set for this test",
System.getenv("NOT_A_VAR") == null
);

final JAXBContext jaxbContext = JAXBContext.newInstance(Element.class);
ConfigurationParser<Element> parser = new TemplatingJaxbConfigurationParser<>(Element.class, jaxbContext, null);

ConfigurationResource cfgResource = mock(ConfigurationResource.class);
ByteArrayInputStream cfgStream = new ByteArrayInputStream(createConfig(createHelloMsg("{$(NOT_A_VAR)$}")).getBytes());
ByteArrayInputStream cfgStream = new ByteArrayInputStream(createHelloMsg("{$(NOT_A_VAR)$}").getBytes());
when(cfgResource.newInputStream()).thenReturn(cfgStream);

parser.read(cfgResource);
templatingParser.read(cfgResource);
}

private static String createHelloMsg(String name) {
return String.format("Hello %s!", name);
}

private static String createConfig(String helloMsg) {
return "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"\n" +
"<element>\n" +
" <hello>" + helloMsg + "</hello>\n" +
" <goodbye>See ya.</goodbye>\n" +
"</element>\n";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import org.openrepose.commons.utils.servlet.http.ResponseMode.{MUTABLE, PASSTHRO
import org.openrepose.commons.utils.servlet.http.{HttpServletRequestWrapper, HttpServletResponseWrapper}
import org.openrepose.commons.utils.string.Base64Helper
import org.openrepose.core.services.config.ConfigurationService
import org.openrepose.core.services.datastore.types.{PatchableSet, SetPatch}
import org.openrepose.core.services.datastore.types.HashSetPatch
import org.openrepose.core.services.datastore.{Datastore, DatastoreService}
import org.openrepose.core.services.httpclient.HttpClientService
import org.openrepose.core.systemmodel.config.SystemModel
Expand Down Expand Up @@ -178,7 +178,7 @@ class KeystoneV2Filter @Inject()(configurationService: ConfigurationService,
val timeToLive = getTtl(cacheSettings.getToken, cacheSettings.getVariability, Some(validToken))

timeToLive foreach { ttl =>
datastore.patch(s"$USER_ID_KEY_PREFIX${validToken.userId}", SetPatch(authToken), ttl, TimeUnit.SECONDS)
datastore.patch(s"$USER_ID_KEY_PREFIX${validToken.userId}", new HashSetPatch(authToken), ttl, TimeUnit.SECONDS)
datastore.put(s"$TOKEN_KEY_PREFIX$authToken", validToken, ttl, TimeUnit.SECONDS)
}
}
Expand Down Expand Up @@ -573,7 +573,7 @@ class KeystoneV2Filter @Inject()(configurationService: ConfigurationService,
val authTokens: Option[collection.Set[String]] = resourceType.headOption match {
// User OR Token Revocation Record (TRR) event
case Some("USER") | Some("TRR_USER") =>
val tokens = Option(datastore.get(s"$USER_ID_KEY_PREFIX${resourceId.get}").asInstanceOf[PatchableSet[String]])
val tokens = Option(datastore.get(s"$USER_ID_KEY_PREFIX${resourceId.get}").asInstanceOf[Set[String]])
datastore.remove(s"$USER_ID_KEY_PREFIX${resourceId.get}")
tokens
case Some("TOKEN") => Some(Set(resourceId.get))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import org.mockito.Matchers.{any => mockitoAny, eq => mockitoEq, _}
import org.mockito.Mockito
import org.mockito.Mockito._
import org.openrepose.core.services.config.ConfigurationService
import org.openrepose.core.services.datastore.types.PatchableSet
import org.openrepose.core.services.datastore.{Datastore, DatastoreService}
import org.openrepose.core.services.httpclient.{HttpClientService, HttpClientServiceClient}
import org.openrepose.filters.keystonev2.KeystoneRequestHandler._
Expand All @@ -39,6 +38,8 @@ import org.scalatest.mock.MockitoSugar
import org.scalatest.{BeforeAndAfterEach, FunSpec, Matchers}
import org.springframework.mock.web.MockFilterConfig

import scala.collection.immutable.HashSet

@RunWith(classOf[JUnitRunner])
class KeystoneV2FilterCacheInvalidationTest extends FunSpec
with IdentityResponses
Expand Down Expand Up @@ -218,7 +219,7 @@ with BeforeAndAfterEach {

List("USER", "TRR_USER").foreach { resourceType =>
it(s"removes the User to Token cache along with the token cache on a $resourceType event") {
when(mockDatastore.get(s"$USER_ID_KEY_PREFIX$userId")).thenReturn(PatchableSet(tokenOne, tokenTwo), null)
when(mockDatastore.get(s"$USER_ID_KEY_PREFIX$userId")).thenReturn(HashSet(tokenOne, tokenTwo), null)
// This was taken from: https://github.com/rackerlabs/standard-usage-schemas/blob/master/message_samples/identity/xml/cloudidentity-user-trr_user-delete-v1-response.xml
filter.CacheInvalidationFeedListener.onNewAtomEntry(
s"""<?xml version="1.0" encoding="UTF-8"?>
Expand Down
Loading