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

Wildfly client model integration and quickstart (client) #178

Merged
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
138 changes: 138 additions & 0 deletions client-subsystem/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2019 Red Hat, Inc.
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>wildfly-microprofile-graphql-parent</artifactId>
<groupId>org.wildfly.extras.graphql</groupId>
<version>2.4.2.Final-SNAPSHOT</version>
</parent>
<version>2.4.2.Final-SNAPSHOT</version>
<modelVersion>4.0.0</modelVersion>

<artifactId>wildfly-microprofile-graphql-client</artifactId>
<name>WildFly MicroProfile GraphQL - Client Subsystem</name>

<dependencies>
<dependency>
<groupId>io.smallrye</groupId>
<artifactId>smallrye-graphql-servlet</artifactId>
</dependency>
<dependency>
<groupId>io.smallrye</groupId>
<artifactId>smallrye-graphql-cdi</artifactId>
</dependency>
<dependency>
<groupId>io.smallrye</groupId>
<artifactId>smallrye-graphql-schema-builder</artifactId>
</dependency>
<dependency>
<groupId>io.smallrye</groupId>
<artifactId>smallrye-graphql-schema-model</artifactId>
</dependency>
<dependency>
<groupId>io.smallrye</groupId>
<artifactId>smallrye-graphql-client-model</artifactId>
</dependency>
<dependency>
<groupId>io.smallrye</groupId>
<artifactId>smallrye-graphql-client-model-builder</artifactId>
</dependency>
<dependency>
<groupId>io.smallrye</groupId>
<artifactId>smallrye-graphql-client</artifactId>
</dependency>
<dependency>
<groupId>com.graphql-java</groupId>
<artifactId>graphql-java</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging-annotations</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging-processor</artifactId>
<!--
This is a compile-time dependency of this project, but is not needed at compile or runtime by other
projects that depend on this project.
-->
<scope>provided</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.wildfly.core</groupId>
<artifactId>wildfly-controller</artifactId>
</dependency>
<dependency>
<groupId>org.wildfly.core</groupId>
<artifactId>wildfly-server</artifactId>
</dependency>
<dependency>
<groupId>org.wildfly</groupId>
<artifactId>wildfly-ee</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.metadata</groupId>
<artifactId>jboss-metadata-web</artifactId>
</dependency>
<dependency>
<groupId>org.wildfly</groupId>
<artifactId>wildfly-web-common</artifactId>
</dependency>
<dependency>
<groupId>org.wildfly</groupId>
<artifactId>wildfly-weld</artifactId>
</dependency>
<dependency>
<groupId>org.wildfly</groupId>
<artifactId>wildfly-undertow</artifactId>
</dependency>

<dependency>
<groupId>io.smallrye</groupId>
<artifactId>smallrye-graphql</artifactId>
</dependency>
<dependency>
<groupId>jakarta.json.bind</groupId>
<artifactId>jakarta.json.bind-api</artifactId>
</dependency>
<dependency>
<groupId>jakarta.websocket</groupId>
<artifactId>jakarta.websocket-api</artifactId>
</dependency>
<dependency>
<groupId>jakarta.websocket</groupId>
<artifactId>jakarta.websocket-client-api</artifactId>
</dependency>

<dependency>
<groupId>org.wildfly.core</groupId>
<artifactId>wildfly-subsystem-test</artifactId>
<type>pom</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>

</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package org.wildfly.extension.microprofile.graphql.client;

import io.smallrye.graphql.client.model.ClientModels;
import jakarta.enterprise.event.Observes;
import jakarta.enterprise.inject.Any;
import jakarta.enterprise.inject.Default;
import jakarta.enterprise.inject.spi.AfterBeanDiscovery;
import jakarta.enterprise.inject.spi.BeanManager;
import jakarta.enterprise.inject.spi.Extension;
import jakarta.enterprise.util.AnnotationLiteral;
import jakarta.inject.Singleton;

