Skip to content

Commit

Permalink
[JBAS-8605]; initial support for legacy MC configuration.
Browse files Browse the repository at this point in the history
  • Loading branch information
alesj authored and n1hility committed Nov 30, 2010
1 parent bcad431 commit cb2d966
Show file tree
Hide file tree
Showing 21 changed files with 1,823 additions and 0 deletions.
123 changes: 123 additions & 0 deletions domain/src/main/resources/schema/jboss-mc_7_0.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
<?xml version="1.0" encoding="UTF-8"?>

<!--
~ JBoss, Home of Professional Open Source.
~ Copyright 2010, 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.
-->

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="urn:jboss:mc:7.0"
xmlns="urn:jboss:mc:7.0"
elementFormDefault="qualified"
attributeFormDefault="unqualified"
version="1.0">

<xs:complexType name="deployment">
<xs:sequence>
<xs:element name="bean" type="bean" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="mode" type="mode" default="active" use="optional"/>
</xs:complexType>

<xs:complexType name="bean">
<xs:sequence>
<xs:element name="constructor" type="constructor" minOccurs="0" maxOccurs="1"/>
<xs:element name="attribute" type="attribute" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="depends" type="depends" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="depends-list" type="depends-list" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="alias" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="annotation" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="name" type="xs:string" use="required"/>
<xs:attribute name="class" type="xs:string" use="required"/>
</xs:complexType>

<xs:complexType name="constructor">
<xs:sequence>
<xs:element name="arg" type="arg" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>

<xs:complexType name="arg">
<xs:attribute name="type" type="xs:string" default="java.lang.String" use="optional"/>
<xs:attribute name="value" type="xs:string" use="required"/>
</xs:complexType>

<xs:simpleType name="mode">
<xs:restriction base="xs:string">
<xs:enumeration value="active"/>
<xs:enumeration value="passive"/>
<xs:enumeration value="on demand"/>
<xs:enumeration value="never"/>
</xs:restriction>
</xs:simpleType>

<xs:complexType name="attribute">
<xs:choice minOccurs="0" maxOccurs="1">
<xs:element name="inject" type="inject"/>
<xs:element name="value-factory" type="value-factory"/>
</xs:choice>
<xs:attribute name="name" type="xs:string" use="required"/>
<xs:attribute name="replace" type="xs:boolean" use="optional"/>
<xs:attribute name="trim" type="xs:boolean" use="optional"/>
</xs:complexType>

<xs:complexType name="depends">
<xs:sequence>
<xs:element name="mbean" type="mbean" minOccurs="0" maxOccurs="1"/>
</xs:sequence>
<xs:attribute name="optional-attribute-name" type="xs:string" use="optional"/>
<xs:attribute name="proxy-type" type="xs:boolean" use="optional"/>
</xs:complexType>

<xs:complexType name="depends-list">
<xs:sequence>
<xs:element name="depends-list-element" type="depends-list-element" minOccurs="0" maxOccurs="1"/>
</xs:sequence>
<xs:attribute name="optional-attribute-name" type="xs:string" use="optional"/>
</xs:complexType>

<xs:complexType name="depends-list-element">
<xs:sequence>
<xs:element name="mbean" type="mbean" minOccurs="0" maxOccurs="1"/>
</xs:sequence>
</xs:complexType>

<xs:complexType name="inject">
<xs:attribute name="bean" type="xs:string" use="required"/>
<xs:attribute name="property" type="xs:string" use="optional"/>
</xs:complexType>

<xs:complexType name="value-factory">
<xs:sequence>
<xs:element name="parameter" type="parameter" minOccurs="0" maxOccurs="1"/>
</xs:sequence>
<xs:attribute name="bean" type="xs:string" use="required"/>
<xs:attribute name="method" type="xs:string" use="required"/>
</xs:complexType>

<xs:complexType name="parameter">
<xs:attribute name="class" type="xs:string" use="required"/>
</xs:complexType>

<!-- Root elements -->

<xs:element name="deployment" type="deployment"/>
</xs:schema>
75 changes: 75 additions & 0 deletions mc/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ JBoss, Home of Professional Open Source.
~ Copyright 2010, 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.
-->

<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">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.jboss.as</groupId>
<artifactId>jboss-as-parent</artifactId>
<version>7.0.0.Alpha2-SNAPSHOT</version>
</parent>

<groupId>org.jboss.as</groupId>
<artifactId>jboss-as-mc</artifactId>
<version>7.0.0.Alpha2-SNAPSHOT</version>

<name>JBoss Application Server: Microcontainer Subsystem</name>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<includes>
<include>**/*TestCase.java</include>
</includes>
<enableAssertions>false</enableAssertions>
</configuration>
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
<groupId>org.jboss</groupId>
<artifactId>jboss-vfs</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.msc</groupId>
<artifactId>jboss-msc</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.as</groupId>
<artifactId>jboss-as-domain</artifactId>
</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,99 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright 2010, Red Hat Middleware LLC, 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.
*/

package org.jboss.as.mc;

import org.jboss.as.deployment.DeploymentPhases;
import org.jboss.as.deployment.unit.DeploymentUnitContext;
import org.jboss.as.deployment.unit.DeploymentUnitProcessingException;
import org.jboss.as.deployment.unit.DeploymentUnitProcessor;
import org.jboss.as.mc.descriptor.KernelDeploymentXmlDescriptor;
import org.jboss.as.mc.descriptor.KernelDeploymentXmlDescriptorParser;
import org.jboss.as.model.ParseResult;
import org.jboss.staxmapper.XMLMapper;
import org.jboss.vfs.VFSUtils;
import org.jboss.vfs.VirtualFile;

