Question
· Jan 19, 2018

How to create productions via routine

Hi All,

I am trying to create a production from a script(routine). 

I am using the below way to create an empty production

Set oProd=##class(Ens.Config.Production).%New()
Set oProd.Name="Test.NewProduction"
Set oProd.ActorPoolSize=1
Set status=oProd.%Save()

But when i tried to start the production, i am getting an error as "Test.NewProduction" class does not exists. 

Is there any other way to create the production via routine or terminal using commands as above?

Discussion (6)2
Log in or sign up to continue

Why would you want to do that?

Here's sample production class:

Class Test.Production Extends Ens.Production
{

XData ProductionDefinition
{
<Production Name="Test.Production" TestingEnabled="true" LogGeneralTraceEvents="true">
  <Description></Description>
  <ActorPoolSize>1</ActorPoolSize>
ion>
}

}

Ens.Config.Production serialized is XData ProductionDefinition and not the class itself.

To create production class automatically you need to:

  1. Create %Dictionary.ClassDefinition object for your test production
  2. Create Ens.Config.Production object
  3. Create %Dictionary.XDataDefinition
  4. Serialize (2) into (3)
  5. Insert XData (3) into (1)
  6. Save and compile (1)

Hi @Raja Mohan and @Haitem El Aaouani 

Bellow a sample method

ClassMethod CreatProdution(package As %String = "test", name As %String = "AutoCreatedProduction") As %Status
{
  #Dim produtionClassName As %String = package _ "." _ name
  If ('$ZName(produtionClasName, 4))
  {
  Return $System.Status.Error(5001, "Invalid Production package or name.")
  }
  // Create empty production class definition
  #Dim productionDefinition As %Dictionary.ClassDefinition = ##Class(%Dictionary.ClassDefinition).%New()
  //
  Set productionDefinition.Name         = produtionClassName
  Set productionDefinition.Super        = "Ens.Production"
  Set productionDefinition.ClassVersion = 25
  //
  // Create the XData definition
  #Dim xdataDefinition As %Dictionary.XDataDefinition = ##Class(%Dictionary.XDataDefinition).%New()
  //
  Set xdataDefinition.Name = "ProductionDefinition"
  //
  Do xdataDefinition.Data.WriteLine("<Production Name="""produtionClassName"""/>")
  //
  // Insert XData Definition into Production Definition
  Do productionDefinition.XDatas.Insert(xdataDefinition)
  //
  #Dim statusCode As %Status = productionDefinition.%Save()
  //
  If ($System.Status.IsError(statusCode))
  {
  Return statusCode
  }
  // Compile the production class
  Set statusCode = $System.OBJ.Compile(produtionClassName,"k-d")
  If ($System.Status.IsError(%Dictionary.XDataDefinition))
  {
  Return statusCode
  }
  // fill in production:
  #Dim production As Ens.Config.Production = ##Class(Ens.Config.Production).%OpenId(produtionClassName)
  If ('$IsObject(production))
  {
  Return $System.Status.Error(5001, "Unable to open new production: " _ produtionClassName)
  }
  Set production.Name           = produtionClassName
  Set production.ActorPoolSize  = 2
  //
  // save production (and item), update production class and account for Source Control
  Return ##Class(EnsPortal.Template.prodConfigSCPage).CallProductionUpdateAndSaveToClass(production,"","SaveProduction")
}