官术网_书友最值得收藏!

Idempotence

Idempotence is an important concept, sometimes confusing, that we will touch on many times throughout this book. Idempotence is defined as an operation that has no additional effect if it is called more than once with the same input. Put another way, it is an operation that can be executed as many times as desired, and it will only change the system state if, and only if, it is not what the desired state is. For example, a PowerShell function looks for the x state and guarantees that it will only change the state of the system if it is not x.

It may seem silly to state something as obvious as this. If you feel this way, think of an MSI installer that installs version 1.1.1.0 of an imaginary software product. When you run the MSI, it only ever installs the software if it isn't already present on the system or if the version present is older than the current version. No matter how many times you execute the MSI, it will only change the system if version 1.1.1.0 is not on the system. This is idempotency. The MSI will only ever change the system state if it is not the desired state, no matter how many times you run it.

Idempotent operations are often used in network protocols or API design between dependent systems and are used in DSC by DSC resources. DSC resources are required to be idempotent in that they do not change the system if the system is in the state that the resource expects it to be in. For example, a DSC resource that operates on Windows Services will only try to start a given service if it is stopped, not if it is started. Another example is the DSC file resource, as that will change a file only if the contents do not match the expected string. By requiring idempotency, DSC resources can be run as many times as you want without ever performing an unexpected change.

When you install a piece of software on a machine that already has that software installed on it, you don't want there to be two copies of the software after you're done. You want the installer to be smart enough to detect the version of the currently installed software and then examine the version that you're attempting to install and ultimately decide that the versions match and no installation needs to be done. That is idempotency in a nutshell.

主站蜘蛛池模板: 镇江市| 富裕县| 靖安县| 牙克石市| 柳州市| 湘西| 康保县| 阳高县| 分宜县| 封丘县| 东丽区| 饶河县| 西乌珠穆沁旗| 江北区| 宜昌市| 岐山县| 安国市| 遂平县| 海原县| 三门峡市| 衢州市| 和林格尔县| 五河县| 阿勒泰市| 织金县| 荥阳市| 彭水| 罗江县| 东台市| 静海县| 衡阳县| 丰台区| 江津市| 田东县| 白水县| 全南县| 通江县| 武乡县| 厦门市| 西畴县| 积石山|