Skip to content

Commit

Permalink
Merge branch 'ladybird' into invocation_integration
Browse files Browse the repository at this point in the history
  • Loading branch information
darranl committed Dec 1, 2016
2 parents 5af7895 + 1239e47 commit e1088bd
Show file tree
Hide file tree
Showing 489 changed files with 9,918 additions and 2,273 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ private synchronized void createConnection() {
final AuthenticationContext context = AuthenticationContext.empty().with(MatchRule.ALL, mergedConfiguration);

// open a connection
endpoint = Endpoint.getCurrent();
endpoint = Endpoint.builder().setEndpointName("endpoint").build();
final IoFuture<Connection> futureConnection = endpoint.connect(uri, OptionMap.create(Options.SASL_POLICY_NOANONYMOUS, Boolean.FALSE, Options.SASL_POLICY_NOPLAINTEXT, Boolean.FALSE), context);
connection = IoFutureHelper.get(futureConnection, 30L, TimeUnit.SECONDS);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/*
* Copyright 2016 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.batch.jberet;

import java.util.EnumMap;
import java.util.EnumSet;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import javax.xml.stream.XMLStreamException;

import org.jboss.as.controller.AttributeDefinition;
import org.jboss.as.controller.AttributeParser;
import org.jboss.as.controller.parsing.ParseUtils;
import org.jboss.dmr.ModelNode;
import org.jboss.staxmapper.XMLExtendedStreamReader;

/**
* Attribute parsing utilities.
*
* @author <a href="mailto:jperkins@redhat.com">James R. Perkins</a>
*/
class AttributeParsers {

/**
* An attribute parser for elements with a single {@code value} that don't allow any content within the element.
*/
static final AttributeParser VALUE = new AttributeParser() {
@Override
public void parseElement(final AttributeDefinition attribute, final XMLExtendedStreamReader reader, final ModelNode operation) throws XMLStreamException {
operation.get(attribute.getName()).set(readValueAttribute(reader));
ParseUtils.requireNoContent(reader);
}

@Override
public boolean isParseAsElement() {
return true;
}
};

/**
* Reads a {@code name} attribute on an element.
*
* @param reader the reader used to read the attribute with
*
* @return the name attribute or {@code null} if the name attribute was not defined
*
* @throws XMLStreamException if an XML processing error occurs
*/
static String readNameAttribute(final XMLExtendedStreamReader reader) throws XMLStreamException {
return readRequiredAttributes(reader, EnumSet.of(Attribute.NAME)).get(Attribute.NAME);
}

/**
* Reads a {@code value} attribute on an element.
*
* @param reader the reader used to read the attribute with
*
* @return the value attribute or {@code null} if the value attribute was not defined
*
* @throws XMLStreamException if an XML processing error occurs
*/
static String readValueAttribute(final XMLExtendedStreamReader reader) throws XMLStreamException {
return readRequiredAttributes(reader, EnumSet.of(Attribute.VALUE)).get(Attribute.VALUE);
}

/**
* Reads the required attributes from an XML configuration.
* <p>
* The reader must be on an element with attributes.
* </p>
*
* @param reader the reader for the attributes
* @param attributes the required attributes
*
* @return a map of the required attributes with the key being the attribute and the value being the value of the
* attribute
*
* @throws XMLStreamException if an XML processing error occurs
*/
static Map<Attribute, String> readRequiredAttributes(final XMLExtendedStreamReader reader, final Set<Attribute> attributes) throws XMLStreamException {
final int attributeCount = reader.getAttributeCount();
final Map<Attribute, String> result = new EnumMap<>(Attribute.class);
for (int i = 0; i < attributeCount; i++) {
final Attribute current = Attribute.forName(reader.getAttributeLocalName(i));
if (attributes.contains(current)) {
if (result.put(current, reader.getAttributeValue(i)) != null) {
throw ParseUtils.duplicateAttribute(reader, current.getLocalName());
}
} else {
throw ParseUtils.unexpectedAttribute(reader, i, attributes.stream().map(Attribute::getLocalName).collect(Collectors.toSet()));
}
}
if (result.isEmpty()) {
throw ParseUtils.missingRequired(reader, attributes.stream().map(Attribute::getLocalName).collect(Collectors.toSet()));
}
return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import org.jberet.repository.JobRepository;
import org.jberet.spi.JobExecutor;
import org.wildfly.security.auth.server.SecurityDomain;

/**
* A configuration for the {@link org.jberet.spi.BatchEnvironment} behavior.
Expand Down Expand Up @@ -47,4 +48,11 @@ public interface BatchConfiguration {
* @return the default job executor
*/
JobExecutor getDefaultJobExecutor();
}

/**
* Returns the security domain if defined.
*
* @return the security domain or {@code null} if not defined
*/
SecurityDomain getSecurityDomain();
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.jboss.msc.service.StartException;
import org.jboss.msc.service.StopContext;
import org.jboss.msc.value.InjectedValue;
import org.wildfly.security.auth.server.SecurityDomain;

/**
* A default batch configuration service.
Expand All @@ -33,6 +34,7 @@ class BatchConfigurationService implements BatchConfiguration, Service<BatchConf

private final InjectedValue<JobRepository> jobRepositoryInjector = new InjectedValue<>();
private final InjectedValue<JobExecutor> jobExecutorInjector = new InjectedValue<>();
private final InjectedValue<SecurityDomain> securityDomainInjector = new InjectedValue<>();
private volatile boolean restartOnResume;

@Override
Expand All @@ -54,6 +56,11 @@ public JobExecutor getDefaultJobExecutor() {
return jobExecutorInjector.getValue();
}

@Override
public SecurityDomain getSecurityDomain() {
return securityDomainInjector.getOptionalValue();
}

@Override
public void start(final StartContext context) throws StartException {
}
Expand All @@ -74,4 +81,8 @@ protected InjectedValue<JobRepository> getJobRepositoryInjector() {
protected InjectedValue<JobExecutor> getJobExecutorInjector() {
return jobExecutorInjector;
}
}

InjectedValue<SecurityDomain> getSecurityDomainInjector() {
return securityDomainInjector;
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
package org.wildfly.extension.batch.jberet;

import org.jboss.as.controller.PathAddress;
import org.jboss.as.controller.PathElement;
import org.jboss.as.controller.descriptions.ModelDescriptionConstants;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.Services;
import org.jboss.as.threads.ThreadsServices;
import org.jboss.msc.service.ServiceName;
import org.wildfly.extension.batch.jberet._private.BatchLogger;

/**
* Service names for the batch subsystem.
Expand Down Expand Up @@ -57,29 +53,23 @@ public static ServiceName jobOperatorServiceName(final DeploymentUnit deployment
/**
* Creates the service name used for the job operator registered for the deployment.
*
* @param address the address to resolve the deployment name from
* @param deploymentRuntimeName the runtime name for the deployment
*
* @return the service name
*/
public static ServiceName jobOperatorServiceName(final PathAddress address) {
String deploymentName = null;
String subdeploymentName = null;
for (PathElement element : address) {
if (ModelDescriptionConstants.DEPLOYMENT.equals(element.getKey())) {
deploymentName = element.getValue();
} else if (ModelDescriptionConstants.SUBDEPLOYMENT.endsWith(element.getKey())) {
subdeploymentName = element.getValue();
}
}
if (deploymentName == null) {
throw BatchLogger.LOGGER.couldNotFindDeploymentName(address.toString());
}
final ServiceName result;
if (subdeploymentName == null) {
result = Services.deploymentUnitName(deploymentName);
} else {
result = Services.deploymentUnitName(deploymentName, subdeploymentName);
}
return result.append("batch").append("job-operator");
public static ServiceName jobOperatorServiceName(final String deploymentRuntimeName) {
return Services.deploymentUnitName(deploymentRuntimeName).append("batch").append("job-operator");
}

/**
* Creates the service name used for the job operator registered for the deployment.
*
* @param deploymentRuntimeName the runtime name for the deployment
* @param subdeploymentName the name of the subdeployment
*
* @return the service name
*/
public static ServiceName jobOperatorServiceName(final String deploymentRuntimeName, final String subdeploymentName) {
return Services.deploymentUnitName(deploymentRuntimeName, subdeploymentName).append("batch").append("job-operator");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import org.jboss.as.controller.SimpleResourceDefinition;
import org.jboss.as.controller.descriptions.ModelDescriptionConstants;
import org.jboss.as.controller.operations.common.GenericSubsystemDescribeHandler;
import org.jboss.as.controller.registry.AttributeAccess;
import org.jboss.as.controller.registry.ManagementResourceRegistration;
import org.jboss.as.server.AbstractDeploymentChainStep;
import org.jboss.as.server.DeploymentProcessorTarget;
Expand All @@ -50,9 +51,11 @@
import org.jboss.as.threads.ThreadFactoryResourceDefinition;
import org.jboss.dmr.ModelNode;
import org.jboss.dmr.ModelType;
import org.jboss.msc.service.ServiceBuilder;
import org.jboss.msc.service.ServiceController;
import org.jboss.msc.service.ServiceTarget;
import org.wildfly.extension.batch.jberet._private.Capabilities;
import org.wildfly.extension.batch.jberet.deployment.BatchCleanupProcessor;
import org.wildfly.extension.batch.jberet.deployment.BatchDependencyProcessor;
import org.wildfly.extension.batch.jberet.deployment.BatchDeploymentDescriptorParser_1_0;
import org.wildfly.extension.batch.jberet.deployment.BatchDeploymentResourceProcessor;
Expand All @@ -61,6 +64,7 @@
import org.wildfly.extension.batch.jberet.job.repository.JdbcJobRepositoryDefinition;
import org.wildfly.extension.batch.jberet.thread.pool.BatchThreadPoolResourceDefinition;
import org.wildfly.extension.requestcontroller.RequestControllerExtension;
import org.wildfly.security.auth.server.SecurityDomain;

public class BatchSubsystemDefinition extends SimpleResourceDefinition {

Expand Down Expand Up @@ -90,9 +94,16 @@ public class BatchSubsystemDefinition extends SimpleResourceDefinition {
static final SimpleAttributeDefinition RESTART_JOBS_ON_RESUME = SimpleAttributeDefinitionBuilder.create("restart-jobs-on-resume", ModelType.BOOLEAN, true)
.setAllowExpression(true)
.setDefaultValue(new ModelNode(true))
.setAttributeParser(AttributeParsers.VALUE)
.setAttributeMarshaller(AttributeMarshallers.VALUE)
.build();

static final SimpleAttributeDefinition SECURITY_DOMAIN = SimpleAttributeDefinitionBuilder.create("security-domain", ModelType.STRING, true)
.setAttributeMarshaller(AttributeMarshallers.NAMED)
.setFlags(AttributeAccess.Flag.RESTART_ALL_SERVICES)
.setCapabilityReference(Capabilities.SECURITY_DOMAIN_CAPABILITY, Capabilities.BATCH_CONFIGURATION_CAPABILITY)
.build();

private final boolean registerRuntimeOnly;

BatchSubsystemDefinition(final boolean registerRuntimeOnly) {
Expand Down Expand Up @@ -123,9 +134,10 @@ public void registerChildren(final ManagementResourceRegistration resourceRegist
@Override
public void registerAttributes(final ManagementResourceRegistration resourceRegistration) {
super.registerAttributes(resourceRegistration);
final OperationStepHandler writeHandler = new ReloadRequiredWriteAttributeHandler(DEFAULT_JOB_REPOSITORY, DEFAULT_THREAD_POOL);
final OperationStepHandler writeHandler = new ReloadRequiredWriteAttributeHandler(DEFAULT_JOB_REPOSITORY, DEFAULT_THREAD_POOL, SECURITY_DOMAIN);
resourceRegistration.registerReadWriteAttribute(DEFAULT_JOB_REPOSITORY, null, writeHandler);
resourceRegistration.registerReadWriteAttribute(DEFAULT_THREAD_POOL, null, writeHandler);
resourceRegistration.registerReadWriteAttribute(SECURITY_DOMAIN, null, writeHandler);
resourceRegistration.registerReadWriteAttribute(RESTART_JOBS_ON_RESUME, null, new AbstractWriteAttributeHandler<Boolean>() {
@Override
protected boolean applyUpdateToRuntime(final OperationContext context, final ModelNode operation, final String attributeName, final ModelNode resolvedValue, final ModelNode currentValue, final HandbackHolder<Boolean> handbackHolder) throws OperationFailedException {
Expand Down Expand Up @@ -159,7 +171,7 @@ static class BatchSubsystemAdd extends AbstractBoottimeAddStepHandler {
static final BatchSubsystemAdd INSTANCE = new BatchSubsystemAdd();

private BatchSubsystemAdd() {
super(Collections.singleton(Capabilities.BATCH_CONFIGURATION_CAPABILITY), DEFAULT_JOB_REPOSITORY, DEFAULT_THREAD_POOL, RESTART_JOBS_ON_RESUME);
super(Collections.singleton(Capabilities.BATCH_CONFIGURATION_CAPABILITY), DEFAULT_JOB_REPOSITORY, DEFAULT_THREAD_POOL, RESTART_JOBS_ON_RESUME, SECURITY_DOMAIN);
}

@Override
Expand All @@ -180,18 +192,21 @@ public void execute(DeploymentProcessorTarget processorTarget) {
Phase.POST_MODULE, Phase.POST_MODULE_BATCH_ENVIRONMENT, new BatchEnvironmentProcessor(rcPresent));
processorTarget.addDeploymentProcessor(NAME,
Phase.INSTALL, Phase.INSTALL_BATCH_RESOURCES, new BatchDeploymentResourceProcessor(NAME));
processorTarget.addDeploymentProcessor(NAME,
Phase.CLEANUP, Phase.CLEANUP_BATCH, new BatchCleanupProcessor());

}
}, OperationContext.Stage.RUNTIME);

final ModelNode defaultJobRepository = DEFAULT_JOB_REPOSITORY.resolveModelAttribute(context, model);
final ModelNode defaultThreadPool = DEFAULT_THREAD_POOL.resolveModelAttribute(context, model);
final ModelNode securityDomain = SECURITY_DOMAIN.resolveModelAttribute(context, model);
final boolean restartOnResume = RESTART_JOBS_ON_RESUME.resolveModelAttribute(context, model).asBoolean();

final ServiceTarget target = context.getServiceTarget();
final BatchConfigurationService service = new BatchConfigurationService();
service.setRestartOnResume(restartOnResume);
target.addService(context.getCapabilityServiceName(Capabilities.BATCH_CONFIGURATION_CAPABILITY.getName(), BatchConfiguration.class), service)
final ServiceBuilder<BatchConfiguration> serviceBuilder = target.addService(context.getCapabilityServiceName(Capabilities.BATCH_CONFIGURATION_CAPABILITY.getName(), BatchConfiguration.class), service)
.addDependency(
context.getCapabilityServiceName(Capabilities.JOB_REPOSITORY_CAPABILITY.getName(), defaultJobRepository.asString(), JobRepository.class),
JobRepository.class,
Expand All @@ -201,11 +216,19 @@ public void execute(DeploymentProcessorTarget processorTarget) {
context.getCapabilityServiceName(Capabilities.THREAD_POOL_CAPABILITY.getName(), defaultThreadPool.asString(), JobExecutor.class),
JobExecutor.class,
service.getJobExecutorInjector()
)
// Only start this service if there are deployments present, allow it to be stopped as deployments
// are removed.
.setInitialMode(ServiceController.Mode.ON_DEMAND)
);
if (securityDomain.isDefined()) {
serviceBuilder.addDependency(
context.getCapabilityServiceName(Capabilities.SECURITY_DOMAIN_CAPABILITY, securityDomain.asString(), SecurityDomain.class),
SecurityDomain.class,
service.getSecurityDomainInjector()
);
}

// Only start this service if there are deployments present, allow it to be stopped as deployments
// are removed.
serviceBuilder.setInitialMode(ServiceController.Mode.ON_DEMAND)
.install();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@

public class BatchSubsystemExtension implements Extension {

private static final int MANAGEMENT_API_MAJOR_VERSION = 1;
private static final int MANAGEMENT_API_MINOR_VERSION = 1;
private static final int MANAGEMENT_API_MAJOR_VERSION = 2;
private static final int MANAGEMENT_API_MINOR_VERSION = 0;
private static final int MANAGEMENT_API_MICRO_VERSION = 0;

/**
Expand All @@ -48,7 +48,8 @@ public class BatchSubsystemExtension implements Extension {

@Override
public void initializeParsers(final ExtensionParsingContext context) {
context.setSubsystemXmlMapping(BatchSubsystemDefinition.NAME, Namespace.BATCH_1_0.getUriString(), new BatchSubsystemParser_1_0());
context.setSubsystemXmlMapping(BatchSubsystemDefinition.NAME, Namespace.BATCH_1_0.getUriString(), BatchSubsystemParser_1_0::new);
context.setSubsystemXmlMapping(BatchSubsystemDefinition.NAME, Namespace.BATCH_2_0.getUriString(), BatchSubsystemParser_2_0::new);
}

@Override
Expand Down
Loading

0 comments on commit e1088bd

Please sign in to comment.