Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V0.10.x feat init cpf merge #703

Draft
wants to merge 13 commits into
base: v0.10.x
Choose a base branch
from
Draft
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- #582 Added functionality to optionally see time of last update and server version of each package
- #609 Added support for `-export-deps` when running the "Package" phase of lifecycle
- #541 Added support for ORAS repository
- #702 Added a new lifecycle phase `Initialize` which supports merging the new `<CPF/>` resource.

### Changed
-
Expand Down
40 changes: 30 additions & 10 deletions src/cls/IPM/Lifecycle/Base.cls
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Property PhaseList As %List;

/// $ListBuild list of phases in this lifecycle. <br />
/// For each phase name, an instance method named "%<phase name>" must be defined in the class with a return type of %Status.
Parameter PHASES = {$ListBuild("Clean","Reload","*","Validate","ExportData","Compile","Activate","Document","MakeDeployed","Test","Package","Verify", "Publish", "Configure","Unconfigure")};
Parameter PHASES = {$ListBuild("Clean","Initialize", "Reload","*","Validate","ExportData","Compile","Activate","Document","MakeDeployed","Test","Package","Verify", "Publish", "Configure","Unconfigure")};

Property Payload As %Stream.Object [ Private ];

Expand Down Expand Up @@ -138,18 +138,19 @@ ClassMethod GetCompletePhasesForOne(pOnePhase As %String) As %List

