@@ -548,11 +548,49 @@ public ResourceUpgradeReport upgrade(ResourceUpgradeContext inventoriedResource)
548548 if (supportsPatching == null || supportsPatching .startsWith ("__UNINITIALIZED_" )) {
549549 upgraded = true ;
550550
551- JBossProductType productType = JBossProductType .valueOf (pluginConfiguration .getSimpleValue ("productType" ));
552- pluginConfiguration
551+ JBossProductType productType = serverPluginConfiguration .getProductType ();
552+ if (productType == null ) {
553+ if (inventoriedResource .getNativeProcess () != null ) {
554+ // if resource seems to run, detect product type
555+ AS7CommandLine commandLine = new AS7CommandLine (inventoriedResource .getNativeProcess ());
556+ File homeDir = getHomeDir (inventoriedResource .getNativeProcess (), commandLine );
557+ File baseDir = getBaseDir (inventoriedResource .getNativeProcess (), commandLine , homeDir );
558+ File configDir = getConfigDir (inventoriedResource .getNativeProcess (), commandLine , baseDir );
559+ File hostXmlFile = getHostXmlFile (commandLine , configDir );
560+ if (hostXmlFile .exists ()) {
561+ try {
562+ HostConfiguration hostConfig = loadHostConfiguration (hostXmlFile );
563+ String apiVersion = hostConfig .getDomainApiVersion ();
564+ productType = JBossProductType .determineJBossProductType (homeDir , apiVersion );
565+ serverPluginConfiguration .setProductType (productType );
566+ pluginConfiguration .setSimpleValue ("supportsPatching" ,
567+ Boolean .toString (supportsPatching (productType , inventoriedResource .getVersion ())));
568+ report .setNewPluginConfiguration (pluginConfiguration );
569+ LOG .info (productType );
570+ } catch (Exception e ) {
571+ LOG .warn ("Unable to detect productType" , e );
572+ }
573+ } else {
574+ LOG .warn ("Unable to upgrade resource " + inventoriedResource
575+ + "Server configuration file not found at the expected location (" + hostXmlFile + ")." );
576+ upgraded = false ;
577+ }
578+
579+
580+ } else {
581+ // we have to skip upgrading at this point since it is not running and we're unable to detect productType
582+ LOG .warn ("Unable to upgrade resource "
583+ + inventoriedResource
584+ + " : resource is missing productType pluginConfiguration property and needs to be running in order to discover it" );
585+ upgraded = false ;
586+ }
587+ } else {
588+ pluginConfiguration
553589 .setSimpleValue ("supportsPatching" , Boolean .toString (supportsPatching (productType , inventoriedResource .getVersion ())));
590+ report .setNewPluginConfiguration (pluginConfiguration );
591+ }
592+
554593
555- report .setNewPluginConfiguration (pluginConfiguration );
556594 }
557595 // detect if server is running and has default values
558596 if (inventoriedResource .getNativeProcess () != null
0 commit comments