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

Backwards compatibility with JBoss 7.1.2 #7

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@ target
.idea
*.iml

/.settings/
/.classpath
/.project
37 changes: 16 additions & 21 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
<version.cassandra.all>2.1.5</version.cassandra.all>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<module.name>org.wildfly.extension.cassandra</module.name>
<version.jboss>7.1.2.Final</version.jboss>
</properties>

<scm>
Expand Down Expand Up @@ -120,28 +121,25 @@
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.wildfly</groupId>
<artifactId>wildfly-controller</artifactId>
<version>${version.wildfly}</version>
<groupId>org.jboss.as</groupId>
<artifactId>jboss-as-server</artifactId>
<version>${version.jboss}</version>
</dependency>
<dependency>
<groupId>org.wildfly</groupId>
<artifactId>wildfly-server</artifactId>
<version>${version.wildfly}</version>
<groupId>org.jboss.as</groupId>
<artifactId>jboss-as-subsystem-test</artifactId>
<version>${version.jboss}</version>
</dependency>
<dependency>
<groupId>org.wildfly</groupId>
<artifactId>wildfly-subsystem-test</artifactId>
<type>pom</type>
<scope>test</scope>
<version>${version.wildfly}</version>
<groupId>org.jboss.as</groupId>
<artifactId>jboss-as-controller</artifactId>
<version>${version.jboss}</version>
</dependency>
<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging</artifactId>
<version>${version.org.jboss.logging.jboss-logging}</version>
</dependency>

<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging-annotations</artifactId>
Expand Down Expand Up @@ -192,20 +190,17 @@

<dependencies>
<dependency>
<groupId>org.wildfly</groupId>
<artifactId>wildfly-controller</artifactId>
<groupId>org.jboss.as</groupId>
<artifactId>jboss-as-controller</artifactId>
</dependency>
<dependency>
<groupId>org.wildfly</groupId>
<artifactId>wildfly-server</artifactId>
<groupId>org.jboss.as</groupId>
<artifactId>jboss-as-subsystem-test</artifactId>
</dependency>
<dependency>
<groupId>org.wildfly</groupId>
<artifactId>wildfly-subsystem-test</artifactId>
<type>pom</type>
<scope>test</scope>
<groupId>org.jboss.as</groupId>
<artifactId>jboss-as-server</artifactId>
</dependency>