Quit $Case(pOnePhase,
"clean": $ListBuild("Clean"),
"reload": $ListBuild("Reload","*"),
"validate": $ListBuild("Reload","*","Validate"),
"initialize": $ListBuild("Initialize"),
"reload": $ListBuild("Initialize","Reload","*"),
"validate": $ListBuild("Initialize","Reload","*","Validate"),
"exportdata": $ListBuild("ExportData"),
"compile": $ListBuild("Reload","*","Validate","Compile"),
"activate": $ListBuild("Reload","*","Validate","Compile","Activate"),
"compile": $ListBuild("Initialize","Reload","*","Validate","Compile"),
"activate": $ListBuild("Initialize","Reload","*","Validate","Compile","Activate"),
"document": $ListBuild("Document"),
"makedeployed": $ListBuild("MakeDeployed"),
"test": $ListBuild("Reload","*","Validate","Compile","Activate","Test"),
"package": $ListBuild("Reload","*","Validate","Compile","Activate","Package"),
"verify": $ListBuild("Reload","*","Validate","Compile","Activate","Package","Verify"),
"register": $ListBuild("Reload","*","Validate","Compile","Activate","Package","Register"),
"publish": $ListBuild("Reload","*","Validate","Compile","Activate","Package","Register","Publish"),
"test": $ListBuild("Initialize","Reload","*","Validate","Compile","Activate","Test"),
"package": $ListBuild("Initialize","Reload","*","Validate","Compile","Activate","Package"),
"verify": $ListBuild("Initialize","Reload","*","Validate","Compile","Activate","Package","Verify"),
"register": $ListBuild("Initialize","Reload","*","Validate","Compile","Activate","Package","Register"),
"publish": $ListBuild("Initialize","Reload","*","Validate","Compile","Activate","Package","Register","Publish"),
"configure": $ListBuild("Configure"),
"unconfigure": $ListBuild("Unconfigure"),
: ""
Expand All @@ -162,6 +163,7 @@ ClassMethod MatchSinglePhase(pOnePhase As %String) As %String
Set phase = $ZCONVERT(pOnePhase, "L")
Quit $Case(phase,
"clean": "Clean",
"initialize": "Initialize",
"reload": "Reload",
"validate": "Validate",
"exportdata": "ExportData",
Expand Down Expand Up @@ -501,6 +503,24 @@ Method %Unconfigure(ByRef pParams) As %Status
Quit tSC
}

Method %Initialize(ByRef pParams) As %Status
{
Set tSC = $$$OK
Try {
Set tKey = ""
For {
Set tResource = ..Module.Resources.GetNext(.tKey)
Quit:tKey=""
isc-shuliu marked this conversation as resolved.
Show resolved Hide resolved
If $IsObject(tResource.Processor) && ($CLASSNAME(tResource.Processor) = "%IPM.ResourceProcessor.CPF") {
isc-shuliu marked this conversation as resolved.
Show resolved Hide resolved
isc-shuliu marked this conversation as resolved.
Show resolved Hide resolved
Set tSC = $$$ADDSC(tSC,tResource.Processor.OnPhase("Initialize",.pParams))
}
}
} Catch ex {
Set tSC = ex.AsStatus()
}
Quit tSC
isc-shuliu marked this conversation as resolved.
Show resolved Hide resolved
}

Method %Reload(ByRef pParams) As %Status
{
Set tSC = $$$OK
Expand Down
51 changes: 51 additions & 0 deletions src/cls/IPM/ResourceProcessor/CPF.cls
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
Class %IPM.ResourceProcessor.CPF Extends %IPM.ResourceProcessor.Abstract
{

/// Comma-separated list of resource attribute names that this processor uses
Parameter ATTRIBUTES As STRING = "Path";

/// Description of resource processor class (shown in UI)
Parameter DESCRIPTION As STRING = "Merges the specified CPF file in the ""Initialize"" lifecycle phase.";

Property Path As %String(MAXLEN = "");
isc-shuliu marked this conversation as resolved.
Show resolved Hide resolved

/// Called as phase <var>pPhase</var> is executed for the resource. If <var>pResourceHandled</var> is set to true,
/// then the default behavior for that resource will be bypassed in the current phase.
/// Currently, this is only used in the Verify phase, because of different handling of intermediate error statuses.
/// TODO: Implement for standard database resources (.INC, .CLS, etc.)
Method OnPhase(pPhase As %String, ByRef pParams, Output pResourceHandled As %Boolean = 0) As %Status
{
Set verbose = $Get(pParams("Verbose"))
Set status = $$$OK
Try {
If pPhase '= "Initialize" {
Quit
}

If '$Data(pParams("RootDirectory"), root) {
isc-shuliu marked this conversation as resolved.
Show resolved Hide resolved
$$$ThrowStatus($$$ERROR($$$GeneralError, "RootDirectory unspecified"))
}
// Use Construct first, rather than NormalizeFilename, so we don't have to deal with leading/trailing slashes
Set filename = ##class(%File).Construct(root, ..Path)
isc-shuliu marked this conversation as resolved.
Show resolved Hide resolved
Set filename = ##class(%File).NormalizeFilename(filename)

Set stream = ##class(%Stream.FileCharacter).%New()
$$$ThrowOnError(stream.LinkToFile(filename))
If verbose {
Write !, "Merging CPF file: ", filename, !
While 'stream.AtEnd {
isc-shuliu marked this conversation as resolved.
Show resolved Hide resolved
Write stream.Read()
}
}
// TODO actually merge the CPF file
isc-shuliu marked this conversation as resolved.
Show resolved Hide resolved
// ...

Set pResourceHandled = 1
} Catch ex {
Set pResourceHandled = 0
Copy link
Collaborator

Choose a reason for hiding this comment

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

For error handling, should see if the error is helpful if the user doesn't have the appropriate permissions and/or doesn't have %System_Callout privileges. Not sure how easy it is to have tests as different users with different privileges but worth adding if possible

Set status = ex.AsStatus()
}
Return status
}

}
16 changes: 16 additions & 0 deletions tests/integration_tests/Test/PM/Integration/CPFMerge.cls
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Class Test.PM.Integration.CPFMerge Extends Test.PM.Integration.Base
{

Parameter TargetModuleName As STRING = "cpf-merge";

Method TestCPFMerge()
isc-shuliu marked this conversation as resolved.
Show resolved Hide resolved
{
Set tModuleDir = ..GetModuleDir(..#TargetModuleName)

Set tSC = ##class(%IPM.Main).Shell("load -v "_tModuleDir)
Do $$$AssertStatusOK(tSC, "Loaded module successfully")

// TODO - Add more tests here
isc-shuliu marked this conversation as resolved.
Show resolved Hide resolved
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[config]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would recommend testing things like package mappings, roles, resources, web apps etc.

globals=0,0,150000,0,0,0
gmheap=393,216
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<Export generator="Cache" version="25">
<Document name="cpf-merge.ZPM">
<Module>
<Name>cpf-merge</Name>
<Version>0.0.1</Version>
<Packaging>module</Packaging>
<CPF Path="/Merge.CPF"/>
</Module>
</Document>
</Export>
Loading