1
0
mirror of https://github.com/akpaevj/executor-scripts.git synced 2024-11-24 08:52:35 +02:00
This commit is contained in:
akpaevj 2024-03-04 18:44:41 +03:00
parent d8288f9543
commit 9930134f44
12 changed files with 175 additions and 28 deletions

View File

@ -1,13 +1,16 @@
#required Common/Path.sbsl
#required Common/Zip.sbsl
#required Common/Log.sbsl
method BuildXmlFiles(CliPath: String, ProjectPath: String, DestinationFolder: String = "", ArchiveName: String = ""): Number
if not Path.Exists(CliPath)
throw new IllegalArgumentException("Couldn't find edt cli executable by passed path")
Log.e("Couldn't find edt cli executable: %CliPath")
return 1
;
if not Path.Exists(ProjectPath)
throw new IllegalArgumentException("Couldn't find project folder by passed path")
Log.e("Couldn't find project folder: %ProjectPath")
return 1
;
if DestinationFolder == ""
@ -15,7 +18,8 @@ method BuildXmlFiles(CliPath: String, ProjectPath: String, DestinationFolder: St
;
if not Path.Exists(DestinationFolder)
throw new IllegalArgumentException("Couldn't find destination folder by passed path")
Log.e("Couldn't find destination folder: %DestinationFolder")
return 1
;
if ArchiveName == ""

View File

@ -23,7 +23,8 @@ method GetConfigurationInfo(
Infobase: String,
User: String,
Password: String,
PlatformVersion = ""): ConfigInfo?
PlatformVersion = "",
Extension = ""): ConfigInfo?
val SshAgentBaseDir = Files.CreateTempDirectory("", True)
val SshAgent = StartSshAgent(PlatformVersion, Server, Infobase, SshAgentBaseDir.Path)
@ -40,7 +41,13 @@ method GetConfigurationInfo(
Console.PromptString = "designer> "
SshAgentConnection.ConnectIB(Console)
SshAgentConnection.UploadConfiguration(Console, ConfigFile.Name)
if Extension == ""
SshAgentConnection.UploadConfiguration(Console, ConfigFile.Name)
else
SshAgentConnection.UploadExtension(Console, ConfigFile.Name, Extension)
;
SshAgentConnection.DisconnectIB(Console)
SshAgentConnection.Shutdown(Console)
SshAgentConnection.Close(Console)
val ConfigurationFile = SshAgentConnection.DownloadFile(User, Password, "Configuration.xml")

View File

@ -58,6 +58,24 @@ structure BracketsNode
;
;
@Global
method ParseList(Content: String, StartIndex: Number = 0): Array<BracketsNode>
val Result = new Array<BracketsNode>()
var Index = StartIndex
while Index < Content.Length()
if Content[Index] == "{"
val Node = ReadBlock(Content, Index)
Result.Add(Node)
Index += Node.Length
else
Index += 1
;
;
return Result
;
@Global
method Parse(Content: String, StartIndex: Number = 0): BracketsNode
return ReadBlock(Content, StartIndex)

View File

@ -17,6 +17,7 @@ method LocalPortIsOpen(Port: Number, TimeoutSeconds: Number): Boolean
val Output = Processes.GetProcessOutput(Process)
if Output.Length() > 0
Console.Write(Output)
Process.Stop()
return True
;

View File

@ -1,3 +1,8 @@
@Global
method IsFile(Path: String): Boolean
return new File(Path).IsFile()
;
@Global
method GetFileName(Path: String): String
return new File(Path).Name

View File

@ -64,9 +64,9 @@ method BlockConnections(
;
method CloseConnection(Connection: V8Connection)
try
try
Connection.Disconnect()
finally
catch Exception: unknown
;
;

View File

@ -14,7 +14,12 @@ method ConnectIB(Console: SshConsole)
@Global
method UploadConfiguration(Console: SshConsole, ConfigFilePath: String)
Console.Execute("config dump-config-to-files --dir=\".\" --list-file=\"${ConfigFilePath}\"", 2m)?.Close()
Console.Execute("config dump-config-to-files --dir=\".\" --list-file=\"%ConfigFilePath\"", 2m)?.Close()
;
@Global
method UploadExtension(Console: SshConsole, ConfigFilePath: String, Extension: String)
Console.Execute("config dump-config-to-files --dir=\".\" --extension=\"%Extension\" --list-file=\"%ConfigFilePath\"", 2m)?.Close()
;
@Global

View File

@ -18,20 +18,31 @@ structure V8Platform
var IbcmdPath: String = ""
;
@Global
method ConfigurationVersionFromExtensionVersion(Version: String = "0.0.0.0"): String
val VS = Version.Split(".")
if VS.Size() == 4
return Version
else if VS.Size() == 5
VS.RemoveAt(VS.Bound())
return VS.Join(".")
else
throw new IllegalFormatException("Unexpected format of the version: %Version")
;
;
@Global
method VersionIsUpper(Version1: String = "0.0.0.0", Version2: String = "0.0.0.0"): Boolean
val VersionFirst = Version1.Split(".")
if VersionFirst.Size() != 4
throw new IllegalFormatException("Invalid argument format (Version1): ${Version1}")
;
val VersionSecond = Version2.Split(".")
if VersionSecond.Size() != 4
throw new IllegalFormatException("Invalid argument format (Version2): ${Version2}")
if VersionFirst.Size() != VersionSecond.Size()
throw new IllegalFormatException("Versions have no the same format: ${Version2}")
;
var Result = 0
for Index = 0 to 3
for Index = 0 to VersionSecond.Size() - 1
Result = new Number(VersionFirst[Index]) - new Number(VersionSecond[Index])
if Result != 0
return Result < 0

View File

@ -1,3 +1,4 @@
#required V8.sbsl
#required Sql.sbsl
#required BracketsParser.sbsl
#required BytesHelper.sbsl
@ -31,7 +32,7 @@ structure ExtensionInfo
val ProtectFromDangerActions: Boolean
val GenerationVersion: Bytes
val SafeMode: Boolean
val Version: Bytes?
val Version: String
val Active: Boolean
val UseMainRolesForAllUsers: Boolean
;
@ -56,12 +57,26 @@ structure Class
)
;
@Global
method HasExtension(ExtensionName: String): Boolean
val Query = Connection.CreateQueryWithSelect("SELECT Count(*) as Count FROM [dbo].[_ExtensionsInfo] WITH(NOLOCK) WHERE [_ExtName] = N'%ExtensionName'")
use QResult = Query.Execute()
QResult.Next()
return (QResult.Get("Count") as Number) > 0
;
@Global
method GetExtensionInfo(ExtensionName: String): ExtensionInfo
val RawData = GetExtensionZippedInfo(ExtensionName)
val Reader = AnotherFuckingOneCFormatReader.NewInstance(RawData, 2)
val FileName = Reader.ReadString()
val Root = GetConfigCASFileDataAsBracketsNode(FileName)
val ConfigCompatibilityMode = V8BracketsHelper.GetCompatibilityMode(Root[0].GetChildNode([1,2,0]))
val ProtectFromDangerActions = Reader.ReadByte() == Bytes {A2}
val GenerationVersion = Reader.ReadVarbinary()
val SafeMode = Reader.ReadBoolean()
@ -71,18 +86,20 @@ structure Class
val BracketsNode = Reader.ReadBracketsNode()
val Synonym = V8BracketsHelper.GetSysonym(BracketsNode.GetChildNode([2]))
var Version: Bytes? = Undefined
var Version = "0.0.0.0"
if not BytesHelper.Contains(Bytes{8182}, Reader.Peek())
// extension version is specified
Version = Reader.ReadVarbinary()
Version = new String(Reader.ReadVarbinary())
;
Reader.ReadBoolean() // unknown flag
if V8.VersionIsUpper("8.3.21", ConfigCompatibilityMode)
Reader.ReadBoolean() // unknown flag
;
val Active = Reader.ReadBoolean()
val UseMainRolesForAllUsers = Reader.ReadBoolean()
Reader.ThrowIfNextIsNot(Bytes{20})
Reader.ThrowIfNextIsNot(Bytes{20})
return new ExtensionInfo(
ExtensionName,
@ -100,14 +117,19 @@ structure Class
return GetFileDataAsBracketsNode("Params", FileName)
;
method GetConfigCASFileDataAsBracketsNode(FileName: String): BracketsParser.BracketsNode
return GetFileDataAsBracketsNode("ConfigCAS", FileName)
method GetConfigCASFileDataAsBracketsNode(FileName: String): Array<BracketsParser.BracketsNode>
return GetFileDataAsBracketsNodes("ConfigCAS", FileName)
;
method GetConfigFileDataAsBracketsNode(FileName: String): BracketsParser.BracketsNode
return GetFileDataAsBracketsNode("Config", FileName)
;
method GetFileDataAsBracketsNodes(TableName: String, FileName: String): Array<BracketsParser.BracketsNode>
val Data = GetFileDataAsString(TableName, FileName)
return BracketsParser.ParseList(Data)
;
method GetFileDataAsBracketsNode(TableName: String, FileName: String): BracketsParser.BracketsNode
val Data = GetFileDataAsString(TableName, FileName)
return BracketsParser.Parse(Data)

View File

@ -1,5 +1,6 @@
#required Common/Sql.sbsl
#required Common/Ras.sbsl
#required Common/Log.sbsl
method Script(
Server: String,
@ -10,9 +11,9 @@ method Script(
RasAddress = "localhost",
RasPort = 1545)
Console.Write("Restoring database from the last backup")
Log.i("Restoring database from the last backup")
Sql.CreateDatabaseFromLastBackup(Server, SourceInfobase, User, Password, InfobaseName)
Console.Write("Register infobase in the cluster")
Log.i("Register infobase in the cluster")
Ras.CreateInfobaseIfNotExists(InfobaseName, Server, User, Password, RasAddress, RasPort)
;

View File

@ -16,7 +16,7 @@ method Script(
RequiredVersion: String,
TemplatesPath: String,
AccessCode: String,
PlatformVersion: String = "")
PlatformVersion: String = ""): Number
use Connection = Sql.BuildConnection(Server, Infobase, SqlUser, SqlPassword)
val Database = V8Database.NewInstance(Connection)
val ConfigInfo = Database.GetConfigInfo()
@ -24,10 +24,11 @@ method Script(
if V8.VersionIsUpper(ConfigInfo.Version, RequiredVersion)
val CfuPath = Path.Join(Path.Join(TemplatesPath, RequiredVersion.Replace(".", "_")), "1cv8.cfu")
if Path.Exists(CfuPath)
if not Path.Exists(CfuPath)
Log.i("Using CFU path: $CfuPath")
else
throw new IllegalStateException("Couldn't find CFU file of required version $RequiredVersion by path: %CfuPath")
Log.e("Couldn't find CFU file of required version $RequiredVersion by path: %CfuPath")
return 1
;
Log.i("Blocking connections")
@ -37,7 +38,7 @@ method Script(
BatchMode.UpdateConfiguration(Server, Infobase, User, Password, AccessCode, CfuPath, PlatformVersion)
Log.i("Unblocking connections")
Ras.UnblockConnections(Infobase, User, Password, AccessCode)
Ras.UnblockConnections(Infobase, User, Password)
else
Log.i("It doesn't need to update configuration (Current: ${ConfigInfo.Version}, Required: %RequiredVersion)")
;

72
UpdateExtension.sbsl Normal file
View File

@ -0,0 +1,72 @@
#required Common/Log.sbsl
#required Common/V8Database.sbsl
#required Common/Sql.sbsl
#required Common/V8.sbsl
#required Common/Path.sbsl
#required Common/BatchMode.sbsl
#required Common/Ras.sbsl
// Method expects to get a path to the zip archive in the "ExtensionPath" parameter
method Script(
Server: String,
Infobase: String,
User: String,
Password: String,
SqlUser: String,
SqlPassword: String,
ExtensionPath: String,
AccessCode: String,
PlatformVersion: String = ""): Number
use Connection = Sql.BuildConnection(Server, Infobase, SqlUser, SqlPassword)
val Database = V8Database.NewInstance(Connection)
if not Path.IsFile(ExtensionPath) and not Path.GetFileExtension(ExtensionPath).ToUpperCase() == "ZIP"
Log.e("ExtensionPath parameter must be path to the zip archive")
return 1
;
val ExtensionFolder = Files.CreateTempDirectory()
val ExtensionArchive = new ZipFile(ExtensionPath)
ExtensionArchive.ExtractAll(ExtensionFolder)
ExtensionPath = ExtensionFolder.Path
val ConfigurationFilePath = Path.Join(ExtensionPath, "Configuration.xml")
if not Path.Exists(ConfigurationFilePath)
Log.e("Couldn't find \"Configuration.xml\" file")
return 1
;
val Reader = new XmlReader(FilesHelper.ReadFileToEnd(ConfigurationFilePath))
val Namespace = "http://v8.1c.ru/8.3/MDClasses"
val NewExtensionName = Xml.GetValue(Reader, "MetaDataObject, Configuration, Properties, Name", Namespace)
val NewExtensionVersion = Xml.GetValue(Reader, "Version", Namespace) ?? "0.0.0.0"
if not Database.HasExtension(NewExtensionName)
Log.e("Extension \"%NewExtensionName\" is not connected to the infobase \"%Infobase\"")
return 1
;
val ConfigInfo = Database.GetConfigInfo()
var ExpectingConfigVersion = V8.ConfigurationVersionFromExtensionVersion(NewExtensionVersion)
if ConfigInfo.Version != ExpectingConfigVersion
Log.e("Extension version (%ExpectingConfigVersion) targets to the other configuration version (${ConfigInfo.Version})")
return 1
;
val ConnectedExtensionInfo = Database.GetExtensionInfo(NewExtensionName)
if not V8.VersionIsUpper(ConnectedExtensionInfo.Version, NewExtensionVersion)
Log.e("It doesn't need to update extension (Current: ${ConnectedExtensionInfo.Version}, New: %NewExtensionVersion)")
return 1
;
Log.i("Blocking connections")
Ras.BlockConnections(Infobase, User, Password, AccessCode)
Log.i("Updating extension (%Server/%Infobase/%NewExtensionName)")
BatchMode.UpdateExtension(Server, Infobase, User, Password, AccessCode, NewExtensionName, ExtensionPath, PlatformVersion)
Log.i("Unblocking connections")
Ras.UnblockConnections(Infobase, User, Password)
;