import javax.xml.namespace.QName;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamReader;
import java.io.InputStream;

import static org.jboss.as.deployment.attachment.VirtualFileAttachment.getVirtualFileAttachment;

/**
* DeploymentUnitProcessor responsible for parsing a jboss-beans.xml
* descriptor and attaching the corresponding KernelDeploymentXmlDescriptor.
*
* @author <a href="mailto:[email protected]">Ales Justin</a>
*/
public class KernelDeploymentParsingProcessor implements DeploymentUnitProcessor {
public static final long PRIORITY = DeploymentPhases.PARSE_DESCRIPTORS.plus(500L);

private final XMLMapper xmlMapper = XMLMapper.Factory.create();
private final XMLInputFactory inputFactory = XMLInputFactory.newInstance();

public KernelDeploymentParsingProcessor() {
xmlMapper.registerRootElement(new QName("urn:jboss:mc:7.0", "deployment"), new KernelDeploymentXmlDescriptorParser());
}

/**
* Process a deployment for jboss-beans.xml files.
* Will parse the xml file and attach an configuration discovered durring processing.
*
* @param context the deployment unit context
* @throws DeploymentUnitProcessingException
*/
public void processDeployment(DeploymentUnitContext context) throws DeploymentUnitProcessingException {
final VirtualFile deploymentRoot = getVirtualFileAttachment(context);

if(deploymentRoot == null || deploymentRoot.exists() == false)
return;

final String deploymentRootName = deploymentRoot.getName();
VirtualFile beansXmlFile = null;
if(deploymentRootName.endsWith(".jar")) {
beansXmlFile = deploymentRoot.getChild("META-INF/jboss-beans.xml");
} else if(deploymentRootName.endsWith("jboss-beans.xml")) {
beansXmlFile = deploymentRoot;
}
if(beansXmlFile == null || beansXmlFile.exists() == false)
return;

InputStream xmlStream = null;
try {
xmlStream = beansXmlFile.openStream();
final XMLStreamReader reader = inputFactory.createXMLStreamReader(xmlStream);
final ParseResult<KernelDeploymentXmlDescriptor> result = new ParseResult<KernelDeploymentXmlDescriptor>();
xmlMapper.parseDocument(result, reader);
final KernelDeploymentXmlDescriptor xmlDescriptor = result.getResult();
if(xmlDescriptor != null)
context.putAttachment(KernelDeploymentXmlDescriptor.ATTACHMENT_KEY, xmlDescriptor);
else
throw new DeploymentUnitProcessingException("Failed to parse MC beans xml [" + beansXmlFile + "]");
} catch(Exception e) {
throw new DeploymentUnitProcessingException("Failed to parse MC beans xml [" + beansXmlFile + "]", e);
} finally {
VFSUtils.safeClose(xmlStream);
}
}
}
68 changes: 68 additions & 0 deletions mc/src/main/java/org/jboss/as/mc/McSubsystemAdd.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright 2010, Red Hat Middleware LLC, 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.
*/

package org.jboss.as.mc;

import org.jboss.as.deployment.chain.DeploymentChain;
import org.jboss.as.deployment.chain.DeploymentChainProcessorInjector;
import org.jboss.as.deployment.unit.DeploymentUnitProcessor;
import org.jboss.as.deployment.unit.DeploymentUnitProcessorService;
import org.jboss.as.model.AbstractSubsystemAdd;
import org.jboss.as.model.UpdateContext;
import org.jboss.as.model.UpdateResultHandler;
import org.jboss.msc.service.BatchBuilder;
import org.jboss.msc.service.BatchServiceBuilder;

import static org.jboss.as.deployment.chain.JarDeploymentActivator.JAR_DEPLOYMENT_CHAIN_SERVICE_NAME;

/**
* Microcontainer substem add.
* Define processors for MC config handling.
*
* @author <a href="mailto:[email protected]">Ales Justin</a>
*/
final class McSubsystemAdd extends AbstractSubsystemAdd<McSubsystemElement> {

private static final long serialVersionUID = 1L;

McSubsystemAdd() {
super(MicrocontainerExtension.NAMESPACE);
}

@Override
protected <P> void applyUpdate(UpdateContext updateContext, UpdateResultHandler<? super Void, P> resultHandler, P param) {
BatchBuilder batchBuilder = updateContext.getBatchBuilder();
addDeploymentProcessor(batchBuilder, new KernelDeploymentParsingProcessor(), KernelDeploymentParsingProcessor.PRIORITY);
addDeploymentProcessor(batchBuilder, new ParsedKernelDeploymentProcessor(), ParsedKernelDeploymentProcessor.PRIORITY);
}

@Override
protected McSubsystemElement createSubsystemElement() {
return new McSubsystemElement();
}

private static <T extends DeploymentUnitProcessor> BatchServiceBuilder<T> addDeploymentProcessor(final BatchBuilder batchBuilder, final T deploymentUnitProcessor, final long priority) {
final DeploymentUnitProcessorService<T> deploymentUnitProcessorService = new DeploymentUnitProcessorService<T>(deploymentUnitProcessor);
return batchBuilder.addService(JAR_DEPLOYMENT_CHAIN_SERVICE_NAME.append(deploymentUnitProcessor.getClass().getName()), deploymentUnitProcessorService)
.addDependency(JAR_DEPLOYMENT_CHAIN_SERVICE_NAME, DeploymentChain.class, new DeploymentChainProcessorInjector<T>(deploymentUnitProcessorService, priority));
}
}
Loading

0 comments on commit cb2d966

Please sign in to comment.