Exemple #1
0
        private void InitializeDevice()
        {
            try
            {
                // Might encounter exception: Unable to cast object of type 'HP.DeviceAutomation.Phoenix.PhoenixDevice' to type 'HP.DeviceAutomation.Jedi.JediDevice'.
                // Device is still initializing operate a different web service which looks like a Phoenix device.
                _device = (JediDevice)DeviceConstructor.Create(_deviceInfo);
                _device.PowerManagement.Wake();
            }
            catch (Exception ex)
            {
                // Make sure the device is disposed, if necessary
                if (_device != null)
                {
                    _device.Dispose();
                    _device = null;
                }

                // Log the error and re-throw.
                ExecutionServices.SystemTrace.LogError(ex);
                throw;
            }
        }
Exemple #2
0
        /// <summary>
        /// Execute the task of the DeviceConfiguration activity.
        /// </summary>
        /// <param name="executionData"></param>
        /// <returns></returns>
        public PluginExecutionResult Execute(PluginExecutionData executionData)
        {
            _executionData = executionData;
            _activityData  = executionData.GetMetadata <DeviceInspectorActivityData>();
            TimeSpan lockTimeout = TimeSpan.FromMinutes(5);
            TimeSpan holdTimeout = TimeSpan.FromMinutes(5);
            ConcurrentDictionary <string, DataPair <string> > verifiedResults = new ConcurrentDictionary <string, DataPair <string> >();

            if (!_executionData.Assets.OfType <IDeviceInfo>().Any())
            {
                return(new PluginExecutionResult(PluginResult.Failed, "There were no assets retrieved.  If this is a count-based run, your reservation in asset inventory may have expired.", "DeviceInfo Asset error"));
            }

            ExecutionServices.SystemTrace.LogDebug("Beginning Update");

            try
            {
                //Parallel.ForEach(_executionData.Assets.OfType<IDeviceInfo>(),asset =>
                foreach (var asset in _executionData.Assets.OfType <IDeviceInfo>())
                {
                    JediDevice device = null;
                    try
                    {
                        try
                        {
                            device = DeviceConstructor.Create(asset) as JediDevice;
                        }
                        catch
                        {
                            device = DeviceFactory.Create(asset.Address) as JediDevice;
                        }

                        // Make sure the device is in a good state
                        var devicePrepManager = DevicePreparationManagerFactory.Create(device);
                        try
                        {
                            devicePrepManager.InitializeDevice(true);
                        }
                        catch (WebInspectorException webInspectorException)
                        {
                            //let's ignore initialise device errors, this might be due to inspection page in use,
                            //since we are not doing any control panel action, this should be ok
                            ExecutionServices.SystemTrace.LogDebug(webInspectorException.Message);
                        }


                        ExecutionServices.SystemTrace.LogDebug(
                            $"Processing {asset.AssetId} on thread {Thread.CurrentThread}");

                        AssetLockToken assetToken = new AssetLockToken(asset, lockTimeout, holdTimeout);

                        ExecutionServices.CriticalSection.Run(assetToken, () =>
                        {
                            ExecutionServices.SystemTrace.LogDebug(
                                $"Performing update on device {asset.AssetId} at address {asset.Address}");
                            var verifiedResult = UpdateDevice(device, asset);
                            verifiedResults.AddOrUpdate(asset.AssetId, verifiedResult, (key, oldvalue) => UpdateDevice(device, asset));
                        });
                    }
                    catch (DeviceCommunicationException deviceCommunicationException)
                    {
                        ExecutionServices.SystemTrace.LogDebug($"Unable to communicate with the device: {deviceCommunicationException.Message}");
                        verifiedResults.AddOrUpdate(asset.AssetId,
                                                    new DataPair <string> {
                            Key = "Device Communication", Value = false
                        },
                                                    (s, pair) => new DataPair <string>()
                        {
                            Key = "Device Communication", Value = false
                        });
                        device?.Dispose();
                    }
                    catch (Exception e)
                    {
                        ExecutionServices.SystemTrace.LogDebug(e);
                        verifiedResults.AddOrUpdate(asset.AssetId,
                                                    new DataPair <string> {
                            Key = "Failed Settings", Value = false
                        },
                                                    (s, pair) => new DataPair <string> {
                            Key = "Failed Settings", Value = false
                        });
                        device?.Dispose();
                    }
                }
            }
            catch
            {
                return(new PluginExecutionResult(PluginResult.Error, "Error during Device Configuration Setup"));
            }

            foreach (var verifiedResult in verifiedResults)
            {
                UpdateStatus($"Device: {verifiedResult.Key} Result: {verifiedResult.Value.Value}, {verifiedResult.Value.Key}");
            }

            if (verifiedResults.Any(x => x.Value.Value == false))
            {
                return(new PluginExecutionResult(PluginResult.Failed));
            }


            return(new PluginExecutionResult(PluginResult.Passed));
        }
        /// <summary>
        /// Execute the task of the DeviceConfiguration activity.
        /// </summary>
        /// <param name="executionData"></param>
        /// <returns></returns>
        public PluginExecutionResult Execute(PluginExecutionData executionData)
        {
            //bool result = false;
            _executionData = executionData;
            _activityData  = executionData.GetMetadata <DeviceConfigurationActivityData>();
            TimeSpan lockTimeout = TimeSpan.FromMinutes(10);
            TimeSpan holdTimeout = TimeSpan.FromMinutes(20);
            ConcurrentDictionary <string, DataPair <string> > results = new ConcurrentDictionary <string, DataPair <string> >();

            if (!_executionData.Assets.OfType <IDeviceInfo>().Any())
            {
                return(new PluginExecutionResult(PluginResult.Failed, "There were no assets retrieved.  If this is a count-based run, your reservation in asset inventory may have expired.", "DeviceInfo Asset error"));
            }

            ExecutionServices.SystemTrace.LogDebug("Beginning Update");

            try
            {
                //Parallel.ForEach(_executionData.Assets.OfType<IDeviceInfo>(), asset =>
                foreach (var asset in _executionData.Assets.OfType <IDeviceInfo>())
                {
                    JediDevice device = null;
                    try
                    {
                        //DeviceConfigResultLog log = new DeviceConfigResultLog(_executionData, asset.AssetId);
                        SetDefaultPassword(asset.Address, asset.AdminPassword);

                        try
                        {
                            device = DeviceConstructor.Create(asset) as JediDevice;
                        }
                        catch
                        {
                            device = DeviceFactory.Create(asset.Address) as JediDevice;
                        }

                        // Make sure the device is in a good state
                        var devicePrepManager = DevicePreparationManagerFactory.Create(device);
                        try
                        {
                            devicePrepManager.InitializeDevice(true);
                        }
                        catch (WebInspectorException webInspectorException)
                        {
                            //let's ignore initialise device errors, this might be due to inspection page in use,
                            //since we are not doing any control panel action, this should be ok
                            ExecutionServices.SystemTrace.LogDebug(webInspectorException.Message);
                        }

                        //devicePrepManager.PerformanceLogger = PerformanceLogger;

                        ExecutionServices.SystemTrace.LogDebug(
                            $"Processing {asset.AssetId} on thread {Thread.CurrentThread}");

                        AssetLockToken assetToken = new AssetLockToken(asset, lockTimeout, holdTimeout);

                        ExecutionServices.CriticalSection.Run(assetToken, () =>
                        {
                            ExecutionServices.SystemTrace.LogDebug(
                                $"Performing update on device {asset.AssetId} at address {asset.Address}");
                            var result = UpdateDevice(device, (AssetInfo)asset, _executionData);
                            results.AddOrUpdate(asset.AssetId, result,
                                                (key, oldValue) => UpdateDevice(device, (AssetInfo)asset, _executionData));
                            device?.Dispose();
                        });
                    }
                    catch (DeviceCommunicationException deviceCommunicationException)
                    {
                        ExecutionServices.SystemTrace.LogDebug($"Unable to communicate with the device: {deviceCommunicationException.Message}");
                        results.AddOrUpdate(asset.AssetId,
                                            new DataPair <string> {
                            Key = "Device Communication", Value = false
                        },
                                            (s, pair) => new DataPair <string>()
                        {
                            Key = "Device Communication", Value = false
                        });
                        device?.Dispose();
                    }
                    catch (Exception e)
                    {
                        ExecutionServices.SystemTrace.LogDebug(e);
                        results.AddOrUpdate(asset.AssetId,
                                            new DataPair <string> {
                            Key = "Failed Settings", Value = false
                        },
                                            (s, pair) => new DataPair <string> {
                            Key = "Failed Settings", Value = false
                        });
                        //[Veda]:we had few in use inspection pages error in subsequent plugin/activities, which was as a result of this plugin failing
                        //eg: invalid xml content. disposing the device to avoid those problems
                        device?.Dispose();
                    }
                }//);
            }
            catch
            {
                return(new PluginExecutionResult(PluginResult.Error, "Error during Device Configuration Setup"));
            }

            foreach (var item in results)
            {
                UpdateStatus($"Device {item.Key}: Result: {item.Value.Value}, {item.Value.Key}");
            }

            if (results.Any(x => x.Value.Value == false))
            {
                return(new PluginExecutionResult(PluginResult.Failed));
            }


            return(new PluginExecutionResult(PluginResult.Passed));
        }