Skip to content

Commit 46c08f0

Browse files
authored
Merge pull request #683 from intersystems/cd-decomp
API for loading decomposed productions
2 parents 4f1f989 + 2ddb19a commit 46c08f0

File tree

9 files changed

+213
-2
lines changed

9 files changed

+213
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8-
## [2.9.1] - Unreleased
8+
## [2.10.0] - Unreleased
9+
10+
### Added
11+
- LoadProductionsFromDirectory method to help custom deployment scripts load decomposed productions from the repository (#670)
912

1013
### Fixed
1114
- Fixed not showing warnings on Studio (#660)

cls/SourceControl/Git/API.cls

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,12 @@ ClassMethod BaselineProductions()
8282
do ##class(SourceControl.Git.Util.Production).BaselineProductions()
8383
}
8484

85+
/// Given the path to a directory that contains production items, this method will import them all
86+
/// and delete any custom items from the production configuration that do not exist in the directory.
87+
/// This method may be called on a namespace that is not configured with Embedded Git for source control.
88+
ClassMethod LoadProductionsFromDirectory(pDirectoryName, Output pFailedItems) As %Status
89+
{
90+
return ##class(SourceControl.Git.Util.Production).LoadProductionsFromDirectory(pDirectoryName, .pFailedItems)
91+
}
92+
8593
}

cls/SourceControl/Git/Util/Production.cls

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,76 @@ ClassMethod ItemIsPTD(externalName) As %Boolean
7070
return 0
7171
}
7272

73+
/// Given the path to a directory that contains production items, this method will import them all
74+
/// and delete any custom items from the production configuration that do not exist in the directory.
75+
/// This method may be called on a namespace that is not configured with Embedded Git for source control.
76+
ClassMethod LoadProductionsFromDirectory(pDirectoryName, Output pFailedItems) As %Status
77+
{
78+
set st = $$$OK
79+
try {
80+
set rs = ##class(%File).FileSetFunc(pDirectoryName,,,1)
81+
throw:rs.%SQLCODE<0 ##class(%Exception.SQL).CreateFromSQLCODE(rs.%SQLCODE,rs.%Message)
82+
kill itemsOnDisk
83+
while rs.%Next() {
84+
continue:rs.Type'="D"
85+
set rs2 = ##class(%File).FileSetFunc(rs.Name,"*.xml",,0)
86+
throw:rs2.%SQLCODE<0 ##class(%Exception.SQL).CreateFromSQLCODE(rs2.%SQLCODE,rs2.%Message)
87+
while rs2.%Next() {
88+
set filePath = rs2.Name
89+
$$$ThrowOnError(##class(SourceControl.Git.Production).ParseExternalName(filePath,.internalName))
90+
set itemName = "", itemClassName = "", productionName = ""
91+
do ##class(SourceControl.Git.Production).ParseInternalName(internalName,,,.itemName,.itemClassName,.productionName)
92+
quit:productionName=""
93+
if (itemName'="") && (itemClassName'="") {
94+
set itemsOnDisk(productionName, itemName, itemClassName) = 1
95+
}
96+
// if production does not exist, create it
97+
if '$isobject(##class(Ens.Config.Production).%OpenId(productionName)) {
98+
$$$ThrowOnError(##class(SourceControl.Git.Production).CreateProduction(productionName))
99+
}
100+
set st = ##class(SourceControl.Git.Production).ImportPTD(filePath, productionName)
101+
if $$$ISERR(st) {
102+
set pFailedItems(filePath) = st
103+
}
104+
}
105+
}
106+
// handle deletes by iterating through XDATA of each production class. for every config item that is not in itemsOnDisk, delete it.
107+
set key = $order(itemsOnDisk(""))
108+
while (key '= "") {
109+
set classDef = ##class(%Dictionary.ClassDefinition).%OpenId(key)
110+
if $isobject(classDef) {
111+
set productionXData = $$$NULLOREF
112+
for i=1:1:classDef.XDatas.Count() {
113+
set xdata = classDef.XDatas.GetAt(i)
114+
if xdata.Name = "ProductionDefinition" {
115+
set productionXData = xdata
116+
quit
117+
}
118+
}
119+
if $isobject(productionXData) {
120+
$$$ThrowOnError(##class(%XML.XPATH.Document).CreateFromStream(productionXData.Data,.xdoc))
121+
$$$ThrowOnError(xdoc.EvaluateExpression("/Production","Item/@Name | Item/@ClassName",.results))
122+
for i=1:2:results.Count() {
123+
set itemName = results.GetAt(i).Value
124+
set itemClassName = results.GetAt(i+1).Value
125+
if (itemName'="") && (itemClassName'="") && '$get(itemsOnDisk(key,itemName, itemClassName)) {
126+
write !, "Removing item from production ", key, ": ", itemName, ":", itemClassName
127+
set internalName = ##class(SourceControl.Git.Production).CreateInternalName(key,itemName, itemClassName)
128+
set st = ##class(SourceControl.Git.Production).RemoveItem(internalName)
129+
if $$$ISERR(st) {
130+
set pFailedItems(itemName, itemClassName) = st
131+
}
132+
}
133+
}
134+
}
135+
}
136+
set key = $order(itemsOnDisk(key))
137+
}
138+
} catch err {
139+
set st = err.AsStatus()
140+
}
141+
if $data(pFailedItems) set st = $$$ADDSC($$$ERROR($$$GeneralError,"Some items failed to deploy."),st)
142+
return st
143+
}
144+
73145
}

