Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions iis/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ var (
"username": hclspec.NewAttr("username", "string", false),
"password": hclspec.NewAttr("password", "string", false),
})),
"resource_limit": hclspec.NewBlock("resource_limit", false, hclspec.NewObject(map[string]*hclspec.Spec{
"cpu_limit": hclspec.NewAttr("cpu_limit", "number", true),
"memory_limit": hclspec.NewAttr("memory_limit", "number", true),
})),
Comment on lines +90 to +93
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this feature, I would prefer we use the resources stanza from Nomad and apply said values to IIS rather than configuring it within the driver config stanza.

https://www.nomadproject.io/docs/job-specification/resources

The resources stanza is a required setting for a nomad job spec, so we shouldn't have to worry about the value not being set. There might be a bit of conversion needed between nomad's value and types to what IIS is expecting, but this will facilitate a better UX for users who use other drivers and their settings.

"bindings": hclspec.NewBlockList("bindings", hclspec.NewObject(map[string]*hclspec.Spec{
"hostname": hclspec.NewAttr("hostname", "string", false),
"ipaddress": hclspec.NewAttr("ipaddress", "string", false),
Expand Down Expand Up @@ -123,6 +127,7 @@ type TaskConfig struct {
AppPoolConfigPath string `codec:"apppool_config_path"`
SiteConfigPath string `codec:"site_config_path"`
AppPoolIdentity iisAppPoolIdentity `codec:"apppool_identity"`
AppPoolResources iisResourceLimit `codec:"resource_limit"`
Bindings []iisBinding `codec:"bindings"`
}

Expand Down
45 changes: 45 additions & 0 deletions iis/iis.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,12 @@ type iisAppPoolIdentity struct {
Username string `codec:"username"`
}

// IIS ResourceLimit used for Application pool worker process
type iisResourceLimit struct {
CPULimit int `codec:"cpu_limit"`
MemoryLimit int `codec:"memory_limit"`
}

// IIS Binding struct to match
type iisBinding struct {
CertHash string `codec:"cert_hash"`
Expand Down Expand Up @@ -259,6 +265,42 @@ func applyAppPoolIdentity(appPoolName string, appPoolIdentity iisAppPoolIdentity
return nil
}

// Applies the Application Pool resource limit
func applyAppPoolResourceLimit(appPoolName string, appPoolResource iisResourceLimit) error {
properties := []string{"set", "config", "-section:system.applicationHost/applicationPools"}

if appPoolResource.CPULimit != 0 {

cpuLimitSize := appPoolResource.CPULimit * 1000

properties = append(properties, fmt.Sprintf("/[name='%s'].cpu.limit:%s", appPoolName, strconv.Itoa(cpuLimitSize)))
properties = append(properties, fmt.Sprintf("/commit:apphost"))

if _, err := executeAppCmd(properties...); err != nil {
return fmt.Errorf("Failed to set Application Pool Resources: %v", err)
}
}
properties = []string{"set", "config", "-section:system.applicationHost/applicationPools"}

properties = append(properties, fmt.Sprintf("/[name='%s'].cpu.action:%s", appPoolName, "KillW3wp"))
properties = append(properties, fmt.Sprintf("/commit:apphost"))
if _, err := executeAppCmd(properties...); err != nil {
return fmt.Errorf("Failed to set Application Pool Resources: %v", err)
}
Comment on lines +283 to +289
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer this be a part of the CPULimit scope above as this pertains to configuring the CPU. Does applying this settings cause a noop if the CPULimit is left at 0?


properties = []string{"set", "config", "-section:system.applicationHost/applicationPools"}

if appPoolResource.MemoryLimit != 0 {
memoryLimitSize := appPoolResource.MemoryLimit * 1000
properties = append(properties, fmt.Sprintf("/[name='%s'].recycling.periodicRestart.privateMemory:%s", appPoolName, strconv.Itoa(memoryLimitSize)))
properties = append(properties, fmt.Sprintf("/commit:apphost"))
if _, err := executeAppCmd(properties...); err != nil {
return fmt.Errorf("Failed to set Application Pool Resources: %v", err)
}
}
return nil
}

// Creates an Application Pool with the given name and applies an IIS exported Application Pool xml if a path is provided
func createAppPool(appPoolName string, configPath string) error {
if exists, err := doesAppPoolExist(appPoolName); err != nil || exists {
Expand Down Expand Up @@ -593,6 +635,9 @@ func createWebsite(websiteName string, config *TaskConfig) error {
if err := applyAppPoolIdentity(websiteName, config.AppPoolIdentity); err != nil {
return err
}
if err := applyAppPoolResourceLimit(websiteName, config.AppPoolResources); err != nil {
return err
}
if err := createSite(websiteName, config.Path, config.SiteConfigPath); err != nil {
return err
}
Expand Down
4 changes: 4 additions & 0 deletions iis/iis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,10 @@ func TestWebsite(t *testing.T) {
{Type: "http", Port: 8080},
{Type: "https", Port: 8081, CertHash: hash},
},
AppPoolResources: iisResourceLimit{
CPULimit: 50,
MemoryLimit: 500,
},
AppPoolConfigPath: "C:\\vagrant\\vagrant\\testapppool.xml",
SiteConfigPath: "C:\\vagrant\\vagrant\\testsite.xml",
}
Expand Down