Skip to content

Commit

Permalink
fixed dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
WianVos committed Aug 30, 2016
1 parent 9e06945 commit d94816f
Show file tree
Hide file tree
Showing 3 changed files with 141 additions and 23 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ The templates can be retrieved by using either the LoadDynamicProfile (variables


#### Variable profile
A variable profile is able to retrieve variables from remote sources .

This is an example of a variable profile:
```
{"variables"`:
{"test1"`: { "default_value" `: "555",
Expand All @@ -171,6 +174,16 @@ The templates can be retrieved by using either the LoadDynamicProfile (variables
{"phase" `: "deploy_to_dev", "task" `: "shitty1", "skip" `: "true"}]
,"tasks"`: {}}
```

Explanation:
* `variables`: indicates that this is the variables part of a template
* `test1` : this is the name of the variable as it will be availeble in xlr
* `default_value`: the default value for the variable is it is not resolvable in any other way
* `collector`: this describes the collection method for the variable
* `type`: what type of collector is this (available collectors: json)
* `url`: url to use to collect the json the extract the variable value from (mandetory for json collector)
* `path`: path to take in the json data: when multiple results are found the first one is used

### Template plan

#### Settings
Expand Down
150 changes: 127 additions & 23 deletions src/main/resources/XLRProfile/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,17 @@ def find_ci_id(self, name, type):
if str(p.getTitle()) == name:
return p

def find_template_id_by_name(self, name):
sp = SearchParameters()
sp.setType(Type.valueOf(str('xlrelease.Release')))

for p in XLReleaseServiceHolder.getRepositoryService().listEntities(sp):
if p.isTemplate() == True:
if str(p.getTitle()) == str(name):
Base.info("Found id: %s for name %s" % (str(p.getId()), name))
return str(p.getId())

return None


def create_phase(self, title, release):
Expand Down Expand Up @@ -594,35 +605,58 @@ def createSimpleTaskObject(self, taskTypeValue, title, propertyMap={}, parentTyp
:return:
"""



if parentTypeValue == None:
parentTypeValue = 'xlrelease.CustomScriptTask'
taskType = Type.valueOf(str(taskTypeValue))

# print propertyMap
parenttaskType = Type.valueOf(str(parentTypeValue))
Task = taskType.descriptor.newInstance("nonamerequired")
Task.setTitle(title)
for item in propertyMap:

parentTask = parenttaskType.descriptor.newInstance("nonamerequired")
parentTask.setTitle(title)
childTaskType = Type.valueOf(taskTypeValue)
childTask = childTaskType.descriptor.newInstance("nonamerequired")
for item in propertyMap:
if Task.hasProperty(item):
type = Task.getType()
desc = type.getDescriptor()
pd = desc.getPropertyDescriptor(item)

if childTask.hasProperty(item):
type = childTask.getType()
desc = type.getDescriptor()
pd = desc.getPropertyDescriptor(item)
if str(pd.getKind()) == "CI":
Task.setProperty(item, self.find_ci_id(str(item), pd.getReferencedType()))
else:
Task.setProperty(item, propertyMap[item])

if str(pd.getKind()) == "CI":
childTask.setProperty(item, self.find_ci_id(str(item), pd.getReferencedType()))
else:
childTask.setProperty(item, propertyMap[item])
Base.info("dropped property: %s on %s because: not applicable" % (item, taskTypeValue))

else:
Base.info("dropped property: %s on %s because: not applicable" % (item, taskTypeValue))
parentTask.setPythonScript(childTask)
return Task


else:
# print propertyMap
parenttaskType = Type.valueOf(str(parentTypeValue))

parentTask = parenttaskType.descriptor.newInstance("nonamerequired")
parentTask.setTitle(title)
childTaskType = Type.valueOf(taskTypeValue)
childTask = childTaskType.descriptor.newInstance("nonamerequired")
for item in propertyMap:

return parentTask
if childTask.hasProperty(item):
type = childTask.getType()
desc = type.getDescriptor()
pd = desc.getPropertyDescriptor(item)

def createSimpleTask(self, phaseId, taskTypeValue, title, propertyMap, release, parentTypeValue = None):
if str(pd.getKind()) == "CI":
childTask.setProperty(item, self.find_ci_id(str(item), pd.getReferencedType()))
else:
childTask.setProperty(item, propertyMap[item])

else:
Base.info("dropped property: %s on %s because: not applicable" % (item, taskTypeValue))
parentTask.setPythonScript(childTask)

return parentTask

def createCustomScriptTask(self, phaseId, taskTypeValue, title, propertyMap, release, parentTypeValue = None):
"""
adds a custom task to a phase in the release
:param phaseId: id of the phase
Expand Down Expand Up @@ -671,6 +705,70 @@ def createSimpleTask(self, phaseId, taskTypeValue, title, propertyMap, release,
self.__taskApi.addTask(str(phaseName), parentTask)


def createSimpleTask(self, phaseId, taskTypeValue, title, propertyMap, release, parentTaskType):
"""
adds a custom task to a phase in the release
:param phaseId: id of the phase
:param taskTypeValue: type of task to add
:param title: title of the task
:param propertyMap: properties to add to the task
:return:
"""
# print propertyMap

Base.warning("createSimpleTask")



phaseName = self.get_target_phase(phaseId, release)

TaskType = Type.valueOf(taskTypeValue)
Task = TaskType.descriptor.newInstance("nonamerequired")
Task.setTitle(title)

vm = {}
for item in propertyMap:
Base.info("settings %s on task of type: %s" % (item, TaskType))
if Task.hasProperty(item):
type = Task.getType()
desc = type.getDescriptor()
pd = desc.getPropertyDescriptor(item)

Base.warning(pd.getKind())
if item == "dependencies":
Base.info("dependencies found, these will be set later")
elif item == "templateId" and "Application" not in propertyMap[item]:
Task.setProperty(item, self.find_template_id_by_name(str(propertyMap[item])))
elif str(pd.getKind()) == "CI":
Task.setProperty(item, self.find_ci_id(str(item), pd.getReferencedType()))
elif str(pd.getKind()) == "bool":
if propertyMap[item] == "false":
Task.setProperty(item, False)
else:
Task.setProperty(item, True)
else:
Task.setProperty(item, propertyMap[item])


else:
Base.info("dropped property: %s on %s because: not applicable" % (item, taskTypeValue))



print dir(Task.getType().getDescriptor().getPropertyDescriptor('templateVariables'))

taskId = self.__taskApi.addTask(str(phaseName), Task)

if propertyMap.has_key("dependencies"):

for dep in propertyMap["dependencies"]:
if dep.has_key("targetId"):
self.__taskApi.addDependency(str(taskId), dep["targetId"])
if dep.has_key("target"):
self.__taskApi.addDependency(str(taskId), dep['target'])




def phase_exists(self, targetPhase):
phaseList = self.__phaseApi.searchPhasesByTitle(targetPhase, release.id)
Expand Down Expand Up @@ -876,11 +974,17 @@ def handle_task(self, phaseId, taskDict, taskSettings, release, containerId=None

try:
if containerId != None:
if localTaskDict['meta']['task_type'] == "xlrelease.gateTask":
Base.Fatal("It is not allowed to create a gate task inside a container, failing")
self.createSimpleTaskInContainer(containerId, taskTitle, localTaskDict['meta']['task_type'], localTaskDict, parentTypeValue)
else:
self.createSimpleTask(phaseId, localTaskDict['meta']['task_type'], taskTitle, localTaskDict, release, parentTypeValue)
if parentTypeValue == None:
self.createSimpleTask(phaseId, localTaskDict['meta']['task_type'], taskTitle, localTaskDict, release, parentTypeValue)
else:
self.createCustomScriptTask(phaseId, localTaskDict['meta']['task_type'], taskTitle, localTaskDict, release, parentTypeValue)

except Exception:
except Exception as e:
Base.warning(e.message)
print "Unable to create task"


Expand Down Expand Up @@ -1033,7 +1137,7 @@ def replace_xlr_variable_in_string(self, input_string, release_id):
xlr_variables = self.get_release_variables(release_id)
pprint.pprint(xlr_variables)
for x, y in xlr_variables.items():
if x in input_string:
if x in input_string and y != "":
Base.info("replacing variable %s with value %s" % (x, y))
input_string = input_string.replace(x, y)

Expand Down
1 change: 1 addition & 0 deletions src/main/resources/rel/LoadTemplateProfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def validUrl(url):
atLeastOne = True
p = XLRProfile.XLRProfile(url=profileList)
p.handle_template(__release.id)
Base.info("done handeling the urls")


elif profile:
Expand Down

0 comments on commit d94816f

Please sign in to comment.