/**
* CDI extension that registers the {@link ClientModels} instance computed by the deployment processor as a singleton bean.
* This allows the {@link ClientModels} instance to be injected into other CDI beans.
*
* @author mskacelik
*/
public class ClientModelsExtension implements Extension {
jmartisk marked this conversation as resolved.
Show resolved Hide resolved

private final ClientModels clientModels;

public ClientModelsExtension() {
this(null);
}

public ClientModelsExtension(ClientModels clientModels) {
this.clientModels = clientModels;
}

void registerClientModelsBean(@Observes AfterBeanDiscovery afterBeanDiscoveryEvent,
BeanManager beanManager) {
afterBeanDiscoveryEvent.addBean()
.types(ClientModels.class)
.qualifiers(new AnnotationLiteral<Default>() {}, new AnnotationLiteral<Any>() {})
.scope(Singleton.class)
.beanClass(ClientModels.class)
.createWith(creationalContext -> clientModels);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* Copyright 2020 Red Hat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.wildfly.extension.microprofile.graphql.client;

import org.jboss.as.controller.ExtensionContext;
import org.jboss.as.controller.ModelVersion;
import org.jboss.as.controller.PathElement;
import org.jboss.as.controller.SubsystemRegistration;
import org.jboss.as.controller.descriptions.ResourceDescriptionResolver;
import org.jboss.as.controller.descriptions.StandardResourceDescriptionResolver;
import org.jboss.as.controller.operations.common.GenericSubsystemDescribeHandler;
import org.jboss.as.controller.parsing.ExtensionParsingContext;
import org.jboss.as.controller.registry.ManagementResourceRegistration;

import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUBSYSTEM;

public class MicroProfileGraphQLClientExtension implements org.jboss.as.controller.Extension {

public static final String SUBSYSTEM_NAME = "microprofile-graphql-client-smallrye";
protected static final PathElement SUBSYSTEM_PATH = PathElement.pathElement(SUBSYSTEM, SUBSYSTEM_NAME);

protected static final ModelVersion VERSION_1_0_0 = ModelVersion.create(1, 0, 0);
private static final ModelVersion CURRENT_MODEL_VERSION = VERSION_1_0_0;

private static final MicroProfileGraphQLClientParser_1_0 CURRENT_PARSER = new MicroProfileGraphQLClientParser_1_0();

static final String WELD_CAPABILITY_NAME = "org.wildfly.weld";
static final String CONFIG_CAPABILITY_NAME = "org.wildfly.microprofile.config";

private static final String RESOURCE_NAME = MicroProfileGraphQLClientExtension.class.getPackage().getName() + ".LocalDescriptions";

@Override
public void initialize(ExtensionContext extensionContext) {
final SubsystemRegistration sr = extensionContext.registerSubsystem(SUBSYSTEM_NAME, CURRENT_MODEL_VERSION);
sr.registerXMLElementWriter(CURRENT_PARSER);
final ManagementResourceRegistration root = sr.registerSubsystemModel(new MicroProfileGraphQLClientSubsystemDefinition());
root.registerOperationHandler(GenericSubsystemDescribeHandler.DEFINITION, GenericSubsystemDescribeHandler.INSTANCE, false);
}

@Override
public void initializeParsers(ExtensionParsingContext extensionParsingContext) {
extensionParsingContext.setSubsystemXmlMapping(SUBSYSTEM_NAME, MicroProfileGraphQLClientParser_1_0.NAMESPACE, CURRENT_PARSER);
}

static ResourceDescriptionResolver getResourceDescriptionResolver(final String... keyPrefix) {
return getResourceDescriptionResolver(true, keyPrefix);
}

static ResourceDescriptionResolver getResourceDescriptionResolver(final boolean useUnprefixedChildTypes, final String... keyPrefix) {
StringBuilder prefix = new StringBuilder();
for (String kp : keyPrefix) {
if (prefix.length() > 0){
prefix.append('.');
}
prefix.append(kp);
}
return new StandardResourceDescriptionResolver(prefix.toString(), RESOURCE_NAME, MicroProfileGraphQLClientExtension.class.getClassLoader(), true, useUnprefixedChildTypes);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.wildfly.extension.microprofile.graphql.client;

import org.jboss.as.controller.PersistentResourceXMLDescription;
import org.jboss.as.controller.PersistentResourceXMLParser;

public class MicroProfileGraphQLClientParser_1_0 extends PersistentResourceXMLParser {

public static final String NAMESPACE = "urn:wildfly:microprofile-graphql-client-smallrye:1.0";

private static final PersistentResourceXMLDescription xmlDescription;

static {
xmlDescription = org.jboss.as.controller.PersistentResourceXMLDescription.builder(MicroProfileGraphQLClientExtension.SUBSYSTEM_PATH, NAMESPACE)
.build();
}

@Override
public PersistentResourceXMLDescription getParserDescription() {
return xmlDescription;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*
* Copyright 2019 Red Hat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.wildfly.extension.microprofile.graphql.client;

import org.jboss.as.controller.AbstractBoottimeAddStepHandler;
import org.jboss.as.controller.AttributeDefinition;
import org.jboss.as.controller.ModelOnlyRemoveStepHandler;
import org.jboss.as.controller.OperationContext;
import org.jboss.as.controller.OperationFailedException;
import org.jboss.as.controller.PersistentResourceDefinition;
import org.jboss.as.controller.capability.RuntimeCapability;
import org.jboss.as.server.AbstractDeploymentChainStep;
import org.jboss.as.server.DeploymentProcessorTarget;
import org.jboss.as.server.deployment.Phase;
import org.jboss.dmr.ModelNode;
import org.wildfly.extension.microprofile.graphql.client._private.MicroProfileGraphQLClientLogger;
import org.wildfly.extension.microprofile.graphql.client.deployment.MicroProfileGraphQLClientDependencyProcessor;
import org.wildfly.extension.microprofile.graphql.client.deployment.MicroProfileGraphQLClientDeploymentProcessor;

import java.util.Collection;
import java.util.Collections;

import static org.wildfly.extension.microprofile.graphql.client.MicroProfileGraphQLClientExtension.CONFIG_CAPABILITY_NAME;
import static org.wildfly.extension.microprofile.graphql.client.MicroProfileGraphQLClientExtension.SUBSYSTEM_NAME;
import static org.wildfly.extension.microprofile.graphql.client.MicroProfileGraphQLClientExtension.SUBSYSTEM_PATH;
import static org.wildfly.extension.microprofile.graphql.client.MicroProfileGraphQLClientExtension.WELD_CAPABILITY_NAME;

public class MicroProfileGraphQLClientSubsystemDefinition extends PersistentResourceDefinition {

private static final String GRAPHQL_CAPABILITY_NAME = "org.wildfly.microprofile.graphql.client";

private static final RuntimeCapability<Void> GRAPHQL_CAPABILITY = RuntimeCapability.Builder
.of(GRAPHQL_CAPABILITY_NAME)
.addRequirements(WELD_CAPABILITY_NAME)
.addRequirements(CONFIG_CAPABILITY_NAME)
.build();

public MicroProfileGraphQLClientSubsystemDefinition() {
super(
new Parameters(
SUBSYSTEM_PATH,
MicroProfileGraphQLClientExtension.getResourceDescriptionResolver(SUBSYSTEM_NAME))
.setAddHandler(AddHandler.INSTANCE)
.setRemoveHandler(new ModelOnlyRemoveStepHandler())
.setCapabilities(GRAPHQL_CAPABILITY)
);
}

@Override
public Collection<AttributeDefinition> getAttributes() {
return Collections.emptyList();
}

static class AddHandler extends AbstractBoottimeAddStepHandler {

static AddHandler INSTANCE = new AddHandler();

private AddHandler() {
super(Collections.emptyList());
}

@Override
protected void performBoottime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {
super.performBoottime(context, operation, model);

context.addStep(new AbstractDeploymentChainStep() {
public void execute(DeploymentProcessorTarget processorTarget) {
final int DEPENDENCIES_MICROPROFILE_GRAPHQL = 6288;
processorTarget.addDeploymentProcessor(SUBSYSTEM_NAME, Phase.DEPENDENCIES, DEPENDENCIES_MICROPROFILE_GRAPHQL, new MicroProfileGraphQLClientDependencyProcessor());
final int POST_MODULE_MICROPROFILE_GRAPHQL = 14241;
processorTarget.addDeploymentProcessor(SUBSYSTEM_NAME, Phase.POST_MODULE, POST_MODULE_MICROPROFILE_GRAPHQL, new MicroProfileGraphQLClientDeploymentProcessor());
}
}, OperationContext.Stage.RUNTIME);

MicroProfileGraphQLClientLogger.LOGGER.activatingSubsystem();
}
}
}
Loading
Loading