/** * @param managedComponent * @throws Exception */ protected void updateComponent(ManagedComponent managedComponent) throws Exception { log.trace( "Updating " + this.name + " with component " //$NON-NLS-1$ //$NON-NLS-2$ + managedComponent.toString() + "..."); //$NON-NLS-1$ ManagementView managementView = getConnection().getManagementView(); managementView.updateComponent(managedComponent); }
/** * Validate that there is only 1 DefaultDS ManagedComponent * * @throws Exception */ public void testJTAComponentCount() throws Exception { ManagementView mgtView = getManagementView(); ComponentType type = new ComponentType("MCBean", "JTA"); Set<ManagedComponent> comps = mgtView.getComponentsForType(type); int count = comps.size(); assertEquals("There is 1 MCBean:JTA ManagedComponent", 1, 1); ManagedComponent comp = comps.iterator().next(); Map<String, ManagedProperty> props = comp.getProperties(); for (ManagedProperty prop : props.values()) { log.info(prop + ", : " + prop.getValue()); } }
/** * Test adding a new no-tx-connection-factory deployment * * @throws Exception */ public void testAddNoTxConnectionFactory() throws Exception { String jndiName = "TestNoTxCf"; Map<String, MetaValue> propValues = new HashMap<String, MetaValue>(); addCommonCfProperties( propValues, jndiName, "jms-ra.rar", "org.jboss.resource.adapter.jms.JmsConnectionFactory"); Map<String, String> xaProps = new HashMap<String, String>(); xaProps.put("SessionDefaultType", "javax.jms.Topic"); xaProps.put("SessionDefaultType.type", "java.lang.String"); xaProps.put("JmsProviderAdapterJNDI", "java:/DefaultJMSProvider"); xaProps.put("JmsProviderAdapterJNDI.type", "java.lang.String"); MetaValue metaValue = this.compositeValueMap(xaProps); propValues.put("config-property", metaValue); propValues.put( "config-property", new MapCompositeValueSupport( new HashMap<String, MetaValue>(), new MapCompositeMetaType(SimpleMetaType.STRING))); // todo: how to set the specific domain? // ApplicationManagedSecurityMetaData secDomain = new ApplicationManagedSecurityMetaData(); // props.get("security-domain").setValue(secDomain); ComponentType compType = new ComponentType("ConnectionFactory", "NoTx"); createComponentTest( "NoTxConnectionFactoryTemplate", propValues, "testNoTxCf", compType, jndiName); // Validate the config-property ManagementView mgtView = getManagementView(); ManagedComponent dsMC = getManagedComponent(mgtView, compType, jndiName); ManagedProperty configProperty = dsMC.getProperty("config-property"); assertNotNull(configProperty); MetaValue value = configProperty.getValue(); assertTrue("MapCompositeMetaType", value.getMetaType() instanceof MapCompositeMetaType); MapCompositeValueSupport cValue = (MapCompositeValueSupport) value; cValue.put("testKey", new SimpleValueSupport(SimpleMetaType.STRING, "testValue")); mgtView.updateComponent(dsMC); mgtView = getManagementView(); dsMC = getManagedComponent(mgtView, compType, jndiName); configProperty = dsMC.getProperty("config-property"); assertNotNull(configProperty); cValue = (MapCompositeValueSupport) configProperty.getValue(); assertNotNull(cValue.get("testKey")); }
/** * The plugin container will call this method when it has a new configuration for your managed * resource. Your plugin will re-configure the managed resource in your own custom way, setting * its configuration based on the new values of the given configuration. * * @see ConfigurationFacet#updateResourceConfiguration(ConfigurationUpdateReport) */ public void updateResourceConfiguration(ConfigurationUpdateReport report) { resourceConfiguration = report.getConfiguration().deepCopy(); Configuration resourceConfig = report.getConfiguration(); ManagementView managementView = null; ComponentType componentType = null; if (this.getComponentType().equals(PluginConstants.ComponentType.VDB.NAME)) { componentType = new ComponentType( PluginConstants.ComponentType.VDB.TYPE, PluginConstants.ComponentType.VDB.SUBTYPE); } else { report.setStatus(ConfigurationUpdateStatus.FAILURE); report.setErrorMessage("Update not implemented for the component type."); // $NON-NLS-1$ } ManagedComponent managedComponent = null; report.setStatus(ConfigurationUpdateStatus.SUCCESS); try { managementView = getConnection().getManagementView(); managedComponent = managementView.getComponent(this.name, componentType); Map<String, ManagedProperty> managedProperties = managedComponent.getProperties(); ProfileServiceUtil.convertConfigurationToManagedProperties( managedProperties, resourceConfig, resourceContext.getResourceType(), null); try { managementView.updateComponent(managedComponent); } catch (Exception e) { LOG.error( "Unable to update component [" //$NON-NLS-1$ + managedComponent.getName() + "] of type " //$NON-NLS-1$ + componentType + ".", e); //$NON-NLS-1$ report.setStatus(ConfigurationUpdateStatus.FAILURE); report.setErrorMessageFromThrowable(e); } } catch (Exception e) { LOG.error("Unable to process update request", e); // $NON-NLS-1$ report.setStatus(ConfigurationUpdateStatus.FAILURE); report.setErrorMessageFromThrowable(e); } }
/** * Test adding a new tx-connection-factory deployment with xa enabled * * @throws Exception */ public void testAddTxXAConnectionFactory() throws Exception { String jndiName = "TestTxCf"; Map<String, MetaValue> propValues = new HashMap<String, MetaValue>(); addCommonCfProperties( propValues, jndiName, "jms-ra.rar", "org.jboss.resource.adapter.jms.JmsConnectionFactory"); Map<String, String> xaProps = new HashMap<String, String>(); xaProps.put("SessionDefaultType", "javax.jms.Topic"); xaProps.put("SessionDefaultType.type", "java.lang.String"); xaProps.put("JmsProviderAdapterJNDI", "java:/DefaultJMSProvider"); xaProps.put("JmsProviderAdapterJNDI.type", "java.lang.String"); MetaValue metaValue = this.compositeValueMap(xaProps); propValues.put("config-property", metaValue); propValues.put("xa-transaction", SimpleValueSupport.wrap(Boolean.TRUE)); propValues.put("xa-resource-timeout", SimpleValueSupport.wrap(new Integer(256))); propValues.put("interleaving", SimpleValueSupport.wrap(Boolean.TRUE)); // todo: how to set the specific domain? // ApplicationManagedSecurityMetaData secDomain = new ApplicationManagedSecurityMetaData(); // props.get("security-domain").setValue(secDomain); createComponentTest( "TxConnectionFactoryTemplate", propValues, "testTxXACf", new ComponentType("ConnectionFactory", "Tx"), jndiName); // Query the interleaving ManagementView mgtView = getManagementView(); ComponentType type = new ComponentType("ConnectionFactory", "Tx"); ManagedComponent txcf = mgtView.getComponent(jndiName, type); assertNotNull(txcf); ManagedProperty interleaving = txcf.getProperty("interleaving"); assertNotNull("interleaving", interleaving); MetaValue interleavingMV = interleaving.getValue(); assertNotNull("interleaving.value", interleavingMV); assertEquals(SimpleValueSupport.wrap(Boolean.TRUE), interleavingMV); }
/** * Test adding a new hsql DataSource deployment * * @throws Exception */ public void testAddXADataSource() throws Exception { String jndiName = "TestXaDs"; Map<String, MetaValue> propValues = new HashMap<String, MetaValue>(); addCommonDsProperties(propValues, jndiName, "jboss-xa-jdbc.rar", "javax.sql.DataSource"); propValues.put("xa-datasource-class", SimpleValueSupport.wrap("org.hsqldb.jdbcDriver")); propValues.put("xa-resource-timeout", SimpleValueSupport.wrap(new Integer(256))); propValues.put("interleaving", SimpleValueSupport.wrap(true)); HashMap<String, String> xaPropValues = new HashMap<String, String>(); xaPropValues.put("URL", "jdbc:hsqldb"); xaPropValues.put("User", "sa"); xaPropValues.put("Password", ""); // MetaValue metaValue = getMetaValueFactory().create(xaPropValues, getMapType()); MetaValue metaValue = this.compositeValueMap(xaPropValues); propValues.put("xa-datasource-properties", metaValue); createComponentTest( "XADataSourceTemplate", propValues, "testXaDs", KnownComponentTypes.DataSourceTypes.XA.getType(), jndiName); // Query the interleaving ManagementView mgtView = getManagementView(); ComponentType type = KnownComponentTypes.DataSourceTypes.XA.getType(); ManagedComponent txcf = mgtView.getComponent(jndiName, type); assertNotNull(txcf); ManagedProperty interleaving = txcf.getProperty("interleaving"); assertNotNull("interleaving", interleaving); MetaValue interleavingMV = interleaving.getValue(); assertNotNull("interleaving.value", interleavingMV); assertEquals( "interleaving.value is true", SimpleValueSupport.wrap(Boolean.TRUE), interleavingMV); }
protected void createComponentTest( String templateName, Map<String, MetaValue> propValues, String deploymentName, ComponentType componentType, String componentName) throws Exception { ManagementView mgtView = getManagementView(); DeploymentTemplateInfo dsInfo = mgtView.getTemplate(templateName); assertNotNull("template " + templateName + " found", dsInfo); Map<String, ManagedProperty> props = dsInfo.getProperties(); for (String propName : propValues.keySet()) { ManagedProperty prop = props.get(propName); // If the property does not exist on the template we don't set it if (prop == null) continue; log.debug("template property before: " + prop.getName() + "," + prop.getValue()); assertNotNull("property " + propName + " found in template " + templateName, prop); prop.setValue(propValues.get(propName)); log.debug("template property after: " + prop.getName() + "," + prop.getValue()); } // Assert map composite if (dsInfo.getProperties().get("config-property") != null) assertTrue( dsInfo.getProperties().get("config-property").getMetaType() instanceof MapCompositeMetaType); mgtView.applyTemplate(deploymentName, dsInfo); // reload the view activeView = null; mgtView = getManagementView(); ManagedComponent dsMC = getManagedComponent(mgtView, componentType, componentName); assertNotNull(dsMC); Set<String> mcPropNames = new HashSet<String>(dsMC.getPropertyNames()); for (String propName : propValues.keySet()) { ManagedProperty prop = dsMC.getProperty(propName); log.debug("Checking: " + propName); assertNotNull(propName, prop); Object propValue = prop.getValue(); Object expectedValue = propValues.get(propName); if (propValue instanceof MetaValue) { if (prop.getMetaType().isComposite()) { // TODO / FIXME - compare composites log.warn("Not checking composite: " + propValue); } else { // Compare the MetaValues assertEquals(prop.getName(), expectedValue, propValue); } } else if (propValue != null) { fail(prop.getName() + " is not a MetaValue: " + propValue); } mcPropNames.remove(propName); } if (!mcPropNames.isEmpty()) { log.warn(getName() + "> untested properties: " + mcPropNames); for (String propName : mcPropNames) { ManagedProperty prop = dsMC.getProperty(propName); log.info(prop); } } }
private CreateResourceReport createConfigurationBasedResource( CreateResourceReport createResourceReport) { ResourceType resourceType = createResourceReport.getResourceType(); Configuration defaultPluginConfig = getDefaultPluginConfiguration(resourceType); Configuration resourceConfig = createResourceReport.getResourceConfiguration(); String resourceName = getResourceName(defaultPluginConfig, resourceConfig); ComponentType componentType = ProfileServiceUtil.getComponentType(resourceType); ManagementView managementView = null; ; managementView = getConnection().getManagementView(); if (ProfileServiceUtil.isManagedComponent(getConnection(), resourceName, componentType)) { createResourceReport.setStatus(CreateResourceStatus.FAILURE); createResourceReport.setErrorMessage( "A " + resourceType.getName() // $NON-NLS-1$ + " named '" + resourceName + "' already exists."); //$NON-NLS-1$ //$NON-NLS-2$ return createResourceReport; } createResourceReport.setResourceName(resourceName); String resourceKey = getResourceKey(resourceType, resourceName); createResourceReport.setResourceKey(resourceKey); PropertySimple templateNameProperty = resourceConfig.getSimple(TranslatorComponent.Config.TEMPLATE_NAME); String templateName = templateNameProperty.getStringValue(); DeploymentTemplateInfo template; try { template = managementView.getTemplate(templateName); Map<String, ManagedProperty> managedProperties = template.getProperties(); ProfileServiceUtil.convertConfigurationToManagedProperties( managedProperties, resourceConfig, resourceType, null); LOG.debug( "Applying template [" + templateName //$NON-NLS-1$ + "] to create ManagedComponent of type [" + componentType //$NON-NLS-1$ + "]..."); //$NON-NLS-1$ try { managementView.applyTemplate(resourceName, template); managementView.process(); createResourceReport.setStatus(CreateResourceStatus.SUCCESS); } catch (Exception e) { LOG.error( "Unable to apply template [" + templateName //$NON-NLS-1$ + "] to create ManagedComponent of type " //$NON-NLS-1$ + componentType + ".", e); //$NON-NLS-1$ createResourceReport.setStatus(CreateResourceStatus.FAILURE); createResourceReport.setException(e); } } catch (NoSuchDeploymentException e) { LOG.error("Unable to find template [" + templateName + "].", e); // $NON-NLS-1$ //$NON-NLS-2$ createResourceReport.setStatus(CreateResourceStatus.FAILURE); createResourceReport.setException(e); } catch (Exception e) { LOG.error("Unable to process create request", e); // $NON-NLS-1$ createResourceReport.setStatus(CreateResourceStatus.FAILURE); createResourceReport.setException(e); } return createResourceReport; }