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

Feature/self inject storage into permission owners #2101

Merged
merged 38 commits into from
Sep 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
c48d174
inject storage into permission owner
thoniTUB Sep 7, 2021
f47c982
Merge branch 'feature/simplify-storage-typing' into feature/self-inje…
thoniTUB Sep 21, 2021
8904ff9
use an injectable storageUpdater instead of the storage it self
thoniTUB Sep 21, 2021
c478068
fix serialization
thoniTUB Sep 21, 2021
ec34339
Update AutoDoc
github-actions[bot] Sep 21, 2021
45f7dc3
pull up store updater
thoniTUB Sep 21, 2021
18f2752
review changes
thoniTUB Sep 21, 2021
4c76604
Revert "use an injectable storageUpdater instead of the storage it self"
thoniTUB Sep 22, 2021
7c85622
capsule storage for group and role handling
thoniTUB Sep 9, 2021
c05d178
fix serialization
thoniTUB Sep 22, 2021
ba83a47
check for all stores in a namespaces storage
thoniTUB Sep 22, 2021
71ffe95
check namespaced storages for stores
thoniTUB Sep 22, 2021
11811a2
Merge remote-tracking branch 'origin/develop' into feature/self-injec…
thoniTUB Sep 22, 2021
0ad7a65
Update AutoDoc
github-actions[bot] Sep 22, 2021
64c0e46
review changes
thoniTUB Sep 22, 2021
7f9e942
Update AutoDoc
github-actions[bot] Sep 22, 2021
abfeff4
Update backend/src/main/java/com/bakdata/conquery/apiv1/auth/ProtoUse…
thoniTUB Sep 23, 2021
66274e8
move auth registration method to AuthorizationHelper.java
thoniTUB Sep 23, 2021
f4945e5
review changes
thoniTUB Sep 23, 2021
872d47f
Update AutoDoc
github-actions[bot] Sep 23, 2021
368a133
adds JsonIgnore to ProtoUser.java
thoniTUB Sep 23, 2021
2f9c5bb
split phase for instantiation and loading of MetaStorage.java to enab…
thoniTUB Sep 23, 2021
849164f
remove validator from MetaStorage
thoniTUB Sep 23, 2021
7148fcd
Update AutoDoc
github-actions[bot] Sep 23, 2021
92e098f
fix SerializationTests for TreeConcept
thoniTUB Sep 23, 2021
6a6f19b
removes inject propagation from stores
thoniTUB Sep 23, 2021
417c0b1
fix GroovyIndexedTest: prep serdes
thoniTUB Sep 23, 2021
a91e91b
add comment
thoniTUB Sep 23, 2021
6b43e0b
Merge remote-tracking branch 'origin/develop' into self-inject-storag…
thoniTUB Sep 28, 2021
0d157fa
add documentation
thoniTUB Sep 27, 2021
d93c097
fix loading of executions and FormConfigs
thoniTUB Sep 28, 2021
f37f259
removes comment
thoniTUB Sep 28, 2021
477ccd1
Update AutoDoc
github-actions[bot] Sep 28, 2021
22379fe
adds comment about checking the storages
thoniTUB Sep 28, 2021
2e9bf07
revert clean shutdown because of port binding problems
thoniTUB Sep 28, 2021
753ffa9
fix removing of datasets in restart test and repeated closing of stores
thoniTUB Sep 28, 2021
8067cf7
Update AutoDoc
github-actions[bot] Sep 28, 2021
62ba406
makes exception to warning
thoniTUB Sep 28, 2021
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 @@ -47,7 +47,7 @@ protected void configure() {
bind(new ConceptsProcessor(manager.getDatasetRegistry())).to(ConceptsProcessor.class);
bind(new MeProcessor(manager.getStorage(), datasets)).to(MeProcessor.class);
bind(new QueryProcessor(datasets, manager.getStorage(), manager.getConfig())).to(QueryProcessor.class);
bind(new FormConfigProcessor(manager.getValidator(), manager.getStorage())).to(FormConfigProcessor.class);
bind(new FormConfigProcessor(manager.getValidator(), manager.getStorage(), datasets)).to(FormConfigProcessor.class);
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.util.function.Consumer;

import com.bakdata.conquery.io.storage.MetaStorage;
import com.bakdata.conquery.models.auth.AuthorizationHelper;
import com.bakdata.conquery.models.auth.entities.User;
import com.bakdata.conquery.models.auth.permissions.Ability;
import com.bakdata.conquery.models.forms.configs.FormConfig;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import java.util.function.Consumer;

import com.bakdata.conquery.io.storage.MetaStorage;
import com.bakdata.conquery.models.auth.AuthorizationHelper;
import com.bakdata.conquery.models.auth.entities.Group;
import com.bakdata.conquery.models.auth.entities.User;
import com.bakdata.conquery.models.auth.permissions.Ability;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.Set;

import javax.validation.Valid;
Expand All @@ -13,12 +14,15 @@
import com.bakdata.conquery.models.auth.basic.LocalAuthenticationRealm;
import com.bakdata.conquery.models.auth.entities.User;
import com.bakdata.conquery.models.auth.permissions.WildcardPermission;
import com.bakdata.conquery.models.identifiable.ids.specific.UserId;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Builder;
import lombok.Getter;
import lombok.NonNull;

/**
* Container class for holding information about initial users.
* Factory class to create configured initial users.

*/
@Getter
@Builder
Expand All @@ -45,39 +49,21 @@ public class ProtoUser {
@NotNull
@Valid
private List<CredentialType> credentials = Collections.emptyList();

@JsonIgnore
// Let this be ignored by the builder
private User user = null;

public User getUser() {
if(user != null) {
return user;
}
public User createOrOverwriteUser(@NonNull MetaStorage storage) {
if (label == null) {
label = name;
}
user = new User(name, label);
return user;
}

public void registerForAuthorization(MetaStorage storage, boolean override) {
User user = this.getUser();
if(override) {
storage.updateUser(user);
} else {
// Should throw an exception, if the user already existed
storage.addUser(user);
}
User user = new User(name, label, storage);
storage.updateUser(user);
for (String sPermission : permissions) {
user.addPermission(storage, new WildcardPermission(sPermission));
user.addPermission(new WildcardPermission(sPermission));
}
return user;
}

public boolean registerForAuthentication(UserManageable userManager, boolean override) {
if(override) {
return userManager.updateUser(getUser(), credentials);
}
return userManager.addUser(getUser(), credentials);

@JsonIgnore
public UserId createId() {
return new UserId(name);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.Set;
import java.util.stream.Collectors;

import com.bakdata.conquery.apiv1.query.concept.specific.external.CQExternal;
import com.bakdata.conquery.io.cps.CPSBase;
import com.bakdata.conquery.io.jackson.InternalOnly;
import com.bakdata.conquery.models.auth.entities.User;
Expand All @@ -16,7 +17,6 @@
import com.bakdata.conquery.models.identifiable.ids.NamespacedIdentifiable;
import com.bakdata.conquery.models.query.QueryResolveContext;
import com.bakdata.conquery.models.query.Visitable;
import com.bakdata.conquery.apiv1.query.concept.specific.external.CQExternal;
import com.bakdata.conquery.models.query.visitor.QueryVisitor;
import com.bakdata.conquery.models.worker.DatasetRegistry;
import com.bakdata.conquery.util.QueryUtils;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import com.bakdata.conquery.io.cps.CPSTypeIdResolver;
import com.bakdata.conquery.io.jackson.InternalOnly;
import com.bakdata.conquery.io.jackson.Jackson;
import com.bakdata.conquery.io.jackson.MutableInjectableValues;
import com.bakdata.conquery.io.jersey.RESTServer;
import com.bakdata.conquery.io.mina.BinaryJacksonCoder;
import com.bakdata.conquery.io.mina.CQProtocolCodecFilter;
Expand All @@ -33,7 +32,6 @@
import com.bakdata.conquery.models.messages.network.MessageToManagerNode;
import com.bakdata.conquery.models.messages.network.NetworkMessageContext;
import com.bakdata.conquery.models.worker.DatasetRegistry;
import com.bakdata.conquery.models.worker.IdResolveContext;
import com.bakdata.conquery.models.worker.Namespace;
import com.bakdata.conquery.models.worker.Worker;
import com.bakdata.conquery.resources.ResourcesProvider;
Expand Down Expand Up @@ -104,11 +102,13 @@ public ManagerNode(@NonNull String name) {
public void run(ConqueryConfig config, Environment environment) throws InterruptedException {
client = new JerseyClientBuilder(environment).using(config.getJerseyClient())
.build(getName());

// Instantiate DatasetRegistry and MetaStorage so they are ready for injection into the object mapper (API + Storage)
datasetRegistry = new DatasetRegistry(config.getCluster().getEntityBucketSize());
storage = new MetaStorage(datasetRegistry);

//inject datasets into the objectmapper
((MutableInjectableValues) environment.getObjectMapper().getInjectableValues())
.add(IdResolveContext.class, datasetRegistry);
datasetRegistry.injectInto(environment.getObjectMapper());
storage.injectInto(environment.getObjectMapper());


jobManager = new JobManager("ManagerNode", config.isFailOnError());
Expand Down Expand Up @@ -183,8 +183,9 @@ public void run(ConqueryConfig config, Environment environment) throws Interrupt
}

private void loadMetaStorage() {
log.info("Started meta storage");
storage = new MetaStorage(validator, config.getStorage(), datasetRegistry);
log.info("Opening MetaStorage");
storage.openStores(config.getStorage());
awildturtok marked this conversation as resolved.
Show resolved Hide resolved
log.info("Loading MetaStorage");
storage.loadData();
log.info("MetaStorage loaded {}", storage);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import javax.validation.Validator;

import com.bakdata.conquery.io.jackson.Jackson;
import com.bakdata.conquery.io.jackson.MutableInjectableValues;
import com.bakdata.conquery.io.mina.BinaryJacksonCoder;
import com.bakdata.conquery.io.mina.CQProtocolCodecFilter;
import com.bakdata.conquery.io.mina.ChunkReader;
Expand Down Expand Up @@ -98,11 +99,14 @@ protected void run(Environment environment, Namespace namespace, ConqueryConfig

scheduler.scheduleAtFixedRate(this::reportJobManagerStatus, 30, 1, TimeUnit.SECONDS);


final ObjectMapper binaryMapper = config.configureObjectMapper(Jackson.BINARY_MAPPER);
((MutableInjectableValues) binaryMapper.getInjectableValues()).add(Validator.class, environment.getValidator());

workers = new Workers(
getConfig().getQueries().getExecutionPool(),
config.configureObjectMapper(Jackson.MAPPER),
config.configureObjectMapper(Jackson.BINARY_MAPPER)
, getConfig().getCluster().getEntityBucketSize()
binaryMapper,
getConfig().getCluster().getEntityBucketSize()
);

final Collection<WorkerStorage> workerStorages = config.getStorage().loadWorkerStorages();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import io.dropwizard.setup.Bootstrap;
import io.dropwizard.setup.Environment;
import lombok.Getter;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import net.sourceforge.argparse4j.inf.Namespace;

Expand Down Expand Up @@ -130,6 +131,5 @@ protected void startStandalone(Environment environment, Namespace namespace, Con
log.debug("Starting REST Server");
ConqueryMDC.setLocation(null);
super.run(environment, namespace, config);
manager = conquery.getManager();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
*/
public interface Injectable {

default ObjectReader injectInto(ObjectReader reader) {
/**
* See {@link Injectable#injectIntoNew(ObjectMapper)}
*/
default ObjectReader injectIntoNew(ObjectReader reader) {
// If is already MutableInjectable, add my values to other, else begin from scratch.
if (reader.getInjectableValues() instanceof MutableInjectableValues) {
return reader.with(inject(((MutableInjectableValues) reader.getInjectableValues()).copy()));
Expand All @@ -17,16 +20,35 @@ default ObjectReader injectInto(ObjectReader reader) {
return reader.with(inject(new MutableInjectableValues()));
}

default ObjectMapper injectInto(ObjectMapper mapper) {
/**
* Creates a copy of the provided mapper and its injected values and adds the caller to the new copy
* @param mapper the blueprint mapper to use which remains untouched
* @return a new mapper with this injected
*/
default ObjectMapper injectIntoNew(ObjectMapper mapper) {
awildturtok marked this conversation as resolved.
Show resolved Hide resolved
// If is already MutableInjectable, add my values to other, else begin from scratch.

if (mapper.getInjectableValues() instanceof MutableInjectableValues) {
return mapper.copy()
.setInjectableValues(inject(((MutableInjectableValues) mapper.getInjectableValues()).copy()));
}
// TODO unsure if overriding is expected here from the user
return mapper.copy()
.setInjectableValues(inject(new MutableInjectableValues()));
}

/**
* Injects this to the provided mapper and returns the mapper
*/
default ObjectMapper injectInto(ObjectMapper mapper) {
// If is already MutableInjectable, add my values to other, else begin from scratch.

if (mapper.getInjectableValues() instanceof MutableInjectableValues) {
mapper.setInjectableValues(inject(((MutableInjectableValues) mapper.getInjectableValues())));
return mapper;
}
throw new IllegalStateException("Cannot add additional injectables if the mapper does not provide MutableInjectableValues");
}

MutableInjectableValues inject(MutableInjectableValues values);
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static class Modifier extends ObjectReaderModifier implements Injectable

@Override
public ObjectReader modify(EndpointConfigBase<?> endpoint, MultivaluedMap<String, String> httpHeaders, JavaType resultType, ObjectReader reader, JsonParser p) throws IOException {
return this.injectInto(reader);
return this.injectIntoNew(reader);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public BinaryJacksonCoder(IdResolveContext datasets, Validator validator, Object
.writerFor(NetworkMessage.class)
.withView(InternalOnly.class);
this.reader = datasets
.injectInto(objectMapper.readerFor(NetworkMessage.class))
.injectIntoNew(objectMapper.readerFor(NetworkMessage.class))
.without(Feature.AUTO_CLOSE_SOURCE)
.withView(InternalOnly.class);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
package com.bakdata.conquery.io.result.arrow;

import static com.bakdata.conquery.io.result.arrow.ResultArrowProcessor.getArrowResult;
import static com.bakdata.conquery.resources.ResourceConstants.FILE_EXTENTION_ARROW_FILE;

import java.nio.channels.Channels;

import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import com.bakdata.conquery.models.auth.entities.User;
import com.bakdata.conquery.models.config.ConqueryConfig;
import com.bakdata.conquery.models.datasets.Dataset;
Expand All @@ -10,13 +18,6 @@
import org.apache.arrow.vector.dictionary.DictionaryProvider;
import org.apache.arrow.vector.ipc.ArrowFileWriter;

import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.nio.channels.Channels;

import static com.bakdata.conquery.io.result.arrow.ResultArrowProcessor.getArrowResult;
import static com.bakdata.conquery.resources.ResourceConstants.FILE_EXTENTION_ARROW_FILE;

@RequiredArgsConstructor
public class ResultArrowFileProcessor {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import java.util.Locale;
import java.util.function.Function;

import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.StreamingOutput;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
package com.bakdata.conquery.io.result.arrow;

import static com.bakdata.conquery.io.result.arrow.ResultArrowProcessor.getArrowResult;
import static com.bakdata.conquery.resources.ResourceConstants.FILE_EXTENTION_ARROW_STREAM;

import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import com.bakdata.conquery.models.auth.entities.User;
import com.bakdata.conquery.models.config.ConqueryConfig;
import com.bakdata.conquery.models.datasets.Dataset;
Expand All @@ -10,12 +16,6 @@
import org.apache.arrow.vector.dictionary.DictionaryProvider;
import org.apache.arrow.vector.ipc.ArrowStreamWriter;

import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import static com.bakdata.conquery.io.result.arrow.ResultArrowProcessor.getArrowResult;
import static com.bakdata.conquery.resources.ResourceConstants.FILE_EXTENTION_ARROW_STREAM;

@RequiredArgsConstructor
public class ResultArrowStreamProcessor {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package com.bakdata.conquery.io.result.excel;

import com.bakdata.conquery.io.result.ResultUtil;
import static com.bakdata.conquery.io.result.ResultUtil.makeResponseWithFileName;

import java.util.Locale;

import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.StreamingOutput;

import com.bakdata.conquery.io.result.ResultUtil;
import com.bakdata.conquery.models.auth.entities.User;
import com.bakdata.conquery.models.auth.permissions.Ability;
import com.bakdata.conquery.models.config.ConqueryConfig;
Expand All @@ -23,12 +24,6 @@
import com.bakdata.conquery.util.io.ConqueryMDC;
import lombok.RequiredArgsConstructor;

import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.StreamingOutput;

import static com.bakdata.conquery.io.result.ResultUtil.makeResponseWithFileName;

@RequiredArgsConstructor
public class ResultExcelProcessor {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@

import javax.validation.Validator;

import com.bakdata.conquery.models.config.StoreFactory;
import com.bakdata.conquery.models.identifiable.CentralRegistry;

public interface ConqueryStorage extends Closeable {

Validator getValidator();
CentralRegistry getCentralRegistry();

void openStores(StoreFactory storageFactory);

void loadData();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,8 @@
@Accessors(fluent=true) @Setter @Getter
public class IdentifiableCachedStore<VALUE extends Identifiable<?>> extends IdentifiableStore<VALUE> {

public IdentifiableCachedStore(CentralRegistry centralRegistry, Store<IId<VALUE>, VALUE> store, Injectable... injectables) {
public IdentifiableCachedStore(CentralRegistry centralRegistry, Store<IId<VALUE>, VALUE> store) {
super(store, centralRegistry);
for(Injectable injectable : injectables) {
store.inject(injectable);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public abstract class IdentifiableStore<VALUE extends Identifiable<?>> extends K

public IdentifiableStore(Store<IId<VALUE>, VALUE> store, CentralRegistry centralRegistry) {
super(store);
store.inject(centralRegistry);
this.centralRegistry = centralRegistry;
}

Expand Down
Loading