<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging-annotations</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.jboss.as.controller.ExtensionContext;
import org.jboss.as.controller.PathElement;
import org.jboss.as.controller.SubsystemRegistration;
import org.jboss.as.controller.descriptions.ModelDescriptionConstants;
import org.jboss.as.controller.descriptions.StandardResourceDescriptionResolver;
import org.jboss.as.controller.operations.common.GenericSubsystemDescribeHandler;
import org.jboss.as.controller.parsing.ExtensionParsingContext;
Expand All @@ -44,7 +45,6 @@ public class CassandraExtension implements Extension {
*/
public static final String SUBSYSTEM_NAME = "cassandra";


protected static final PathElement SUBSYSTEM_PATH = PathElement.pathElement(SUBSYSTEM, SUBSYSTEM_NAME);
protected static PathElement CLUSTER_PATH = PathElement.pathElement(CassandraModel.CLUSTER);

Expand All @@ -68,7 +68,7 @@ public void initializeParsers(ExtensionParsingContext context) {
public void initialize(ExtensionContext context) {
final SubsystemRegistration subsystem = context.registerSubsystem(SUBSYSTEM_NAME, 1, 0);
final ManagementResourceRegistration registration = subsystem.registerSubsystemModel(RootDefinition.INSTANCE);
registration.registerOperationHandler(GenericSubsystemDescribeHandler.DEFINITION, GenericSubsystemDescribeHandler.INSTANCE);
registration.registerOperationHandler(ModelDescriptionConstants.DESCRIBE, GenericSubsystemDescribeHandler.INSTANCE, CassandraModelDescriptionProvider.INSTANCE);
subsystem.registerXMLElementWriter(SubsystemParser.INSTANCE);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package org.wildfly.extension.cassandra;

import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.DESCRIBE;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.DESCRIPTION;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OPERATION_NAME;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.REPLY_PROPERTIES;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.TYPE;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.VALUE_TYPE;

import java.util.Locale;
import java.util.ResourceBundle;
import org.jboss.as.controller.descriptions.DescriptionProvider;
import org.jboss.as.controller.descriptions.common.CommonDescriptions;
import org.jboss.dmr.ModelNode;
import org.jboss.dmr.ModelType;

/**
* A generic handler recursively creating add operations for a managed resource using it's
* attributes as the request-parameters.
*
* @author Emanuel Muckenhuber
*/
public class CassandraModelDescriptionProvider implements DescriptionProvider {

public static final CassandraModelDescriptionProvider INSTANCE = new CassandraModelDescriptionProvider();

protected CassandraModelDescriptionProvider() {
//
}

@Override
public ModelNode getModelDescription(Locale locale) {
final ResourceBundle bundle = getResourceBundle(locale);
final ModelNode root = new ModelNode();
root.get(OPERATION_NAME).set(DESCRIBE);
root.get(DESCRIPTION).set(bundle.getString("subsystem.describe"));
root.get(REPLY_PROPERTIES, TYPE).set(ModelType.LIST);
root.get(REPLY_PROPERTIES, VALUE_TYPE).set(ModelType.OBJECT);
return root;
}

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

private static ResourceBundle getResourceBundle(Locale locale) {
if (locale == null) {
locale = Locale.getDefault();
}
return ResourceBundle.getBundle(RESOURCE_NAME, locale);
}

}
13 changes: 3 additions & 10 deletions src/main/java/org/wildfly/extension/cassandra/ClusterAdd.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,6 @@ static void installRuntimeServices(OperationContext context, PathAddress address
private static Config createServiceConfig(final OperationContext context, PathAddress address,
ModelNode fullModel) throws OperationFailedException {

final ExpressionResolver expressionResolver = new ExpressionResolver() {
@Override
public ModelNode resolveExpressions(ModelNode node) throws OperationFailedException {
return context.resolveExpressions(node);
}
};

// create the actual cassandra config singleton
final Config cassandraConfig = new Config();
cassandraConfig.cluster_name = address.getLastElement().getValue();
Expand All @@ -115,16 +108,16 @@ public ModelNode resolveExpressions(ModelNode node) throws OperationFailedExcept
LinkedHashMap providerConfig = new LinkedHashMap();
providerConfig.put("class_name", ClusterDefinition.SEED_PROVIDER.resolveModelAttribute(context, fullModel).asString());
HashMap<String, String> params = new HashMap<String, String>();
params.put("seeds", ClusterDefinition.SEEDS.resolveModelAttribute(expressionResolver, fullModel).asString());
params.put("seeds", ClusterDefinition.SEEDS.resolveModelAttribute(context, fullModel).asString());
ArrayList wrapper = new ArrayList();
wrapper.add(params);
providerConfig.put("parameters", wrapper);

SeedProviderDef providerDef = new SeedProviderDef(providerConfig);
cassandraConfig.seed_provider = providerDef;

cassandraConfig.listen_address = ClusterDefinition.LISTEN_ADDRESS.resolveModelAttribute(expressionResolver, fullModel).asString();
cassandraConfig.broadcast_address = ClusterDefinition.BROADCAST_ADDRESS.resolveModelAttribute(expressionResolver, fullModel).asString();
cassandraConfig.listen_address = ClusterDefinition.LISTEN_ADDRESS.resolveModelAttribute(context, fullModel).asString();
cassandraConfig.broadcast_address = ClusterDefinition.BROADCAST_ADDRESS.resolveModelAttribute(context, fullModel).asString();

cassandraConfig.start_native_transport = ClusterDefinition.START_NATIVE_TRANSPORT.resolveModelAttribute(context, fullModel).asBoolean();
cassandraConfig.start_rpc = ClusterDefinition.START_RPC.resolveModelAttribute(context, fullModel).asBoolean();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,13 @@
package org.wildfly.extension.cassandra;

import org.jboss.as.controller.AttributeDefinition;
import org.jboss.as.controller.PersistentResourceDefinition;
import org.jboss.as.controller.ServiceRemoveStepHandler;
import org.jboss.as.controller.SimpleAttributeDefinition;
import org.jboss.as.controller.SimpleAttributeDefinitionBuilder;
import org.jboss.as.controller.access.constraint.ApplicationTypeConfig;
import org.jboss.as.controller.access.management.AccessConstraintDefinition;
import org.jboss.as.controller.access.management.ApplicationTypeAccessConstraintDefinition;
import org.jboss.as.controller.registry.ManagementResourceRegistration;
import org.jboss.dmr.ModelNode;
import org.jboss.dmr.ModelType;
import org.wildfly.extension.cassandra.future.PersistentResourceDefinition;
import org.wildfly.extension.cassandra.future.ServiceRemoveStepHandler;

import java.util.Arrays;
import java.util.Collection;
Expand All @@ -42,16 +39,11 @@
*/
public class ClusterDefinition extends PersistentResourceDefinition {

private final List<AccessConstraintDefinition> accessConstraints;

private ClusterDefinition() {
super(CassandraExtension.CLUSTER_PATH,
CassandraExtension.getResourceDescriptionResolver(CassandraModel.CLUSTER),
ClusterAdd.INSTANCE,
new ServiceRemoveStepHandler(ClusterAdd.SERVICE_NAME, ClusterAdd.INSTANCE));

ApplicationTypeConfig atc = new ApplicationTypeConfig(CassandraExtension.SUBSYSTEM_NAME, CassandraModel.CLUSTER);
accessConstraints = new ApplicationTypeAccessConstraintDefinition(atc).wrapAsList();
}

// -----------
Expand Down Expand Up @@ -261,10 +253,4 @@ protected List<? extends PersistentResourceDefinition> getChildren() {
return CHILDREN;
}

@Override
public List<AccessConstraintDefinition> getAccessConstraints() {
return accessConstraints;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
package org.wildfly.extension.cassandra;

import org.jboss.as.controller.AttributeDefinition;
import org.jboss.as.controller.PersistentResourceDefinition;
import org.jboss.as.controller.ReloadRequiredRemoveStepHandler;
import org.wildfly.extension.cassandra.future.PersistentResourceDefinition;

import java.util.Arrays;
import java.util.Collection;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,20 @@
package org.wildfly.extension.cassandra;

import org.jboss.as.controller.PathAddress;
import org.jboss.as.controller.PersistentResourceXMLDescription;
import org.jboss.as.controller.persistence.SubsystemMarshallingContext;
import org.jboss.dmr.ModelNode;
import org.jboss.staxmapper.XMLElementReader;
import org.jboss.staxmapper.XMLElementWriter;
import org.jboss.staxmapper.XMLExtendedStreamReader;
import org.jboss.staxmapper.XMLExtendedStreamWriter;
import org.wildfly.extension.cassandra.future.PersistentResourceXMLDescription;

import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamException;
import java.util.List;

import static org.jboss.as.controller.PersistentResourceXMLDescription.builder;
import static org.wildfly.extension.cassandra.future.PersistentResourceXMLDescription.builder;

import java.util.List;


/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package org.wildfly.extension.cassandra.future;

/*
* JBoss, Home of Professional Open Source.
* Copyright 2012, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/

import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;

import org.jboss.as.controller.AttributeDefinition;
import org.jboss.as.controller.ControllerMessages;
import org.jboss.dmr.ModelNode;

/**
* @author <a href="mailto:[email protected]">Tomaz Cerar</a>
*/
public abstract class AttributeMarshaller {

/**
* Gets whether the given {@code resourceModel} has a value for this attribute that should be marshalled to XML.
* <p>
* This is the same as {@code isMarshallable(resourceModel, true)}.
* </p>
* @param attribute - attribute for which marshaling is being done
* @param resourceModel the model, a non-null node of {@link org.jboss.dmr.ModelType#OBJECT}.
* @return {@code true} if the given {@code resourceModel} has a defined value under this attribute's {@link AttributeDefinition#getName()} () name}.
*/
public boolean isMarshallable(final AttributeDefinition attribute,final ModelNode resourceModel) {
return isMarshallable(attribute,resourceModel, true);
}

/**
* Gets whether the given {@code resourceModel} has a value for this attribute that should be marshalled to XML.
*
* @param attribute - attribute for which marshaling is being done
* @param resourceModel the model, a non-null node of {@link org.jboss.dmr.ModelType#OBJECT}.
* @param marshallDefault {@code true} if the value should be marshalled even if it matches the default value
* @return {@code true} if the given {@code resourceModel} has a defined value under this attribute's {@link AttributeDefinition#getName()} () name}
* and {@code marshallDefault} is {@code true} or that value differs from this attribute's {@link AttributeDefinition#getDefaultValue() default value}.
*/
public boolean isMarshallable(final AttributeDefinition attribute, final ModelNode resourceModel, final boolean marshallDefault) {
return resourceModel.hasDefined(attribute.getName()) && (marshallDefault || !resourceModel.get(attribute.getName()).equals(attribute.getDefaultValue()));
}

/**
* Marshalls the value from the given {@code resourceModel} as an xml element, if it
* {@link #isMarshallable(AttributeDefinition, org.jboss.dmr.ModelNode, boolean) is marshallable}.
*
* @param attribute - attribute for which marshaling is being done
* @param resourceModel the model, a non-null node of {@link org.jboss.dmr.ModelType#OBJECT}.
* @param writer stream writer to use for writing the attribute
* @throws javax.xml.stream.XMLStreamException
* if thrown by {@code writer}
*/

public void marshallAsAttribute(final AttributeDefinition attribute,final ModelNode resourceModel, final boolean marshallDefault, final XMLStreamWriter writer) throws XMLStreamException{
throw ControllerMessages.MESSAGES.cannotWriteTo(attribute.getName());
}

public void marshallAsElement(final AttributeDefinition attribute, final ModelNode resourceModel, final boolean marshallDefault, final XMLStreamWriter writer) throws XMLStreamException{
throw ControllerMessages.MESSAGES.cannotWriteTo(attribute.getName());
}

public boolean isMarshallableAsElement(){
return false;
}
}
Loading