Skip to content

Commit 3b109af

Browse files
author
nalexand
committed
cls/kutac/monitor/utils/Installer.cls.xml
1 parent fecda64 commit 3b109af

File tree

1 file changed

+275
-8
lines changed

1 file changed

+275
-8
lines changed

cls/kutac/monitor/utils/Installer.cls.xml

Lines changed: 275 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<Export generator="Cache" version="25" zv="Cache for Windows (x86-64) 2015.1.1 (Build 505U)" ts="2015-07-11 22:05:09">
3-
<Class name="kutac.monitor.utils.Installer">
4-
<Abstract>1</Abstract>
5-
<TimeChanged>63744,79488.649152</TimeChanged>
2+
<Export generator="Cache" version="25" zv="Cache for Windows (x86-32) 2015.1 (Build 429U)" ts="2015-07-23 18:15:29">
3+
<Class name="cls.kutac.monitor.utils.Installer">
4+
<TimeChanged>63756,59616.718811</TimeChanged>
65
<TimeCreated>63732,50627.865496</TimeCreated>
76

87
<XData name="Install">
@@ -15,23 +14,56 @@
1514
</IfNotDef>
1615
<If Condition='(##class(Config.Namespaces).Exists("${Namespace}")=0)'>
1716
<Log Text="Creating namespace ${Namespace}" Level="0"/>
18-
<Namespace Name="${Namespace}" Create="yes" Code="${Namespace}" Ensemble="" Data="${Namespace}">
17+
<Namespace Name="${Namespace}" Create="yes" Code="CACHESYS" Ensemble="" Data="CACHESYS">
1918
<Configuration>
2019
<Database Name="${Namespace}" Dir="${MGRDIR}/${Namespace}" Create="yes" MountRequired="true" Resource="%DB_${Namespace}" PublicPermissions="RW" MountAtStartup="true"/>
2120
</Configuration>
21+
<Log Text="Creating web application /csp/${Namespace}" Level="0"/>
22+
<CSPApplication Url="/csp/${Namespace}" Directory="#{##class(%DeepSee.Report.UI.reportModelServer).GetCSPDirectory()}/${Namespace}" AuthenticationMethods="64" IsNamespaceDefault="true" />
23+
<RunInstall Class="kutac.monitor.utils.Installer" Method="EnableDeepSee"/>
2224
</Namespace>
23-
<Log Text="End Creating namespace ${Namespace}" Level="0"/>
25+
<Log Text="End Creating namespace ${Namespace} and web application /csp/${Namespace}" Level="0"/>
2426
</If>
2527
2628
<Namespace Name="${Namespace}" Create="no">
29+
<IfDef Var="SourceDir">
30+
<Log Text="SourceDir defined - offline install from ${SourceDir}" Level="0"/>
31+
<Import File="${SourceDir}"/>
32+
</IfDef>
33+
34+
<IfNotDef Var="SourceDir">
35+
<Log Text="SourceDir undefined - online install from GitHub" Level="0"/>
36+
<RunInstall Class="kutac.monitor.utils.Installer" Method="DownloadFromGitHub"/>
37+
</IfNotDef>
38+
39+
2740
2841
</Namespace>
2942
30-
<Log Text="Mapping kutac package to %All namespace" Level="0"/>
31-
<Namespace Name="%SYS" Create="no">
43+
44+
45+
<Log Text="Mapping kutac package to choosed namespace" Level="0"/>
46+
<Namespace Name="${Namespace}" Create="no">
3247
<ClassMapping From="${Namespace}" Package="kutac"/>
3348
</Namespace>
3449
50+
51+
52+
<Log Text="Moving to configuring monitor" Level="0"/>
53+
<RunInstall Class="kutac.monitor.utils.Installer" Method="ConfiguringMonitor"/>
54+
55+
56+
<!--<Log Text="Configuring startup namespace" Level="0"/>
57+
<RunInstall Class="kutac.monitor.utils.Installer" Method="ConfiguringClasses"/>
58+
59+
<Log Text="Activating Monitor Classes" Level="0"/>
60+
<RunInstall Class="kutac.monitor.utils.Installer" Method="ActivatingingClasses"/>
61+
62+
<Log Text="Starting Monitor" Level="0"/>
63+
<RunInstall Class="kutac.monitor.utils.Installer" Method="RunningMonitor"/>-->
64+
65+
66+
3567
</Manifest>
3668
]]></Data>
3769
</XData>
@@ -50,5 +82,240 @@ do ##class(kutac.monitor.utils.Installer).setup(.pVars)</Description>
5082
<Implementation><![CDATA[ Quit ##class(%Installer.Manifest).%Generate(%compiledclass, %code, "Install")
5183
]]></Implementation>
5284
</Method>
85+
86+
<Method name="EnableDeepSee">
87+
<ClassMethod>1</ClassMethod>
88+
<FormalSpec>pVars,pLogLevel,tInstaller</FormalSpec>
89+
<ReturnType>%Status</ReturnType>
90+
<Implementation><![CDATA[
91+
do EnableDeepSee^%SYS.cspServer("/csp/"_pVars("Namespace")_"/")
92+
quit $$$OK
93+
]]></Implementation>
94+
</Method>
95+
96+
<Method name="DownloadFromGitHub">
97+
<ClassMethod>1</ClassMethod>
98+
<FormalSpec>pVars,pLogLevel,tInstaller</FormalSpec>
99+
<ReturnType>%Status</ReturnType>
100+
<Implementation><![CDATA[
101+
Set Namespace=tInstaller.Evaluate("${Namespace}")
102+
Do tInstaller.PushNS("%SYS")
103+
Set tSC = ..Update(Namespace, "intersystems-ru", "deepsee-sysmon-dashboards", "master")
104+
Do tInstaller.PopNS()
105+
If $$$ISERR(tSC) Throw ##class(%Installer.Exception).CreateFromStatus(tSC)
106+
quit $$$OK
107+
]]></Implementation>
108+
</Method>
109+
110+
<Method name="Update">
111+
<ClassMethod>1</ClassMethod>
112+
<FormalSpec>Namespace=$Namespace,Owner:%String="intersystems-ru",Repository:%String="deepsee-sysmon-dashboards",Branch:%String,Username:%String,Password:%String</FormalSpec>
113+
<ReturnType>%Status</ReturnType>
114+
<Implementation><![CDATA[
115+
Set namespace = $Namespace
116+
Set SSLConfig = "GitHub"
117+
118+
Zn "%SYS"
119+
Do:'##class(Security.SSLConfigs).Exists(SSLConfig) ##class(Security.SSLConfigs).Create(SSLConfig)
120+
121+
Set req=##class(%Net.HttpRequest).%New()
122+
Set req.Https=1
123+
Set req.SSLConfiguration=SSLConfig
124+
Set req.Server="api.github.com"
125+
Set req.Location = "repos/" _ Owner _ "/" _ Repository _ "/contents" // as described in https://developer.github.com/v3/repos/
126+
Do:$d(Branch) req.SetParam("ref",Branch) // if omitted the repository’s default branch (usually master) would be used
127+
Do req.SetHeader("Accept","application/vnd.github.v3+json") // we want to receive API v3
128+
129+
If ($d(Username) && $d(Password)) { // supply Username and Passwor, if both are provided. GitHub accept Basic Auth
130+
Set req.Username = Username // https://developer.github.com/v3/auth/
131+
Set req.Password = Password
132+
}
133+
134+
Set links = ##class(%ListOfDataTypes).%New()
135+
Set st = ..ProcessDirectory("",req,.links)
136+
Return:$$$ISERR(st) st
137+
138+
Zn Namespace
139+
Set st = ..DownloadFiles(links,req,.list)
140+
Set st2 = $system.OBJ.CompileList(.list)
141+
Zn namespace
142+
143+
Return $$$ADDSC(st, st2)
144+
]]></Implementation>
145+
</Method>
146+
147+
<Method name="ProcessDirectory">
148+
<ClassMethod>1</ClassMethod>
149+
<FormalSpec><![CDATA[Path:%String="",Request:%Net.HttpRequest,&Links:%ListOfDataTypes]]></FormalSpec>
150+
<ReturnType>%Status</ReturnType>
151+
<Implementation><![CDATA[
152+
Set location = Request.Location
153+
Set Request.Location = Request.Location _ Path
154+
155+
Set st = Request.Get()
156+
Return:$$$ISERR(st) st
157+
Return:(Request.HttpResponse.StatusCode = 404) $$$ERROR($$$GeneralError,"Repository doesn't exist OR you don't have access")
158+
Return:((Request.HttpResponse.StatusCode = 403) && (Request.HttpResponse.GetHeader("X-RATELIMIT-REMAINING")=0)) $$$ERROR($$$GeneralError,"API rate limit exceeded. Try logging in.")
159+
Return:(Request.HttpResponse.StatusCode '= 200) $$$ERROR($$$GeneralError,"Received " _ Request.HttpResponse.StatusCode _ " status, expected 200")
160+
161+
#dim objects As List of %ZEN.proxyObject
162+
#dim obj As %ZEN.proxyObject
163+
Set st = ##class(%ZEN.Auxiliary.jsonProvider).%ConvertJSONToObject(Request.HttpResponse.Data,,.objects,1)
164+
Return:$$$ISERR(st) st
165+
166+
For i = 1:1:objects.Count() {
167+
Set obj = objects.GetAt(i)
168+
If (obj.type = "dir") {
169+
Set st = ..ProcessDirectory("/"_obj.name,Request,.Links)
170+
Return:$$$ISERR(st) st
171+
} ElseIf (obj.type = "file") {
172+
Do:..IsCacheFile(obj) Links.Insert(obj."download_url")
173+
} Else {
174+
// obj.type = "symlink" or obj.type = "submodule"
175+
}
176+
}
177+
Set Request.Location = location // to keep track of where in the repository tree we are
178+
Return $$$OK
179+
]]></Implementation>
180+
</Method>
181+
182+
<Method name="IsCacheFile">
183+
<ClassMethod>1</ClassMethod>
184+
<FormalSpec>File:%ZEN.proxyObject</FormalSpec>
185+
<ReturnType>%Boolean</ReturnType>
186+
<Implementation><![CDATA[
187+
Set extensions = ",xml,cls,csp,csr,mac,int,bas,inc,gbl,prj,obj,pkg,gof,"
188+
Return:($L(File.name,".")=1) 0 //no extension
189+
Set File.Extension = $P(File.name,".",$L(File.name,"."))
190+
Return $F(extensions,","_$ZCVT(File.Extension,"l")_",")
191+
]]></Implementation>
192+
</Method>
193+
194+
<Method name="DownloadFiles">
195+
<ClassMethod>1</ClassMethod>
196+
<FormalSpec>Links:%ListOfDataTypes,Request:%Net.HttpRequest,*Items</FormalSpec>
197+
<ReturnType>%Status</ReturnType>
198+
<Implementation><![CDATA[
199+
Kill Items
200+
Set Request.Server = "raw.githubusercontent.com"
201+
Set st = $$$OK
202+
203+
For i = 1:1:Links.Count() {
204+
Set streq = Request.Get($e(Links.GetAt(i),35,*)) // Remove "https://raw.githubusercontent.com/" from URL.
205+
Set:$$$ISERR(streq) st=$$$ADDSC(st, streq)
206+
Set stload = $system.OBJ.LoadStream(Request.HttpResponse.Data,"",.error,.items)
207+
Set:$$$ISERR(stload) st=$$$ADDSC(st, stload)
208+
Merge Items = items
209+
}
210+
211+
Set Request.Server="api.github.com"
212+
Return st
213+
]]></Implementation>
214+
</Method>
215+
216+
<Method name="ConfiguringMonitor">
217+
<ClassMethod>1</ClassMethod>
218+
<FormalSpec>pVars,pLogLevel,tInstaller</FormalSpec>
219+
<ReturnType>%Status</ReturnType>
220+
<Implementation><![CDATA[
221+
Set Namespace=tInstaller.Evaluate("${Namespace}")
222+
Do tInstaller.PushNS("%SYS")
223+
write !, "Configuring startup namespace"
224+
set st1 = ..ConfiguringClasses(Namespace)
225+
write !, "Activating Monitor Classes"
226+
set st2 = ..ActivatingClasses()
227+
write !, "Starting Monitor"
228+
set st3 = ..RunningMonitor()
229+
write !, "Creating Task"
230+
set st4 = ..CreateTask()
231+
set st = $$$ADDSC(st4, $$$ADDSC(st1, $$$ADDSC(st2, st3)))
232+
if $$$ISERR(st) Throw ##class(%Installer.Exception).CreateFromStatus(st)
233+
Do tInstaller.PopNS()
234+
quit $$$OK
235+
]]></Implementation>
236+
</Method>
237+
238+
<Method name="ConfiguringClasses">
239+
<ClassMethod>1</ClassMethod>
240+
<FormalSpec>Namespace=$Namespace</FormalSpec>
241+
<ReturnType>%Status</ReturnType>
242+
<Implementation><![CDATA[
243+
Set rsm = ##class(%SYS.Monitor).SetStartNS(Namespace)
244+
if rsm'=1
245+
{
246+
write !, "Error setting Monitor namespaces: "_$ze,!
247+
//quit $$$ISERR
248+
}
249+
250+
Set rsys = ##class(%SYS.Monitor).SetStartNS("%SYS")
251+
if rsys'=1
252+
{
253+
write !, "Error setting Monitor namespaces: "_$ze,!
254+
//quit $$$ISERR
255+
}
256+
//quit $$$OK
257+
return $$$ADDSC(rsm, rsys)
258+
]]></Implementation>
259+
</Method>
260+
261+
<Method name="ActivatingClasses">
262+
<ClassMethod>1</ClassMethod>
263+
<ReturnType>%Status</ReturnType>
264+
<Implementation><![CDATA[
265+
set act = $LISTBUILD("%Monitor.System.HistoryPerf","%Monitor.System.Diskspace","%Monitor.System.License","%Monitor.System.Processes","%Monitor.System.HistorySys","%Monitor.System.Freespace","%Monitor.System.LockTable","%Monitor.System.Routines")
266+
set str = $LISTTOSTRING(act)
267+
for i = 1:1:$LISTLENGTH(act)
268+
{
269+
set cls = $PIECE(str, ",", i)
270+
set id = ""
271+
do ##class(%Monitor.ItemGroup).MetricsClassItemGroup(cls,.id)
272+
s class = ##class(%Monitor.ItemGroup).%OpenId(id)
273+
if '$IsObject(class)
274+
{
275+
write !,"ERROR: Class '"_cls_"' does not exist",!
276+
}
277+
else
278+
{
279+
set class.Activated = 1
280+
set status = class.%Save()
281+
if ('status)
282+
{
283+
w $System.Status.GetErrorText(st)
284+
}
285+
}
286+
}
287+
return $$$OK
288+
]]></Implementation>
289+
</Method>
290+
291+
<Method name="RunningMonitor">
292+
<ClassMethod>1</ClassMethod>
293+
<ReturnType>%Status</ReturnType>
294+
<Implementation><![CDATA[
295+
set sc = ##class(%SYS.Monitor).Start()
296+
if sc = 1
297+
{
298+
write !, " System Monitor started"
299+
}
300+
elseif sc = -1
301+
{
302+
write !, " System Monitor already running!"
303+
}
304+
else
305+
{
306+
write !,"ERROR: "_$ZE
307+
return sc
308+
}
309+
return $$$OK
310+
]]></Implementation>
311+
</Method>
312+
313+
<Method name="CreateTask">
314+
<ClassMethod>1</ClassMethod>
315+
<FormalSpec>min:%Integer=180</FormalSpec>
316+
<ReturnType>%Status</ReturnType>
317+
<Implementation><![CDATA[ q ##class(%DeepSee.CubeManager.Task.Synch).Schedule(0, 1, 1, min, $p($H,",",2) + 60, 0)
318+
]]></Implementation>
319+
</Method>
53320
</Class>
54321
</Export>

0 commit comments

Comments
 (0)