Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'hqapi-2.x'
  • Loading branch information
Ryan Morgan committed Jan 12, 2010
2 parents 40b1fb0 + 2f100f3 commit b47744b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 16 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
Expand Up @@ -49,6 +49,10 @@ Changes in HQApi 3.0

Changes in HQApi 2.4

*) [HHQ-3664] Increase application update/create by not using Groovy's
Collection.minus() and pre-fetch the application inventory prior to the
session being marked read-write.

*) [HHQ-3624] For resource type alert definitions, update the "basic"
information in a separate call so that the instance alert
definitions are also updated
Expand Down
48 changes: 32 additions & 16 deletions hqu/hqapi1/app/ApplicationController.groovy
Expand Up @@ -90,6 +90,22 @@ class ApplicationController extends ApiController {
return true
}

private buildServiceList(resources) {
def svcList = [] // List of AppdefEntityID's to add to the application

if (resources) {
resources.each { res ->
def rid = res.'@id'?.toInteger()
def sid = resMan.findResourceById(rid)?.instanceId
def entId = AppdefEntityID.newServiceID(sid)
if (!svcList.contains(entId)) {
svcList.add(entId)
}
}
}
svcList
}

/**
* Create an Application via XML.
*
Expand Down Expand Up @@ -117,6 +133,10 @@ class ApplicationController extends ApiController {
applicationValue.opsContact = appOps
applicationValue.businessContact = appBiz

// Build resource list prior to update to avoid dirty checking of
// all Resource objects.
def resources = buildServiceList(xmlApplication['Resource'])

def newApp
try {
applicationValue.applicationType = appMan.findApplicationType(1)
Expand All @@ -135,7 +155,6 @@ class ApplicationController extends ApiController {
return null
}

def resources = xmlApplication['Resource']
updateAppServices(newApp, resources)
return newApp
}
Expand Down Expand Up @@ -209,6 +228,10 @@ class ApplicationController extends ApiController {
applicationValue.opsContact = appOps
applicationValue.businessContact = appBiz

// Build resource list prior to update to avoid dirty checking of
// all Resource objects.
def resources = buildServiceList(xmlApplication['Resource'])

try {
appMan.updateApplication(user, applicationValue)
} catch (AppdefDuplicateNameException e) {
Expand All @@ -222,7 +245,6 @@ class ApplicationController extends ApiController {
return null
}

def resources = xmlApplication['Resource']
updateAppServices(updateApp, resources)
return getApplication(appId)
}
Expand Down Expand Up @@ -324,19 +346,7 @@ class ApplicationController extends ApiController {
}
}

private updateAppServices(app, resources) {
def svcList = [] // List of AppdefEntityID's to add to the application

if (resources) {
resources.each { res ->
def rid = res.'@id'?.toInteger()
def sid = resMan.findResourceById(rid)?.instanceId
def entId = AppdefEntityID.newServiceID(sid)
if (!svcList.contains(entId)) {
svcList.add(entId)
}
}
}
private updateAppServices(app, svcList) {

// Setting the application services does not remove any app services
// that may have been removed from the application. It will also add
Expand All @@ -358,7 +368,13 @@ class ApplicationController extends ApiController {
}
}

def toAdd = svcList - svcListExisting
def toAdd = []
for (svc in svcList) {
if (!svcListExisting.contains(svc)) {
toAdd << svc
}
}

appMan.setApplicationServices(user, app.id, toAdd)

// Remove all deleted services
Expand Down

0 comments on commit b47744b

Please sign in to comment.