You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@unomi.apache.org by ta...@apache.org on 2021/02/04 17:31:58 UTC
[unomi] 01/01: try fix IT
This is an automated email from the ASF dual-hosted git repository.
taybou pushed a commit to branch IT
in repository https://gitbox.apache.org/repos/asf/unomi.git
commit f54cfa45ba01cfb3fdcc29da14e85cda78dc8915
Author: Taybou <be...@gmail.com>
AuthorDate: Thu Feb 4 18:31:39 2021 +0100
try fix IT
---
.../unomi/graphql/schema/GraphQLSchemaUpdater.java | 349 +--------------------
...aUpdater.java => GraphQLSchemaUpdaterImpl.java} | 33 +-
.../apache/unomi/itests/graphql/BaseGraphQLIT.java | 9 +
.../unomi/itests/graphql/GraphQLSegmentIT.java | 1 +
4 files changed, 38 insertions(+), 354 deletions(-)
diff --git a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/schema/GraphQLSchemaUpdater.java b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/schema/GraphQLSchemaUpdater.java
index 73a7712..2c85132 100644
--- a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/schema/GraphQLSchemaUpdater.java
+++ b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/schema/GraphQLSchemaUpdater.java
@@ -17,353 +17,14 @@
package org.apache.unomi.graphql.schema;
import graphql.GraphQL;
-import graphql.execution.SubscriptionExecutionStrategy;
-import graphql.schema.GraphQLCodeRegistry;
import graphql.schema.GraphQLSchema;
-import org.apache.unomi.api.services.EventTypeRegistry;
-import org.apache.unomi.api.services.ProfileService;
-import org.apache.unomi.graphql.fetchers.event.UnomiEventPublisher;
-import org.apache.unomi.graphql.providers.GraphQLAdditionalTypesProvider;
-import org.apache.unomi.graphql.providers.GraphQLCodeRegistryProvider;
-import org.apache.unomi.graphql.providers.GraphQLExtensionsProvider;
-import org.apache.unomi.graphql.providers.GraphQLFieldVisibilityProvider;
-import org.apache.unomi.graphql.providers.GraphQLMutationProvider;
-import org.apache.unomi.graphql.providers.GraphQLProvider;
-import org.apache.unomi.graphql.providers.GraphQLQueryProvider;
-import org.apache.unomi.graphql.providers.GraphQLSubscriptionProvider;
-import org.apache.unomi.graphql.providers.GraphQLTypeFunctionProvider;
-import org.apache.unomi.graphql.types.output.CDPEventInterface;
-import org.apache.unomi.graphql.types.output.CDPPersona;
-import org.apache.unomi.graphql.types.output.CDPProfile;
-import org.apache.unomi.graphql.types.output.CDPProfileInterface;
-import org.apache.unomi.graphql.types.output.CDPPropertyInterface;
-import org.osgi.service.component.annotations.Activate;
-import org.osgi.service.component.annotations.Component;
-import org.osgi.service.component.annotations.Deactivate;
-import org.osgi.service.component.annotations.Reference;
-import org.osgi.service.component.annotations.ReferenceCardinality;
-import org.osgi.service.component.annotations.ReferencePolicy;
-import org.osgi.service.component.annotations.ReferencePolicyOption;
-import java.util.List;
-import java.util.concurrent.CopyOnWriteArrayList;
-import java.util.concurrent.Executors;
-import java.util.concurrent.ScheduledExecutorService;
-import java.util.concurrent.ScheduledFuture;
-import java.util.concurrent.TimeUnit;
+public interface GraphQLSchemaUpdater {
+ boolean isSchemaUpdating();
-@Component(service = GraphQLSchemaUpdater.class)
-public class GraphQLSchemaUpdater {
+ void updateSchema();
- public @interface SchemaConfig {
-
- int schema_update_delay() default 0;
-
- }
-
- private final List<GraphQLQueryProvider> queryProviders = new CopyOnWriteArrayList<>();
-
- private final List<GraphQLMutationProvider> mutationProviders = new CopyOnWriteArrayList<>();
-
- private final List<GraphQLSubscriptionProvider> subscriptionProviders = new CopyOnWriteArrayList<>();
-
- private final List<GraphQLExtensionsProvider> extensionsProviders = new CopyOnWriteArrayList<>();
-
- private final List<GraphQLAdditionalTypesProvider> additionalTypesProviders = new CopyOnWriteArrayList<>();
-
- private final List<GraphQLTypeFunctionProvider> typeFunctionProviders = new CopyOnWriteArrayList<>();
-
- private GraphQLFieldVisibilityProvider fieldVisibilityProvider;
-
- private GraphQLCodeRegistryProvider codeRegistryProvider;
-
- private UnomiEventPublisher eventPublisher;
-
- private GraphQL graphQL;
-
- private ProfileService profileService;
-
- private EventTypeRegistry eventTypeRegistry;
-
- private CDPEventInterfaceRegister eventInterfaceRegister;
-
- private CDPProfileInterfaceRegister profilesInterfaceRegister;
-
- private CDPPropertyInterfaceRegister propertyInterfaceRegister;
-
- private ScheduledExecutorService executorService;
-
- private ScheduledFuture<?> updateFuture;
-
- private boolean isActivated;
-
- private int schemaUpdateDelay;
-
- @Activate
- public void activate(final SchemaConfig config) {
- this.isActivated = true;
- this.schemaUpdateDelay = config.schema_update_delay();
-
- if (config.schema_update_delay() != 0) {
- this.executorService = Executors.newSingleThreadScheduledExecutor();
- }
-
- updateSchema();
- }
-
- @Deactivate
- public void deactivate() {
- this.isActivated = false;
-
- if (executorService != null) {
- executorService.shutdown();
- }
- }
-
- @Reference
- public void setEventPublisher(UnomiEventPublisher eventPublisher) {
- this.eventPublisher = eventPublisher;
- }
-
- @Reference
- public void setProfileService(ProfileService profileService) {
- this.profileService = profileService;
- }
-
- @Reference
- public void setEventTypeRegistry(EventTypeRegistry eventTypeRegistry) {
- this.eventTypeRegistry = eventTypeRegistry;
- }
-
- @Reference
- public void setEventInterfaceRegister(CDPEventInterfaceRegister eventInterfaceRegister) {
- this.eventInterfaceRegister = eventInterfaceRegister;
- }
-
- @Reference
- public void setProfilesInterfaceRegister(CDPProfileInterfaceRegister profilesInterfaceRegister) {
- this.profilesInterfaceRegister = profilesInterfaceRegister;
- }
-
- @Reference
- public void setPropertiesInterfaceRegister(CDPPropertyInterfaceRegister propertyInterfaceRegister) {
- this.propertyInterfaceRegister = propertyInterfaceRegister;
- }
-
- @Reference(cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC)
- public void bindProvider(GraphQLProvider provider) {
- if (provider instanceof GraphQLQueryProvider) {
- queryProviders.add((GraphQLQueryProvider) provider);
- }
- if (provider instanceof GraphQLMutationProvider) {
- mutationProviders.add((GraphQLMutationProvider) provider);
- }
- if (provider instanceof GraphQLSubscriptionProvider) {
- subscriptionProviders.add((GraphQLSubscriptionProvider) provider);
- }
- if (provider instanceof GraphQLAdditionalTypesProvider) {
- additionalTypesProviders.add((GraphQLAdditionalTypesProvider) provider);
- }
- if (provider instanceof GraphQLFieldVisibilityProvider) {
- fieldVisibilityProvider = (GraphQLFieldVisibilityProvider) provider;
- }
- if (provider instanceof GraphQLCodeRegistryProvider) {
- codeRegistryProvider = (GraphQLCodeRegistryProvider) provider;
- }
- updateSchema();
- }
-
- public void unbindProvider(GraphQLProvider provider) {
- if (provider instanceof GraphQLQueryProvider) {
- queryProviders.remove(provider);
- }
- if (provider instanceof GraphQLMutationProvider) {
- mutationProviders.remove(provider);
- }
- if (provider instanceof GraphQLSubscriptionProvider) {
- subscriptionProviders.remove(provider);
- }
- if (provider instanceof GraphQLAdditionalTypesProvider) {
- additionalTypesProviders.remove(provider);
- }
- if (provider instanceof GraphQLFieldVisibilityProvider) {
- fieldVisibilityProvider = null;
- }
- if (provider instanceof GraphQLCodeRegistryProvider) {
- codeRegistryProvider = GraphQLCodeRegistry::newCodeRegistry;
- }
- updateSchema();
- }
-
- @Reference(cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC)
- public void bindQueryProvider(GraphQLQueryProvider provider) {
- queryProviders.add(provider);
-
- updateSchema();
- }
-
- public void unbindQueryProvider(GraphQLQueryProvider provider) {
- queryProviders.remove(provider);
-
- updateSchema();
- }
-
- @Reference(cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC)
- public void bindMutationProvider(GraphQLMutationProvider provider) {
- mutationProviders.add(provider);
-
- updateSchema();
- }
-
- public void unbindMutationProvider(GraphQLMutationProvider provider) {
- mutationProviders.remove(provider);
-
- updateSchema();
- }
-
- @Reference(cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC)
- public void bindSubscriptionProvider(GraphQLSubscriptionProvider provider) {
- subscriptionProviders.add(provider);
-
- updateSchema();
- }
-
- public void unbindSubscriptionProvider(GraphQLSubscriptionProvider provider) {
- subscriptionProviders.remove(provider);
-
- updateSchema();
- }
-
-
- @Reference(cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC)
- public void bindFieldVisibilityProvider(GraphQLFieldVisibilityProvider provider) {
- fieldVisibilityProvider = provider;
-
- updateSchema();
- }
-
- public void unbindFieldVisibilityProvider(GraphQLFieldVisibilityProvider provider) {
- fieldVisibilityProvider = null;
-
- updateSchema();
- }
-
- @Reference(cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC)
- public void bindExtensionsProvider(GraphQLExtensionsProvider provider) {
- extensionsProviders.add(provider);
-
- updateSchema();
- }
-
- public void unbindExtensionsProvider(GraphQLExtensionsProvider provider) {
- extensionsProviders.remove(provider);
-
- updateSchema();
- }
-
- @Reference(cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC)
- public void bindAdditionalTypes(GraphQLAdditionalTypesProvider provider) {
- additionalTypesProviders.add(provider);
-
- updateSchema();
- }
-
- public void unbindAdditionalTypes(GraphQLAdditionalTypesProvider provider) {
- additionalTypesProviders.remove(provider);
-
- updateSchema();
- }
-
- @Reference(cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC)
- public void bindTypeFunctionProviders(GraphQLTypeFunctionProvider typeFunctionProvider) {
- this.typeFunctionProviders.add(typeFunctionProvider);
-
- updateSchema();
- }
-
- public void unbindTypeFunctionProviders(GraphQLTypeFunctionProvider typeFunctionProvider) {
- typeFunctionProviders.remove(typeFunctionProvider);
-
- updateSchema();
- }
-
- @Reference(cardinality = ReferenceCardinality.OPTIONAL, policy = ReferencePolicy.DYNAMIC, policyOption = ReferencePolicyOption.GREEDY)
- public void bindCodeRegistryProvider(GraphQLCodeRegistryProvider codeRegistryProvider) {
- this.codeRegistryProvider = codeRegistryProvider;
-
- updateSchema();
- }
-
- public void unbindCodeRegistryProvider(GraphQLCodeRegistryProvider codeRegistryProvider) {
- this.codeRegistryProvider = null;
-
- updateSchema();
- }
-
- public void updateSchema() {
- if (!isActivated) {
- return;
- }
-
- if (schemaUpdateDelay == 0) {
- doUpdateSchema();
- } else {
- if (updateFuture != null) {
- updateFuture.cancel(true);
- }
-
- updateFuture = executorService.scheduleWithFixedDelay(this::doUpdateSchema, 0, schemaUpdateDelay, TimeUnit.SECONDS);
- }
- }
-
- private void doUpdateSchema() {
- final GraphQLSchema graphQLSchema = createGraphQLSchema();
-
- this.graphQL = GraphQL.newGraphQL(graphQLSchema)
- .subscriptionExecutionStrategy(new SubscriptionExecutionStrategy())
- .build();
- }
-
- public GraphQL getGraphQL() {
- return graphQL;
- }
-
- @SuppressWarnings("unchecked")
- private GraphQLSchema createGraphQLSchema() {
- final GraphQLSchemaProvider schemaProvider = GraphQLSchemaProvider.create(profileService, eventTypeRegistry)
- .typeFunctionProviders(typeFunctionProviders)
- .extensionsProviders(extensionsProviders)
- .additionalTypesProviders(additionalTypesProviders)
- .queryProviders(queryProviders)
- .mutationProviders(mutationProviders)
- .subscriptionProviders(subscriptionProviders)
- .eventPublisher(eventPublisher)
- .codeRegistryProvider(codeRegistryProvider)
- .fieldVisibilityProvider(fieldVisibilityProvider)
- .build();
-
- final GraphQLSchema schema = schemaProvider.createSchema();
-
- profilesInterfaceRegister.register(CDPProfile.class);
- profilesInterfaceRegister.register(CDPPersona.class);
-
- if (schemaProvider.getAdditionalTypes() != null && !schemaProvider.getAdditionalTypes().isEmpty()) {
- schemaProvider.getAdditionalTypes().forEach(additionalType -> {
- if (CDPEventInterface.class.isAssignableFrom(additionalType)) {
- eventInterfaceRegister.register((Class<? extends CDPEventInterface>) additionalType);
- }
-
- if (CDPProfileInterface.class.isAssignableFrom(additionalType)) {
- profilesInterfaceRegister.register((Class<? extends CDPProfileInterface>) additionalType);
- }
-
- if (CDPPropertyInterface.class.isAssignableFrom(additionalType)) {
- propertyInterfaceRegister.register((Class<? extends CDPPropertyInterface>) additionalType);
- }
- });
- }
-
- return schema;
- }
+ GraphQL getGraphQL();
+ GraphQLSchema createGraphQLSchema();
}
diff --git a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/schema/GraphQLSchemaUpdater.java b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/schema/GraphQLSchemaUpdaterImpl.java
similarity index 97%
copy from graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/schema/GraphQLSchemaUpdater.java
copy to graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/schema/GraphQLSchemaUpdaterImpl.java
index 73a7712..383c17c 100644
--- a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/schema/GraphQLSchemaUpdater.java
+++ b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/schema/GraphQLSchemaUpdaterImpl.java
@@ -53,7 +53,7 @@ import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
@Component(service = GraphQLSchemaUpdater.class)
-public class GraphQLSchemaUpdater {
+public class GraphQLSchemaUpdaterImpl implements GraphQLSchemaUpdater {
public @interface SchemaConfig {
@@ -99,6 +99,8 @@ public class GraphQLSchemaUpdater {
private int schemaUpdateDelay;
+ private boolean schemaUpdating;
+
@Activate
public void activate(final SchemaConfig config) {
this.isActivated = true;
@@ -300,6 +302,12 @@ public class GraphQLSchemaUpdater {
updateSchema();
}
+ @Override
+ public boolean isSchemaUpdating() {
+ return schemaUpdating;
+ }
+
+ @Override
public void updateSchema() {
if (!isActivated) {
return;
@@ -316,20 +324,14 @@ public class GraphQLSchemaUpdater {
}
}
- private void doUpdateSchema() {
- final GraphQLSchema graphQLSchema = createGraphQLSchema();
-
- this.graphQL = GraphQL.newGraphQL(graphQLSchema)
- .subscriptionExecutionStrategy(new SubscriptionExecutionStrategy())
- .build();
- }
-
+ @Override
public GraphQL getGraphQL() {
return graphQL;
}
@SuppressWarnings("unchecked")
- private GraphQLSchema createGraphQLSchema() {
+ @Override
+ public GraphQLSchema createGraphQLSchema() {
final GraphQLSchemaProvider schemaProvider = GraphQLSchemaProvider.create(profileService, eventTypeRegistry)
.typeFunctionProviders(typeFunctionProviders)
.extensionsProviders(extensionsProviders)
@@ -366,4 +368,15 @@ public class GraphQLSchemaUpdater {
return schema;
}
+ private void doUpdateSchema() {
+ schemaUpdating = true;
+ final GraphQLSchema graphQLSchema = createGraphQLSchema();
+
+ this.graphQL = GraphQL.newGraphQL(graphQLSchema)
+ .subscriptionExecutionStrategy(new SubscriptionExecutionStrategy())
+ .build();
+
+ schemaUpdating = false;
+ }
+
}
diff --git a/itests/src/test/java/org/apache/unomi/itests/graphql/BaseGraphQLIT.java b/itests/src/test/java/org/apache/unomi/itests/graphql/BaseGraphQLIT.java
index df3e8b0..d7122ca 100644
--- a/itests/src/test/java/org/apache/unomi/itests/graphql/BaseGraphQLIT.java
+++ b/itests/src/test/java/org/apache/unomi/itests/graphql/BaseGraphQLIT.java
@@ -23,6 +23,7 @@ import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils;
+import org.apache.unomi.graphql.schema.GraphQLSchemaUpdater;
import org.apache.unomi.graphql.utils.GraphQLObjectMapper;
import org.apache.unomi.itests.BaseIT;
import org.apache.unomi.lifecycle.BundleWatcher;
@@ -57,11 +58,19 @@ public abstract class BaseGraphQLIT extends BaseIT {
@Filter(timeout = 600000)
protected BundleWatcher bundleWatcher;
+ @Inject
+ @Filter(timeout = 600000)
+ protected GraphQLSchemaUpdater graphQLSchemaUpdater;
+
@Before
public void setUp() throws InterruptedException {
while (!bundleWatcher.isStartupComplete()) {
Thread.sleep(1000);
}
+
+ while (graphQLSchemaUpdater.isSchemaUpdating()) {
+ Thread.sleep(100);
+ }
}
protected CloseableHttpResponse post(final String resource) throws IOException {
diff --git a/itests/src/test/java/org/apache/unomi/itests/graphql/GraphQLSegmentIT.java b/itests/src/test/java/org/apache/unomi/itests/graphql/GraphQLSegmentIT.java
index be6b536..5ea86b0 100644
--- a/itests/src/test/java/org/apache/unomi/itests/graphql/GraphQLSegmentIT.java
+++ b/itests/src/test/java/org/apache/unomi/itests/graphql/GraphQLSegmentIT.java
@@ -39,6 +39,7 @@ public class GraphQLSegmentIT extends BaseGraphQLIT {
@Before
public void setUp() throws InterruptedException {
+ super.setUp();
removeItems(Segment.class);
}