* @param phaseContext the deployment unit context
* @throws DeploymentUnitProcessingException
*/
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final ConnectorXmlDescriptor connectorXmlDescriptor = phaseContext.getDeploymentUnit().getAttachment(ConnectorXmlDescriptor.ATTACHMENT_KEY);
final ManagementResourceRegistration registration = phaseContext.getDeploymentUnit().getAttachment(DeploymentModelUtils.MUTABLE_REGISTRATION_ATTACHMENT);
if(connectorXmlDescriptor == null) {
return; // Skip non ra deployments
}
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
final IronJacamarXmlDescriptor ironJacamarXmlDescriptor = deploymentUnit
.getAttachment(IronJacamarXmlDescriptor.ATTACHMENT_KEY);
final Module module = deploymentUnit.getAttachment(Attachments.MODULE);
if (module == null)
throw MESSAGES.failedToGetModuleAttachment(phaseContext.getDeploymentUnit());
final ClassLoader classLoader = module.getClassLoader();
Connector cmd = connectorXmlDescriptor != null ? connectorXmlDescriptor.getConnector() : null;
final IronJacamar ijmd = ironJacamarXmlDescriptor != null ? ironJacamarXmlDescriptor.getIronJacamar() : null;
try {
// Annotation merging
Annotations annotator = new Annotations();
Map<ResourceRoot, Index> indexes = AnnotationIndexUtils.getAnnotationIndexes(deploymentUnit);
for (Entry<ResourceRoot, Index> entry : indexes.entrySet()) {
AnnotationRepository repository = new JandexAnnotationRepositoryImpl(entry.getValue(), classLoader);
cmd = annotator.merge(cmd, repository, classLoader);
}
// FIXME: when the connector is null the Iron Jacamar data is ignored
if (cmd != null) {
// Validate metadata
cmd.validate();
// Merge metadata
cmd = (new Merger()).mergeConnectorWithCommonIronJacamar(ijmd, cmd);
}
final ServiceName deployerServiceName = ConnectorServices.RESOURCE_ADAPTER_DEPLOYER_SERVICE_PREFIX.append(connectorXmlDescriptor.getDeploymentName());
final ResourceAdapterDeploymentService raDeploymentService = new ResourceAdapterDeploymentService(connectorXmlDescriptor, cmd, ijmd, module, null);
final ServiceTarget serviceTarget = phaseContext.getServiceTarget();
// Create the service
ServiceBuilder builder = serviceTarget.addService(deployerServiceName, raDeploymentService)
.addDependency(ConnectorServices.IRONJACAMAR_MDR, MetadataRepository.class, raDeploymentService.getMdrInjector())
.addDependency(ConnectorServices.RA_REPOSITORY_SERVICE, ResourceAdapterRepository.class, raDeploymentService.getRaRepositoryInjector())
.addDependency(ConnectorServices.MANAGEMENT_REPOSITORY_SERVICE, ManagementRepository.class, raDeploymentService.getManagementRepositoryInjector())
.addDependency(ConnectorServices.RESOURCE_ADAPTER_REGISTRY_SERVICE, ResourceAdapterDeploymentRegistry.class, raDeploymentService.getRegistryInjector())
.addDependency(ConnectorServices.TRANSACTION_INTEGRATION_SERVICE, TransactionIntegration.class, raDeploymentService.getTxIntegrationInjector())
.addDependency(ConnectorServices.CONNECTOR_CONFIG_SERVICE, JcaSubsystemConfiguration.class, raDeploymentService.getConfigInjector())
.addDependency(SubjectFactoryService.SERVICE_NAME, SubjectFactory.class, raDeploymentService.getSubjectFactoryInjector())
.addDependency(ConnectorServices.CCM_SERVICE, CachedConnectionManager.class, raDeploymentService.getCcmInjector())
.addDependency(ConnectorServices.IDLE_REMOVER_SERVICE)
.addDependency(ConnectorServices.CONNECTION_VALIDATOR_SERVICE)
.addDependency(NamingService.SERVICE_NAME);
builder.addListener(new AbstractServiceListener<Object>() {
public void transition(final ServiceController<? extends Object> controller,
final ServiceController.Transition transition) {
switch (transition) {
case STARTING_to_UP: {
CommonDeployment deploymentMD = ((ResourceAdapterDeploymentService) controller.getService()).getRaDeployment();
if (deploymentMD.getConnectionManagers() != null ) {
for (ConnectionManager cm : deploymentMD.getConnectionManagers()) {
if(cm.getPool() != null) {
StatisticsPlugin poolStats = cm.getPool().getStatistics();
if (poolStats.getNames().size() != 0) {
DescriptionProvider statsResourceDescriptionProvider = new StatisticsDescriptionProvider(ResourceAdaptersSubsystemProviders.RESOURCE_NAME, "statistics", poolStats);
PathElement pe = PathElement.pathElement(ModelDescriptionConstants.SUBSYSTEM, ResourceAdaptersExtension.SUBSYSTEM_NAME);
PathElement peCD = PathElement.pathElement(Constants.CONNECTIONDEFINITIONS_NAME, cm.getJndiName());
ManagementResourceRegistration overrideRegistration = registration;
//when you are in deploy you have a registration pointing to deployment=*
//when you are in re-deploy it points to specific deploymentUnit
if (registration.isAllowsOverride()) {
overrideRegistration = registration.registerOverrideModel(deploymentUnit.getName(), new OverrideDescriptionProvider() {
@Override
public Map<String, ModelNode> getAttributeOverrideDescriptions(Locale locale) {
return Collections.emptyMap();
}
@Override
public Map<String, ModelNode> getChildTypeOverrideDescriptions(Locale locale) {
return Collections.emptyMap();
}
});
}
ManagementResourceRegistration subRegistration = overrideRegistration.getSubModel(PathAddress.pathAddress(pe));
if (subRegistration == null) {
subRegistration = overrideRegistration.registerSubModel(pe, new SubSystemExtensionDescriptionProvider(ResourceAdaptersSubsystemProviders.RESOURCE_NAME, "statistics"));
}
if (subRegistration.getSubModel(PathAddress.pathAddress(peCD)) == null) {
ManagementResourceRegistration cdSubRegistration = subRegistration.registerSubModel(peCD, statsResourceDescriptionProvider);
for (String statName : poolStats.getNames()) {
cdSubRegistration.registerMetric(statName, new PoolMetrics.ParametrizedPoolMetricsHandler(poolStats));
}
cdSubRegistration.registerOperationHandler("clear-statistics", new ClearStatisticsHandler(poolStats), ResourceAdaptersSubsystemProviders.CLEAR_STATISTICS_DESC, false);
}
}
}
}
}
break;
}
case UP_to_STOP_REQUESTED: {
PathElement pe = PathElement.pathElement(ModelDescriptionConstants.SUBSYSTEM, ResourceAdaptersExtension.SUBSYSTEM_NAME);
ManagementResourceRegistration overrideRegistration = registration.getOverrideModel(deploymentUnit.getName());
if (overrideRegistration.getSubModel(PathAddress.pathAddress(pe)) != null) {
overrideRegistration.unregisterSubModel(pe);
}
break;
}