@@ -5994,15 +5994,20 @@ public IAgentControl getAgentControl() {
59945994 }
59955995
59965996 @ Override
5997- public PingCommand getCurrentStatus (long id ) {
5998- gcAndKillHungWorkerVMs ();
5999-
6000- HashMap <String , State > newStates = sync ();
6001- if (newStates == null ) {
6002- return null ;
6003- }
6004- return new PingRoutingCommand (getType (), id , newStates , syncHostVmStates ());
6005- }
5997+ public PingCommand getCurrentStatus (long id ) {
5998+ try {
5999+ gcAndKillHungWorkerVMs ();
6000+
6001+ HashMap <String , State > newStates = sync ();
6002+ if (newStates == null ) {
6003+ return null ;
6004+ }
6005+ return new PingRoutingCommand (getType (), id , newStates ,
6006+ syncHostVmStates ());
6007+ } finally {
6008+ recycleServiceContext ();
6009+ }
6010+ }
60066011
60076012 private void gcAndKillHungWorkerVMs () {
60086013 try {
@@ -6071,8 +6076,6 @@ else if(prop.getName().equals(workerTagPropName)) {
60716076 s_logger .warn ("Encounter remote exception to vCenter, invalidate VMware session context" );
60726077 invalidateServiceContext ();
60736078 }
6074- } finally {
6075- recycleServiceContext ();
60766079 }
60776080 }
60786081
@@ -6939,67 +6942,62 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
69396942 _guestTrafficInfo = (VmwareTrafficLabel ) params .get ("guestTrafficInfo" );
69406943 _publicTrafficInfo = (VmwareTrafficLabel ) params .get ("publicTrafficInfo" );
69416944 VmwareContext context = getServiceContext ();
6942-
6943- // TODO ??? this is an invalid usage pattern. need to fix the reference to VolumeManagerImp here at resource file
6944- // volMgr = ComponentContext.inject(VolumeManagerImpl.class);
6945- try {
6946- VmwareManager mgr = context .getStockObject (VmwareManager .CONTEXT_STOCK_NAME );
6947- mgr .setupResourceStartupParams (params );
6948-
6949- CustomFieldsManagerMO cfmMo = new CustomFieldsManagerMO (context , context .getServiceContent ().getCustomFieldsManager ());
6950- cfmMo .ensureCustomFieldDef ("Datastore" , CustomFieldConstants .CLOUD_UUID );
6951- if (_publicTrafficInfo != null && _publicTrafficInfo .getVirtualSwitchType () != VirtualSwitchType .StandardVirtualSwitch ||
6952- _guestTrafficInfo != null && _guestTrafficInfo .getVirtualSwitchType () != VirtualSwitchType .StandardVirtualSwitch ) {
6953- cfmMo .ensureCustomFieldDef ("DistributedVirtualPortgroup" , CustomFieldConstants .CLOUD_GC_DVP );
6954- }
6955- cfmMo .ensureCustomFieldDef ("Network" , CustomFieldConstants .CLOUD_GC );
6956- cfmMo .ensureCustomFieldDef ("VirtualMachine" , CustomFieldConstants .CLOUD_UUID );
6957- cfmMo .ensureCustomFieldDef ("VirtualMachine" , CustomFieldConstants .CLOUD_NIC_MASK );
6958- cfmMo .ensureCustomFieldDef ("VirtualMachine" , CustomFieldConstants .CLOUD_VM_INTERNAL_NAME );
6959- cfmMo .ensureCustomFieldDef ("VirtualMachine" , CustomFieldConstants .CLOUD_WORKER );
6960- cfmMo .ensureCustomFieldDef ("VirtualMachine" , CustomFieldConstants .CLOUD_WORKER_TAG );
6961-
6962- VmwareHypervisorHost hostMo = this .getHyperHost (context );
6963- _hostName = hostMo .getHyperHostName ();
6964-
6965- Map <String , String > vsmCredentials ;
6966- if (_guestTrafficInfo .getVirtualSwitchType () == VirtualSwitchType .NexusDistributedVirtualSwitch ||
6967- _publicTrafficInfo .getVirtualSwitchType () == VirtualSwitchType .NexusDistributedVirtualSwitch ) {
6968- vsmCredentials = mgr .getNexusVSMCredentialsByClusterId (Long .parseLong (_cluster ));
6969- if (vsmCredentials != null ) {
6970- s_logger .info ("Stocking credentials while configuring resource." );
6971- context .registerStockObject ("vsmcredentials" , vsmCredentials );
6972- }
6973- _privateNetworkVSwitchName = mgr .getPrivateVSwitchName (Long .parseLong (_dcId ), HypervisorType .VMware );
6945+ VmwareManager mgr = context .getStockObject (VmwareManager .CONTEXT_STOCK_NAME );
6946+ if (mgr == null ) {
6947+ throw new ConfigurationException ("Invalid vmwareContext: vmwareMgr stock object is not set or cleared." );
6948+ }
6949+ mgr .setupResourceStartupParams (params );
6950+
6951+ CustomFieldsManagerMO cfmMo = new CustomFieldsManagerMO (context , context .getServiceContent ().getCustomFieldsManager ());
6952+ cfmMo .ensureCustomFieldDef ("Datastore" , CustomFieldConstants .CLOUD_UUID );
6953+ if (_publicTrafficInfo != null && _publicTrafficInfo .getVirtualSwitchType () != VirtualSwitchType .StandardVirtualSwitch ||
6954+ _guestTrafficInfo != null && _guestTrafficInfo .getVirtualSwitchType () != VirtualSwitchType .StandardVirtualSwitch ) {
6955+ cfmMo .ensureCustomFieldDef ("DistributedVirtualPortgroup" , CustomFieldConstants .CLOUD_GC_DVP );
6956+ }
6957+ cfmMo .ensureCustomFieldDef ("Network" , CustomFieldConstants .CLOUD_GC );
6958+ cfmMo .ensureCustomFieldDef ("VirtualMachine" , CustomFieldConstants .CLOUD_UUID );
6959+ cfmMo .ensureCustomFieldDef ("VirtualMachine" , CustomFieldConstants .CLOUD_NIC_MASK );
6960+ cfmMo .ensureCustomFieldDef ("VirtualMachine" , CustomFieldConstants .CLOUD_VM_INTERNAL_NAME );
6961+ cfmMo .ensureCustomFieldDef ("VirtualMachine" , CustomFieldConstants .CLOUD_WORKER );
6962+ cfmMo .ensureCustomFieldDef ("VirtualMachine" , CustomFieldConstants .CLOUD_WORKER_TAG );
6963+
6964+ VmwareHypervisorHost hostMo = this .getHyperHost (context );
6965+ _hostName = hostMo .getHyperHostName ();
6966+
6967+ Map <String , String > vsmCredentials ;
6968+ if (_guestTrafficInfo .getVirtualSwitchType () == VirtualSwitchType .NexusDistributedVirtualSwitch ||
6969+ _publicTrafficInfo .getVirtualSwitchType () == VirtualSwitchType .NexusDistributedVirtualSwitch ) {
6970+ vsmCredentials = mgr .getNexusVSMCredentialsByClusterId (Long .parseLong (_cluster ));
6971+ if (vsmCredentials != null ) {
6972+ s_logger .info ("Stocking credentials while configuring resource." );
6973+ context .registerStockObject ("vsmcredentials" , vsmCredentials );
69746974 }
6975-
6976- } catch (Exception e ) {
6977- s_logger .error ("Unexpected Exception " , e );
6975+ _privateNetworkVSwitchName = mgr .getPrivateVSwitchName (Long .parseLong (_dcId ), HypervisorType .VMware );
69786976 }
69796977
6980- if (_privateNetworkVSwitchName == null ) {
6981- _privateNetworkVSwitchName = (String ) params .get ("private.network.vswitch.name" );
6978+ if (_privateNetworkVSwitchName == null ) {
6979+ _privateNetworkVSwitchName = (String )params .get ("private.network.vswitch.name" );
69826980 }
69836981
6984- String value = (String ) params .get ("vmware.reserve.cpu" );
6985- if (value != null && value .equalsIgnoreCase ("true" ))
6982+ String value = (String )params .get ("vmware.reserve.cpu" );
6983+ if (value != null && value .equalsIgnoreCase ("true" ))
69866984 _reserveCpu = true ;
69876985
6988- value = (String ) params .get ("vmware.recycle.hung.wokervm" );
6989- if (value != null && value .equalsIgnoreCase ("true" ))
6986+ value = (String )params .get ("vmware.recycle.hung.wokervm" );
6987+ if (value != null && value .equalsIgnoreCase ("true" ))
69906988 _recycleHungWorker = true ;
69916989
6992- value = (String ) params .get ("vmware.reserve.mem" );
6993- if (value != null && value .equalsIgnoreCase ("true" ))
6990+ value = (String )params .get ("vmware.reserve.mem" );
6991+ if (value != null && value .equalsIgnoreCase ("true" ))
69946992 _reserveMem = true ;
69956993
69966994 value = (String )params .get ("vmware.root.disk.controller" );
6997- if (value != null && value .equalsIgnoreCase ("scsi" ))
6995+ if (value != null && value .equalsIgnoreCase ("scsi" ))
69986996 _rootDiskController = DiskControllerType .scsi ;
69996997 else
70006998 _rootDiskController = DiskControllerType .ide ;
70016999
7002- Integer intObj = (Integer ) params .get ("ports.per.dvportgroup" );
7000+ Integer intObj = (Integer )params .get ("ports.per.dvportgroup" );
70037001 if (intObj != null )
70047002 _portsPerDvPortGroup = intObj .intValue ();
70057003
@@ -7009,29 +7007,34 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
70097007 ", guest traffic over " + _guestTrafficInfo .getVirtualSwitchType () + " : " +
70107008 _guestTrafficInfo .getVirtualSwitchName ());
70117009
7012- value = params .get ("vmware.create.full.clone" ). toString ( );
7013- if (value != null && value . equalsIgnoreCase ( "true" )) {
7010+ Boolean boolObj = ( Boolean ) params .get ("vmware.create.full.clone" );
7011+ if (boolObj != null && boolObj . booleanValue ( )) {
70147012 _fullCloneFlag = true ;
70157013 } else {
70167014 _fullCloneFlag = false ;
70177015 }
70187016
7019- value = params .get ("vm.instancename.flag" ). toString ( );
7020- if (value != null && value . equalsIgnoreCase ( "true" )) {
7017+ boolObj = ( Boolean ) params .get ("vm.instancename.flag" );
7018+ if (boolObj != null && boolObj . booleanValue ( )) {
70217019 _instanceNameFlag = true ;
70227020 } else {
70237021 _instanceNameFlag = false ;
70247022 }
70257023
70267024 value = (String )params .get ("scripts.timeout" );
70277025 int timeout = NumbersUtil .parseInt (value , 1440 ) * 1000 ;
7028- VmwareManager mgr = context .getStockObject (VmwareManager .CONTEXT_STOCK_NAME );
70297026 VmwareStorageProcessor storageProcessor = new VmwareStorageProcessor ((VmwareHostService )this , _fullCloneFlag , (VmwareStorageMount )mgr ,
70307027 timeout , this , _shutdown_waitMs , null
70317028 );
70327029 storageHandler = new VmwareStorageSubsystemCommandHandler (storageProcessor );
70337030
7031+ if (s_logger .isTraceEnabled ()) {
7032+ s_logger .trace ("Successfully configured VmwareResource." );
7033+ }
70347034 return true ;
7035+ } catch (Exception e ) {
7036+ s_logger .error ("Unexpected Exception " , e );
7037+ throw new ConfigurationException ("Failed to configure VmwareResource due to unexpect exception." );
70357038 } finally {
70367039 recycleServiceContext ();
70377040 }
@@ -7070,6 +7073,9 @@ public VmwareContext getServiceContext(Command cmd) {
70707073 if (s_serviceContext .get () != null ) {
70717074 context = s_serviceContext .get ();
70727075 if (context .validate ()) {
7076+ if (s_logger .isTraceEnabled ()) {
7077+ s_logger .trace ("ThreadLocal context is still valid, just reuse" );
7078+ }
70737079 return context ;
70747080 } else {
70757081 s_logger .info ("Validation of the context failed, dispose and use a new one" );
@@ -7097,10 +7103,16 @@ public void invalidateServiceContext(VmwareContext context) {
70977103
70987104 private static void recycleServiceContext () {
70997105 VmwareContext context = s_serviceContext .get ();
7106+ if (s_logger .isTraceEnabled ()) {
7107+ s_logger .trace ("Reset threadlocal context to null" );
7108+ }
71007109 s_serviceContext .set (null );
71017110
71027111 if (context != null ) {
71037112 assert (context .getPool () != null );
7113+ if (s_logger .isTraceEnabled ()) {
7114+ s_logger .trace ("Recycling threadlocal context to pool" );
7115+ }
71047116 context .getPool ().returnContext (context );
71057117 }
71067118 }
0 commit comments