Skip to content

Commit

Permalink
Merge pull request #2 from grookage/fixes
Browse files Browse the repository at this point in the history
Bug Fixes
  • Loading branch information
koushikr authored Jan 20, 2025
2 parents fc39a92 + c0e0df4 commit 42dc622
Show file tree
Hide file tree
Showing 27 changed files with 143 additions and 37 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

All notable changes to this project will be documented in this file.

## [0.0.1-RC2]

- Added a preProcessor and post-processor for every config update, basis namespace, configName and configEvent
- Bug Fix : AS Repository wasn't saving namespace and config bins. Fixed it

## [0.0.1-RC1]

- A versioned config registry, to register various configs backed by a RBAC enabled maker-checker process
Expand Down
2 changes: 1 addition & 1 deletion concierge-aerospike-dw/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.grookage.concierge</groupId>
<artifactId>concierge-parent</artifactId>
<version>0.0.1-RC1</version>
<version>0.0.1-RC2</version>
<relativePath>../concierge-parent</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion concierge-aerospike/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.grookage.concierge</groupId>
<artifactId>concierge-parent</artifactId>
<version>0.0.1-RC1</version>
<version>0.0.1-RC2</version>
<relativePath>../concierge-parent</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ public void bulkUpdate(List<AerospikeRecord> aerospikeRecords) {
try {
final var writePolicy = client.copyWritePolicyDefault();
writePolicy.txn = transaction;
for (AerospikeRecord storageRecord : aerospikeRecords) {
aerospikeRecords.forEach(storageRecord -> {
final var key = getKey(storageRecord.getReferenceId());
final var bin = new Bin(AerospikeStorageConstants.DEFAULT_BIN, MapperUtils.mapper().writeValueAsBytes(storageRecord));
client.put(writePolicy, key, bin);
}
final var bins = getBins(storageRecord).toArray(Bin[]::new);
client.put(writePolicy, key, bins);
});
} catch (Exception e) {
log.debug("There is an error trying to commit the transaction with id {}. Aborting the transaction", transaction.getId(), e);
client.abort(transaction);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.grookage.concierge.models.config.ConfigState;
import com.grookage.concierge.repository.AbstractConciergeRepository;
import com.grookage.concierge.repository.cache.CacheConfig;
import lombok.EqualsAndHashCode;
import lombok.Getter;

import java.util.List;
Expand All @@ -16,6 +17,7 @@
import java.util.stream.Collectors;

@Getter
@EqualsAndHashCode(callSuper = true)
public class AerospikeRepository extends AbstractConciergeRepository {

private final AerospikeManager aerospikeManager;
Expand Down Expand Up @@ -88,26 +90,26 @@ public boolean createdRecordExists(String namespace, String configName) {
@Override
public List<ConfigDetails> getStoredRecords() {
return aerospikeManager.getRecords(List.of(), List.of(), List.of())
.stream().map(this::toConfigDetails).collect(Collectors.toList());
.stream().map(this::toConfigDetails).toList();
}

@Override
public List<ConfigDetails> getStoredRecords(String namespace, Set<String> configNames, Set<ConfigState> configStates) {
return aerospikeManager.getRecords(List.of(namespace), configNames.stream().toList(),
configStates.stream().map(Enum::name).collect(Collectors.toList()))
.stream().map(this::toConfigDetails).collect(Collectors.toList());
configStates.stream().map(Enum::name).toList())
.stream().map(this::toConfigDetails).toList();
}

@Override
public List<ConfigDetails> getActiveStoredRecords(Set<String> namespaces) {
return aerospikeManager.getRecords(namespaces.stream().toList(),
List.of(), List.of(ConfigState.ACTIVATED.name())).stream()
.map(this::toConfigDetails).collect(Collectors.toList());
.map(this::toConfigDetails).toList();
}

@Override
public List<ConfigDetails> getStoredRecords(Set<String> namespaces) {
return aerospikeManager.getRecords(namespaces.stream().toList(), List.of(), List.of())
.stream().map(this::toConfigDetails).collect(Collectors.toList());
.stream().map(this::toConfigDetails).toList();
}
}
2 changes: 1 addition & 1 deletion concierge-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.grookage.concierge</groupId>
<artifactId>concierge</artifactId>
<version>0.0.1-RC1</version>
<version>0.0.1-RC2</version>
</parent>

<artifactId>concierge-bom</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion concierge-client-dw/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.grookage.concierge</groupId>
<artifactId>concierge-parent</artifactId>
<version>0.0.1-RC1</version>
<version>0.0.1-RC2</version>
<relativePath>../concierge-parent</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion concierge-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.grookage.concierge</groupId>
<artifactId>concierge-parent</artifactId>
<version>0.0.1-RC1</version>
<version>0.0.1-RC2</version>
<relativePath>../concierge-parent</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion concierge-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.grookage.concierge</groupId>
<artifactId>concierge-parent</artifactId>
<version>0.0.1-RC1</version>
<version>0.0.1-RC2</version>
<relativePath>../concierge-parent</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@
import com.grookage.concierge.models.config.ConfigDetails;
import com.grookage.concierge.models.config.ConfigEvent;
import com.grookage.concierge.models.config.ConfigHistoryItem;
import com.grookage.concierge.models.exception.ConciergeCoreErrorCode;
import com.grookage.concierge.models.exception.ConciergeException;
import com.grookage.concierge.models.processor.ProcessorKey;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;

import java.util.function.Supplier;


@Slf4j
public abstract class ConciergeProcessor {
Expand All @@ -31,14 +36,19 @@ public void addHistory(ConciergeContext context, ConfigDetails configDetails) {

public abstract void process(ConciergeContext context);

@SneakyThrows
public void fire(ConciergeContext context, ProcessorFactory processorFactory) {
final var processorKey = context.getContext(ProcessorKey.class)
.orElseThrow((Supplier<Throwable>) () -> ConciergeException.error(ConciergeCoreErrorCode.VALUE_NOT_FOUND));
final var processor = null != processorFactory ? processorFactory.getProcessor(processorKey).orElse(null) : null;

if (null != processor) {
processor.preProcess(context);
}
process(context);
final var configEvent = name();
if (null != processorFactory) {
final var postProcessor = processorFactory.getProcessor(configEvent).orElse(null);
if (null != postProcessor) {
postProcessor.process(context);
}

if (null != processor) {
processor.postProcess(context);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

public interface EventProcessor {

void process(ConciergeContext context);
void preProcess(ConciergeContext context);

void postProcess(ConciergeContext context);

}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.grookage.concierge.core.managers;

import com.grookage.concierge.models.config.ConfigEvent;
import com.grookage.concierge.models.processor.ProcessorKey;

import java.util.Optional;

public interface ProcessorFactory {

Optional<EventProcessor> getProcessor(final ConfigEvent configEvent);
Optional<EventProcessor> getProcessor(final ProcessorKey processorKey);

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.grookage.concierge.models.exception.ConciergeException;
import com.grookage.concierge.models.ingestion.ConfigurationRequest;
import com.grookage.concierge.models.ingestion.UpdateConfigRequest;
import com.grookage.concierge.models.processor.ProcessorKey;
import lombok.AllArgsConstructor;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -32,6 +33,12 @@ public ConfigDetails createConfiguration(C configUpdater, ConfigurationRequest c
final var conciergeContext = new ConciergeContext();
conciergeContext.addContext(ConfigurationRequest.class.getSimpleName(), configurationRequest);
ContextUtils.addConfigUpdaterContext(conciergeContext, configUpdater);
final var processorKey = ProcessorKey.builder()
.namespace(configurationRequest.getNamespace())
.configName(configurationRequest.getConfigName())
.configEvent(ConfigEvent.CREATE_CONFIG)
.build();
conciergeContext.addContext(ProcessorKey.class.getSimpleName(), processorKey);
final var processor = conciergeHub.getProcessor(ConfigEvent.CREATE_CONFIG)
.orElseThrow((Supplier<Throwable>) () -> ConciergeException.error(ConciergeCoreErrorCode.PROCESSOR_NOT_FOUND));
processor.fire(conciergeContext, processorFactory.get());
Expand All @@ -44,6 +51,12 @@ public ConfigDetails updateConfiguration(C configUpdater, UpdateConfigRequest co
final var conciergeContext = new ConciergeContext();
conciergeContext.addContext(UpdateConfigRequest.class.getSimpleName(), configurationRequest);
ContextUtils.addConfigUpdaterContext(conciergeContext, configUpdater);
final var processorKey = ProcessorKey.builder()
.namespace(configurationRequest.getNamespace())
.configName(configurationRequest.getConfigName())
.configEvent(ConfigEvent.CREATE_CONFIG)
.build();
conciergeContext.addContext(ProcessorKey.class.getSimpleName(), processorKey);
final var processor = conciergeHub.getProcessor(ConfigEvent.UPDATE_CONFIG)
.orElseThrow((Supplier<Throwable>) () -> ConciergeException.error(ConciergeCoreErrorCode.PROCESSOR_NOT_FOUND));
processor.fire(conciergeContext, processorFactory.get());
Expand All @@ -56,6 +69,12 @@ public ConfigDetails approveConfiguration(C configUpdater, ConfigKey configKey)
final var conciergeContext = new ConciergeContext();
conciergeContext.addContext(ConfigKey.class.getSimpleName(), configKey);
ContextUtils.addConfigUpdaterContext(conciergeContext, configUpdater);
final var processorKey = ProcessorKey.builder()
.namespace(configKey.getNamespace())
.configName(configKey.getConfigName())
.configEvent(ConfigEvent.CREATE_CONFIG)
.build();
conciergeContext.addContext(ProcessorKey.class.getSimpleName(), processorKey);
final var processor = conciergeHub.getProcessor(ConfigEvent.APPROVE_CONFIG)
.orElseThrow((Supplier<Throwable>) () -> ConciergeException.error(ConciergeCoreErrorCode.PROCESSOR_NOT_FOUND));
processor.fire(conciergeContext, processorFactory.get());
Expand All @@ -68,6 +87,12 @@ public ConfigDetails rejectConfiguration(C configUpdater, ConfigKey configKey) {
final var conciergeContext = new ConciergeContext();
conciergeContext.addContext(ConfigKey.class.getSimpleName(), configKey);
ContextUtils.addConfigUpdaterContext(conciergeContext, configUpdater);
final var processorKey = ProcessorKey.builder()
.namespace(configKey.getNamespace())
.configName(configKey.getConfigName())
.configEvent(ConfigEvent.CREATE_CONFIG)
.build();
conciergeContext.addContext(ProcessorKey.class.getSimpleName(), processorKey);
final var processor = conciergeHub.getProcessor(ConfigEvent.REJECT_CONFIG)
.orElseThrow((Supplier<Throwable>) () -> ConciergeException.error(ConciergeCoreErrorCode.PROCESSOR_NOT_FOUND));
processor.fire(conciergeContext, processorFactory.get());
Expand All @@ -80,6 +105,12 @@ public ConfigDetails activateConfiguration(C configUpdater, ConfigKey configKey)
final var conciergeContext = new ConciergeContext();
conciergeContext.addContext(ConfigKey.class.getSimpleName(), configKey);
ContextUtils.addConfigUpdaterContext(conciergeContext, configUpdater);
final var processorKey = ProcessorKey.builder()
.namespace(configKey.getNamespace())
.configName(configKey.getConfigName())
.configEvent(ConfigEvent.CREATE_CONFIG)
.build();
conciergeContext.addContext(ProcessorKey.class.getSimpleName(), processorKey);
final var processor = conciergeHub.getProcessor(ConfigEvent.ACTIVATE_CONFIG)
.orElseThrow((Supplier<Throwable>) () -> ConciergeException.error(ConciergeCoreErrorCode.PROCESSOR_NOT_FOUND));
processor.fire(conciergeContext, processorFactory.get());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.grookage.concierge.core.stubs.TestConfigUpdater;
import com.grookage.concierge.models.ConfigUpdater;
import com.grookage.concierge.models.config.ConfigEvent;
import com.grookage.concierge.models.processor.ProcessorKey;
import com.grookage.concierge.repository.ConciergeRepository;
import org.junit.jupiter.api.BeforeEach;
import org.mockito.Mockito;
Expand Down Expand Up @@ -38,7 +39,7 @@ void setup() {
conciergeRepository = Mockito.mock(ConciergeRepository.class);
processorFactory = Mockito.mock(ProcessorFactory.class);
eventProcessor = Mockito.mock(EventProcessor.class);
Mockito.when(processorFactory.getProcessor(Mockito.any(ConfigEvent.class)))
Mockito.when(processorFactory.getProcessor(Mockito.any(ProcessorKey.class)))
.thenReturn(Optional.of(eventProcessor));
conciergeProcessor = createConciergeProcessor();
}
Expand Down
2 changes: 1 addition & 1 deletion concierge-dw/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.grookage.concierge</groupId>
<artifactId>concierge-parent</artifactId>
<version>0.0.1-RC1</version>
<version>0.0.1-RC2</version>
<relativePath>../concierge-parent</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public class IngestionResource<U extends ConfigUpdater> {
@ExceptionMetered
@Path("/add")
public ConfigDetails addConfig(@Context HttpHeaders headers,
@Valid final ConfigurationRequest configurationRequest) {
@Valid final ConfigurationRequest configurationRequest) {
final var updater = updaterResolver.get().resolve(headers);
permissionValidatorSupplier.get().authorize(headers, updater, configurationRequest);
return ingestionService.createConfiguration(updater, configurationRequest);
Expand All @@ -71,7 +71,7 @@ public ConfigDetails addConfig(@Context HttpHeaders headers,
@ExceptionMetered
@Path("/update")
public ConfigDetails updateConfig(@Context HttpHeaders headers,
@Valid final UpdateConfigRequest updateRequest) {
@Valid final UpdateConfigRequest updateRequest) {
final var updater = updaterResolver.get().resolve(headers);
permissionValidatorSupplier.get().authorize(headers, updater, updateRequest);
return ingestionService.updateConfiguration(updater, updateRequest);
Expand All @@ -82,7 +82,7 @@ public ConfigDetails updateConfig(@Context HttpHeaders headers,
@ExceptionMetered
@Path("/approve")
public ConfigDetails approveConfig(@Context HttpHeaders headers,
@Valid final ConfigKey configKey) {
@Valid final ConfigKey configKey) {
final var updater = updaterResolver.get().resolve(headers);
permissionValidatorSupplier.get().authorizeApproval(headers, updater, configKey);
return ingestionService.approveConfiguration(updater, configKey);
Expand All @@ -93,7 +93,7 @@ public ConfigDetails approveConfig(@Context HttpHeaders headers,
@ExceptionMetered
@Path("/reject")
public ConfigDetails rejectConfig(@Context HttpHeaders headers,
@Valid final ConfigKey configKey) {
@Valid final ConfigKey configKey) {
final var updater = updaterResolver.get().resolve(headers);
permissionValidatorSupplier.get().authorizeRejection(headers, updater, configKey);
return ingestionService.rejectConfiguration(updater, configKey);
Expand All @@ -104,7 +104,7 @@ public ConfigDetails rejectConfig(@Context HttpHeaders headers,
@ExceptionMetered
@Path("/activate")
public ConfigDetails activateConfig(@Context HttpHeaders headers,
@Valid final ConfigKey configKey) {
@Valid final ConfigKey configKey) {
final var updater = updaterResolver.get().resolve(headers);
permissionValidatorSupplier.get().authorizeActivation(headers, updater, configKey);
return ingestionService.activateConfiguration(updater, configKey);
Expand Down
2 changes: 1 addition & 1 deletion concierge-elastic-dw/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.grookage.concierge</groupId>
<artifactId>concierge-parent</artifactId>
<version>0.0.1-RC1</version>
<version>0.0.1-RC2</version>
<relativePath>../concierge-parent</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion concierge-elastic/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.grookage.concierge</groupId>
<artifactId>concierge-parent</artifactId>
<version>0.0.1-RC1</version>
<version>0.0.1-RC2</version>
<relativePath>../concierge-parent</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import com.grookage.concierge.models.config.ConfigState;
import com.grookage.concierge.repository.AbstractConciergeRepository;
import com.grookage.concierge.repository.cache.CacheConfig;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.SneakyThrows;

Expand All @@ -46,6 +47,7 @@
import java.util.stream.Collectors;

@Getter
@EqualsAndHashCode(callSuper = true)
public class ElasticRepository extends AbstractConciergeRepository {

private static final String CONFIG_INDEX = "config_registry";
Expand Down
2 changes: 1 addition & 1 deletion concierge-models/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.grookage.concierge</groupId>
<artifactId>concierge-parent</artifactId>
<version>0.0.1-RC1</version>
<version>0.0.1-RC2</version>
<relativePath>../concierge-parent</relativePath>
</parent>

Expand Down
Loading

0 comments on commit 42dc622

Please sign in to comment.