module.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<Document name="git-source-control.ZPM">
44
<Module>
55
<Name>git-source-control</Name>
6-
<Version>2.9.1</Version>
6+
<Version>2.10.0</Version>
77
<Description>Server-side source control extension for use of Git on InterSystems platforms</Description>
88
<Keywords>git source control studio vscode</Keywords>
99
<Packaging>module</Packaging>

test/UnitTest/SourceControl/Git/Util/Production.cls

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,22 @@ Method TestItemIsPTD()
1515
do $$$AssertTrue(##class(SourceControl.Git.Util.Production).ItemIsPTD("ptd2\test.xml"))
1616
}
1717

18+
Method TestLoadProductionsFromDirectory()
19+
{
20+
// load a production from a class file under resources
21+
set packageRoot = ##class(SourceControl.Git.PackageManagerContext).ForInternalName("git-source-control.zpm").Package.Root
22+
$$$ThrowOnError($System.OBJ.Load(packageRoot_"test/_resources/cls/UnitTest/SampleProduction.cls","ck"))
23+
// call LoadProductionsFromDirectory on a directory under resources/ptd
24+
do $$$AssertStatusOK(##class(SourceControl.Git.Util.Production).LoadProductionsFromDirectory(packageRoot_"test/_resources/ptd"))
25+
// confirm items were deleted and added
26+
set itemA = ##class(Ens.Config.Production).OpenItemByConfigName("UnitTest.SampleProduction||a")
27+
do $$$AssertNotTrue($isobject(itemA),"item a was deleted")
28+
set itemB = ##class(Ens.Config.Production).OpenItemByConfigName("UnitTest.SampleProduction||b")
29+
do $$$AssertEquals(itemB.Settings.GetAt(1).Value,71)
30+
set itemB = ##class(Ens.Config.Production).OpenItemByConfigName("UnitTest.SampleProduction||c")
31+
do $$$AssertTrue($isobject(itemB),"item a was created")
32+
}
33+
1834
Method OnBeforeAllTests() As %Status
1935
{
2036
merge ..Mappings = @##class(SourceControl.Git.Utils).MappingsNode()
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
Class UnitTest.SampleProduction Extends Ens.Production
2+
{
3+
4+
XData ProductionDefinition
5+
{
6+
<Production Name="UnitTest.SampleProduction" LogGeneralTraceEvents="false">
7+
<Item Name="a" Category="" ClassName="Ens.Activity.Operation.Local" PoolSize="1" Enabled="true" Foreground="false" Comment="" LogTraceEvents="false" Schedule="">
8+
<Setting Target="Host" Name="RecordStatsInterval">60</Setting>
9+
</Item>
10+
<Item Name="b" Category="" ClassName="Ens.Activity.Operation.Local" PoolSize="1" Enabled="true" Foreground="false" Comment="" LogTraceEvents="false" Schedule="">
11+
<Setting Target="Host" Name="RecordStatsInterval">61</Setting>
12+
</Item>
13+
</Production>
14+
}
15+
16+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Export generator="IRIS" version="26">
3+
<Project name="ProductionSettings-UnitTest_SampleProduction" LastModified="1841-01-01 00:00:00.0000000">
4+
<Items>
5+
<ProjectItem name="EnsExportNotes.ProductionSettings-UnitTest_SampleProduction.PTD" type="PTD"></ProjectItem>
6+
<ProjectItem name="ProductionSettings:UnitTest.SampleProduction.PTD" type="PTD"></ProjectItem>
7+
</Items>
8+
</Project>
9+
10+
11+
<Document name="EnsExportNotes.ProductionSettings-UnitTest_SampleProduction.PTD"><ProjectTextDocument name="EnsExportNotes.ProductionSettings-UnitTest_SampleProduction" description="Export Notes for export ProductionSettings-UnitTest_SampleProduction">
12+
<![CDATA[<Deployment>
13+
<Creation>
14+
<SourceProduction>UnitTest.SampleProduction</SourceProduction>
15+
<UTC>1841-01-01 00:00:00.000</UTC>
16+
</Creation>
17+
<Notes>
18+
</Notes>
19+
<Contents>
20+
<ExportProject>ProductionSettings-UnitTest_SampleProduction</ExportProject>
21+
<Item num="1">ProductionSettings:UnitTest.SampleProduction.PTD</Item>
22+
</Contents>
23+
<ProductionClassInExport></ProductionClassInExport>
24+
</Deployment>
25+
26+
]]></ProjectTextDocument>
27+
</Document>
28+
29+
<Document name="ProductionSettings:UnitTest.SampleProduction.PTD"><ProjectTextDocument name="ProductionSettings:UnitTest.SampleProduction" description="Settings for production UnitTest.SampleProduction">
30+
<![CDATA[<Production Name='UnitTest.SampleProduction' LogGeneralTraceEvents='false'/>
31+
]]></ProjectTextDocument>
32+
</Document></Export>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Export generator="IRIS" version="26">
3+
<Project name="Settings-b" LastModified="1841-01-01 00:00:00.0000000">
4+
<Items>
5+
<ProjectItem name="EnsExportNotes.Settings-b.PTD" type="PTD"></ProjectItem>
6+
<ProjectItem name="Settings:b.PTD" type="PTD"></ProjectItem>
7+
</Items>
8+
</Project>
9+
10+
11+
<Document name="EnsExportNotes.Settings-b.PTD"><ProjectTextDocument name="EnsExportNotes.Settings-b" description="Export Notes for export Settings-b">
12+
<![CDATA[<Deployment>
13+
<Creation>
14+
<SourceProduction>UnitTest.SampleProduction</SourceProduction>
15+
<UTC>1841-01-01 00:00:00.000</UTC>
16+
</Creation>
17+
<Notes>
18+
</Notes>
19+
<Contents>
20+
<ExportProject>Settings-b</ExportProject>
21+
<Item num="1">Settings:b.PTD</Item>
22+
</Contents>
23+
<ProductionClassInExport></ProductionClassInExport>
24+
</Deployment>
25+
26+
]]></ProjectTextDocument>
27+
</Document>
28+
29+
<Document name="Settings:b.PTD"><ProjectTextDocument name="Settings:b" description="Settings for b in Production UnitTest.SampleProduction">
30+
<![CDATA[<Item Name="b" Category="" ClassName="Ens.Activity.Operation.Local" PoolSize="1" Enabled="true" Foreground="false" Comment="" LogTraceEvents="false" Schedule=""><Setting Target="Host" Name="RecordStatsInterval">71</Setting></Item>
31+
]]></ProjectTextDocument>
32+
</Document></Export>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Export generator="IRIS" version="26">
3+
<Project name="Settings-c" LastModified="1841-01-01 00:00:00.0000000">
4+
<Items>
5+
<ProjectItem name="EnsExportNotes.Settings-c.PTD" type="PTD"></ProjectItem>
6+
<ProjectItem name="Settings:c.PTD" type="PTD"></ProjectItem>
7+
</Items>
8+
</Project>
9+
10+
11+
<Document name="EnsExportNotes.Settings-c.PTD"><ProjectTextDocument name="EnsExportNotes.Settings-c" description="Export Notes for export Settings-c">
12+
<![CDATA[<Deployment>
13+
<Creation>
14+
<SourceProduction>UnitTest.SampleProduction</SourceProduction>
15+
<UTC>1841-01-01 00:00:00.000</UTC>
16+
</Creation>
17+
<Notes>
18+
</Notes>
19+
<Contents>
20+
<ExportProject>Settings-c</ExportProject>
21+
<Item num="1">Settings:c.PTD</Item>
22+
</Contents>
23+
<ProductionClassInExport></ProductionClassInExport>
24+
</Deployment>
25+
26+
]]></ProjectTextDocument>
27+
</Document>
28+
29+
<Document name="Settings:c.PTD"><ProjectTextDocument name="Settings:c" description="Settings for c in Production UnitTest.SampleProduction">
30+
<![CDATA[<Item Name="c" Category="" ClassName="Ens.Activity.Operation.Local" PoolSize="1" Enabled="false" Foreground="false" Comment="" LogTraceEvents="false" Schedule=""></Item>
31+
]]></ProjectTextDocument>
32+
</Document></Export>

0 commit comments

Comments
 (0)